6#if PETSC_VERSION_GE(3, 6, 0)
7#include <petsc/private/dmimpl.h>
10#include <petsc-private/dmimpl.h>
11#include <petsc-private/vecimpl.h>
21 *iface =
const_cast<DMCtx *
>(
this);
27 auto core_log = logging::core::get();
50 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
66 CHKERR DMSetMatType(dm, MATMPIAIJ);
72 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
80 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
83 auto *dm_field =
static_cast<DMCtxImpl *
>(dm->data);
90 CHKERR dm_field->tsCtx->clearLoops();
91 if (dm_field->snesCtx)
92 CHKERR dm_field->snesCtx->clearLoops();
94 CHKERR dm_field->kspCtx->clearLoops();
96 dm_field->nestedSchurDataPtr.reset();
97 dm_field->blocMatDataPtr.reset();
98 dm_field->tsCtx.reset();
99 dm_field->snesCtx.reset();
100 dm_field->kspCtx.reset();
106 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
111 CHKERR PetscObjectGetComm((PetscObject)dm, &
comm);
114 MPI_Comm_compare(
comm, PETSC_COMM_SELF, &result);
115 if (result == MPI_IDENT)
117 <<
"MoFEM DM destroy for problem " << dm_field->
problemName
121 <<
"MoFEM DM destroy for problem " << dm_field->
problemName
134 delete static_cast<DMCtxImpl *
>(dm->data);
144 const char problem_name[],
152 "data structure for MoFEM not yet created");
156 "DM function not implemented into MoFEM");
174 boost::shared_ptr<KspCtx>(
new KspCtx(*m_field_ptr, problem_name));
176 boost::shared_ptr<SnesCtx>(
new SnesCtx(*m_field_ptr, problem_name));
178 boost::shared_ptr<TsCtx>(
new TsCtx(*m_field_ptr, problem_name));
181 CHKERR PetscObjectGetComm((PetscObject)dm, &
comm);
183 MPI_Comm_compare(
comm, m_field_ptr->
get_comm(), &result);
184 if (result > MPI_CONGRUENT) {
186 "MoFEM and DM using different communicators");
188 MPI_Comm_size(
comm, &dm_field->
sIze);
189 MPI_Comm_rank(
comm, &dm_field->
rAnk);
195 MPI_Comm_compare(
comm, PETSC_COMM_SELF, &result);
196 if (result == MPI_IDENT) {
198 <<
"MoFEM DM created for problem " << dm_field->
problemName;
202 <<
"MoFEM DM created for problem " << dm_field->
problemName;
214 "data structure for MoFEM not yet created");
217 delete static_cast<DMCtxImpl *
>(dm_duplicate->data);
219 dm_duplicate->data = dm->data;
220 ++(
static_cast<DMCtxImpl *
>(dm_duplicate->data)->referenceNumber);
229 "data structure for MoFEM not yet created on dm");
232 "data structure for MoFEM not yet created on swap dm");
234 auto *dm_field =
static_cast<DMCtxImpl *
>(dm->data);
235 auto *dm_field_swap =
static_cast<DMCtxImpl *
>(dm_swap->data);
237 auto tmp_field = dm_field;
238 dm_field = dm_field_swap;
239 dm_field_swap = tmp_field;
249 "data structure for MoFEM not yet created");
258 subdm_field->
isSubDM = PETSC_TRUE;
268 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
273 "data structure for MoFEM not yet created");
288 boost::shared_ptr<Range> r_ptr) {
289 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
294 "data structure for MoFEM not yet created");
305 boost::shared_ptr<Range> r_ptr) {
310 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
315 "data structure for MoFEM not yet created");
330 boost::shared_ptr<Range> r_ptr) {
331 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
336 "data structure for MoFEM not yet created");
347 boost::shared_ptr<Range> r_ptr) {
352 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
355 *is_sub_dm = dm_field->
isSubDM;
360 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
363 if (dm_field->
isSubDM != PETSC_TRUE) {
365 "This DM is not created as a SubDM");
370 boost::shared_ptr<Problem::SubProblemData> sub_data =
372 CHKERR sub_data->getRowIs(is);
377 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
380 if (dm_field->
isSubDM != PETSC_TRUE) {
382 "This DM is not created as a SubDM");
387 boost::shared_ptr<Problem::SubProblemData> sub_data =
389 CHKERR sub_data->getColIs(is);
394 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
399 "data structure for MoFEM not yet created");
412 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
417 "data structure for MoFEM not yet created");
424 "No need to add problem on column when problem block structurally "
432 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
440 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
445 "data structure for MoFEM not yet created");
452 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
457 "data structure for MoFEM not yet created");
464 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
472 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
480 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
488 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
492 ->resolveSharedFiniteElements(dm_field->
problemPtr, fe_name);
497 PetscLayout *layout) {
498 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
503 CHKERR PetscObjectGetComm((PetscObject)dm, &
comm);
510 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
518 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
528 for (
auto fe : fe_name) {
535 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
544 ScatterMode scatter_mode,
546 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
555 ScatterMode scatter_mode,
557 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
566 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
576 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
592 dm_field->
problemPtr, fe_name, *method, low_rank, up_rank,
nullptr,
599 DM dm,
const std::string fe_name, boost::shared_ptr<MoFEM::FEMethod> method,
602 low_rank, up_rank, cache_ptr);
608 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
612 dm, fe_name, method, dm_field->
rAnk, dm_field->
rAnk, cache_ptr);
619 boost::shared_ptr<MoFEM::FEMethod> method,
626 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
631 *method, dm_field->
rAnk, dm_field->
rAnk);
636template <
class S,
class T0,
class T1,
class T2>
638 T1 pre_only, T2 post_only) {
639 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
643 dm_field->
kspCtx->getPreProcComputeRhs().push_back(pre_only);
646 dm_field->
kspCtx->getComputeRhs().push_back(
650 dm_field->
kspCtx->getPostProcComputeRhs().push_back(post_only);
662 dm, fe_name, method, pre_only, post_only);
667 boost::shared_ptr<MoFEM::FEMethod> method,
668 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
669 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
671 boost::shared_ptr<MoFEM::FEMethod>,
672 boost::shared_ptr<MoFEM::BasicMethod>,
673 boost::shared_ptr<MoFEM::BasicMethod>>(
674 dm, fe_name, method, pre_only, post_only);
677template <
class S,
class T0,
class T1,
class T2>
679 T1 pre_only, T2 post_only) {
680 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
684 dm_field->
kspCtx->getPreProcSetOperators().push_back(pre_only);
687 dm_field->
kspCtx->getSetOperators().push_back(
691 dm_field->
kspCtx->getPostProcSetOperators().push_back(post_only);
704 dm, fe_name, method, pre_only, post_only);
709 boost::shared_ptr<MoFEM::FEMethod> method,
710 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
711 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
713 boost::shared_ptr<MoFEM::FEMethod>>(
714 dm, fe_name, method, pre_only, post_only);
717template <
class S,
class T0,
class T1,
class T2>
719 T1 pre_only, T2 post_only) {
720 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
724 dm_field->
snesCtx->getPreProcComputeRhs().push_back(pre_only);
727 dm_field->
snesCtx->getComputeRhs().push_back(
731 dm_field->
snesCtx->getPostProcComputeRhs().push_back(post_only);
743 dm, fe_name, method, pre_only, post_only);
748 boost::shared_ptr<MoFEM::FEMethod> method,
749 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
750 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
752 boost::shared_ptr<MoFEM::FEMethod>,
753 boost::shared_ptr<MoFEM::BasicMethod>,
754 boost::shared_ptr<MoFEM::BasicMethod>>(
755 dm, fe_name, method, pre_only, post_only);
758template <
class S,
class T0,
class T1,
class T2>
760 T1 pre_only, T2 post_only) {
761 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
765 dm_field->
snesCtx->getPreProcSetOperators().push_back(pre_only);
768 dm_field->
snesCtx->getSetOperators().push_back(
772 dm_field->
snesCtx->getPostProcSetOperators().push_back(post_only);
784 dm, fe_name, method, pre_only, post_only);
789 boost::shared_ptr<MoFEM::FEMethod> method,
790 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
791 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
793 boost::shared_ptr<MoFEM::FEMethod>,
794 boost::shared_ptr<MoFEM::BasicMethod>,
795 boost::shared_ptr<MoFEM::BasicMethod>>(
796 dm, fe_name, method, pre_only, post_only);
799template <
class S,
class T0,
class T1,
class T2>
801 T1 pre_only, T2 post_only) {
802 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
806 dm_field->
tsCtx->getPreProcessIFunction().push_back(pre_only);
809 dm_field->
tsCtx->getLoopsIFunction().push_back(
813 dm_field->
tsCtx->getPostProcessIFunction().push_back(post_only);
825 dm, fe_name, method, pre_only, post_only);
831 boost::shared_ptr<MoFEM::FEMethod> method,
832 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
833 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
835 boost::shared_ptr<MoFEM::FEMethod>,
836 boost::shared_ptr<MoFEM::BasicMethod>,
837 boost::shared_ptr<MoFEM::BasicMethod>>(
838 dm, fe_name, method, pre_only, post_only);
842template <
class S,
class T0,
class T1,
class T2>
844 T1 pre_only, T2 post_only) {
845 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
849 dm_field->
tsCtx->getPreProcessIJacobian().push_back(pre_only);
852 dm_field->
tsCtx->getLoopsIJacobian().push_back(
856 dm_field->
tsCtx->getPostProcessIJacobian().push_back(post_only);
868 pre_only, post_only);
873 boost::shared_ptr<MoFEM::FEMethod> method,
874 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
875 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
877 boost::shared_ptr<MoFEM::FEMethod>,
878 boost::shared_ptr<MoFEM::BasicMethod>,
879 boost::shared_ptr<MoFEM::BasicMethod>>(
880 dm, fe_name, method, pre_only, post_only);
883template <
class S,
class T0,
class T1,
class T2>
885 T1 pre_only, T2 post_only) {
886 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
890 dm_field->
tsCtx->getPreProcessRHSFunction().push_back(pre_only);
892 dm_field->
tsCtx->getLoopsRHSFunction().push_back(
895 dm_field->
tsCtx->getPostProcessRHSFunction().push_back(post_only);
902 boost::shared_ptr<MoFEM::FEMethod> method,
903 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
904 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
906 boost::shared_ptr<MoFEM::FEMethod>,
907 boost::shared_ptr<MoFEM::BasicMethod>,
908 boost::shared_ptr<MoFEM::BasicMethod>>(
909 dm, fe_name, method, pre_only, post_only);
919 dm, fe_name, method, pre_only, post_only);
923template <
class S,
class T0,
class T1,
class T2>
925 T1 pre_only, T2 post_only) {
926 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
930 dm_field->
tsCtx->getPreProcessRHSFunction().push_back(pre_only);
932 dm_field->
tsCtx->getLoopsRHSFunction().push_back(
935 dm_field->
tsCtx->getPostProcessRHSFunction().push_back(post_only);
942 boost::shared_ptr<MoFEM::FEMethod> method,
943 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
944 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
946 boost::shared_ptr<MoFEM::FEMethod>,
947 boost::shared_ptr<MoFEM::BasicMethod>,
948 boost::shared_ptr<MoFEM::BasicMethod>>(
949 dm, fe_name, method, pre_only, post_only);
959 dm, fe_name, method, pre_only, post_only);
963template <
class S,
class T0,
class T1,
class T2>
965 T1 pre_only, T2 post_only) {
966 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
970 dm_field->
tsCtx->getPreProcessIFunction().push_back(pre_only);
973 dm_field->
tsCtx->getLoopsIFunction().push_back(
977 dm_field->
tsCtx->getPostProcessIFunction().push_back(post_only);
989 dm, fe_name, method, pre_only, post_only);
995 boost::shared_ptr<MoFEM::FEMethod> method,
996 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
997 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
999 boost::shared_ptr<MoFEM::FEMethod>,
1000 boost::shared_ptr<MoFEM::BasicMethod>,
1001 boost::shared_ptr<MoFEM::BasicMethod>>(
1002 dm, fe_name, method, pre_only, post_only);
1006template <
class S,
class T0,
class T1,
class T2>
1008 T1 pre_only, T2 post_only) {
1009 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1013 dm_field->
tsCtx->getPreProcessIJacobian().push_back(pre_only);
1016 dm_field->
tsCtx->getLoopsIJacobian().push_back(
1020 dm_field->
tsCtx->getPostProcessIJacobian().push_back(post_only);
1032 pre_only, post_only);
1037 boost::shared_ptr<MoFEM::FEMethod> method,
1038 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
1039 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
1041 boost::shared_ptr<MoFEM::FEMethod>,
1042 boost::shared_ptr<MoFEM::BasicMethod>,
1043 boost::shared_ptr<MoFEM::BasicMethod>>(
1044 dm, fe_name, method, pre_only, post_only);
1047template <
class S,
class T0,
class T1,
class T2>
1049 T1 pre_only, T2 post_only) {
1050 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1054 dm_field->
tsCtx->getPreProcessMonitor().push_back(pre_only);
1056 dm_field->
tsCtx->getLoopsMonitor().push_back(
1059 dm_field->
tsCtx->getPostProcessMonitor().push_back(post_only);
1070 dm, ts, fe_name, method, pre_only, post_only);
1076 boost::shared_ptr<MoFEM::FEMethod> method,
1077 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
1078 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
1080 boost::shared_ptr<MoFEM::FEMethod>,
1081 boost::shared_ptr<MoFEM::BasicMethod>,
1082 boost::shared_ptr<MoFEM::BasicMethod>>(
1083 dm, ts, fe_name, method, pre_only, post_only);
1088 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1091 *ksp_ctx = dm_field->
kspCtx.get();
1097 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1100 const_cast<boost::shared_ptr<MoFEM::KspCtx> &
>(ksp_ctx) = dm_field->
kspCtx;
1105 boost::shared_ptr<MoFEM::KspCtx> ksp_ctx) {
1106 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1109 dm_field->
kspCtx = ksp_ctx;
1114 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1117 *snes_ctx = dm_field->
snesCtx.get();
1123 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1126 const_cast<boost::shared_ptr<MoFEM::SnesCtx> &
>(snes_ctx) = dm_field->
snesCtx;
1131 boost::shared_ptr<MoFEM::SnesCtx> snes_ctx) {
1132 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1143 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1154 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1162 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1170 const boost::shared_ptr<MoFEM::TsCtx> &
ts_ctx) {
1171 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1174 const_cast<boost::shared_ptr<MoFEM::TsCtx> &
>(
ts_ctx) = dm_field->
tsCtx;
1179 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1187 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1198 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1203 CHKERR VecSetDM(g_ptr, dm);
1208 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1218 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1222 if (strcmp(dm->mattype, MATSHELL) == 0) {
1230 "Matrix shell data not set, or matrix type not implemented");
1233 }
else if (strcmp(dm->mattype, MATMPIAIJ) == 0) {
1235 ->createMPIAIJWithArrays<PetscGlobalIdx_mi_tag>(dm_field->
problemName,
1237 }
else if (strcmp(dm->mattype, MATAIJ) == 0) {
1239 ->createSeqAIJWithArrays<PetscLocalIdx_mi_tag>(dm_field->
problemName,
1241 }
else if (strcmp(dm->mattype, MATAIJCUSPARSE) == 0) {
1243 ->createMPIAIJCUSPARSEWithArrays<PetscGlobalIdx_mi_tag>(
1245 }
else if (strcmp(dm->mattype, MATSEQAIJCUSPARSE) == 0) {
1247 ->createSeqAIJCUSPARSEWithArrays<PetscLocalIdx_mi_tag>(
1251 "Matrix type not implemented");
1258 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1262 if (strcmp(dm->mattype, MATSHELL) == 0) {
1270 "Matrix shell data not set, or matrix type not implemented");
1272 }
else if (strcmp(dm->mattype, MATMPIAIJ) == 0) {
1274 ->createMPIAIJWithArrays<PetscGlobalIdx_mi_tag>(dm_field->
problemName,
1276 }
else if (strcmp(dm->mattype, MATAIJ) == 0) {
1278 ->createSeqAIJWithArrays<PetscLocalIdx_mi_tag>(dm_field->
problemName,
1280 }
else if (strcmp(dm->mattype, MATAIJCUSPARSE) == 0) {
1282 ->createMPIAIJCUSPARSEWithArrays<PetscGlobalIdx_mi_tag>(
1284 }
else if (strcmp(dm->mattype, MATSEQAIJCUSPARSE) == 0) {
1286 ->createSeqAIJCUSPARSEWithArrays<PetscLocalIdx_mi_tag>(
1290 "Matrix type not implemented");
1296#if PETSC_VERSION_GE(3, 17, 0)
1298 PetscOptionItems *PetscOptionsObject) {
1299#elif PETSC_VERSION_GE(3, 7, 0)
1302#elif PETSC_VERSION_GE(3, 5, 3)
1308 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1311#if PETSC_VERSION_GE(3, 18, 0)
1312 PetscOptionsHeadBegin(PetscOptionsObject,
"DMMoFEM Options");
1313#elif PETSC_VERSION_GE(3, 5, 3)
1314 PetscOptionsHead(PetscOptionsObject,
"DMMoFEM Options");
1316 PetscOptionsHead(
"DMMoFEM Options");
1318 ierr = PetscOptionsBool(
"-dm_is_partitioned",
1319 "set if mesh is partitioned (works which native MOAB "
1320 "file format, i.e. h5m",
1328 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1375 PetscValidHeaderSpecific(subdm, DM_CLASSID, 1);
1384 map<std::string, boost::shared_ptr<Range>> *entity_map_row =
nullptr;
1385 map<std::string, boost::shared_ptr<Range>> *entity_map_col =
nullptr;
1395 subdm_field->
isSquareMatrix == PETSC_TRUE, entity_map_row, entity_map_col,
1402 0, subdm_field->
sIze,
1423 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1425 CHKERR VecGhostUpdateBegin(
g, INSERT_VALUES, SCATTER_FORWARD);
1430 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1433 CHKERR VecGhostUpdateEnd(
g, INSERT_VALUES, SCATTER_FORWARD);
1439 double *array_loc, *array_glob;
1440 CHKERR VecGetArray(
l, &array_loc);
1441 CHKERR VecGetArray(
g, &array_glob);
1444 cblas_dcopy(nb_dofs + nb_ghost, array_glob, 1, array_loc, 1);
1447 cblas_daxpy(nb_dofs + nb_ghost, 1, array_glob, 1, array_loc, 1);
1452 CHKERR VecRestoreArray(
l, &array_loc);
1453 CHKERR VecRestoreArray(
g, &array_glob);
1460 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1467 double *array_loc, *array_glob;
1468 CHKERR VecGetArray(
l, &array_loc);
1469 CHKERR VecGetArray(
g, &array_glob);
1472 cblas_dcopy(nb_dofs + nb_ghost, array_loc, 1, array_glob, 1);
1475 cblas_daxpy(nb_dofs + nb_ghost, 1, array_loc, 1, array_glob, 1);
1480 CHKERR VecRestoreArray(
l, &array_loc);
1481 CHKERR VecRestoreArray(
g, &array_glob);
1492 char ***fieldNames, IS **fields) {
1493 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1508 Field_multiIndex::iterator fit, hi_fit;
1509 fit = fields_ptr->begin();
1510 hi_fit = fields_ptr->end();
1511 *numFields = std::distance(fit, hi_fit);
1514 CHKERR PetscMalloc1(*numFields, fieldNames);
1517 CHKERR PetscMalloc1(*numFields, fields);
1520 for (
int f = 0; fit != hi_fit; fit++, f++) {
1522 CHKERR PetscStrallocpy(fit->get()->getName().c_str(),
1523 (
char **)&(*fieldNames)[f]);
1527 ->isCreateProblemFieldAndRank(
1529 fit->get()->getNbOfCoeffs(), &(*fields)[f]);
1538 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1548 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1556 boost::shared_ptr<BlockStructure> data) {
1557 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1565 boost::shared_ptr<BlockStructure> &data) {
1566 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1574 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1578 *mat = mat_data.first;
1579 CHKERR PetscObjectReference((PetscObject)(*mat));
1585 boost::shared_ptr<NestSchurData> data) {
1586 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1598 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1602 *mat = mat_data.first;
1603 CHKERR PetscObjectReference((PetscObject)(*mat));
1608 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
Implementation of DM context. You should not use it directly.
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 DMoFEMMeshToGlobalVector(DM dm, Vec g, InsertMode mode, ScatterMode scatter_mode, RowColData rc=RowColData::COL)
set ghosted vector values on all existing mesh entities
PetscErrorCode DMGlobalToLocalEnd_MoFEM(DM dm, Vec, InsertMode, Vec)
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 DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
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 DMMoFEMGetProblemFiniteElementLayout(DM dm, std::string fe_name, PetscLayout *layout)
Get finite elements layout in the problem.
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 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 DMoFEMPostProcessFiniteElements(DM dm, MoFEM::FEMethod *method)
execute finite element method for each element in dm (problem)
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 DMMoFEMAddSubFieldRow(DM dm, const char field_name[])
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 DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode, RowColData rc=RowColData::COL)
set local (or ghosted) vector values on mesh for partition only
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
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 DMMoFEMResolveSharedFiniteElements(DM dm, std::string fe_name)
Resolve shared entities.
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
MoFEMErrorCode DMMoFEMCreateBlockMat(DM dm, Mat *mat)
Create block matrix.
PetscErrorCode DMoFEMGetInterfacePtr(DM dm, MoFEM::Interface **m_field_ptr)
Get pointer to MoFEM::Interface.
PetscErrorCode DMMoFEMAddSubFieldCol(DM dm, const char field_name[])
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 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 DMMoFEMUnSetElement(DM dm, std::string fe_name)
unset element from dm
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 buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
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, boost::shared_ptr< Range > > *entityMapRow=nullptr, const map< std::string, boost::shared_ptr< Range > > *entityMapCol=nullptr, int verb=VERBOSE)
build sub problem
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 add_problem(const std::string &name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add problem.
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 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
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
FTensor::Index< 'l', 3 > l
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 jacobian 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)
MoFEMErrorCode DMMoFEMCreateHybridL2Mat(DM dm, SmartPetscObj< Mat > &mat)
Create matrix for hybridised system.
PetscErrorCode DMMoFEMGetDestroyProblem(DM dm, PetscBool *destroy_problem)
MoFEMErrorCode DMMoFEMGetBlocMatData(DM dm, boost::shared_ptr< BlockStructure > &)
Get data for block mat.
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.
std::pair< SmartPetscObj< Mat >, boost::shared_ptr< NestSchurData > > createSchurNestedMatrix(boost::shared_ptr< NestSchurData > schur_net_data_ptr)
Create a Mat Diag Blocks object.
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 DMMoFEMClearDMCtx(DM dm)
Clear solver and Schur data owned by a MoFEM DM context.
MoFEMErrorCode DMMoFEMCreateNestSchurMat(DM dm, Mat *mat)
Create nest schur matrix.
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.
MoFEMErrorCode DMMoFEMSetBlocMatData(DM dm, boost::shared_ptr< BlockStructure >)
Set data for block mat.
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 Jacobian for second order PDE in time.
PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx)
Run over elements in the list.
PetscErrorCode TsSetRHSJacobian(TS ts, PetscReal t, Vec u, Mat A, Mat B, void *ctx)
TS solver function.
MoFEMErrorCode DMMoFEMSetNestSchurData(DM dm, boost::shared_ptr< NestSchurData >)
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 DMMoFEMSwapDMCtx(DM dm, DM dm_swap)
Swap internal data structure.
PetscErrorCode DMMoFEMDuplicateDMCtx(DM dm, DM dm_duplicate)
Duplicate internal data structure.
SchurShellMatData createBlockMat(DM dm, boost::shared_ptr< BlockStructure > data)
Create a Schur Mat object.
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
PetscBool isSquareMatrix
true if rows equals to cols
std::vector< std::string > rowCompPrb
boost::shared_ptr< NestSchurData > nestedSchurDataPtr
PetscBool destroyProblem
If true destroy problem with DM.
const Problem * problemMainOfSubPtr
pointer to main problem to sub-problem
std::string problemName
Problem name.
PetscBool isPartitioned
true if read mesh is on parts
std::map< std::string, boost::shared_ptr< Range > > mapTypeCol
const Problem * problemPtr
pointer to problem data structure
std::map< std::string, boost::shared_ptr< Range > > mapTypeRow
std::vector< std::string > colSubFields
boost::shared_ptr< BlockStructure > blocMatDataPtr
Interface * mField_ptr
MoFEM interface.
std::vector< std::string > rowSubFields
PetscBool isProblemBuild
True if problem is build.
std::vector< std::string > colCompPrb
PETSc Discrete Manager data structure.
boost::shared_ptr< SnesCtx > snesCtx
data structure SNES
boost::shared_ptr< TsCtx > tsCtx
data structure for TS solver
boost::shared_ptr< KspCtx > kspCtx
data structure KSP
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Deprecated interface functions.
Data structure for user loop methods on degrees of freedom (DOFs)
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.
MoFEMErrorCode createHybridL2MPIAIJ(const std::string problem_name, SmartPetscObj< Mat > &aij_ptr, int verb=QUIET)
Create a Hybrid MPIAij object.
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.
intrusive_ptr for managing petsc objects
Interface for nonlinear (SNES) solver.
Interface for Time Stepping (TS) solver.
base class for all interface classes
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Vector manager is used to create vectors \mofem_vectors.