v0.16.3
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
Fun3::HybridProblem Struct Reference

Retain the parent/sub-DMs, field DOFs and block storage across mesh edits. More...

#include "tutorials/fun-3_delaunay_reconstruction/HybridProblem.hpp"

Collaboration diagram for Fun3::HybridProblem:
[legend]

Public Member Functions

 HybridProblem (MoFEM::Interface &m_field)
 
 HybridProblem (const HybridProblem &)=delete
 
HybridProblem & operator= (const HybridProblem &)=delete
 
 ~HybridProblem ()
 
MoFEMErrorCode prepareUpdate ()
 Release numeric objects and cached vectors before topology edits.
 
MoFEMErrorCode release ()
 Final teardown, after all retained storage stops referencing sub-DMs.
 
MoFEMErrorCode buildSubProblem (const char *name, const std::vector< std::string > &fields, SmartPetscObj< DM > &dm)
 Rebuild subproblem numbering while keeping its DM and field selection.
 
SchurFEOpsFEandFields getBlockOperations () const
 Couplings used by both construction and the optional fresh-build oracle.
 
MoFEMErrorCode build (const Range &entities, const Range &skeleton, const BitRefLevel &active_bit, int order, bool refresh_registration)
 Construct the DMs and matrices without running validation or test fills.
 
MoFEMErrorCode validate (const Range &entities, const Range &skeleton, int order, const std::string &tag)
 Check the completed algebra; graph validation fills the hybrid matrix.
 

Public Attributes

MoFEM::Interface & mField
 
Simple * simplePtr
 
bool configured = false
 
bool updatePrepared = false
 
bool structuresReused = false
 
PetscBool rebuildStructures = PETSC_TRUE
 
PetscBool checkRebuiltStructures = PETSC_FALSE
 
std::array< double, 5 > summary {}
 
std::array< PetscObjectId, 3 > dmIds {}
 
std::array< boost::shared_ptr< DofEntity >, 3 > retainedDofPtrs
 
SmartPetscObj< DM > schurDMPtr
 
SmartPetscObj< DM > blockDMPtr
 
SmartPetscObj< Mat > blockMatPtr
 
SmartPetscObj< Mat > nestedMatPtr
 
SmartPetscObj< Mat > hybridMatPtr
 
boost::shared_ptr< BlockStructure > blockDataPtr
 
boost::shared_ptr< NestSchurData > nestedDataPtr
 

Detailed Description

Retain the parent/sub-DMs, field DOFs and block storage across mesh edits.

Examples
mesh_reconstruction.cpp.

Definition at line 102 of file HybridProblem.hpp.

Constructor & Destructor Documentation

◆ HybridProblem() [1/2]

Fun3::HybridProblem::HybridProblem ( MoFEM::Interface &  m_field)
inlineexplicit

Definition at line 118 of file HybridProblem.hpp.

119 : mField(m_field), simplePtr(m_field.getInterface<Simple>()) {}
MoFEM::Interface & mField
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.

◆ HybridProblem() [2/2]

Fun3::HybridProblem::HybridProblem ( const HybridProblem &  )
delete

◆ ~HybridProblem()

Fun3::HybridProblem::~HybridProblem ( )
inline

Definition at line 122 of file HybridProblem.hpp.

122{ CHKERRABORT(mField.get_comm(), release()); }
MoFEMErrorCode release()
Final teardown, after all retained storage stops referencing sub-DMs.
virtual MPI_Comm & get_comm() const =0

Member Function Documentation

◆ build()

MoFEMErrorCode Fun3::HybridProblem::build ( const Range &  entities,
const Range &  skeleton,
const BitRefLevel &  active_bit,
int  order,
bool  refresh_registration 
)
inline

Construct the DMs and matrices without running validation or test fills.

Definition at line 210 of file HybridProblem.hpp.

212 {
215 updatePrepared = false;
216 const bool update = bool(simplePtr->getDM());
217 auto &mb = mField.get_moab();
218 if (!configured) {
219 CHKERR PetscOptionsGetBool(nullptr, nullptr, "-rebuild_structures",
220 &rebuildStructures, nullptr);
221 CHKERR PetscOptionsGetBool(nullptr, nullptr, "-check_rebuilt_structures",
222 &checkRebuiltStructures, nullptr);
223 simplePtr->setDim(3);
224 simplePtr->getAddBoundaryFE() = false;
225 CHKERR mb.create_meshset(MESHSET_SET, simplePtr->getMeshset());
226 CHKERR mb.create_meshset(MESHSET_SET, simplePtr->getSkeletonMeshSet());
231 1);
234 CHKERR simplePtr->setFieldOrder("HYBRID", order - 1);
235 configured = true;
236 }
237 for (auto set : {simplePtr->getMeshset(), simplePtr->getSkeletonMeshSet()})
238 CHKERR mb.clear_meshset(&set, 1);
239 CHKERR mb.add_entities(simplePtr->getMeshset(), entities);
240 CHKERR mb.add_entities(simplePtr->getSkeletonMeshSet(), skeleton);
241 simplePtr->getBitRefLevel() = active_bit;
242 simplePtr->getBitAdjEnt() = active_bit;
243 simplePtr->getBitAdjParent().reset();
244 if (!update || refresh_registration) {
245 Range new_field_entities;
246 auto comm_ptr = mField.getInterface<CommInterface>();
247 // A face may leave the skeleton without being deleted (e.g. when it
248 // joins a crack). Do not retain its old trace DOFs or skeleton element.
249 for (const auto &name : {"BROKEN", "U", "HYBRID"}) {
250 Range registered;
251 CHKERR mb.get_entities_by_handle(mField.get_field_meshset(name),
252 registered);
253 const auto &keep = std::string(name) == "HYBRID" ? skeleton : entities;
254 const auto removed = subtract(registered, keep);
255 if (!removed.empty())
257 registered = intersect(registered, keep);
258 const int dim = std::string(name) == "HYBRID" ? 2 : 3;
259 const auto added = subtract(keep.subset_by_dimension(dim), registered);
261 CHKERR comm_ptr->synchroniseFieldEntities(name, 0);
262 Range current;
263 CHKERR mb.get_entities_by_handle(mField.get_field_meshset(name),
264 current);
265 // A loaded checkpoint can carry field memberships and an older order.
266 // Initialise all current members once, then update additions only.
267 const auto new_entities =
268 update ? subtract(current, registered) : current;
269 if (!new_entities.empty())
271 new_entities, name,
272 std::string(name) == "BROKEN" ? order : order - 1, QUIET);
273 new_field_entities.merge(new_entities);
274 }
275 for (const auto &[name, keep] :
276 std::vector<std::pair<std::string, Range>>{
277 {simplePtr->getDomainFEName(), entities},
278 {simplePtr->getSkeletonFEName(), skeleton}}) {
280 continue;
281 Range registered;
282 CHKERR mb.get_entities_by_handle(
284 const auto removed = subtract(registered, keep);
285 if (!removed.empty())
287 }
288 if (!update)
292 // The range overload preserves existing DOF objects. Rebuilding views
293 // still visits surviving faces whose adjacent cells may have changed.
294 CHKERR mField.build_fields(new_field_entities, QUIET);
296 }
297 if (!update)
298 CHKERR simplePtr->defineProblem(PETSC_TRUE);
299 if (update) {
302 auto problems_ptr = mField.getInterface<ProblemsManager>();
303 const auto from_fields = problems_ptr->buildProblemFromFields;
304 problems_ptr->buildProblemFromFields = PETSC_TRUE;
305 const auto ierr = DMMoFEMRebuildProblem(simplePtr->getDM(), active_bit,
307 problems_ptr->buildProblemFromFields = from_fields;
308 CHKERR ierr;
309 } else
311 CHKERR buildSubProblem("SCHUR", {"HYBRID"}, schurDMPtr);
312 CHKERR buildSubProblem("BLOCK", {"BROKEN", "U"}, blockDMPtr);
313 const auto ops = getBlockOperations();
314 const bool reuse = rebuildStructures && blockDataPtr && nestedDataPtr;
315 structuresReused = reuse;
316 if (reuse)
318 else {
319 nestedDataPtr.reset();
321 }
323 if (reuse)
326 else
328 {schurDMPtr, blockDMPtr}, blockDataPtr, {"BROKEN", "U"},
329 {nullptr, nullptr}, true);
333 }
std::vector< int > removed
moab::Interface & mb
std::string name
@ QUIET
@ DEMKOWICZ_JACOBI_BASE
Definition definitions.h:66
@ 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 ...
#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 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.
Definition DMMoFEM.cpp:479
virtual EntityHandle get_finite_element_meshset(const std::string name) const =0
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.
virtual MoFEMErrorCode remove_ents_from_field(const std::string name, const EntityHandle meshset, const EntityType type, int verb=DEFAULT_VERBOSITY)=0
remove entities from field
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
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 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
SchurShellMatData createBlockMat(DM dm, boost::shared_ptr< BlockStructure > data)
Create a Schur Mat object.
Definition Schur.cpp:3615
MoFEMErrorCode buildSubProblem(const char *name, const std::vector< std::string > &fields, SmartPetscObj< DM > &dm)
Rebuild subproblem numbering while keeping its DM and field selection.
boost::shared_ptr< NestSchurData > nestedDataPtr
PetscBool checkRebuiltStructures
SmartPetscObj< Mat > blockMatPtr
SmartPetscObj< DM > blockDMPtr
MoFEMErrorCode prepareUpdate()
Release numeric objects and cached vectors before topology edits.
SmartPetscObj< Mat > nestedMatPtr
boost::shared_ptr< BlockStructure > blockDataPtr
SchurFEOpsFEandFields getBlockOperations() const
Couplings used by both construction and the optional fresh-build oracle.
SmartPetscObj< DM > schurDMPtr
SmartPetscObj< Mat > hybridMatPtr
virtual moab::Interface & get_moab()=0
virtual EntityHandle get_field_meshset(const std::string name) const =0
get field meshset
virtual bool check_finite_element(const std::string &name) const =0
Check if finite element is in database.
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
virtual MoFEMErrorCode remove_ents_from_finite_element(const std::string name, const EntityHandle meshset, const EntityType type, int verb=DEFAULT_VERBOSITY)=0
remove entities from given refinement level to finite element database
MoFEMErrorCode buildProblem()
Build problem.
Definition Simple.cpp:724
MoFEMErrorCode addDomainField(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_ZERO, int verb=-1)
Add field on domain.
Definition Simple.cpp:264
bool & getAddBoundaryFE()
Get the addBoundaryFE flag.
Definition Simple.hpp:546
MoFEMErrorCode defineFiniteElements()
Define finite elements.
Definition Simple.cpp:474
EntityHandle & getMeshset()
Get the MeshSet object.
Definition Simple.hpp:394
auto & getBitAdjParent()
Get bit ref level for parent.
Definition Simple.hpp:562
MoFEMErrorCode buildFiniteElements()
Build finite elements.
Definition Simple.cpp:662
const std::string getSkeletonFEName() const
Get the Skeleton FE Name.
Definition Simple.hpp:443
EntityHandle & getSkeletonMeshSet()
Get the SkeletonMeshSet object.
Definition Simple.hpp:408
void setDim(int dim)
Set the problem dimension.
Definition Simple.hpp:380
MoFEMErrorCode getDM(DM *dm)
Get DM.
Definition Simple.cpp:802
auto & getBitAdjEnt()
Get bit ref level for entities.
Definition Simple.hpp:576
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
Definition Simple.cpp:578
MoFEMErrorCode defineProblem(const PetscBool is_partitioned=PETSC_TRUE)
define problem
Definition Simple.cpp:554
BitRefLevel & getBitRefLevelMask()
Get the BitRefLevelMask.
Definition Simple.hpp:422
const std::string getDomainFEName() const
Get the Domain FE Name.
Definition Simple.hpp:429
MoFEMErrorCode setSkeletonAdjacency(int dim=-1, std::string fe_name="")
Set the skeleton adjacency object.
Definition Simple.cpp:143
BitRefLevel & getBitRefLevel()
Get the BitRefLevel.
Definition Simple.hpp:415
MoFEMErrorCode addDomainBrokenField(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_ZERO, int verb=-1)
Add broken field on domain.
Definition Simple.cpp:285
MoFEMErrorCode addSkeletonField(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_ZERO, int verb=-1)
Add field on skeleton.
Definition Simple.cpp:376

◆ buildSubProblem()

MoFEMErrorCode Fun3::HybridProblem::buildSubProblem ( const char *  name,
const std::vector< std::string > &  fields,
SmartPetscObj< DM > &  dm 
)
inline

Rebuild subproblem numbering while keeping its DM and field selection.

Definition at line 166 of file HybridProblem.hpp.

168 {
170 const bool update = bool(dm);
171 if (!update) {
172 dm = createDM(mField.get_comm(), "DMMOFEM");
174 CHKERR DMMoFEMSetDestroyProblem(dm, PETSC_FALSE);
175 CHKERR DMMoFEMSetSquareProblem(dm, PETSC_TRUE);
178 for (const auto &field : fields) {
181 }
182 }
183 // Creation adds selector bits to an existing named problem. Rebuilding
184 // must replace them, otherwise inactive source cells enter preallocation.
185 const Problem *parent_ptr;
188 name, parent_ptr->getBitRefLevel());
190 name, parent_ptr->getBitRefLevelMask());
191 // DMSetUp() skips a DM already set up by PETSc. Invoke MoFEM's subproblem
192 // setup directly to refresh its numbering and partitions in this object.
193 if (update)
195 else
196 CHKERR DMSetUp(dm);
198 }
ProjectedField & field
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 DMMoFEMAddSubFieldCol(DM dm, const char field_name[])
Definition DMMoFEM.cpp:309
PetscErrorCode DMSubDMSetUp_MoFEM(DM subdm)
Definition DMMoFEM.cpp:1431
virtual MoFEMErrorCode modify_problem_mask_ref_level_set_bit(const std::string &name_problem, const BitRefLevel &bit)=0
set dof mask ref level for problem
virtual MoFEMErrorCode modify_problem_ref_level_set_bit(const std::string &name_problem, const BitRefLevel &bit)=0
set ref level for problem
PetscErrorCode DMMoFEMSetDestroyProblem(DM dm, PetscBool destroy_problem)
Definition DMMoFEM.cpp:463
auto createDM(MPI_Comm comm, const std::string dm_type_name)
Creates smart DM object.

◆ getBlockOperations()

SchurFEOpsFEandFields Fun3::HybridProblem::getBlockOperations ( ) const
inline

Couplings used by both construction and the optional fresh-build oracle.

Definition at line 201 of file HybridProblem.hpp.

201 {
202 return {
204 {{"BROKEN", "BROKEN"}, {"U", "U"}, {"BROKEN", "U"}, {"U", "BROKEN"}}},
206 {{"BROKEN", "HYBRID"}, {"HYBRID", "BROKEN"}}}};
207 }

◆ operator=()

HybridProblem & Fun3::HybridProblem::operator= ( const HybridProblem &  )
delete

◆ prepareUpdate()

MoFEMErrorCode Fun3::HybridProblem::prepareUpdate ( )
inline

Release numeric objects and cached vectors before topology edits.

Definition at line 125 of file HybridProblem.hpp.

125 {
127 if (updatePrepared)
129 hybridMatPtr.reset();
130 nestedMatPtr.reset();
131 blockMatPtr.reset();
132 for (DM dm : {simplePtr->getDM().get(), schurDMPtr.get(), blockDMPtr.get()})
133 if (dm) {
135 CHKERR DMClearGlobalVectors(dm);
136 CHKERR DMClearLocalVectors(dm);
137 CHKERR DMClearNamedGlobalVectors(dm);
138 CHKERR DMClearNamedLocalVectors(dm);
139 }
140 updatePrepared = true;
142 }
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
PetscErrorCode DMMoFEMClearDMCtx(DM dm)
Clear solver and Schur data owned by a MoFEM DM context.
Definition DMMoFEM.cpp:79

◆ release()

MoFEMErrorCode Fun3::HybridProblem::release ( )
inline

Final teardown, after all retained storage stops referencing sub-DMs.

Definition at line 145 of file HybridProblem.hpp.

145 {
148 nestedDataPtr.reset();
149 blockDataPtr.reset();
150 schurDMPtr.reset();
151 blockDMPtr.reset();
152 for (const auto &name : {"SCHUR", "BLOCK"})
155 auto parent_dm_ptr = simplePtr->getDM();
156 if (parent_dm_ptr) {
157 CHKERR DMMoFEMSetDestroyProblem(parent_dm_ptr, PETSC_TRUE);
159 parent_dm_ptr.reset();
161 }
163 }
virtual MoFEMErrorCode delete_problem(const std::string name)=0
Delete problem.
virtual bool check_problem(const std::string name)=0
check if problem exist
MoFEMErrorCode deleteDM()
Delete dm.
Definition Simple.cpp:814
MoFEMErrorCode deleteFiniteElements()
Delete finite elements.
Definition Simple.cpp:825

◆ validate()

MoFEMErrorCode Fun3::HybridProblem::validate ( const Range &  entities,
const Range &  skeleton,
int  order,
const std::string &  tag 
)
inline

Check the completed algebra; graph validation fills the hybrid matrix.

Definition at line 336 of file HybridProblem.hpp.

337 {
339 if (!hybridMatPtr)
341 "Build the hybrid problem before validating it");
343 auto fresh_block_ptr =
345 auto fresh_nested_ptr = createSchurNestedMatrixStruture(
346 {schurDMPtr, blockDMPtr}, fresh_block_ptr, {"BROKEN", "U"},
347 {nullptr, nullptr}, true);
348 auto compare = [&](const std::string &what, auto rebuilt_ptr,
349 auto fresh_ptr) {
351 const auto r = schurBlockStructureDigest(rebuilt_ptr);
352 const auto f = schurBlockStructureDigest(fresh_ptr);
353 if (r.nbBlocks != f.nbBlocks || r.nbElems != f.nbElems ||
354 r.indexHash != f.indexHash || r.blocksHash != f.blocksHash ||
355 r.elemsHash != f.elemsHash)
356 MOFEM_LOG("WORLD", Sev::error)
357 << what << " digest: blocks " << r.nbBlocks << "/" << f.nbBlocks
358 << ", elements " << r.nbElems << "/" << f.nbElems << ", index "
359 << r.indexHash << "/" << f.indexHash << ", layout "
360 << r.blocksHash << "/" << f.blocksHash << ", element layout "
361 << r.elemsHash << "/" << f.elemsHash;
362 CHKERR mField.getInterface<TestingInterface>()
364 tag + " rebuilt " + what + " equals fresh structure",
365 r.nbBlocks == f.nbBlocks && r.nbElems == f.nbElems &&
366 r.indexHash == f.indexHash &&
367 r.blocksHash == f.blocksHash &&
368 r.elemsHash == f.elemsHash
369 ? 0
370 : 1,
371 0, TestingInterface::Tolerance{0, 0});
373 };
374 CHKERR compare("block", blockDataPtr, fresh_block_ptr);
375 for (int q = 0; q != 4; ++q)
376 CHKERR compare("quadrant " + std::to_string(q),
377 std::get<1>(*nestedDataPtr)[q],
378 std::get<1>(*fresh_nested_ptr)[q]);
379 }
380 auto testing_ptr = mField.getInterface<TestingInterface>();
381 const auto zero = TestingInterface::Tolerance{0, 0};
382 int dm_index = 0;
383 for (DM dm :
384 {simplePtr->getDM().get(), blockDMPtr.get(), schurDMPtr.get()}) {
385 PetscObjectId id;
386 CHKERR PetscObjectGetId(reinterpret_cast<PetscObject>(dm), &id);
387 if (!dmIds[dm_index])
388 dmIds[dm_index] = id;
389 CHKERR testing_ptr->checkValue<TestType::SCALAR>(
390 tag + " DM " + std::to_string(dm_index) + " identity retained",
391 id == dmIds[dm_index] ? 0 : 1, 0, zero);
392 ++dm_index;
393 }
394 // Sample one DOF per field. Replaced entities may have new field objects;
395 // a surviving field entity must keep its existing DOF object as well.
396 const auto &dofs = mField.get_dofs()->get<Unique_mi_tag>();
397 int field_index = 0;
398 for (const auto &name : {"BROKEN", "U", "HYBRID"}) {
399 auto &old_ptr = retainedDofPtrs[field_index++];
400 int identity_error = 0;
401 if (old_ptr) {
402 auto it = dofs.find(old_ptr->getLocalUniqueId());
403 if (it != dofs.end() &&
404 (*it)->getFieldEntityPtr() == old_ptr->getFieldEntityPtr())
405 identity_error = *it == old_ptr ? 0 : 1;
406 }
407 CHKERR testing_ptr->checkValue<TestType::SCALAR>(
408 tag + " surviving " + name + " DOF identity retained", identity_error,
409 0, zero);
410 const auto bit_number = mField.get_field_bit_number(name);
411 auto it = dofs.lower_bound(FieldEntity::getLoBitNumberUId(bit_number));
412 old_ptr = it != dofs.end() && (*it)->getBitNumber() == bit_number
413 ? *it
414 : nullptr;
415 }
416 int counts[2] = {static_cast<int>(entities.num_of_type(MBTET)),
417 static_cast<int>(skeleton.size())};
418 CHKERR MPI_Bcast(counts, 2, MPI_INT, 0, mField.get_comm());
419 const double broken =
421 const double block_rows = counts[0] * (broken + NBVOLUMETET_L2(order - 1));
422 const double schur_rows = counts[1] * NBFACETRI_L2(order - 1);
423 const double parent_rows = block_rows + schur_rows;
424 for (const auto &[dm, expected] :
425 std::vector<std::pair<DM, double>>{{simplePtr->getDM(), parent_rows},
426 {blockDMPtr, block_rows},
427 {schurDMPtr, schur_rows}}) {
428 const Problem *problem_ptr;
429 CHKERR DMMoFEMGetProblemPtr(dm, &problem_ptr);
430 CHKERR testing_ptr->checkValue<TestType::SCALAR>(
431 tag + " DM DOFs match complete root topology",
432 problem_ptr->getNbDofsRow(), expected, zero);
433 auto vector = createDMVector(dm);
434 PetscInt n, first, last;
435 CHKERR VecGetSize(vector, &n);
436 CHKERR VecGetOwnershipRange(vector, &first, &last);
437 CHKERR testing_ptr->checkValue<TestType::SCALAR>(
438 tag + " DM vector global size", n, expected, zero);
439 CHKERR testing_ptr->checkValue<TestType::SCALAR>(
440 tag + " DM vector local size", last - first,
441 problem_ptr->nbLocDofsRow, zero);
442 }
443 for (const auto &[matrix, expected] :
444 std::vector<std::pair<Mat, double>>{{blockMatPtr, parent_rows},
445 {nestedMatPtr, parent_rows},
446 {hybridMatPtr, schur_rows}}) {
447 PetscInt m, n;
448 CHKERR MatGetSize(matrix, &m, &n);
449 CHKERR testing_ptr->checkValue<TestType::SCALAR>(tag + " matrix rows", m,
450 expected, zero);
451 CHKERR testing_ptr->checkValue<TestType::SCALAR>(tag + " matrix columns",
452 n, expected, zero);
453 }
454 double nnz;
456 entities.subset_by_type(MBTET), hybridMatPtr,
457 *testing_ptr, tag, nnz);
458 summary = {static_cast<double>(order), parent_rows, block_rows, schur_rows,
459 nnz};
460 MOFEM_LOG("WORLD", Sev::inform)
461 << "Hybrid rebuilt " << tag
462 << (structuresReused ? " [reused structures]" : " [fresh structures]")
463 << ": parent " << parent_rows << ", BLOCK " << block_rows << ", SCHUR "
464 << schur_rows << ", nonzeros " << nnz;
466 }
Tag tag
It it
Definition Schur.cpp:2568
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
auto createDMVector(DM dm, RowColData rc=RowColData::COL)
Get smart vector from DM.
Definition DMMoFEM.hpp:1279
virtual const DofEntity_multiIndex * get_dofs() const =0
Get the dofs object.
#define MOFEM_LOG(channel, severity)
Log.
#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.
MoFEMErrorCode check_hybrid_matrix(MoFEM::Interface &m_field, DM dm, const Range &tets, Mat matrix, TestingInterface &testing, const std::string &tag, double &nonzeros)
SchurBlockStructureDigest schurBlockStructureDigest(boost::shared_ptr< BlockStructure > data_ptr)
Definition Schur.cpp:4821
MoFEMErrorCode TestingInterface::checkValue< TestType::SCALAR >(const std::string &check_name, PetscReal actual, PetscReal expected, Tolerance tolerance, Sev error_severity, Sev success_severity) const
int r
Definition sdf.py:205
double q
FTensor::Index< 'm', 3 > m
std::array< double, 5 > summary
std::array< PetscObjectId, 3 > dmIds
std::array< boost::shared_ptr< DofEntity >, 3 > retainedDofPtrs
virtual FieldBitNumber get_field_bit_number(const std::string name) const =0
get field bit number
static UId getLoBitNumberUId(const FieldBitNumber bit_number)

Member Data Documentation

◆ blockDataPtr

boost::shared_ptr<BlockStructure> Fun3::HybridProblem::blockDataPtr

Definition at line 115 of file HybridProblem.hpp.

◆ blockDMPtr

SmartPetscObj<DM> Fun3::HybridProblem::blockDMPtr

Definition at line 113 of file HybridProblem.hpp.

◆ blockMatPtr

SmartPetscObj<Mat> Fun3::HybridProblem::blockMatPtr

Definition at line 114 of file HybridProblem.hpp.

◆ checkRebuiltStructures

PetscBool Fun3::HybridProblem::checkRebuiltStructures = PETSC_FALSE

Definition at line 109 of file HybridProblem.hpp.

◆ configured

bool Fun3::HybridProblem::configured = false

Definition at line 105 of file HybridProblem.hpp.

◆ dmIds

std::array<PetscObjectId, 3> Fun3::HybridProblem::dmIds {}

Definition at line 111 of file HybridProblem.hpp.

111{};

◆ hybridMatPtr

SmartPetscObj<Mat> Fun3::HybridProblem::hybridMatPtr

Definition at line 114 of file HybridProblem.hpp.

◆ mField

MoFEM::Interface& Fun3::HybridProblem::mField

Definition at line 103 of file HybridProblem.hpp.

◆ nestedDataPtr

boost::shared_ptr<NestSchurData> Fun3::HybridProblem::nestedDataPtr

Definition at line 116 of file HybridProblem.hpp.

◆ nestedMatPtr

SmartPetscObj<Mat> Fun3::HybridProblem::nestedMatPtr

Definition at line 114 of file HybridProblem.hpp.

◆ rebuildStructures

PetscBool Fun3::HybridProblem::rebuildStructures = PETSC_TRUE

Definition at line 108 of file HybridProblem.hpp.

◆ retainedDofPtrs

std::array<boost::shared_ptr<DofEntity>, 3> Fun3::HybridProblem::retainedDofPtrs

Definition at line 112 of file HybridProblem.hpp.

◆ schurDMPtr

SmartPetscObj<DM> Fun3::HybridProblem::schurDMPtr

Definition at line 113 of file HybridProblem.hpp.

◆ simplePtr

Simple* Fun3::HybridProblem::simplePtr

Definition at line 104 of file HybridProblem.hpp.

◆ structuresReused

bool Fun3::HybridProblem::structuresReused = false

Definition at line 107 of file HybridProblem.hpp.

◆ summary

std::array<double, 5> Fun3::HybridProblem::summary {}

Definition at line 110 of file HybridProblem.hpp.

110{};

◆ updatePrepared

bool Fun3::HybridProblem::updatePrepared = false

Definition at line 106 of file HybridProblem.hpp.


The documentation for this struct was generated from the following file: