429 {
430
432
433 try {
434
435 moab::Core mb_instance;
436 moab::Interface &moab = mb_instance;
437
438 char mesh_file_name[255];
439 PetscBool flg = PETSC_FALSE;
441 mesh_file_name, 255, &flg);
442 if (flg != PETSC_TRUE)
444 "-file_name <mesh> is required");
446 PetscBool is_partitioned = PETSC_FALSE, skip_matrix = PETSC_FALSE;
448 PETSC_NULLPTR);
450 PETSC_NULLPTR);
452 &is_partitioned, PETSC_NULLPTR);
453
454
456 PETSC_NULLPTR);
457
458
459 PetscBool incremental = PETSC_TRUE;
461 PETSC_NULLPTR);
462
463
464
465 PetscInt local_from = -1;
467 PETSC_NULLPTR);
468
469
470
471 PetscBool in_place = PETSC_FALSE;
473 PETSC_NULLPTR);
474 if (in_place && !is_partitioned)
476 "-in_place needs -dm_is_partitioned");
477
478 CHKERR moab.load_file(mesh_file_name, 0,
"");
479
484
485 Events ev;
486 CHKERR PetscLogEventRegister(
"RP_Refine", 0, &ev.refine);
487 CHKERR PetscLogEventRegister(
"RP_FieldsFEs", 0, &ev.fieldsFes);
488 CHKERR PetscLogEventRegister(
"RP_Rebuild", 0, &ev.rebuild);
489 CHKERR PetscLogEventRegister(
"RP_Fresh", 0, &ev.fresh);
490 CHKERR PetscLogEventRegister(
"RP_Matrix", 0, &ev.matrix);
491
496 << (is_partitioned ? "distributed" : "replicated") << " builder, "
497 << (incremental ? "incremental" : "full")
498 << " field/element registration, "
499 << (in_place ? "in-place rebuild" : "recreate path");
500
501 auto count_tets = [&](
int l) {
505 bit(
l), allBits(), 3, tets),
506 "count tets");
507 return tets.size();
508 };
509
510 auto log_level = [&](
int l,
const std::string &
name,
const Summary &
s,
511 double seconds) {
515 <<
"Level " <<
l <<
" " <<
name <<
": tets " << count_tets(
l)
516 <<
", elements " <<
s.elements <<
", dofs " <<
s.globalDofs
517 <<
" (local " <<
s.localDofs <<
", ghost " <<
s.ghostDofs
518 << "), build " << seconds << " s";
519 };
520
522 State st;
523
524
525
526
527
528 auto rebuilt_mask = [&](
int l) {
529 return (local_from >= 0 &&
l >= local_from) ? allBits()
531 };
532
533
537 MB_TAG_DENSE);
542 fieldName);
543
544 auto require = [&](bool ok, const std::string &what) {
546 if (!ok)
548 "Stage order broken: %s", what.c_str());
550 };
551
552
555 PetscLogEventBegin(ev.fieldsFes, 0, 0, 0, 0);
556 CHKERR registerLevel(m_field, 0,
order, incremental);
557 PetscLogEventEnd(ev.fieldsFes, 0, 0, 0, 0);
558 st.level = 0;
559 st.aliveName = "P0";
560 CHKERR buildProblem(m_field, st.aliveName,
bit(0), allBits(),
561 is_partitioned, ev.fresh, st.alive, st.aliveSeconds);
562 CHKERR summarise(m_field, st.aliveName, st.aliveSummary);
563 log_level(0, st.aliveName, st.aliveSummary, st.aliveSeconds);
565 "level 0 has dofs", st.aliveSummary.globalDofs > 0 ? 1 : 0, 1,
566 zero);
568 });
569
571 const auto tag =
"level " + std::to_string(
l);
572 const int base = 10 *
l;
573
576 CHKERR require(st.level ==
l - 1 && st.alive,
577 tag +
" refine needs level " + std::to_string(
l - 1) +
578 " registered and its problem alive");
579 const bool local = local_from >= 0 &&
l >= local_from;
580 const auto tets_before = count_tets(
l - 1);
581 int refined;
582 PetscLogEventBegin(ev.refine, 0, 0, 0, 0);
583 CHKERR refineLevel(m_field,
l, local, refined);
584 PetscLogEventEnd(ev.refine, 0, 0, 0, 0);
585 PetscLogDouble t0, t1;
587 PetscLogEventBegin(ev.fieldsFes, 0, 0, 0, 0);
589 PetscLogEventEnd(ev.fieldsFes, 0, 0, 0, 0);
592 int duplicates;
593 CHKERR countDuplicateViewEntries(m_field, duplicates);
597 <<
"Level " <<
l << (local ?
" local" :
" uniform")
598 << " refinement of " << refined
599 << " tets; fields and elements registered in " << t1 - t0
600 << " s, duplicate view entries " << duplicates;
601
603 tag +
" tets after refinement", count_tets(
l),
604 tets_before + 7. * refined, zero);
606 tag +
" element views without duplicates", duplicates, 0, zero);
608 });
609
610
611
612
613
616 CHKERR require(st.level ==
l && st.alive && !st.rebuilt,
617 tag +
" rebuild needs the refined level and the "
618 "previous problem alive");
619 if (in_place) {
620 std::map<UId, int> old_global;
621 {
622 const Problem *prb;
624 for (auto &dof : *prb->getNumeredRowDofsPtr())
625 if (dof->getPetscGlobalDofIdx() >= 0)
626 old_global[dof->getLocalUniqueId()] =
627 dof->getPetscGlobalDofIdx();
628 }
629 IS raw_old, raw_new;
630 PetscLogDouble t0, t1;
632 PetscLogEventBegin(ev.rebuild, 0, 0, 0, 0);
634 &raw_old, &raw_new);
635 PetscLogEventEnd(ev.rebuild, 0, 0, 0, 0);
638 st.rebuilt = st.alive;
639 st.alive.reset();
640 st.rebuiltName = st.aliveName;
641 st.rebuiltSeconds = t1 - t0;
642 CHKERR summarise(m_field, st.rebuiltName, st.rebuiltSummary);
643 log_level(
l, st.rebuiltName +
" in place", st.rebuiltSummary,
644 st.rebuiltSeconds);
646 tag +
" problem keeps its name",
649 tag +
" staging problem removed",
650 m_field.
check_problem(st.rebuiltName +
"__REBUILD_STAGE") ? 1
651 : 0,
652 0, zero);
654 old_global, st.aliveSummary.localDofs,
655 st.aliveSummary.globalDofs, is_old, is_new);
657 }
658 st.rebuiltName =
"P" + std::to_string(
l) +
"_rebuild";
659 CHKERR buildProblem(m_field, st.rebuiltName,
bit(
l), rebuilt_mask(
l),
660 is_partitioned, ev.rebuild, st.rebuilt,
661 st.rebuiltSeconds);
662 CHKERR summarise(m_field, st.rebuiltName, st.rebuiltSummary);
663 log_level(
l, st.rebuiltName, st.rebuiltSummary, st.rebuiltSeconds);
664
665 Summary source_after;
666 CHKERR summarise(m_field, st.aliveName, source_after);
668 tag +
" source dofs unchanged", source_after.globalDofs,
669 st.aliveSummary.globalDofs, zero);
671 tag +
" source numbering unchanged",
672 source_after.numbering == st.aliveSummary.numbering ? 0 : 1, 0,
673 zero);
674
675
676 st.alive.reset();
678 tag +
" source problem deleted",
681 });
682
683
686 CHKERR require(st.level ==
l && st.rebuilt && !st.alive && !st.fresh,
687 tag +
" fresh build needs the rebuilt problem and "
688 "the source destroyed");
689 st.freshName =
"P" + std::to_string(
l);
690 CHKERR buildProblem(m_field, st.freshName,
bit(
l), allBits(),
691 is_partitioned, ev.fresh, st.fresh,
692 st.freshSeconds);
693 CHKERR summarise(m_field, st.freshName, st.freshSummary);
694 log_level(
l, st.freshName, st.freshSummary, st.freshSeconds);
696 });
697
700 CHKERR require(st.level ==
l && st.rebuilt && st.fresh,
701 tag +
" compare needs both problems");
702 const auto &
r = st.rebuiltSummary, &
f = st.freshSummary;
704 tag +
" global dofs",
r.globalDofs,
f.globalDofs, zero);
706 tag +
" local dofs",
r.localDofs,
f.localDofs, zero);
708 tag +
" ghost dofs",
r.ghostDofs,
f.ghostDofs, zero);
710 tag +
" elements",
r.elements,
f.elements, zero);
712 tag +
" numbering hash equal",
713 r.numbering ==
f.numbering ? 0 : 1, 0, zero);
714 Mismatch mismatch;
715 CHKERR compareProblems(m_field, st.rebuiltName, st.freshName,
bit(
l),
716 mismatch);
718 tag +
" dofs missing from fresh", mismatch.missing, 0, zero);
720 tag +
" dofs with different index", mismatch.index, 0, zero);
722 tag +
" dofs on source-only parents", mismatch.parents, 0, zero);
724 });
725
726
727
730 CHKERR require(st.level ==
l && st.rebuilt && st.fresh,
731 tag +
" matrix needs both problems");
732 if (!skip_matrix) {
733 double rows_rebuilt, nnz_rebuilt, rows_fresh, nnz_fresh;
734 double seconds_rebuilt, seconds_fresh;
735 MatrixGraph graph;
736 CHKERR matrixInfo(m_field, st.rebuiltName, ev.matrix, rows_rebuilt,
737 nnz_rebuilt, seconds_rebuilt, graph);
738 CHKERR matrixInfo(m_field, st.freshName, ev.matrix, rows_fresh,
739 nnz_fresh, seconds_fresh, graph, true);
743 <<
"Level " <<
l <<
" matrix rows " << rows_rebuilt
744 << ", non-zeros " << nnz_rebuilt << ", created in "
745 << seconds_rebuilt << " s and " << seconds_fresh << " s";
747 tag +
" matrix rows", rows_rebuilt, rows_fresh, zero);
749 tag +
" matrix rows equal dofs", rows_rebuilt,
750 st.rebuiltSummary.globalDofs, zero);
752 tag +
" matrix non-zeros", nnz_rebuilt, nnz_fresh, zero);
754 tag +
" matrix rows with different column indices",
755 graph.differentRows, 0, zero);
756 }
757
758 st.fresh.reset();
759 st.alive = st.rebuilt;
760 st.rebuilt.reset();
761 st.aliveName = st.rebuiltName;
762 st.aliveSummary = st.rebuiltSummary;
763 st.aliveSeconds = st.rebuiltSeconds;
765 });
766 }
767
768
769
771 }
773
775
776 return 0;
777}
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
#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()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
PetscErrorCode DMMoFEMRebuildProblem(DM dm, const MoFEM::BitRefLevel target_bit, const MoFEM::BitRefLevel target_mask, IS *old_row_indices=PETSC_NULLPTR, IS *new_row_indices=PETSC_NULLPTR)
Rebuild the DM's parent problem in place on a new bit ref level.
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
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
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
virtual MoFEMErrorCode modify_finite_element_add_field_col(const std::string &fe_name, const std::string name_row)=0
set field col which finite element use
virtual MoFEMErrorCode modify_finite_element_add_field_row(const std::string &fe_name, const std::string name_row)=0
set field row which finite element use
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string name_field)=0
set finite element field data
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
virtual bool check_problem(const std::string name)=0
check if problem exist
FTensor::Index< 'l', 3 > l
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
virtual MoFEMErrorCode add_field(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add field.
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.
intrusive_ptr for managing petsc objects
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.