v0.16.3
Loading...
Searching...
No Matches
Namespaces | Macros
ProblemsCore.cpp File Reference

Managing complexities for problem. More...

#include <MoFEM.hpp>

Go to the source code of this file.

Namespaces

namespace  MoFEM
 implementation of Data Operators for Forces and Sources
 

Macros

#define ProblemCoreFunctionBegin
 
#define SET_BASIC_METHOD(METHOD, PROBLEM_PTR)
 

Detailed Description

Managing complexities for problem.

Definition in file ProblemsCore.cpp.

Macro Definition Documentation

◆ ProblemCoreFunctionBegin

#define ProblemCoreFunctionBegin
Value:
MOFEM_LOG_CHANNEL("WORLD"); \
MOFEM_LOG_CHANNEL("SYNC"); \
MOFEM_LOG_FUNCTION(); \
MOFEM_LOG_TAG("SYNC", "ProblemCore"); \
MOFEM_LOG_TAG("WORLD", "ProblemCore")
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...

Definition at line 8 of file ProblemsCore.cpp.

15 {
16
17bool Core::check_problem(const string name) {
18 Problem_multiIndex::index<Problem_mi_tag>::type::iterator pit;
19 pit = pRoblems.get<Problem_mi_tag>().find(name);
20 if (pit == pRoblems.get<Problem_mi_tag>().end()) {
21 return false;
22 }
23 return true;
24}
25
26MoFEMErrorCode Core::addProblem(const BitProblemId id, const std::string &name,
27 int verb) {
29
30 if (verb == -1)
31 verb = verbose;
32 EntityHandle meshset;
33 CHKERR get_moab().create_meshset(MESHSET_SET, meshset);
34 CHKERR get_moab().tag_set_data(th_ProblemId, &meshset, 1, &id);
35
36 // Add problem meshset to partion meshset. In case of no elements
37 // on processor part, when mesh file is read, finite element meshset is
38 // prevented from deletion by moab reader.
39 auto add_meshset_to_partition = [&](auto meshset) {
41 const void *tag_vals[] = {&rAnk};
42 ParallelComm *pcomm = ParallelComm::get_pcomm(
43 &get_moab(), get_basic_entity_data_ptr()->pcommID);
44 Tag part_tag = pcomm->part_tag();
45 Range tagged_sets;
46 CHKERR get_moab().get_entities_by_type_and_tag(0, MBENTITYSET, &part_tag,
47 tag_vals, 1, tagged_sets,
48 moab::Interface::UNION);
49 for (auto s : tagged_sets)
50 CHKERR get_moab().add_entities(s, &meshset, 1);
52 };
53 CHKERR add_meshset_to_partition(meshset);
54
55 void const *tag_data[] = {name.c_str()};
56 int tag_sizes[1];
57 tag_sizes[0] = name.size();
58 CHKERR get_moab().tag_set_by_ptr(th_ProblemName, &meshset, 1, tag_data,
59 tag_sizes);
60 // create entry
61 auto p = pRoblems.insert(Problem(moab, meshset));
62 if (!p.second) {
64 MOFEM_LOG_ATTRIBUTES("SELF", LogManager::BitScope);
65 MOFEM_LOG("SELF", Sev::error) << "Following problem can not be added:";
66 MOFEM_LOG("SELF", Sev::error)
67 << "Problem " << name << " id(" << id.to_ulong() << ") " << id
68 << " added meshset " << meshset;
69 MOFEM_LOG("SELF", Sev::error) << "List of problems already in databse:";
70 for (auto &p : pRoblems) {
71 MOFEM_LOG("SELF", Sev::error)
72 << p.getName() << " id(" << p.getId().to_ulong() << ") " << id
73 << " on meshset " << p.meshset;
74 }
75 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Problem not added");
76 }
77
78 MOFEM_LOG("WORLD", Sev::inform) << "Add problem " << name;
79
81}
82
83MoFEMErrorCode Core::add_problem(const std::string &name, enum MoFEMTypes bh,
84 int verb) {
86 if (verb == -1)
87 verb = verbose;
88 auto miit = pRoblems.get<Problem_mi_tag>().find(name);
89 if (miit == pRoblems.get<Problem_mi_tag>().end()) {
90
91 int p_shift = 0;
92 for (; pRoblems.get<BitProblemId_mi_tag>().find(BitProblemId().set(
93 p_shift)) != pRoblems.get<BitProblemId_mi_tag>().end();
94 ++p_shift) {
95 }
96
97 auto id = BitProblemId().set(p_shift);
98 CHKERR addProblem(id, name, verb);
99
100 } else if (bh == MF_EXCL) {
101 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "problem is in database %s",
102 name.c_str());
103 }
105}
106
107MoFEMErrorCode Core::delete_problem(const std::string name) {
109 auto p_miit = pRoblems.get<Problem_mi_tag>().find(name);
110 if (p_miit == pRoblems.get<Problem_mi_tag>().end()) {
111 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "no such problem like < %s >",
112 name.c_str());
113 }
114 const EntityHandle meshset = p_miit->meshset;
115 pRoblems.get<Problem_mi_tag>().erase(p_miit);
116 // addProblem put the meshset into the partition set; do not leave a stale
117 // handle there.
118 CHKERR CommInterface::removeMeshsetFromPartition(
119 get_moab(), meshset, get_basic_entity_data_ptr()->pcommID);
120 CHKERR get_moab().delete_entities(&meshset, 1);
122}
123
124BitProblemId Core::getBitProblemId(const std::string &name) const {
125 auto p_miit = pRoblems.get<Problem_mi_tag>().find(name);
126 if (p_miit == pRoblems.get<Problem_mi_tag>().end()) {
127 THROW_MESSAGE("no such problem like " + name + " >");
128 }
129 return p_miit->getId();
130}
131
132MoFEMErrorCode Core::list_problem() const {
134 typedef Problem_multiIndex::index<BitProblemId_mi_tag>::type ProblemById;
135 const ProblemById &set_id = pRoblems.get<BitProblemId_mi_tag>();
136 ProblemById::iterator miit = set_id.begin();
137 for (; miit != set_id.end(); miit++) {
138 std::ostringstream ss;
139 ss << *miit << std::endl;
140 PetscPrintf(mofemComm, "%s", ss.str().c_str());
141 }
143}
144
146Core::modify_problem_add_finite_element(const std::string name_problem,
147 const std::string &fe_name) {
149 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
150 ProblemsByName &set = pRoblems.get<Problem_mi_tag>();
151 ProblemsByName::iterator miit = set.find(name_problem);
152 if (miit == set.end()) {
153 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "this problem <%s> is not there",
154 name_problem.c_str());
155 }
156 BitFEId f_id = getBitFEId(fe_name);
157 bool success = set.modify(miit, ProblemFiniteElementChangeBitAdd(f_id));
158 if (!success)
159 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
160 "modification unsuccessful");
162}
163
165Core::modify_problem_unset_finite_element(const std::string name_problem,
166 const std::string &fe_name) {
168 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
169 ProblemsByName &set = pRoblems.get<Problem_mi_tag>();
170 ProblemsByName::iterator miit = set.find(name_problem);
171 if (miit == set.end()) {
172 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "this problem <%s> is not there",
173 name_problem.c_str());
174 }
175 BitFEId f_id = getBitFEId(fe_name);
176 bool success = set.modify(miit, ProblemFiniteElementChangeBitUnSet(f_id));
177 if (!success)
178 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
179 "modification unsuccessful");
181}
182
184Core::modify_problem_ref_level_add_bit(const std::string &name_problem,
185 const BitRefLevel &bit) {
187 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
188 ProblemsByName &set = pRoblems.get<Problem_mi_tag>();
189 ProblemsByName::iterator miit = set.find(name_problem);
190 std::ostringstream ss;
191 ss << name_problem;
192 if (miit == set.end())
193 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "this problem <%s> is there",
194 ss.str().c_str());
195 bool success = set.modify(miit, ProblemChangeRefLevelBitAdd(bit));
196 if (!success)
197 SETERRQ(PETSC_COMM_SELF, 1, "modification unsuccessful");
199}
200
202Core::modify_problem_ref_level_set_bit(const std::string &name_problem,
203 const BitRefLevel &bit) {
205 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
206 ProblemsByName &set = pRoblems.get<Problem_mi_tag>();
207 ProblemsByName::iterator miit = set.find(name_problem);
208 std::ostringstream ss;
209 ss << name_problem;
210 if (miit == set.end())
211 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "this problem <%s> is there",
212 ss.str().c_str());
213 bool success = set.modify(miit, ProblemChangeRefLevelBitSet(bit));
214 if (!success)
215 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
216 "modification unsuccessful");
218}
219
221Core::modify_problem_mask_ref_level_add_bit(const std::string &name_problem,
222 const BitRefLevel &bit) {
224 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
225 ProblemsByName &set = pRoblems.get<Problem_mi_tag>();
226 ProblemsByName::iterator miit = set.find(name_problem);
227 if (miit == set.end()) {
228 std::ostringstream ss;
229 ss << name_problem;
230 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "this problem <%s> is there",
231 ss.str().c_str());
232 }
233 bool success = set.modify(miit, ProblemChangeRefLevelBitDofMaskAdd(bit));
234 if (!success)
235 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
236 "modification unsuccessful");
238}
239
241Core::modify_problem_mask_ref_level_set_bit(const std::string &name_problem,
242 const BitRefLevel &bit) {
243 MoFEMFunctionBegin typedef Problem_multiIndex::index<Problem_mi_tag>::type
244 ProblemsByName;
245 ProblemsByName &set = pRoblems.get<Problem_mi_tag>();
246 ProblemsByName::iterator miit = set.find(name_problem);
247 if (miit == set.end()) {
248 std::ostringstream ss;
249 ss << name_problem;
250 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "this problem <%s> is there",
251 ss.str().c_str());
252 }
253 bool success = set.modify(miit, ProblemChangeRefLevelBitDofMaskSet(bit));
254 if (!success)
255 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
256 "modification unsuccessful");
258}
259
260MoFEMErrorCode Core::build_problem_on_distributed_mesh(int verb) {
262 if (verb == -1)
263 verb = verbose;
264 Problem_multiIndex::iterator p_miit = pRoblems.begin();
265 for (; p_miit != pRoblems.end(); p_miit++) {
266 CHKERR getInterface<ProblemsManager>()->buildProblemOnDistributedMesh(
267 const_cast<Problem *>(&*p_miit), verb);
268 }
270}
271
272MoFEMErrorCode Core::clear_problem(const std::string problem_name, int verb) {
274 if (verb == -1)
275 verb = verbose;
276 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
277 ProblemsByName &prob_by_name = pRoblems.get<Problem_mi_tag>();
278 ProblemsByName::iterator p_miit = prob_by_name.find(problem_name);
279 if (p_miit == prob_by_name.end()) {
280 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
281 "problem < %s > not found, (top tip: check spelling)",
282 problem_name.c_str());
283 }
284 // zero rows
285 bool success = prob_by_name.modify(p_miit, ProblemZeroNbRowsChange());
286 if (!success)
287 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
288 "modification unsuccessful");
289 // zero cols
290 success = prob_by_name.modify(p_miit, ProblemZeroNbColsChange());
291 if (!success)
292 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
293 "modification unsuccessful");
294 // clear finite elements
295 success =
296 prob_by_name.modify(p_miit, ProblemClearNumeredFiniteElementsChange());
297 if (!success)
298 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
299 "modification unsuccessful");
300 // clear data structures
301 success = prob_by_name.modify(p_miit, ProblemClearSubProblemData());
302 if (!success)
303 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
304 "modification unsuccessful");
305 success = prob_by_name.modify(p_miit, ProblemClearComposedProblemData());
306 if (!success)
307 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
308 "modification unsuccessful");
309 if (p_miit->getRowDofsSequence())
310 p_miit->getRowDofsSequence()->clear();
311 if (p_miit->getColDofsSequence())
312 p_miit->getColDofsSequence()->clear();
313 if (p_miit->getSubData())
314 p_miit->getSubData().reset();
315 if (p_miit->getComposedProblemsData())
316 p_miit->getComposedProblemsData().reset();
318}
319
320MoFEMErrorCode Core::build_problems(int verb) {
322 if (verb == -1)
323 verb = verbose;
324 if (!((*buildMoFEM) & BUILD_FIELD))
325 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "fields not build");
326 if (!((*buildMoFEM) & BUILD_FE))
327 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "FEs not build");
328 if (!((*buildMoFEM) & BUILD_ADJ))
329 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "adjacencies not build");
330 // iterate problems
331 Problem_multiIndex::iterator p_miit = pRoblems.begin();
332 for (; p_miit != pRoblems.end(); p_miit++) {
333 Problem *problem_ptr = const_cast<Problem *>(&*p_miit);
334 CHKERR getInterface<ProblemsManager>()->buildProblem(problem_ptr, false,
335 verb);
336 }
337 *buildMoFEM |= BUILD_PROBLEM;
339}
340
341MoFEMErrorCode Core::clear_problems(int verb) {
343 if (verb == -1)
344 verb = verbose;
345 // iterate problems
346 for (auto p_miit = pRoblems.begin(); p_miit != pRoblems.end(); p_miit++)
347 CHKERR clear_problem(p_miit->getName(), verb);
349}
350
351#define SET_BASIC_METHOD(METHOD, PROBLEM_PTR) \
352 { \
353 METHOD.rAnk = rAnk; \
354 METHOD.sIze = sIze; \
355 METHOD.problemPtr = PROBLEM_PTR; \
356 METHOD.fieldsPtr = &fIelds; \
357 METHOD.refinedEntitiesPtr = &refinedEntities; \
358 METHOD.entitiesPtr = &entsFields; \
359 METHOD.dofsPtr = &dofsField; \
360 METHOD.refinedFiniteElementsPtr = &refinedFiniteElements; \
361 METHOD.finiteElementsPtr = &finiteElements; \
362 METHOD.finiteElementsEntitiesPtr = &entsFiniteElements; \
363 METHOD.adjacenciesPtr = &entFEAdjacencies; \
364 }
365
366MoFEMErrorCode Core::problem_basic_method_preProcess(const Problem *problem_ptr,
367 BasicMethod &method,
368 int verb) {
370 if (verb == -1)
371 verb = verbose;
372 // finite element
373 SET_BASIC_METHOD(method, problem_ptr)
374 PetscLogEventBegin(MOFEM_EVENT_preProcess, 0, 0, 0, 0);
375 CHKERR method.preProcess();
376 PetscLogEventEnd(MOFEM_EVENT_preProcess, 0, 0, 0, 0);
378}
379
381Core::problem_basic_method_preProcess(const std::string &problem_name,
382 BasicMethod &method, int verb) {
384 if (verb == -1)
385 verb = verbose;
386 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
387 // find p_miit
388 ProblemsByName &pRoblems_set = pRoblems.get<Problem_mi_tag>();
389 ProblemsByName::iterator p_miit = pRoblems_set.find(problem_name);
390 if (p_miit == pRoblems_set.end())
391 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "problem is not in database %s",
392 problem_name.c_str());
393 CHKERR problem_basic_method_preProcess(&*p_miit, method, verb);
395}
396
398Core::problem_basic_method_postProcess(const Problem *problem_ptr,
399 BasicMethod &method, int verb) {
401 SET_BASIC_METHOD(method, problem_ptr)
402
403 PetscLogEventBegin(MOFEM_EVENT_postProcess, 0, 0, 0, 0);
404 CHKERR method.postProcess();
405 PetscLogEventEnd(MOFEM_EVENT_postProcess, 0, 0, 0, 0);
406
408}
409
411Core::problem_basic_method_postProcess(const std::string &problem_name,
412 BasicMethod &method, int verb) {
414 if (verb == -1)
415 verb = verbose;
416 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
417
418 // find p_miit
419 ProblemsByName &pRoblems_set = pRoblems.get<Problem_mi_tag>();
420 ProblemsByName::iterator p_miit = pRoblems_set.find(problem_name);
421 if (p_miit == pRoblems_set.end())
422 SETERRQ(mofemComm, 1, "problem is not in database %s",
423 problem_name.c_str());
424
425 CHKERR problem_basic_method_postProcess(&*p_miit, method, verb);
426
428}
429
430MoFEMErrorCode Core::loop_finite_elements(
431 const Problem *problem_ptr, const std::string &fe_name, FEMethod &method,
432 int lower_rank, int upper_rank,
433 boost::shared_ptr<NumeredEntFiniteElement_multiIndex> fe_ptr, MoFEMTypes bh,
434 CacheTupleWeakPtr cache_ptr, int verb) {
436 if (verb == DEFAULT_VERBOSITY)
437 verb = verbose;
438
439 CacheTupleSharedPtr tmp_cache_ptr;
440 if (!cache_ptr.use_count()) {
441 tmp_cache_ptr = boost::make_shared<CacheTuple>();
442 CHKERR cache_problem_entities(problem_ptr->getName(), tmp_cache_ptr);
443 method.cacheWeakPtr = tmp_cache_ptr;
444 } else {
445 method.cacheWeakPtr = cache_ptr;
446 }
447
448 if (!fe_ptr)
449 fe_ptr = problem_ptr->numeredFiniteElementsPtr;
450
451 auto miit = fe_ptr->get<Composite_Name_And_Part_mi_tag>().lower_bound(
452 boost::make_tuple(fe_name, lower_rank));
453 auto hi_miit = fe_ptr->get<Composite_Name_And_Part_mi_tag>().upper_bound(
454 boost::make_tuple(fe_name, upper_rank));
455
456 if (miit == hi_miit && (bh & MF_EXIST)) {
457 if (!check_finite_element(fe_name)) {
458 SETERRQ(mofemComm, MOFEM_NOT_FOUND, "finite element < %s > not found",
459 fe_name.c_str());
460 }
461 }
462
463 method.feName = fe_name;
464 method.loopSize =
465 std::distance(miit, hi_miit); // Set numbers of elements in the loop
466 method.loHiFERank = std::make_pair(lower_rank, upper_rank);
467
468 SET_BASIC_METHOD(method, &*problem_ptr)
469
470 PetscLogEventBegin(MOFEM_EVENT_preProcess, 0, 0, 0, 0);
471 CHKERR method.preProcess();
472 PetscLogEventEnd(MOFEM_EVENT_preProcess, 0, 0, 0, 0);
473
474 PetscLogEventBegin(MOFEM_EVENT_operator, 0, 0, 0, 0);
475 for (int nn = 0; miit != hi_miit; miit++, nn++) {
476
477 method.nInTheLoop = nn; // Index of element in the loop
478 method.numeredEntFiniteElementPtr = *miit;
479
480 if (method.exeTestHook) {
481 if (method.exeTestHook(&method)) {
482 CHKERR method();
483 }
484 } else {
485 CHKERR method();
486 }
487
488 }
489 PetscLogEventEnd(MOFEM_EVENT_operator, 0, 0, 0, 0);
490
491 PetscLogEventBegin(MOFEM_EVENT_postProcess, 0, 0, 0, 0);
492 CHKERR method.postProcess();
493 PetscLogEventEnd(MOFEM_EVENT_postProcess, 0, 0, 0, 0);
494
496}
497
498MoFEMErrorCode Core::loop_finite_elements(
499 const std::string problem_name, const std::string &fe_name,
500 FEMethod &method,
501 boost::shared_ptr<NumeredEntFiniteElement_multiIndex> fe_ptr, MoFEMTypes bh,
502 CacheTupleWeakPtr cache_ptr, int verb) {
504 if (verb == DEFAULT_VERBOSITY)
505 verb = verbose;
506
507 CHKERR loop_finite_elements(problem_name, fe_name, method, rAnk, rAnk, fe_ptr,
508 bh, cache_ptr, verb);
509
511}
512
513MoFEMErrorCode Core::loop_finite_elements(
514 const std::string problem_name, const std::string &fe_name,
515 FEMethod &method, int lower_rank, int upper_rank,
516 boost::shared_ptr<NumeredEntFiniteElement_multiIndex> fe_ptr, MoFEMTypes bh,
517 CacheTupleWeakPtr cache_ptr, int verb) {
519 if (verb == DEFAULT_VERBOSITY)
520 verb = verbose;
521
522 auto &prb_by_name = pRoblems.get<Problem_mi_tag>();
523 auto p_miit = prb_by_name.find(problem_name);
524 if (p_miit == prb_by_name.end())
525 SETERRQ(mofemComm, MOFEM_INVALID_DATA, "Problem <%s> is not in database",
526 problem_name.c_str());
527
528 CHKERR loop_finite_elements(&*p_miit, fe_name, method, lower_rank, upper_rank,
529 fe_ptr, bh, cache_ptr, verb);
530
532}
533
534MoFEMErrorCode Core::loop_dofs(const Problem *problem_ptr,
535 const std::string &field_name, RowColData rc,
536 DofMethod &method, int lower_rank,
537 int upper_rank, int verb) {
539 SET_BASIC_METHOD(method, &*problem_ptr);
540 typedef NumeredDofEntity_multiIndex::index<Unique_mi_tag>::type
541 NumeredDofsByUId;
542 NumeredDofsByUId *dofs;
543 switch (rc) {
544 case ROW:
545 dofs = &problem_ptr->numeredRowDofsPtr->get<Unique_mi_tag>();
546 break;
547 case COL:
548 dofs = &problem_ptr->numeredColDofsPtr->get<Unique_mi_tag>();
549 break;
550 default:
551 SETERRQ(mofemComm, MOFEM_DATA_INCONSISTENCY, "Not implemented");
552 }
553
554 auto field_it = fIelds.get<FieldName_mi_tag>().find(field_name);
555 if (field_it != fIelds.get<FieldName_mi_tag>().end()) {
556 method.fieldPtr = *field_it;
557 } else {
558 SETERRQ(mofemComm, MOFEM_NOT_FOUND, "Field not found %s",
559 field_name.c_str());
560 }
561
562 auto miit = dofs->lower_bound(
563 FieldEntity::getLoBitNumberUId((*field_it)->getBitNumber()));
564 auto hi_miit = dofs->upper_bound(
565 FieldEntity::getHiBitNumberUId((*field_it)->getBitNumber()));
566
567 method.loopSize = std::distance(miit, hi_miit);
568 method.loHiFERank = std::make_pair(lower_rank, upper_rank);
569
570 CHKERR method.preProcess();
571
572 int nn = 0;
573 for (; miit != hi_miit; miit++, nn++) {
574 if ((*miit)->getPart() >= lower_rank && (*miit)->getPart() <= upper_rank) {
575 method.nInTheLoop = nn; // Index of element in the loop
576 method.dofPtr = miit->get()->getDofEntityPtr();
577 method.dofNumeredPtr = *miit;
578 CHKERR method();
579 }
580 }
581
582 CHKERR method.postProcess();
584}
585
586MoFEMErrorCode Core::loop_dofs(
587 const std::string &problem_name, const std::string &field_name,
588 RowColData rc, // ROW or COL
589 DofMethod &method, // Finite element instance processed on each DOF
590 int lower_rank, // Only DOFs on processor higher or equal to this are
591 // processed
592 int upper_rank, // Only DOFs lowest or higher to this are processed
593 int verb // verbosity level
594) {
596 if (verb == DEFAULT_VERBOSITY)
597 verb = verbose;
598 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
599 // find p_miit
600 ProblemsByName &pRoblems_set = pRoblems.get<Problem_mi_tag>();
601 ProblemsByName::iterator p_miit = pRoblems_set.find(problem_name);
602 if (p_miit == pRoblems_set.end())
603 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "problem not in database %s",
604 problem_name.c_str());
605 CHKERR loop_dofs(&*p_miit, field_name, rc, method, lower_rank, upper_rank,
606 verb);
608}
609
610MoFEMErrorCode Core::loop_dofs(const std::string &problem_name,
611 const std::string &field_name, RowColData rc,
612 DofMethod &method, int verb) {
614 if (verb == DEFAULT_VERBOSITY)
615 verb = verbose;
616 CHKERR loop_dofs(problem_name, field_name, rc, method, 0, sIze, verb);
618}
619
620MoFEMErrorCode Core::loop_dofs(const std::string &field_name, DofMethod &method,
621 int verb) {
623 if (verb == DEFAULT_VERBOSITY)
624 verb = verbose;
625 SET_BASIC_METHOD(method, nullptr);
626
627 auto field_it = fIelds.get<FieldName_mi_tag>().find(field_name);
628 if (field_it != fIelds.get<FieldName_mi_tag>().end()) {
629 method.fieldPtr = *field_it;
630 } else {
631 SETERRQ(mofemComm, MOFEM_NOT_FOUND, "Field not found %s",
632 field_name.c_str());
633 }
634
635 auto miit = dofsField.get<Unique_mi_tag>().lower_bound(
636 FieldEntity::getLoBitNumberUId((*field_it)->getBitNumber()));
637 auto hi_miit = dofsField.get<Unique_mi_tag>().upper_bound(
638 FieldEntity::getHiBitNumberUId((*field_it)->getBitNumber()));
639
640 method.loopSize = std::distance(miit, hi_miit);
641 method.loHiFERank = std::make_pair(0, get_comm_size());
642
643 CHKERR method.preProcess();
644 for (int nn = 0; miit != hi_miit; miit++, nn++) {
645 method.nInTheLoop = nn;
646 method.dofPtr = *miit;
647 CHKERR method();
648 }
649 CHKERR method.postProcess();
651}
652
653MoFEMErrorCode Core::loop_entities(const Problem *problem_ptr,
654 const std::string field_name, RowColData rc,
655 EntityMethod &method, int lower_rank,
656 int upper_rank, int verb) {
658 if (verb == DEFAULT_VERBOSITY)
659 verb = verbose;
660 decltype(problem_ptr->numeredRowDofsPtr) dofs;
661 switch (rc) {
662 case ROW:
663 dofs = problem_ptr->numeredRowDofsPtr;
664 break;
665 case COL:
666 dofs = problem_ptr->numeredColDofsPtr;
667 break;
668 default:
669 SETERRQ(mofemComm, MOFEM_DATA_INCONSISTENCY,
670 "It works only with rows or columns");
671 }
672
673 auto field_it = fIelds.get<FieldName_mi_tag>().find(field_name);
674 if (field_it != fIelds.get<FieldName_mi_tag>().end()) {
675 method.fieldPtr = *field_it;
676 } else {
677 SETERRQ(mofemComm, MOFEM_NOT_FOUND, "Field not found %s",
678 field_name.c_str());
679 }
680
681 auto miit = dofs->lower_bound(
682 FieldEntity::getLoBitNumberUId((*field_it)->getBitNumber()));
683 auto hi_miit = dofs->upper_bound(
684 FieldEntity::getHiBitNumberUId((*field_it)->getBitNumber()));
685
686 using FieldEntity_view_multiIndex = multi_index_container<
687
688 boost::shared_ptr<FieldEntity>,
689 indexed_by<
690
692
693 tag<Ent_mi_tag>,
694 const_mem_fun<FieldEntity::interface_type_RefEntity, EntityHandle,
695 &FieldEntity::getEnt>>
696
697 >>;
698
699 FieldEntity_view_multiIndex ents_view;
700 auto hint = ents_view.begin();
701 for (; miit != hi_miit; ++miit)
702 if ((*miit)->getPart() >= lower_rank && (*miit)->getPart() <= upper_rank)
703 ents_view.emplace_hint(hint, (*miit)->getFieldEntityPtr());
704
705 SET_BASIC_METHOD(method, problem_ptr);
706
707 method.loopSize = ents_view.size();
708 method.loHiFERank = std::make_pair(lower_rank, upper_rank);
709
710 CHKERR method.preProcess();
711 method.nInTheLoop = 0;
712 for (auto &field_ent : ents_view) {
713 method.entPtr = field_ent;
714 CHKERR method();
715 ++method.nInTheLoop;
716 }
717 CHKERR method.postProcess();
719}
720
721MoFEMErrorCode Core::loop_entities(const std::string problem_name,
722 const std::string field_name, RowColData rc,
723 EntityMethod &method, int lower_rank,
724 int upper_rank, int verb) {
726 if (verb == DEFAULT_VERBOSITY)
727 verb = verbose;
728 // find p_miit
729 auto &prb = pRoblems.get<Problem_mi_tag>();
730 auto p_miit = prb.find(problem_name);
731 if (p_miit == prb.end())
732 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "problem not in database %s",
733 problem_name.c_str());
734 CHKERR loop_entities(&*p_miit, field_name, rc, method, lower_rank, upper_rank,
735 verb);
737}
738
739MoFEMErrorCode Core::loop_entities(const std::string problem_name,
740 const std::string field_name, RowColData rc,
741 EntityMethod &method, int verb) {
742 return loop_entities(problem_name, field_name, rc, method, rAnk, rAnk, verb);
743}
744
745MoFEMErrorCode Core::loop_entities(const std::string field_name,
746 EntityMethod &method,
747 Range const *const ents, int verb) {
749 if (verb == DEFAULT_VERBOSITY)
750 verb = verbose;
751 SET_BASIC_METHOD(method, nullptr);
752
753 auto field_it = fIelds.get<FieldName_mi_tag>().find(field_name);
754 if (field_it != fIelds.get<FieldName_mi_tag>().end()) {
755 method.fieldPtr = *field_it;
756 } else {
757 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "Field not found %s",
758 field_name.c_str());
759 }
760
761 auto lo_eit = entsFields.get<Unique_mi_tag>().lower_bound(
762 FieldEntity::getLoBitNumberUId((*field_it)->getBitNumber()));
763 auto hi_eit = entsFields.get<Unique_mi_tag>().upper_bound(
764 FieldEntity::getHiBitNumberUId((*field_it)->getBitNumber()));
765
766 typedef multi_index_container<
767 boost::shared_ptr<FieldEntity>,
768 indexed_by<ordered_unique<
769 tag<Ent_mi_tag>, const_mem_fun<FieldEntity::interface_RefEntity,
770 EntityHandle, &FieldEntity::getEnt>>>>
771 FieldEntity_view_multiIndex;
772
773 FieldEntity_view_multiIndex ents_view;
774 ents_view.insert(lo_eit, hi_eit);
775
776 method.loopSize = ents_view.size();
777 method.loHiFERank = std::make_pair(0, get_comm_size());
778
779 CHKERR method.preProcess();
780 method.nInTheLoop = 0;
781
782 if (ents)
783 for (auto p = ents->const_pair_begin(); p != ents->const_pair_end(); ++p)
784 for (auto feit = ents_view.lower_bound(p->first);
785 feit != ents_view.upper_bound(p->second); ++feit) {
786 method.entPtr = *feit;
787 CHKERR method();
788 ++method.nInTheLoop;
789 }
790 else
791 for (auto &field_ent : ents_view) {
792 method.entPtr = field_ent;
793 CHKERR method();
794 ++method.nInTheLoop;
795 }
796
797 CHKERR method.postProcess();
799}
800
801MoFEMErrorCode Core::cache_problem_entities(const std::string prb_name,
802 CacheTupleWeakPtr cache_weak_ptr) {
804
805 if (auto cache_ptr = cache_weak_ptr.lock()) {
806 auto p_miit = pRoblems.get<Problem_mi_tag>().find(prb_name);
807 if (p_miit == pRoblems.get<Problem_mi_tag>().end())
808 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "problem not in database %s",
809 prb_name.c_str());
810
811 const BitRefLevel &prb_bit = p_miit->getBitRefLevel();
812 const BitRefLevel &prb_mask = p_miit->getBitRefLevelMask();
813 const BitFEId &prb_fe_id = p_miit->getBitFEId();
814
815 auto &row_dofs = p_miit->numeredRowDofsPtr;
816 auto &col_dofs = p_miit->numeredColDofsPtr;
817
818 auto &cache_data = std::get<0>(*cache_ptr);
819 auto &cache_row = std::get<1>(*cache_ptr);
820 auto &cache_col = std::get<2>(*cache_ptr);
821
822 cache_row.resize(entsFields.size());
823 if (row_dofs != col_dofs)
824 cache_col.resize(entsFields.size());
825 cache_data.resize(entsFields.size());
826
827 size_t idx = 0;
828 for (auto it = entsFields.begin(); it != entsFields.end(); ++it, ++idx) {
829
830 const auto uid = (*it)->getLocalUniqueId();
831 auto r = entFEAdjacencies.get<Unique_mi_tag>().equal_range(uid);
832 for (auto lo = r.first; lo != r.second; ++lo) {
833
834 if ((lo->getBitFEId() & prb_fe_id).any()) {
835
836 const BitRefLevel &fe_bit = lo->entFePtr->getBitRefLevel();
837
838 // if entity is not problem refinement level
839 if (((fe_bit & prb_mask) != fe_bit) || ((fe_bit & prb_bit).none()))
840 continue;
841
842 auto cache_numered_dofs = [&](auto &numered_dofs, auto &cache_vec,
843 auto &ent_cache) {
844 auto dit = numered_dofs->lower_bound(uid);
845 decltype(dit) hi_dit;
846 if (dit != numered_dofs->end())
847 hi_dit = numered_dofs->upper_bound(
848 uid | static_cast<UId>(MAX_DOFS_ON_ENTITY - 1));
849 else
850 hi_dit = dit;
851
852 ent_cache = boost::shared_ptr<EntityCacheNumeredDofs>(
853 cache_ptr, &(cache_vec[idx]));
854 cache_vec[idx].loHi = {dit, hi_dit};
855 };
856
857 auto cache_dofs = [&](auto &dofs, auto &cache_vec, auto &ent_cache) {
858 auto dit = dofs.lower_bound(uid);
859 decltype(dit) hi_dit;
860 if (dit != dofs.end())
861 hi_dit = dofs.upper_bound(
862 uid | static_cast<UId>(MAX_DOFS_ON_ENTITY - 1));
863 else
864 hi_dit = dit;
865
866 ent_cache = boost::shared_ptr<EntityCacheDofs>(cache_ptr,
867 &(cache_vec[idx]));
868 cache_vec[idx].loHi = {dit, hi_dit};
869 };
870
871 cache_numered_dofs(row_dofs, cache_row, (*it)->entityCacheRowDofs);
872 if (row_dofs != col_dofs) {
873 if (cache_col.size() != entsFields.size())
874 cache_col.resize(entsFields.size());
875 cache_numered_dofs(col_dofs, cache_col, (*it)->entityCacheColDofs);
876 } else {
877 (*it)->entityCacheColDofs = (*it)->entityCacheRowDofs;
878 }
879
880 cache_dofs(dofsField, cache_data, (*it)->entityCacheDataDofs);
881
882 break;
883 }
884 }
885 }
886 } else {
887 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Cache not allocated");
888 }
889
891}
892
893} // namespace MoFEM
#define ProblemCoreFunctionBegin
#define SET_BASIC_METHOD(METHOD, PROBLEM_PTR)
It it
Definition Schur.cpp:2568
It end
Definition Schur.cpp:2568
std::string name
@ DEFAULT_VERBOSITY
RowColData
RowColData.
@ COL
@ ROW
MoFEMTypes
Those types control how functions respond on arguments, f.e. error handling.
@ MF_EXIST
@ MF_EXCL
#define MAX_DOFS_ON_ENTITY
Maximal number of DOFs on entity.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
@ MOFEM_NOT_FOUND
Definition definitions.h:33
@ MOFEM_OPERATION_UNSUCCESSFUL
Definition definitions.h:34
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
@ MOFEM_INVALID_DATA
Definition definitions.h:36
#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 ...
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_ATTRIBUTES(channel, bit)
Add attributes to channel.
#define MOFEM_LOG_FUNCTION()
Set scope.
auto bit
set bit
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
std::bitset< BITFEID_SIZE > BitFEId
Finite element Id.
Definition Types.hpp:43
std::bitset< BITPROBLEMID_SIZE > BitProblemId
Problem Id.
Definition Types.hpp:44
uint128_t UId
Unique Id.
Definition Types.hpp:31
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40
Field_multiIndex::index< FieldName_mi_tag >::type::iterator field_it
boost::shared_ptr< CacheTuple > CacheTupleSharedPtr
list[str] ordered_unique(Iterable[str] items)
int r
Definition sdf.py:205
constexpr auto field_name

◆ SET_BASIC_METHOD

#define SET_BASIC_METHOD (   METHOD,
  PROBLEM_PTR 
)
Value:
{ \
METHOD.rAnk = rAnk; \
METHOD.sIze = sIze; \
METHOD.problemPtr = PROBLEM_PTR; \
METHOD.fieldsPtr = &fIelds; \
METHOD.refinedEntitiesPtr = &refinedEntities; \
METHOD.entitiesPtr = &entsFields; \
METHOD.dofsPtr = &dofsField; \
METHOD.refinedFiniteElementsPtr = &refinedFiniteElements; \
METHOD.finiteElementsPtr = &finiteElements; \
METHOD.finiteElementsEntitiesPtr = &entsFiniteElements; \
METHOD.adjacenciesPtr = &entFEAdjacencies; \
}

Definition at line 352 of file ProblemsCore.cpp.

353 { \
354 METHOD.rAnk = rAnk; \
355 METHOD.sIze = sIze; \
356 METHOD.problemPtr = PROBLEM_PTR; \
357 METHOD.fieldsPtr = &fIelds; \
358 METHOD.refinedEntitiesPtr = &refinedEntities; \
359 METHOD.entitiesPtr = &entsFields; \
360 METHOD.dofsPtr = &dofsField; \
361 METHOD.refinedFiniteElementsPtr = &refinedFiniteElements; \
362 METHOD.finiteElementsPtr = &finiteElements; \
363 METHOD.finiteElementsEntitiesPtr = &entsFiniteElements; \
364 METHOD.adjacenciesPtr = &entFEAdjacencies; \
365 }