293 {
294
296
297 try {
298
299 moab::Core mb_instance;
300 moab::Interface &moab = mb_instance;
306
308 PetscBool is_partitioned = PETSC_FALSE, incremental = PETSC_TRUE;
309 PetscBool rebuild_structures = PETSC_FALSE;
310 PetscInt local_from = -1;
312 PETSC_NULLPTR);
314 PETSC_NULLPTR);
316 &is_partitioned, PETSC_NULLPTR);
318 PETSC_NULLPTR);
320 &rebuild_structures, PETSC_NULLPTR);
322 PETSC_NULLPTR);
325 const int u_order =
order - 1;
326 const int hybrid_order =
order - 1;
327
329 simple->getAddBoundaryFE() =
false;
331 if (
simple->getDim() != 3)
333 "Tetrahedral meshes only");
334
342
344
345
346
350
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)
362 << (rebuild_structures ? ", block and nested structures rebuilt"
363 : "");
364
365
369 const int dofs_hybrid_per_face =
NBFACETRI_L2(hybrid_order);
370
372 auto count_tets = [&](
int l) {
376 bit(
l), allBits(), 3, tets),
377 "count tets");
378 return static_cast<int>(tets.size());
379 };
380
381
383 {
simple->getDomainFEName(),
384 {{"BROKEN", "BROKEN"},
385 {"U", "U"},
386 {"BROKEN", "U"},
387 {"U", "BROKEN"}}},
388 {
simple->getSkeletonFEName(),
389 {{"BROKEN", "HYBRID"}, {"HYBRID", "BROKEN"}}}};
390
391 boost::shared_ptr<BlockStructure> kept_block;
392 boost::shared_ptr<NestSchurData> kept_nested;
393
394 struct Level {
397 boost::shared_ptr<BlockStructure> blockData;
398 boost::shared_ptr<NestSchurData> nestedData;
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
406 const auto tag =
"level " + std::to_string(
l);
407 auto &lv = levels[
l];
408
412 const bool local =
l > 0 && local_from >= 0 &&
l >= local_from;
413 int refined = 0;
417 lv.tets = count_tets(
l);
420 [&]() {
421 return registerLevel(m_field, *
simple,
l,
order, incremental);
422 },
423 lv.t.registration);
426 tag +
" tets are eight per parent", lv.tets,
427 8. * levels[
l - 1].tets, zero);
428 if (local) {
432 <<
"Level " <<
l <<
" local refinement of " << refined <<
" of "
433 << levels[
l - 1].tets <<
" tets";
435 tag +
" local refinement leaves tets unchanged",
436 refined < levels[
l - 1].tets ? 1 : 0, 1, zero);
437 }
439 });
440
443
444
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;
451 tag +
" parent dofs = BROKEN + U + HYBRID", lv.rows, expected,
452 zero);
454 });
455
460 [&]() {
461 return subProblem(m_field, *
simple,
"SCHUR", {
"HYBRID"},
462 lv.schurDM);
463 },
464 lv.t.schurSub);
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);
474 tag +
" SCHUR dofs = HYBRID", lv.schurRows,
475 double(lv.skeletonFaces) * dofs_hybrid_per_face, zero);
477 tag +
" BLOCK + SCHUR dofs = parent", lv.blockRows + lv.schurRows,
478 lv.rows, zero);
480 });
481
483 "matrices",
486 const bool rebuild = rebuild_structures && kept_block && kept_nested;
488 [&]() {
490 if (rebuild) {
492 kept_block);
493 lv.blockData = kept_block;
494 } else {
495 lv.blockData =
497 }
499 lv.blockMat = block.first;
501 },
502 lv.t.blockMat);
504 [&]() {
506 if (rebuild) {
508 {lv.schurDM, lv.blockDM}, kept_nested);
509 lv.nestedData = kept_nested;
510 } else {
512 {lv.schurDM, lv.blockDM}, lv.blockData, {"BROKEN", "U"},
513 {nullptr, nullptr}, true);
514 }
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
526 boost::shared_ptr<BlockStructure> fresh_block;
527 boost::shared_ptr<NestSchurData> fresh_nested;
528 double fresh_block_seconds, fresh_nested_seconds;
530 [&]() {
532 fresh_block =
535 },
536 fresh_block_seconds);
538 [&]() {
541 {lv.schurDM, lv.blockDM}, fresh_block, {"BROKEN", "U"},
542 {nullptr, nullptr}, true);
544 },
545 fresh_nested_seconds);
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) {
559 tag +
" rebuilt " + what +
" blocks",
r.nbBlocks,
f.nbBlocks,
560 zero);
562 tag +
" rebuilt " + what +
" A00 elements",
r.nbElems,
565 tag +
" rebuilt " + what +
" block index equal",
566 r.indexHash ==
f.indexHash ? 0 : 1, 0, zero);
568 tag +
" rebuilt " + what +
" blocks equal",
569 r.blocksHash ==
f.blocksHash ? 0 : 1, 0, zero);
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 }
583 CHKERR MatGetSize(lv.blockMat, &
m, &
n);
585 tag +
" block matrix rows = parent",
m, lv.rows, zero);
586 CHKERR MatGetSize(lv.nestedMat, &
m, &
n);
588 tag +
" nested matrix rows = parent",
m, lv.rows, zero);
590 });
591
596 [&]() {
600 },
601 lv.t.hybridMat);
603 CHKERR MatGetSize(lv.hybridMat, &
m, &
n);
605 tag +
" hybrid matrix rows = SCHUR dofs",
m, lv.schurRows, zero);
607 tag +
" hybrid matrix columns = SCHUR dofs",
n, lv.schurRows, zero);
608 CHKERR checkHybridMatrix(m_field, lv.schurDM,
l, lv.hybridMat, *
testing,
610
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;
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
627 lv.hybridMat.reset();
628 lv.nestedMat.reset();
629 lv.nestedData.reset();
630 lv.blockMat.reset();
631 lv.blockData.reset();
632
633
634 lv.blockDM.reset();
635 lv.schurDM.reset();
637 });
638 }
639
641 }
643
645
646 return 0;
647}
Vec t
Removal: the ring edge.
void simple(double P1[], double P2[], double P3[], double c[], const int N)
#define CATCH_ERRORS
Catch errors.
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
@ L2
field with C-1 continuity
@ HDIV
field with continuous normal traction
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
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
#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.
FTensor::Index< 'l', 3 > l
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
SchurBlockStructureDigest schurBlockStructureDigest(boost::shared_ptr< BlockStructure > data_ptr)
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.
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
auto createDMHybridisedL2Matrix(DM dm)
Get smart hybridised L2 matrix from DM.
boost::shared_ptr< BlockStructure > createBlockMatStructure(DM dm, SchurFEOpsFEandFields schur_fe_op_vec)
Create block matrix structure.
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].
MoFEMErrorCode rebuildSchurNestedMatrixStruture(std::pair< SmartPetscObj< DM >, SmartPetscObj< DM > > dms, boost::shared_ptr< NestSchurData > nest_data_ptr)
Rebuild a nested Schur structure after rebuildBlockMatStructure.
MoFEMErrorCode rebuildBlockMatStructure(DM dm, SchurFEOpsFEandFields schur_fe_op_vec, boost::shared_ptr< BlockStructure > data_ptr)
Rebuild a block matrix structure after its problem changed.
std::vector< std::pair< std::string, std::vector< SchurFieldPair > > > SchurFEOpsFEandFields
SchurShellMatData createBlockMat(DM dm, boost::shared_ptr< BlockStructure > data)
Create a Schur Mat object.
FTensor::Index< 'm', 3 > m
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Deprecated interface functions.
Simple interface for fast problem set-up.
intrusive_ptr for managing petsc objects
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.