v0.16.3
Loading...
Searching...
No Matches
rebuild_problem_hybrid.cpp
Go to the documentation of this file.
1/** \file rebuild_problem_hybrid.cpp
2 * \example mofem/atom_tests/rebuild_problem_hybrid.cpp
3 * \brief Build a hybridised broken H(div) problem on uniformly refined
4 * levels and time its problem, sub-problems and matrices.
5 *
6 * Fields, as in test_broken_space.cpp: BROKEN (broken H(div)) and U (L2) on
7 * the interior, HYBRID (L2) on the skeleton; the domain element carries
8 * BROKEN and U, the skeleton element BROKEN and HYBRID through the skeleton
9 * adjacency. At every level, after the uniform refinement of the previous
10 * one, the test times and checks:
11 *
12 * 1. incremental field and element registration on new tetrahedra and
13 * skeleton faces (or Simple's all-entities builders);
14 * 2. the parent problem (adjacencies and DMSetUp through Simple::reSetUp);
15 * 3. the SCHUR sub-problem, HYBRID only on both elements, and the BLOCK
16 * sub-problem, BROKEN and U;
17 * 4. the block matrix of the parent (createBlockMatStructure and
18 * createBlockMat) and the nested Schur matrix on the two sub-problems;
19 * 5. the hybridised L2 matrix of the SCHUR sub-problem
20 * (MatrixManager::createHybridL2MPIAIJ through
21 * createDMHybridisedL2Matrix), the Schur complement's pattern.
22 *
23 * DOF counts are checked against the entity counts and the per-entity DOF
24 * numbers of the bases; every stage is a TestingInterface test. Options:
25 * -file_name, -nb_levels, -order (BROKEN order; U and HYBRID one less),
26 * -dm_is_partitioned, -incremental (default true; false uses Simple's
27 * all-entities field/element builders), -local_from <l> (from level l on,
28 * refine only the tetrahedra with an edge in the star of one vertex, which
29 * keeps the mesh conforming), -rebuild_structures (from level 1 on, update
30 * the block and nested structures of the previous level with
31 * rebuildBlockMatStructure and rebuildSchurNestedMatrixStruture, and check
32 * them against new ones made by createBlockMatStructure and
33 * createSchurNestedMatrixStruture). Hybrid preallocation is checked
34 * against the couplings of skeleton faces sharing an active tetrahedron,
35 * then filled with new allocations forbidden and checked for a diagonal.
36 */
37
38#include <MoFEM.hpp>
39#include <unordered_map>
40
41using namespace MoFEM;
42
43static char help[] = "Hybridised broken H(div) problem on refined levels: "
44 "problem, sub-problem and matrix timings.\n"
45 "-file_name <mesh> -nb_levels <n> -order <p> "
46 "[-incremental true|false] [-local_from <l>] "
47 "[-rebuild_structures]\n\n";
48
49namespace {
50
51inline BitRefLevel bit(int l) { return BitRefLevel().set(l); }
52inline BitRefLevel allBits() { return BitRefLevel().set(); }
53
54/// Timings of one level, seconds.
55struct Timings {
56 double registration = 0, problem = 0, schurSub = 0, blockSub = 0,
57 blockMat = 0, nestedSchur = 0, hybridMat = 0;
58};
59
60MoFEMErrorCode time(std::function<MoFEMErrorCode()> fn, double &seconds) {
62 PetscLogDouble t0, t1;
63 CHKERR PetscTime(&t0);
64 CHKERR fn();
65 CHKERR PetscTime(&t1);
66 seconds = t1 - t0;
68}
69
70/// Refine the tetrahedra of level l-1 onto level l and put the children into
71/// Simple's meshset. Uniformly, or locally: the edges of the star of one
72/// vertex are split, and every tetrahedron with a split edge is refined, so
73/// the mesh stays conforming; the other tetrahedra and their faces, edges
74/// and vertices join level l unchanged.
75MoFEMErrorCode refineLevel(MoFEM::Interface &m_field, Simple &simple, int l,
76 bool local, int &refined) {
78 auto bit_mng = m_field.getInterface<BitRefManager>();
79 auto &moab = m_field.get_moab();
80 Range level_tets;
81 CHKERR bit_mng->getEntitiesByDimAndRefLevel(bit(l - 1), allBits(), 3,
82 level_tets);
83 Range tets = level_tets, edges;
84 if (local) {
85 Range verts;
86 CHKERR moab.get_connectivity(level_tets, verts, true);
87 const EntityHandle vertex = verts.front();
88 Range star;
89 CHKERR moab.get_adjacencies(&vertex, 1, 3, false, star);
90 star = intersect(star, level_tets);
91 CHKERR moab.get_adjacencies(star, 1, true, edges, moab::Interface::UNION);
92 Range touched;
93 CHKERR moab.get_adjacencies(edges, 3, false, touched,
94 moab::Interface::UNION);
95 tets = intersect(touched, level_tets);
96 } else {
97 CHKERR moab.get_adjacencies(tets, 1, true, edges, moab::Interface::UNION);
98 }
99 refined = tets.size();
100 auto refine = m_field.getInterface<MeshRefinement>();
101 CHKERR refine->addVerticesInTheMiddleOfEdges(edges, bit(l));
102 CHKERR refine->refineTets(tets, bit(l));
103 if (local) {
104 const Range unchanged = subtract(level_tets, tets);
105 Range adj;
106 CHKERR moab.get_connectivity(unchanged, adj, true);
107 for (auto d : {1, 2})
108 CHKERR moab.get_adjacencies(unchanged, d, false, adj,
109 moab::Interface::UNION);
110 CHKERR bit_mng->addBitRefLevel(unchanged, bit(l));
111 CHKERR bit_mng->addBitRefLevel(adj, bit(l));
112 }
113 // Simple registers fields and elements from its meshset, which is the root
114 // set after loadFile, so the children are already in it; a user meshset
115 // would need its children added.
116 if (simple.getMeshset() != 0)
117 CHKERR bit_mng->updateMeshsetByEntitiesChildren(
118 simple.getMeshset(), bit(l), simple.getMeshset(), MBTET, true);
120}
121
122/// Skeleton of level l: its faces without the skin of its tetrahedra.
123MoFEMErrorCode setSkeleton(MoFEM::Interface &m_field, Simple &simple, int l,
124 int &nb_skeleton_faces) {
126 auto &moab = m_field.get_moab();
127 auto bit_mng = m_field.getInterface<BitRefManager>();
128 Range tets, faces;
129 CHKERR bit_mng->getEntitiesByDimAndRefLevel(bit(l), allBits(), 3, tets);
130 CHKERR moab.get_adjacencies(tets, 2, true, faces, moab::Interface::UNION);
131 Range skin;
132 Skinner skinner(&moab);
133 CHKERR skinner.find_skin(0, tets, false, skin);
134 const Range skeleton = subtract(faces, skin);
135 const EntityHandle meshset = simple.getSkeletonMeshSet();
136 CHKERR moab.clear_meshset(&meshset, 1);
137 CHKERR moab.add_entities(meshset, skeleton);
138 nb_skeleton_faces = skeleton.size();
140}
141
142/// Register and build only entities not already in the corresponding field.
143MoFEMErrorCode registerLevel(MoFEM::Interface &m_field, Simple &simple, int l,
144 int order, bool incremental) {
146 if (!incremental) {
147 CHKERR simple.buildFields();
148 CHKERR simple.buildFiniteElements();
150 }
151
152 auto &moab = m_field.get_moab();
153 Range tets, faces, registered;
154 CHKERR m_field.getInterface<BitRefManager>()->getEntitiesByDimAndRefLevel(
155 bit(l), allBits(), 3, tets);
156 CHKERR moab.get_entities_by_handle(m_field.get_field_meshset("BROKEN"),
157 registered);
158 tets = subtract(tets, registered);
159 CHKERR moab.get_entities_by_handle(simple.getSkeletonMeshSet(), faces);
160 registered.clear();
161 CHKERR moab.get_entities_by_handle(m_field.get_field_meshset("HYBRID"),
162 registered);
163 faces = subtract(faces, registered);
164
165 auto comm_ptr = m_field.getInterface<CommInterface>();
166 for (const auto &field : {"BROKEN", "U"}) {
167 CHKERR m_field.add_ents_to_field_by_dim(tets, 3, field);
168 CHKERR comm_ptr->synchroniseFieldEntities(field, 0);
169 CHKERR m_field.set_field_order(
170 tets, field, std::string(field) == "BROKEN" ? order : order - 1);
171 }
172 CHKERR m_field.add_ents_to_field_by_dim(faces, 2, "HYBRID");
173 CHKERR comm_ptr->synchroniseFieldEntities("HYBRID", 0);
174 CHKERR m_field.set_field_order(faces, "HYBRID", order - 1);
175 Range new_ents = tets;
176 new_ents.merge(faces);
177 CHKERR m_field.build_fields(new_ents);
178
180 simple.getDomainFEName());
182 simple.getSkeletonFEName());
183 CHKERR m_field.build_finite_elements(simple.getDomainFEName(), &tets);
184 CHKERR m_field.build_finite_elements(simple.getSkeletonFEName(), &faces);
186}
187
188/// Independent element-wise oracle for the hybrid matrix's preallocation.
189MoFEMErrorCode checkHybridMatrix(MoFEM::Interface &m_field, DM dm, int l,
190 Mat matrix, TestingInterface &testing,
191 const std::string &tag, double &nonzeros) {
193 const Problem *problem_ptr;
194 CHKERR DMMoFEMGetProblemPtr(dm, &problem_ptr);
195 std::unordered_map<EntityHandle, std::vector<PetscInt>> face_dofs;
196 for (auto &dof : *problem_ptr->getNumeredColDofsPtr())
197 if (dof->getPetscGlobalDofIdx() >= 0)
198 face_dofs[dof->getEnt()].push_back(dof->getPetscGlobalDofIdx());
199
200 // Every active cell couples all its skeleton faces, including each face
201 // with itself. Deduplication accounts for a face belonging to two cells.
202 std::unordered_map<EntityHandle, std::vector<PetscInt>> neighbors;
203 Range tets;
204 CHKERR m_field.getInterface<BitRefManager>()->getEntitiesByDimAndRefLevel(
205 bit(l), allBits(), 3, tets);
206 for (auto tet : tets) {
207 Range faces;
208 CHKERR m_field.get_moab().get_adjacencies(&tet, 1, 2, false, faces);
209 std::vector<PetscInt> columns;
210 for (auto face : faces) {
211 auto it = face_dofs.find(face);
212 if (it != face_dofs.end())
213 columns.insert(columns.end(), it->second.begin(), it->second.end());
214 }
215 for (auto face : faces)
216 if (face_dofs.count(face)) {
217 auto &adj = neighbors[face];
218 adj.insert(adj.end(), columns.begin(), columns.end());
219 }
220 }
221
222 PetscInt first_row, last_row;
223 CHKERR MatGetOwnershipRange(matrix, &first_row, &last_row);
224 MatInfo before;
225 CHKERR MatGetInfo(matrix, MAT_GLOBAL_SUM, &before);
226 CHKERR MatSetOption(matrix, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_TRUE);
227 double local_nnz = 0;
228 for (auto &entry : neighbors) {
229 auto &columns = entry.second;
230 std::sort(columns.begin(), columns.end());
231 columns.erase(std::unique(columns.begin(), columns.end()), columns.end());
232 const PetscInt nb_cols = columns.size();
233 const std::vector<PetscScalar> values(nb_cols, 1.);
234 for (auto row : face_dofs.at(entry.first))
235 if (row >= first_row && row < last_row) {
236 local_nnz += nb_cols;
237 CHKERR MatSetValues(matrix, 1, &row, nb_cols, columns.data(),
238 values.data(), INSERT_VALUES);
239 }
240 }
241 double expected_nnz;
242 CHKERR MPI_Allreduce(&local_nnz, &expected_nnz, 1, MPI_DOUBLE, MPI_SUM,
243 m_field.get_comm());
244 const auto zero = TestingInterface::Tolerance{0, 0};
245 CHKERR testing.checkValue<TestType::SCALAR>(
246 tag + " hybrid allocation equals topology non-zeros", before.nz_allocated,
247 expected_nnz, zero);
248 CHKERR MatAssemblyBegin(matrix, MAT_FINAL_ASSEMBLY);
249 CHKERR MatAssemblyEnd(matrix, MAT_FINAL_ASSEMBLY);
250 MatInfo after;
251 CHKERR MatGetInfo(matrix, MAT_GLOBAL_SUM, &after);
252 nonzeros = after.nz_used;
253 CHKERR testing.checkValue<TestType::SCALAR>(
254 tag + " hybrid filled non-zeros equal topology", nonzeros, expected_nnz,
255 zero);
256 CHKERR testing.checkValue<TestType::SCALAR>(
257 tag + " hybrid fill without reallocations", after.mallocs, before.mallocs,
258 zero);
259 PetscBool missing;
260 PetscInt missing_row;
261 CHKERR MatMissingDiagonal(matrix, &missing, &missing_row);
262 CHKERR testing.checkValue<TestType::SCALAR>(
263 tag + " hybrid diagonal exists in every row", missing ? 1 : 0, 0, zero);
265}
266
267MoFEMErrorCode subProblem(MoFEM::Interface &m_field, Simple &simple,
268 const std::string &name,
269 const std::vector<std::string> &fields,
270 SmartPetscObj<DM> &dm) {
272 dm = createDM(m_field.get_comm(), "DMMOFEM");
273 CHKERR DMMoFEMCreateSubDM(dm, simple.getDM(), name.c_str());
274 CHKERR DMMoFEMSetSquareProblem(dm, PETSC_TRUE);
275 CHKERR DMMoFEMAddElement(dm, simple.getDomainFEName());
276 CHKERR DMMoFEMAddElement(dm, simple.getSkeletonFEName());
277 for (auto &field : fields) {
280 }
281 CHKERR DMSetUp(dm);
283}
284
285int problemRows(MoFEM::Interface &m_field, DM dm) {
286 const Problem *prb;
287 CHK_THROW_MESSAGE(DMMoFEMGetProblemPtr(dm, &prb), "problem of DM");
288 return prb->getNbDofsRow();
289}
290
291} // namespace
292
293int main(int argc, char *argv[]) {
294
295 MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
296
297 try {
298
299 moab::Core mb_instance;
300 moab::Interface &moab = mb_instance;
301 MoFEM::Core core(moab);
302 MoFEM::Interface &m_field = core;
304 auto *simple = m_field.getInterface<Simple>();
305 CHKERR DMRegister_MoFEM("DMMOFEM");
306
307 PetscInt nb_levels = 2, order = 2;
308 PetscBool is_partitioned = PETSC_FALSE, incremental = PETSC_TRUE;
309 PetscBool rebuild_structures = PETSC_FALSE;
310 PetscInt local_from = -1;
311 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-nb_levels", &nb_levels,
312 PETSC_NULLPTR);
313 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-order", &order,
314 PETSC_NULLPTR);
315 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-dm_is_partitioned",
316 &is_partitioned, PETSC_NULLPTR);
317 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-incremental", &incremental,
318 PETSC_NULLPTR);
319 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-rebuild_structures",
320 &rebuild_structures, PETSC_NULLPTR);
321 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-local_from", &local_from,
322 PETSC_NULLPTR);
323 if (order < 1)
324 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "-order must be >= 1");
325 const int u_order = order - 1;
326 const int hybrid_order = order - 1;
327
328 CHKERR simple->getOptions();
329 simple->getAddBoundaryFE() = false;
330 CHKERR simple->loadFile();
331 if (simple->getDim() != 3)
332 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
333 "Tetrahedral meshes only");
334
335 const auto base = DEMKOWICZ_JACOBI_BASE;
336 CHKERR simple->addDomainBrokenField("BROKEN", HDIV, base, 1);
337 CHKERR simple->addDomainField("U", L2, base, 1);
338 CHKERR simple->addSkeletonField("HYBRID", L2, base, 1);
339 CHKERR simple->setFieldOrder("BROKEN", order);
340 CHKERR simple->setFieldOrder("U", u_order);
341 CHKERR simple->setFieldOrder("HYBRID", hybrid_order);
342
343 CHKERR simple->defineFiniteElements();
344 // Simple's skeleton adjacency also reaches the DOFs of the parent cells
345 // of the bridge cells (for hanging nodes); each level here is a complete
346 // mesh, so the skeleton element sees its two bridge cells only.
347 simple->getBitAdjParent() = BitRefLevel();
348 CHKERR simple->setSkeletonAdjacency(-1, simple->getSkeletonFEName());
349 CHKERR simple->defineProblem(is_partitioned);
350
351 MOFEM_LOG_CHANNEL("WORLD");
352 MOFEM_LOG_TAG("WORLD", "RebuildHybrid");
353 MOFEM_LOG("WORLD", Sev::inform)
354 << "Levels " << nb_levels << ", BROKEN order " << order
355 << ", U and HYBRID order " << u_order << ", "
356 << (is_partitioned ? "distributed" : "replicated") << " builder, "
357 << (incremental ? "incremental" : "full")
358 << " field/element registration"
359 << (local_from >= 0 ? ", local refinement from level " +
360 std::to_string(local_from)
361 : std::string())
362 << (rebuild_structures ? ", block and nested structures rebuilt"
363 : "");
364
365 // DOFs per entity for the bases used.
366 const int dofs_broken_per_tet = 4 * NBFACETRI_DEMKOWICZ_HDIV(order) +
368 const int dofs_u_per_tet = NBVOLUMETET_L2(u_order);
369 const int dofs_hybrid_per_face = NBFACETRI_L2(hybrid_order);
370
371 auto zero = TestingInterface::Tolerance{0, 0};
372 auto count_tets = [&](int l) {
373 Range tets;
376 bit(l), allBits(), 3, tets),
377 "count tets");
378 return static_cast<int>(tets.size());
379 };
380
381 // elements and field pairs of the block matrix
382 const SchurFEOpsFEandFields block_ops = {
383 {simple->getDomainFEName(),
384 {{"BROKEN", "BROKEN"},
385 {"U", "U"},
386 {"BROKEN", "U"},
387 {"U", "BROKEN"}}},
388 {simple->getSkeletonFEName(),
389 {{"BROKEN", "HYBRID"}, {"HYBRID", "BROKEN"}}}};
390 // structures kept from level to level with -rebuild_structures
391 boost::shared_ptr<BlockStructure> kept_block;
392 boost::shared_ptr<NestSchurData> kept_nested;
393
394 struct Level {
395 SmartPetscObj<DM> schurDM, blockDM;
396 SmartPetscObj<Mat> blockMat, nestedMat, hybridMat;
397 boost::shared_ptr<BlockStructure> blockData;
398 boost::shared_ptr<NestSchurData> nestedData;
399 Timings t;
400 int tets = 0, skeletonFaces = 0, rows = 0, schurRows = 0, blockRows = 0;
401 double hybridNnz = 0;
402 };
403 std::vector<Level> levels(nb_levels + 1);
404
405 for (int l = 0; l <= nb_levels; ++l) {
406 const auto tag = "level " + std::to_string(l);
407 auto &lv = levels[l];
408
409 CHKERR testing->addTest(10 * l + 1, tag + " refine and register", [&, l,
410 tag]() {
412 const bool local = l > 0 && local_from >= 0 && l >= local_from;
413 int refined = 0;
414 if (l > 0)
415 CHKERR refineLevel(m_field, *simple, l, local, refined);
416 CHKERR setSkeleton(m_field, *simple, l, lv.skeletonFaces);
417 lv.tets = count_tets(l);
418 simple->getBitRefLevel() = bit(l);
419 CHKERR time(
420 [&]() {
421 return registerLevel(m_field, *simple, l, order, incremental);
422 },
423 lv.t.registration);
424 if (l > 0 && !local)
425 CHKERR testing->checkValue<TestType::SCALAR>(
426 tag + " tets are eight per parent", lv.tets,
427 8. * levels[l - 1].tets, zero);
428 if (local) {
429 MOFEM_LOG_CHANNEL("WORLD");
430 MOFEM_LOG_TAG("WORLD", "RebuildHybrid");
431 MOFEM_LOG("WORLD", Sev::inform)
432 << "Level " << l << " local refinement of " << refined << " of "
433 << levels[l - 1].tets << " tets";
434 CHKERR testing->checkValue<TestType::SCALAR>(
435 tag + " local refinement leaves tets unchanged",
436 refined < levels[l - 1].tets ? 1 : 0, 1, zero);
437 }
439 });
440
441 CHKERR testing->addTest(10 * l + 2, tag + " problem", [&, l, tag]() {
443 // Adjacencies on the level, the problem selector set to the level
444 // and DMSetUp of the parent; previous levels' sub-problems are gone.
445 CHKERR time([&]() { return simple->reSetUp(true); }, lv.t.problem);
446 lv.rows = problemRows(m_field, simple->getDM());
447 const double expected =
448 double(lv.tets) * (dofs_broken_per_tet + dofs_u_per_tet) +
449 double(lv.skeletonFaces) * dofs_hybrid_per_face;
450 CHKERR testing->checkValue<TestType::SCALAR>(
451 tag + " parent dofs = BROKEN + U + HYBRID", lv.rows, expected,
452 zero);
454 });
455
456 CHKERR testing->addTest(10 * l + 3, tag + " sub-problems", [&, l,
457 tag]() {
459 CHKERR time(
460 [&]() {
461 return subProblem(m_field, *simple, "SCHUR", {"HYBRID"},
462 lv.schurDM);
463 },
464 lv.t.schurSub);
465 CHKERR time(
466 [&]() {
467 return subProblem(m_field, *simple, "BLOCK", {"BROKEN", "U"},
468 lv.blockDM);
469 },
470 lv.t.blockSub);
471 lv.schurRows = problemRows(m_field, lv.schurDM);
472 lv.blockRows = problemRows(m_field, lv.blockDM);
473 CHKERR testing->checkValue<TestType::SCALAR>(
474 tag + " SCHUR dofs = HYBRID", lv.schurRows,
475 double(lv.skeletonFaces) * dofs_hybrid_per_face, zero);
476 CHKERR testing->checkValue<TestType::SCALAR>(
477 tag + " BLOCK + SCHUR dofs = parent", lv.blockRows + lv.schurRows,
478 lv.rows, zero);
480 });
481
482 CHKERR testing->addTest(10 * l + 4, tag + " block and nested Schur "
483 "matrices",
484 [&, l, tag]() {
486 const bool rebuild = rebuild_structures && kept_block && kept_nested;
487 CHKERR time(
488 [&]() {
490 if (rebuild) {
491 CHKERR rebuildBlockMatStructure(simple->getDM(), block_ops,
492 kept_block);
493 lv.blockData = kept_block;
494 } else {
495 lv.blockData =
496 createBlockMatStructure(simple->getDM(), block_ops);
497 }
498 auto block = createBlockMat(simple->getDM(), lv.blockData);
499 lv.blockMat = block.first;
501 },
502 lv.t.blockMat);
503 CHKERR time(
504 [&]() {
506 if (rebuild) {
508 {lv.schurDM, lv.blockDM}, kept_nested);
509 lv.nestedData = kept_nested;
510 } else {
511 lv.nestedData = createSchurNestedMatrixStruture(
512 {lv.schurDM, lv.blockDM}, lv.blockData, {"BROKEN", "U"},
513 {nullptr, nullptr}, true);
514 }
515 auto nested = createSchurNestedMatrix(lv.nestedData);
516 lv.nestedMat = nested.first;
518 },
519 lv.t.nestedSchur);
520 if (rebuild_structures) {
521 kept_block = lv.blockData;
522 kept_nested = lv.nestedData;
523 }
524 if (rebuild) {
525 // Oracle: new structures for the same DMs, made from scratch.
526 boost::shared_ptr<BlockStructure> fresh_block;
527 boost::shared_ptr<NestSchurData> fresh_nested;
528 double fresh_block_seconds, fresh_nested_seconds;
529 CHKERR time(
530 [&]() {
532 fresh_block =
533 createBlockMatStructure(simple->getDM(), block_ops);
535 },
536 fresh_block_seconds);
537 CHKERR time(
538 [&]() {
540 fresh_nested = createSchurNestedMatrixStruture(
541 {lv.schurDM, lv.blockDM}, fresh_block, {"BROKEN", "U"},
542 {nullptr, nullptr}, true);
544 },
545 fresh_nested_seconds);
546 MOFEM_LOG_CHANNEL("WORLD");
547 MOFEM_LOG_TAG("WORLD", "RebuildHybrid");
548 MOFEM_LOG("WORLD", Sev::inform)
549 << "Level " << l << " structures [s]: rebuilt block "
550 << lv.t.blockMat << ", rebuilt nested " << lv.t.nestedSchur
551 << "; new block " << fresh_block_seconds << ", new nested "
552 << fresh_nested_seconds;
553 auto compare = [&](const std::string &what, auto rebuilt,
554 auto fresh) {
556 const auto r = schurBlockStructureDigest(rebuilt);
557 const auto f = schurBlockStructureDigest(fresh);
558 CHKERR testing->checkValue<TestType::SCALAR>(
559 tag + " rebuilt " + what + " blocks", r.nbBlocks, f.nbBlocks,
560 zero);
561 CHKERR testing->checkValue<TestType::SCALAR>(
562 tag + " rebuilt " + what + " A00 elements", r.nbElems,
563 f.nbElems, zero);
564 CHKERR testing->checkValue<TestType::SCALAR>(
565 tag + " rebuilt " + what + " block index equal",
566 r.indexHash == f.indexHash ? 0 : 1, 0, zero);
567 CHKERR testing->checkValue<TestType::SCALAR>(
568 tag + " rebuilt " + what + " blocks equal",
569 r.blocksHash == f.blocksHash ? 0 : 1, 0, zero);
570 CHKERR testing->checkValue<TestType::SCALAR>(
571 tag + " rebuilt " + what + " A00 elements equal",
572 r.elemsHash == f.elemsHash ? 0 : 1, 0, zero);
574 };
575 CHKERR compare("block matrix", lv.blockData, fresh_block);
576 const auto &rebuilt_parts = std::get<1>(*lv.nestedData);
577 const auto &fresh_parts = std::get<1>(*fresh_nested);
578 for (int q = 0; q != 4; ++q)
579 CHKERR compare("nested quadrant " + std::to_string(q),
580 rebuilt_parts[q], fresh_parts[q]);
581 }
582 PetscInt m, n;
583 CHKERR MatGetSize(lv.blockMat, &m, &n);
584 CHKERR testing->checkValue<TestType::SCALAR>(
585 tag + " block matrix rows = parent", m, lv.rows, zero);
586 CHKERR MatGetSize(lv.nestedMat, &m, &n);
587 CHKERR testing->checkValue<TestType::SCALAR>(
588 tag + " nested matrix rows = parent", m, lv.rows, zero);
590 });
591
592 CHKERR testing->addTest(10 * l + 5, tag + " hybrid L2 matrix", [&, l,
593 tag]() {
595 CHKERR time(
596 [&]() {
598 lv.hybridMat = createDMHybridisedL2Matrix(lv.schurDM);
600 },
601 lv.t.hybridMat);
602 PetscInt m, n;
603 CHKERR MatGetSize(lv.hybridMat, &m, &n);
604 CHKERR testing->checkValue<TestType::SCALAR>(
605 tag + " hybrid matrix rows = SCHUR dofs", m, lv.schurRows, zero);
606 CHKERR testing->checkValue<TestType::SCALAR>(
607 tag + " hybrid matrix columns = SCHUR dofs", n, lv.schurRows, zero);
608 CHKERR checkHybridMatrix(m_field, lv.schurDM, l, lv.hybridMat, *testing,
609 tag, lv.hybridNnz);
610
611 MOFEM_LOG_CHANNEL("WORLD");
612 MOFEM_LOG_TAG("WORLD", "RebuildHybrid");
613 MOFEM_LOG("WORLD", Sev::inform)
614 << "Level " << l << ": tets " << lv.tets << ", skeleton faces "
615 << lv.skeletonFaces << ", dofs " << lv.rows << " (SCHUR "
616 << lv.schurRows << ", BLOCK " << lv.blockRows
617 << "), hybrid non-zeros " << lv.hybridNnz;
618 MOFEM_LOG("WORLD", Sev::inform)
619 << "Level " << l << " times [s]: registration "
620 << lv.t.registration << ", problem " << lv.t.problem
621 << ", sub SCHUR " << lv.t.schurSub << ", sub BLOCK "
622 << lv.t.blockSub << ", block matrix " << lv.t.blockMat
623 << ", nested Schur " << lv.t.nestedSchur << ", hybrid matrix "
624 << lv.t.hybridMat;
625
626 // Release this level's algebra before the next level is built.
627 lv.hybridMat.reset();
628 lv.nestedMat.reset();
629 lv.nestedData.reset();
630 lv.blockMat.reset();
631 lv.blockData.reset();
632 // with -rebuild_structures the structures stay for the next level;
633 // its nested shell matrices are replaced by the rebuild
634 lv.blockDM.reset();
635 lv.schurDM.reset();
637 });
638 }
639
640 CHKERR testing->runTests();
641 }
643
645
646 return 0;
647}
std::vector< std::array< EntityHandle, 3 > > faces
Sorted keys.
FaceSet skin
WorkMesh base
Vec t
Removal: the ring edge.
Tag tag
ProjectedField & field
std::vector< FieldBitNumber > row
Definition Schur.cpp:2488
It it
Definition Schur.cpp:2568
SmartPetscObj< Vec > values
SmartPetscObj< IS > rows
std::string name
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition acoustic.cpp:69
int main()
#define CATCH_ERRORS
Catch errors.
@ DEMKOWICZ_JACOBI_BASE
Definition definitions.h:66
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
@ L2
field with C-1 continuity
Definition definitions.h:88
@ HDIV
field with continuous normal traction
Definition definitions.h:87
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ 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.
constexpr int order
PetscErrorCode DMMoFEMCreateSubDM(DM subdm, DM dm, const char problem_name[])
Must be called by user to set Sub DM MoFEM data structures.
Definition DMMoFEM.cpp:244
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
Definition DMMoFEM.cpp:574
PetscErrorCode DMMoFEMSetSquareProblem(DM dm, PetscBool square_problem)
set squared problem
Definition DMMoFEM.cpp:536
PetscErrorCode DMMoFEMGetProblemPtr(DM dm, const MoFEM::Problem **problem_ptr)
Get pointer to problem data structure.
Definition DMMoFEM.cpp:451
PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, const char field_name[])
Definition DMMoFEM.cpp:267
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition DMMoFEM.cpp:43
PetscErrorCode DMMoFEMAddSubFieldCol(DM dm, const char field_name[])
Definition DMMoFEM.cpp:309
MoFEMErrorCode getEntitiesByDimAndRefLevel(const BitRefLevel bit, const BitRefLevel mask, const int dim, const EntityHandle meshset, int verb=0) const
add all ents from ref level given by bit to meshset
MoFEMErrorCode addBitRefLevel(const Range &ents, const BitRefLevel bit, int verb=QUIET) const
Add bit ref level to ref entity.
virtual MoFEMErrorCode add_ents_to_finite_element_by_dim(const EntityHandle entities, const int dim, const std::string name, const bool recursive=true)=0
add entities to finite element
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
virtual MoFEMErrorCode add_ents_to_field_by_dim(const Range &ents, const int dim, const std::string &name, int verb=DEFAULT_VERBOSITY)=0
Add entities to field meshset.
virtual MoFEMErrorCode set_field_order(const EntityHandle meshset, const EntityType type, const std::string &name, const ApproximationOrder order, int verb=DEFAULT_VERBOSITY)=0
Set order approximation of the entities in the field.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
#define NBFACETRI_L2(P)
Number of base functions on triangle for L2 space.
#define NBVOLUMETET_DEMKOWICZ_HDIV(P)
#define NBFACETRI_DEMKOWICZ_HDIV(P)
#define NBVOLUMETET_L2(P)
Number of base functions on tetrahedron for L2 space.
auto bit
set bit
PetscBool testing
constexpr int nb_levels
Definition level_set.cpp:58
FTensor::Index< 'l', 3 > l
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
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
SchurBlockStructureDigest schurBlockStructureDigest(boost::shared_ptr< BlockStructure > data_ptr)
Definition Schur.cpp:4821
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
std::pair< SmartPetscObj< Mat >, boost::shared_ptr< NestSchurData > > createSchurNestedMatrix(boost::shared_ptr< NestSchurData > schur_net_data_ptr)
Create a Mat Diag Blocks object.
Definition Schur.cpp:4859
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
auto createDMHybridisedL2Matrix(DM dm)
Get smart hybridised L2 matrix from DM.
Definition DMMoFEM.hpp:1249
boost::shared_ptr< BlockStructure > createBlockMatStructure(DM dm, SchurFEOpsFEandFields schur_fe_op_vec)
Create block matrix structure.
Definition Schur.cpp:2819
boost::shared_ptr< NestSchurData > createSchurNestedMatrixStruture(std::pair< SmartPetscObj< DM >, SmartPetscObj< DM > > dms, boost::shared_ptr< BlockStructure > block_mat_data_ptr, std::vector< std::string > fields_names, std::vector< boost::shared_ptr< Range > > field_ents, bool add_preconditioner_block)
Create structure of nested matrix [A11 A10; A01 A00].
Definition Schur.cpp:4760
MoFEMErrorCode MatSetValues(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const double *ptr, InsertMode iora)
Assemble PETSc matrix.
MoFEMErrorCode rebuildSchurNestedMatrixStruture(std::pair< SmartPetscObj< DM >, SmartPetscObj< DM > > dms, boost::shared_ptr< NestSchurData > nest_data_ptr)
Rebuild a nested Schur structure after rebuildBlockMatStructure.
Definition Schur.cpp:4799
MoFEMErrorCode rebuildBlockMatStructure(DM dm, SchurFEOpsFEandFields schur_fe_op_vec, boost::shared_ptr< BlockStructure > data_ptr)
Rebuild a block matrix structure after its problem changed.
Definition Schur.cpp:2833
std::vector< std::pair< std::string, std::vector< SchurFieldPair > > > SchurFEOpsFEandFields
Definition Schur.hpp:83
auto createDM(MPI_Comm comm, const std::string dm_type_name)
Creates smart DM object.
SchurShellMatData createBlockMat(DM dm, boost::shared_ptr< BlockStructure > data)
Create a Schur Mat object.
Definition Schur.cpp:3615
static char help[]
double q
FTensor::Index< 'm', 3 > m
Managing BitRefLevels.
Managing BitRefLevels.
virtual moab::Interface & get_moab()=0
virtual EntityHandle get_field_meshset(const std::string name) const =0
get field meshset
virtual MPI_Comm & get_comm() const =0
Core (interface) class.
Definition Core.hpp:83
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition Core.cpp:68
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:123
Deprecated interface functions.
Mesh refinement interface.
MoFEMErrorCode addVerticesInTheMiddleOfEdges(const EntityHandle meshset, const BitRefLevel &bit, const bool recursive=false, int verb=QUIET, EntityHandle start_v=0)
make vertices in the middle of edges in meshset and add them to refinement levels defined by bit
keeps basic data about problem
DofIdx getNbDofsRow() const
auto & getNumeredColDofsPtr() const
get access to numeredColDofsPtr storing DOFs on cols
Simple interface for fast problem set-up.
Definition Simple.hpp:27
intrusive_ptr for managing petsc objects
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.