8 #define ProblemCoreFunctionBegin \
10 MOFEM_LOG_CHANNEL("WORLD"); \
11 MOFEM_LOG_CHANNEL("SYNC"); \
12 MOFEM_LOG_FUNCTION(); \
13 MOFEM_LOG_TAG("SYNC", "ProblemCore"); \
14 MOFEM_LOG_TAG("WORLD", "ProblemCore")
19 Problem_multiIndex::index<Problem_mi_tag>::type::iterator pit;
20 pit = pRoblems.get<Problem_mi_tag>().find(name);
21 if (pit == pRoblems.get<Problem_mi_tag>().end()) {
34 CHKERR get_moab().create_meshset(MESHSET_SET, meshset);
35 CHKERR get_moab().tag_set_data(th_ProblemId, &meshset, 1, &
id);
40 auto add_meshset_to_partition = [&](
auto meshset) {
42 const void *tag_vals[] = {&rAnk};
43 ParallelComm *pcomm = ParallelComm::get_pcomm(
44 &get_moab(), get_basic_entity_data_ptr()->pcommID);
45 Tag part_tag = pcomm->part_tag();
47 CHKERR get_moab().get_entities_by_type_and_tag(0, MBENTITYSET, &part_tag,
48 tag_vals, 1, tagged_sets,
49 moab::Interface::UNION);
50 for (
auto s : tagged_sets)
51 CHKERR get_moab().add_entities(s, &meshset, 1);
54 CHKERR add_meshset_to_partition(meshset);
56 void const *tag_data[] = {name.c_str()};
58 tag_sizes[0] = name.size();
59 CHKERR get_moab().tag_set_by_ptr(th_ProblemName, &meshset, 1, tag_data,
62 auto p = pRoblems.insert(
Problem(moab, meshset));
66 MOFEM_LOG(
"SELF", Sev::error) <<
"Following problem can not be added:";
68 <<
"Problem " << name <<
" id(" <<
id.to_ulong() <<
") " <<
id
69 <<
" added meshset " << meshset;
70 MOFEM_LOG(
"SELF", Sev::error) <<
"List of problems already in databse:";
71 for (
auto &p : pRoblems) {
73 << p.getName() <<
" id(" << p.getId().to_ulong() <<
") " <<
id
74 <<
" on meshset " << p.meshset;
79 MOFEM_LOG(
"WORLD", Sev::inform) <<
"Add problem " << name;
99 CHKERR addProblem(
id, name, verb);
102 SETERRQ1(PETSC_COMM_SELF,
MOFEM_NOT_FOUND,
"problem is in database %s",
112 SETERRQ1(PETSC_COMM_SELF,
MOFEM_NOT_FOUND,
"no such problem like < %s >",
117 CHKERR get_moab().delete_entities(&meshset, 1);
126 return p_miit->getId();
133 ProblemById::iterator miit = set_id.begin();
134 for (; miit != set_id.end(); miit++) {
135 std::ostringstream ss;
136 ss << *miit << std::endl;
137 PetscPrintf(mofemComm, ss.str().c_str());
144 const std::string &fe_name) {
148 ProblemsByName::iterator miit = set.find(name_problem);
149 if (miit == set.end()) {
150 SETERRQ1(PETSC_COMM_SELF,
MOFEM_NOT_FOUND,
"this problem <%s> is not there",
151 name_problem.c_str());
153 BitFEId f_id = getBitFEId(fe_name);
157 "modification unsuccessful");
163 const std::string &fe_name) {
167 ProblemsByName::iterator miit = set.find(name_problem);
168 if (miit == set.end()) {
169 SETERRQ1(PETSC_COMM_SELF,
MOFEM_NOT_FOUND,
"this problem <%s> is not there",
170 name_problem.c_str());
172 BitFEId f_id = getBitFEId(fe_name);
176 "modification unsuccessful");
186 ProblemsByName::iterator miit = set.find(name_problem);
187 std::ostringstream ss;
189 if (miit == set.end())
190 SETERRQ1(PETSC_COMM_SELF,
MOFEM_NOT_FOUND,
"this problem <%s> is there",
194 SETERRQ(PETSC_COMM_SELF, 1,
"modification unsuccessful");
204 ProblemsByName::iterator miit = set.find(name_problem);
205 std::ostringstream ss;
207 if (miit == set.end())
208 SETERRQ1(PETSC_COMM_SELF,
MOFEM_NOT_FOUND,
"this problem <%s> is there",
213 "modification unsuccessful");
223 ProblemsByName::iterator miit = set.find(name_problem);
224 if (miit == set.end()) {
225 std::ostringstream ss;
227 SETERRQ1(PETSC_COMM_SELF,
MOFEM_NOT_FOUND,
"this problem <%s> is there",
233 "modification unsuccessful");
243 ProblemsByName::iterator miit = set.find(name_problem);
244 if (miit == set.end()) {
245 std::ostringstream ss;
247 SETERRQ1(PETSC_COMM_SELF,
MOFEM_NOT_FOUND,
"this problem <%s> is there",
253 "modification unsuccessful");
261 Problem_multiIndex::iterator p_miit = pRoblems.begin();
262 for (; p_miit != pRoblems.end(); p_miit++) {
263 CHKERR getInterface<ProblemsManager>()->buildProblemOnDistributedMesh(
264 const_cast<Problem *
>(&*p_miit), verb);
275 ProblemsByName::iterator p_miit = prob_by_name.find(problem_name);
276 if (p_miit == prob_by_name.end()) {
278 "problem < %s > not found, (top tip: check spelling)",
279 problem_name.c_str());
285 "modification unsuccessful");
290 "modification unsuccessful");
296 "modification unsuccessful");
301 "modification unsuccessful");
305 "modification unsuccessful");
306 if (p_miit->getRowDofsSequence())
307 p_miit->getRowDofsSequence()->clear();
308 if (p_miit->getColDofsSequence())
309 p_miit->getColDofsSequence()->clear();
310 if (p_miit->getSubData())
311 p_miit->getSubData().reset();
312 if (p_miit->getComposedProblemsData())
313 p_miit->getComposedProblemsData().reset();
321 if (!((*buildMoFEM) & BUILD_FIELD))
323 if (!((*buildMoFEM) & BUILD_FE))
325 if (!((*buildMoFEM) & BUILD_ADJ))
328 Problem_multiIndex::iterator p_miit = pRoblems.begin();
329 for (; p_miit != pRoblems.end(); p_miit++) {
331 CHKERR getInterface<ProblemsManager>()->buildProblem(problem_ptr,
false,
334 *buildMoFEM |= BUILD_PROBLEM;
343 for (
auto p_miit = pRoblems.begin(); p_miit != pRoblems.end(); p_miit++)
344 CHKERR clear_problem(p_miit->getName(), verb);
348 #define SET_BASIC_METHOD(METHOD, PROBLEM_PTR) \
350 METHOD.rAnk = rAnk; \
351 METHOD.sIze = sIze; \
352 METHOD.problemPtr = PROBLEM_PTR; \
353 METHOD.fieldsPtr = &fIelds; \
354 METHOD.refinedEntitiesPtr = &refinedEntities; \
355 METHOD.entitiesPtr = &entsFields; \
356 METHOD.dofsPtr = &dofsField; \
357 METHOD.refinedFiniteElementsPtr = &refinedFiniteElements; \
358 METHOD.finiteElementsPtr = &finiteElements; \
359 METHOD.finiteElementsEntitiesPtr = &entsFiniteElements; \
360 METHOD.adjacenciesPtr = &entFEAdjacencies; \
371 PetscLogEventBegin(MOFEM_EVENT_preProcess, 0, 0, 0, 0);
373 PetscLogEventEnd(MOFEM_EVENT_preProcess, 0, 0, 0, 0);
386 ProblemsByName::iterator p_miit = pRoblems_set.find(problem_name);
387 if (p_miit == pRoblems_set.end())
388 SETERRQ1(PETSC_COMM_SELF,
MOFEM_NOT_FOUND,
"problem is not in database %s",
389 problem_name.c_str());
390 CHKERR problem_basic_method_preProcess(&*p_miit, method, verb);
400 PetscLogEventBegin(MOFEM_EVENT_postProcess, 0, 0, 0, 0);
402 PetscLogEventEnd(MOFEM_EVENT_postProcess, 0, 0, 0, 0);
417 ProblemsByName::iterator p_miit = pRoblems_set.find(problem_name);
418 if (p_miit == pRoblems_set.end())
419 SETERRQ1(mofemComm, 1,
"problem is not in database %s",
420 problem_name.c_str());
422 CHKERR problem_basic_method_postProcess(&*p_miit, method, verb);
428 const Problem *problem_ptr,
const std::string &fe_name,
FEMethod &method,
429 int lower_rank,
int upper_rank,
430 boost::shared_ptr<NumeredEntFiniteElement_multiIndex> fe_ptr,
MoFEMTypes bh,
437 if (!cache_ptr.use_count()) {
438 tmp_cache_ptr = boost::make_shared<CacheTuple>();
439 CHKERR cache_problem_entities(problem_ptr->
getName(), tmp_cache_ptr);
449 boost::make_tuple(fe_name, lower_rank));
451 boost::make_tuple(fe_name, upper_rank));
453 if (miit == hi_miit && (bh &
MF_EXIST)) {
454 if (!check_finite_element(fe_name)) {
455 SETERRQ1(mofemComm,
MOFEM_NOT_FOUND,
"finite element < %s > not found",
462 std::distance(miit, hi_miit);
463 method.
loHiFERank = std::make_pair(lower_rank, upper_rank);
467 PetscLogEventBegin(MOFEM_EVENT_preProcess, 0, 0, 0, 0);
469 PetscLogEventEnd(MOFEM_EVENT_preProcess, 0, 0, 0, 0);
471 PetscLogEventBegin(MOFEM_EVENT_operator, 0, 0, 0, 0);
472 for (
int nn = 0; miit != hi_miit; miit++, nn++) {
486 PetscLogEventEnd(MOFEM_EVENT_operator, 0, 0, 0, 0);
488 PetscLogEventBegin(MOFEM_EVENT_postProcess, 0, 0, 0, 0);
490 PetscLogEventEnd(MOFEM_EVENT_postProcess, 0, 0, 0, 0);
496 const std::string problem_name,
const std::string &fe_name,
498 boost::shared_ptr<NumeredEntFiniteElement_multiIndex> fe_ptr,
MoFEMTypes bh,
504 CHKERR loop_finite_elements(problem_name, fe_name, method, rAnk, rAnk, fe_ptr,
505 bh, cache_ptr, verb);
511 const std::string problem_name,
const std::string &fe_name,
512 FEMethod &method,
int lower_rank,
int upper_rank,
513 boost::shared_ptr<NumeredEntFiniteElement_multiIndex> fe_ptr,
MoFEMTypes bh,
520 auto p_miit = prb_by_name.find(problem_name);
521 if (p_miit == prb_by_name.end())
523 problem_name.c_str());
525 CHKERR loop_finite_elements(&*p_miit, fe_name, method, lower_rank, upper_rank,
526 fe_ptr, bh, cache_ptr, verb);
534 int upper_rank,
int verb) {
539 NumeredDofsByUId *dofs;
559 auto miit = dofs->lower_bound(
561 auto hi_miit = dofs->upper_bound(
564 method.
loopSize = std::distance(miit, hi_miit);
565 method.
loHiFERank = std::make_pair(lower_rank, upper_rank);
570 for (; miit != hi_miit; miit++, nn++) {
571 if ((*miit)->getPart() >= lower_rank && (*miit)->getPart() <= upper_rank) {
573 method.
dofPtr = miit->get()->getDofEntityPtr();
584 const std::string &problem_name,
const std::string &
field_name,
598 ProblemsByName::iterator p_miit = pRoblems_set.find(problem_name);
599 if (p_miit == pRoblems_set.end())
600 SETERRQ1(PETSC_COMM_SELF,
MOFEM_NOT_FOUND,
"problem not in database %s",
601 problem_name.c_str());
637 method.
loopSize = std::distance(miit, hi_miit);
638 method.
loHiFERank = std::make_pair(0, get_comm_size());
641 for (
int nn = 0; miit != hi_miit; miit++, nn++) {
653 int upper_rank,
int verb) {
667 "It works only with rows or columns");
678 auto miit = dofs->lower_bound(
680 auto hi_miit = dofs->upper_bound(
683 using FieldEntity_view_multiIndex = multi_index_container<
685 boost::shared_ptr<FieldEntity>,
696 FieldEntity_view_multiIndex ents_view;
697 auto hint = ents_view.begin();
698 for (; miit != hi_miit; ++miit)
699 if ((*miit)->getPart() >= lower_rank && (*miit)->getPart() <= upper_rank)
700 ents_view.emplace_hint(hint, (*miit)->getFieldEntityPtr());
705 method.
loHiFERank = std::make_pair(lower_rank, upper_rank);
709 for (
auto &field_ent : ents_view) {
710 method.
entPtr = field_ent;
721 int upper_rank,
int verb) {
727 auto p_miit = prb.find(problem_name);
728 if (p_miit == prb.end())
729 SETERRQ1(PETSC_COMM_SELF,
MOFEM_NOT_FOUND,
"problem not in database %s",
730 problem_name.c_str());
731 CHKERR loop_entities(&*p_miit,
field_name, rc, method, lower_rank, upper_rank,
739 return loop_entities(problem_name,
field_name, rc, method, rAnk, rAnk, verb);
744 Range const *
const ents,
int verb) {
763 typedef multi_index_container<
764 boost::shared_ptr<FieldEntity>,
765 indexed_by<ordered_unique<
768 FieldEntity_view_multiIndex;
770 FieldEntity_view_multiIndex ents_view;
771 ents_view.insert(lo_eit, hi_eit);
774 method.
loHiFERank = std::make_pair(0, get_comm_size());
780 for (
auto p = ents->const_pair_begin(); p != ents->const_pair_end(); ++p)
781 for (
auto feit = ents_view.lower_bound(p->first);
782 feit != ents_view.upper_bound(p->second); ++feit) {
788 for (
auto &field_ent : ents_view) {
789 method.
entPtr = field_ent;
802 if (
auto cache_ptr = cache_weak_ptr.lock()) {
805 SETERRQ1(PETSC_COMM_SELF,
MOFEM_NOT_FOUND,
"problem not in database %s",
808 const BitRefLevel &prb_bit = p_miit->getBitRefLevel();
809 const BitRefLevel &prb_mask = p_miit->getBitRefLevelMask();
810 const BitFEId &prb_fe_id = p_miit->getBitFEId();
812 auto &row_dofs = p_miit->numeredRowDofsPtr;
813 auto &col_dofs = p_miit->numeredColDofsPtr;
815 auto &cache_data = std::get<0>(*cache_ptr);
816 auto &cache_row = std::get<1>(*cache_ptr);
817 auto &cache_col = std::get<2>(*cache_ptr);
819 cache_row.resize(entsFields.size());
820 if (row_dofs != col_dofs)
821 cache_col.resize(entsFields.size());
822 cache_data.resize(entsFields.size());
825 for (
auto it = entsFields.begin(); it != entsFields.end(); ++it, ++idx) {
827 const auto uid = (*it)->getLocalUniqueId();
829 for (
auto lo =
r.first; lo !=
r.second; ++lo) {
831 if ((lo->getBitFEId() & prb_fe_id).any()) {
833 const BitRefLevel &fe_bit = lo->entFePtr->getBitRefLevel();
836 if (((fe_bit & prb_mask) != fe_bit) || ((fe_bit & prb_bit).none()))
839 auto cache_numered_dofs = [&](
auto &numered_dofs,
auto &cache_vec,
841 auto dit = numered_dofs->lower_bound(uid);
842 decltype(dit) hi_dit;
843 if (dit != numered_dofs->end())
844 hi_dit = numered_dofs->upper_bound(
849 ent_cache = boost::shared_ptr<EntityCacheNumeredDofs>(
850 cache_ptr, &(cache_vec[idx]));
851 cache_vec[idx].loHi = {dit, hi_dit};
854 auto cache_dofs = [&](
auto &dofs,
auto &cache_vec,
auto &ent_cache) {
855 auto dit = dofs.lower_bound(uid);
856 decltype(dit) hi_dit;
857 if (dit != dofs.end())
858 hi_dit = dofs.upper_bound(
863 ent_cache = boost::shared_ptr<EntityCacheDofs>(cache_ptr,
865 cache_vec[idx].loHi = {dit, hi_dit};
868 cache_numered_dofs(row_dofs, cache_row, (*it)->entityCacheRowDofs);
869 if (row_dofs != col_dofs) {
870 if (cache_col.size() != entsFields.size())
871 cache_col.resize(entsFields.size());
872 cache_numered_dofs(col_dofs, cache_col, (*it)->entityCacheColDofs);
874 (*it)->entityCacheColDofs = (*it)->entityCacheRowDofs;
877 cache_dofs(dofsField, cache_data, (*it)->entityCacheDataDofs);