v0.16.3
Loading...
Searching...
No Matches
ProblemsManager.cpp
Go to the documentation of this file.
1/** \file ProblemsManager.cpp
2 * \brief Managing complexities for problem
3 * \ingroup mofem_problems_manager
4 */
5
6namespace MoFEM {
7
8#define ProblemManagerFunctionBegin \
9 MoFEMFunctionBegin; \
10 MOFEM_LOG_CHANNEL("WORLD"); \
11 MOFEM_LOG_CHANNEL("SYNC"); \
12 MOFEM_LOG_FUNCTION(); \
13 MOFEM_LOG_TAG("SYNC", "ProblemsManager"); \
14 MOFEM_LOG_TAG("WORLD", "ProblemsManager")
15
17 IdxDataType(const UId uid, const int dof) {
18 bcopy(&uid, dAta, 4 * sizeof(int));
19 dAta[4] = dof;
20 }
21
22private:
23 int dAta[5];
24};
25
27 IdxDataTypePtr(const int *ptr) : pTr(ptr) {}
28 inline int getGlobalIdx() const {
29 int global_dof = pTr[4];
30 return global_dof;
31 }
32 inline UId getUId() const {
33 unsigned int b0, b1, b2, b3;
34 bcopy(&pTr[0], &b0, sizeof(int));
35 bcopy(&pTr[1], &b1, sizeof(int));
36 bcopy(&pTr[2], &b2, sizeof(int));
37 bcopy(&pTr[3], &b3, sizeof(int));
38 UId uid = static_cast<UId>(b0) | static_cast<UId>(b1) << 8 * sizeof(int) |
39 static_cast<UId>(b2) << 16 * sizeof(int) |
40 static_cast<UId>(b3) << 24 * sizeof(int);
41 return uid;
42 }
43
44private:
45 const int *pTr;
46};
47
48/// Publish stable records using hints shared by all five ordered indices.
51 const boost::shared_ptr<std::vector<NumeredDofEntity>> &sequence_ptr,
52 const bool serial_uid_numbering = false) {
53 if (sequence_ptr->empty())
54 return;
55 const auto end_hint = dofs.end();
56 // The serial main builders assign numbering in UID order. Within one
57 // field, entity handles have that order too, so no group checks are needed.
58 if (serial_uid_numbering && dofs.empty() &&
59 sequence_ptr->front().getFieldEntityPtr()->getBitNumber() ==
60 sequence_ptr->back().getFieldEntityPtr()->getBitNumber()) {
61 for (auto &dof : *sequence_ptr)
62 dofs.emplace_hint(end_hint, sequence_ptr, &dof);
63 return;
64 }
65 auto first = sequence_ptr->begin();
66 while (first != sequence_ptr->end()) {
67 const auto &head = *first;
68 const bool append =
69 dofs.empty() ||
70 ((*dofs.rbegin())->getLocalUniqueId() < head.getLocalUniqueId() &&
71 (*dofs.get<Part_mi_tag>().rbegin())->getPart() <= head.getPart() &&
72 (*dofs.get<PetscGlobalIdx_mi_tag>().rbegin())
73 ->getPetscGlobalDofIdx() <= head.getPetscGlobalDofIdx() &&
74 (*dofs.get<PetscLocalIdx_mi_tag>().rbegin())->getPetscLocalDofIdx() <=
75 head.getPetscLocalDofIdx() &&
76 (*dofs.get<Ent_mi_tag>().rbegin())->getEnt() <= head.getEnt());
77
78 auto last = std::next(first);
79 auto previous = first;
80 // Split at field/entity boundaries and at incompatible numbering runs.
81 // Equal owner/entity keys are kept in their original publication order.
82 while (last != sequence_ptr->end() &&
83 last->getEntLocalUniqueId() == head.getEntLocalUniqueId() &&
84 last->getPart() == head.getPart() &&
85 previous->getLocalUniqueId() < last->getLocalUniqueId() &&
86 previous->getPetscGlobalDofIdx() <= last->getPetscGlobalDofIdx() &&
87 previous->getPetscLocalDofIdx() <= last->getPetscLocalDofIdx()) {
88 previous = last;
89 ++last;
90 }
91
92 if (append) {
93 for (auto it = first; it != last; ++it)
94 dofs.emplace_hint(end_hint, sequence_ptr, &*it);
95 } else {
96 // Insert the largest key first, then insert before its successor.
97 // Interleaved keys from earlier groups may still need tree searches.
98 auto hint = end_hint;
99 auto it = last;
100 while (it != first) {
101 --it;
102 hint = dofs.emplace_hint(hint, sequence_ptr, &*it);
103 }
104 }
105 first = last;
106 }
107}
108
110ProblemsManager::query_interface(boost::typeindex::type_index type_index,
111 UnknownInterface **iface) const {
112 *iface = const_cast<ProblemsManager *>(this);
113 return 0;
114}
115
117 : cOre(const_cast<MoFEM::Core &>(core)),
118 buildProblemFromFields(PETSC_FALSE),
119 synchroniseProblemEntities(PETSC_FALSE) {
120 PetscLogEventRegister("ProblemsManager", 0, &MOFEM_EVENT_ProblemsManager);
121}
122
124 MoFEM::Interface &m_field = cOre;
126 PetscOptionsBegin(m_field.get_comm(), "", "Problem manager", "none");
127 {
128 CHKERR PetscOptionsBool(
129 "-problem_build_from_fields",
130 "Add DOFs to problem directly from fields not through DOFs on elements",
132 }
133 PetscOptionsEnd();
135}
136
138 const Range &ents, const int dim, const int adj_dim, const int n_parts,
139 Tag *th_vertex_weights, Tag *th_edge_weights, Tag *th_part_weights,
140 int verb, const bool debug) {
141 return static_cast<MoFEM::Interface &>(cOre)
142 .getInterface<CommInterface>()
143 ->partitionMesh(ents, dim, adj_dim, n_parts, th_vertex_weights,
144 th_edge_weights, th_part_weights, verb, debug);
145}
146
148 const bool square_matrix,
149 int verb) {
150
151 MoFEM::Interface &m_field = cOre;
153 if (!(cOre.getBuildMoFEM() & (1 << 0)))
154 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "fields not build");
155 if (!(cOre.getBuildMoFEM() & (1 << 1)))
156 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "FEs not build");
157 if (!(cOre.getBuildMoFEM() & (1 << 2)))
158 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "adjacencies not build");
159 const Problem *problem_ptr;
160 CHKERR m_field.get_problem(name, &problem_ptr);
161 CHKERR buildProblem(const_cast<Problem *>(problem_ptr), square_matrix, verb);
162 cOre.getBuildMoFEM() |= 1 << 3; // It is assumed that user who uses this
163 // function knows what he is doing
165}
166
168 const bool square_matrix,
169 int verb) {
170 MoFEM::Interface &m_field = cOre;
171 auto dofs_field_ptr = m_field.get_dofs();
172 auto ents_field_ptr = m_field.get_field_ents();
173 auto adjacencies_ptr = m_field.get_ents_elements_adjacency();
175 PetscLogEventBegin(MOFEM_EVENT_ProblemsManager, 0, 0, 0, 0);
176
177 // Note: Only allowed changes on problem_ptr structure which not influence
178 // multi-index.
179
180 if (problem_ptr->getBitRefLevel().none()) {
181 SETERRQ(PETSC_COMM_SELF, 1, "problem <%s> refinement level not set",
182 problem_ptr->getName().c_str());
183 }
184 CHKERR m_field.clear_problem(problem_ptr->getName());
185
186 // zero finite elements
187 problem_ptr->numeredFiniteElementsPtr->clear();
188
189 // Field entities are visited in UID order and each contributes its DOF
190 // range at most once per view, so plain vectors arrive sorted and unique;
191 // an indexed view would pay two tree insertions per DOF for nothing.
192 using DofPtrVector = std::vector<boost::shared_ptr<DofEntity>>;
193 DofPtrVector dofs_rows, dofs_cols;
194 auto make_rows_and_cols_view = [&](auto &dofs_rows, auto &dofs_cols) {
196 for (auto it = ents_field_ptr->begin(); it != ents_field_ptr->end(); ++it) {
197
198 const auto uid = (*it)->getLocalUniqueId();
199
200 auto r = adjacencies_ptr->get<Unique_mi_tag>().equal_range(uid);
201 for (auto lo = r.first; lo != r.second; ++lo) {
202
203 if ((lo->getBitFEId() & problem_ptr->getBitFEId()).any()) {
204 std::array<bool, 2> row_col = {false, false};
205
206 const BitRefLevel &prb_bit = problem_ptr->getBitRefLevel();
207 const BitRefLevel &prb_mask = problem_ptr->getBitRefLevelMask();
208 const BitRefLevel &fe_bit = lo->entFePtr->getBitRefLevel();
209
210 // if entity is not problem refinement level
211 if ((fe_bit & prb_mask) != fe_bit)
212 continue;
213 if ((fe_bit & prb_bit).none())
214 continue;
215
216 auto add_to_view = [&](auto &nb_dofs, auto &view, auto rc) {
217 auto dit = nb_dofs->lower_bound(uid);
218 decltype(dit) hi_dit;
219 if (dit != nb_dofs->end()) {
220 hi_dit = nb_dofs->upper_bound(
221 uid | static_cast<UId>(MAX_DOFS_ON_ENTITY - 1));
222 view.insert(view.end(), dit, hi_dit);
223 row_col[rc] = true;
224 }
225 };
226
227 if ((lo->entFePtr->getBitFieldIdRow() & (*it)->getId()).any())
228 add_to_view(dofs_field_ptr, dofs_rows, ROW);
229
230 if (!square_matrix)
231 if ((lo->entFePtr->getBitFieldIdCol() & (*it)->getId()).any())
232 add_to_view(dofs_field_ptr, dofs_cols, COL);
233
234 if (square_matrix && row_col[ROW])
235 break;
236 else if (row_col[ROW] && row_col[COL])
237 break;
238 }
239 }
240 }
241 auto by_uid = [](const auto &a, const auto &b) {
242 return a->getLocalUniqueId() < b->getLocalUniqueId();
243 };
244 for (auto *view : {&dofs_rows, &dofs_cols}) {
245 if (!std::is_sorted(view->begin(), view->end(), by_uid))
246 std::sort(view->begin(), view->end(), by_uid);
247 }
249 };
250
251 CHKERR make_rows_and_cols_view(dofs_rows, dofs_cols);
252
253 // Add row dofs to problem
254 {
255 // zero rows
256 problem_ptr->nbDofsRow = 0;
257 problem_ptr->nbLocDofsRow = 0;
258 problem_ptr->nbGhostDofsRow = 0;
259
260 // add dofs for rows
261 int count_dofs = 0;
262 for (auto &dof : dofs_rows)
263 if (dof->getActive())
264 ++count_dofs;
265 boost::shared_ptr<std::vector<NumeredDofEntity>> dofs_array =
266 boost::shared_ptr<std::vector<NumeredDofEntity>>(
267 new std::vector<NumeredDofEntity>());
268 problem_ptr->getRowDofsSequence()->push_back(dofs_array);
269 dofs_array->reserve(count_dofs);
270 // The global index is the insertion order, which is the UID order and
271 // the same on every rank. On one rank it is final, with part 0 and the
272 // same local index, so partitionProblem finds nothing to modify. On more
273 // ranks it is provisional: part and local index stay -1 and
274 // partitionProblem renumbers through the adjacency of this ordering.
275 const bool serial = m_field.get_comm_size() == 1;
276 for (auto miit = dofs_rows.begin(); miit != dofs_rows.end(); miit++) {
277 if ((*miit)->getActive()) {
278 dofs_array->emplace_back(*miit);
279 auto &dof = dofs_array->back();
280 dof.petscGloablDofIdx = (problem_ptr->nbDofsRow)++;
281 if (serial) {
282 dof.pArt = 0;
283 dof.petscLocalDofIdx = dof.petscGloablDofIdx;
284 }
285 }
286 }
287 publish_numbered_dofs(*problem_ptr->numeredRowDofsPtr, dofs_array, serial);
288 }
289
290 // Add col dofs to problem
291 if (!square_matrix) {
292 // zero cols
293 problem_ptr->nbDofsCol = 0;
294 problem_ptr->nbLocDofsCol = 0;
295 problem_ptr->nbGhostDofsCol = 0;
296
297 // add dofs for cols
298 int count_dofs = 0;
299 for (auto &dof : dofs_cols)
300 if (dof->getActive())
301 ++count_dofs;
302
303 boost::shared_ptr<std::vector<NumeredDofEntity>> dofs_array =
304 boost::shared_ptr<std::vector<NumeredDofEntity>>(
305 new std::vector<NumeredDofEntity>());
306 problem_ptr->getColDofsSequence()->push_back(dofs_array);
307 dofs_array->reserve(count_dofs);
308 for (auto miit = dofs_cols.begin(); miit != dofs_cols.end(); miit++) {
309 if (!(*miit)->getActive()) {
310 continue;
311 }
312 dofs_array->emplace_back(*miit);
313 auto &dof = dofs_array->back();
314 dof.petscGloablDofIdx = problem_ptr->nbDofsCol++;
315 if (m_field.get_comm_size() == 1) {
316 dof.pArt = 0;
317 dof.petscLocalDofIdx = dof.petscGloablDofIdx;
318 }
319 }
320 publish_numbered_dofs(*problem_ptr->numeredColDofsPtr, dofs_array,
321 m_field.get_comm_size() == 1);
322 } else {
323 problem_ptr->numeredColDofsPtr = problem_ptr->numeredRowDofsPtr;
324 problem_ptr->nbLocDofsCol = problem_ptr->nbLocDofsRow;
325 problem_ptr->nbDofsCol = problem_ptr->nbDofsRow;
326 }
327
328 // job done, some debugging and postprocessing
329 if (verb >= VERBOSE) {
330 MOFEM_LOG("SYNC", Sev::verbose)
331 << problem_ptr->getName() << " Nb. local dofs "
332 << problem_ptr->numeredRowDofsPtr->size() << " by "
333 << problem_ptr->numeredColDofsPtr->size();
334 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::verbose);
335 }
336
337 if (verb >= NOISY) {
338 MOFEM_LOG("SYNC", Sev::noisy)
339 << "FEs row dofs " << *problem_ptr << " Nb. row dof "
340 << problem_ptr->getNbDofsRow();
341 for (auto &miit : *problem_ptr->numeredRowDofsPtr)
342 MOFEM_LOG("SYNC", Sev::noisy) << *miit;
343
344 MOFEM_LOG("SYNC", Sev::noisy)
345 << "FEs col dofs " << *problem_ptr << " Nb. col dof "
346 << problem_ptr->getNbDofsCol();
347 for (auto &miit : *problem_ptr->numeredColDofsPtr)
348 MOFEM_LOG("SYNC", Sev::noisy) << *miit;
349 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::noisy);
350 }
351
352 cOre.getBuildMoFEM() |= Core::BUILD_PROBLEM; // It is assumed that user who
353 // uses this function knows
354 // what he is doing
355
356 PetscLogEventEnd(MOFEM_EVENT_ProblemsManager, 0, 0, 0, 0);
357
359}
360
362 const std::string name, const bool square_matrix, int verb) {
363 MoFEM::Interface &m_field = cOre;
365
367 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "fields not build");
368 if (!((cOre.getBuildMoFEM()) & Core::BUILD_FE))
369 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "FEs not build");
371 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "adjacencies not build");
372
373 const Problem *problem_ptr;
374 CHKERR m_field.get_problem(name, &problem_ptr);
375 CHKERR buildProblemOnDistributedMesh(const_cast<Problem *>(problem_ptr),
376 square_matrix, verb);
377
380
382}
383
385 const std::string &name, const BitRefLevel target_bit,
386 const BitRefLevel target_mask, const bool square_matrix, int verb,
387 SmartPetscObj<IS> *old_row_indices, SmartPetscObj<IS> *new_row_indices) {
388 MoFEM::Interface &m_field = cOre;
390
391 if (target_bit.none())
392 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
393 "rebuild of <%s>: target bit ref level is not set", name.c_str());
394
395 using ProblemsByName = Problem_multiIndex::index<Problem_mi_tag>::type;
396 auto &problems_by_name = const_cast<ProblemsByName &>(
397 m_field.get_problems()->get<Problem_mi_tag>());
398 auto live_it = problems_by_name.find(name);
399 if (live_it == problems_by_name.end())
400 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND,
401 "problem <%s> is not found (top tip: check spelling)",
402 name.c_str());
403 if (live_it->getSubData() || live_it->getComposedProblemsData())
404 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
405 "rebuild of <%s>: only a parent problem is rebuilt in place",
406 name.c_str());
407
408 auto modify = [&](auto it, auto &&change) {
410 if (!problems_by_name.modify(it, change))
411 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
412 "modification unsuccessful");
414 };
415
416 // Stage: a hidden problem with the live problem's elements and the target
417 // selector, built by the distributed builder. The live problem is not
418 // touched until the staged containers are published below, so a failure
419 // of the build leaves it as it was.
420 const std::string staged_name = name + "__REBUILD_STAGE";
421 if (m_field.check_problem(staged_name))
422 CHKERR m_field.delete_problem(staged_name);
423 CHKERR m_field.add_problem(staged_name, MF_EXCL, verb);
424 auto staged_it = problems_by_name.find(staged_name);
425 CHKERR modify(staged_it,
426 ProblemFiniteElementChangeBitAdd(live_it->getBitFEId()));
427 CHKERR modify(staged_it, ProblemChangeRefLevelBitSet(target_bit));
428 CHKERR modify(staged_it, ProblemChangeRefLevelBitDofMaskSet(target_mask));
429 staged_it->getEmptyFieldBlocks() = live_it->getEmptyFieldBlocks();
430 CHKERR buildProblemOnDistributedMesh(staged_name, square_matrix, verb);
431
432 // Survivors: DOFs owned by this rank in the new numbering that exist in
433 // the old one, with their old and new global row indices in one order.
434 if (old_row_indices || new_row_indices) {
435 std::vector<PetscInt> old_idx, new_idx;
436 const auto &old_by_uid =
437 live_it->getNumeredRowDofsPtr()->get<Unique_mi_tag>();
438 const auto &new_by_local =
439 staged_it->getNumeredRowDofsPtr()->get<PetscLocalIdx_mi_tag>();
440 const auto hi = new_by_local.lower_bound(staged_it->getNbLocalDofsRow());
441 for (auto it = new_by_local.lower_bound(0); it != hi; ++it) {
442 auto old_it = old_by_uid.find((*it)->getLocalUniqueId());
443 if (old_it != old_by_uid.end() &&
444 (*old_it)->getPetscGlobalDofIdx() >= 0) {
445 old_idx.push_back((*old_it)->getPetscGlobalDofIdx());
446 new_idx.push_back((*it)->getPetscGlobalDofIdx());
447 }
448 }
449 auto make_is = [&](std::vector<PetscInt> &idx) {
450 return createISGeneral(m_field.get_comm(), idx.size(),
451 idx.empty() ? nullptr : idx.data(),
452 PETSC_COPY_VALUES);
453 };
454 if (old_row_indices)
455 *old_row_indices = make_is(old_idx);
456 if (new_row_indices)
457 *new_row_indices = make_is(new_idx);
458 }
459
460 // Publish: the live problem takes the staged containers, sequences, counts
461 // and the target selector; the staged problem takes the old numbering and
462 // is deleted with it. The numbered finite elements are cleared, to be
463 // rebuilt by partitionFiniteElements.
464 const Problem &live = *live_it;
465 const Problem &staged = *staged_it;
466 std::swap(live.numeredRowDofsPtr, staged.numeredRowDofsPtr);
467 std::swap(live.numeredColDofsPtr, staged.numeredColDofsPtr);
468 std::swap(live.getRowDofsSequence(), staged.getRowDofsSequence());
469 std::swap(live.getColDofsSequence(), staged.getColDofsSequence());
470 std::swap(live.nbDofsRow, staged.nbDofsRow);
471 std::swap(live.nbDofsCol, staged.nbDofsCol);
472 std::swap(live.nbLocDofsRow, staged.nbLocDofsRow);
473 std::swap(live.nbLocDofsCol, staged.nbLocDofsCol);
474 std::swap(live.nbGhostDofsRow, staged.nbGhostDofsRow);
475 std::swap(live.nbGhostDofsCol, staged.nbGhostDofsCol);
477 CHKERR modify(live_it, ProblemChangeRefLevelBitSet(target_bit));
478 CHKERR modify(live_it, ProblemChangeRefLevelBitDofMaskSet(target_mask));
479 CHKERR m_field.delete_problem(staged_name);
480
481 MOFEM_LOG("WORLD", Sev::verbose)
482 << "Rebuilt problem " << name << " in place: " << live.getNbDofsRow()
483 << " dofs (" << live.getNbLocalDofsRow() << " local)";
484
486}
487
489 Problem *problem_ptr, const bool square_matrix, int verb) {
490 MoFEM::Interface &m_field = cOre;
491 auto fields_ptr = m_field.get_fields();
492 auto fe_ptr = m_field.get_finite_elements();
493 auto dofs_field_ptr = m_field.get_dofs();
495 PetscLogEventBegin(MOFEM_EVENT_ProblemsManager, 0, 0, 0, 0);
496
497 // Fetched once: every owner/status query below would otherwise look the
498 // ParallelComm up through two tag operations.
499 auto *pcomm = ParallelComm::get_pcomm(
500 &m_field.get_moab(), m_field.get_basic_entity_data_ptr()->pcommID);
501
502 // clear data structures
503 CHKERR m_field.clear_problem(problem_ptr->getName());
504
506
507 if (problem_ptr->getBitRefLevel().none())
508 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND,
509 "problem <%s> refinement level not set",
510 problem_ptr->getName().c_str());
511
512 int loop_size = 2;
513 if (square_matrix) {
514 loop_size = 1;
515 problem_ptr->numeredColDofsPtr = problem_ptr->numeredRowDofsPtr;
516 } else if (problem_ptr->numeredColDofsPtr == problem_ptr->numeredRowDofsPtr) {
517 problem_ptr->numeredColDofsPtr =
518 boost::shared_ptr<NumeredDofEntity_multiIndex>(
520 }
521
522 const BitRefLevel &prb_bit = problem_ptr->getBitRefLevel();
523 const BitRefLevel &prb_mask = problem_ptr->getBitRefLevelMask();
524
525 // Rows and columns DOF views as plain vectors of DOF pointers; they are
526 // sorted by UID and made unique once all selection and synchronisation
527 // has added to them (finalise_views below). An indexed view would pay two
528 // tree insertions per DOF for the same result.
529 using DofPtrVector = std::vector<boost::shared_ptr<DofEntity>>;
530 DofPtrVector dofs_rows, dofs_cols;
531
532 // Add DOFs to problem by visiting all elements and adding DOFs from
533 // elements to the problem
534 if (buildProblemFromFields == PETSC_FALSE) {
535
536 auto make_rows_and_cols_view = [&](auto &dofs_rows, auto &dofs_cols) {
537 auto ents_field_ptr = m_field.get_field_ents();
538 auto adjacencies_ptr = m_field.get_ents_elements_adjacency();
540 for (auto it = ents_field_ptr->begin(); it != ents_field_ptr->end();
541 ++it) {
542
543 const auto uid = (*it)->getLocalUniqueId();
544
545 auto r = adjacencies_ptr->get<Unique_mi_tag>().equal_range(uid);
546 for (auto lo = r.first; lo != r.second; ++lo) {
547
548 if ((lo->getBitFEId() & problem_ptr->getBitFEId()).any()) {
549 std::array<bool, 2> row_col = {false, false};
550
551 const BitRefLevel &fe_bit = lo->entFePtr->getBitRefLevel();
552
553 // if entity is not problem refinement level
554 if ((fe_bit & prb_bit).any() && (fe_bit & prb_mask) == fe_bit) {
555
556 auto add_to_view = [&](auto dofs, auto &view, auto rc) {
557 auto dit = dofs->lower_bound(uid);
558 decltype(dit) hi_dit;
559 if (dit != dofs->end()) {
560 hi_dit = dofs->upper_bound(
561 uid | static_cast<UId>(MAX_DOFS_ON_ENTITY - 1));
562 view.insert(view.end(), dit, hi_dit);
563 row_col[rc] = true;
564 }
565 };
566
567 if ((lo->entFePtr->getBitFieldIdRow() & (*it)->getId()).any())
568 add_to_view(dofs_field_ptr, dofs_rows, ROW);
569
570 if (!square_matrix)
571 if ((lo->entFePtr->getBitFieldIdCol() & (*it)->getId()).any())
572 add_to_view(dofs_field_ptr, dofs_cols, COL);
573
574 if (square_matrix && row_col[ROW])
575 break;
576 else if (row_col[ROW] && row_col[COL])
577 break;
578 }
579 }
580 }
581 }
583 };
584
585 CHKERR make_rows_and_cols_view(dofs_rows, dofs_cols);
586 }
587
588 // Add DOFS to the problem by searching all the filedes, and adding to
589 // problem owned or shared DOFs
590 if (buildProblemFromFields == PETSC_TRUE) {
591 // Get fields IDs on elements
592 BitFieldId fields_ids_row, fields_ids_col;
593 for (auto fit = fe_ptr->begin(); fit != fe_ptr->end(); fit++) {
594 if ((fit->get()->getId() & problem_ptr->getBitFEId()).any()) {
595 fields_ids_row |= fit->get()->getBitFieldIdRow();
596 fields_ids_col |= fit->get()->getBitFieldIdCol();
597 }
598 }
599 // Get fields DOFs
600 for (auto fit = fields_ptr->begin(); fit != fields_ptr->end(); fit++) {
601 if ((fit->get()->getId() & (fields_ids_row | fields_ids_col)).any()) {
602
603 auto dit = dofs_field_ptr->get<Unique_mi_tag>().lower_bound(
604 FieldEntity::getLoBitNumberUId((*fit)->getBitNumber()));
605 auto hi_dit = dofs_field_ptr->get<Unique_mi_tag>().upper_bound(
606 FieldEntity::getHiBitNumberUId((*fit)->getBitNumber()));
607
608 for (; dit != hi_dit; dit++) {
609
610 const int owner_proc = dit->get()->getOwnerProc(pcomm);
611 if (owner_proc != m_field.get_comm_rank()) {
612 const unsigned char pstatus = dit->get()->getPStatus(pcomm);
613 if (pstatus == 0) {
614 continue;
615 }
616 }
617
618 const auto &dof_bit = (*dit)->getBitRefLevel();
619 // if entity is not problem refinement level
620 if ((dof_bit & prb_bit).any() && (dof_bit & prb_mask) == dof_bit) {
621
622 if ((fit->get()->getId() & fields_ids_row).any()) {
623 dofs_rows.push_back(*dit);
624 }
625 if (!square_matrix) {
626 if ((fit->get()->getId() & fields_ids_col).any()) {
627 dofs_cols.push_back(*dit);
628 }
629 }
630 }
631 }
632 }
633 }
634 }
635
637 // Get fields IDs on elements
638 BitFieldId fields_ids_row, fields_ids_col;
639 BitFieldId *fields_ids[2] = {&fields_ids_row, &fields_ids_col};
640 for (FiniteElement_multiIndex::iterator fit = fe_ptr->begin();
641 fit != fe_ptr->end(); fit++) {
642 if ((fit->get()->getId() & problem_ptr->getBitFEId()).any()) {
643 fields_ids_row |= fit->get()->getBitFieldIdRow();
644 fields_ids_col |= fit->get()->getBitFieldIdCol();
645 }
646 }
647
648 DofPtrVector *dofs_ptr[] = {&dofs_rows, &dofs_cols};
649 for (int ss = 0; ss != ((square_matrix) ? 1 : 2); ++ss) {
650 Range ents_to_synchronise;
651 for (auto &dof : *dofs_ptr[ss]) {
652 if (!dof->getActive() || dof->getEntDofIdx() != 0)
653 continue;
654 ents_to_synchronise.insert(dof->getEnt());
655 }
656 Range tmp_ents = ents_to_synchronise;
657 CHKERR m_field.getInterface<CommInterface>()->synchroniseEntities(
658 ents_to_synchronise, nullptr, verb);
659 ents_to_synchronise = subtract(ents_to_synchronise, tmp_ents);
660 for (auto fit = fields_ptr->begin(); fit != fields_ptr->end(); fit++) {
661 if ((fit->get()->getId() & *fields_ids[ss]).any()) {
662 const auto bit_number = (*fit)->getBitNumber();
663 for (Range::pair_iterator pit = ents_to_synchronise.pair_begin();
664 pit != ents_to_synchronise.pair_end(); ++pit) {
665 const auto f = pit->first;
666 const auto s = pit->second;
667 const auto lo_uid =
669 const auto hi_uid =
671
672 auto dit = dofs_field_ptr->get<Unique_mi_tag>().lower_bound(lo_uid);
673 auto hi_dit =
674 dofs_field_ptr->get<Unique_mi_tag>().upper_bound(hi_uid);
675
676 dofs_ptr[ss]->insert(dofs_ptr[ss]->end(), dit, hi_dit);
677 }
678 }
679 }
680 }
681 }
682
683 // Element-based selection appends each entity's DOF range once in UID
684 // order; field-based selection and synchronisation may append out of
685 // order or twice, so sort when needed and drop duplicates.
686 auto finalise_view = [](DofPtrVector &view) {
687 auto by_uid = [](const auto &a, const auto &b) {
688 return a->getLocalUniqueId() < b->getLocalUniqueId();
689 };
690 if (!std::is_sorted(view.begin(), view.end(), by_uid))
691 std::sort(view.begin(), view.end(), by_uid);
692 view.erase(std::unique(view.begin(), view.end(),
693 [](const auto &a, const auto &b) {
694 return a->getLocalUniqueId() ==
695 b->getLocalUniqueId();
696 }),
697 view.end());
698 };
699 finalise_view(dofs_rows);
700 finalise_view(dofs_cols);
701
702 // add dofs for rows and cols and set ownership
703 DofPtrVector *dofs_ptr[] = {&dofs_rows, &dofs_cols};
704 boost::shared_ptr<NumeredDofEntity_multiIndex> numered_dofs_ptr[] = {
705 problem_ptr->numeredRowDofsPtr, problem_ptr->numeredColDofsPtr};
706 int *nbdof_ptr[] = {&problem_ptr->nbDofsRow, &problem_ptr->nbDofsCol};
707 int *local_nbdof_ptr[] = {&problem_ptr->nbLocDofsRow,
708 &problem_ptr->nbLocDofsCol};
709 int *ghost_nbdof_ptr[] = {&problem_ptr->nbGhostDofsRow,
710 &problem_ptr->nbGhostDofsCol};
711 for (int ss = 0; ss < 2; ss++) {
712 *(nbdof_ptr[ss]) = 0;
713 *(local_nbdof_ptr[ss]) = 0;
714 *(ghost_nbdof_ptr[ss]) = 0;
715 }
716
717 // Loop over dofs on rows and columns and add to multi-indices in dofs
718 // problem structure, set partition for each dof
719 int nb_local_dofs[] = {0, 0};
720 for (int ss = 0; ss < loop_size; ss++) {
721 for (auto &dof : *dofs_ptr[ss]) {
722 if (!dof->getActive())
723 continue;
724 if (dof->getOwnerProc(pcomm) == m_field.get_comm_rank())
725 nb_local_dofs[ss]++;
726 }
727 }
728
729 // get layout
730 int start_ranges[2], end_ranges[2];
731 for (int ss = 0; ss != loop_size; ss++) {
732 PetscLayout layout;
733 CHKERR PetscLayoutCreate(m_field.get_comm(), &layout);
734 CHKERR PetscLayoutSetBlockSize(layout, 1);
735 CHKERR PetscLayoutSetLocalSize(layout, nb_local_dofs[ss]);
736 CHKERR PetscLayoutSetUp(layout);
737 CHKERR PetscLayoutGetSize(layout, &*nbdof_ptr[ss]);
738 CHKERR PetscLayoutGetRange(layout, &start_ranges[ss], &end_ranges[ss]);
739 CHKERR PetscLayoutDestroy(&layout);
740 }
741 if (square_matrix) {
742 nbdof_ptr[1] = nbdof_ptr[0];
743 nb_local_dofs[1] = nb_local_dofs[0];
744 start_ranges[1] = start_ranges[0];
745 end_ranges[1] = end_ranges[0];
746 }
747
748 // set local and global indices on own dofs
749 const size_t idx_data_type_size = sizeof(IdxDataType);
750 const size_t data_block_size = idx_data_type_size / sizeof(int);
751
752 if (sizeof(IdxDataType) % sizeof(int)) {
753 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "data inconsistency");
754 }
755 std::vector<std::vector<IdxDataType>> ids_data_packed_rows(
756 m_field.get_comm_size()),
757 ids_data_packed_cols(m_field.get_comm_size());
758
759 // Loop over dofs on this processor and prepare those dofs to send on
760 // another proc
761 for (int ss = 0; ss != loop_size; ++ss) {
762
763 boost::shared_ptr<std::vector<NumeredDofEntity>> dofs_array =
764 boost::shared_ptr<std::vector<NumeredDofEntity>>(
765 new std::vector<NumeredDofEntity>());
766 int nb_dofs_to_add = 0;
767 for (auto &dof : *dofs_ptr[ss])
768 if (dof->getActive())
769 ++nb_dofs_to_add;
770 dofs_array->reserve(nb_dofs_to_add);
771 if (ss == 0) {
772 problem_ptr->getRowDofsSequence()->push_back(dofs_array);
773 } else {
774 problem_ptr->getColDofsSequence()->push_back(dofs_array);
775 }
776
777 int &local_idx = *local_nbdof_ptr[ss];
778 for (auto miit = dofs_ptr[ss]->begin(); miit != dofs_ptr[ss]->end();
779 ++miit) {
780
781 // Only set global idx for dofs on this processor part
782 if (!(miit->get()->getActive()))
783 continue;
784
785 dofs_array->emplace_back(*miit);
786
787 int owner_proc = dofs_array->back().getOwnerProc(pcomm);
788 if (owner_proc < 0) {
789 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
790 "data inconsistency");
791 }
792
793 if (owner_proc != m_field.get_comm_rank()) {
794 dofs_array->back().pArt = owner_proc;
795 dofs_array->back().petscGloablDofIdx = -1;
796 dofs_array->back().petscLocalDofIdx = -1;
797 } else {
798
799 // Set part and indexes
800 int glob_idx = start_ranges[ss] + local_idx;
801 dofs_array->back().pArt = owner_proc;
802 dofs_array->back().petscGloablDofIdx = glob_idx;
803 dofs_array->back().petscLocalDofIdx = local_idx;
804 local_idx++;
805
806 unsigned char pstatus = dofs_array->back().getPStatus(pcomm);
807 // check id dof is shared, if that is a case global idx added to data
808 // structure and is sended to other processors
809 if (pstatus > 0) {
810 const UId global_uid = dofs_array->back().getGlobalUniqueId();
811
812 for (int proc = 0;
813 proc < MAX_SHARING_PROCS &&
814 -1 != dofs_array->back().getSharingProcsPtr(pcomm)[proc];
815 proc++) {
816 // make it different for rows and columns when needed
817 if (ss == 0) {
818 ids_data_packed_rows[dofs_array->back()
819 .getSharingProcsPtr(pcomm)[proc]]
820 .emplace_back(global_uid, glob_idx);
821 } else {
822 ids_data_packed_cols[dofs_array->back()
823 .getSharingProcsPtr(pcomm)[proc]]
824 .emplace_back(global_uid, glob_idx);
825 }
826 if (!(pstatus & PSTATUS_MULTISHARED)) {
827 break;
828 }
829 }
830 }
831 }
832 }
833
834 publish_numbered_dofs(*numered_dofs_ptr[ss], dofs_array,
835 m_field.get_comm_size() == 1);
836 }
837 if (square_matrix) {
838 local_nbdof_ptr[1] = local_nbdof_ptr[0];
839 }
840
841 int nsends_rows = 0, nsends_cols = 0;
842 // Non zero lengths[i] represent a message to i of length lengths[i].
843 // Value-initialised to zero; the size must stay comm_size for the indexed
844 // writes below and for PetscGatherNumberOfMessages.
845 std::vector<int> lengths_rows(m_field.get_comm_size(), 0),
846 lengths_cols(m_field.get_comm_size(), 0);
847 for (int proc = 0; proc < m_field.get_comm_size(); proc++) {
848 lengths_rows[proc] = ids_data_packed_rows[proc].size() * data_block_size;
849 lengths_cols[proc] = ids_data_packed_cols[proc].size() * data_block_size;
850 if (!ids_data_packed_rows[proc].empty())
851 nsends_rows++;
852 if (!ids_data_packed_cols[proc].empty())
853 nsends_cols++;
854 }
855
856 MPI_Status *status;
857 CHKERR PetscMalloc1(m_field.get_comm_size(), &status);
858
859 // Do rows
860 int nrecvs_rows; // number of messages received
861 int *onodes_rows; // list of node-ids from which messages are expected
862 int *olengths_rows; // corresponding message lengths
863 int **rbuf_row; // must bee freed by user
864
865 // make sure it is a PETSc comm
866 MPI_Comm comm;
867 CHKERR PetscCommDuplicate(m_field.get_comm(), &comm, NULL);
868
869 {
870
871 // rows
872
873 // Computes the number of messages a node expects to receive
874 CHKERR PetscGatherNumberOfMessages(comm, NULL, &lengths_rows[0],
875 &nrecvs_rows);
876 // std::cerr << nrecvs_rows << std::endl;
877
878 // Computes info about messages that a MPI-node will receive, including
879 // (from-id,length) pairs for each message.
880 CHKERR PetscGatherMessageLengths(comm, nsends_rows, nrecvs_rows,
881 &lengths_rows[0], &onodes_rows,
882 &olengths_rows);
883
884 // Gets a unique new tag from a PETSc communicator. All processors that
885 // share the communicator MUST call this routine EXACTLY the same number
886 // of times. This tag should only be used with the current objects
887 // communicator; do NOT use it with any other MPI communicator.
888 int tag_row;
889 CHKERR PetscCommGetNewTag(comm, &tag_row);
890
891 // Allocate a buffer sufficient to hold messages of size specified in
892 // olengths. And post Irecvs on these buffers using node info from onodes
893 MPI_Request *r_waits_row; // must bee freed by user
894 // rbuf has a pointers to messeges. It has size of of nrecvs (number of
895 // messages) +1. In the first index a block is allocated,
896 // such that rbuf[i] = rbuf[i-1]+olengths[i-1].
897
898 CHKERR PetscPostIrecvInt(comm, tag_row, nrecvs_rows, onodes_rows,
899 olengths_rows, &rbuf_row, &r_waits_row);
900 CHKERR PetscFree(onodes_rows);
901
902 MPI_Request *s_waits_row; // status of sens messages
903 CHKERR PetscMalloc1(nsends_rows, &s_waits_row);
904
905 // Send messeges
906 for (int proc = 0, kk = 0; proc < m_field.get_comm_size(); proc++) {
907 if (!lengths_rows[proc])
908 continue; // no message to send to this proc
909 CHKERR MPI_Isend(&(ids_data_packed_rows[proc])[0], // buffer to send
910 lengths_rows[proc], // message length
911 MPIU_INT, proc, // to proc
912 tag_row, comm, s_waits_row + kk);
913 kk++;
914 }
915
916 if (nrecvs_rows) {
917 CHKERR MPI_Waitall(nrecvs_rows, r_waits_row, status);
918 }
919 if (nsends_rows) {
920 CHKERR MPI_Waitall(nsends_rows, s_waits_row, status);
921 }
922
923 CHKERR PetscFree(r_waits_row);
924 CHKERR PetscFree(s_waits_row);
925 }
926
927 // cols
928 int nrecvs_cols = nrecvs_rows;
929 int *olengths_cols = olengths_rows;
930 PetscInt **rbuf_col = rbuf_row;
931 if (!square_matrix) {
932
933 // Computes the number of messages a node expects to receive
934 CHKERR PetscGatherNumberOfMessages(comm, NULL, &lengths_cols[0],
935 &nrecvs_cols);
936
937 // Computes info about messages that a MPI-node will receive, including
938 // (from-id,length) pairs for each message.
939 int *onodes_cols;
940 CHKERR PetscGatherMessageLengths(comm, nsends_cols, nrecvs_cols,
941 &lengths_cols[0], &onodes_cols,
942 &olengths_cols);
943
944 // Gets a unique new tag from a PETSc communicator.
945 int tag_col;
946 CHKERR PetscCommGetNewTag(comm, &tag_col);
947
948 // Allocate a buffer sufficient to hold messages of size specified in
949 // olengths. And post Irecvs on these buffers using node info from onodes
950 MPI_Request *r_waits_col; // must bee freed by user
951 CHKERR PetscPostIrecvInt(comm, tag_col, nrecvs_cols, onodes_cols,
952 olengths_cols, &rbuf_col, &r_waits_col);
953 CHKERR PetscFree(onodes_cols);
954
955 MPI_Request *s_waits_col; // status of sens messages
956 CHKERR PetscMalloc1(nsends_cols, &s_waits_col);
957
958 // Send messages
959 for (int proc = 0, kk = 0; proc < m_field.get_comm_size(); proc++) {
960 if (!lengths_cols[proc])
961 continue; // no message to send to this proc
962 CHKERR MPI_Isend(&(ids_data_packed_cols[proc])[0], // buffer to send
963 lengths_cols[proc], // message length
964 MPIU_INT, proc, // to proc
965 tag_col, comm, s_waits_col + kk);
966 kk++;
967 }
968
969 if (nrecvs_cols) {
970 CHKERR MPI_Waitall(nrecvs_cols, r_waits_col, status);
971 }
972 if (nsends_cols) {
973 CHKERR MPI_Waitall(nsends_cols, s_waits_col, status);
974 }
975
976 CHKERR PetscFree(r_waits_col);
977 CHKERR PetscFree(s_waits_col);
978 }
979
980 CHKERR PetscCommDestroy(&comm);
981 CHKERR PetscFree(status);
982
983 // Cache global keys only for this receive phase: comparison must not query
984 // ownership tags, and keys must be refreshed after sharing/ownership changes.
985 using GlobalDof = std::pair<UId, boost::shared_ptr<DofEntity>>;
986 std::vector<GlobalDof> dofs_glob_uid_view;
987 if (nrecvs_rows > 0 || nrecvs_cols > 0) {
988 dofs_glob_uid_view.reserve(m_field.get_dofs()->size());
989 const FieldEntity *last_field_ptr = nullptr;
990 UId field_uid;
991 for (const auto &dof : *m_field.get_dofs()) {
992 const auto &field_ptr = dof->getFieldEntityPtr();
993 if (field_ptr.get() != last_field_ptr) {
994 field_uid = field_ptr->getGlobalUniqueId();
995 last_field_ptr = field_ptr.get();
996 }
997 dofs_glob_uid_view.emplace_back(
998 DofEntity::getUniqueIdCalculate(dof->getEntDofIdx(), field_uid), dof);
999 }
1000 // A duplicate global UID keeps the first DOF in the original UID traversal,
1001 // as the former ordered_unique view did. std::sort needs no merge buffer.
1002 std::sort(dofs_glob_uid_view.begin(), dofs_glob_uid_view.end(),
1003 [](const GlobalDof &a, const GlobalDof &b) {
1004 return a.first == b.first
1005 ? a.second->getLocalUniqueId() <
1006 b.second->getLocalUniqueId()
1007 : a.first < b.first;
1008 });
1009 }
1010
1011 // set values received from other processors
1012 for (int ss = 0; ss != loop_size; ++ss) {
1013
1014 int nrecvs;
1015 int *olengths;
1016 int **data_procs;
1017 if (ss == 0) {
1018 nrecvs = nrecvs_rows;
1019 olengths = olengths_rows;
1020 data_procs = rbuf_row;
1021 } else {
1022 nrecvs = nrecvs_cols;
1023 olengths = olengths_cols;
1024 data_procs = rbuf_col;
1025 }
1026
1027 UId uid;
1028 for (int kk = 0; kk != nrecvs; ++kk) {
1029 int len = olengths[kk];
1030 int *data_from_proc = data_procs[kk];
1031 for (int dd = 0; dd < len; dd += data_block_size) {
1032 uid = IdxDataTypePtr(&data_from_proc[dd]).getUId();
1033 auto ddit = std::lower_bound(
1034 dofs_glob_uid_view.begin(), dofs_glob_uid_view.end(), uid,
1035 [](const GlobalDof &record, const UId &key) {
1036 return record.first < key;
1037 });
1038 if (ddit != dofs_glob_uid_view.end() && ddit->first != uid)
1039 ddit = dofs_glob_uid_view.end();
1040 const auto owner_proc = FieldEntity::getOwnerFromUniqueId(uid);
1041
1042 if (owner_proc == m_field.get_comm_rank() &&
1043 PetscUnlikely(ddit == dofs_glob_uid_view.end())) {
1044
1045#ifndef NDEBUG
1046 auto ents_field_ptr = m_field.get_field_ents();
1047 MOFEM_LOG("SELF", Sev::error)
1048 << "DOF is shared or multishared between processors. For example "
1049 "if order of field on given entity is set in inconsistently, "
1050 "has different value on two processor, error such as this is "
1051 "triggered";
1052
1053 MOFEM_LOG("SELF", Sev::error) << "UId " << uid << " is not found";
1054 MOFEM_LOG("SELF", Sev::error)
1055 << "Problematic UId owner proc is " << owner_proc;
1056 const auto uid_handle = FieldEntity::getHandleFromUniqueId(uid);
1057 MOFEM_LOG("SELF", Sev::error)
1058 << "Problematic UId entity owning processor handle is "
1059 << uid_handle << " entity type "
1060 << moab::CN::EntityTypeName(type_from_handle(uid_handle));
1061 const auto uid_bit_number =
1063 MOFEM_LOG("SELF", Sev::error)
1064 << "Problematic UId field is "
1065 << m_field.get_field_name(
1066 field_bit_from_bit_number(uid_bit_number));
1067
1069 field_view.insert(ents_field_ptr->begin(), ents_field_ptr->end());
1070 auto fe_it = field_view.find(FieldEntity::getGlobalUniqueIdCalculate(
1071 owner_proc, uid_bit_number, uid_handle));
1072 if (fe_it == field_view.end()) {
1073 MOFEM_LOG("SELF", Sev::error)
1074 << "Also, no field entity in database for given global UId";
1075 } else {
1076 MOFEM_LOG("SELF", Sev::error) << "Field entity in databse exist "
1077 "(but have no DOF wih give UId";
1078 MOFEM_LOG("SELF", Sev::error) << **fe_it;
1079
1080 // Save file with missing entity
1081 auto error_file_name =
1082 "error_with_missing_entity_" +
1083 boost::lexical_cast<std::string>(m_field.get_comm_rank()) +
1084 ".vtk";
1085 MOFEM_LOG("SELF", Sev::error)
1086 << "Look to file < " << error_file_name
1087 << " > it contains entity with missing DOF.";
1088
1089 auto tmp_msh = get_temp_meshset_ptr(m_field.get_moab());
1090 const auto local_fe_ent = (*fe_it)->getEnt();
1091 CHKERR m_field.get_moab().add_entities(*tmp_msh, &local_fe_ent, 1);
1092 CHKERR m_field.get_moab().write_file(error_file_name.c_str(), "VTK",
1093 "", tmp_msh->get_ptr(), 1);
1094 }
1095#endif
1096
1097 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1098 "DOF with global UId not found (Compile code in Debug to "
1099 "learn more about problem");
1100 }
1101
1102 if (PetscUnlikely(ddit == dofs_glob_uid_view.end())) {
1103 continue;
1104 }
1105
1106 auto dit = numered_dofs_ptr[ss]->find(ddit->second->getLocalUniqueId());
1107
1108 if (dit != numered_dofs_ptr[ss]->end()) {
1109
1110 int global_idx = IdxDataTypePtr(&data_from_proc[dd]).getGlobalIdx();
1111#ifndef NDEBUG
1112 if (PetscUnlikely(global_idx < 0))
1113 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1114 "received negative dof");
1115#endif
1116 // One modify sets the global index; the part and the local index
1117 // (-1, not owned) are kept.
1118 const bool success = numered_dofs_ptr[ss]->modify(
1120 (*dit)->getPart(), global_idx,
1121 (*dit)->getPetscLocalDofIdx()));
1122 if (PetscUnlikely(!success))
1123 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1124 "modification unsuccessful");
1125 };
1126
1127#ifndef NDEBUG
1128 if (PetscUnlikely(ddit->second->getPStatus() == 0)) {
1129
1130 // Dof is shared on this processor, however there is no element
1131 // which have this dof. If DOF is not shared and received from other
1132 // processor, but not marked as a shared on other that means that is
1133 // data inconstancy and error should be thrown.
1134
1135 std::ostringstream zz;
1136 zz << *ddit->second << std::endl;
1137 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1138 "data inconsistency, dofs is not shared, but received "
1139 "from other proc\n"
1140 "%s",
1141 zz.str().c_str());
1142 }
1143#endif
1144 }
1145 }
1146 }
1147
1148 if (square_matrix) {
1149 (problem_ptr->nbDofsCol) = (problem_ptr->nbDofsRow);
1150 (problem_ptr->nbLocDofsCol) = (problem_ptr->nbLocDofsRow);
1151 }
1152
1153 CHKERR PetscFree(olengths_rows);
1154 CHKERR PetscFree(rbuf_row[0]);
1155 CHKERR PetscFree(rbuf_row);
1156 if (!square_matrix) {
1157 CHKERR PetscFree(olengths_cols);
1158 CHKERR PetscFree(rbuf_col[0]);
1159 CHKERR PetscFree(rbuf_col);
1160 }
1161
1162 if (square_matrix) {
1163 if (numered_dofs_ptr[0]->size() != numered_dofs_ptr[1]->size()) {
1164 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1165 "data inconsistency for square_matrix %ld!=%ld",
1166 numered_dofs_ptr[0]->size(), numered_dofs_ptr[1]->size());
1167 }
1168 if (problem_ptr->numeredRowDofsPtr != problem_ptr->numeredColDofsPtr) {
1169 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1170 "data inconsistency for square_matrix");
1171 }
1172 }
1173
1174 CHKERR printPartitionedProblem(problem_ptr, verb);
1175 CHKERR debugPartitionedProblem(problem_ptr, verb);
1176
1177 PetscLogEventEnd(MOFEM_EVENT_ProblemsManager, 0, 0, 0, 0);
1178
1180}
1181
1183 const std::string out_name,
1184
1185 const std::vector<std::string> &fields_row,
1186 const std::vector<std::string> &fields_col,
1187
1188 const std::string main_problem, const bool square_matrix,
1189
1190 const map<std::string, boost::shared_ptr<Range>> *entityMapRow,
1191 const map<std::string, boost::shared_ptr<Range>> *entityMapCol,
1192
1193 int verb) {
1194 MoFEM::Interface &m_field = cOre;
1195 auto problems_ptr = m_field.get_problems();
1197
1198 CHKERR m_field.clear_problem(out_name);
1199
1200 // get reference to all problems
1201 using ProblemByName = decltype(problems_ptr->get<Problem_mi_tag>());
1202 auto &problems_by_name =
1203 const_cast<ProblemByName &>(problems_ptr->get<Problem_mi_tag>());
1204
1205 // get iterators to out problem, i.e. build problem
1206 auto out_problem_it = problems_by_name.find(out_name);
1207 if (out_problem_it == problems_by_name.end()) {
1208 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1209 "subproblem with name < %s > not defined (top tip check spelling)",
1210 out_name.c_str());
1211 }
1212 // get iterator to main problem, i.e. out problem is subproblem of main
1213 // problem
1214 auto main_problem_it = problems_by_name.find(main_problem);
1215 if (main_problem_it == problems_by_name.end()) {
1216 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1217 "problem of subproblem with name < %s > not defined (top tip "
1218 "check spelling)",
1219 main_problem.c_str());
1220 }
1221
1222 // get dofs for row & columns for out problem,
1223 boost::shared_ptr<NumeredDofEntity_multiIndex> out_problem_dofs[] = {
1224 out_problem_it->numeredRowDofsPtr, out_problem_it->numeredColDofsPtr};
1225 // get dofs for row & columns for main problem
1226 boost::shared_ptr<NumeredDofEntity_multiIndex> main_problem_dofs[] = {
1227 main_problem_it->numeredRowDofsPtr, main_problem_it->numeredColDofsPtr};
1228 // get local indices counter
1229 int *nb_local_dofs[] = {&out_problem_it->nbLocDofsRow,
1230 &out_problem_it->nbLocDofsCol};
1231 // get global indices counter
1232 int *nb_dofs[] = {&out_problem_it->nbDofsRow, &out_problem_it->nbDofsCol};
1233
1234 // set number of ghost nodes to zero
1235 {
1236 out_problem_it->nbGhostDofsRow = 0;
1237 out_problem_it->nbGhostDofsCol = 0;
1238 }
1239
1240 // put rows & columns field names in array
1241 std::vector<std::string> fields[] = {fields_row, fields_col};
1242 const map<std::string, boost::shared_ptr<Range>> *entityMap[] = {
1243 entityMapRow, entityMapCol};
1244
1245 // make data structure fos sub-problem data
1246 out_problem_it->subProblemData =
1247 boost::make_shared<Problem::SubProblemData>();
1248
1249 // Loop over rows and columns
1250 for (int ss = 0; ss != (square_matrix ? 1 : 2); ++ss) {
1251
1252 // reset dofs and columns counters
1253 (*nb_local_dofs[ss]) = 0;
1254 (*nb_dofs[ss]) = 0;
1255 // clear arrays
1256 out_problem_dofs[ss]->clear();
1257
1258 // If DOFs are cleared clear finite elements too.
1259 out_problem_it->numeredFiniteElementsPtr->clear();
1260
1261 // Number records in stable sequences before publishing them once.
1262 struct Record {
1263 NumeredDofEntity *dof;
1264 };
1265 std::vector<Record> records;
1266 std::vector<boost::shared_ptr<std::vector<NumeredDofEntity>>> sequences;
1267 auto fields_by_bit = fields[ss];
1268 std::sort(fields_by_bit.begin(), fields_by_bit.end(),
1269 [&](const std::string &a, const std::string &b) {
1270 return m_field.get_field_bit_number(a) <
1271 m_field.get_field_bit_number(b);
1272 });
1273
1274 // get dofs by field name and copy them into the out problem sequences
1275 for (auto field : fields_by_bit) {
1276
1277 // Following reserve memory in sequences, only two allocations are here,
1278 // once for array of objects, next for array of shared pointers
1279
1280 // aliased sequence of pointer is killed with element
1281 boost::shared_ptr<std::vector<NumeredDofEntity>> dofs_array =
1282 boost::make_shared<std::vector<NumeredDofEntity>>();
1283 sequences.push_back(dofs_array);
1284 // reserve memory for field dofs
1285 if (!ss)
1286 out_problem_it->getRowDofsSequence()->emplace_back(dofs_array);
1287 else
1288 out_problem_it->getColDofsSequence()->emplace_back(dofs_array);
1289
1290 // create elements objects
1291 auto bit_number = m_field.get_field_bit_number(field);
1292
1293 auto add_dit_to_dofs_array = [&](auto &dit) {
1294 if (dit->get()->getPetscGlobalDofIdx() >= 0)
1295 dofs_array->emplace_back(
1296 dit->get()->getDofEntityPtr(), dit->get()->getPetscGlobalDofIdx(),
1297 dit->get()->getPetscLocalDofIdx(), dit->get()->getPart());
1298 };
1299
1300 auto get_dafult_dof_range = [&]() {
1301 auto dit = main_problem_dofs[ss]->get<Unique_mi_tag>().lower_bound(
1302 FieldEntity::getLoBitNumberUId(bit_number));
1303 auto hi_dit = main_problem_dofs[ss]->get<Unique_mi_tag>().upper_bound(
1304 FieldEntity::getHiBitNumberUId(bit_number));
1305 return std::make_pair(dit, hi_dit);
1306 };
1307
1308 auto check = [&](auto &field) -> boost::shared_ptr<Range> {
1309 if (entityMap[ss]) {
1310 auto mit = entityMap[ss]->find(field);
1311 if (mit != entityMap[ss]->end()) {
1312 return mit->second;
1313 } else {
1314 return nullptr;
1315 }
1316 } else {
1317 return nullptr;
1318 }
1319 };
1320
1321 if (auto r_ptr = check(field)) {
1322 for (auto p = r_ptr->pair_begin(); p != r_ptr->pair_end(); ++p) {
1323 const auto lo_ent = p->first;
1324 const auto hi_ent = p->second;
1325 auto dit = main_problem_dofs[ss]->get<Unique_mi_tag>().lower_bound(
1326 DofEntity::getLoFieldEntityUId(bit_number, lo_ent));
1327 auto hi_dit = main_problem_dofs[ss]->get<Unique_mi_tag>().upper_bound(
1328 DofEntity::getHiFieldEntityUId(bit_number, hi_ent));
1329 dofs_array->reserve(std::distance(dit, hi_dit));
1330 for (; dit != hi_dit; dit++) {
1331 add_dit_to_dofs_array(dit);
1332 }
1333 }
1334 } else {
1335 auto [dit, hi_dit] = get_dafult_dof_range();
1336 dofs_array->reserve(std::distance(dit, hi_dit));
1337 for (; dit != hi_dit; dit++)
1338 add_dit_to_dofs_array(dit);
1339 }
1340
1341 // The sequence is complete, so pointers into it are stable.
1342 records.reserve(records.size() + dofs_array->size());
1343 for (auto &v : *dofs_array)
1344 records.push_back({&v});
1345 }
1346
1347 // Number the records before insertion, as the main problem would be
1348 // visited by its global index (the records still carry it): local index
1349 // in that order for DOFs of this part, -1 otherwise.
1350 std::vector<Record *> by_main_index;
1351 by_main_index.reserve(records.size());
1352 for (auto &r : records)
1353 by_main_index.push_back(&r);
1354 std::sort(by_main_index.begin(), by_main_index.end(),
1355 [](const Record *a, const Record *b) {
1356 return a->dof->getPetscGlobalDofIdx() <
1357 b->dof->getPetscGlobalDofIdx();
1358 });
1359 const unsigned int rank = m_field.get_comm_rank();
1360 for (auto *r : by_main_index)
1361 r->dof->petscLocalDofIdx =
1362 (r->dof->getPart() == rank) ? (*nb_local_dofs[ss])++ : -1;
1363
1364 // Map the main problem's global indices of this part's DOFs to the
1365 // compressed global indices of the out problem.
1366 {
1367 std::vector<int> main_indices;
1368 main_indices.reserve(*nb_local_dofs[ss]);
1369 for (auto *r : by_main_index)
1370 if (r->dof->petscLocalDofIdx >= 0)
1371 main_indices.push_back(r->dof->getPetscGlobalDofIdx());
1372 const int nb = main_indices.size();
1373 IS is;
1374 CHKERR ISCreateGeneral(m_field.get_comm(), nb, main_indices.data(),
1375 PETSC_USE_POINTER, &is);
1376 AO ao;
1377 CHKERR AOCreateMappingIS(is, PETSC_NULLPTR, &ao);
1378 if (ss == 0) {
1379 IS is_dup;
1380 CHKERR ISDuplicate(is, &is_dup);
1381 out_problem_it->getSubData()->rowIs = SmartPetscObj<IS>(is_dup, false);
1382 out_problem_it->getSubData()->rowMap = SmartPetscObj<AO>(ao, true);
1383 } else {
1384 IS is_dup;
1385 CHKERR ISDuplicate(is, &is_dup);
1386 out_problem_it->getSubData()->colIs = SmartPetscObj<IS>(is_dup, false);
1387 out_problem_it->getSubData()->colMap = SmartPetscObj<AO>(ao, true);
1388 }
1389 // The IS uses main_indices in place; after the mapping they are the
1390 // out problem's global indices.
1391 CHKERR AOApplicationToPetscIS(ao, is);
1392 CHKERR ISGetSize(is, nb_dofs[ss]);
1393 CHKERR ISDestroy(&is);
1394 {
1395 auto it = main_indices.begin();
1396 for (auto *r : by_main_index)
1397 if (r->dof->petscLocalDofIdx >= 0) {
1398 r->dof->petscGloablDofIdx = *it;
1399 ++it;
1400 }
1401 }
1402 // DOFs of other parts get the mapped global index. The IS and the
1403 // mapping are collective, so every rank makes them, with no entries if
1404 // it has no such DOFs.
1405 std::vector<int> main_indices_non_local;
1406 main_indices_non_local.reserve(records.size() - nb);
1407 for (auto *r : by_main_index)
1408 if (r->dof->petscLocalDofIdx < 0)
1409 main_indices_non_local.push_back(r->dof->getPetscGlobalDofIdx());
1410 {
1411 IS is_non_local;
1412 CHKERR ISCreateGeneral(m_field.get_comm(), main_indices_non_local.size(),
1413 main_indices_non_local.data(), PETSC_USE_POINTER,
1414 &is_non_local);
1415 CHKERR AOApplicationToPetscIS(ao, is_non_local);
1416 CHKERR ISDestroy(&is_non_local);
1417 auto it = main_indices_non_local.begin();
1418 for (auto *r : by_main_index)
1419 if (r->dof->petscLocalDofIdx < 0)
1420 r->dof->petscGloablDofIdx = *it++;
1421 }
1422 CHKERR AODestroy(&ao);
1423 }
1424
1425 for (auto &sequence_ptr : sequences)
1426 publish_numbered_dofs(*out_problem_dofs[ss], sequence_ptr);
1427 }
1428
1429 if (square_matrix) {
1430 out_problem_it->numeredColDofsPtr = out_problem_it->numeredRowDofsPtr;
1431 out_problem_it->nbLocDofsCol = out_problem_it->nbLocDofsRow;
1432 out_problem_it->nbDofsCol = out_problem_it->nbDofsRow;
1433 out_problem_it->getSubData()->colIs = out_problem_it->getSubData()->rowIs;
1434 out_problem_it->getSubData()->colMap = out_problem_it->getSubData()->rowMap;
1435 }
1436
1437 CHKERR printPartitionedProblem(&*out_problem_it, verb);
1438 CHKERR debugPartitionedProblem(&*out_problem_it, verb);
1439
1441}
1442
1443MoFEMErrorCode ProblemsManager::buildComposedProblem(
1444 const std::string out_name, const std::vector<std::string> add_row_problems,
1445 const std::vector<std::string> add_col_problems, const bool square_matrix,
1446 int verb) {
1447 if (!(cOre.getBuildMoFEM() & Core::BUILD_FIELD))
1448 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "fields not build");
1449 if (!(cOre.getBuildMoFEM() & Core::BUILD_FE))
1450 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "FEs not build");
1451 if (!(cOre.getBuildMoFEM() & Core::BUILD_ADJ))
1452 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "adjacencies not build");
1453 MoFEM::Interface &m_field = cOre;
1454 auto problems_ptr = m_field.get_problems();
1456
1457 CHKERR m_field.clear_problem(out_name);
1458 // get reference to all problems
1459 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemByName;
1460 ProblemByName &problems_by_name =
1461 const_cast<ProblemByName &>(problems_ptr->get<Problem_mi_tag>());
1462
1463 // Get iterators to out problem, i.e. build problem
1464 ProblemByName::iterator out_problem_it = problems_by_name.find(out_name);
1465 if (out_problem_it == problems_by_name.end()) {
1466 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1467 "problem with name < %s > not defined (top tip check spelling)",
1468 out_name.c_str());
1469 }
1470 // Make data structure for composed-problem data
1471 out_problem_it->composedProblemsData =
1472 boost::make_shared<ComposedProblemsData>();
1473 boost::shared_ptr<ComposedProblemsData> cmp_prb_data =
1474 out_problem_it->getComposedProblemsData();
1475
1476 const std::vector<std::string> *add_prb[] = {&add_row_problems,
1477 &add_col_problems};
1478 std::vector<const Problem *> *add_prb_ptr[] = {&cmp_prb_data->rowProblemsAdd,
1479 &cmp_prb_data->colProblemsAdd};
1480 std::vector<SmartPetscObj<IS>> *add_prb_is[] = {&cmp_prb_data->rowIs,
1481 &cmp_prb_data->colIs};
1482
1483 // Get local indices counter
1484 int *nb_local_dofs[] = {&out_problem_it->nbLocDofsRow,
1485 &out_problem_it->nbLocDofsCol};
1486 // Get global indices counter
1487 int *nb_dofs[] = {&out_problem_it->nbDofsRow, &out_problem_it->nbDofsCol};
1488
1489 // Set number of ghost nodes to zero
1490 {
1491 out_problem_it->nbDofsRow = 0;
1492 out_problem_it->nbDofsCol = 0;
1493 out_problem_it->nbLocDofsRow = 0;
1494 out_problem_it->nbLocDofsCol = 0;
1495 out_problem_it->nbGhostDofsRow = 0;
1496 out_problem_it->nbGhostDofsCol = 0;
1497 }
1498 int nb_dofs_reserve[] = {0, 0};
1499
1500 // Loop over rows and columns in the main problem and sub-problems
1501 for (int ss = 0; ss != ((square_matrix) ? 1 : 2); ss++) {
1502 add_prb_ptr[ss]->reserve(add_prb[ss]->size());
1503 add_prb_is[ss]->reserve(add_prb[ss]->size());
1504 for (std::vector<std::string>::const_iterator vit = add_prb[ss]->begin();
1505 vit != add_prb[ss]->end(); vit++) {
1506 ProblemByName::iterator prb_it = problems_by_name.find(*vit);
1507 if (prb_it == problems_by_name.end()) {
1508 SETERRQ(
1509 PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1510 "problem with name < %s > not defined (top tip check spelling)",
1511 vit->c_str());
1512 }
1513 add_prb_ptr[ss]->push_back(&*prb_it);
1514 // set number of dofs on rows and columns
1515 if (ss == 0) {
1516 // row
1517 *nb_dofs[ss] += add_prb_ptr[ss]->back()->getNbDofsRow();
1518 *nb_local_dofs[ss] += add_prb_ptr[ss]->back()->getNbLocalDofsRow();
1519 nb_dofs_reserve[ss] +=
1520 add_prb_ptr[ss]->back()->numeredRowDofsPtr->size();
1521 } else {
1522 // column
1523 *nb_dofs[ss] += add_prb_ptr[ss]->back()->getNbDofsCol();
1524 *nb_local_dofs[ss] += add_prb_ptr[ss]->back()->getNbLocalDofsCol();
1525 nb_dofs_reserve[ss] +=
1526 add_prb_ptr[ss]->back()->numeredColDofsPtr->size();
1527 }
1528 }
1529 }
1530 // if squre problem, rows and columns are the same
1531 if (square_matrix) {
1532 add_prb_ptr[1]->reserve(add_prb_ptr[0]->size());
1533 add_prb_is[1]->reserve(add_prb_ptr[0]->size());
1534 out_problem_it->numeredColDofsPtr = out_problem_it->numeredRowDofsPtr;
1535 *nb_dofs[1] = *nb_dofs[0];
1536 *nb_local_dofs[1] = *nb_local_dofs[0];
1537 }
1538
1539 // reserve memory for dofs
1540 boost::shared_ptr<std::vector<NumeredDofEntity>> dofs_array[2];
1541 // Reserve memory
1542 for (int ss = 0; ss != ((square_matrix) ? 1 : 2); ss++) {
1543 dofs_array[ss] = boost::make_shared<std::vector<NumeredDofEntity>>();
1544 dofs_array[ss]->reserve(nb_dofs_reserve[ss]);
1545 if (!ss)
1546 out_problem_it->getRowDofsSequence()->emplace_back(dofs_array[ss]);
1547 else
1548 out_problem_it->getColDofsSequence()->emplace_back(dofs_array[ss]);
1549 }
1550
1551 // Push back DOFs
1552 for (int ss = 0; ss != ((square_matrix) ? 1 : 2); ss++) {
1553 NumeredDofEntity_multiIndex::index<PetscGlobalIdx_mi_tag>::type::iterator
1554 dit,
1555 hi_dit;
1556 int shift_glob = 0;
1557 int shift_loc = 0;
1558 for (unsigned int pp = 0; pp != add_prb_ptr[ss]->size(); pp++) {
1559 PetscInt *dofs_out_idx_ptr;
1560 int nb_local_dofs = (*add_prb_ptr[ss])[pp]->getNbLocalDofsRow();
1561 CHKERR PetscMalloc(nb_local_dofs * sizeof(int), &dofs_out_idx_ptr);
1562 if (ss == 0) {
1563 dit = (*add_prb_ptr[ss])[pp]
1564 ->numeredRowDofsPtr->get<PetscGlobalIdx_mi_tag>()
1565 .begin();
1566 hi_dit = (*add_prb_ptr[ss])[pp]
1567 ->numeredRowDofsPtr->get<PetscGlobalIdx_mi_tag>()
1568 .end();
1569 } else {
1570 dit = (*add_prb_ptr[ss])[pp]
1571 ->numeredColDofsPtr->get<PetscGlobalIdx_mi_tag>()
1572 .begin();
1573 hi_dit = (*add_prb_ptr[ss])[pp]
1574 ->numeredColDofsPtr->get<PetscGlobalIdx_mi_tag>()
1575 .end();
1576 }
1577 int is_nb = 0;
1578 for (; dit != hi_dit; dit++) {
1579 const BitRefLevel &prb_bit = out_problem_it->getBitRefLevel();
1580 const BitRefLevel &prb_mask = out_problem_it->getBitRefLevelMask();
1581 const BitRefLevel &dof_bit = dit->get()->getBitRefLevel();
1582 if ((dof_bit & prb_bit).none() || ((dof_bit & prb_mask) != dof_bit))
1583 continue;
1584 const int rank = m_field.get_comm_rank();
1585 const int part = dit->get()->getPart();
1586 const int glob_idx = shift_glob + dit->get()->getPetscGlobalDofIdx();
1587 const int loc_idx =
1588 (part == rank) ? (shift_loc + dit->get()->getPetscLocalDofIdx())
1589 : -1;
1590 dofs_array[ss]->emplace_back(dit->get()->getDofEntityPtr(), glob_idx,
1591 loc_idx, part);
1592 if (part == rank) {
1593 dofs_out_idx_ptr[is_nb++] = glob_idx;
1594 }
1595 }
1596 if (is_nb > nb_local_dofs) {
1597 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
1598 "Data inconsistency");
1599 }
1600 IS is;
1601 CHKERR ISCreateGeneral(m_field.get_comm(), is_nb, dofs_out_idx_ptr,
1602 PETSC_OWN_POINTER, &is);
1603 auto smart_is = SmartPetscObj<IS>(is);
1604 (*add_prb_is[ss]).push_back(smart_is);
1605 if (ss == 0) {
1606 shift_glob += (*add_prb_ptr[ss])[pp]->getNbDofsRow();
1607 shift_loc += (*add_prb_ptr[ss])[pp]->getNbLocalDofsRow();
1608 } else {
1609 shift_glob += (*add_prb_ptr[ss])[pp]->getNbDofsCol();
1610 shift_loc += (*add_prb_ptr[ss])[pp]->getNbLocalDofsCol();
1611 }
1612 if (square_matrix) {
1613 (*add_prb_ptr[1]).push_back((*add_prb_ptr[0])[pp]);
1614 (*add_prb_is[1]).push_back(smart_is);
1615 }
1616 }
1617 }
1618
1619 if ((*add_prb_is[1]).size() != (*add_prb_is[0]).size()) {
1620 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY, "Data inconsistency");
1621 }
1622
1623 // Insert DOFs to problem multi-index
1624 for (int ss = 0; ss != ((square_matrix) ? 1 : 2); ss++) {
1625 auto &dofs = ss == 0 ? *out_problem_it->numeredRowDofsPtr
1626 : *out_problem_it->numeredColDofsPtr;
1627 publish_numbered_dofs(dofs, dofs_array[ss]);
1628 }
1629
1630 // Compress DOFs
1631 *nb_dofs[0] = 0;
1632 *nb_dofs[1] = 0;
1633 *nb_local_dofs[0] = 0;
1634 *nb_local_dofs[1] = 0;
1635 for (int ss = 0; ss != ((square_matrix) ? 1 : 2); ss++) {
1636
1637 boost::shared_ptr<NumeredDofEntity_multiIndex> dofs_ptr;
1638 if (ss == 0) {
1639 dofs_ptr = out_problem_it->numeredRowDofsPtr;
1640 } else {
1641 dofs_ptr = out_problem_it->numeredColDofsPtr;
1642 }
1643 NumeredDofEntityByUId::iterator dit, hi_dit;
1644 dit = dofs_ptr->get<Unique_mi_tag>().begin();
1645 hi_dit = dofs_ptr->get<Unique_mi_tag>().end();
1646 std::vector<int> idx;
1647 idx.reserve(std::distance(dit, hi_dit));
1648 // set dofs in order entity and dof number on entity
1649 for (; dit != hi_dit; dit++) {
1650 if (dit->get()->getPart() == (unsigned int)m_field.get_comm_rank()) {
1651 bool success = dofs_ptr->get<Unique_mi_tag>().modify(
1652 dit, NumeredDofEntity_local_idx_change((*nb_local_dofs[ss])++));
1653 if (!success) {
1654 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
1655 "modification unsuccessful");
1656 }
1657 idx.push_back(dit->get()->getPetscGlobalDofIdx());
1658 } else {
1659 if (dit->get()->getPetscLocalDofIdx() != -1) {
1660 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
1661 "local index should be negative");
1662 }
1663 }
1664 }
1665 if (square_matrix) {
1666 *nb_local_dofs[1] = *nb_local_dofs[0];
1667 }
1668
1669 // set new dofs mapping
1670 IS is;
1671 CHKERR ISCreateGeneral(m_field.get_comm(), idx.size(), &*idx.begin(),
1672 PETSC_USE_POINTER, &is);
1673 CHKERR ISGetSize(is, nb_dofs[ss]);
1674 if (square_matrix) {
1675 *nb_dofs[1] = *nb_dofs[0];
1676 }
1677
1678 AO ao;
1679 CHKERR AOCreateMappingIS(is, PETSC_NULLPTR, &ao);
1680 for (unsigned int pp = 0; pp != (*add_prb_is[ss]).size(); pp++)
1681 CHKERR AOApplicationToPetscIS(ao, (*add_prb_is[ss])[pp]);
1682
1683 // Set DOFs numeration
1684 {
1685 std::vector<int> idx_new;
1686 idx_new.reserve(dofs_ptr->size());
1687 for (NumeredDofEntityByUId::iterator dit =
1688 dofs_ptr->get<Unique_mi_tag>().begin();
1689 dit != dofs_ptr->get<Unique_mi_tag>().end(); dit++) {
1690 idx_new.push_back(dit->get()->getPetscGlobalDofIdx());
1691 }
1692 // set new global dofs numeration
1693 IS is_new;
1694 CHKERR ISCreateGeneral(m_field.get_comm(), idx_new.size(),
1695 &*idx_new.begin(), PETSC_USE_POINTER, &is_new);
1696 CHKERR AOApplicationToPetscIS(ao, is_new);
1697 // set global indices to multi-index
1698 std::vector<int>::iterator vit = idx_new.begin();
1699 for (NumeredDofEntityByUId::iterator dit =
1700 dofs_ptr->get<Unique_mi_tag>().begin();
1701 dit != dofs_ptr->get<Unique_mi_tag>().end(); dit++) {
1702 bool success =
1703 dofs_ptr->modify(dit, NumeredDofEntity_part_and_glob_idx_change(
1704 dit->get()->getPart(), *(vit++)));
1705 if (!success) {
1706 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
1707 "modification unsuccessful");
1708 }
1709 }
1710 CHKERR ISDestroy(&is_new);
1711 }
1712 CHKERR ISDestroy(&is);
1713 CHKERR AODestroy(&ao);
1714 }
1715
1716 CHKERR printPartitionedProblem(&*out_problem_it, verb);
1717 CHKERR debugPartitionedProblem(&*out_problem_it, verb);
1718
1719 // Inidcate that porble has been build
1720 cOre.getBuildMoFEM() |= Core::BUILD_PROBLEM;
1721 cOre.getBuildMoFEM() |= Core::PARTITION_PROBLEM;
1722
1724}
1725
1726MoFEMErrorCode ProblemsManager::partitionSimpleProblem(const std::string name,
1727 int verb) {
1728
1729 MoFEM::Interface &m_field = cOre;
1730 auto problems_ptr = m_field.get_problems();
1732
1733 if (!(cOre.getBuildMoFEM() & Core::BUILD_FIELD))
1734 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "fields not build");
1735 if (!(cOre.getBuildMoFEM() & Core::BUILD_FE))
1736 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "FEs not build");
1737 if (!(cOre.getBuildMoFEM() & Core::BUILD_ADJ))
1738 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "adjacencies not build");
1739 if (!(cOre.getBuildMoFEM() & Core::BUILD_PROBLEM))
1740 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "adjacencies not build");
1741 MOFEM_LOG("WORLD", Sev::verbose) << "Simple partition problem " << name;
1742
1743 // find p_miit
1744 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemByName;
1745 ProblemByName &problems_set =
1746 const_cast<ProblemByName &>(problems_ptr->get<Problem_mi_tag>());
1747 ProblemByName::iterator p_miit = problems_set.find(name);
1748 if (p_miit == problems_set.end()) {
1749 SETERRQ(PETSC_COMM_SELF, 1,
1750 "problem < %s > is not found (top tip: check spelling)",
1751 name.c_str());
1752 }
1753 // Parts are contiguous ranges of the provisional global index set by
1754 // buildProblem; the index is kept and only the part and the local index
1755 // change, so modifying through the iterated index leaves elements in place.
1756 typedef boost::multi_index::index<NumeredDofEntity_multiIndex,
1758 NumeredDofEntitysByIdx;
1759 NumeredDofEntitysByIdx &dofs_row_by_idx =
1760 p_miit->numeredRowDofsPtr->get<PetscGlobalIdx_mi_tag>();
1761 NumeredDofEntitysByIdx &dofs_col_by_idx =
1762 p_miit->numeredColDofsPtr->get<PetscGlobalIdx_mi_tag>();
1763 NumeredDofEntitysByIdx::iterator miit_row, hi_miit_row;
1764 NumeredDofEntitysByIdx::iterator miit_col, hi_miit_col;
1765 DofIdx &nb_row_local_dofs = p_miit->nbLocDofsRow;
1766 DofIdx &nb_row_ghost_dofs = p_miit->nbGhostDofsRow;
1767 nb_row_local_dofs = 0;
1768 nb_row_ghost_dofs = 0;
1769 DofIdx &nb_col_local_dofs = p_miit->nbLocDofsCol;
1770 DofIdx &nb_col_ghost_dofs = p_miit->nbGhostDofsCol;
1771 nb_col_local_dofs = 0;
1772 nb_col_ghost_dofs = 0;
1773
1774 bool square_matrix = false;
1775 if (p_miit->numeredRowDofsPtr == p_miit->numeredColDofsPtr) {
1776 square_matrix = true;
1777 }
1778
1779 // get row range of local indices
1780 PetscLayout layout_row;
1781 const int *ranges_row;
1782
1783 DofIdx nb_dofs_row = dofs_row_by_idx.size();
1784 CHKERR PetscLayoutCreate(m_field.get_comm(), &layout_row);
1785 CHKERR PetscLayoutSetBlockSize(layout_row, 1);
1786 CHKERR PetscLayoutSetSize(layout_row, nb_dofs_row);
1787 CHKERR PetscLayoutSetUp(layout_row);
1788 CHKERR PetscLayoutGetRanges(layout_row, &ranges_row);
1789 // get col range of local indices
1790 PetscLayout layout_col;
1791 const int *ranges_col;
1792 if (!square_matrix) {
1793 DofIdx nb_dofs_col = dofs_col_by_idx.size();
1794 CHKERR PetscLayoutCreate(m_field.get_comm(), &layout_col);
1795 CHKERR PetscLayoutSetBlockSize(layout_col, 1);
1796 CHKERR PetscLayoutSetSize(layout_col, nb_dofs_col);
1797 CHKERR PetscLayoutSetUp(layout_col);
1798 CHKERR PetscLayoutGetRanges(layout_col, &ranges_col);
1799 }
1800 for (unsigned int part = 0; part < (unsigned int)m_field.get_comm_size();
1801 part++) {
1802 miit_row = dofs_row_by_idx.lower_bound(ranges_row[part]);
1803 hi_miit_row = dofs_row_by_idx.lower_bound(ranges_row[part + 1]);
1804 if (std::distance(miit_row, hi_miit_row) !=
1805 ranges_row[part + 1] - ranges_row[part]) {
1806 SETERRQ(
1807 PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
1808 "data inconsistency, std::distance(miit_row,hi_miit_row) != rend - "
1809 "rstart (%ld != %d - %d = %d) ",
1810 std::distance(miit_row, hi_miit_row), ranges_row[part + 1],
1811 ranges_row[part], ranges_row[part + 1] - ranges_row[part]);
1812 }
1813 // loop rows
1814 for (; miit_row != hi_miit_row; miit_row++) {
1815 bool success = dofs_row_by_idx.modify(
1817 part, (*miit_row)->getPetscGlobalDofIdx()));
1818 if (!success)
1819 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1820 "modification unsuccessful");
1821 if (part == (unsigned int)m_field.get_comm_rank()) {
1822 success = dofs_row_by_idx.modify(
1823 miit_row, NumeredDofEntity_local_idx_change(nb_row_local_dofs++));
1824 if (!success)
1825 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1826 "modification unsuccessful");
1827 }
1828 }
1829 if (!square_matrix) {
1830 miit_col = dofs_col_by_idx.lower_bound(ranges_col[part]);
1831 hi_miit_col = dofs_col_by_idx.lower_bound(ranges_col[part + 1]);
1832 if (std::distance(miit_col, hi_miit_col) !=
1833 ranges_col[part + 1] - ranges_col[part]) {
1834 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
1835 "data inconsistency, std::distance(miit_col,hi_miit_col) != "
1836 "rend - "
1837 "rstart (%ld != %d - %d = %d) ",
1838 std::distance(miit_col, hi_miit_col), ranges_col[part + 1],
1839 ranges_col[part], ranges_col[part + 1] - ranges_col[part]);
1840 }
1841 // loop cols
1842 for (; miit_col != hi_miit_col; miit_col++) {
1843 bool success = dofs_col_by_idx.modify(
1845 part, (*miit_col)->getPetscGlobalDofIdx()));
1846 if (!success)
1847 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1848 "modification unsuccessful");
1849 if (part == (unsigned int)m_field.get_comm_rank()) {
1850 success = dofs_col_by_idx.modify(
1851 miit_col, NumeredDofEntity_local_idx_change(nb_col_local_dofs++));
1852 if (!success)
1853 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1854 "modification unsuccessful");
1855 }
1856 }
1857 }
1858 }
1859 CHKERR PetscLayoutDestroy(&layout_row);
1860 if (!square_matrix) {
1861 CHKERR PetscLayoutDestroy(&layout_col);
1862 }
1863 if (square_matrix) {
1864 nb_col_local_dofs = nb_row_local_dofs;
1865 nb_col_ghost_dofs = nb_row_ghost_dofs;
1866 }
1867 CHKERR printPartitionedProblem(&*p_miit, verb);
1868 cOre.getBuildMoFEM() |= Core::PARTITION_PROBLEM;
1870}
1871
1872MoFEMErrorCode ProblemsManager::partitionProblem(const std::string name,
1873 int verb) {
1874 MoFEM::Interface &m_field = cOre;
1875 auto problems_ptr = m_field.get_problems();
1877
1878 MOFEM_LOG("WORLD", Sev::noisy) << "Partition problem " << name;
1879
1880 // DOFs are visited in UID order, which is the order of the provisional
1881 // global index set by buildProblem, through the UID index: the global
1882 // index is modified and must not be the iterated key.
1883 using NumeredDofEntitysByIdx =
1884 NumeredDofEntity_multiIndex::index<Unique_mi_tag>::type;
1885 using ProblemsByName = Problem_multiIndex::index<Problem_mi_tag>::type;
1886
1887 // Find problem pointer by name
1888 auto &problems_set =
1889 const_cast<ProblemsByName &>(problems_ptr->get<Problem_mi_tag>());
1890 auto p_miit = problems_set.find(name);
1891 if (p_miit == problems_set.end()) {
1892 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
1893 "problem with name %s not defined (top tip check spelling)",
1894 name.c_str());
1895 }
1896 int nb_dofs_row = p_miit->getNbDofsRow();
1897
1898 if (m_field.get_comm_size() != 1) {
1899
1900 if (!(cOre.getBuildMoFEM() & (1 << 0)))
1901 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "fields not build");
1902 if (!(cOre.getBuildMoFEM() & (1 << 1)))
1903 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "FEs not build");
1904 if (!(cOre.getBuildMoFEM() & (1 << 2)))
1905 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1906 "entFEAdjacencies not build");
1907 if (!(cOre.getBuildMoFEM() & (1 << 3)))
1908 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Problems not build");
1909
1910 Mat Adj;
1912 ->createMPIAdjWithArrays<PetscGlobalIdx_mi_tag>(name, &Adj, verb);
1913
1914 int m, n;
1915 CHKERR MatGetSize(Adj, &m, &n);
1916 if (verb > VERY_VERBOSE)
1917 MatView(Adj, PETSC_VIEWER_STDOUT_WORLD);
1918
1919 // partitioning
1920 MatPartitioning part;
1921 IS is;
1922 CHKERR MatPartitioningCreate(m_field.get_comm(), &part);
1923 CHKERR MatPartitioningSetAdjacency(part, Adj);
1924 CHKERR MatPartitioningSetFromOptions(part);
1925 CHKERR MatPartitioningSetNParts(part, m_field.get_comm_size());
1926 CHKERR MatPartitioningApply(part, &is);
1927 if (verb > VERY_VERBOSE)
1928 ISView(is, PETSC_VIEWER_STDOUT_WORLD);
1929
1930 // gather
1931 IS is_gather, is_num, is_gather_num;
1932 CHKERR ISAllGather(is, &is_gather);
1933 CHKERR ISPartitioningToNumbering(is, &is_num);
1934 CHKERR ISAllGather(is_num, &is_gather_num);
1935 const int *part_number, *petsc_idx;
1936 CHKERR ISGetIndices(is_gather, &part_number);
1937 CHKERR ISGetIndices(is_gather_num, &petsc_idx);
1938 int size_is_num, size_is_gather;
1939 CHKERR ISGetSize(is_gather, &size_is_gather);
1940 if (size_is_gather != (int)nb_dofs_row)
1941 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
1942 "data inconsistency %d != %d", size_is_gather, nb_dofs_row);
1943
1944 CHKERR ISGetSize(is_num, &size_is_num);
1945 if (size_is_num != (int)nb_dofs_row)
1946 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
1947 "data inconsistency %d != %d", size_is_num, nb_dofs_row);
1948
1949 bool square_matrix = false;
1950 if (p_miit->numeredRowDofsPtr == p_miit->numeredColDofsPtr)
1951 square_matrix = true;
1952
1953 // if (!square_matrix) {
1954 // // FIXME: This is for back compatibility, if deprecate interface
1955 // function
1956 // // build interfaces is removed, this part of the code will be obsolete
1957 // auto mit_row = p_miit->numeredRowDofsPtr->get<Unique_mi_tag>().begin();
1958 // auto hi_mit_row = p_miit->numeredRowDofsPtr->get<Unique_mi_tag>().end();
1959 // auto mit_col = p_miit->numeredColDofsPtr->get<Unique_mi_tag>().begin();
1960 // auto hi_mit_col = p_miit->numeredColDofsPtr->get<Unique_mi_tag>().end();
1961 // for (; mit_row != hi_mit_row; mit_row++, mit_col++) {
1962 // if (mit_col == hi_mit_col) {
1963 // SETERRQ(
1964 // PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1965 // "check finite element definition, nb. of rows is not equal to "
1966 // "number for columns");
1967 // }
1968 // if (mit_row->get()->getLocalUniqueId() !=
1969 // mit_col->get()->getLocalUniqueId()) {
1970 // SETERRQ(
1971 // PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1972 // "check finite element definition, nb. of rows is not equal to "
1973 // "number for columns");
1974 // }
1975 // }
1976 // }
1977
1978 auto number_dofs = [&](auto &dofs_idx, auto &counter) {
1980 for (auto miit_dofs_row = dofs_idx.begin();
1981 miit_dofs_row != dofs_idx.end(); miit_dofs_row++) {
1982 const int idx = (*miit_dofs_row)->getPetscGlobalDofIdx();
1983 const int part = part_number[idx];
1984 if (part == (unsigned int)m_field.get_comm_rank()) {
1985 const bool success = dofs_idx.modify(
1987 part, petsc_idx[idx], counter++));
1988 if (!success) {
1989 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1990 "modification unsuccessful");
1991 }
1992 } else {
1993 const bool success = dofs_idx.modify(
1995 part, petsc_idx[idx]));
1996 if (!success) {
1997 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1998 "modification unsuccessful");
1999 }
2000 }
2001 }
2003 };
2004
2005 // Set petsc global indices
2006 auto &dofs_row_by_idx_no_const = const_cast<NumeredDofEntitysByIdx &>(
2007 p_miit->numeredRowDofsPtr->get<Unique_mi_tag>());
2008 int &nb_row_local_dofs = p_miit->nbLocDofsRow;
2009 int &nb_row_ghost_dofs = p_miit->nbGhostDofsRow;
2010 nb_row_local_dofs = 0;
2011 nb_row_ghost_dofs = 0;
2012
2013 CHKERR number_dofs(dofs_row_by_idx_no_const, nb_row_local_dofs);
2014
2015 int &nb_col_local_dofs = p_miit->nbLocDofsCol;
2016 int &nb_col_ghost_dofs = p_miit->nbGhostDofsCol;
2017 if (square_matrix) {
2018 nb_col_local_dofs = nb_row_local_dofs;
2019 nb_col_ghost_dofs = nb_row_ghost_dofs;
2020 } else {
2021 NumeredDofEntitysByIdx &dofs_col_by_idx_no_const =
2022 const_cast<NumeredDofEntitysByIdx &>(
2023 p_miit->numeredColDofsPtr->get<Unique_mi_tag>());
2024 nb_col_local_dofs = 0;
2025 nb_col_ghost_dofs = 0;
2026 CHKERR number_dofs(dofs_col_by_idx_no_const, nb_col_local_dofs);
2027 }
2028
2029 CHKERR ISRestoreIndices(is_gather, &part_number);
2030 CHKERR ISRestoreIndices(is_gather_num, &petsc_idx);
2031 CHKERR ISDestroy(&is_num);
2032 CHKERR ISDestroy(&is_gather_num);
2033 CHKERR ISDestroy(&is_gather);
2034 CHKERR ISDestroy(&is);
2035 CHKERR MatPartitioningDestroy(&part);
2036 CHKERR MatDestroy(&Adj);
2037 CHKERR printPartitionedProblem(&*p_miit, verb);
2038 } else {
2039
2040 auto number_dofs = [&](auto &dof_idx, auto &counter) {
2042 for (auto miit_dofs_row = dof_idx.begin(); miit_dofs_row != dof_idx.end();
2043 miit_dofs_row++) {
2044 // buildProblem numbers serial problems at insertion; a modify through
2045 // the five indices is needed only when the record does not match.
2046 const auto &dof = **miit_dofs_row;
2047 if (dof.getPart() != 0 || dof.getPetscGlobalDofIdx() != counter ||
2048 dof.getPetscLocalDofIdx() != counter) {
2049 const bool success = dof_idx.modify(
2050 miit_dofs_row,
2051 NumeredDofEntity_part_and_indices_change(0, counter, counter));
2052 if (!success) {
2053 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
2054 "modification unsuccessful");
2055 }
2056 }
2057 ++counter;
2058 }
2060 };
2061
2062 auto &dofs_row_by_idx_no_const = const_cast<NumeredDofEntitysByIdx &>(
2063 p_miit->numeredRowDofsPtr->get<Unique_mi_tag>());
2064 int &nb_row_local_dofs = p_miit->nbLocDofsRow;
2065 int &nb_row_ghost_dofs = p_miit->nbGhostDofsRow;
2066 nb_row_local_dofs = 0;
2067 nb_row_ghost_dofs = 0;
2068
2069 CHKERR number_dofs(dofs_row_by_idx_no_const, nb_row_local_dofs);
2070
2071 bool square_matrix = false;
2072 if (p_miit->numeredRowDofsPtr == p_miit->numeredColDofsPtr)
2073 square_matrix = true;
2074
2075 int &nb_col_local_dofs = p_miit->nbLocDofsCol;
2076 int &nb_col_ghost_dofs = p_miit->nbGhostDofsCol;
2077 if (square_matrix) {
2078 nb_col_local_dofs = nb_row_local_dofs;
2079 nb_col_ghost_dofs = nb_row_ghost_dofs;
2080 } else {
2081 NumeredDofEntitysByIdx &dofs_col_by_idx_no_const =
2082 const_cast<NumeredDofEntitysByIdx &>(
2083 p_miit->numeredColDofsPtr->get<Unique_mi_tag>());
2084 nb_col_local_dofs = 0;
2085 nb_col_ghost_dofs = 0;
2086 CHKERR number_dofs(dofs_col_by_idx_no_const, nb_col_local_dofs);
2087 }
2088 }
2089
2090 cOre.getBuildMoFEM() |= 1 << 4;
2092}
2093
2094MoFEMErrorCode ProblemsManager::inheritPartition(
2095 const std::string name, const std::string problem_for_rows, bool copy_rows,
2096 const std::string problem_for_cols, bool copy_cols, int verb) {
2097 MoFEM::Interface &m_field = cOre;
2098 auto problems_ptr = m_field.get_problems();
2100
2101 if (!(cOre.getBuildMoFEM() & Core::BUILD_PROBLEM))
2102 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY, "pRoblems not build");
2103
2104 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemByName;
2105
2106 // find p_miit
2107 ProblemByName &problems_by_name =
2108 const_cast<ProblemByName &>(problems_ptr->get<Problem_mi_tag>());
2109 ProblemByName::iterator p_miit = problems_by_name.find(name);
2110 if (p_miit == problems_by_name.end()) {
2111 SETERRQ(m_field.get_comm(), MOFEM_NOT_FOUND,
2112 "problem with name < %s > not defined (top tip check spelling)",
2113 name.c_str());
2114 }
2115 if (verb > QUIET)
2116 MOFEM_LOG("WORLD", Sev::inform)
2117 << p_miit->getName() << " from rows of " << problem_for_rows
2118 << " and columns of " << problem_for_cols;
2119
2120 // find p_miit_row
2121 ProblemByName::iterator p_miit_row = problems_by_name.find(problem_for_rows);
2122 if (p_miit_row == problems_by_name.end()) {
2123 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2124 "problem with name < %s > not defined (top tip check spelling)",
2125 problem_for_rows.c_str());
2126 }
2127 const boost::shared_ptr<NumeredDofEntity_multiIndex> dofs_row =
2128 p_miit_row->numeredRowDofsPtr;
2129
2130 // find p_mit_col
2131 ProblemByName::iterator p_miit_col = problems_by_name.find(problem_for_cols);
2132 if (p_miit_col == problems_by_name.end()) {
2133 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2134 "problem with name < %s > not defined (top tip check spelling)",
2135 problem_for_cols.c_str());
2136 }
2137 boost::shared_ptr<NumeredDofEntity_multiIndex> dofs_col =
2138 p_miit_col->numeredColDofsPtr;
2139
2140 bool copy[] = {copy_rows, copy_cols};
2141 boost::shared_ptr<NumeredDofEntity_multiIndex> composed_dofs[] = {
2142 p_miit->numeredRowDofsPtr, p_miit->numeredColDofsPtr};
2143
2144 int *nb_local_dofs[] = {&p_miit->nbLocDofsRow, &p_miit->nbLocDofsCol};
2145 int *nb_dofs[] = {&p_miit->nbDofsRow, &p_miit->nbDofsCol};
2146 boost::shared_ptr<NumeredDofEntity_multiIndex> copied_dofs[] = {dofs_row,
2147 dofs_col};
2148
2149 for (int ss = 0; ss < 2; ss++) {
2150
2151 // build indices
2152 *nb_local_dofs[ss] = 0;
2153 if (!copy[ss]) {
2154
2155 // only copy indices which are belong to some elements if this problem
2156 std::vector<int> is_local, is_new;
2157
2158 NumeredDofEntityByUId &dofs_by_uid =
2159 copied_dofs[ss]->get<Unique_mi_tag>();
2160 for (NumeredDofEntity_multiIndex::iterator dit =
2161 composed_dofs[ss]->begin();
2162 dit != composed_dofs[ss]->end(); dit++) {
2163 NumeredDofEntityByUId::iterator diit =
2164 dofs_by_uid.find((*dit)->getLocalUniqueId());
2165 if (diit == dofs_by_uid.end()) {
2166 SETERRQ(
2168 "data inconsistency, could not find dof in composite problem");
2169 }
2170 int part_number = (*diit)->getPart(); // get part number
2171 int petsc_global_dof = (*diit)->getPetscGlobalDofIdx();
2172 bool success;
2173 success = composed_dofs[ss]->modify(
2175 petsc_global_dof));
2176 if (!success) {
2177 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
2178 "modification unsuccessful");
2179 }
2180 if ((*dit)->getPart() == (unsigned int)m_field.get_comm_rank()) {
2181 success = composed_dofs[ss]->modify(
2182 dit, NumeredDofEntity_local_idx_change((*nb_local_dofs[ss])++));
2183 if (!success) {
2184 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
2185 "modification unsuccessful");
2186 }
2187 is_local.push_back(petsc_global_dof);
2188 }
2189 }
2190
2191 AO ao;
2192 CHKERR AOCreateMapping(m_field.get_comm(), is_local.size(), &is_local[0],
2193 NULL, &ao);
2194
2195 // apply local to global mapping
2196 is_local.resize(0);
2197 for (NumeredDofEntity_multiIndex::iterator dit =
2198 composed_dofs[ss]->begin();
2199 dit != composed_dofs[ss]->end(); dit++) {
2200 is_local.push_back((*dit)->getPetscGlobalDofIdx());
2201 }
2202 CHKERR AOPetscToApplication(ao, is_local.size(), &is_local[0]);
2203 int idx2 = 0;
2204 for (NumeredDofEntity_multiIndex::iterator dit =
2205 composed_dofs[ss]->begin();
2206 dit != composed_dofs[ss]->end(); dit++) {
2207 int part_number = (*dit)->getPart(); // get part number
2208 int petsc_global_dof = is_local[idx2++];
2209 bool success;
2210 success = composed_dofs[ss]->modify(
2212 petsc_global_dof));
2213 if (!success) {
2214 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
2215 "modification unsuccessful");
2216 }
2217 }
2218
2219 CHKERR AODestroy(&ao);
2220
2221 } else {
2222
2223 for (NumeredDofEntity_multiIndex::iterator dit = copied_dofs[ss]->begin();
2224 dit != copied_dofs[ss]->end(); dit++) {
2225 std::pair<NumeredDofEntity_multiIndex::iterator, bool> p;
2226 p = composed_dofs[ss]->insert(boost::shared_ptr<NumeredDofEntity>(
2227 new NumeredDofEntity((*dit)->getDofEntityPtr())));
2228 if (p.second) {
2229 (*nb_dofs[ss])++;
2230 }
2231 int part_number = (*dit)->getPart(); // get part number
2232 int petsc_global_dof = (*dit)->getPetscGlobalDofIdx();
2233 if (part_number == (unsigned int)m_field.get_comm_rank()) {
2234 const bool success = composed_dofs[ss]->modify(
2236 part_number, petsc_global_dof,
2237 (*nb_local_dofs[ss])++));
2238 if (!success) {
2239 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
2240 "modification unsuccessful");
2241 }
2242 } else {
2243 const bool success = composed_dofs[ss]->modify(
2245 part_number, petsc_global_dof));
2246 if (!success) {
2247 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
2248 "modification unsuccessful");
2249 }
2250 }
2251 }
2252 }
2253 }
2254
2255 CHKERR printPartitionedProblem(&*p_miit, verb);
2256 CHKERR debugPartitionedProblem(&*p_miit, verb);
2257
2259}
2260
2262ProblemsManager::printPartitionedProblem(const Problem *problem_ptr, int verb) {
2263 MoFEM::Interface &m_field = cOre;
2265
2266 if (verb > QUIET) {
2267
2268 MOFEM_LOG("SYNC", Sev::inform)
2269 << problem_ptr->getName() << " Nb. local dof "
2270 << problem_ptr->getNbLocalDofsRow() << " by "
2271 << problem_ptr->getNbLocalDofsCol() << " nb global dofs "
2272 << problem_ptr->getNbDofsRow() << " by " << problem_ptr->getNbDofsCol();
2273
2275 }
2276
2278}
2279
2281ProblemsManager::debugPartitionedProblem(const Problem *problem_ptr, int verb) {
2282 MoFEM::Interface &m_field = cOre;
2284
2285 auto save_ent = [](moab::Interface &moab, const std::string name,
2286 const EntityHandle ent) {
2288 EntityHandle out_meshset;
2289 CHKERR moab.create_meshset(MESHSET_SET, out_meshset);
2290 CHKERR moab.add_entities(out_meshset, &ent, 1);
2291 CHKERR moab.write_file(name.c_str(), "VTK", "", &out_meshset, 1);
2292 CHKERR moab.delete_entities(&out_meshset, 1);
2294 };
2295
2296 if (debug > 0) {
2297
2298 typedef NumeredDofEntity_multiIndex::index<Unique_mi_tag>::type
2299 NumeredDofEntitysByIdx;
2300 NumeredDofEntitysByIdx::iterator dit, hi_dit;
2301 const NumeredDofEntitysByIdx *numered_dofs_ptr[] = {
2302 &(problem_ptr->numeredRowDofsPtr->get<Unique_mi_tag>()),
2303 &(problem_ptr->numeredColDofsPtr->get<Unique_mi_tag>())};
2304
2305 int *nbdof_ptr[] = {&problem_ptr->nbDofsRow, &problem_ptr->nbDofsCol};
2306 int *local_nbdof_ptr[] = {&problem_ptr->nbLocDofsRow,
2307 &problem_ptr->nbLocDofsCol};
2308
2309 for (int ss = 0; ss < 2; ss++) {
2310
2311 dit = numered_dofs_ptr[ss]->begin();
2312 hi_dit = numered_dofs_ptr[ss]->end();
2313 for (; dit != hi_dit; dit++) {
2314 if ((*dit)->getPart() == (unsigned int)m_field.get_comm_rank()) {
2315 if ((*dit)->getPetscLocalDofIdx() < 0) {
2316 std::ostringstream zz;
2317 zz << "rank " << m_field.get_comm_rank() << " " << **dit;
2318 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE,
2319 "local dof index for %d (0-row, 1-col) not set, i.e. has "
2320 "negative value\n %s",
2321 ss, zz.str().c_str());
2322 }
2323 if ((*dit)->getPetscLocalDofIdx() >= *local_nbdof_ptr[ss]) {
2324 std::ostringstream zz;
2325 zz << "rank " << m_field.get_comm_rank() << " " << **dit;
2326 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE,
2327 "local dofs for %d (0-row, 1-col) out of range\n %s", ss,
2328 zz.str().c_str());
2329 }
2330 } else {
2331 if ((*dit)->getPetscGlobalDofIdx() < 0) {
2332
2333 const EntityHandle ent = (*dit)->getEnt();
2334 CHKERR save_ent(
2335 m_field.get_moab(),
2336 "debug_part" +
2337 boost::lexical_cast<std::string>(m_field.get_comm_rank()) +
2338 "_negative_global_index.vtk",
2339 ent);
2340
2341 std::ostringstream zz;
2342 zz << "rank " << m_field.get_comm_rank() << " "
2343 << dit->get()->getBitRefLevel() << " " << **dit;
2344 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE,
2345 "global dof index for %d (0-row, 1-col) row not set, i.e. "
2346 "has negative value\n %s",
2347 ss, zz.str().c_str());
2348 }
2349 if ((*dit)->getPetscGlobalDofIdx() >= *nbdof_ptr[ss]) {
2350 std::ostringstream zz;
2351 zz << "rank " << m_field.get_comm_rank() << " nb_dofs "
2352 << *nbdof_ptr[ss] << " " << **dit;
2353 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE,
2354 "global dofs for %d (0-row, 1-col) out of range\n %s", ss,
2355 zz.str().c_str());
2356 }
2357 }
2358 }
2359 }
2360 }
2362}
2363
2364MoFEMErrorCode ProblemsManager::partitionFiniteElements(const std::string name,
2365 bool part_from_moab,
2366 int low_proc,
2367 int hi_proc, int verb) {
2368 MoFEM::Interface &m_field = cOre;
2369 auto problems_ptr = m_field.get_problems();
2370 auto fe_ent_ptr = m_field.get_ents_finite_elements();
2372
2373 if (!(cOre.getBuildMoFEM() & Core::BUILD_FIELD))
2374 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY, "fields not build");
2375
2376 if (!(cOre.getBuildMoFEM() & Core::BUILD_FE))
2377 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY, "FEs not build");
2378
2379 if (!(cOre.getBuildMoFEM() & Core::BUILD_ADJ))
2380 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2381 "adjacencies not build");
2382
2383 if (!(cOre.getBuildMoFEM() & Core::BUILD_PROBLEM))
2384 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY, "problem not build");
2385
2386 if (!(cOre.getBuildMoFEM() & Core::PARTITION_PROBLEM))
2387 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2388 "problem not partitioned");
2389
2390 if (low_proc == -1)
2391 low_proc = m_field.get_comm_rank();
2392 if (hi_proc == -1)
2393 hi_proc = m_field.get_comm_rank();
2394
2395 // Find pointer to problem of given name
2396 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemByName;
2397 auto &problems =
2398 const_cast<ProblemByName &>(problems_ptr->get<Problem_mi_tag>());
2399 ProblemByName::iterator p_miit = problems.find(name);
2400 if (p_miit == problems.end()) {
2401 SETERRQ(m_field.get_comm(), MOFEM_NOT_FOUND,
2402 "problem < %s > not found (top tip: check spelling)",
2403 name.c_str());
2404 }
2405
2406 // Get reference on finite elements multi-index on the problem
2407 NumeredEntFiniteElement_multiIndex &problem_finite_elements =
2408 *p_miit->numeredFiniteElementsPtr;
2409
2410 // Clear all elements and data, build it again
2411 problem_finite_elements.clear();
2412
2413 // Check if dofs and columns are the same, i.e. structurally symmetric
2414 // problem
2415 bool do_cols_prob = true;
2416 if (p_miit->numeredRowDofsPtr == p_miit->numeredColDofsPtr) {
2417 do_cols_prob = false;
2418 }
2419
2420 auto get_good_elems = [&]() {
2421 auto good_elems = std::vector<decltype(fe_ent_ptr->begin())>();
2422 good_elems.reserve(fe_ent_ptr->size());
2423
2424 const auto prb_bit = p_miit->getBitRefLevel();
2425 const auto prb_mask = p_miit->getBitRefLevelMask();
2426
2427 // Loop over all elements in database and if right element is there add it
2428 // to problem finite element multi-index
2429 for (auto efit = fe_ent_ptr->begin(); efit != fe_ent_ptr->end(); ++efit) {
2430
2431 // if element is not part of problem
2432 if (((*efit)->getId() & p_miit->getBitFEId()).any()) {
2433
2434 const auto &fe_bit = (*efit)->getBitRefLevel();
2435
2436 // if entity is not problem refinement level
2437 if ((fe_bit & prb_mask) == fe_bit && (fe_bit & prb_bit).any())
2438 good_elems.emplace_back(efit);
2439 }
2440 }
2441
2442 return good_elems;
2443 };
2444
2445 auto good_elems = get_good_elems();
2446
2447 auto numbered_good_elems_ptr =
2448 boost::make_shared<std::vector<NumeredEntFiniteElement>>();
2449 numbered_good_elems_ptr->reserve(good_elems.size());
2450 for (auto &efit : good_elems)
2451 numbered_good_elems_ptr->emplace_back(NumeredEntFiniteElement(*efit));
2452
2453 if (!do_cols_prob) {
2454 for (auto &fe : *numbered_good_elems_ptr) {
2455 if (fe.sPtr->getRowFieldEntsPtr() == fe.sPtr->getColFieldEntsPtr()) {
2456 fe.getColFieldEntsPtr() = fe.getRowFieldEntsPtr();
2457 }
2458 }
2459 }
2460
2461 if (part_from_moab) {
2462 for (auto &fe : *numbered_good_elems_ptr) {
2463 // All imported elements belong to rank zero in a serial communicator.
2464 if (m_field.get_comm_size() == 1 || fe.getEntType() == MBENTITYSET) {
2465 fe.part = m_field.get_comm_rank();
2466 } else {
2467 // if partition is taken from moab partition
2468 int proc = fe.getPartProc();
2469 if (proc == -1 && fe.getEntType() == MBVERTEX)
2470 proc = fe.getOwnerProc();
2471 fe.part = proc;
2472 }
2473 }
2474 }
2475
2476 // The element's row DOF view is needed only to vote on its part when the
2477 // partition is not taken from MOAB and there is more than one rank.
2478 if (!part_from_moab) {
2479 for (auto &fe : *numbered_good_elems_ptr) {
2480 if (fe.getEntType() == MBENTITYSET || m_field.get_comm_size() == 1) {
2481 fe.part = m_field.get_comm_rank();
2482 } else {
2484 CHKERR fe.sPtr->getRowDofView(*(p_miit->numeredRowDofsPtr), rows_view);
2485 std::vector<int> parts(m_field.get_comm_size(), 0);
2486 for (auto &dof_ptr : rows_view)
2487 parts[dof_ptr->pArt]++;
2488 std::vector<int>::iterator pos =
2489 max_element(parts.begin(), parts.end());
2490 const auto max_part = std::distance(parts.begin(), pos);
2491 fe.part = max_part;
2492 }
2493 }
2494 }
2495
2496 for (auto &fe : *numbered_good_elems_ptr) {
2497
2498 auto check_fields_and_dofs = [&]() {
2499 if (!part_from_moab) {
2500 if (fe.getBitFieldIdRow().none() && m_field.get_comm_size() == 0) {
2501 MOFEM_LOG("WORLD", Sev::warning)
2502 << "At least one field has to be added to element row to "
2503 "determine partition of finite element. Check element " +
2504 boost::lexical_cast<std::string>(fe.getName());
2505 }
2506 }
2507
2508 return true;
2509 };
2510
2511 if (check_fields_and_dofs()) {
2512 // Add element to the problem
2513 auto p = problem_finite_elements.insert(
2514 boost::shared_ptr<NumeredEntFiniteElement>(numbered_good_elems_ptr,
2515 &fe));
2516 if (!p.second)
2517 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "element is there");
2518 }
2519 }
2520
2521 if (verb >= VERBOSE) {
2522 auto elements_on_rank =
2523 problem_finite_elements.get<Part_mi_tag>().equal_range(
2524 m_field.get_comm_rank());
2525 MOFEM_LOG("SYNC", Sev::verbose)
2526 << p_miit->getName() << " nb. elems "
2527 << std::distance(elements_on_rank.first, elements_on_rank.second);
2528 auto fe_ptr = m_field.get_finite_elements();
2529 for (auto &fe : *fe_ptr) {
2530 auto e_range =
2531 problem_finite_elements.get<Composite_Name_And_Part_mi_tag>()
2532 .equal_range(
2533 boost::make_tuple(fe->getName(), m_field.get_comm_rank()));
2534 MOFEM_LOG("SYNC", Sev::noisy)
2535 << "Element " << fe->getName() << " nb. elems "
2536 << std::distance(e_range.first, e_range.second);
2537 }
2538
2540 }
2541
2542 cOre.getBuildMoFEM() |= Core::PARTITION_FE;
2544}
2545
2546MoFEMErrorCode ProblemsManager::partitionGhostDofs(const std::string name,
2547 int verb) {
2548 MoFEM::Interface &m_field = cOre;
2549 auto problems_ptr = m_field.get_problems();
2551
2552 if (!(cOre.getBuildMoFEM() & Core::PARTITION_PROBLEM))
2553 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2554 "partition of problem not build");
2555 if (!(cOre.getBuildMoFEM() & Core::PARTITION_FE))
2556 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2557 "partitions finite elements not build");
2558
2559 // get problem pointer
2560 auto p_miit = problems_ptr->get<Problem_mi_tag>().find(name);
2561 if (p_miit == problems_ptr->get<Problem_mi_tag>().end())
2562 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "Problem %s not fond",
2563 name.c_str());
2564
2565 // get reference to number of ghost dofs
2566 int &nb_row_ghost_dofs = p_miit->nbGhostDofsRow;
2567 int &nb_col_ghost_dofs = p_miit->nbGhostDofsCol;
2568 nb_row_ghost_dofs = 0;
2569 nb_col_ghost_dofs = 0;
2570
2571 // do work if more than one processor
2572 if (m_field.get_comm_size() > 1) {
2573
2575 ghost_idx_col_view;
2576
2577 // get elements on this partition
2578 auto fe_range =
2579 p_miit->numeredFiniteElementsPtr->get<Part_mi_tag>().equal_range(
2580 m_field.get_comm_rank());
2581
2582 // get dofs on elements which are not part of this partition
2583
2584 struct Inserter {
2585 using Vec = std::vector<boost::shared_ptr<NumeredDofEntity>>;
2586 using It = Vec::iterator;
2587 It operator()(Vec &dofs_view, It &hint,
2588 boost::shared_ptr<NumeredDofEntity> &&dof) {
2589 dofs_view.emplace_back(dof);
2590 return dofs_view.end();
2591 }
2592 };
2593
2594 // rows
2595 std::vector<boost::shared_ptr<NumeredDofEntity>> fe_vec_view;
2596 auto hint_r = ghost_idx_row_view.begin();
2597 for (auto fe_ptr = fe_range.first; fe_ptr != fe_range.second; ++fe_ptr) {
2598
2599 fe_vec_view.clear();
2600 CHKERR EntFiniteElement::getDofView((*fe_ptr)->getRowFieldEnts(),
2601 *(p_miit->getNumeredRowDofsPtr()),
2602 fe_vec_view, Inserter());
2603
2604 for (auto &dof_ptr : fe_vec_view) {
2605 if (dof_ptr->getPart() != (unsigned int)m_field.get_comm_rank()) {
2606 hint_r = ghost_idx_row_view.emplace_hint(hint_r, dof_ptr);
2607 ++hint_r;
2608 }
2609 }
2610 }
2611
2612 // columns
2613 if (p_miit->numeredColDofsPtr == p_miit->numeredRowDofsPtr) {
2614
2615 auto hint_c = ghost_idx_col_view.begin();
2616 for (auto fe_ptr = fe_range.first; fe_ptr != fe_range.second; ++fe_ptr) {
2617
2618 fe_vec_view.clear();
2619 CHKERR EntFiniteElement::getDofView((*fe_ptr)->getColFieldEnts(),
2620 *(p_miit->getNumeredColDofsPtr()),
2621 fe_vec_view, Inserter());
2622
2623 for (auto &dof_ptr : fe_vec_view) {
2624 if (dof_ptr->getPart() != (unsigned int)m_field.get_comm_rank()) {
2625 hint_c = ghost_idx_col_view.emplace_hint(hint_c, dof_ptr);
2626 ++hint_c;
2627 }
2628 }
2629 }
2630 }
2631
2632 int *nb_ghost_dofs[2] = {&nb_row_ghost_dofs, &nb_col_ghost_dofs};
2633 int nb_local_dofs[2] = {p_miit->nbLocDofsRow, p_miit->nbLocDofsCol};
2634
2636 &ghost_idx_row_view, &ghost_idx_col_view};
2637 NumeredDofEntityByUId *dof_by_uid_no_const[2] = {
2638 &p_miit->numeredRowDofsPtr->get<Unique_mi_tag>(),
2639 &p_miit->numeredColDofsPtr->get<Unique_mi_tag>()};
2640
2641 int loop_size = 2;
2642 if (p_miit->numeredColDofsPtr == p_miit->numeredRowDofsPtr) {
2643 loop_size = 1;
2644 }
2645
2646 // set local ghost dofs indices
2647 for (int ss = 0; ss != loop_size; ++ss) {
2648 for (auto &gid : *ghost_idx_view[ss]) {
2649 NumeredDofEntityByUId::iterator dof =
2650 dof_by_uid_no_const[ss]->find(gid->getLocalUniqueId());
2651 if (PetscUnlikely((*dof)->petscLocalDofIdx != (DofIdx)-1))
2652 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2653 "inconsistent data, ghost dof already set");
2654 bool success = dof_by_uid_no_const[ss]->modify(
2655 dof, NumeredDofEntity_local_idx_change(nb_local_dofs[ss]++));
2656 if (PetscUnlikely(!success))
2657 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
2658 "modification unsuccessful");
2659 (*nb_ghost_dofs[ss])++;
2660 }
2661 }
2662 if (loop_size == 1) {
2663 (*nb_ghost_dofs[1]) = (*nb_ghost_dofs[0]);
2664 }
2665 }
2666
2667 if (verb > QUIET) {
2668 MOFEM_LOG("SYNC", Sev::inform)
2669 << " FEs ghost dofs on problem " << p_miit->getName()
2670 << " Nb. ghost dof " << p_miit->getNbGhostDofsRow() << " by "
2671 << p_miit->getNbGhostDofsCol() << " Nb. local dof "
2672 << p_miit->getNbLocalDofsRow() << " by " << p_miit->getNbLocalDofsCol();
2673
2675 }
2676
2677 cOre.getBuildMoFEM() |= Core::PARTITION_GHOST_DOFS;
2679}
2680
2682ProblemsManager::partitionGhostDofsOnDistributedMesh(const std::string name,
2683 int verb) {
2684 MoFEM::Interface &m_field = cOre;
2685 auto problems_ptr = m_field.get_problems();
2687
2688 if (!(cOre.getBuildMoFEM() & Core::PARTITION_PROBLEM))
2689 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2690 "partition of problem not build");
2691 if (!(cOre.getBuildMoFEM() & Core::PARTITION_FE))
2692 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2693 "partitions finite elements not build");
2694
2695 // get problem pointer
2696 typedef Problem_multiIndex::index<Problem_mi_tag>::type ProblemsByName;
2697 // find p_miit
2698 ProblemsByName &problems_set =
2699 const_cast<ProblemsByName &>(problems_ptr->get<Problem_mi_tag>());
2700 ProblemsByName::iterator p_miit = problems_set.find(name);
2701
2702 // get reference to number of ghost dofs
2703 // get number of local dofs
2704 DofIdx *nb_ghost_dofs[2] = {&(p_miit->nbGhostDofsRow),
2705 &(p_miit->nbGhostDofsCol)};
2706 DofIdx nb_local_dofs[2] = {p_miit->nbLocDofsRow, p_miit->nbLocDofsCol};
2707 for (int ss = 0; ss != 2; ++ss) {
2708 (*nb_ghost_dofs[ss]) = 0;
2709 }
2710
2711 // do work if more than one processor
2712 if (m_field.get_comm_size() > 1) {
2713 // determine if rows on columns are different from dofs on rows
2714 int loop_size = 2;
2715 if (p_miit->numeredColDofsPtr == p_miit->numeredRowDofsPtr) {
2716 loop_size = 1;
2717 }
2718
2719 typedef decltype(p_miit->numeredRowDofsPtr) NumbDofTypeSharedPtr;
2720 NumbDofTypeSharedPtr numered_dofs[] = {p_miit->numeredRowDofsPtr,
2721 p_miit->numeredColDofsPtr};
2722
2723 // iterate over dofs on rows and dofs on columns
2724 for (int ss = 0; ss != loop_size; ++ss) {
2725
2726 // create dofs view by uid
2727 auto r = numered_dofs[ss]->get<PetscLocalIdx_mi_tag>().equal_range(-1);
2728
2729 std::vector<NumeredDofEntity_multiIndex::iterator> ghost_idx_view;
2730 ghost_idx_view.reserve(std::distance(r.first, r.second));
2731 for (; r.first != r.second; ++r.first)
2732 ghost_idx_view.emplace_back(numered_dofs[ss]->project<0>(r.first));
2733
2734 auto cmp = [](auto a, auto b) {
2735 return (*a)->getLocalUniqueId() < (*b)->getLocalUniqueId();
2736 };
2737 sort(ghost_idx_view.begin(), ghost_idx_view.end(), cmp);
2738
2739 // iterate over dofs which have negative local index
2740 for (auto gid_it : ghost_idx_view) {
2741 bool success = numered_dofs[ss]->modify(
2742 gid_it, NumeredDofEntity_local_idx_change((nb_local_dofs[ss])++));
2743 if (!success)
2744 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
2745 "modification unsuccessful");
2746 ++(*nb_ghost_dofs[ss]);
2747 }
2748 }
2749 if (loop_size == 1) {
2750 (*nb_ghost_dofs[1]) = (*nb_ghost_dofs[0]);
2751 }
2752 }
2753
2754 if (verb > QUIET) {
2755 MOFEM_LOG("SYNC", Sev::inform)
2756 << " FEs ghost dofs on problem " << p_miit->getName()
2757 << " Nb. ghost dof " << p_miit->getNbGhostDofsRow() << " by "
2758 << p_miit->getNbGhostDofsCol() << " Nb. local dof "
2759 << p_miit->getNbLocalDofsRow() << " by " << p_miit->getNbLocalDofsCol();
2760
2762 }
2763
2764 cOre.getBuildMoFEM() |= Core::PARTITION_GHOST_DOFS;
2766}
2767
2768MoFEMErrorCode ProblemsManager::getFEMeshset(const std::string prb_name,
2769 const std::string &fe_name,
2770 EntityHandle *meshset) const {
2771 MoFEM::Interface &m_field = cOre;
2772 const Problem *problem_ptr;
2773 const FiniteElement_multiIndex *fes_ptr;
2775
2776 CHKERR m_field.get_moab().create_meshset(MESHSET_SET, *meshset);
2777 CHKERR m_field.get_problem(prb_name, &problem_ptr);
2778 CHKERR m_field.get_finite_elements(&fes_ptr);
2779
2780 auto fe_miit = fes_ptr->get<FiniteElement_name_mi_tag>().find(fe_name);
2781 if (fe_miit != fes_ptr->get<FiniteElement_name_mi_tag>().end()) {
2782 auto fit =
2783 problem_ptr->numeredFiniteElementsPtr->get<Unique_mi_tag>().lower_bound(
2784 EntFiniteElement::getLocalUniqueIdCalculate(
2785 0, (*fe_miit)->getFEUId()));
2786 auto hi_fe_it =
2787 problem_ptr->numeredFiniteElementsPtr->get<Unique_mi_tag>().upper_bound(
2788 EntFiniteElement::getLocalUniqueIdCalculate(
2789 get_id_for_max_type<MBENTITYSET>(), (*fe_miit)->getFEUId()));
2790 std::vector<EntityHandle> fe_vec;
2791 fe_vec.reserve(std::distance(fit, hi_fe_it));
2792 for (; fit != hi_fe_it; fit++)
2793 fe_vec.push_back(fit->get()->getEnt());
2794 CHKERR m_field.get_moab().add_entities(*meshset, &*fe_vec.begin(),
2795 fe_vec.size());
2796 }
2797
2799}
2800
2802ProblemsManager::getProblemElementsLayout(const std::string name,
2803 const std::string &fe_name,
2804 PetscLayout *layout) const {
2805 MoFEM::Interface &m_field = cOre;
2806 const Problem *problem_ptr;
2808 CHKERR m_field.get_problem(name, &problem_ptr);
2809 CHKERR problem_ptr->getNumberOfElementsByNameAndPart(PETSC_COMM_WORLD,
2810 fe_name, layout);
2812}
2813
2814MoFEMErrorCode ProblemsManager::getSideDofsOnBrokenSpaceEntities(
2815
2816 std::vector<boost::weak_ptr<NumeredDofEntity>> &vec_dof_view,
2817
2818 const std::string problem_name, RowColData rc, const std::string field_name,
2819 const Range ents, int bridge_dim, const int lo_coeff, const int hi_coeff,
2820 const int lo_order, const int hi_order, int verb, const bool debug
2821
2822) const {
2823 MoFEM::Interface &m_field = cOre;
2825
2826 switch (rc) {
2827 case ROW:
2828 case COL:
2829 break;
2830 default:
2831 SETERRQ(m_field.get_comm(), MOFEM_INVALID_DATA, "invalid RowColData");
2832 break;
2833 }
2834
2835 const Problem *prb_ptr;
2836 CHKERR m_field.get_problem(problem_name, &prb_ptr);
2837
2838 decltype(prb_ptr->numeredRowDofsPtr) numered_dofs[2] = {
2839 prb_ptr->numeredRowDofsPtr, nullptr};
2840 if (prb_ptr->numeredRowDofsPtr != prb_ptr->numeredColDofsPtr)
2841 numered_dofs[1] = prb_ptr->numeredColDofsPtr;
2842
2843 Range bridge_ents;
2844 CHKERR m_field.get_moab().get_adjacencies(
2845 ents, bridge_dim, false, bridge_ents, moab::Interface::UNION);
2846
2847 auto &moab = m_field.get_moab();
2848 const auto bit_number = m_field.get_field_bit_number(field_name);
2849 const auto nb_coeffs =
2851 const auto &side_dof_map = m_field.get_field_structure(field_name)
2852 ->getDofSideMap();
2853
2854 using NumeredDofEntity_it_view_multiIndex = multi_index_container<
2855
2856 NumeredDofEntity_multiIndex::iterator, indexed_by<sequenced<>>
2857
2858 >;
2859 NumeredDofEntity_it_view_multiIndex dofs_it_view;
2860
2861 for (auto pit = bridge_ents.const_pair_begin();
2862 pit != bridge_ents.const_pair_end(); ++pit) {
2863 auto lo = numered_dofs[rc]->get<Unique_mi_tag>().lower_bound(
2864 DofEntity::getLoFieldEntityUId(bit_number, pit->first));
2865 auto hi = numered_dofs[rc]->get<Unique_mi_tag>().upper_bound(
2866 DofEntity::getHiFieldEntityUId(bit_number, pit->second));
2867
2868 auto bride_type = moab.type_from_handle(pit->first);
2869
2870 for (; lo != hi; ++lo) {
2871 if ((*lo)->getDofCoeffIdx() >= lo_coeff &&
2872 (*lo)->getDofCoeffIdx() <= hi_coeff &&
2873 (*lo)->getDofOrder() >= lo_order &&
2874 (*lo)->getDofOrder() <= hi_order) {
2875 auto ent_dof_index = (*lo)->getEntDofIdx();
2876 auto side_it = side_dof_map.at(bride_type)
2877 .get<EntDofIdx_mi_tag>()
2878 .find(std::floor(static_cast<double>(ent_dof_index) /
2879 nb_coeffs));
2880 if (side_it !=
2881 side_dof_map.at(bride_type).get<EntDofIdx_mi_tag>().end()) {
2882 auto bridge_ent = (*lo)->getEnt();
2883 auto type = side_it->type;
2884 auto side = side_it->side;
2885 auto dim = CN::Dimension(type);
2886 EntityHandle side_ent = 0;
2887 CHKERR moab.side_element(bridge_ent, dim, side, side_ent);
2888 if (ents.find(side_ent) != ents.end()) {
2889 dofs_it_view.emplace_back(numered_dofs[rc]->project<0>(lo));
2890 }
2891 } else {
2892#ifndef NDEBUG
2893 MOFEM_LOG("SELF", Sev::error)
2894 << *m_field.get_field_structure(field_name);
2895 MOFEM_LOG("SELF", Sev::error)
2896 << "side not found for entity " << CN::EntityTypeName(bride_type);
2897 MOFEM_LOG("SELF", Sev::error)
2898 << "ent_dof_index / nb_coeffs "
2899 << std::floor(static_cast<double>(ent_dof_index) / nb_coeffs);
2900 MOFEM_LOG("SELF", Sev::error)
2901 << "side_dof_map.size() " << side_dof_map.size();
2902#endif // NDEBUG
2903 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
2904 "side not found - you will get more information in debug");
2905 }
2906 }
2907 }
2908 }
2909
2910 if (verb > QUIET) {
2911 for (auto &dof : dofs_it_view)
2912 MOFEM_LOG("SYNC", Sev::noisy) << **dof;
2913 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::noisy);
2914 }
2915
2916 vec_dof_view.reserve(vec_dof_view.size() + dofs_it_view.size());
2917 for (auto dit : dofs_it_view)
2918 vec_dof_view.push_back(*dit);
2919
2921}
2922
2923MoFEMErrorCode ProblemsManager::removeDofs(
2924 const std::string problem_name, RowColData rc,
2925 std::vector<boost::weak_ptr<NumeredDofEntity>> &vec_dof_view, int verb,
2926 const bool debug) {
2927
2928 MoFEM::Interface &m_field = cOre;
2930
2931 switch (rc) {
2932 case ROW:
2933 case COL:
2934 break;
2935 default:
2936 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE, "Should be row or column");
2937 }
2938
2939 const Problem *prb_ptr;
2940 CHKERR m_field.get_problem(problem_name, &prb_ptr);
2941
2942 decltype(prb_ptr->numeredRowDofsPtr) numered_dofs[2] = {
2943 prb_ptr->numeredRowDofsPtr, nullptr};
2944 if (prb_ptr->numeredRowDofsPtr != prb_ptr->numeredColDofsPtr)
2945 numered_dofs[1] = prb_ptr->numeredColDofsPtr;
2946
2947 int *nbdof_ptr[] = {&prb_ptr->nbDofsRow, &prb_ptr->nbDofsCol};
2948 int *local_nbdof_ptr[] = {&prb_ptr->nbLocDofsRow, &prb_ptr->nbLocDofsCol};
2949 int *ghost_nbdof_ptr[] = {&prb_ptr->nbGhostDofsRow, &prb_ptr->nbGhostDofsCol};
2950
2951 const int nb_init_row_dofs = prb_ptr->getNbDofsRow();
2952 const int nb_init_col_dofs = prb_ptr->getNbDofsCol();
2953 const int nb_init_loc_row_dofs = prb_ptr->getNbLocalDofsRow();
2954 const int nb_init_ghost_row_dofs = prb_ptr->getNbGhostDofsRow();
2955 const int nb_init_ghost_col_dofs = prb_ptr->getNbGhostDofsCol();
2956
2957 if (numered_dofs[rc]) {
2958
2959 if (verb >= NOISY)
2960 MOFEM_LOG_C("SYNC", Sev::noisy,
2961 "Number of DOFs in multi-index %zu and to delete %zu\n",
2962 numered_dofs[rc]->size(), vec_dof_view.size());
2963
2964 // erase dofs from problem
2965 for (auto weak_dit : vec_dof_view)
2966 if (auto dit = weak_dit.lock()) {
2967 numered_dofs[rc]->erase(dit->getLocalUniqueId());
2968 }
2969
2970 if (verb >= NOISY)
2971 MOFEM_LOG_C("SYNC", Sev::noisy,
2972 "Number of DOFs in multi-index after delete %zu\n",
2973 numered_dofs[rc]->size());
2974
2975 // get current number of ghost dofs
2976 int nb_local_dofs = 0;
2977 int nb_ghost_dofs = 0;
2978 for (auto dit = numered_dofs[rc]->get<PetscLocalIdx_mi_tag>().begin();
2979 dit != numered_dofs[rc]->get<PetscLocalIdx_mi_tag>().end(); ++dit) {
2980 if ((*dit)->getPetscLocalDofIdx() >= 0 &&
2981 (*dit)->getPetscLocalDofIdx() < *(local_nbdof_ptr[rc]))
2982 ++nb_local_dofs;
2983 else if ((*dit)->getPetscLocalDofIdx() >= *(local_nbdof_ptr[rc]))
2984 ++nb_ghost_dofs;
2985 else
2986 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
2987 "Impossible case. You could run problem on no distributed "
2988 "mesh. That is not implemented. Dof local index is %d",
2989 (*dit)->getPetscLocalDofIdx());
2990 }
2991
2992 // get indices
2993 auto get_indices_by_tag = [&](auto tag, auto &indices, bool only_local) {
2994 const int nb_dofs = numered_dofs[rc]->size();
2995 indices.clear();
2996 indices.reserve(nb_dofs);
2997 for (auto dit = numered_dofs[rc]->get<decltype(tag)>().begin();
2998 dit != numered_dofs[rc]->get<decltype(tag)>().end(); ++dit) {
2999 bool add = true;
3000 if (only_local) {
3001 if ((*dit)->getPetscLocalDofIdx() < 0 ||
3002 (*dit)->getPetscLocalDofIdx() >= *(local_nbdof_ptr[rc])) {
3003 add = false;
3004 }
3005 }
3006 if (add)
3007 indices.push_back(decltype(tag)::get_index(dit));
3008 }
3009 };
3010
3011 auto get_indices_by_uid = [&](auto tag, auto &indices) {
3012 const int nb_dofs = numered_dofs[rc]->size();
3013 indices.clear();
3014 indices.reserve(nb_dofs);
3015 for (auto dit = numered_dofs[rc]->begin(); dit != numered_dofs[rc]->end();
3016 ++dit)
3017 indices.push_back(decltype(tag)::get_index(dit));
3018 };
3019
3020 auto get_sub_ao = [&](auto sub_data) {
3021 if (rc == 0) {
3022 return sub_data->getSmartRowMap();
3023 } else {
3024 return sub_data->getSmartColMap();
3025 }
3026 };
3027
3028 auto set_sub_is_and_ao = [&rc, &prb_ptr](auto sub_data, auto is, auto ao) {
3029 if (rc == ROW) {
3030 sub_data->rowIs = is;
3031 sub_data->rowMap = ao;
3032 if (prb_ptr->numeredRowDofsPtr == prb_ptr->numeredColDofsPtr) {
3033 sub_data->colIs = is;
3034 sub_data->colMap = ao;
3035 }
3036 } else {
3037 sub_data->colIs = is;
3038 sub_data->colMap = ao;
3039 }
3040 };
3041
3042 auto apply_symmetry = [&rc, &prb_ptr](auto sub_data) {
3043 if (rc == ROW) {
3044 if (prb_ptr->numeredRowDofsPtr == prb_ptr->numeredColDofsPtr) {
3045 sub_data->colIs = sub_data->getSmartRowIs();
3046 sub_data->colMap = sub_data->getSmartRowMap();
3047 }
3048 }
3049 };
3050
3051 auto concatenate_dofs = [&](auto tag, auto &indices,
3052 const auto local_only) {
3054 get_indices_by_tag(tag, indices, local_only);
3055
3056 auto indices_ptr = [](auto &indices) {
3057 return indices.empty() ? nullptr : indices.data();
3058 };
3059
3061 // Create AO from app indices (i.e. old), to pestc indices (new after
3062 // remove)
3063 if (local_only)
3064 ao = createAOMapping(m_field.get_comm(), indices.size(),
3065 indices_ptr(indices), PETSC_NULLPTR);
3066 else
3067 ao = createAOMapping(PETSC_COMM_SELF, indices.size(),
3068 indices_ptr(indices), PETSC_NULLPTR);
3069
3070 // Set mapping to sub dm data
3071 if (local_only) {
3072 if (auto sub_data = prb_ptr->getSubData()) {
3073 // create is and then map it to main problem of sub-problem
3074 auto sub_is = createISGeneral(m_field.get_comm(), indices.size(),
3075 indices_ptr(indices), PETSC_COPY_VALUES);
3076 // get old app, i.e. oroginal befor sub indices, and ao, from app,
3077 // to petsc sub indices.
3078 auto sub_ao = get_sub_ao(sub_data);
3079 if (sub_ao.get()) {
3080 CHKERR AOPetscToApplicationIS(sub_ao, sub_is);
3081 sub_ao = createAOMappingIS(sub_is, PETSC_NULLPTR);
3082 } else {
3083 sub_ao = ao;
3084 }
3085 // set new sub ao
3086 set_sub_is_and_ao(sub_data, sub_is, sub_ao);
3087 apply_symmetry(sub_data);
3088 } else {
3089 // create sub data
3090 prb_ptr->getSubData() = boost::make_shared<Problem::SubProblemData>();
3091 auto sub_is = createISGeneral(m_field.get_comm(), indices.size(),
3092 indices_ptr(indices), PETSC_COPY_VALUES);
3093 // set sub is ao
3094 set_sub_is_and_ao(prb_ptr->getSubData(), sub_is, ao);
3095 apply_symmetry(prb_ptr->getSubData());
3096 }
3097 }
3098
3099 get_indices_by_uid(tag, indices);
3100 CHKERR AOApplicationToPetsc(ao, indices.size(), indices_ptr(indices));
3101
3103 };
3104
3105 // set indices index
3106 auto set_concatenated_indices = [&]() {
3107 std::vector<int> global_indices;
3108 std::vector<int> local_indices;
3110 CHKERR concatenate_dofs(PetscGlobalIdx_mi_tag(), global_indices, true);
3111 CHKERR concatenate_dofs(PetscLocalIdx_mi_tag(), local_indices, false);
3112 auto gi = global_indices.begin();
3113 auto li = local_indices.begin();
3114 for (auto dit = numered_dofs[rc]->begin(); dit != numered_dofs[rc]->end();
3115 ++dit) {
3117 (*dit)->getPart(), *gi, *li);
3118 bool success = numered_dofs[rc]->modify(dit, mod);
3119 if (!success)
3120 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
3121 "can not set negative indices");
3122 ++gi;
3123 ++li;
3124 }
3126 };
3127 CHKERR set_concatenated_indices();
3128
3129 MPI_Allreduce(&nb_local_dofs, nbdof_ptr[rc], 1, MPI_INT, MPI_SUM,
3130 m_field.get_comm());
3131 *(local_nbdof_ptr[rc]) = nb_local_dofs;
3132 *(ghost_nbdof_ptr[rc]) = nb_ghost_dofs;
3133
3134 if (debug)
3135 for (auto dof : (*numered_dofs[rc])) {
3136 if (dof->getPetscGlobalDofIdx() < 0) {
3137 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
3138 "Negative global idx");
3139 }
3140 if (dof->getPetscLocalDofIdx() < 0) {
3141 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
3142 "Negative local idx");
3143 }
3144 }
3145
3146 } else {
3147
3148 *(nbdof_ptr[1]) = *(nbdof_ptr[0]);
3149 *(local_nbdof_ptr[1]) = *(local_nbdof_ptr[0]);
3150 *(ghost_nbdof_ptr[1]) = *(ghost_nbdof_ptr[0]);
3151 }
3152
3153 if (verb > QUIET) {
3155 "WORLD", Sev::inform,
3156 "Removed DOFs from problem %s dofs [%d / %d (before %d / %d) global]",
3157 prb_ptr->getName().c_str(), prb_ptr->getNbDofsRow(),
3158 prb_ptr->getNbDofsCol(), nb_init_row_dofs, nb_init_col_dofs);
3159 MOFEM_LOG_C("SYNC", Sev::verbose,
3160 "Removed DOFs from problem %s dofs [ %d / %d "
3161 "(before %d / %d) local, %d / %d (before %d / %d)]",
3162 prb_ptr->getName().c_str(), prb_ptr->getNbLocalDofsRow(),
3163 prb_ptr->getNbLocalDofsCol(), nb_init_loc_row_dofs,
3164 nb_init_loc_row_dofs, prb_ptr->getNbGhostDofsRow(),
3165 prb_ptr->getNbGhostDofsCol(), nb_init_ghost_row_dofs,
3166 nb_init_ghost_col_dofs);
3167 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::verbose);
3168 }
3169
3171}
3172
3173MoFEMErrorCode ProblemsManager::removeDofsOnEntities(
3174 const std::string problem_name, const std::string field_name,
3175 const Range ents, const int lo_coeff, const int hi_coeff,
3176 const int lo_order, const int hi_order, int verb, const bool debug) {
3177
3178 MoFEM::Interface &m_field = cOre;
3180
3181 const Problem *prb_ptr;
3182 CHKERR m_field.get_problem(problem_name, &prb_ptr);
3183
3184 decltype(prb_ptr->numeredRowDofsPtr) numered_dofs[2] = {
3185 prb_ptr->numeredRowDofsPtr, nullptr};
3186 if (prb_ptr->numeredRowDofsPtr != prb_ptr->numeredColDofsPtr)
3187 numered_dofs[1] = prb_ptr->numeredColDofsPtr;
3188
3189 int *nbdof_ptr[] = {&prb_ptr->nbDofsRow, &prb_ptr->nbDofsCol};
3190 int *local_nbdof_ptr[] = {&prb_ptr->nbLocDofsRow, &prb_ptr->nbLocDofsCol};
3191 int *ghost_nbdof_ptr[] = {&prb_ptr->nbGhostDofsRow, &prb_ptr->nbGhostDofsCol};
3192
3193 const int nb_init_row_dofs = prb_ptr->getNbDofsRow();
3194 const int nb_init_col_dofs = prb_ptr->getNbDofsCol();
3195 const int nb_init_loc_row_dofs = prb_ptr->getNbLocalDofsRow();
3196 const int nb_init_loc_col_dofs = prb_ptr->getNbLocalDofsCol();
3197 const int nb_init_ghost_row_dofs = prb_ptr->getNbGhostDofsRow();
3198 const int nb_init_ghost_col_dofs = prb_ptr->getNbGhostDofsCol();
3199
3200 for (int s = 0; s != 2; ++s)
3201 if (numered_dofs[s]) {
3202
3203 using NumeredDofEntity_it_view_multiIndex = multi_index_container<
3204
3205 NumeredDofEntity_multiIndex::iterator, indexed_by<sequenced<>>
3206
3207 >;
3208
3209 const auto bit_number = m_field.get_field_bit_number(field_name);
3210 NumeredDofEntity_it_view_multiIndex dofs_it_view;
3211
3212 // Set -1 to global and local dofs indices
3213 for (auto pit = ents.const_pair_begin(); pit != ents.const_pair_end();
3214 ++pit) {
3215 auto lo = numered_dofs[s]->get<Unique_mi_tag>().lower_bound(
3216 DofEntity::getLoFieldEntityUId(bit_number, pit->first));
3217 auto hi = numered_dofs[s]->get<Unique_mi_tag>().upper_bound(
3218 DofEntity::getHiFieldEntityUId(bit_number, pit->second));
3219
3220 for (; lo != hi; ++lo)
3221 if ((*lo)->getDofCoeffIdx() >= lo_coeff &&
3222 (*lo)->getDofCoeffIdx() <= hi_coeff &&
3223 (*lo)->getDofOrder() >= lo_order &&
3224 (*lo)->getDofOrder() <= hi_order)
3225 dofs_it_view.emplace_back(numered_dofs[s]->project<0>(lo));
3226 }
3227
3228 if (verb > QUIET) {
3229 for (auto &dof : dofs_it_view)
3230 MOFEM_LOG("SYNC", Sev::noisy) << **dof;
3231 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::noisy);
3232 }
3233
3234 // create weak view
3235 std::vector<boost::weak_ptr<NumeredDofEntity>> dofs_weak_view;
3236 dofs_weak_view.reserve(dofs_it_view.size());
3237 for (auto dit : dofs_it_view)
3238 dofs_weak_view.push_back(*dit);
3239
3240 if (verb >= NOISY)
3241 MOFEM_LOG_C("SYNC", Sev::noisy,
3242 "Number of DOFs in multi-index %zu and to delete %zu\n",
3243 numered_dofs[s]->size(), dofs_it_view.size());
3244
3245 // erase dofs from problem
3246 for (auto weak_dit : dofs_weak_view)
3247 if (auto dit = weak_dit.lock()) {
3248 numered_dofs[s]->erase(dit->getLocalUniqueId());
3249 }
3250
3251 if (verb >= NOISY)
3252 MOFEM_LOG_C("SYNC", Sev::noisy,
3253 "Number of DOFs in multi-index after delete %zu\n",
3254 numered_dofs[s]->size());
3255
3256 // get current number of ghost dofs
3257 int nb_local_dofs = 0;
3258 int nb_ghost_dofs = 0;
3259 for (auto dit = numered_dofs[s]->get<PetscLocalIdx_mi_tag>().begin();
3260 dit != numered_dofs[s]->get<PetscLocalIdx_mi_tag>().end(); ++dit) {
3261 if ((*dit)->getPetscLocalDofIdx() >= 0 &&
3262 (*dit)->getPetscLocalDofIdx() < *(local_nbdof_ptr[s]))
3263 ++nb_local_dofs;
3264 else if ((*dit)->getPetscLocalDofIdx() >= *(local_nbdof_ptr[s]))
3265 ++nb_ghost_dofs;
3266 else
3267 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
3268 "Impossible case. You could run problem on no distributed "
3269 "mesh. That is not implemented. Dof local index is %d",
3270 (*dit)->getPetscLocalDofIdx());
3271 }
3272
3273 // get indices
3274 auto get_indices_by_tag = [&](auto tag, auto &indices, bool only_local) {
3275 const int nb_dofs = numered_dofs[s]->size();
3276 indices.clear();
3277 indices.reserve(nb_dofs);
3278 for (auto dit = numered_dofs[s]->get<decltype(tag)>().begin();
3279 dit != numered_dofs[s]->get<decltype(tag)>().end(); ++dit) {
3280 bool add = true;
3281 if (only_local) {
3282 if ((*dit)->getPetscLocalDofIdx() < 0 ||
3283 (*dit)->getPetscLocalDofIdx() >= *(local_nbdof_ptr[s])) {
3284 add = false;
3285 }
3286 }
3287 if (add)
3288 indices.push_back(decltype(tag)::get_index(dit));
3289 }
3290 };
3291
3292 auto get_indices_by_uid = [&](auto tag, auto &indices) {
3293 const int nb_dofs = numered_dofs[s]->size();
3294 indices.clear();
3295 indices.reserve(nb_dofs);
3296 for (auto dit = numered_dofs[s]->begin(); dit != numered_dofs[s]->end();
3297 ++dit)
3298 indices.push_back(decltype(tag)::get_index(dit));
3299 };
3300
3301 auto get_sub_ao = [&](auto sub_data) {
3302 if (s == 0) {
3303 return sub_data->getSmartRowMap();
3304 } else {
3305 return sub_data->getSmartColMap();
3306 }
3307 };
3308
3309 auto set_sub_is_and_ao = [&s, &prb_ptr](auto sub_data, auto is, auto ao) {
3310 if (s == 0) {
3311 sub_data->rowIs = is;
3312 sub_data->rowMap = ao;
3313 if (prb_ptr->numeredRowDofsPtr == prb_ptr->numeredColDofsPtr) {
3314 sub_data->colIs = is;
3315 sub_data->colMap = ao;
3316 }
3317 } else {
3318 sub_data->colIs = is;
3319 sub_data->colMap = ao;
3320 }
3321 };
3322
3323 auto apply_symmetry = [&s, &prb_ptr](auto sub_data) {
3324 if (s == 0) {
3325 if (prb_ptr->numeredRowDofsPtr == prb_ptr->numeredColDofsPtr) {
3326 sub_data->colIs = sub_data->getSmartRowIs();
3327 sub_data->colMap = sub_data->getSmartRowMap();
3328 }
3329 }
3330 };
3331
3332 auto concatenate_dofs = [&](auto tag, auto &indices,
3333 const auto local_only) {
3335 get_indices_by_tag(tag, indices, local_only);
3336
3337 auto indices_ptr = [](auto &indices) {
3338 return indices.empty() ? nullptr : indices.data();
3339 };
3340
3342 // Create AO from app indices (i.e. old), to pestc indices (new after
3343 // remove)
3344 if (local_only)
3345 ao = createAOMapping(m_field.get_comm(), indices.size(),
3346 indices_ptr(indices), PETSC_NULLPTR);
3347 else
3348 ao = createAOMapping(PETSC_COMM_SELF, indices.size(),
3349 indices_ptr(indices), PETSC_NULLPTR);
3350
3351 // Set mapping to sub dm data
3352 if (local_only) {
3353 if (auto sub_data = prb_ptr->getSubData()) {
3354 // create is and then map it to main problem of sub-problem
3355 auto sub_is =
3356 createISGeneral(m_field.get_comm(), indices.size(),
3357 indices_ptr(indices), PETSC_COPY_VALUES);
3358 // get old app, i.e. oroginal befor sub indices, and ao, from app,
3359 // to petsc sub indices.
3360 auto sub_ao = get_sub_ao(sub_data);
3361 if (sub_ao.get()) {
3362 CHKERR AOPetscToApplicationIS(sub_ao, sub_is);
3363 sub_ao = createAOMappingIS(sub_is, PETSC_NULLPTR);
3364 } else {
3365 sub_ao = ao;
3366 }
3367 // set new sub ao
3368 set_sub_is_and_ao(sub_data, sub_is, sub_ao);
3369 apply_symmetry(sub_data);
3370 } else {
3371 // create sub data
3372 prb_ptr->getSubData() =
3373 boost::make_shared<Problem::SubProblemData>();
3374 auto sub_is =
3375 createISGeneral(m_field.get_comm(), indices.size(),
3376 indices_ptr(indices), PETSC_COPY_VALUES);
3377 // set sub is ao
3378 set_sub_is_and_ao(prb_ptr->getSubData(), sub_is, ao);
3379 apply_symmetry(prb_ptr->getSubData());
3380 }
3381 }
3382
3383 get_indices_by_uid(tag, indices);
3384 CHKERR AOApplicationToPetsc(ao, indices.size(), indices_ptr(indices));
3385
3387 };
3388
3389 // set indices index
3390 auto set_concatenated_indices = [&]() {
3391 std::vector<int> global_indices;
3392 std::vector<int> local_indices;
3394 CHKERR concatenate_dofs(PetscGlobalIdx_mi_tag(), global_indices, true);
3395 CHKERR concatenate_dofs(PetscLocalIdx_mi_tag(), local_indices, false);
3396 auto gi = global_indices.begin();
3397 auto li = local_indices.begin();
3398 for (auto dit = numered_dofs[s]->begin(); dit != numered_dofs[s]->end();
3399 ++dit) {
3401 (*dit)->getPart(), *gi, *li);
3402 bool success = numered_dofs[s]->modify(dit, mod);
3403 if (!success)
3404 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
3405 "can not set negative indices");
3406 ++gi;
3407 ++li;
3408 }
3410 };
3411 CHKERR set_concatenated_indices();
3412
3413 MPI_Allreduce(&nb_local_dofs, nbdof_ptr[s], 1, MPI_INT, MPI_SUM,
3414 m_field.get_comm());
3415 *(local_nbdof_ptr[s]) = nb_local_dofs;
3416 *(ghost_nbdof_ptr[s]) = nb_ghost_dofs;
3417
3418 if (debug)
3419 for (auto dof : (*numered_dofs[s])) {
3420 if (dof->getPetscGlobalDofIdx() < 0) {
3421 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
3422 "Negative global idx");
3423 }
3424 if (dof->getPetscLocalDofIdx() < 0) {
3425 SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
3426 "Negative local idx");
3427 }
3428 }
3429
3430 } else {
3431
3432 *(nbdof_ptr[1]) = *(nbdof_ptr[0]);
3433 *(local_nbdof_ptr[1]) = *(local_nbdof_ptr[0]);
3434 *(ghost_nbdof_ptr[1]) = *(ghost_nbdof_ptr[0]);
3435 }
3436
3437 if (verb > QUIET) {
3439 "WORLD", Sev::inform,
3440 "Removed DOFs from problem %s dofs [%d / %d (before %d / %d) global]",
3441 prb_ptr->getName().c_str(), prb_ptr->getNbDofsRow(),
3442 prb_ptr->getNbDofsCol(), nb_init_row_dofs, nb_init_col_dofs);
3443 MOFEM_LOG_C("SYNC", Sev::verbose,
3444 "Removed DOFs from problem %s dofs [ %d / %d "
3445 "(before %d / %d) local, %d / %d (before %d / %d)]",
3446 prb_ptr->getName().c_str(), prb_ptr->getNbLocalDofsRow(),
3447 prb_ptr->getNbLocalDofsCol(), nb_init_loc_row_dofs,
3448 nb_init_loc_col_dofs, prb_ptr->getNbGhostDofsRow(),
3449 prb_ptr->getNbGhostDofsCol(), nb_init_ghost_row_dofs,
3450 nb_init_ghost_col_dofs);
3451 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::verbose);
3452 }
3453
3455}
3456
3457MoFEMErrorCode ProblemsManager::removeDofsOnEntitiesNotDistributed(
3458 const std::string problem_name, const std::string field_name,
3459 const Range ents, const int lo_coeff, const int hi_coeff,
3460 const int lo_order, const int hi_order, int verb, const bool debug) {
3461
3462 MoFEM::Interface &m_field = cOre;
3464
3465 const Problem *prb_ptr;
3466 CHKERR m_field.get_problem(problem_name, &prb_ptr);
3467
3468 decltype(prb_ptr->numeredRowDofsPtr) numered_dofs[2] = {
3469 prb_ptr->numeredRowDofsPtr, nullptr};
3470 if (prb_ptr->numeredRowDofsPtr != prb_ptr->numeredColDofsPtr)
3471 numered_dofs[1] = prb_ptr->numeredColDofsPtr;
3472
3473 int *nbdof_ptr[] = {&prb_ptr->nbDofsRow, &prb_ptr->nbDofsCol};
3474 int *local_nbdof_ptr[] = {&prb_ptr->nbLocDofsRow, &prb_ptr->nbLocDofsCol};
3475 int *ghost_nbdof_ptr[] = {&prb_ptr->nbGhostDofsRow, &prb_ptr->nbGhostDofsCol};
3476
3477 const int nb_init_row_dofs = prb_ptr->getNbDofsRow();
3478 const int nb_init_col_dofs = prb_ptr->getNbDofsCol();
3479 const int nb_init_loc_row_dofs = prb_ptr->getNbLocalDofsRow();
3480 // const int nb_init_loc_col_dofs = prb_ptr->getNbLocalDofsCol();
3481 const int nb_init_ghost_row_dofs = prb_ptr->getNbGhostDofsRow();
3482 const int nb_init_ghost_col_dofs = prb_ptr->getNbGhostDofsCol();
3483
3484 const std::array<int, 2> nb_init_dofs = {nb_init_row_dofs, nb_init_col_dofs};
3485
3486 for (int s = 0; s != 2; ++s)
3487 if (numered_dofs[s]) {
3488
3489 typedef multi_index_container<
3490
3491 NumeredDofEntity_multiIndex::iterator, indexed_by<sequenced<>>
3492
3493 >
3494 NumeredDofEntity_it_view_multiIndex;
3495
3496 const auto bit_number = m_field.get_field_bit_number(field_name);
3497 NumeredDofEntity_it_view_multiIndex dofs_it_view;
3498
3499 // Set -1 to global and local dofs indices
3500 for (auto pit = ents.const_pair_begin(); pit != ents.const_pair_end();
3501 ++pit) {
3502 auto lo = numered_dofs[s]->get<Unique_mi_tag>().lower_bound(
3503 DofEntity::getLoFieldEntityUId(bit_number, pit->first));
3504 auto hi = numered_dofs[s]->get<Unique_mi_tag>().upper_bound(
3505 DofEntity::getHiFieldEntityUId(bit_number, pit->second));
3506
3507 for (; lo != hi; ++lo)
3508 if ((*lo)->getDofCoeffIdx() >= lo_coeff &&
3509 (*lo)->getDofCoeffIdx() <= hi_coeff &&
3510 (*lo)->getDofOrder() >= lo_order &&
3511 (*lo)->getDofOrder() <= hi_order)
3512 dofs_it_view.emplace_back(numered_dofs[s]->project<0>(lo));
3513 }
3514
3515 if (verb > QUIET) {
3516 for (auto &dof : dofs_it_view)
3517 MOFEM_LOG("SYNC", Sev::noisy) << **dof;
3518 }
3519
3520 // set negative index
3521 auto mod = NumeredDofEntity_part_and_indices_change(-1, -1, -1);
3522 for (auto dit : dofs_it_view) {
3523 bool success = numered_dofs[s]->modify(dit, mod);
3524 if (!success)
3525 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
3526 "can not set negative indices");
3527 }
3528
3529 // create weak view
3530 std::vector<boost::weak_ptr<NumeredDofEntity>> dosf_weak_view;
3531 dosf_weak_view.reserve(dofs_it_view.size());
3532 for (auto dit : dofs_it_view)
3533 dosf_weak_view.push_back(*dit);
3534
3535 if (verb >= NOISY)
3536 MOFEM_LOG_C("SYNC", Sev::noisy,
3537 "Number of DOFs in multi-index %zu and to delete %zu\n",
3538 numered_dofs[s]->size(), dofs_it_view.size());
3539
3540 // erase dofs from problem
3541 for (auto weak_dit : dosf_weak_view)
3542 if (auto dit = weak_dit.lock()) {
3543 numered_dofs[s]->erase(dit->getLocalUniqueId());
3544 }
3545
3546 if (verb >= NOISY)
3547 MOFEM_LOG_C("SYNC", Sev::noisy,
3548 "Number of DOFs in multi-index after delete %zu\n",
3549 numered_dofs[s]->size());
3550
3551 // get current number of ghost dofs
3552 int nb_global_dof = 0;
3553 int nb_local_dofs = 0;
3554 int nb_ghost_dofs = 0;
3555
3556 for (auto dit = numered_dofs[s]->begin(); dit != numered_dofs[s]->end();
3557 ++dit) {
3558
3559 if ((*dit)->getPetscGlobalDofIdx() >= 0) {
3560
3561 if ((*dit)->getPetscLocalDofIdx() >= 0 &&
3562 (*dit)->getPetscLocalDofIdx() < *(local_nbdof_ptr[s]))
3563 ++nb_local_dofs;
3564 else if ((*dit)->getPetscLocalDofIdx() >= *(local_nbdof_ptr[s]))
3565 ++nb_ghost_dofs;
3566
3567 ++nb_global_dof;
3568 }
3569 }
3570
3571 if (debug) {
3572 MPI_Allreduce(&nb_local_dofs, nbdof_ptr[s], 1, MPI_INT, MPI_SUM,
3573 m_field.get_comm());
3574 if (*(nbdof_ptr[s]) != nb_global_dof)
3575 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
3576 "Number of local DOFs do not add up %d != %d",
3577 *(nbdof_ptr[s]), nb_global_dof);
3578 }
3579
3580 *(nbdof_ptr[s]) = nb_global_dof;
3581 *(local_nbdof_ptr[s]) = nb_local_dofs;
3582 *(ghost_nbdof_ptr[s]) = nb_ghost_dofs;
3583
3584 // Indices in slots of the global index before renumbering. The slots
3585 // are sized by the global count: on a replicated mesh DOFs of other
3586 // parts have a global index but no local index.
3587 auto get_indices_by_tag = [&](auto tag) {
3588 std::vector<int> indices;
3589 indices.resize(nb_init_dofs[s], -1);
3590 for (auto dit =
3591 numered_dofs[s]->get<PetscGlobalIdx_mi_tag>().lower_bound(0);
3592 dit != numered_dofs[s]->get<PetscGlobalIdx_mi_tag>().end();
3593 ++dit) {
3594 indices[(*dit)->getPetscGlobalDofIdx()] =
3595 decltype(tag)::get_index(dit);
3596 }
3597 return indices;
3598 };
3599
3600 auto renumber = [&](auto tag, auto &indices) {
3602 int idx = 0;
3603 for (auto dit = numered_dofs[s]->get<decltype(tag)>().lower_bound(0);
3604 dit != numered_dofs[s]->get<decltype(tag)>().end(); ++dit) {
3605 indices[(*dit)->getPetscGlobalDofIdx()] = idx++;
3606 }
3608 };
3609
3610 auto get_sub_ao = [&](auto sub_data) {
3611 if (s == 0) {
3612 return sub_data->getSmartRowMap();
3613 } else {
3614 return sub_data->getSmartColMap();
3615 }
3616 };
3617
3618 auto set_sub_is_and_ao = [&s, &prb_ptr](auto sub_data, auto is, auto ao) {
3619 if (s == 0) {
3620 sub_data->rowIs = is;
3621 sub_data->rowMap = ao;
3622 if (prb_ptr->numeredRowDofsPtr == prb_ptr->numeredColDofsPtr) {
3623 sub_data->colIs = is;
3624 sub_data->colMap = ao;
3625 }
3626 } else {
3627 sub_data->colIs = is;
3628 sub_data->colMap = ao;
3629 }
3630 };
3631
3632 auto apply_symmetry = [&s, &prb_ptr](auto sub_data) {
3633 if (s == 0) {
3634 if (prb_ptr->numeredRowDofsPtr == prb_ptr->numeredColDofsPtr) {
3635 sub_data->colIs = sub_data->getSmartRowIs();
3636 sub_data->colMap = sub_data->getSmartRowMap();
3637 }
3638 }
3639 };
3640
3641 auto set_sub_data = [&](auto &indices) {
3643 auto indices_ptr = [](auto &indices) {
3644 return indices.empty() ? nullptr : indices.data();
3645 };
3646 if (auto sub_data = prb_ptr->getSubData()) {
3647 // create is and then map it to main problem of sub-problem
3648 auto sub_is = createISGeneral(m_field.get_comm(), indices.size(),
3649 indices_ptr(indices), PETSC_COPY_VALUES);
3650 // get old app, i.e. oroginal befor sub indices, and ao, from
3651 // app, to petsc sub indices.
3652 auto sub_ao = get_sub_ao(sub_data);
3653 if (sub_ao.get())
3654 CHKERR AOPetscToApplicationIS(sub_ao, sub_is);
3655 sub_ao = createAOMappingIS(sub_is, PETSC_NULLPTR);
3656 // set new sub ao
3657 set_sub_is_and_ao(sub_data, sub_is, sub_ao);
3658 apply_symmetry(sub_data);
3659 } else {
3660 prb_ptr->getSubData() = boost::make_shared<Problem::SubProblemData>();
3661 auto sub_is = createISGeneral(m_field.get_comm(), indices.size(),
3662 indices_ptr(indices), PETSC_COPY_VALUES);
3663 auto sub_ao = createAOMappingIS(sub_is, PETSC_NULLPTR);
3664 // set sub is ao
3665 set_sub_is_and_ao(prb_ptr->getSubData(), sub_is, sub_ao);
3666 apply_symmetry(prb_ptr->getSubData());
3667 }
3669 };
3670
3671 auto global_indices = get_indices_by_tag(PetscGlobalIdx_mi_tag());
3672 auto local_indices = get_indices_by_tag(PetscLocalIdx_mi_tag());
3673 CHKERR set_sub_data(global_indices);
3674 CHKERR renumber(PetscGlobalIdx_mi_tag(), global_indices);
3675 CHKERR renumber(PetscLocalIdx_mi_tag(), local_indices);
3676
3677 for (auto dit = numered_dofs[s]->begin(); dit != numered_dofs[s]->end();
3678 ++dit) {
3679 const auto idx = (*dit)->getPetscGlobalDofIdx();
3680 if (idx >= 0) {
3682 (*dit)->getPart(), global_indices[idx], local_indices[idx]);
3683 bool success = numered_dofs[s]->modify(dit, mod);
3684 if (!success)
3685 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
3686 "can not set negative indices");
3687 } else {
3689 (*dit)->getPart(), -1, -1);
3690 bool success = numered_dofs[s]->modify(dit, mod);
3691 if (!success)
3692 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
3693 "can not set negative indices");
3694 }
3695 };
3696
3697 if (debug) {
3698 for (auto dof : (*numered_dofs[s])) {
3699 if (dof->getPetscGlobalDofIdx() >= *(nbdof_ptr[s])) {
3700 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
3701 "Global idx out of range");
3702 }
3703 }
3704 }
3705
3706 } else {
3707
3708 *(nbdof_ptr[1]) = *(nbdof_ptr[0]);
3709 *(local_nbdof_ptr[1]) = *(local_nbdof_ptr[0]);
3710 *(ghost_nbdof_ptr[1]) = *(ghost_nbdof_ptr[0]);
3711 }
3712
3713 if (verb >= NOISY)
3715
3716 if (verb > QUIET) {
3718 "WORLD", Sev::inform,
3719 "Removed DOFs from problem %s dofs [%d / %d (before %d / %d) global]",
3720 prb_ptr->getName().c_str(), prb_ptr->getNbDofsRow(),
3721 prb_ptr->getNbDofsCol(), nb_init_row_dofs, nb_init_col_dofs);
3722 MOFEM_LOG_C("SYNC", Sev::verbose,
3723 "Removed DOFs from problem %s dofs [ %d / %d "
3724 "(before %d / %d) local, %d / %d (before %d / %d)]",
3725 prb_ptr->getName().c_str(), prb_ptr->getNbLocalDofsRow(),
3726 prb_ptr->getNbLocalDofsCol(), nb_init_loc_row_dofs,
3727 nb_init_loc_row_dofs, prb_ptr->getNbGhostDofsRow(),
3728 prb_ptr->getNbGhostDofsCol(), nb_init_ghost_row_dofs,
3729 nb_init_ghost_col_dofs);
3731 }
3733}
3734
3735MoFEMErrorCode ProblemsManager::removeDofsOnEntities(
3736 const std::string problem_name, const std::string field_name,
3737 const BitRefLevel bit_ref_level, const BitRefLevel bit_ref_mask,
3738 Range *ents_ptr, const int lo_coeff, const int hi_coeff, const int lo_order,
3739 const int hi_order, int verb, const bool debug) {
3740 MoFEM::Interface &m_field = cOre;
3742
3743 auto bit_manager = m_field.getInterface<BitRefManager>();
3744
3745 Range ents;
3746 if (ents_ptr) {
3747 ents = *ents_ptr;
3748 CHKERR bit_manager->filterEntitiesByRefLevel(bit_ref_level, bit_ref_mask,
3749 ents, verb);
3750 } else {
3751 CHKERR bit_manager->getEntitiesByRefLevel(bit_ref_level, bit_ref_mask, ents,
3752 verb);
3753 }
3754
3755 CHKERR removeDofsOnEntities(problem_name, field_name, ents, lo_coeff,
3756 hi_coeff, lo_order, hi_order, verb, debug);
3757
3759}
3760
3761MoFEMErrorCode ProblemsManager::removeDofsOnEntitiesNotDistributed(
3762 const std::string problem_name, const std::string field_name,
3763 const BitRefLevel bit_ref_level, const BitRefLevel bit_ref_mask,
3764 Range *ents_ptr, const int lo_coeff, const int hi_coeff, const int lo_order,
3765 const int hi_order, int verb, const bool debug) {
3766 MoFEM::Interface &m_field = cOre;
3768
3769 auto bit_manager = m_field.getInterface<BitRefManager>();
3770
3771 Range ents;
3772 if (ents_ptr) {
3773 ents = *ents_ptr;
3774 CHKERR bit_manager->filterEntitiesByRefLevel(bit_ref_level, bit_ref_mask,
3775 ents, verb);
3776 } else {
3777 CHKERR bit_manager->getEntitiesByRefLevel(bit_ref_level, bit_ref_mask, ents,
3778 verb);
3779 }
3780
3781 CHKERR removeDofsOnEntitiesNotDistributed(problem_name, field_name, ents,
3782 lo_coeff, hi_coeff, lo_order,
3783 hi_order, verb, debug);
3784
3786}
3787
3789ProblemsManager::markDofs(const std::string problem_name, RowColData rc,
3790 const enum MarkOP op, const Range ents,
3791 std::vector<unsigned char> &marker) const {
3792
3793 Interface &m_field = cOre;
3794 const Problem *problem_ptr;
3796 CHKERR m_field.get_problem(problem_name, &problem_ptr);
3797 boost::shared_ptr<NumeredDofEntity_multiIndex> dofs;
3798 switch (rc) {
3799 case ROW:
3800 dofs = problem_ptr->getNumeredRowDofsPtr();
3801 break;
3802 case COL:
3803 dofs = problem_ptr->getNumeredColDofsPtr();
3804 default:
3805 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE, "Should be row or column");
3806 }
3807 marker.resize(dofs->size(), 0);
3808 std::vector<unsigned char> marker_tmp;
3809
3810 switch (op) {
3811 case MarkOP::OR:
3812 for (auto p = ents.pair_begin(); p != ents.pair_end(); ++p) {
3813 auto lo = dofs->get<Ent_mi_tag>().lower_bound(p->first);
3814 auto hi = dofs->get<Ent_mi_tag>().upper_bound(p->second);
3815 for (; lo != hi; ++lo) {
3816 if ((*lo)->getPetscLocalDofIdx() < 0)
3817 continue;
3818 marker[(*lo)->getPetscLocalDofIdx()] |= 1;
3819 }
3820 }
3821 break;
3822 case MarkOP::AND:
3823 marker_tmp.resize(dofs->size(), 0);
3824 for (auto p = ents.pair_begin(); p != ents.pair_end(); ++p) {
3825 auto lo = dofs->get<Ent_mi_tag>().lower_bound(p->first);
3826 auto hi = dofs->get<Ent_mi_tag>().upper_bound(p->second);
3827 for (; lo != hi; ++lo) {
3828 if ((*lo)->getPetscLocalDofIdx() < 0)
3829 continue;
3830 marker_tmp[(*lo)->getPetscLocalDofIdx()] = 1;
3831 }
3832 }
3833 for (int i = 0; i != marker.size(); ++i) {
3834 marker[i] &= marker_tmp[i];
3835 }
3836 break;
3837 }
3838
3840}
3841
3842MoFEMErrorCode ProblemsManager::modifyMarkDofs(
3843 const std::string problem_name, RowColData rc, const std::string field_name,
3844 const int lo, const int hi, const enum ProblemsManager::MarkOP op,
3845 const unsigned char c, std::vector<unsigned char> &marker) const {
3846
3847 Interface &m_field = cOre;
3848 const Problem *problem_ptr;
3850 CHKERR m_field.get_problem(problem_name, &problem_ptr);
3851 boost::shared_ptr<NumeredDofEntity_multiIndex> dofs;
3852 switch (rc) {
3853 case ROW:
3854 dofs = problem_ptr->getNumeredRowDofsPtr();
3855 break;
3856 case COL:
3857 dofs = problem_ptr->getNumeredColDofsPtr();
3858 default:
3859 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE, "Should be row or column");
3860 }
3861 marker.resize(dofs->size(), 0);
3862
3863 auto dof_lo = dofs->get<Unique_mi_tag>().lower_bound(
3864 FieldEntity::getLoBitNumberUId(m_field.get_field_bit_number(field_name)));
3865 auto dof_hi = dofs->get<Unique_mi_tag>().upper_bound(
3866 FieldEntity::getHiBitNumberUId(m_field.get_field_bit_number(field_name)));
3867
3868 switch (op) {
3869 case MarkOP::OR:
3870 for (; dof_lo != dof_hi; ++dof_lo) {
3871 if ((*dof_lo)->getPetscLocalDofIdx() < 0)
3872 continue;
3873 if ((*dof_lo)->getDofCoeffIdx() >= lo &&
3874 (*dof_lo)->getDofCoeffIdx() <= hi)
3875 marker[(*dof_lo)->getPetscLocalDofIdx()] |= c;
3876 }
3877 break;
3878 case MarkOP::AND:
3879 for (; dof_lo != dof_hi; ++dof_lo) {
3880 if ((*dof_lo)->getPetscLocalDofIdx() < 0)
3881 continue;
3882 if ((*dof_lo)->getDofCoeffIdx() >= lo &&
3883 (*dof_lo)->getDofCoeffIdx() <= hi)
3884 marker[(*dof_lo)->getPetscLocalDofIdx()] &= c;
3885 }
3886 break;
3887 }
3888
3890}
3891
3892MoFEMErrorCode ProblemsManager::markDofs(
3893
3894 const std::string problem_name, RowColData rc,
3895 std::vector<boost::weak_ptr<NumeredDofEntity>> &vec_dof_view,
3896 const enum MarkOP op, std::vector<unsigned char> &marker
3897
3898) const {
3899 Interface &m_field = cOre;
3901
3902 const Problem *problem_ptr;
3903 CHKERR m_field.get_problem(problem_name, &problem_ptr);
3904 boost::shared_ptr<NumeredDofEntity_multiIndex> dofs;
3905 switch (rc) {
3906 case ROW:
3907 dofs = problem_ptr->getNumeredRowDofsPtr();
3908 break;
3909 case COL:
3910 dofs = problem_ptr->getNumeredColDofsPtr();
3911 break;
3912 default:
3913 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE, "Should be row or column");
3914 }
3915 marker.resize(dofs->size(), 0);
3916
3917 for (auto &dof : vec_dof_view) {
3918 if (auto dof_ptr = dof.lock()) {
3919 if (dof_ptr->getPetscLocalDofIdx() < 0)
3920 continue;
3921 if (op == MarkOP::OR)
3922 marker[dof_ptr->getPetscLocalDofIdx()] |= 1;
3923 else
3924 marker[dof_ptr->getPetscLocalDofIdx()] &= 1;
3925 }
3926 }
3927
3929}
3930
3932ProblemsManager::addFieldToEmptyFieldBlocks(const std::string problem_name,
3933 const std::string row_field,
3934 const std::string col_field) const {
3935
3936 Interface &m_field = cOre;
3938
3939 const auto problem_ptr = m_field.get_problem(problem_name);
3940 auto get_field_id = [&](const std::string field_name) {
3941 return m_field.get_field_structure(field_name)->getId();
3942 };
3943 const auto row_id = get_field_id(row_field);
3944 const auto col_id = get_field_id(col_field);
3945
3946 problem_ptr->addFieldToEmptyFieldBlocks(BlockFieldPair(row_id, col_id));
3947
3949}
3950
3951} // namespace MoFEM
std::vector< int > size
unsigned char status
ParentChildKey key
MPI_Comm comm
Core & cOre
Tag tag
ProjectedField & field
std::map< EntityHandle, std::pair< bool, std::vector< double > > > previous
std::vector< double > empty
One value per component.
std::map< EntityHandle, std::vector< double > > staged
std::string type
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
#define MOFEM_LOG_SYNCHRONISE(comm)
Synchronise "SYNC" channel.
#define MOFEM_LOG_C(channel, severity, format,...)
#define ProblemManagerFunctionBegin
It it
Definition Schur.cpp:2568
int nb
number of DOFs
Definition Schur.cpp:2505
It end
Definition Schur.cpp:2568
std::string name
constexpr double a
@ VERY_VERBOSE
@ QUIET
@ NOISY
@ VERBOSE
RowColData
RowColData.
@ COL
@ ROW
@ 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_IMPOSSIBLE_CASE
Definition definitions.h:35
@ MOFEM_OPERATION_UNSUCCESSFUL
Definition definitions.h:34
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
@ MOFEM_INVALID_DATA
Definition definitions.h:36
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
#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 ...
static const bool debug
multi_index_container< boost::shared_ptr< FieldEntity >, indexed_by< ordered_unique< tag< Unique_mi_tag >, const_mem_fun< FieldEntity, UId, &FieldEntity::getGlobalUniqueId > > > > FieldEntity_multiIndex_global_uid_view
multi-index view on DofEntity by uid
NumeredDofEntity_multiIndex::index< Unique_mi_tag >::type NumeredDofEntityByUId
Numbered DoF multi-index by UId.
multi_index_container< boost::shared_ptr< NumeredDofEntity >, indexed_by< ordered_unique< tag< Unique_mi_tag >, const_mem_fun< NumeredDofEntity::interface_type_DofEntity, UId, &NumeredDofEntity::getLocalUniqueId > >, ordered_non_unique< tag< Part_mi_tag >, member< NumeredDofEntity, unsigned int, &NumeredDofEntity::pArt > >, ordered_non_unique< tag< PetscGlobalIdx_mi_tag >, member< NumeredDofEntity, DofIdx, &NumeredDofEntity::petscGloablDofIdx > >, ordered_non_unique< tag< PetscLocalIdx_mi_tag >, member< NumeredDofEntity, DofIdx, &NumeredDofEntity::petscLocalDofIdx > >, ordered_non_unique< tag< Ent_mi_tag >, const_mem_fun< NumeredDofEntity::interface_type_DofEntity, EntityHandle, &NumeredDofEntity::getEnt > > > > NumeredDofEntity_multiIndex
MultiIndex container keeps NumeredDofEntity.
multi_index_container< boost::shared_ptr< NumeredEntFiniteElement >, indexed_by< ordered_unique< tag< Unique_mi_tag >, const_mem_fun< NumeredEntFiniteElement::interface_type_EntFiniteElement, UId, &NumeredEntFiniteElement::getLocalUniqueId > >, ordered_non_unique< tag< Part_mi_tag >, member< NumeredEntFiniteElement, unsigned int, &NumeredEntFiniteElement::part > >, ordered_non_unique< tag< Ent_mi_tag >, const_mem_fun< NumeredEntFiniteElement::interface_type_RefEntity, EntityHandle, &NumeredEntFiniteElement::getEnt > >, ordered_non_unique< tag< Composite_Name_And_Part_mi_tag >, composite_key< NumeredEntFiniteElement, const_mem_fun< NumeredEntFiniteElement::interface_type_FiniteElement, boost::string_ref, &NumeredEntFiniteElement::getNameRef >, member< NumeredEntFiniteElement, unsigned int, &NumeredEntFiniteElement::part > > > > > NumeredEntFiniteElement_multiIndex
MultiIndex for entities for NumeredEntFiniteElement.
multi_index_container< boost::shared_ptr< FiniteElement >, indexed_by< hashed_unique< tag< FiniteElement_Meshset_mi_tag >, member< FiniteElement, EntityHandle, &FiniteElement::meshset > >, hashed_unique< tag< BitFEId_mi_tag >, const_mem_fun< FiniteElement, BitFEId, &FiniteElement::getId >, HashBit< BitFEId >, EqBit< BitFEId > >, ordered_unique< tag< FiniteElement_name_mi_tag >, const_mem_fun< FiniteElement, boost::string_ref, &FiniteElement::getNameRef > > > > FiniteElement_multiIndex
MultiIndex for entities for FiniteElement.
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
virtual const FieldEntity_multiIndex * get_field_ents() const =0
Get the field ents object.
virtual MoFEMErrorCode get_ents_elements_adjacency(const FieldEntityEntFiniteElementAdjacencyMap_multiIndex **dofs_elements_adjacency) const =0
Get the dofs elements adjacency object.
virtual const FiniteElement_multiIndex * get_finite_elements() const =0
Get the finite elements object.
virtual const DofEntity_multiIndex * get_dofs() const =0
Get the dofs object.
virtual const Problem_multiIndex * get_problems() const =0
Get the problems object.
virtual const EntFiniteElement_multiIndex * get_ents_finite_elements() const =0
Get the ents finite elements object.
virtual const Field_multiIndex * get_fields() const =0
Get the fields object.
virtual const Field * get_field_structure(const std::string &name, enum MoFEMTypes bh=MF_EXIST) const =0
get field structure
#define MOFEM_LOG(channel, severity)
Log.
MoFEMErrorCode buildProblemOnDistributedMesh(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures, assuming that mesh is distributed (collective)
MoFEMErrorCode printPartitionedProblem(const Problem *problem_ptr, int verb=VERBOSE)
Print partition information for debugging.
MoFEMErrorCode rebuildProblemOnDistributedMesh(const std::string &name, const BitRefLevel target_bit, const BitRefLevel target_mask, const bool square_matrix, int verb=VERBOSE, SmartPetscObj< IS > *old_row_indices=nullptr, SmartPetscObj< IS > *new_row_indices=nullptr)
Rebuild a parent problem in place on a distributed mesh (collective)
MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
DEPRECATED MoFEMErrorCode partitionMesh(const Range &ents, const int dim, const int adj_dim, const int n_parts, Tag *th_vertex_weights=nullptr, Tag *th_edge_weights=nullptr, Tag *th_part_weights=nullptr, int verb=VERBOSE, const bool debug=false)
Set partition tag to each finite element in the problem.
MoFEMErrorCode buildSubProblem(const std::string out_name, const std::vector< std::string > &fields_row, const std::vector< std::string > &fields_col, const std::string main_problem, const bool square_matrix=true, const map< std::string, boost::shared_ptr< Range > > *entityMapRow=nullptr, const map< std::string, boost::shared_ptr< Range > > *entityMapCol=nullptr, int verb=VERBOSE)
build sub problem
MoFEMErrorCode debugPartitionedProblem(const Problem *problem_ptr, int verb=VERBOSE)
Debug partition information.
MoFEMErrorCode getOptions()
Get command line options for ProblemsManager.
virtual MoFEMErrorCode add_problem(const std::string &name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add problem.
virtual MoFEMErrorCode delete_problem(const std::string name)=0
Delete problem.
virtual MoFEMErrorCode clear_problem(const std::string name, int verb=DEFAULT_VERBOSITY)=0
clear problem
virtual bool check_problem(const std::string name)=0
check if problem exist
auto marker
set bit to marker
FTensor::Index< 'i', SPACE_DIM > i
const double c
speed of light (cm/ns)
const double v
phase velocity of light in medium (cm/ns)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
int DofIdx
Index of DOF.
Definition Types.hpp:18
std::bitset< BITFIELDID_SIZE > BitFieldId
Field Id.
Definition Types.hpp:42
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
auto type_from_handle(const EntityHandle h)
get type from entity handle
auto createISGeneral(MPI_Comm comm, PetscInt n, const PetscInt idx[], PetscCopyMode mode)
Creates a data structure for an index set containing a list of integers.
auto createAOMapping(MPI_Comm comm, PetscInt napp, const PetscInt myapp[], const PetscInt mypetsc[])
Creates an application mapping using two integer arrays.
auto createAOMappingIS(IS isapp, IS ispetsc)
Creates an application mapping using two index sets.
auto field_bit_from_bit_number(const int bit_number)
get field bit id from bit number
Problem::BlockFieldPair BlockFieldPair
auto get_temp_meshset_ptr(moab::Interface &moab)
Create smart pointer to temporary meshset.
multi_index_container< boost::shared_ptr< NumeredDofEntity >, indexed_by< ordered_unique< const_mem_fun< NumeredDofEntity::interface_type_DofEntity, UId, &NumeredDofEntity::getLocalUniqueId > > > > NumeredDofEntity_multiIndex_uid_view_ordered
static void publish_numbered_dofs(NumeredDofEntity_multiIndex &dofs, const boost::shared_ptr< std::vector< NumeredDofEntity > > &sequence_ptr, const bool serial_uid_numbering=false)
Publish stable records using hints shared by all five ordered indices.
constexpr auto field_name
FTensor::Index< 'm', 3 > m
Managing BitRefLevels.
Managing BitRefLevels.
virtual int get_comm_size() const =0
virtual FieldBitNumber get_field_bit_number(const std::string name) const =0
get field bit number
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() const =0
virtual std::string get_field_name(const BitFieldId id) const =0
get field name from id
virtual int get_comm_rank() const =0
virtual boost::shared_ptr< BasicEntityData > & get_basic_entity_data_ptr()=0
Get pointer to basic entity data.
Core (interface) class.
Definition Core.hpp:83
int & getBuildMoFEM() const
Get flags/semaphores for different stages.
Definition Core.hpp:230
Deprecated interface functions.
static UId getLoFieldEntityUId(const FieldBitNumber bit, const EntityHandle ent)
static UId getHiFieldEntityUId(const FieldBitNumber bit, const EntityHandle ent)
static UId getUniqueIdCalculate(const DofIdx dof, const UId &ent_uid)
Struct keeps handle to entity in the field.
static UId getHiBitNumberUId(const FieldBitNumber bit_number)
static auto getHandleFromUniqueId(const UId uid)
Get the Handle From Unique Id.
static auto getFieldBitNumberFromUniqueId(const UId uid)
Get the Field Bit Number From Unique Id.
UId getLocalUniqueIdCalculate()
Get the Local Unique Id Calculate object.
static UId getLoBitNumberUId(const FieldBitNumber bit_number)
UId getGlobalUniqueId() const
Get global unique id.
static auto getOwnerFromUniqueId(const UId uid)
UId getGlobalUniqueIdCalculate() const
Calculate global UId.
FieldCoefficientsNumber getNbOfCoeffs() const
Get number of field coefficients per DOF.
std::map< int, BaseFunction::DofsSideMap > & getDofSideMap() const
Get DOF side mapping for broken spaces.
const BitFieldId & getId() const
Get unique field identifier.
IdxDataTypePtr(const int *ptr)
IdxDataType(const UId uid, const int dof)
Matrix manager is used to build and partition problems.
keeps information about indexed dofs for the problem
Partitioned (Indexed) Finite Element in Problem.
Index tags of the numbered DOF containers that also read the index.
keeps basic data about problem
DofIdx getNbLocalDofsRow() const
MoFEMErrorCode getNumberOfElementsByNameAndPart(MPI_Comm comm, const std::string name, PetscLayout *layout) const
Get number of finite elements by name on processors.
DofIdx getNbDofsRow() const
BitRefLevel getBitRefLevel() const
auto & getColDofsSequence() const
Get reference to sequence data numbered dof container.
BitRefLevel getBitRefLevelMask() const
boost::shared_ptr< SubProblemData > & getSubData() const
Get main problem of sub-problem is.
DofIdx nbGhostDofsCol
Number of ghost DOFs in col.
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredRowDofsPtr
store DOFs on rows for this problem
boost::shared_ptr< NumeredEntFiniteElement_multiIndex > numeredFiniteElementsPtr
store finite elements
DofIdx getNbGhostDofsCol() const
DofIdx nbLocDofsRow
Local number of DOFs in row.
BitFEId getBitFEId() const
Get the BitFEIDs in problem
DofIdx nbDofsCol
Global number of DOFs in col.
DofIdx getNbDofsCol() const
DofIdx getNbLocalDofsCol() const
DofIdx nbGhostDofsRow
Number of ghost DOFs in row.
auto & getNumeredColDofsPtr() const
get access to numeredColDofsPtr storing DOFs on cols
DofIdx nbLocDofsCol
Local number of DOFs in colIs.
DofIdx nbDofsRow
Global number of DOFs in row.
DofIdx getNbGhostDofsRow() const
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredColDofsPtr
store DOFs on columns for this problem
auto & getNumeredRowDofsPtr() const
get access to numeredRowDofsPtr storing DOFs on rows
auto & getRowDofsSequence() const
Get reference to sequence data numbered dof container.
Problem manager is used to build and partition problems.
ProblemsManager(const MoFEM::Core &core)
PetscLogEvent MOFEM_EVENT_ProblemsManager
PetscBool synchroniseProblemEntities
DOFs in fields, not from DOFs on elements.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
intrusive_ptr for managing petsc objects
base class for all interface classes
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.