826 {
828
832
834
835 auto set_section_monitor = [&](auto solver) {
837 SNES snes;
838 CHKERR TSGetSNES(solver, &snes);
839 CHKERR SNESMonitorSet(snes,
842 (void *)(snes_ctx_ptr.get()), nullptr);
844 };
845
846 auto create_post_process_elements = [&]() {
847 auto push_vol_ops = [this](auto &pip) {
849 pip, {
H1,
HDIV},
"GEOMETRY");
850
851 auto [common_plastic_ptr, common_hencky_ptr] =
852 PlasticOps::createCommonPlasticOps<SPACE_DIM, IT, DomainEleOp>(
853 mField,
"MAT_PLASTIC", pip,
"U",
"EP",
"TAU", 1., Sev::inform);
854
855 if (common_hencky_ptr) {
856 if (common_plastic_ptr->mGradPtr != common_hencky_ptr->matGradPtr)
858 }
859
860 return std::make_pair(common_plastic_ptr, common_hencky_ptr);
861 };
862
863 auto push_vol_post_proc_ops = [this](auto &pp_fe, auto &&p) {
865
866 auto &pip = pp_fe->getOpPtrVector();
867
868 auto [common_plastic_ptr, common_hencky_ptr] = p;
869
871
872 auto x_ptr = boost::make_shared<MatrixDouble>();
873 pip.push_back(
875 auto u_ptr = boost::make_shared<MatrixDouble>();
877
879
880 pip.push_back(
881
883
884 pp_fe->getPostProcMesh(), pp_fe->getMapGaussPts(),
885
886 {{"PLASTIC_SURFACE",
887 common_plastic_ptr->getPlasticSurfacePtr()},
888 {"PLASTIC_MULTIPLIER",
889 common_plastic_ptr->getPlasticTauPtr()}},
890
891 {{"U", u_ptr}, {"GEOMETRY", x_ptr}},
892
893 {{"GRAD", common_hencky_ptr->matGradPtr},
894 {"FIRST_PIOLA", common_hencky_ptr->getMatFirstPiolaStress()}},
895
896 {{"HENCKY_STRAIN", common_hencky_ptr->getMatLogC()},
897 {"PLASTIC_STRAIN", common_plastic_ptr->getPlasticStrainPtr()},
898 {"PLASTIC_FLOW", common_plastic_ptr->getPlasticFlowPtr()}}
899
900 )
901
902 );
903
904 } else {
905
906 pip.push_back(
907
909
910 pp_fe->getPostProcMesh(), pp_fe->getMapGaussPts(),
911
912 {{"PLASTIC_SURFACE",
913 common_plastic_ptr->getPlasticSurfacePtr()},
914 {"PLASTIC_MULTIPLIER",
915 common_plastic_ptr->getPlasticTauPtr()}},
916
917 {{"U", u_ptr}, {"GEOMETRY", x_ptr}},
918
919 {},
920
921 {{"STRAIN", common_plastic_ptr->mStrainPtr},
922 {"STRESS", common_plastic_ptr->mStressPtr},
923 {"PLASTIC_STRAIN", common_plastic_ptr->getPlasticStrainPtr()},
924 {"PLASTIC_FLOW", common_plastic_ptr->getPlasticFlowPtr()}}
925
926 )
927
928 );
929 }
930
932 };
933
934 PetscBool post_proc_vol;
935 PetscBool post_proc_skin;
936
938 post_proc_vol = PETSC_TRUE;
939 post_proc_skin = PETSC_FALSE;
940 } else {
941 post_proc_vol = PETSC_FALSE;
942 post_proc_skin = PETSC_TRUE;
943 }
945 PETSC_NULLPTR);
947 &post_proc_skin, PETSC_NULLPTR);
948
949 auto vol_post_proc = [this, push_vol_post_proc_ops, push_vol_ops,
950 post_proc_vol]() {
951 if (post_proc_vol == PETSC_FALSE)
952 return boost::shared_ptr<PostProcEle>();
953 auto pp_fe = boost::make_shared<PostProcEle>(
mField);
955 push_vol_post_proc_ops(pp_fe, push_vol_ops(pp_fe->getOpPtrVector())),
956 "push_vol_post_proc_ops");
957 return pp_fe;
958 };
959
960 auto skin_post_proc = [this, push_vol_post_proc_ops, push_vol_ops,
961 post_proc_skin]() {
962 if (post_proc_skin == PETSC_FALSE)
963 return boost::shared_ptr<SkinPostProcEle>();
964
966 auto pp_fe = boost::make_shared<SkinPostProcEle>(
mField);
969 pp_fe->getOpPtrVector().push_back(op_side);
971 pp_fe, push_vol_ops(op_side->getOpPtrVector())),
972 "push_vol_post_proc_ops");
973 return pp_fe;
974 };
975
976 return std::make_pair(vol_post_proc(), skin_post_proc());
977 };
978
979 auto scatter_create = [&](
auto D,
auto coeff) {
982 ROW,
"U", coeff, coeff, is);
983 int loc_size;
984 CHKERR ISGetLocalSize(is, &loc_size);
987 VecScatter scatter;
988 CHKERR VecScatterCreate(
D, is,
v, PETSC_NULLPTR, &scatter);
991 };
992
993 boost::shared_ptr<SetPtsData> field_eval_data;
994 boost::shared_ptr<MatrixDouble> u_field_ptr;
995
996 std::array<double, 3> field_eval_coords{0.0, 0.0, 0.0};
997 int coords_dim = 3;
999 field_eval_coords.data(), &coords_dim,
1001
1002 boost::shared_ptr<std::map<std::string, boost::shared_ptr<VectorDouble>>>
1003 scalar_field_ptrs = boost::make_shared<
1004 std::map<std::string, boost::shared_ptr<VectorDouble>>>();
1005 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
1006 vector_field_ptrs = boost::make_shared<
1007 std::map<std::string, boost::shared_ptr<MatrixDouble>>>();
1008 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
1009 sym_tensor_field_ptrs = boost::make_shared<
1010 std::map<std::string, boost::shared_ptr<MatrixDouble>>>();
1011 boost::shared_ptr<std::map<std::string, boost::shared_ptr<MatrixDouble>>>
1012 tensor_field_ptrs = boost::make_shared<
1013 std::map<std::string, boost::shared_ptr<MatrixDouble>>>();
1014
1016 auto u_field_ptr = boost::make_shared<MatrixDouble>();
1017 field_eval_data =
1019
1022
1023 field_eval_data->setEvalPoints(field_eval_coords.data(), 1);
1024 auto no_rule = [](
int,
int,
int) {
return -1; };
1025 auto field_eval_fe_ptr = field_eval_data->feMethodPtr;
1026 field_eval_fe_ptr->getRuleHook = no_rule;
1027
1029 field_eval_fe_ptr->getOpPtrVector(), {H1, HDIV}, "GEOMETRY");
1030
1031 auto [common_plastic_ptr, common_hencky_ptr] =
1032 PlasticOps::createCommonPlasticOps<SPACE_DIM, IT, DomainEleOp>(
1033 mField,
"MAT_PLASTIC", field_eval_fe_ptr->getOpPtrVector(),
"U",
1034 "EP", "TAU", 1., Sev::inform);
1035
1036 field_eval_fe_ptr->getOpPtrVector().push_back(
1038
1039 if ((common_plastic_ptr) && (common_hencky_ptr) && (scalar_field_ptrs)) {
1041 scalar_field_ptrs->insert(
1042 {"PLASTIC_SURFACE", common_plastic_ptr->getPlasticSurfacePtr()});
1043 scalar_field_ptrs->insert(
1044 {"PLASTIC_MULTIPLIER", common_plastic_ptr->getPlasticTauPtr()});
1045 vector_field_ptrs->insert({"U", u_field_ptr});
1046 sym_tensor_field_ptrs->insert(
1047 {"PLASTIC_STRAIN", common_plastic_ptr->getPlasticStrainPtr()});
1048 sym_tensor_field_ptrs->insert(
1049 {"PLASTIC_FLOW", common_plastic_ptr->getPlasticFlowPtr()});
1050 sym_tensor_field_ptrs->insert(
1051 {"HENCKY_STRAIN", common_hencky_ptr->getMatLogC()});
1052 tensor_field_ptrs->insert({"GRAD", common_hencky_ptr->matGradPtr});
1053 tensor_field_ptrs->insert(
1054 {"FIRST_PIOLA", common_hencky_ptr->getMatFirstPiolaStress()});
1055 } else {
1056 scalar_field_ptrs->insert(
1057 {"PLASTIC_SURFACE", common_plastic_ptr->getPlasticSurfacePtr()});
1058 scalar_field_ptrs->insert(
1059 {"PLASTIC_MULTIPLIER", common_plastic_ptr->getPlasticTauPtr()});
1060 vector_field_ptrs->insert({"U", u_field_ptr});
1061 sym_tensor_field_ptrs->insert(
1062 {"STRAIN", common_plastic_ptr->mStrainPtr});
1063 sym_tensor_field_ptrs->insert(
1064 {"STRESS", common_plastic_ptr->mStressPtr});
1065 sym_tensor_field_ptrs->insert(
1066 {"PLASTIC_STRAIN", common_plastic_ptr->getPlasticStrainPtr()});
1067 sym_tensor_field_ptrs->insert(
1068 {"PLASTIC_FLOW", common_plastic_ptr->getPlasticFlowPtr()});
1069 }
1070 }
1071 }
1072
1073 auto test_monitor_ptr = boost::make_shared<FEMethod>();
1074
1075 auto set_time_monitor = [&](auto dm, auto solver) {
1079 field_eval_coords, field_eval_data, scalar_field_ptrs,
1080 vector_field_ptrs, sym_tensor_field_ptrs, tensor_field_ptrs));
1081 boost::shared_ptr<ForcesAndSourcesCore> null;
1082
1083 test_monitor_ptr->postProcessHook = [&]() {
1085
1086 if (
atom_test && fabs(test_monitor_ptr->ts_t - 0.5) < 1e-12 &&
1087 test_monitor_ptr->ts_step == 25) {
1088
1089 if (scalar_field_ptrs->at("PLASTIC_MULTIPLIER")->size()) {
1090 auto t_tau =
1092 MOFEM_LOG(
"PlasticSync", Sev::inform) <<
"Eval point tau: " << t_tau;
1093
1094 if (
atom_test == 1 && fabs(t_tau - 0.688861) > 1e-5) {
1096 "atom test %d failed: wrong plastic multiplier value",
1098 }
1099 }
1100
1101 if (vector_field_ptrs->at("U")->size1()) {
1103 auto t_disp =
1104 getFTensor1FromMat<SPACE_DIM>(*vector_field_ptrs->at("U"));
1105 MOFEM_LOG(
"PlasticSync", Sev::inform) <<
"Eval point U: " << t_disp;
1106
1107 if (
atom_test == 1 && fabs(t_disp(0) - 0.25 / 2.) > 1e-5 ||
1108 fabs(t_disp(1) + 0.0526736) > 1e-5) {
1110 "atom test %d failed: wrong displacement value",
1112 }
1113 }
1114
1115 if (sym_tensor_field_ptrs->at("PLASTIC_STRAIN")->size1()) {
1116 auto t_plastic_strain = getFTensor2SymmetricFromMat<SPACE_DIM>(
1117 *sym_tensor_field_ptrs->at("PLASTIC_STRAIN"));
1119 << "Eval point EP: " << t_plastic_strain;
1120
1122 fabs(t_plastic_strain(0, 0) - 0.221943) > 1e-5 ||
1123 fabs(t_plastic_strain(0, 1)) > 1e-5 ||
1124 fabs(t_plastic_strain(1, 1) + 0.110971) > 1e-5) {
1126 "atom test %d failed: wrong plastic strain value",
1128 }
1129 }
1130
1131 if (tensor_field_ptrs->at("FIRST_PIOLA")->size1()) {
1132 auto t_piola_stress = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(
1133 *tensor_field_ptrs->at("FIRST_PIOLA"));
1135 << "Eval point Piola stress: " << t_piola_stress;
1136
1137 if (
atom_test == 1 && fabs((t_piola_stress(0, 0) - 198.775) /
1138 t_piola_stress(0, 0)) > 1e-5 ||
1139 fabs(t_piola_stress(0, 1)) + fabs(t_piola_stress(1, 0)) +
1140 fabs(t_piola_stress(1, 1)) >
1141 1e-5) {
1143 "atom test %d failed: wrong Piola stress value",
1145 }
1146 }
1147 }
1148
1151 };
1152
1154 monitor_ptr, null, test_monitor_ptr);
1155
1157 };
1158
1159 auto set_schur_pc = [&](auto solver,
1160 boost::shared_ptr<SetUpSchur> &schur_ptr) {
1162
1164
1165
1174 for (
auto f : {
"U"}) {
1177 }
1179
1181 };
1182
1191#ifdef ADD_CONTACT
1192 for (
auto f : {
"SIGMA",
"EP",
"TAU"}) {
1195 }
1196#else
1197 for (
auto f : {
"EP",
"TAU"}) {
1200 }
1201#endif
1204 };
1205
1206
1207 if constexpr (
AT == AssemblyType::BLOCK_SCHUR) {
1208
1213
1214#ifdef ADD_CONTACT
1215
1216 auto get_nested_mat_data = [&](auto schur_dm, auto block_dm) {
1219
1220 {
1221
1222 {simple->getDomainFEName(),
1223
1224 {{"U", "U"},
1225 {"SIGMA", "SIGMA"},
1226 {"U", "SIGMA"},
1227 {"SIGMA", "U"},
1228 {"EP", "EP"},
1229 {"TAU", "TAU"},
1230 {"U", "EP"},
1231 {"EP", "U"},
1232 {"EP", "TAU"},
1233 {"TAU", "EP"},
1234 {"TAU", "U"}
1235
1236 }},
1237
1238 {simple->getBoundaryFEName(),
1239
1240 {{"SIGMA", "SIGMA"}, {"U", "SIGMA"}, {"SIGMA", "U"}
1241
1242 }}
1243
1244 }
1245
1246 );
1247
1249
1250 {dm_schur, dm_block}, block_mat_data,
1251
1252 {"SIGMA", "EP", "TAU"}, {nullptr, nullptr, nullptr}, true
1253
1254 );
1255 };
1256
1257#else
1258
1259 auto get_nested_mat_data = [&](auto schur_dm, auto block_dm) {
1260 auto block_mat_data =
1262
1263 {{simple->getDomainFEName(),
1264
1265 {{"U", "U"},
1266 {"EP", "EP"},
1267 {"TAU", "TAU"},
1268 {"U", "EP"},
1269 {"EP", "U"},
1270 {"EP", "TAU"},
1271 {"TAU", "U"},
1272 {"TAU", "EP"}
1273
1274 }}}
1275
1276 );
1277
1279
1280 {dm_schur, dm_block}, block_mat_data,
1281
1282 {"EP", "TAU"}, {nullptr, nullptr}, false
1283
1284 );
1285 };
1286
1287#endif
1288
1289 auto nested_mat_data = get_nested_mat_data(dm_schur, dm_block);
1291
1292 auto block_is =
getDMSubData(dm_block)->getSmartRowIs();
1293 auto ao_schur =
getDMSubData(dm_schur)->getSmartRowMap();
1294
1295
1296
1297 schur_ptr =
1299 CHKERR schur_ptr->setUp(solver);
1300 }
1301
1303 };
1304
1308 CHKERR VecSetDM(
D, PETSC_NULLPTR);
1309 CHKERR VecSetDM(DD, PETSC_NULLPTR);
1314
1315 auto create_solver = [pip_mng]() {
1317 return pip_mng->createTSIM();
1318 else
1319 return pip_mng->createTSIM2();
1320 };
1321
1322 auto solver = create_solver();
1323
1324 auto active_pre_lhs = []() {
1329 };
1330
1331 auto active_post_lhs = [&]() {
1333 auto get_iter = [&]() {
1334 SNES snes;
1336 int iter;
1338 "Can not get iter");
1339 return iter;
1340 };
1341
1342 auto iter = get_iter();
1343 if (iter >= 0) {
1344
1345 std::array<int, 5> activity_data;
1346 std::fill(activity_data.begin(), activity_data.end(), 0);
1348 activity_data.data(), activity_data.size(), MPI_INT,
1350
1351 int &active_points = activity_data[0];
1352 int &avtive_full_elems = activity_data[1];
1353 int &avtive_elems = activity_data[2];
1354 int &nb_points = activity_data[3];
1355 int &nb_elements = activity_data[4];
1356
1357 if (nb_points) {
1358
1359 double proc_nb_points =
1360 100 * static_cast<double>(active_points) / nb_points;
1361 double proc_nb_active =
1362 100 * static_cast<double>(avtive_elems) / nb_elements;
1363 double proc_nb_full_active = 100;
1364 if (avtive_elems)
1365 proc_nb_full_active =
1366 100 * static_cast<double>(avtive_full_elems) / avtive_elems;
1367
1369 "Iter %d nb pts %d nb active pts %d (%3.3f\%) nb active "
1370 "elements %d "
1371 "(%3.3f\%) nb full active elems %d (%3.3f\%)",
1372 iter, nb_points, active_points, proc_nb_points,
1373 avtive_elems, proc_nb_active, avtive_full_elems,
1374 proc_nb_full_active, iter);
1375 }
1376 }
1377
1379 };
1380
1381 auto add_active_dofs_elem = [&](auto dm) {
1383 auto fe_pre_proc = boost::make_shared<FEMethod>();
1384 fe_pre_proc->preProcessHook = active_pre_lhs;
1385 auto fe_post_proc = boost::make_shared<FEMethod>();
1386 fe_post_proc->postProcessHook = active_post_lhs;
1388 ts_ctx_ptr->getPreProcessIJacobian().push_front(fe_pre_proc);
1389 ts_ctx_ptr->getPostProcessIJacobian().push_back(fe_post_proc);
1391 };
1392
1393 auto set_essential_bc = [&](auto dm, auto solver) {
1395
1396
1397 auto pre_proc_ptr = boost::make_shared<FEMethod>();
1398 auto post_proc_rhs_ptr = boost::make_shared<FEMethod>();
1399 auto post_proc_lhs_ptr = boost::make_shared<FEMethod>();
1401 ts_ctx_ptr->getPreProcessIFunction().push_front(pre_proc_ptr);
1402 ts_ctx_ptr->getPreProcessIJacobian().push_front(pre_proc_ptr);
1403 ts_ctx_ptr->getPostProcessIFunction().push_back(post_proc_rhs_ptr);
1404 ts_ctx_ptr->getPostProcessIJacobian().push_back(post_proc_lhs_ptr);
1405
1406
1407 auto disp_time_scale = boost::make_shared<TimeScale>();
1408
1409 auto get_bc_hook_rhs = [&]() {
1411 mField, pre_proc_ptr, {disp_time_scale},
false);
1412 };
1413 pre_proc_ptr->preProcessHook = get_bc_hook_rhs();
1414
1415 auto waak_post_proc_rhs_ptr = boost::weak_ptr<FEMethod>(
1416 post_proc_rhs_ptr);
1417 auto get_post_proc_hook_rhs = [this, waak_post_proc_rhs_ptr]() {
1420 mField, waak_post_proc_rhs_ptr.lock(),
nullptr, Sev::verbose)();
1422 mField, waak_post_proc_rhs_ptr.lock(), 1.)();
1424 };
1425 auto get_post_proc_hook_lhs = [&]() {
1427 mField, post_proc_lhs_ptr, 1.);
1428 };
1429
1430 post_proc_rhs_ptr->postProcessHook = get_post_proc_hook_rhs;
1431 post_proc_lhs_ptr->postProcessHook = get_post_proc_hook_lhs();
1432
1434 };
1435
1438 CHKERR TSSetIJacobian(solver,
B,
B, PETSC_NULLPTR, PETSC_NULLPTR);
1439 } else {
1440 CHKERR TSSetI2Jacobian(solver,
B,
B, PETSC_NULLPTR, PETSC_NULLPTR);
1441 }
1443 CHKERR TSSetSolution(solver,
D);
1444 } else {
1445 CHKERR TS2SetSolution(solver,
D, DD);
1446 }
1447 CHKERR set_section_monitor(solver);
1448 CHKERR set_time_monitor(dm, solver);
1449 CHKERR TSSetFromOptions(solver);
1450
1451 CHKERR add_active_dofs_elem(dm);
1452 boost::shared_ptr<SetUpSchur> schur_ptr;
1453 CHKERR set_schur_pc(solver, schur_ptr);
1454 CHKERR set_essential_bc(dm, solver);
1455
1459 BOOST_LOG_SCOPED_THREAD_ATTR("Timeline", attrs::timer());
1460 MOFEM_LOG(
"TIMER", Sev::verbose) <<
"TSSetUp";
1462 MOFEM_LOG(
"TIMER", Sev::verbose) <<
"TSSetUp <= done";
1463 MOFEM_LOG(
"TIMER", Sev::verbose) <<
"TSSolve";
1464 CHKERR TSSolve(solver, NULL);
1465
1466
1467 {
1468 PetscReal expected_time;
1469 CHKERR TSGetTime(solver, &expected_time);
1471 solver, expected_time, {1e-12, 1e-12}, "plasticity");
1472 }
1473 MOFEM_LOG(
"TIMER", Sev::verbose) <<
"TSSolve <= done";
1474
1478 "ts_manager_graph.dot");
1479 }
1480
1482}
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.
auto getDMTsCtx(DM dm)
Get TS context data structure used by DM.
MoFEMErrorCode MoFEMSNESMonitorFields(SNES snes, PetscInt its, PetscReal fgnorm, SnesCtx *ctx)
Sens monitor printing residual field by field.
auto getDMSubData(DM dm)
Get sub problem data structure.
boost::shared_ptr< BlockStructure > createBlockMatStructure(DM dm, SchurFEOpsFEandFields schur_fe_op_vec)
Create block matrix structure.
boost::shared_ptr< NestSchurData > createSchurNestedMatrixStruture(std::pair< SmartPetscObj< DM >, SmartPetscObj< DM > > dms, boost::shared_ptr< BlockStructure > block_mat_data_ptr, std::vector< std::string > fields_names, std::vector< boost::shared_ptr< Range > > field_ents, bool add_preconditioner_block)
Create structure of nested matrix [A11 A10; A01 A00].
MoFEMErrorCode DMMoFEMSetNestSchurData(DM dm, boost::shared_ptr< NestSchurData >)
static auto getFTensor0FromVec(V &data)
Get tensor rank 0 (scalar) form data vector.
auto getDMSnesCtx(DM dm)
Get SNES context data structure used by DM.
std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter > > uZScatter
std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter > > uXScatter
std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter > > uYScatter
Section manager is used to create indexes and sections.
static MoFEMErrorCode writeTSGraphGraphviz(TsCtx *ts_ctx, std::string file_name)
TS graph to Graphviz file.
static std::array< int, 5 > activityData
static boost::shared_ptr< SetUpSchur > createSetUpSchur(MoFEM::Interface &m_field)