18#if PETSC_VERSION_GE(3, 6, 0)
19#include <petsc/private/dmimpl.h>
22#include <petsc-private/dmimpl.h>
23#include <petsc-private/vecimpl.h>
31 : mField_ptr(PETSC_NULL), isProblemBuild(PETSC_FALSE),
32 isPartitioned(PETSC_FALSE), isSquareMatrix(PETSC_TRUE),
33 isSubDM(PETSC_FALSE), isCompDM(PETSC_FALSE), destroyProblem(PETSC_FALSE),
34 verbosity(
VERBOSE), referenceNumber(0) {
37 auto core_log = logging::core::get();
55 *iface =
const_cast<DMCtx *
>(
this);
66 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
82 CHKERR DMSetMatType(dm, MATMPIAIJ);
88 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
90 dm->data =
new DMCtx();
96 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
97 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
101 CHKERR PetscObjectGetComm((PetscObject)dm, &comm);
104 MPI_Comm_compare(comm, PETSC_COMM_SELF, &result);
105 if (result == MPI_IDENT)
107 <<
"MoFEM DM destroy for problem " << dm_field->
problemName
111 <<
"MoFEM DM destroy for problem " << dm_field->
problemName
122 delete static_cast<DMCtx *
>(dm->data);
131 const char problem_name[],
136 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
139 "data structure for MoFEM not yet created");
143 "DM function not implemented into MoFEM");
161 boost::shared_ptr<KspCtx>(
new KspCtx(*m_field_ptr, problem_name));
163 boost::shared_ptr<SnesCtx>(
new SnesCtx(*m_field_ptr, problem_name));
165 boost::shared_ptr<TsCtx>(
new TsCtx(*m_field_ptr, problem_name));
168 CHKERR PetscObjectGetComm((PetscObject)dm, &comm);
170 MPI_Comm_compare(comm, m_field_ptr->
get_comm(), &result);
171 if (result > MPI_CONGRUENT) {
173 "MoFEM and DM using different communicators");
175 MPI_Comm_size(comm, &dm_field->
sIze);
176 MPI_Comm_rank(comm, &dm_field->
rAnk);
182 MPI_Comm_compare(comm, PETSC_COMM_SELF, &result);
183 if (result == MPI_IDENT) {
185 <<
"MoFEM DM created for problem " << dm_field->
problemName;
189 <<
"MoFEM DM created for problem " << dm_field->
problemName;
199 auto *dm_field =
static_cast<DMCtx *
>(dm->data);
202 "data structure for MoFEM not yet created");
205 delete static_cast<DMCtx *
>(dm_duplicate->data);
207 dm_duplicate->data = dm->data;
208 ++(
static_cast<DMCtx *
>(dm_duplicate->data)->referenceNumber);
216 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
219 "data structure for MoFEM not yet created");
226 subdm_field->
isSubDM = PETSC_TRUE;
237 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
239 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
242 "data structure for MoFEM not yet created");
248 if (lo_type != MBVERTEX || hi_type != MBMAXTYPE) {
251 std::map<std::string, std::pair<EntityType, EntityType>>>();
253 std::pair<EntityType, EntityType>(lo_type, hi_type);
260 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
262 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
265 "data structure for MoFEM not yet created");
271 if (lo_type != MBVERTEX || hi_type != MBMAXTYPE) {
274 std::map<std::string, std::pair<EntityType, EntityType>>>();
276 std::pair<EntityType, EntityType>(lo_type, hi_type);
283 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
285 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
286 *is_sub_dm = dm_field->
isSubDM;
292 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
294 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
295 if (dm_field->
isSubDM != PETSC_TRUE) {
297 "This DM is not created as a SubDM");
302 boost::shared_ptr<Problem::SubProblemData> sub_data =
304 CHKERR sub_data->getRowIs(is);
310 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
312 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
313 if (dm_field->
isSubDM != PETSC_TRUE) {
315 "This DM is not created as a SubDM");
320 boost::shared_ptr<Problem::SubProblemData> sub_data =
322 CHKERR sub_data->getColIs(is);
327 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
329 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
332 "data structure for MoFEM not yet created");
345 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
347 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
350 "data structure for MoFEM not yet created");
357 "No need to add problem on column when problem block structurally "
366 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
368 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
374 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
376 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
379 "data structure for MoFEM not yet created");
386 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
388 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
391 "data structure for MoFEM not yet created");
399 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
401 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
408 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
410 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
417 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
419 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
426 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
428 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
430 ->resolveSharedFiniteElements(dm_field->
problemPtr, fe_name);
439 PetscLayout *layout) {
441 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
443 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
446 CHKERR PetscObjectGetComm((PetscObject)dm, &comm);
455 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
457 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
463 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
465 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
473 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
475 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
483 ScatterMode scatter_mode) {
485 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
487 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
495 ScatterMode scatter_mode) {
496 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
498 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
506 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
508 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
516 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
518 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
530 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
532 dm_field->
problemPtr, fe_name, *method, low_rank, up_rank,
nullptr,
539 DM dm,
const std::string fe_name, boost::shared_ptr<MoFEM::FEMethod> method,
542 low_rank, up_rank, cache_ptr);
548 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
550 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
552 dm, fe_name, method, dm_field->
rAnk, dm_field->
rAnk, cache_ptr);
559 boost::shared_ptr<MoFEM::FEMethod> method,
566 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
568 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
571 *method, dm_field->
rAnk, dm_field->
rAnk);
576template <
class S,
class T0,
class T1,
class T2>
578 T1 pre_only, T2 post_only) {
579 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
581 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
583 dm_field->
kspCtx->get_preProcess_to_do_Rhs().push_back(pre_only);
586 dm_field->
kspCtx->get_loops_to_do_Rhs().push_back(
590 dm_field->
kspCtx->get_postProcess_to_do_Rhs().push_back(post_only);
602 dm, fe_name, method, pre_only, post_only);
607 boost::shared_ptr<MoFEM::FEMethod> method,
608 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
609 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
611 boost::shared_ptr<MoFEM::FEMethod>,
612 boost::shared_ptr<MoFEM::BasicMethod>,
613 boost::shared_ptr<MoFEM::BasicMethod>>(
614 dm, fe_name, method, pre_only, post_only);
617template <
class S,
class T0,
class T1,
class T2>
619 T1 pre_only, T2 post_only) {
620 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
622 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
624 dm_field->
kspCtx->get_preProcess_to_do_Mat().push_back(pre_only);
627 dm_field->
kspCtx->get_loops_to_do_Mat().push_back(
631 dm_field->
kspCtx->get_postProcess_to_do_Mat().push_back(post_only);
644 dm, fe_name, method, pre_only, post_only);
649 boost::shared_ptr<MoFEM::FEMethod> method,
650 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
651 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
653 boost::shared_ptr<MoFEM::FEMethod>>(
654 dm, fe_name, method, pre_only, post_only);
657template <
class S,
class T0,
class T1,
class T2>
659 T1 pre_only, T2 post_only) {
660 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
662 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
664 dm_field->
snesCtx->get_preProcess_to_do_Rhs().push_back(pre_only);
667 dm_field->
snesCtx->get_loops_to_do_Rhs().push_back(
671 dm_field->
snesCtx->get_postProcess_to_do_Rhs().push_back(post_only);
683 dm, fe_name, method, pre_only, post_only);
688 boost::shared_ptr<MoFEM::FEMethod> method,
689 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
690 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
692 boost::shared_ptr<MoFEM::FEMethod>,
693 boost::shared_ptr<MoFEM::BasicMethod>,
694 boost::shared_ptr<MoFEM::BasicMethod>>(
695 dm, fe_name, method, pre_only, post_only);
698template <
class S,
class T0,
class T1,
class T2>
700 T1 pre_only, T2 post_only) {
701 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
703 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
705 dm_field->
snesCtx->get_preProcess_to_do_Mat().push_back(pre_only);
708 dm_field->
snesCtx->get_loops_to_do_Mat().push_back(
712 dm_field->
snesCtx->get_postProcess_to_do_Mat().push_back(post_only);
724 dm, fe_name, method, pre_only, post_only);
729 boost::shared_ptr<MoFEM::FEMethod> method,
730 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
731 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
733 boost::shared_ptr<MoFEM::FEMethod>,
734 boost::shared_ptr<MoFEM::BasicMethod>,
735 boost::shared_ptr<MoFEM::BasicMethod>>(
736 dm, fe_name, method, pre_only, post_only);
739template <
class S,
class T0,
class T1,
class T2>
741 T1 pre_only, T2 post_only) {
742 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
744 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
746 dm_field->
tsCtx->getPreProcessIFunction().push_back(pre_only);
749 dm_field->
tsCtx->getLoopsIFunction().push_back(
753 dm_field->
tsCtx->getPostProcessIFunction().push_back(post_only);
765 dm, fe_name, method, pre_only, post_only);
771 boost::shared_ptr<MoFEM::FEMethod> method,
772 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
773 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
775 boost::shared_ptr<MoFEM::FEMethod>,
776 boost::shared_ptr<MoFEM::BasicMethod>,
777 boost::shared_ptr<MoFEM::BasicMethod>>(
778 dm, fe_name, method, pre_only, post_only);
782template <
class S,
class T0,
class T1,
class T2>
784 T1 pre_only, T2 post_only) {
785 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
787 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
789 dm_field->
tsCtx->getPreProcessIJacobian().push_back(pre_only);
792 dm_field->
tsCtx->getLoopsIJacobian().push_back(
796 dm_field->
tsCtx->getPostProcessIJacobian().push_back(post_only);
808 pre_only, post_only);
813 boost::shared_ptr<MoFEM::FEMethod> method,
814 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
815 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
817 boost::shared_ptr<MoFEM::FEMethod>,
818 boost::shared_ptr<MoFEM::BasicMethod>,
819 boost::shared_ptr<MoFEM::BasicMethod>>(
820 dm, fe_name, method, pre_only, post_only);
823template <
class S,
class T0,
class T1,
class T2>
825 T1 pre_only, T2 post_only) {
826 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
828 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
830 dm_field->
tsCtx->getPreProcessRHSFunction().push_back(pre_only);
832 dm_field->
tsCtx->getLoopsRHSFunction().push_back(
835 dm_field->
tsCtx->getPostProcessRHSFunction().push_back(post_only);
842 boost::shared_ptr<MoFEM::FEMethod> method,
843 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
844 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
846 boost::shared_ptr<MoFEM::FEMethod>,
847 boost::shared_ptr<MoFEM::BasicMethod>,
848 boost::shared_ptr<MoFEM::BasicMethod>>(
849 dm, fe_name, method, pre_only, post_only);
859 dm, fe_name, method, pre_only, post_only);
863template <
class S,
class T0,
class T1,
class T2>
865 T1 pre_only, T2 post_only) {
866 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
868 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
870 dm_field->
tsCtx->getPreProcessRHSFunction().push_back(pre_only);
872 dm_field->
tsCtx->getLoopsRHSFunction().push_back(
875 dm_field->
tsCtx->getPostProcessRHSFunction().push_back(post_only);
882 boost::shared_ptr<MoFEM::FEMethod> method,
883 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
884 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
886 boost::shared_ptr<MoFEM::FEMethod>,
887 boost::shared_ptr<MoFEM::BasicMethod>,
888 boost::shared_ptr<MoFEM::BasicMethod>>(
889 dm, fe_name, method, pre_only, post_only);
899 dm, fe_name, method, pre_only, post_only);
903template <
class S,
class T0,
class T1,
class T2>
905 T1 pre_only, T2 post_only) {
906 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
908 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
910 dm_field->
tsCtx->getPreProcessIFunction().push_back(pre_only);
913 dm_field->
tsCtx->getLoopsIFunction().push_back(
917 dm_field->
tsCtx->getPostProcessIFunction().push_back(post_only);
929 dm, fe_name, method, pre_only, post_only);
935 boost::shared_ptr<MoFEM::FEMethod> method,
936 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
937 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
939 boost::shared_ptr<MoFEM::FEMethod>,
940 boost::shared_ptr<MoFEM::BasicMethod>,
941 boost::shared_ptr<MoFEM::BasicMethod>>(
942 dm, fe_name, method, pre_only, post_only);
946template <
class S,
class T0,
class T1,
class T2>
948 T1 pre_only, T2 post_only) {
949 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
951 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
953 dm_field->
tsCtx->getPreProcessIJacobian().push_back(pre_only);
956 dm_field->
tsCtx->getLoopsIJacobian().push_back(
960 dm_field->
tsCtx->getPostProcessIJacobian().push_back(post_only);
972 pre_only, post_only);
977 boost::shared_ptr<MoFEM::FEMethod> method,
978 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
979 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
981 boost::shared_ptr<MoFEM::FEMethod>,
982 boost::shared_ptr<MoFEM::BasicMethod>,
983 boost::shared_ptr<MoFEM::BasicMethod>>(
984 dm, fe_name, method, pre_only, post_only);
987template <
class S,
class T0,
class T1,
class T2>
989 T1 pre_only, T2 post_only) {
990 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
992 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
994 dm_field->
tsCtx->getPreProcessMonitor().push_back(pre_only);
996 dm_field->
tsCtx->getLoopsMonitor().push_back(
999 dm_field->
tsCtx->getPostProcessMonitor().push_back(post_only);
1010 dm, ts, fe_name, method, pre_only, post_only);
1016 boost::shared_ptr<MoFEM::FEMethod> method,
1017 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
1018 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
1020 boost::shared_ptr<MoFEM::FEMethod>,
1021 boost::shared_ptr<MoFEM::BasicMethod>,
1022 boost::shared_ptr<MoFEM::BasicMethod>>(
1023 dm, ts, fe_name, method, pre_only, post_only);
1028 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1030 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1031 *ksp_ctx = dm_field->
kspCtx.get();
1037 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1039 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1040 const_cast<boost::shared_ptr<MoFEM::KspCtx> &
>(ksp_ctx) = dm_field->
kspCtx;
1045 boost::shared_ptr<MoFEM::KspCtx> ksp_ctx) {
1046 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1048 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1049 dm_field->
kspCtx = ksp_ctx;
1054 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1057 *snes_ctx = dm_field->
snesCtx.get();
1063 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1065 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1066 const_cast<boost::shared_ptr<MoFEM::SnesCtx> &
>(snes_ctx) = dm_field->
snesCtx;
1071 boost::shared_ptr<MoFEM::SnesCtx> snes_ctx) {
1072 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1074 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1083 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1085 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1094 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1096 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1102 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1104 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1105 *ts_ctx = dm_field->
tsCtx.get();
1110 const boost::shared_ptr<MoFEM::TsCtx> &ts_ctx) {
1111 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1113 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1114 const_cast<boost::shared_ptr<MoFEM::TsCtx> &
>(ts_ctx) = dm_field->
tsCtx;
1119 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1121 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1122 dm_field->
tsCtx = ts_ctx;
1127 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1129 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1137 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1139 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1142 CHKERR VecSetDM(g_ptr, dm);
1147 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1149 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1157 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1159 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1160 if (strcmp(dm->mattype, MATMPIAIJ) == 0) {
1162 ->createMPIAIJWithArrays<PetscGlobalIdx_mi_tag>(dm_field->
problemName,
1164 }
else if (strcmp(dm->mattype, MATAIJ) == 0) {
1166 ->createSeqAIJWithArrays<PetscLocalIdx_mi_tag>(dm_field->
problemName,
1170 "Matrix type not implemented");
1177 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1179 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1180 if (strcmp(dm->mattype, MATMPIAIJ) == 0) {
1182 ->createMPIAIJWithArrays<PetscGlobalIdx_mi_tag>(dm_field->
problemName,
1184 }
else if (strcmp(dm->mattype, MATAIJ) == 0) {
1186 ->createSeqAIJWithArrays<PetscLocalIdx_mi_tag>(dm_field->
problemName,
1190 "Matrix type not implemented");
1196#if PETSC_VERSION_GE(3, 7, 0)
1199#elif PETSC_VERSION_GE(3, 5, 3)
1205 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1207 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1208#if PETSC_VERSION_GE(3, 5, 3)
1209 ierr = PetscOptionsHead(PetscOptionsObject,
"DMMoFEM Options");
1212 ierr = PetscOptionsHead(
"DMMoFEM Options");
1215 ierr = PetscOptionsBool(
"-dm_is_partitioned",
1216 "set if mesh is partitioned (works which native MOAB "
1217 "file format, i.e. h5m",
1225 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1228 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1272 PetscValidHeaderSpecific(subdm, DM_CLASSID, 1);
1276 DMCtx *subdm_field =
static_cast<DMCtx *
>(subdm->data);
1281 map<std::string, std::pair<EntityType, EntityType>> *entity_map_row =
nullptr;
1282 map<std::string, std::pair<EntityType, EntityType>> *entity_map_col =
nullptr;
1285 entity_map_row = subdm_field->
mapTypeRow.get();
1287 entity_map_row = subdm_field->
mapTypeCol.get();
1292 subdm_field->
isSquareMatrix == PETSC_TRUE, entity_map_row, entity_map_col,
1299 0, subdm_field->
sIze,
1320 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1322 CHKERR VecGhostUpdateBegin(
g, INSERT_VALUES, SCATTER_FORWARD);
1328 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1331 CHKERR VecGhostUpdateEnd(
g, INSERT_VALUES, SCATTER_FORWARD);
1333 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1337 double *array_loc, *array_glob;
1338 CHKERR VecGetArray(
l, &array_loc);
1339 CHKERR VecGetArray(
g, &array_glob);
1342 cblas_dcopy(nb_dofs + nb_ghost, array_glob, 1, array_loc, 1);
1345 cblas_daxpy(nb_dofs + nb_ghost, 1, array_glob, 1, array_loc, 1);
1350 CHKERR VecRestoreArray(
l, &array_loc);
1351 CHKERR VecRestoreArray(
g, &array_glob);
1358 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1361 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1365 double *array_loc, *array_glob;
1366 CHKERR VecGetArray(
l, &array_loc);
1367 CHKERR VecGetArray(
g, &array_glob);
1370 cblas_dcopy(nb_dofs + nb_ghost, array_loc, 1, array_glob, 1);
1373 cblas_daxpy(nb_dofs + nb_ghost, 1, array_loc, 1, array_glob, 1);
1378 CHKERR VecRestoreArray(
l, &array_loc);
1379 CHKERR VecRestoreArray(
g, &array_glob);
1391 char ***fieldNames, IS **fields) {
1392 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1405 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1407 Field_multiIndex::iterator fit, hi_fit;
1408 fit = fields_ptr->begin();
1409 hi_fit = fields_ptr->end();
1410 *numFields = std::distance(fit, hi_fit);
1413 CHKERR PetscMalloc1(*numFields, fieldNames);
1416 CHKERR PetscMalloc1(*numFields, fields);
1419 for (
int f = 0; fit != hi_fit; fit++,
f++) {
1421 CHKERR PetscStrallocpy(fit->get()->getName().c_str(),
1422 (
char **)&(*fieldNames)[
f]);
1426 ->isCreateProblemFieldAndRank(
1428 fit->get()->getNbOfCoeffs(), &(*fields)[
f]);
1437 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1439 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
1447 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1449 DMCtx *dm_field =
static_cast<DMCtx *
>(dm->data);
Discrete manager interface for MoFEM.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
PetscErrorCode DMGlobalToLocalBegin_MoFEM(DM dm, Vec, InsertMode, Vec)
PetscErrorCode DMGlobalToLocalEnd_MoFEM(DM dm, Vec, InsertMode, Vec)
PetscErrorCode DMMoFEMResolveSharedFiniteElements(DM dm, const char fe_name[])
Resolve shared entities.
PetscErrorCode DMMoFEMSetIsPartitioned(DM dm, PetscBool is_partitioned)
PetscErrorCode DMMoFEMCreateSubDM(DM subdm, DM dm, const char problem_name[])
Must be called by user to set Sub DM MoFEM data structures.
PetscErrorCode DMMoFEMGetIsPartitioned(DM dm, PetscBool *is_partitioned)
PetscErrorCode DMMoFEMGetProblemFiniteElementLayout(DM dm, const char fe_name[], PetscLayout *layout)
Get finite elements layout in the problem.
PetscErrorCode DMMoFEMSNESSetFunction(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set SNES residual evaluation function
PetscErrorCode DMCreateLocalVector_MoFEM(DM dm, Vec *l)
DMShellSetCreateLocalVector.
PetscErrorCode DMMoFEMSetSquareProblem(DM dm, PetscBool square_problem)
set squared problem
PetscErrorCode DMMoFEMTSSetIFunction(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set TS implicit function evaluation function
PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, const char field_name[], EntityType lo_type=MBVERTEX, EntityType hi_type=MBMAXTYPE)
PetscErrorCode DMDestroy_MoFEM(DM dm)
Destroys dm with MoFEM data structure.
PetscErrorCode DMMoFEMCreateMoFEM(DM dm, MoFEM::Interface *m_field_ptr, const char problem_name[], const MoFEM::BitRefLevel bit_level, const MoFEM::BitRefLevel bit_mask=MoFEM::BitRefLevel().set())
Must be called by user to set MoFEM data structures.
PetscErrorCode DMMoFEMAddElement(DM dm, const char fe_name[])
add element to dm
PetscErrorCode DMoFEMPostProcessFiniteElements(DM dm, MoFEM::FEMethod *method)
execute finite element method for each element in dm (problem)
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
PetscErrorCode DMMoFEMAddColCompositeProblem(DM dm, const char prb_name[])
Add problem to composite DM on col.
PetscErrorCode DMLocalToGlobalBegin_MoFEM(DM, Vec, InsertMode, Vec)
PetscErrorCode DMMoFEMGetProblemPtr(DM dm, const MoFEM::Problem **problem_ptr)
Get pointer to problem data structure.
PetscErrorCode DMCreate_MoFEM(DM dm)
Create dm data structure with MoFEM data structure.
PetscErrorCode DMMoFEMSetSnesCtx(DM dm, boost::shared_ptr< MoFEM::SnesCtx > snes_ctx)
Set MoFEM::SnesCtx data structure.
PetscErrorCode DMMoFEMSetKspCtx(DM dm, boost::shared_ptr< MoFEM::KspCtx > ksp_ctx)
set MoFEM::KspCtx data structure
PetscErrorCode DMMoFEMGetIsSubDM(DM dm, PetscBool *is_sub_dm)
PetscErrorCode DMMoFEMAddRowCompositeProblem(DM dm, const char prb_name[])
Add problem to composite DM on row.
PetscErrorCode DMMoFEMSNESSetJacobian(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set SNES Jacobian evaluation function
PetscErrorCode DMCreateMatrix_MoFEM(DM dm, Mat *M)
PetscErrorCode DMSetFromOptions_MoFEM(DM dm)
PetscErrorCode DMMoFEMGetTsCtx(DM dm, MoFEM::TsCtx **ts_ctx)
get MoFEM::TsCtx data structure
PetscErrorCode DMMoFEMAddSubFieldCol(DM dm, const char field_name[], EntityType lo_type=MBVERTEX, EntityType hi_type=MBMAXTYPE)
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
PetscErrorCode DMMoFEMUnSetElement(DM dm, const char fe_name[])
unset element from dm
PetscErrorCode DMMoFEMGetKspCtx(DM dm, MoFEM::KspCtx **ksp_ctx)
get MoFEM::KspCtx data structure
PetscErrorCode DMMoFEMGetSquareProblem(DM dm, PetscBool *square_problem)
get squared problem
PetscErrorCode DMoFEMLoopDofs(DM dm, const char field_name[], MoFEM::DofMethod *method)
execute method for dofs on field in problem
PetscErrorCode DMMoFEMKSPSetComputeRHS(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set KSP right hand side evaluation function
PetscErrorCode DMMoFEMSetTsCtx(DM dm, boost::shared_ptr< MoFEM::TsCtx > ts_ctx)
Set MoFEM::TsCtx data structure.
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
PetscErrorCode DMMoFEMGetFieldIS(DM dm, RowColData rc, const char field_name[], IS *is)
get field is in the problem
PetscErrorCode DMMoFEMTSSetIJacobian(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS Jacobian evaluation function
PetscErrorCode DMoFEMGetInterfacePtr(DM dm, MoFEM::Interface **m_field_ptr)
Get pointer to MoFEM::Interface.
PetscErrorCode DMMoFEMTSSetI2Jacobian(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS Jacobian evaluation function
PetscErrorCode DMMoFEMTSSetI2Function(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS implicit function evaluation function
PetscErrorCode DMCreateGlobalVector_MoFEM(DM dm, Vec *g)
DMShellSetCreateGlobalVector.
PetscErrorCode DMMoFEMGetSnesCtx(DM dm, MoFEM::SnesCtx **snes_ctx)
get MoFEM::SnesCtx data structure
PetscErrorCode DMoFEMMeshToGlobalVector(DM dm, Vec g, InsertMode mode, ScatterMode scatter_mode)
set ghosted vector values on all existing mesh entities
PetscErrorCode DMMoFEMGetIsCompDM(DM dm, PetscBool *is_comp_dm)
Get if this DM is composite DM.
PetscErrorCode DMSubDMSetUp_MoFEM(DM subdm)
PetscErrorCode DMMoFEMKSPSetComputeOperators(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
Set KSP operators and push mofem finite element methods.
PetscErrorCode DMCreateFieldIS_MoFEM(DM dm, PetscInt *numFields, char ***fieldNames, IS **fields)
PetscErrorCode DMSetUp_MoFEM(DM dm)
PetscErrorCode DMLocalToGlobalEnd_MoFEM(DM, Vec, InsertMode, Vec)
PetscErrorCode DMoFEMLoopFiniteElementsUpAndLowRank(DM dm, const char fe_name[], MoFEM::FEMethod *method, int low_rank, int up_rank, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
PetscErrorCode DMoFEMPreProcessFiniteElements(DM dm, MoFEM::FEMethod *method)
execute finite element method for each element in dm (problem)
PetscErrorCode DMSetOperators_MoFEM(DM dm)
Set operators for MoFEM dm.
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
virtual const Field_multiIndex * get_fields() const =0
Get the fields object.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
virtual MoFEMErrorCode loop_dofs(const Problem *problem_ptr, const std::string &field_name, RowColData rc, DofMethod &method, int lower_rank, int upper_rank, int verb=DEFAULT_VERBOSITY)=0
Make a loop over dofs.
virtual MoFEMErrorCode problem_basic_method_postProcess(const Problem *problem_ptr, BasicMethod &method, int verb=DEFAULT_VERBOSITY)=0
Set data for BasicMethod.
virtual MoFEMErrorCode loop_finite_elements(const std::string &problem_name, const std::string &fe_name, FEMethod &method, boost::shared_ptr< NumeredEntFiniteElement_multiIndex > fe_ptr=nullptr, MoFEMTypes bh=MF_EXIST, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr(), int verb=DEFAULT_VERBOSITY)=0
Make a loop over finite elements.
MoFEMErrorCode buildProblemOnDistributedMesh(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures, assuming that mesh is distributed (collective)
MoFEMErrorCode partitionGhostDofs(const std::string name, int verb=VERBOSE)
determine ghost nodes
MoFEMErrorCode buildComposedProblem(const std::string out_name, const std::vector< std::string > add_row_problems, const std::vector< std::string > add_col_problems, const bool square_matrix=true, int verb=1)
build composite problem
MoFEMErrorCode buildSubProblem(const std::string out_name, const std::vector< std::string > &fields_row, const std::vector< std::string > &fields_col, const std::string main_problem, const bool square_matrix=true, const map< std::string, std::pair< EntityType, EntityType > > *entityMapRow=nullptr, const map< std::string, std::pair< EntityType, EntityType > > *entityMapCol=nullptr, int verb=VERBOSE)
build sub problem
MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
MoFEMErrorCode partitionProblem(const std::string name, int verb=VERBOSE)
partition problem dofs (collective)
MoFEMErrorCode partitionGhostDofsOnDistributedMesh(const std::string name, int verb=VERBOSE)
determine ghost nodes on distributed meshes
MoFEMErrorCode partitionFiniteElements(const std::string name, bool part_from_moab=false, int low_proc=-1, int hi_proc=-1, int verb=VERBOSE)
partition finite elements
virtual MoFEMErrorCode modify_problem_unset_finite_element(const std::string &name_problem, const std::string &fe_name)=0
unset finite element from problem, this remove entities assigned to finite element to a particular pr...
virtual MoFEMErrorCode modify_problem_add_finite_element(const std::string &name_problem, const std::string &fe_name)=0
add finite element to problem, this add entities assigned to finite element to a particular problem
virtual MoFEMErrorCode add_problem(const std::string &name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add problem.
virtual MoFEMErrorCode delete_problem(const std::string name)=0
Delete problem.
virtual MoFEMErrorCode modify_problem_ref_level_add_bit(const std::string &name_problem, const BitRefLevel &bit)=0
add ref level to problem
virtual bool check_problem(const std::string name)=0
check if problem exist
virtual MoFEMErrorCode modify_problem_mask_ref_level_add_bit(const std::string &name_problem, const BitRefLevel &bit)=0
set dof mask ref level for problem
FTensor::Index< 'l', 3 > l
const FTensor::Tensor2< T, Dim, Dim > Vec
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
implementation of Data Operators for Forces and Sources
PetscErrorCode DMMoFEMTSSetMonitor(DM dm, TS ts, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
Set Monitor To TS solver.
PetscErrorCode TsSetIJacobian(TS ts, PetscReal t, Vec u, Vec u_t, PetscReal a, Mat A, Mat B, void *ctx)
Set function evaluating jacobina in TS solver.
PetscErrorCode TsMonitorSet(TS ts, PetscInt step, PetscReal t, Vec u, void *ctx)
Set monitor for TS solver.
PetscErrorCode DMMoFEMTSSetRHSFunction(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS the right hand side function
PetscErrorCode SnesMat(SNES snes, Vec x, Mat A, Mat B, void *ctx)
This is MoFEM implementation for the left hand side (tangent matrix) evaluation in SNES solver.
PetscErrorCode DMMoFEMSetDestroyProblem(DM dm, PetscBool destroy_problem)
PetscErrorCode DMMoFEMGetDestroyProblem(DM dm, PetscBool *destroy_problem)
PetscErrorCode TsSetI2Function(TS ts, PetscReal t, Vec u, Vec u_t, Vec u_tt, Vec F, void *ctx)
Calculation the right hand side for second order PDE in time.
PetscErrorCode TsSetRHSFunction(TS ts, PetscReal t, Vec u, Vec F, void *ctx)
TS solver function.
PetscErrorCode SnesRhs(SNES snes, Vec x, Vec f, void *ctx)
This is MoFEM implementation for the right hand side (residual vector) evaluation in SNES solver.
PetscErrorCode DMMoFEMGetSubRowIS(DM dm, IS *is)
get sub problem is
PetscErrorCode TsSetIFunction(TS ts, PetscReal t, Vec u, Vec u_t, Vec F, void *ctx)
Set IFunction for TS solver.
PetscErrorCode DMMoFEMGetSubColIS(DM dm, IS *is)
get sub problem is
PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx)
Run over elements in the lists.
PetscErrorCode TsSetI2Jacobian(TS ts, PetscReal t, Vec u, Vec u_t, Vec u_tt, PetscReal a, PetscReal aa, Mat A, Mat B, void *ctx)
Calculation Jaconian for second order PDE in time.
PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx)
Run over elenents in the list.
PetscErrorCode TsSetRHSJacobian(TS ts, PetscReal t, Vec u, Mat A, Mat B, void *ctx)
TS solver function.
PetscErrorCode DMMoFEMTSSetRHSJacobian(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS the right hand side jacobian
PetscErrorCode DMMoFEMSetVerbosity(DM dm, const int verb)
Set verbosity level.
PetscErrorCode DMMoFEMDuplicateDMCtx(DM dm, DM dm_duplicate)
Duplicate internal data struture.
DEPRECATED PetscErrorCode DMMoFEMResolveSharedEntities(DM dm, const char fe_name[])
boost::weak_ptr< CacheTuple > CacheTupleWeakPtr
constexpr auto field_name
Data structure to exchange data between mofem and User Loop Methods.
virtual MoFEMErrorCode problem_basic_method_preProcess(const Problem *problem_ptr, BasicMethod &method, int verb=DEFAULT_VERBOSITY)=0
Set data for BasicMethod.
virtual MPI_Comm & get_comm() const =0
PETSc Discrete Manager data structure.
std::string problemName
Problem name.
const Problem * problemPtr
pinter to problem data structure
std::vector< std::string > rowCompPrb
boost::shared_ptr< SnesCtx > snesCtx
data structure SNES
boost::shared_ptr< TsCtx > tsCtx
data structure for TS solver
PetscBool isSquareMatrix
true if rows equals to cols
PetscBool isPartitioned
true if read mesh is on parts
PetscBool isProblemBuild
True if problem is build.
Interface * mField_ptr
MoFEM interface.
boost::shared_ptr< KspCtx > kspCtx
data structure KSP
boost::shared_ptr< std::map< std::string, std::pair< EntityType, EntityType > > > mapTypeRow
std::vector< std::string > colCompPrb
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
std::vector< std::string > colFields
PetscBool destroyProblem
If true destroy problem with DM.
std::vector< std::string > rowFields
const Problem * problemMainOfSubPtr
pinter to main problem to sub-problem
boost::shared_ptr< std::map< std::string, std::pair< EntityType, EntityType > > > mapTypeCol
Deprecated interface functions.
Data structure to exchange data between mofem and User Loop Methods on entities.
structure for User Loop Methods on finite elements
Section manager is used to create indexes and sections.
Interface for linear (KSP) solver.
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
static boost::shared_ptr< std::ostream > getStrmWorld()
Get the strm world object.
static boost::shared_ptr< std::ostream > getStrmSync()
Get the strm sync object.
static bool checkIfChannelExist(const std::string channel)
Check if channel exist.
static boost::shared_ptr< std::ostream > getStrmSelf()
Get the strm self object.
Matrix manager is used to build and partition problems.
keeps basic data about problem
DofIdx getNbLocalDofsRow() const
MoFEMErrorCode getNumberOfElementsByNameAndPart(MPI_Comm comm, const std::string name, PetscLayout *layout) const
Get number of finite elements by name on processors.
BitRefLevel getBitRefLevel() const
BitRefLevel getBitRefLevelMask() const
boost::shared_ptr< SubProblemData > & getSubData() const
Get main problem of sub-problem is.
DofIdx getNbGhostDofsRow() const
Problem manager is used to build and partition problems.
Interface for nonlinear (SNES) solver.
Interface for Time Stepping (TS) solver.
base class for all interface classes
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Vector manager is used to create vectors \mofem_vectors.