v0.16.3
Loading...
Searching...
No Matches
ProblemsCore.cpp
Go to the documentation of this file.
1/** \file ProblemsCore.cpp
2 * \brief Managing complexities for problem
3 */
4
5
6#include <MoFEM.hpp>
7
8#define ProblemCoreFunctionBegin \
9 MoFEMFunctionBegin; \
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")
15
16namespace MoFEM {
17
18bool Core::check_problem(const string name) {
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()) {
22 return false;
23 }
24 return true;
25}
26
27MoFEMErrorCode Core::addProblem(const BitProblemId id, const std::string &name,
28 int verb) {
30
31 if (verb == -1)
32 verb = verbose;
33 EntityHandle meshset;
34 CHKERR get_moab().create_meshset(MESHSET_SET, meshset);
35 CHKERR get_moab().tag_set_data(th_ProblemId, &meshset, 1, &id);
36
37 // Add problem meshset to partion meshset. In case of no elements
38 // on processor part, when mesh file is read, finite element meshset is
39 // prevented from deletion by moab reader.
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();
46 Range tagged_sets;
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);
53 };
54 CHKERR add_meshset_to_partition(meshset);
55
56 void const *tag_data[] = {name.c_str()};
57 int tag_sizes[1];
58 tag_sizes[0] = name.size();
59 CHKERR get_moab().tag_set_by_ptr(th_ProblemName, &meshset, 1, tag_data,
60 tag_sizes);
61 // create entry
62 auto p = pRoblems.insert(Problem(moab, meshset));
63 if (!p.second) {
66 MOFEM_LOG("SELF", Sev::error) << "Following problem can not be added:";
67 MOFEM_LOG("SELF", Sev::error)
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) {
72 MOFEM_LOG("SELF", Sev::error)
73 << p.getName() << " id(" << p.getId().to_ulong() << ") " << id
74 << " on meshset " << p.meshset;
75 }
76 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Problem not added");
77 }
78
79 MOFEM_LOG("WORLD", Sev::inform) << "Add problem " << name;
80
82}
83
84MoFEMErrorCode Core::add_problem(const std::string &name, enum MoFEMTypes bh,
85 int verb) {
87 if (verb == -1)
88 verb = verbose;
89 auto miit = pRoblems.get<Problem_mi_tag>().find(name);
90 if (miit == pRoblems.get<Problem_mi_tag>().end()) {
91
92 int p_shift = 0;
93 for (; pRoblems.get<BitProblemId_mi_tag>().find(BitProblemId().set(
94 p_shift)) != pRoblems.get<BitProblemId_mi_tag>().end();
95 ++p_shift) {
96 }
97
98 auto id = BitProblemId().set(p_shift);
99 CHKERR addProblem(id, name, verb);
100
101 } else if (bh == MF_EXCL) {
102 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "problem is in database %s",
103 name.c_str());
104 }
106}
107
110 auto p_miit = pRoblems.get<Problem_mi_tag>().find(name);
111 if (p_miit == pRoblems.get<Problem_mi_tag>().end()) {
112 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "no such problem like < %s >",
113 name.c_str());
114 }
115 const EntityHandle meshset = p_miit->meshset;
116 pRoblems.get<Problem_mi_tag>().erase(p_miit);
117 // addProblem put the meshset into the partition set; do not leave a stale
118 // handle there.
120 get_moab(), meshset, get_basic_entity_data_ptr()->pcommID);
121 CHKERR get_moab().delete_entities(&meshset, 1);
123}
124
125BitProblemId Core::getBitProblemId(const std::string &name) const {
126 auto p_miit = pRoblems.get<Problem_mi_tag>().find(name);
127 if (p_miit == pRoblems.get<Problem_mi_tag>().end()) {
128 THROW_MESSAGE("no such problem like " + name + " >");
129 }
130 return p_miit->getId();
131}
132
135 typedef Problem_multiIndex::index<BitProblemId_mi_tag>::type ProblemById;
136 const ProblemById &set_id = pRoblems.get<BitProblemId_mi_tag>();
137 ProblemById::iterator miit = set_id.begin();
138 for (; miit != set_id.end(); miit++) {
139 std::ostringstream ss;
140 ss << *miit << std::endl;
141 PetscPrintf(mofemComm, "%s", ss.str().c_str());
142 }
144}
145
147Core::modify_problem_add_finite_element(const std::string name_problem,
148 const std::string &fe_name) {
150 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
151 ProblemsByName &set = pRoblems.get<Problem_mi_tag>();
152 ProblemsByName::iterator miit = set.find(name_problem);
153 if (miit == set.end()) {
154 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "this problem <%s> is not there",
155 name_problem.c_str());
156 }
157 BitFEId f_id = getBitFEId(fe_name);
158 bool success = set.modify(miit, ProblemFiniteElementChangeBitAdd(f_id));
159 if (!success)
160 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
161 "modification unsuccessful");
163}
164
166Core::modify_problem_unset_finite_element(const std::string name_problem,
167 const std::string &fe_name) {
169 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
170 ProblemsByName &set = pRoblems.get<Problem_mi_tag>();
171 ProblemsByName::iterator miit = set.find(name_problem);
172 if (miit == set.end()) {
173 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "this problem <%s> is not there",
174 name_problem.c_str());
175 }
176 BitFEId f_id = getBitFEId(fe_name);
177 bool success = set.modify(miit, ProblemFiniteElementChangeBitUnSet(f_id));
178 if (!success)
179 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
180 "modification unsuccessful");
182}
183
185Core::modify_problem_ref_level_add_bit(const std::string &name_problem,
186 const BitRefLevel &bit) {
188 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
189 ProblemsByName &set = pRoblems.get<Problem_mi_tag>();
190 ProblemsByName::iterator miit = set.find(name_problem);
191 std::ostringstream ss;
192 ss << name_problem;
193 if (miit == set.end())
194 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "this problem <%s> is there",
195 ss.str().c_str());
196 bool success = set.modify(miit, ProblemChangeRefLevelBitAdd(bit));
197 if (!success)
198 SETERRQ(PETSC_COMM_SELF, 1, "modification unsuccessful");
200}
201
203Core::modify_problem_ref_level_set_bit(const std::string &name_problem,
204 const BitRefLevel &bit) {
206 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
207 ProblemsByName &set = pRoblems.get<Problem_mi_tag>();
208 ProblemsByName::iterator miit = set.find(name_problem);
209 std::ostringstream ss;
210 ss << name_problem;
211 if (miit == set.end())
212 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "this problem <%s> is there",
213 ss.str().c_str());
214 bool success = set.modify(miit, ProblemChangeRefLevelBitSet(bit));
215 if (!success)
216 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
217 "modification unsuccessful");
219}
220
222Core::modify_problem_mask_ref_level_add_bit(const std::string &name_problem,
223 const BitRefLevel &bit) {
225 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
226 ProblemsByName &set = pRoblems.get<Problem_mi_tag>();
227 ProblemsByName::iterator miit = set.find(name_problem);
228 if (miit == set.end()) {
229 std::ostringstream ss;
230 ss << name_problem;
231 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "this problem <%s> is there",
232 ss.str().c_str());
233 }
234 bool success = set.modify(miit, ProblemChangeRefLevelBitDofMaskAdd(bit));
235 if (!success)
236 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
237 "modification unsuccessful");
239}
240
242Core::modify_problem_mask_ref_level_set_bit(const std::string &name_problem,
243 const BitRefLevel &bit) {
244 MoFEMFunctionBegin typedef Problem_multiIndex::index<Problem_mi_tag>::type
245 ProblemsByName;
246 ProblemsByName &set = pRoblems.get<Problem_mi_tag>();
247 ProblemsByName::iterator miit = set.find(name_problem);
248 if (miit == set.end()) {
249 std::ostringstream ss;
250 ss << name_problem;
251 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "this problem <%s> is there",
252 ss.str().c_str());
253 }
254 bool success = set.modify(miit, ProblemChangeRefLevelBitDofMaskSet(bit));
255 if (!success)
256 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
257 "modification unsuccessful");
259}
260
263 if (verb == -1)
264 verb = verbose;
265 Problem_multiIndex::iterator p_miit = pRoblems.begin();
266 for (; p_miit != pRoblems.end(); p_miit++) {
267 CHKERR getInterface<ProblemsManager>()->buildProblemOnDistributedMesh(
268 const_cast<Problem *>(&*p_miit), verb);
269 }
271}
272
273MoFEMErrorCode Core::clear_problem(const std::string problem_name, int verb) {
275 if (verb == -1)
276 verb = verbose;
277 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
278 ProblemsByName &prob_by_name = pRoblems.get<Problem_mi_tag>();
279 ProblemsByName::iterator p_miit = prob_by_name.find(problem_name);
280 if (p_miit == prob_by_name.end()) {
281 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
282 "problem < %s > not found, (top tip: check spelling)",
283 problem_name.c_str());
284 }
285 // zero rows
286 bool success = prob_by_name.modify(p_miit, ProblemZeroNbRowsChange());
287 if (!success)
288 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
289 "modification unsuccessful");
290 // zero cols
291 success = prob_by_name.modify(p_miit, ProblemZeroNbColsChange());
292 if (!success)
293 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
294 "modification unsuccessful");
295 // clear finite elements
296 success =
297 prob_by_name.modify(p_miit, ProblemClearNumeredFiniteElementsChange());
298 if (!success)
299 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
300 "modification unsuccessful");
301 // clear data structures
302 success = prob_by_name.modify(p_miit, ProblemClearSubProblemData());
303 if (!success)
304 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
305 "modification unsuccessful");
306 success = prob_by_name.modify(p_miit, ProblemClearComposedProblemData());
307 if (!success)
308 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
309 "modification unsuccessful");
310 if (p_miit->getRowDofsSequence())
311 p_miit->getRowDofsSequence()->clear();
312 if (p_miit->getColDofsSequence())
313 p_miit->getColDofsSequence()->clear();
314 if (p_miit->getSubData())
315 p_miit->getSubData().reset();
316 if (p_miit->getComposedProblemsData())
317 p_miit->getComposedProblemsData().reset();
319}
320
323 if (verb == -1)
324 verb = verbose;
325 if (!((*buildMoFEM) & BUILD_FIELD))
326 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "fields not build");
327 if (!((*buildMoFEM) & BUILD_FE))
328 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "FEs not build");
329 if (!((*buildMoFEM) & BUILD_ADJ))
330 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "adjacencies not build");
331 // iterate problems
332 Problem_multiIndex::iterator p_miit = pRoblems.begin();
333 for (; p_miit != pRoblems.end(); p_miit++) {
334 Problem *problem_ptr = const_cast<Problem *>(&*p_miit);
335 CHKERR getInterface<ProblemsManager>()->buildProblem(problem_ptr, false,
336 verb);
337 }
338 *buildMoFEM |= BUILD_PROBLEM;
340}
341
344 if (verb == -1)
345 verb = verbose;
346 // iterate problems
347 for (auto p_miit = pRoblems.begin(); p_miit != pRoblems.end(); p_miit++)
348 CHKERR clear_problem(p_miit->getName(), verb);
350}
351
352#define SET_BASIC_METHOD(METHOD, PROBLEM_PTR) \
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 }
366
368 BasicMethod &method,
369 int verb) {
371 if (verb == -1)
372 verb = verbose;
373 // finite element
374 SET_BASIC_METHOD(method, problem_ptr)
375 PetscLogEventBegin(MOFEM_EVENT_preProcess, 0, 0, 0, 0);
376 CHKERR method.preProcess();
377 PetscLogEventEnd(MOFEM_EVENT_preProcess, 0, 0, 0, 0);
379}
380
382Core::problem_basic_method_preProcess(const std::string &problem_name,
383 BasicMethod &method, int verb) {
385 if (verb == -1)
386 verb = verbose;
387 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
388 // find p_miit
389 ProblemsByName &pRoblems_set = pRoblems.get<Problem_mi_tag>();
390 ProblemsByName::iterator p_miit = pRoblems_set.find(problem_name);
391 if (p_miit == pRoblems_set.end())
392 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "problem is not in database %s",
393 problem_name.c_str());
394 CHKERR problem_basic_method_preProcess(&*p_miit, method, verb);
396}
397
400 BasicMethod &method, int verb) {
402 SET_BASIC_METHOD(method, problem_ptr)
403
404 PetscLogEventBegin(MOFEM_EVENT_postProcess, 0, 0, 0, 0);
405 CHKERR method.postProcess();
406 PetscLogEventEnd(MOFEM_EVENT_postProcess, 0, 0, 0, 0);
407
409}
410
412Core::problem_basic_method_postProcess(const std::string &problem_name,
413 BasicMethod &method, int verb) {
415 if (verb == -1)
416 verb = verbose;
417 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
418
419 // find p_miit
420 ProblemsByName &pRoblems_set = pRoblems.get<Problem_mi_tag>();
421 ProblemsByName::iterator p_miit = pRoblems_set.find(problem_name);
422 if (p_miit == pRoblems_set.end())
423 SETERRQ(mofemComm, 1, "problem is not in database %s",
424 problem_name.c_str());
425
426 CHKERR problem_basic_method_postProcess(&*p_miit, method, verb);
427
429}
430
432 const Problem *problem_ptr, const std::string &fe_name, FEMethod &method,
433 int lower_rank, int upper_rank,
434 boost::shared_ptr<NumeredEntFiniteElement_multiIndex> fe_ptr, MoFEMTypes bh,
435 CacheTupleWeakPtr cache_ptr, int verb) {
437 if (verb == DEFAULT_VERBOSITY)
438 verb = verbose;
439
440 CacheTupleSharedPtr tmp_cache_ptr;
441 if (!cache_ptr.use_count()) {
442 tmp_cache_ptr = boost::make_shared<CacheTuple>();
443 CHKERR cache_problem_entities(problem_ptr->getName(), tmp_cache_ptr);
444 method.cacheWeakPtr = tmp_cache_ptr;
445 } else {
446 method.cacheWeakPtr = cache_ptr;
447 }
448
449 if (!fe_ptr)
450 fe_ptr = problem_ptr->numeredFiniteElementsPtr;
451
452 auto miit = fe_ptr->get<Composite_Name_And_Part_mi_tag>().lower_bound(
453 boost::make_tuple(fe_name, lower_rank));
454 auto hi_miit = fe_ptr->get<Composite_Name_And_Part_mi_tag>().upper_bound(
455 boost::make_tuple(fe_name, upper_rank));
456
457 if (miit == hi_miit && (bh & MF_EXIST)) {
458 if (!check_finite_element(fe_name)) {
459 SETERRQ(mofemComm, MOFEM_NOT_FOUND, "finite element < %s > not found",
460 fe_name.c_str());
461 }
462 }
463
464 method.feName = fe_name;
465 method.loopSize =
466 std::distance(miit, hi_miit); // Set numbers of elements in the loop
467 method.loHiFERank = std::make_pair(lower_rank, upper_rank);
468
469 SET_BASIC_METHOD(method, &*problem_ptr)
470
471 PetscLogEventBegin(MOFEM_EVENT_preProcess, 0, 0, 0, 0);
472 CHKERR method.preProcess();
473 PetscLogEventEnd(MOFEM_EVENT_preProcess, 0, 0, 0, 0);
474
475 PetscLogEventBegin(MOFEM_EVENT_operator, 0, 0, 0, 0);
476 for (int nn = 0; miit != hi_miit; miit++, nn++) {
477
478 method.nInTheLoop = nn; // Index of element in the loop
479 method.numeredEntFiniteElementPtr = *miit;
480
481 if (method.exeTestHook) {
482 if (method.exeTestHook(&method)) {
483 CHKERR method();
484 }
485 } else {
486 CHKERR method();
487 }
488
489 }
490 PetscLogEventEnd(MOFEM_EVENT_operator, 0, 0, 0, 0);
491
492 PetscLogEventBegin(MOFEM_EVENT_postProcess, 0, 0, 0, 0);
493 CHKERR method.postProcess();
494 PetscLogEventEnd(MOFEM_EVENT_postProcess, 0, 0, 0, 0);
495
497}
498
500 const std::string problem_name, const std::string &fe_name,
501 FEMethod &method,
502 boost::shared_ptr<NumeredEntFiniteElement_multiIndex> fe_ptr, MoFEMTypes bh,
503 CacheTupleWeakPtr cache_ptr, int verb) {
505 if (verb == DEFAULT_VERBOSITY)
506 verb = verbose;
507
508 CHKERR loop_finite_elements(problem_name, fe_name, method, rAnk, rAnk, fe_ptr,
509 bh, cache_ptr, verb);
510
512}
513
515 const std::string problem_name, const std::string &fe_name,
516 FEMethod &method, int lower_rank, int upper_rank,
517 boost::shared_ptr<NumeredEntFiniteElement_multiIndex> fe_ptr, MoFEMTypes bh,
518 CacheTupleWeakPtr cache_ptr, int verb) {
520 if (verb == DEFAULT_VERBOSITY)
521 verb = verbose;
522
523 auto &prb_by_name = pRoblems.get<Problem_mi_tag>();
524 auto p_miit = prb_by_name.find(problem_name);
525 if (p_miit == prb_by_name.end())
526 SETERRQ(mofemComm, MOFEM_INVALID_DATA, "Problem <%s> is not in database",
527 problem_name.c_str());
528
529 CHKERR loop_finite_elements(&*p_miit, fe_name, method, lower_rank, upper_rank,
530 fe_ptr, bh, cache_ptr, verb);
531
533}
534
536 const std::string &field_name, RowColData rc,
537 DofMethod &method, int lower_rank,
538 int upper_rank, int verb) {
540 SET_BASIC_METHOD(method, &*problem_ptr);
541 typedef NumeredDofEntity_multiIndex::index<Unique_mi_tag>::type
542 NumeredDofsByUId;
543 NumeredDofsByUId *dofs;
544 switch (rc) {
545 case ROW:
546 dofs = &problem_ptr->numeredRowDofsPtr->get<Unique_mi_tag>();
547 break;
548 case COL:
549 dofs = &problem_ptr->numeredColDofsPtr->get<Unique_mi_tag>();
550 break;
551 default:
552 SETERRQ(mofemComm, MOFEM_DATA_INCONSISTENCY, "Not implemented");
553 }
554
555 auto field_it = fIelds.get<FieldName_mi_tag>().find(field_name);
556 if (field_it != fIelds.get<FieldName_mi_tag>().end()) {
557 method.fieldPtr = *field_it;
558 } else {
559 SETERRQ(mofemComm, MOFEM_NOT_FOUND, "Field not found %s",
560 field_name.c_str());
561 }
562
563 auto miit = dofs->lower_bound(
564 FieldEntity::getLoBitNumberUId((*field_it)->getBitNumber()));
565 auto hi_miit = dofs->upper_bound(
566 FieldEntity::getHiBitNumberUId((*field_it)->getBitNumber()));
567
568 method.loopSize = std::distance(miit, hi_miit);
569 method.loHiFERank = std::make_pair(lower_rank, upper_rank);
570
571 CHKERR method.preProcess();
572
573 int nn = 0;
574 for (; miit != hi_miit; miit++, nn++) {
575 if ((*miit)->getPart() >= lower_rank && (*miit)->getPart() <= upper_rank) {
576 method.nInTheLoop = nn; // Index of element in the loop
577 method.dofPtr = miit->get()->getDofEntityPtr();
578 method.dofNumeredPtr = *miit;
579 CHKERR method();
580 }
581 }
582
583 CHKERR method.postProcess();
585}
586
588 const std::string &problem_name, const std::string &field_name,
589 RowColData rc, // ROW or COL
590 DofMethod &method, // Finite element instance processed on each DOF
591 int lower_rank, // Only DOFs on processor higher or equal to this are
592 // processed
593 int upper_rank, // Only DOFs lowest or higher to this are processed
594 int verb // verbosity level
595) {
597 if (verb == DEFAULT_VERBOSITY)
598 verb = verbose;
599 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
600 // find p_miit
601 ProblemsByName &pRoblems_set = pRoblems.get<Problem_mi_tag>();
602 ProblemsByName::iterator p_miit = pRoblems_set.find(problem_name);
603 if (p_miit == pRoblems_set.end())
604 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "problem not in database %s",
605 problem_name.c_str());
606 CHKERR loop_dofs(&*p_miit, field_name, rc, method, lower_rank, upper_rank,
607 verb);
609}
610
611MoFEMErrorCode Core::loop_dofs(const std::string &problem_name,
612 const std::string &field_name, RowColData rc,
613 DofMethod &method, int verb) {
615 if (verb == DEFAULT_VERBOSITY)
616 verb = verbose;
617 CHKERR loop_dofs(problem_name, field_name, rc, method, 0, sIze, verb);
619}
620
622 int verb) {
624 if (verb == DEFAULT_VERBOSITY)
625 verb = verbose;
626 SET_BASIC_METHOD(method, nullptr);
627
628 auto field_it = fIelds.get<FieldName_mi_tag>().find(field_name);
629 if (field_it != fIelds.get<FieldName_mi_tag>().end()) {
630 method.fieldPtr = *field_it;
631 } else {
632 SETERRQ(mofemComm, MOFEM_NOT_FOUND, "Field not found %s",
633 field_name.c_str());
634 }
635
636 auto miit = dofsField.get<Unique_mi_tag>().lower_bound(
637 FieldEntity::getLoBitNumberUId((*field_it)->getBitNumber()));
638 auto hi_miit = dofsField.get<Unique_mi_tag>().upper_bound(
639 FieldEntity::getHiBitNumberUId((*field_it)->getBitNumber()));
640
641 method.loopSize = std::distance(miit, hi_miit);
642 method.loHiFERank = std::make_pair(0, get_comm_size());
643
644 CHKERR method.preProcess();
645 for (int nn = 0; miit != hi_miit; miit++, nn++) {
646 method.nInTheLoop = nn;
647 method.dofPtr = *miit;
648 CHKERR method();
649 }
650 CHKERR method.postProcess();
652}
653
655 const std::string field_name, RowColData rc,
656 EntityMethod &method, int lower_rank,
657 int upper_rank, int verb) {
659 if (verb == DEFAULT_VERBOSITY)
660 verb = verbose;
661 decltype(problem_ptr->numeredRowDofsPtr) dofs;
662 switch (rc) {
663 case ROW:
664 dofs = problem_ptr->numeredRowDofsPtr;
665 break;
666 case COL:
667 dofs = problem_ptr->numeredColDofsPtr;
668 break;
669 default:
670 SETERRQ(mofemComm, MOFEM_DATA_INCONSISTENCY,
671 "It works only with rows or columns");
672 }
673
674 auto field_it = fIelds.get<FieldName_mi_tag>().find(field_name);
675 if (field_it != fIelds.get<FieldName_mi_tag>().end()) {
676 method.fieldPtr = *field_it;
677 } else {
678 SETERRQ(mofemComm, MOFEM_NOT_FOUND, "Field not found %s",
679 field_name.c_str());
680 }
681
682 auto miit = dofs->lower_bound(
683 FieldEntity::getLoBitNumberUId((*field_it)->getBitNumber()));
684 auto hi_miit = dofs->upper_bound(
685 FieldEntity::getHiBitNumberUId((*field_it)->getBitNumber()));
686
687 using FieldEntity_view_multiIndex = multi_index_container<
688
689 boost::shared_ptr<FieldEntity>,
690 indexed_by<
691
692 ordered_unique<
693
694 tag<Ent_mi_tag>,
695 const_mem_fun<FieldEntity::interface_type_RefEntity, EntityHandle,
697
698 >>;
699
700 FieldEntity_view_multiIndex ents_view;
701 auto hint = ents_view.begin();
702 for (; miit != hi_miit; ++miit)
703 if ((*miit)->getPart() >= lower_rank && (*miit)->getPart() <= upper_rank)
704 ents_view.emplace_hint(hint, (*miit)->getFieldEntityPtr());
705
706 SET_BASIC_METHOD(method, problem_ptr);
707
708 method.loopSize = ents_view.size();
709 method.loHiFERank = std::make_pair(lower_rank, upper_rank);
710
711 CHKERR method.preProcess();
712 method.nInTheLoop = 0;
713 for (auto &field_ent : ents_view) {
714 method.entPtr = field_ent;
715 CHKERR method();
716 ++method.nInTheLoop;
717 }
718 CHKERR method.postProcess();
720}
721
722MoFEMErrorCode Core::loop_entities(const std::string problem_name,
723 const std::string field_name, RowColData rc,
724 EntityMethod &method, int lower_rank,
725 int upper_rank, int verb) {
727 if (verb == DEFAULT_VERBOSITY)
728 verb = verbose;
729 // find p_miit
730 auto &prb = pRoblems.get<Problem_mi_tag>();
731 auto p_miit = prb.find(problem_name);
732 if (p_miit == prb.end())
733 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "problem not in database %s",
734 problem_name.c_str());
735 CHKERR loop_entities(&*p_miit, field_name, rc, method, lower_rank, upper_rank,
736 verb);
738}
739
740MoFEMErrorCode Core::loop_entities(const std::string problem_name,
741 const std::string field_name, RowColData rc,
742 EntityMethod &method, int verb) {
743 return loop_entities(problem_name, field_name, rc, method, rAnk, rAnk, verb);
744}
745
747 EntityMethod &method,
748 Range const *const ents, int verb) {
750 if (verb == DEFAULT_VERBOSITY)
751 verb = verbose;
752 SET_BASIC_METHOD(method, nullptr);
753
754 auto field_it = fIelds.get<FieldName_mi_tag>().find(field_name);
755 if (field_it != fIelds.get<FieldName_mi_tag>().end()) {
756 method.fieldPtr = *field_it;
757 } else {
758 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "Field not found %s",
759 field_name.c_str());
760 }
761
762 auto lo_eit = entsFields.get<Unique_mi_tag>().lower_bound(
763 FieldEntity::getLoBitNumberUId((*field_it)->getBitNumber()));
764 auto hi_eit = entsFields.get<Unique_mi_tag>().upper_bound(
765 FieldEntity::getHiBitNumberUId((*field_it)->getBitNumber()));
766
767 typedef multi_index_container<
768 boost::shared_ptr<FieldEntity>,
769 indexed_by<ordered_unique<
770 tag<Ent_mi_tag>, const_mem_fun<FieldEntity::interface_RefEntity,
771 EntityHandle, &FieldEntity::getEnt>>>>
772 FieldEntity_view_multiIndex;
773
774 FieldEntity_view_multiIndex ents_view;
775 ents_view.insert(lo_eit, hi_eit);
776
777 method.loopSize = ents_view.size();
778 method.loHiFERank = std::make_pair(0, get_comm_size());
779
780 CHKERR method.preProcess();
781 method.nInTheLoop = 0;
782
783 if (ents)
784 for (auto p = ents->const_pair_begin(); p != ents->const_pair_end(); ++p)
785 for (auto feit = ents_view.lower_bound(p->first);
786 feit != ents_view.upper_bound(p->second); ++feit) {
787 method.entPtr = *feit;
788 CHKERR method();
789 ++method.nInTheLoop;
790 }
791 else
792 for (auto &field_ent : ents_view) {
793 method.entPtr = field_ent;
794 CHKERR method();
795 ++method.nInTheLoop;
796 }
797
798 CHKERR method.postProcess();
800}
801
803 CacheTupleWeakPtr cache_weak_ptr) {
805
806 if (auto cache_ptr = cache_weak_ptr.lock()) {
807 auto p_miit = pRoblems.get<Problem_mi_tag>().find(prb_name);
808 if (p_miit == pRoblems.get<Problem_mi_tag>().end())
809 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "problem not in database %s",
810 prb_name.c_str());
811
812 const BitRefLevel &prb_bit = p_miit->getBitRefLevel();
813 const BitRefLevel &prb_mask = p_miit->getBitRefLevelMask();
814 const BitFEId &prb_fe_id = p_miit->getBitFEId();
815
816 auto &row_dofs = p_miit->numeredRowDofsPtr;
817 auto &col_dofs = p_miit->numeredColDofsPtr;
818
819 auto &cache_data = std::get<0>(*cache_ptr);
820 auto &cache_row = std::get<1>(*cache_ptr);
821 auto &cache_col = std::get<2>(*cache_ptr);
822
823 cache_row.resize(entsFields.size());
824 if (row_dofs != col_dofs)
825 cache_col.resize(entsFields.size());
826 cache_data.resize(entsFields.size());
827
828 size_t idx = 0;
829 for (auto it = entsFields.begin(); it != entsFields.end(); ++it, ++idx) {
830
831 const auto uid = (*it)->getLocalUniqueId();
832 auto r = entFEAdjacencies.get<Unique_mi_tag>().equal_range(uid);
833 for (auto lo = r.first; lo != r.second; ++lo) {
834
835 if ((lo->getBitFEId() & prb_fe_id).any()) {
836
837 const BitRefLevel &fe_bit = lo->entFePtr->getBitRefLevel();
838
839 // if entity is not problem refinement level
840 if (((fe_bit & prb_mask) != fe_bit) || ((fe_bit & prb_bit).none()))
841 continue;
842
843 auto cache_numered_dofs = [&](auto &numered_dofs, auto &cache_vec,
844 auto &ent_cache) {
845 auto dit = numered_dofs->lower_bound(uid);
846 decltype(dit) hi_dit;
847 if (dit != numered_dofs->end())
848 hi_dit = numered_dofs->upper_bound(
849 uid | static_cast<UId>(MAX_DOFS_ON_ENTITY - 1));
850 else
851 hi_dit = dit;
852
853 ent_cache = boost::shared_ptr<EntityCacheNumeredDofs>(
854 cache_ptr, &(cache_vec[idx]));
855 cache_vec[idx].loHi = {dit, hi_dit};
856 };
857
858 auto cache_dofs = [&](auto &dofs, auto &cache_vec, auto &ent_cache) {
859 auto dit = dofs.lower_bound(uid);
860 decltype(dit) hi_dit;
861 if (dit != dofs.end())
862 hi_dit = dofs.upper_bound(
863 uid | static_cast<UId>(MAX_DOFS_ON_ENTITY - 1));
864 else
865 hi_dit = dit;
866
867 ent_cache = boost::shared_ptr<EntityCacheDofs>(cache_ptr,
868 &(cache_vec[idx]));
869 cache_vec[idx].loHi = {dit, hi_dit};
870 };
871
872 cache_numered_dofs(row_dofs, cache_row, (*it)->entityCacheRowDofs);
873 if (row_dofs != col_dofs) {
874 if (cache_col.size() != entsFields.size())
875 cache_col.resize(entsFields.size());
876 cache_numered_dofs(col_dofs, cache_col, (*it)->entityCacheColDofs);
877 } else {
878 (*it)->entityCacheColDofs = (*it)->entityCacheRowDofs;
879 }
880
881 cache_dofs(dofsField, cache_data, (*it)->entityCacheDataDofs);
882
883 break;
884 }
885 }
886 }
887 } else {
888 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Cache not allocated");
889 }
890
892}
893
894} // 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()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ 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
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
Field_multiIndex::index< FieldName_mi_tag >::type::iterator field_it
boost::shared_ptr< CacheTuple > CacheTupleSharedPtr
boost::weak_ptr< CacheTuple > CacheTupleWeakPtr
constexpr auto field_name
Data structure to exchange data between MoFEM and User Loop Methods.
int loopSize
Total number of methods to process in the loop.
std::pair< int, int > loHiFERank
Processor rank range for distributed finite element iteration.
int nInTheLoop
Current index of processed method in the loop.
virtual MoFEMErrorCode postProcess()
Post-processing function executed at loop completion.
virtual MoFEMErrorCode preProcess()
Pre-processing function executed at loop initialization.
boost::weak_ptr< CacheTuple > cacheWeakPtr
Weak pointer to cached entity data.
static MoFEMErrorCode removeMeshsetFromPartition(moab::Interface &moab, const EntityHandle meshset, const int pcomm_id=MYPCOMM_INDEX)
Remove a meshset from all partition sets before it is deleted.
MoFEMErrorCode modify_problem_mask_ref_level_add_bit(const std::string &name_problem, const BitRefLevel &bit)
set dof mask ref level for problem
MoFEMErrorCode modify_problem_unset_finite_element(const std::string name_problem, const std::string &fe_name)
unset finite element from problem, this remove entities assigned to finite element to a particular pr...
MoFEMErrorCode problem_basic_method_postProcess(const Problem *problem_ptr, BasicMethod &method, int verb=DEFAULT_VERBOSITY)
Set data for BasicMethod.
MoFEMErrorCode loop_entities(const Problem *problem_ptr, const std::string field_name, RowColData rc, EntityMethod &method, int lower_rank, int upper_rank, int verb=DEFAULT_VERBOSITY)
Loop over field entities in the problem.
MoFEMErrorCode list_problem() const
list problems
DEPRECATED MoFEMErrorCode build_problem_on_distributed_mesh(int verb=DEFAULT_VERBOSITY)
MoFEMErrorCode add_problem(const std::string &name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)
Add problem.
MoFEMErrorCode modify_problem_add_finite_element(const std::string name_problem, const std::string &fe_name)
add finite element to problem, this add entities assigned to finite element to a particular problem
MoFEMErrorCode problem_basic_method_preProcess(const Problem *problem_ptr, BasicMethod &method, int verb=DEFAULT_VERBOSITY)
Set data for BasicMethod.
MoFEMErrorCode modify_problem_ref_level_add_bit(const std::string &name_problem, const BitRefLevel &bit)
add ref level to problem
MoFEMErrorCode loop_finite_elements(const Problem *problem_ptr, const std::string &fe_name, FEMethod &method, int lower_rank, int upper_rank, boost::shared_ptr< NumeredEntFiniteElement_multiIndex > fe_ptr=nullptr, MoFEMTypes bh=MF_EXIST, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr(), int verb=DEFAULT_VERBOSITY)
Make a loop over finite elements on partitions from upper to lower rank.
MoFEMErrorCode clear_problem(const std::string name, int verb=DEFAULT_VERBOSITY)
clear problem
MoFEMErrorCode addProblem(const BitProblemId id, const std::string &name, int verb=DEFAULT_VERBOSITY)
add problem
MoFEMErrorCode clear_problems(int verb=DEFAULT_VERBOSITY)
clear problems
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)
Make a loop over dofs.
MoFEMErrorCode modify_problem_mask_ref_level_set_bit(const std::string &name_problem, const BitRefLevel &bit)
set dof mask ref level for problem
bool check_problem(const std::string name)
check if problem exist
BitProblemId getBitProblemId(const std::string &name) const
DEPRECATED MoFEMErrorCode build_problems(int verb=DEFAULT_VERBOSITY)
MoFEMErrorCode cache_problem_entities(const std::string prb_name, CacheTupleWeakPtr cache_ptr)
Cache variables.
MoFEMErrorCode modify_problem_ref_level_set_bit(const std::string &name_problem, const BitRefLevel &bit)
set ref level for problem
MoFEMErrorCode delete_problem(const std::string name)
Delete problem.
Data structure for user loop methods on degrees of freedom (DOFs)
boost::shared_ptr< DofEntity > dofPtr
Shared pointer to DOF entity data.
boost::shared_ptr< NumeredDofEntity > dofNumeredPtr
Shared pointer to numbered DOF entity data.
boost::shared_ptr< Field > fieldPtr
Shared pointer to field information.
Data structure for user loop methods on entities.
boost::shared_ptr< Field > fieldPtr
Shared pointer to field information.
boost::shared_ptr< FieldEntity > entPtr
Shared pointer to field entity data.
Structure for user loop methods on finite elements.
std::string feName
Name of the finite element being processed.
boost::shared_ptr< const NumeredEntFiniteElement > numeredEntFiniteElementPtr
Shared pointer to finite element database structure.
boost::function< bool(FEMethod *fe_method_ptr)> exeTestHook
Test function to determine if element should be skipped.
static UId getHiBitNumberUId(const FieldBitNumber bit_number)
static UId getLoBitNumberUId(const FieldBitNumber bit_number)
interface_RefEntity< RefEntity > interface_type_RefEntity
MultiIndex Tag for field name.
Clear composed problem data structure.
Clear sub-problem data structure.
keeps basic data about problem
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredRowDofsPtr
store DOFs on rows for this problem
boost::shared_ptr< NumeredEntFiniteElement_multiIndex > numeredFiniteElementsPtr
store finite elements
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredColDofsPtr
store DOFs on columns for this problem
interface_RefEntity(const boost::shared_ptr< REFENT > &sptr)