9 #ifndef EXECUTABLE_DIMENSION
10 #define EXECUTABLE_DIMENSION 3
15 using namespace MoFEM;
55 GAUSS>::OpMixDivTimesScalar<SPACE_DIM>;
69 GAUSS>::OpBaseTimesVector<3, SPACE_DIM, 1>;
76 GAUSS>::OpMixDivTimesU<3, 1, SPACE_DIM>;
116 GAUSS>::OpEssentialRhs<HeatFluxCubitBcData, 3, SPACE_DIM>;
119 GAUSS>::OpEssentialLhs<HeatFluxCubitBcData, 3, SPACE_DIM>;
148 CHKERR moab.add_entities(*out_meshset,
r);
149 CHKERR moab.write_file(name.c_str(),
"VTK",
"", out_meshset->get_ptr(), 1);
177 :
public boost::enable_shared_from_this<BlockedParameters> {
184 return boost::shared_ptr<MatrixDouble>(shared_from_this(), &mD);
188 return boost::shared_ptr<double>(shared_from_this(), &coeffExpansion);
192 return boost::shared_ptr<double>(shared_from_this(), &heatConductivity);
196 return boost::shared_ptr<double>(shared_from_this(), &heatCapacity);
201 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
202 std::string block_elastic_name, std::string block_thermal_name,
203 boost::shared_ptr<BlockedParameters> blockedParamsPtr,
Sev sev);
207 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pipeline,
208 std::string block_elastic_name, std::string block_thermal_name,
209 boost::shared_ptr<BlockedParameters> blockedParamsPtr,
Sev sev) {
213 OpMatElasticBlocks(boost::shared_ptr<MatrixDouble>
m,
double bulk_modulus_K,
216 std::vector<const CubitMeshSets *> meshset_vec_ptr)
221 "Can not get data from block");
228 for (
auto &b : blockData) {
230 if (b.blockEnts.find(getFEEntityHandle()) != b.blockEnts.end()) {
231 CHKERR getMatDPtr(matDPtr, b.bulkModulusK, b.shearModulusG);
236 CHKERR getMatDPtr(matDPtr, bulkModulusKDefault, shearModulusGDefault);
241 boost::shared_ptr<MatrixDouble> matDPtr;
245 double shearModulusG;
249 double bulkModulusKDefault;
250 double shearModulusGDefault;
251 std::vector<BlockData> blockData;
255 std::vector<const CubitMeshSets *> meshset_vec_ptr,
259 for (
auto m : meshset_vec_ptr) {
261 std::vector<double> block_data;
262 CHKERR m->getAttributes(block_data);
263 if (block_data.size() < 2) {
265 "Expected that block has two attributes");
267 auto get_block_ents = [&]() {
270 m_field.
get_moab().get_entities_by_handle(
m->meshset, ents,
true);
290 MoFEMErrorCode getMatDPtr(boost::shared_ptr<MatrixDouble> mat_D_ptr,
294 auto set_material_stiffness = [&]() {
304 auto t_D = getFTensor4DdgFromMat<SPACE_DIM, SPACE_DIM, 0>(*mat_D_ptr);
313 set_material_stiffness();
318 double default_bulk_modulus_K =
320 double default_shear_modulus_G =
323 pipeline.push_back(
new OpMatElasticBlocks(
324 blockedParamsPtr->getDPtr(), default_bulk_modulus_K,
325 default_bulk_modulus_K, mField, sev,
330 (boost::format(
"%s(.*)") % block_elastic_name).str()
337 OpMatThermalBlocks(boost::shared_ptr<double> expansion_ptr,
338 boost::shared_ptr<double> conductivity_ptr,
339 boost::shared_ptr<double> capacity_ptr,
341 std::vector<const CubitMeshSets *> meshset_vec_ptr)
343 expansionPtr(expansion_ptr), conductivityPtr(conductivity_ptr),
344 capacityPtr(capacity_ptr) {
346 "Can not get data from block");
353 for (
auto &b : blockData) {
355 if (b.blockEnts.find(getFEEntityHandle()) != b.blockEnts.end()) {
356 *expansionPtr = b.expansion;
357 *conductivityPtr = b.conductivity;
358 *capacityPtr = b.capacity;
378 std::vector<BlockData> blockData;
382 std::vector<const CubitMeshSets *> meshset_vec_ptr,
386 for (
auto m : meshset_vec_ptr) {
388 std::vector<double> block_data;
389 CHKERR m->getAttributes(block_data);
390 if (block_data.size() < 3) {
392 "Expected that block has two attributes");
394 auto get_block_ents = [&]() {
397 m_field.
get_moab().get_entities_by_handle(
m->meshset, ents,
true);
402 <<
m->getName() <<
": expansion = " << block_data[0]
403 <<
" conductivity = " << block_data[1] <<
" capacity "
407 {block_data[0], block_data[1], block_data[2], get_block_ents()});
413 boost::shared_ptr<double> expansionPtr;
414 boost::shared_ptr<double> conductivityPtr;
415 boost::shared_ptr<double> capacityPtr;
418 pipeline.push_back(
new OpMatThermalBlocks(
419 blockedParamsPtr->getCoeffExpansionPtr(),
420 blockedParamsPtr->getHeatConductivityPtr(),
421 blockedParamsPtr->getHeatCapacityPtr(), mField, sev,
426 (boost::format(
"%s(.*)") % block_thermal_name).str()
439 CHKERR createCommonData();
470 fieldEvalCoords.data(), &coords_dim,
473 scalarFieldPtr = boost::make_shared<VectorDouble>();
474 vectorFieldPtr = boost::make_shared<MatrixDouble>();
475 tensorFieldPtr = boost::make_shared<MatrixDouble>();
483 fieldEvalData,
simple->getDomainFEName());
486 fieldEvalData,
simple->getDomainFEName());
489 fieldEvalData->setEvalPoints(fieldEvalCoords.data(), 1);
490 auto no_rule = [](
int,
int,
int) {
return -1; };
492 auto field_eval_fe_ptr = fieldEvalData->feMethodPtr.lock();
493 field_eval_fe_ptr->getRuleHook = no_rule;
495 field_eval_fe_ptr->getOpPtrVector().push_back(
497 field_eval_fe_ptr->getOpPtrVector().push_back(
499 field_eval_fe_ptr->getOpPtrVector().push_back(
501 "U", tensorFieldPtr));
512 auto get_command_line_parameters = [&]() {
542 <<
"Reference temperature " <<
ref_temp;
549 CHKERR get_command_line_parameters();
567 auto get_skin = [&]() {
569 CHKERR mField.get_moab().get_entities_by_dimension(0,
SPACE_DIM, body_ents);
570 Skinner skin(&mField.get_moab());
572 CHKERR skin.find_skin(0, body_ents,
false, skin_ents);
576 auto filter_flux_blocks = [&](
auto skin) {
577 auto remove_cubit_blocks = [&](
auto c) {
585 CHKERR mField.get_moab().get_entities_by_dimension(
587 skin = subtract(skin, ents);
592 auto remove_named_blocks = [&](
auto n) {
597 (boost::format(
"%s(.*)") %
n).str()
603 CHKERR mField.get_moab().get_entities_by_dimension(
605 skin = subtract(skin, ents);
611 "remove_cubit_blocks");
613 "remove_cubit_blocks");
615 "remove_named_blocks");
621 auto filter_true_skin = [&](
auto skin) {
623 ParallelComm *pcomm =
625 CHKERR pcomm->filter_pstatus(skin, PSTATUS_SHARED | PSTATUS_MULTISHARED,
626 PSTATUS_NOT, -1, &boundary_ents);
627 return boundary_ents;
630 auto remove_flux_ents = filter_true_skin(filter_flux_blocks(get_skin()));
635 MOFEM_LOG(
"SYNC", Sev::noisy) << remove_flux_ents << endl;
642 (boost::format(
"flux_remove_%d.vtk") % mField.get_comm_rank()).str(),
648 simple->getProblemName(),
"FLUX", remove_flux_ents);
650 auto set_init_temp = [](boost::shared_ptr<FieldEntity> field_entity_ptr) {
651 field_entity_ptr->getEntFieldData()[0] =
init_temp;
654 CHKERR mField.getInterface<
FieldBlas>()->fieldLambdaOnEntities(set_init_temp,
658 simple->getProblemName(),
"U");
660 simple->getProblemName(),
"FLUX",
false);
677 auto boundary_marker =
678 bc_mng->getMergedBlocksMarker(vector<string>{
"HEATFLUX"});
688 auto block_params = boost::make_shared<BlockedParameters>();
689 auto mDPtr = block_params->getDPtr();
690 auto coeff_expansion_ptr = block_params->getCoeffExpansionPtr();
691 auto heat_conductivity_ptr = block_params->getHeatConductivityPtr();
692 auto heat_capacity_ptr = block_params->getHeatCapacityPtr();
695 auto time_scale = boost::make_shared<TimeScale>();
698 auto time_bodyforce_scaling =
699 boost::make_shared<TimeScale>(
"bodyforce_scale.txt");
700 auto time_heatsource_scaling =
701 boost::make_shared<TimeScale>(
"heatsource_scale.txt");
702 auto time_temperature_scaling =
703 boost::make_shared<TimeScale>(
"temperature_bc_scale.txt");
704 auto time_displacement_scaling =
705 boost::make_shared<TimeScale>(
"displacement_bc_scale.txt");
706 auto time_flux_scaling = boost::make_shared<TimeScale>(
"flux_bc_scale.txt");
707 auto time_force_scaling =
708 boost::make_shared<TimeScale>(
"force_bc_scale.txt");
710 auto add_domain_rhs_ops = [&](
auto &pipeline) {
716 auto mat_grad_ptr = boost::make_shared<MatrixDouble>();
717 auto mat_strain_ptr = boost::make_shared<MatrixDouble>();
718 auto mat_stress_ptr = boost::make_shared<MatrixDouble>();
720 auto vec_temp_ptr = boost::make_shared<VectorDouble>();
721 auto vec_temp_dot_ptr = boost::make_shared<VectorDouble>();
722 auto mat_flux_ptr = boost::make_shared<MatrixDouble>();
723 auto vec_temp_div_ptr = boost::make_shared<VectorDouble>();
729 "FLUX", vec_temp_div_ptr));
737 pipeline.push_back(
new OpStressThermal(mat_strain_ptr, vec_temp_ptr, mDPtr,
741 pipeline.push_back(
new OpSetBc(
"FLUX",
true, boundary_marker));
745 [](
double,
double,
double) constexpr {
return 1; }));
747 auto resistance = [heat_conductivity_ptr](
const double,
const double,
749 return (1. / (*heat_conductivity_ptr));
752 auto capacity = [heat_capacity_ptr](
const double,
const double,
754 return -(*heat_capacity_ptr);
759 pipeline.push_back(
new OpHdivFlux(
"FLUX", mat_flux_ptr, resistance));
760 pipeline.push_back(
new OpHDivTemp(
"FLUX", vec_temp_ptr, unity));
761 pipeline.push_back(
new OpBaseDivFlux(
"T", vec_temp_div_ptr, unity));
762 pipeline.push_back(
new OpBaseDotT(
"T", vec_temp_dot_ptr, capacity));
764 pipeline.push_back(
new OpUnSetBc(
"FLUX"));
768 pipeline, mField,
"T", {time_scale, time_heatsource_scaling},
769 "HEAT_SOURCE", Sev::inform);
771 pipeline, mField,
"U", {time_scale, time_bodyforce_scaling},
772 "BODY_FORCE", Sev::inform);
774 pipeline, mField,
"T", vec_temp_ptr,
"SETTEMP", Sev::inform);
779 auto add_domain_lhs_ops = [&](
auto &pipeline) {
785 pipeline.push_back(
new OpSetBc(
"FLUX",
true, boundary_marker));
787 pipeline.push_back(
new OpKCauchy(
"U",
"U", mDPtr));
789 "U",
"T", mDPtr, coeff_expansion_ptr));
791 auto resistance = [heat_conductivity_ptr](
const double,
const double,
793 return (1. / (*heat_conductivity_ptr));
795 auto capacity = [heat_capacity_ptr](
const double,
const double,
797 return -(*heat_capacity_ptr);
799 pipeline.push_back(
new OpHdivHdiv(
"FLUX",
"FLUX", resistance));
800 pipeline.push_back(
new OpHdivT(
801 "FLUX",
"T", []() constexpr {
return -1; },
true));
803 auto op_capacity =
new OpCapacity(
"T",
"T", capacity);
804 op_capacity->feScalingFun = [](
const FEMethod *fe_ptr) {
807 pipeline.push_back(op_capacity);
809 pipeline.push_back(
new OpUnSetBc(
"FLUX"));
811 auto vec_temp_ptr = boost::make_shared<VectorDouble>();
814 pipeline, mField,
"T", vec_temp_ptr,
"SETTEMP", Sev::verbose);
819 auto add_boundary_rhs_ops = [&](
auto &pipeline) {
824 pipeline.push_back(
new OpSetBc(
"FLUX",
true, boundary_marker));
828 pipeline_mng->getOpBoundaryRhsPipeline(), mField,
"U",
829 {time_scale, time_force_scaling},
"FORCE", Sev::inform);
832 pipeline_mng->getOpBoundaryRhsPipeline(), mField,
"FLUX",
833 {time_scale, time_temperature_scaling},
"TEMPERATURE", Sev::inform);
835 pipeline.push_back(
new OpUnSetBc(
"FLUX"));
837 auto mat_flux_ptr = boost::make_shared<MatrixDouble>();
842 mField, pipeline,
simple->getProblemName(),
"FLUX", mat_flux_ptr,
843 {time_scale, time_flux_scaling});
848 auto add_boundary_lhs_ops = [&](
auto &pipeline) {
855 mField, pipeline,
simple->getProblemName(),
"FLUX");
861 auto get_bc_hook_rhs = [&]() {
863 mField, pipeline_mng->getDomainRhsFE(),
864 {time_scale, time_displacement_scaling});
867 auto get_bc_hook_lhs = [&]() {
869 mField, pipeline_mng->getDomainLhsFE(),
870 {time_scale, time_displacement_scaling});
874 pipeline_mng->getDomainRhsFE()->preProcessHook = get_bc_hook_rhs();
875 pipeline_mng->getDomainLhsFE()->preProcessHook = get_bc_hook_lhs();
877 CHKERR add_domain_rhs_ops(pipeline_mng->getOpDomainRhsPipeline());
878 CHKERR add_domain_lhs_ops(pipeline_mng->getOpDomainLhsPipeline());
879 CHKERR add_boundary_rhs_ops(pipeline_mng->getOpBoundaryRhsPipeline());
880 CHKERR add_boundary_lhs_ops(pipeline_mng->getOpBoundaryLhsPipeline());
894 auto dm =
simple->getDM();
895 auto solver = pipeline_mng->createTSIM();
898 auto set_section_monitor = [&](
auto solver) {
901 CHKERR TSGetSNES(solver, &snes);
902 CHKERR SNESMonitorSet(snes,
905 (
void *)(snes_ctx_ptr.get()),
nullptr);
909 auto create_post_process_element = [&]() {
910 auto post_proc_fe = boost::make_shared<PostProcEle>(mField);
912 auto block_params = boost::make_shared<BlockedParameters>();
913 auto mDPtr = block_params->getDPtr();
914 auto coeff_expansion_ptr = block_params->getCoeffExpansionPtr();
917 "MAT_THERMAL", block_params, Sev::verbose);
920 post_proc_fe->getOpPtrVector(), {H1, HDIV});
922 auto mat_grad_ptr = boost::make_shared<MatrixDouble>();
923 auto mat_strain_ptr = boost::make_shared<MatrixDouble>();
924 auto mat_stress_ptr = boost::make_shared<MatrixDouble>();
926 auto vec_temp_ptr = boost::make_shared<VectorDouble>();
927 auto mat_flux_ptr = boost::make_shared<MatrixDouble>();
929 post_proc_fe->getOpPtrVector().push_back(
931 post_proc_fe->getOpPtrVector().push_back(
934 auto u_ptr = boost::make_shared<MatrixDouble>();
935 post_proc_fe->getOpPtrVector().push_back(
937 post_proc_fe->getOpPtrVector().push_back(
940 post_proc_fe->getOpPtrVector().push_back(
942 post_proc_fe->getOpPtrVector().push_back(
944 coeff_expansion_ptr, mat_stress_ptr));
948 post_proc_fe->getOpPtrVector().push_back(
952 post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
954 {{
"T", vec_temp_ptr}},
956 {{
"U", u_ptr}, {
"FLUX", mat_flux_ptr}},
960 {{
"STRAIN", mat_strain_ptr}, {
"STRESS", mat_stress_ptr}}
969 auto monitor_ptr = boost::make_shared<FEMethod>();
970 auto post_proc_fe = create_post_process_element();
972 auto set_time_monitor = [&](
auto dm,
auto solver) {
974 monitor_ptr->preProcessHook = [&]() {
979 monitor_ptr->getCacheWeakPtr());
980 CHKERR post_proc_fe->writeFile(
981 "out_" + boost::lexical_cast<std::string>(monitor_ptr->ts_step) +
987 ->evalFEAtThePoint3D(
988 fieldEvalCoords.data(), 1e-12,
simple->getProblemName(),
989 simple->getDomainFEName(), fieldEvalData,
990 mField.get_comm_rank(), mField.get_comm_rank(),
nullptr,
994 ->evalFEAtThePoint2D(
995 fieldEvalCoords.data(), 1e-12,
simple->getProblemName(),
996 simple->getDomainFEName(), fieldEvalData,
997 mField.get_comm_rank(), mField.get_comm_rank(),
nullptr,
1001 if (scalarFieldPtr->size()) {
1003 MOFEM_LOG(
"ThermoElasticSync", Sev::inform)
1004 <<
"Eval point T: " << t_temp;
1006 if (vectorFieldPtr->size1()) {
1008 auto t_disp = getFTensor1FromMat<SPACE_DIM>(*vectorFieldPtr);
1009 MOFEM_LOG(
"ThermoElasticSync", Sev::inform)
1010 <<
"Eval point U magnitude: " << sqrt(t_disp(
i) * t_disp(
i));
1012 if (tensorFieldPtr->size1()) {
1015 getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*tensorFieldPtr);
1016 MOFEM_LOG(
"ThermoElasticSync", Sev::inform)
1017 <<
"Eval point U_GRAD trace: " << t_disp_grad(
i,
i);
1025 auto null = boost::shared_ptr<FEMethod>();
1031 auto set_fieldsplit_preconditioner = [&](
auto solver) {
1035 CHKERR TSGetSNES(solver, &snes);
1037 CHKERR SNESGetKSP(snes, &ksp);
1039 CHKERR KSPGetPC(ksp, &pc);
1040 PetscBool is_pcfs = PETSC_FALSE;
1041 PetscObjectTypeCompare((PetscObject)pc, PCFIELDSPLIT, &is_pcfs);
1044 if (is_pcfs == PETSC_TRUE) {
1045 auto bc_mng = mField.getInterface<
BcManager>();
1047 auto name_prb =
simple->getProblemName();
1050 CHKERR is_mng->isCreateProblemFieldAndRank(name_prb,
ROW,
"U", 0,
1053 CHKERR is_mng->isCreateProblemFieldAndRank(name_prb,
ROW,
"FLUX", 0, 0,
1056 CHKERR is_mng->isCreateProblemFieldAndRank(name_prb,
ROW,
"T", 0, 0,
1059 CHKERR ISExpand(is_T, is_flux, &is_tmp);
1062 auto is_all_bc = bc_mng->getBlockIS(name_prb,
"HEATFLUX",
"FLUX", 0, 0);
1064 CHKERR ISGetSize(is_all_bc, &is_all_bc_size);
1066 <<
"Field split block size " << is_all_bc_size;
1067 if (is_all_bc_size) {
1069 CHKERR ISDifference(is_TFlux, is_all_bc, &is_tmp2);
1071 CHKERR PCFieldSplitSetIS(pc, PETSC_NULL,
1077 CHKERR PCFieldSplitSetIS(pc, PETSC_NULL, is_TFlux);
1078 CHKERR PCFieldSplitSetIS(pc, PETSC_NULL, is_u);
1086 CHKERR TSSetSolution(solver,
D);
1087 CHKERR TSSetFromOptions(solver);
1089 CHKERR set_section_monitor(solver);
1090 CHKERR set_fieldsplit_preconditioner(solver);
1091 CHKERR set_time_monitor(dm, solver);
1094 CHKERR TSSolve(solver, NULL);
1105 const char param_file[] =
"param_file.petsc";
1109 auto core_log = logging::core::get();
1123 DMType dm_name =
"DMMOFEM";