17 : comm(comm), isPetscComm(petsc) {
41 constexpr
const int CoreTmp<-1>::value;
47 if (type_index == boost::typeindex::type_id<CoreInterface>()) {
50 }
else if (type_index ==
51 boost::typeindex::type_id<DeprecatedCoreInterface>()) {
57 auto it = iFaces.find(type_index);
58 if (it != iFaces.end()) {
75 MPI_Initialized(&mpiInitialised);
79 PetscInitialized(&isInitialized);
80 if (isInitialized == PETSC_FALSE) {
81 PetscInitialize(argc,
args, file,
help);
88 isGloballyInitialised =
true;
91 char petsc_version[255];
92 CHKERR PetscGetVersion(petsc_version, 255);
93 MOFEM_LOG_C(
"WORLD", Sev::inform,
"MoFEM version %d.%d.%d (%s %s)",
94 MoFEM_VERSION_MAJOR, MoFEM_VERSION_MINOR, MoFEM_VERSION_BUILD,
95 MOAB_VERSION_STRING, petsc_version);
96 MOFEM_LOG_C(
"WORLD", Sev::inform,
"git commit id %s", GIT_SHA1_NAME);
98 auto log_time = [&](
const auto perefix,
auto time) {
100 << perefix << time.date().year() <<
"-" << time.date().month() <<
"-"
101 << time.date().day() <<
" " << time.time_of_day().hours() <<
":"
102 << time.time_of_day().minutes() <<
":" << time.time_of_day().seconds();
106 log_time(
"Local time: ", boost::posix_time::second_clock::local_time());
107 log_time(
"UTC time: ", boost::posix_time::second_clock::universal_time());
113 if (isGloballyInitialised) {
114 PetscPopErrorHandler();
115 isGloballyInitialised =
false;
117 if (isInitialized == PETSC_FALSE) {
118 PetscBool is_finalized;
119 PetscFinalized(&is_finalized);
124 if (!mpiInitialised) {
126 MPI_Finalized(&mpi_finalized);
139 -> decltype(ptr->getSubInterfaceOptions()) {
140 return ptr->getSubInterfaceOptions();
152 -> decltype(ptr->getEventOptions()) {
153 return ptr->getEventptions();
168 CHKERR registerInterface<IFACE>(
true);
169 IFACE *ptr =
new IFACE(*
this);
174 auto get_sub_iface_options = [](
auto *
const ptr) {
177 CHKERR get_sub_iface_options(ptr);
179 auto type_idx = boost::typeindex::type_id<IFACE>();
180 iFaces.insert(type_idx, ptr);
186 auto ptr = boost::make_shared<IFACE>();
190 auto get_event_options = [](
auto *
const ptr) {
193 CHKERR get_event_options(ptr.get());
198 MPI_Comm comm,
const int verbose) {
202 if (!isGloballyInitialised)
204 "MoFEM globally is not initialised, call MoFEM::Core::Initialize");
207 wrapMPIMOABComm = boost::make_shared<WrapMPIComm>(comm,
false);
209 MPI_Comm_size(mofemComm, &sIze);
210 MPI_Comm_rank(mofemComm, &rAnk);
213 ParallelComm *pComm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
215 pComm =
new ParallelComm(&moab, wrapMPIMOABComm->get_comm());
218 CHKERR registerInterface<UnknownInterface>();
219 CHKERR registerInterface<CoreInterface>();
220 CHKERR registerInterface<DeprecatedCoreInterface>();
223 PetscLogEventRegister(
"FE_preProcess", 0, &MOFEM_EVENT_preProcess);
224 PetscLogEventRegister(
"FE_operator", 0, &MOFEM_EVENT_operator);
225 PetscLogEventRegister(
"FE_postProcess", 0, &MOFEM_EVENT_postProcess);
226 PetscLogEventRegister(
"MoFEMCreateMat", 0, &MOFEM_EVENT_createMat);
243 ierr = this->registerSubInterfaces();
244 CHKERRABORT(comm,
ierr);
245 ierr = this->clearMap();
246 CHKERRABORT(comm,
ierr);
247 ierr = this->getTags();
248 CHKERRABORT(comm,
ierr);
249 ierr = this->getOptions(verbose);
250 CHKERRABORT(comm,
ierr);
252 this->basicEntityDataPtr = boost::make_shared<BasicEntityData>(moab);
253 setRefEntBasicDataPtr(*
this, this->basicEntityDataPtr);
255 ierr = this->initialiseDatabaseFromMesh(verbose);
256 CHKERRABORT(comm,
ierr);
267 ierr = this->registerSubInterfaces();
268 CHKERRABORT(comm,
ierr);
269 ierr = this->clearMap();
270 CHKERRABORT(comm,
ierr);
271 ierr = this->getTags();
272 CHKERRABORT(comm,
ierr);
273 ierr = this->getOptions(verbose);
274 CHKERRABORT(comm,
ierr);
276 this->basicEntityDataPtr = boost::make_shared<BasicEntityData>(moab);
277 setRefEntBasicDataPtr(*
this, this->basicEntityDataPtr);
279 ierr = this->initialiseDatabaseFromMesh(verbose);
280 CHKERRABORT(comm,
ierr);
284 PetscBool is_finalized;
285 PetscFinalized(&is_finalized);
289 if (isGloballyInitialised && is_finalized) {
290 isGloballyInitialised =
false;
300 Range ref_elems_to_add;
304 CHKERR get_moab().get_entities_by_type(0, MBENTITYSET, meshsets,
false);
305 Range special_meshsets;
306 for (
auto mit : meshsets) {
309 CHKERR get_moab().tag_get_data(th_FieldId, &mit, 1, &field_id);
313 const void *tag_name;
315 CHKERR get_moab().tag_get_by_ptr(
316 th_FieldName, &mit, 1, (
const void **)&tag_name, &tag_name_size);
321 << boost::string_ref((
char *)tag_name, tag_name_size);
323 auto p = fIelds.insert(boost::make_shared<Field>(moab, mit));
329 CHKERR get_moab().get_entities_by_handle(mit, ents,
true);
330 CHKERR get_moab().add_entities((*p.first)->getMeshset(), ents);
331 CHKERR get_moab().delete_entities(&mit, 1);
333 special_meshsets.insert(mit);
339 CHKERR get_moab().tag_get_data(th_FEId, &mit, 1, &fe_id);
342 std::pair<FiniteElement_multiIndex::iterator, bool> p =
343 finiteElements.insert(
344 boost::shared_ptr<FiniteElement>(
new FiniteElement(moab, mit)));
346 MOFEM_LOG(
"WORLD", Sev::verbose) <<
"Read finite element " << **p.first;
349 CHKERR get_moab().get_entities_by_type(mit, MBENTITYSET, ents,
false);
350 CHKERR get_moab().get_entities_by_handle(mit, ents,
true);
351 ref_elems_to_add.merge(ents);
355 CHKERR get_moab().add_entities((*p.first)->getMeshset(), ents);
356 CHKERR get_moab().delete_entities(&mit, 1);
358 special_meshsets.insert(mit);
363 CHKERR get_moab().tag_get_data(th_ProblemId, &mit, 1, &problem_id);
365 if (problem_id != 0) {
366 std::pair<Problem_multiIndex::iterator, bool> p =
367 pRoblems.insert(
Problem(moab, mit));
369 MOFEM_LOG(
"WORLD", Sev::verbose) <<
"Read problem " << *p.first;
371 <<
"\tBitRef " << p.first->getBitRefLevel() <<
" BitMask "
372 << p.first->getBitRefLevelMask();
379 CHKERR get_moab().get_entities_by_handle(mit, ents,
true);
380 CHKERR get_moab().get_entities_by_type(mit, MBENTITYSET, ents,
true);
381 CHKERR get_moab().add_entities(p.first->meshset, ents);
382 CHKERR get_moab().delete_entities(&mit, 1);
384 special_meshsets.insert(mit);
391 CHKERR get_moab().get_entities_by_handle(0, bit_ref_ents,
false);
392 bit_ref_ents = subtract(bit_ref_ents, special_meshsets);
393 CHKERR getInterface<BitRefManager>()->filterEntitiesByRefLevel(
395 CHKERR getInterface<BitRefManager>()->setEntitiesBitRefLevel(bit_ref_ents);
396 CHKERR getInterface<BitRefManager>()->setElementsBitRefLevel(
400 for (
auto field : fIelds) {
401 if (field->getSpace() !=
NOSPACE) {
402 Range ents_of_id_meshset;
403 CHKERR get_moab().get_entities_by_handle(field->getMeshset(),
404 ents_of_id_meshset,
false);
405 CHKERR set_field_order(ents_of_id_meshset, field->getId(), -1, verb);
409 if (initaliseAndBuildField || initaliseAndBuildFiniteElements) {
410 CHKERR build_fields(verb);
411 if (initaliseAndBuildFiniteElements) {
412 CHKERR build_finite_elements(verb);
418 list_finite_elements();
424 CHKERR getInterface(m_manger_ptr);
427 CHKERR getInterface(series_recorder_ptr);
442 moab = std::ref(new_moab);
445 ParallelComm *pComm = ParallelComm::get_pcomm(&new_moab,
MYPCOMM_INDEX);
447 pComm =
new ParallelComm(&new_moab, wrapMPIMOABComm->get_comm());
454 basicEntityDataPtr = boost::make_shared<BasicEntityData>(moab);
455 setRefEntBasicDataPtr(*
this, this->basicEntityDataPtr);
458 CHKERR this->initialiseDatabaseFromMesh(verb);
469 CHKERR regSubInterface<LogManager>();
470 CHKERR regSubInterface<Simple>();
471 CHKERR regSubInterface<OperatorsTester>();
472 CHKERR regSubInterface<PipelineManager>();
473 CHKERR regSubInterface<ProblemsManager>();
474 CHKERR regSubInterface<MatrixManager>();
475 CHKERR regSubInterface<ISManager>();
476 CHKERR regSubInterface<VecManager>();
477 CHKERR regSubInterface<FieldBlas>();
478 CHKERR regSubInterface<BitRefManager>();
479 CHKERR regSubInterface<Tools>();
480 CHKERR regSubInterface<CommInterface>();
481 CHKERR regSubInterface<MeshsetsManager>();
482 CHKERR regSubInterface<NodeMergerInterface>();
483 CHKERR regSubInterface<PrismsFromSurfaceInterface>();
484 CHKERR regSubInterface<MeshRefinement>();
485 CHKERR regSubInterface<PrismInterface>();
486 CHKERR regSubInterface<CutMeshInterface>();
487 CHKERR regSubInterface<SeriesRecorder>();
489 CHKERR regSubInterface<TetGenInterface>();
492 CHKERR regSubInterface<MedInterface>();
494 CHKERR regSubInterface<FieldEvaluatorInterface>();
495 CHKERR regSubInterface<BcManager>();
498 CHKERR regEvents<SchurEvents>();
506 CHKERR getInterface<SeriesRecorder>()->clearMap();
507 CHKERR getInterface<MeshsetsManager>()->clearMap();
508 CHKERR getInterface<CutMeshInterface>()->clearMap();
510 refinedEntities.clear();
511 refinedFiniteElements.clear();
515 finiteElements.clear();
516 entsFiniteElements.clear();
517 entFEAdjacencies.clear();
526 std::pair<RefEntity_multiIndex::iterator, bool> p_ent;
527 p_ent = refinedEntities.insert(
528 boost::make_shared<RefEntity>(basicEntityDataPtr, prism));
530 std::pair<RefElement_multiIndex::iterator, bool> p;
531 p = refinedFiniteElements.insert(
535 CHKERR get_moab().get_connectivity(prism, conn, num_nodes,
true);
536 Range face_side3, face_side4;
537 CHKERR get_moab().get_adjacencies(conn, 3, 2,
false, face_side3);
538 CHKERR get_moab().get_adjacencies(&conn[3], 3, 2,
false, face_side4);
539 if (face_side3.size() != 1)
541 "prism don't have side face 3");
542 if (face_side4.size() != 1)
544 "prims don't have side face 4");
545 p.first->get()->getSideNumberPtr(*face_side3.begin());
546 p.first->get()->getSideNumberPtr(*face_side4.begin());
554 const EntityHandle root_meshset = get_moab().get_root_set();
557 "Root meshset should be 0");
563 CHKERR getFileVersion(moab, version);
569 auto check_tag_allocated = [](
auto &
rval) {
571 if (
rval == MB_ALREADY_ALLOCATED)
580 rval = get_moab().tag_get_handle(
"_MoFEMBuild", 1, MB_TYPE_INTEGER,
581 th_MoFEMBuild, MB_TAG_CREAT | MB_TAG_MESH,
585 CHKERR get_moab().tag_get_by_ptr(th_MoFEMBuild, &root_meshset, 1,
586 (
const void **)&buildMoFEM);
591 const int def_part = -1;
592 CHKERR get_moab().tag_get_handle(
"PARTITION", 1, MB_TYPE_INTEGER, th_Part,
593 MB_TAG_CREAT | MB_TAG_SPARSE, &def_part);
602 const int def_part = -1;
603 CHKERR get_moab().tag_get_handle(
"_MeshsetPartition", 1, MB_TYPE_INTEGER,
604 th_Part, MB_TAG_CREAT | MB_TAG_SPARSE,
607 CHKERR get_moab().tag_get_handle(
"_RefParentHandle", 1, MB_TYPE_HANDLE,
609 MB_TAG_CREAT | MB_TAG_SPARSE, &def_handle);
611 CHKERR get_moab().tag_get_handle(
612 "_RefBitLevel",
sizeof(
BitRefLevel), MB_TYPE_OPAQUE, th_RefBitLevel,
613 MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE, &def_bit_level);
615 CHKERR get_moab().tag_get_handle(
616 "_RefBitLevelMask",
sizeof(
BitRefLevel), MB_TYPE_OPAQUE,
617 th_RefBitLevel_Mask, MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE,
618 &def_bit_level_mask);
620 CHKERR get_moab().tag_get_handle(
621 "_RefBitEdge",
sizeof(
BitRefEdges), MB_TYPE_OPAQUE, th_RefBitEdge,
622 MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_BYTES, &def_bit_edge);
627 const unsigned long int def_id = 0;
628 CHKERR get_moab().tag_get_handle(
629 "_FieldId",
sizeof(
BitFieldId), MB_TYPE_OPAQUE, th_FieldId,
630 MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE, &def_id);
632 CHKERR get_moab().tag_get_handle(
633 "_FieldSpace",
sizeof(
FieldSpace), MB_TYPE_OPAQUE, th_FieldSpace,
634 MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE, &def_space);
636 CHKERR get_moab().tag_get_handle(
638 th_FieldContinuity, MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE,
641 CHKERR get_moab().tag_get_handle(
643 th_FieldBase, MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE, &def_base);
644 const int def_val_len = 0;
645 CHKERR get_moab().tag_get_handle(
646 "_FieldName", def_val_len, MB_TYPE_OPAQUE, th_FieldName,
647 MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_VARLEN | MB_TAG_SPARSE, NULL);
648 CHKERR get_moab().tag_get_handle(
649 "_FieldName_DataNamePrefix", def_val_len, MB_TYPE_OPAQUE,
650 th_FieldName_DataNamePrefix,
651 MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_VARLEN | MB_TAG_SPARSE, NULL);
656 const unsigned long int def_id = 0;
657 const int def_val_len = 0;
658 CHKERR get_moab().tag_get_handle(
659 "_FEId",
sizeof(
BitFEId), MB_TYPE_OPAQUE, th_FEId,
660 MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE, &def_id);
661 CHKERR get_moab().tag_get_handle(
662 "_FEName", def_val_len, MB_TYPE_OPAQUE, th_FEName,
663 MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_VARLEN | MB_TAG_SPARSE, NULL);
664 CHKERR get_moab().tag_get_handle(
665 "_FEIdCol",
sizeof(
BitFieldId), MB_TYPE_OPAQUE, th_FEIdCol,
666 MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE, &def_id);
667 CHKERR get_moab().tag_get_handle(
668 "_FEIdRow",
sizeof(
BitFieldId), MB_TYPE_OPAQUE, th_FEIdRow,
669 MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE, &def_id);
670 CHKERR get_moab().tag_get_handle(
671 "_FEIdData",
sizeof(
BitFieldId), MB_TYPE_OPAQUE, th_FEIdData,
672 MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE, &def_id);
677 const unsigned long int def_id = 0;
678 const int def_val_len = 0;
679 CHKERR get_moab().tag_get_handle(
680 "_ProblemId",
sizeof(
BitProblemId), MB_TYPE_OPAQUE, th_ProblemId,
681 MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE, &def_id);
682 CHKERR get_moab().tag_get_handle(
683 "_ProblemFEId",
sizeof(
BitFEId), MB_TYPE_OPAQUE, th_ProblemFEId,
684 MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE, &def_id);
685 CHKERR get_moab().tag_get_handle(
686 "_ProblemName", def_val_len, MB_TYPE_OPAQUE, th_ProblemName,
687 MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_VARLEN | MB_TAG_SPARSE, NULL);
689 CHKERR get_moab().tag_get_handle(
690 "_ProblemNbDofsRow",
sizeof(
DofIdx), MB_TYPE_OPAQUE,
691 th_ProblemNbDofsRow, MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE,
693 CHKERR get_moab().tag_get_handle(
694 "_ProblemNbDofsCol",
sizeof(
DofIdx), MB_TYPE_OPAQUE,
695 th_ProblemNbDofsCol, MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE,
697 CHKERR get_moab().tag_get_handle(
698 "_ProblemLocalNbDofsRow",
sizeof(
DofIdx), MB_TYPE_OPAQUE,
699 th_ProblemLocalNbDofRow, MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE,
701 CHKERR get_moab().tag_get_handle(
702 "_ProblemGhostNbDofsRow",
sizeof(
DofIdx), MB_TYPE_OPAQUE,
703 th_ProblemGhostNbDofRow, MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE,
705 CHKERR get_moab().tag_get_handle(
706 "_ProblemLocalNbDofsCol",
sizeof(
DofIdx), MB_TYPE_OPAQUE,
707 th_ProblemLocalNbDofCol, MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE,
709 CHKERR get_moab().tag_get_handle(
710 "_ProblemGhostNbDofsCol",
sizeof(
DofIdx), MB_TYPE_OPAQUE,
711 th_ProblemGhostNbDofCol, MB_TAG_CREAT | MB_TAG_BYTES | MB_TAG_SPARSE,
717 CHKERR getInterface(meshsets_manager_ptr);
722 CHKERR getInterface(series_recorder_ptr);
741 CHKERR this->getTags(verb);
742 CHKERR this->initialiseDatabaseFromMesh(verb);
747 return this->setMoabInterface(new_moab, verb);
752 return this->setMoabInterface(new_moab, verb);
760 CHKERR PetscOptionsBegin(mofemComm, optionsPrefix.c_str(),
"Mesh cut options",
761 "See MoFEM documentation");
764 "-mofem_init_fields",
"Initialise fields on construction",
"",
765 initaliseAndBuildField, &initaliseAndBuildField, NULL);
768 "-mofem_init_fields",
"Initialise fields on construction",
"",
769 initaliseAndBuildFiniteElements, &initaliseAndBuildFiniteElements, NULL);
774 ierr = PetscOptionsEnd();
784 *fields_ptr = &fIelds;
791 *refined_entities_ptr = &refinedEntities;
797 *refined_finite_elements_ptr = &refinedFiniteElements;
802 const Problem **problem_ptr)
const {
806 ProblemsByName::iterator p_miit = problems.find(problem_name);
807 if (p_miit == problems.end()) {
809 "problem < %s > not found, (top tip: check spelling)",
810 problem_name.c_str());
812 *problem_ptr = &*p_miit;
819 *problems_ptr = &pRoblems;
826 *field_ents = &entsFields;
831 *dofs_ptr = &dofsField;
838 *fe_ptr = &finiteElements;
845 *fe_ent_ptr = &entsFiniteElements;
851 getInterface(meshsets_manager_ptr);
852 return meshsets_manager_ptr;
857 getInterface(meshsets_manager_ptr);
858 return meshsets_manager_ptr;
863 *dofs_elements_adjacency)
const {
865 *dofs_elements_adjacency = &entFEAdjacencies;
871 return &entFEAdjacencies;
876 return &refinedEntities;
879 return &refinedFiniteElements;
882 return &finiteElements;
885 return &entsFiniteElements;
894 "Problem of given name not found");
899 template <
int V,
typename std::enable_if<(V >= 0),
int>
::type * =
nullptr>
904 template <
int V,
typename std::enable_if<(V < 0),
int>::type * =
nullptr>
905 void set_ref_ent_basic_data_ptr_impl(boost::shared_ptr<BasicEntityData> &ptr) {
909 void Core::setRefEntBasicDataPtr(MoFEM::Interface &m_field,
910 boost::shared_ptr<BasicEntityData> &ptr) {
912 switch (m_field.getValue()) {
914 set_ref_ent_basic_data_ptr_impl<-1>(ptr);
917 set_ref_ent_basic_data_ptr_impl<0>(ptr);
920 set_ref_ent_basic_data_ptr_impl<1>(ptr);
923 THROW_MESSAGE("Core index can vary from -1 to MAX_CORE_TMP");
927 boost::shared_ptr<RefEntityTmp<0>>
928 Core::makeSharedRefEntity(MoFEM::Interface &m_field, const EntityHandle ent) {
930 boost::shared_ptr<RefEntityTmp<0>> ref_ent_ptr;
932 switch (m_field.getValue()) {
934 ref_ent_ptr = boost::shared_ptr<RefEntityTmp<0>>(
936 new RefEntityTmp<-1>(m_field.get_basic_entity_data_ptr(), ent)
941 ref_ent_ptr = boost::shared_ptr<RefEntityTmp<0>>(
943 new RefEntityTmp<0>(m_field.get_basic_entity_data_ptr(), ent)
948 ref_ent_ptr = boost::shared_ptr<RefEntityTmp<0>>(
950 new RefEntityTmp<1>(m_field.get_basic_entity_data_ptr(), ent)
955 THROW_MESSAGE("Core index can vary from -1 to MAX_CORE_TMP");
961 boost::shared_ptr<RefEntityTmp<0>>
962 Core::make_shared_ref_entity(const EntityHandle ent) {
963 return this->makeSharedRefEntity(*
this, ent);
966 boost::shared_ptr<RefEntityTmp<0>>
968 return this->makeSharedRefEntity(*
this, ent);