v0.16.3
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
MoFEM::ProblemsManager Struct Reference

Problem manager is used to build and partition problems. More...

#include "src/interfaces/ProblemsManager.hpp"

Inheritance diagram for MoFEM::ProblemsManager:
[legend]
Collaboration diagram for MoFEM::ProblemsManager:
[legend]

Public Types

enum  MarkOP { OR , AND }
 

Public Member Functions

MoFEMErrorCode query_interface (boost::typeindex::type_index type_index, UnknownInterface **iface) const
 
 ProblemsManager (const MoFEM::Core &core)
 
virtual ~ProblemsManager ()=default
 
MoFEMErrorCode getOptions ()
 Get command line options for ProblemsManager.
 
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 buildProblem (const std::string name, const bool square_matrix, int verb=VERBOSE)
 build problem data structures
 
MoFEMErrorCode buildProblem (Problem *problem_ptr, const bool square_matrix, int verb=VERBOSE)
 build problem data structures
 
MoFEMErrorCode buildProblemOnDistributedMesh (const std::string name, const bool square_matrix, int verb=VERBOSE)
 build problem data structures, assuming that mesh is distributed (collective)
 
MoFEMErrorCode buildProblemOnDistributedMesh (Problem *problem_ptr, const bool square_matrix=true, int verb=VERBOSE)
 build problem data structures, assuming that mesh is distributed (collective)
 
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 buildComposedProblem (const std::string out_name, const std::vector< std::string > add_row_problems, const std::vector< std::string > add_col_problems, const bool square_matrix=true, int verb=1)
 build composite problem
 
MoFEMErrorCode inheritPartition (const std::string name, const std::string problem_for_rows, bool copy_rows, const std::string problem_for_cols, bool copy_cols, int verb=VERBOSE)
 build indexing and partition problem inheriting indexing and partitioning from two other problems
 
MoFEMErrorCode partitionSimpleProblem (const std::string name, int verb=VERBOSE)
 partition problem dofs
 
MoFEMErrorCode partitionProblem (const std::string name, int verb=VERBOSE)
 partition problem dofs (collective)
 
MoFEMErrorCode printPartitionedProblem (const Problem *problem_ptr, int verb=VERBOSE)
 Print partition information for debugging.
 
MoFEMErrorCode debugPartitionedProblem (const Problem *problem_ptr, int verb=VERBOSE)
 Debug partition information.
 
MoFEMErrorCode partitionFiniteElements (const std::string name, bool part_from_moab=false, int low_proc=-1, int hi_proc=-1, int verb=VERBOSE)
 partition finite elements
 
MoFEMErrorCode partitionGhostDofs (const std::string name, int verb=VERBOSE)
 determine ghost nodes
 
MoFEMErrorCode partitionGhostDofsOnDistributedMesh (const std::string name, int verb=VERBOSE)
 determine ghost nodes on distributed meshes
 
MoFEMErrorCode getFEMeshset (const std::string prb_name, const std::string &fe_name, EntityHandle *meshset) const
 Create finite element meshset for the problem.
 
MoFEMErrorCode getProblemElementsLayout (const std::string name, const std::string &fe_name, PetscLayout *layout) const
 Get layout of elements in the problem.
 
MoFEMErrorCode removeDofsOnEntities (const std::string problem_name, const std::string field_name, const Range ents, const int lo_coeff=0, const int hi_coeff=MAX_DOFS_ON_ENTITY, const int lo_order=0, const int hi_order=100, int verb=VERBOSE, const bool debug=false)
 Remove DOFs from problem.
 
MoFEMErrorCode removeDofsOnEntitiesNotDistributed (const std::string problem_name, const std::string field_name, const Range ents, const int lo_coeff=0, const int hi_coeff=MAX_DOFS_ON_ENTITY, const int lo_order=0, const int hi_order=100, int verb=VERBOSE, const bool debug=false)
 Remove DOFs from problem.
 
MoFEMErrorCode removeDofsOnEntities (const std::string problem_name, const std::string field_name, const BitRefLevel bit_ref_level, const BitRefLevel bit_ref_mask, Range *ents_ptr=nullptr, const int lo_coeff=0, const int hi_coeff=MAX_DOFS_ON_ENTITY, const int lo_order=0, const int hi_order=100, int verb=VERBOSE, const bool debug=false)
 Remove DOFs from problem by bit ref level.
 
MoFEMErrorCode removeDofsOnEntitiesNotDistributed (const std::string problem_name, const std::string field_name, const BitRefLevel bit_ref_level, const BitRefLevel bit_ref_mask, Range *ents_ptr=nullptr, const int lo_coeff=0, const int hi_coeff=MAX_DOFS_ON_ENTITY, const int lo_order=0, const int hi_order=100, int verb=VERBOSE, const bool debug=false)
 Remove DOFs from problem.
 
MoFEMErrorCode removeDofs (const std::string problem_name, RowColData rc, std::vector< boost::weak_ptr< NumeredDofEntity > > &vec_dof_view, int verb=VERBOSE, const bool debug=false)
 Remove DOFs from problem on broken space.
 
MoFEMErrorCode getSideDofsOnBrokenSpaceEntities (std::vector< boost::weak_ptr< NumeredDofEntity > > &vec_dof_view, const std::string problem_name, RowColData rc, const std::string field_name, const Range ents, int bridge_dim, const int lo_coeff=0, const int hi_coeff=MAX_DOFS_ON_ENTITY, const int lo_order=0, const int hi_order=100, int verb=VERBOSE, const bool debug=false) const
 Get DOFs on side entities for broken space.
 
MoFEMErrorCode markDofs (const std::string problem_name, RowColData rc, const enum MarkOP op, const Range ents, std::vector< unsigned char > &marker) const
 Create vector with marked indices.
 
DEPRECATED MoFEMErrorCode markDofs (const std::string problem_name, RowColData rc, const Range ents, std::vector< unsigned char > &marker) const
 
MoFEMErrorCode modifyMarkDofs (const std::string problem_name, RowColData rc, const std::string field_name, const int lo, const int hi, const enum MarkOP op, const unsigned char c, std::vector< unsigned char > &marker) const
 Modify DOF markers for specific field and coefficient range.
 
MoFEMErrorCode markDofs (const std::string problem_name, RowColData rc, std::vector< boost::weak_ptr< NumeredDofEntity > > &vec_dof_view, const enum MarkOP op, std::vector< unsigned char > &marker) const
 Create vector with marked DOF indices based on DOF view.
 
MoFEMErrorCode addFieldToEmptyFieldBlocks (const std::string problem_name, const std::string row_field, const std::string col_field) const
 Add empty field blocks to optimize matrix storage.
 
- Public Member Functions inherited from MoFEM::UnknownInterface
template<class IFACE >
MoFEMErrorCode registerInterface (bool error_if_registration_failed=true)
 Register interface.
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE *&iface) const
 Get interface reference to pointer of interface.
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE **const iface) const
 Get interface pointer to pointer of interface.
 
template<class IFACE , typename boost::enable_if< boost::is_pointer< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get interface pointer to pointer of interface.
 
template<class IFACE , typename boost::enable_if< boost::is_reference< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get reference to interface.
 
template<class IFACE >
IFACE * getInterface () const
 Function returning pointer to interface.
 
virtual ~UnknownInterface ()=default
 

Public Attributes

MoFEM::Core & cOre
 
PetscBool buildProblemFromFields
 
PetscBool synchroniseProblemEntities
 DOFs in fields, not from DOFs on elements.
 

Private Attributes

PetscLogEvent MOFEM_EVENT_ProblemsManager
 

Additional Inherited Members

- Static Public Member Functions inherited from MoFEM::UnknownInterface
static MoFEMErrorCode getLibVersion (Version &version)
 Get library version.
 
static MoFEMErrorCode getFileVersion (moab::Interface &moab, Version &version)
 Get database major version.
 
static MoFEMErrorCode setFileVersion (moab::Interface &moab, Version version=Version(MoFEM_VERSION_MAJOR, MoFEM_VERSION_MINOR, MoFEM_VERSION_BUILD))
 Get database major version.
 
static MoFEMErrorCode getInterfaceVersion (Version &version)
 Get database major version.
 

Detailed Description

Problem manager is used to build and partition problems.

Overview

The ProblemsManager serves as the central interface for creating, configuring, and managing finite element problems within the MoFEM framework. It acts as a bridge between the Core interface (which manages the fundamental MoFEM data structures like fields, finite elements, and DOFs) and the PETSc Discrete Manager (DM) system for parallel computing.

Connection to Core Interface

The ProblemsManager operates on top of the MoFEM::Core interface:

Integration with PETSc Discrete Manager (DM)

The ProblemsManager creates and configures PETSc DM objects:

Distributed vs Non-Distributed Meshes

Non-Distributed Meshes

Distributed Meshes <br>

Problem Types

Sub-Problems

Composite Problems

Broken DOFs (Discontinuous Spaces)

Broken DOFs support discontinuous finite element spaces:

DOF Removal Operations

DOF removal serves multiple purposes:

Boundary Condition Enforcement

Model Reduction

Numerical Efficiency

The removal process:

  1. Identification: Mark DOFs for removal based on criteria
  2. Dependency Check: Verify no essential DOFs depend on removed ones
  3. Index Renumbering: Compact DOF indices to eliminate gaps
  4. Matrix/Vector Update: Adjust PETSc data structures accordingly
  5. Solver Configuration: Update preconditioners and solver contexts

Typical Workflow

  1. Problem Definition: Define fields, finite elements, and DOFs via Core
  2. Problem Building: Use buildProblem*() to create Problem object
  3. Partitioning: Apply partition*() functions for parallel distribution
  4. Ghost Setup: Configure ghost DOFs for parallel assembly
  5. Constraint Application: Remove DOFs for boundary conditions
  6. DM Creation: Generate PETSc DM for solver integration
  7. Matrix Assembly: Use Problem for parallel finite element assembly
Examples
mofem/atom_tests/boundary_marker.cpp, mofem/atom_tests/build_composite_problem.cpp, mofem/atom_tests/build_large_problem.cpp, mofem/atom_tests/build_problems.cpp, mofem/atom_tests/child_and_parent.cpp, mofem/atom_tests/continuity_check_on_contact_prism_side_ele.cpp, mofem/atom_tests/continuity_check_on_skeleton_3d.cpp, mofem/atom_tests/forces_and_sources_testing_edge_element.cpp, mofem/atom_tests/forces_and_sources_testing_flat_prism_element.cpp, mofem/atom_tests/forces_and_sources_testing_users_base.cpp, mofem/atom_tests/hanging_node_approx.cpp, mofem/atom_tests/hcurl_divergence_operator_2d.cpp, mofem/atom_tests/mesh_insert_interface_atom.cpp, mofem/atom_tests/prism_elements_from_surface.cpp, mofem/atom_tests/prism_polynomial_approximation.cpp, mofem/atom_tests/quad_polynomial_approximation.cpp, mofem/atom_tests/remove_entities_from_problem.cpp, mofem/atom_tests/remove_entities_from_problem_not_partitioned.cpp, mofem/atom_tests/test_cache_on_entities.cpp, mofem/tools/mesh_smoothing.cpp, mofem/tutorials/adv-3_level_set/level_set.cpp, mofem/tutorials/adv-5_poroelasticity/seepage.cpp, mofem/tutorials/clx-0_acoustics/helmholtz.cpp, mofem/tutorials/cor-12_cohesive_interface/arc_length_interface.cpp, mofem/tutorials/cor-9_reaction_diffusion/reaction_diffusion.cpp, mofem/tutorials/mix-0_mixed_poisson/mixed_poisson.cpp, mofem/tutorials/scl-9_heat_method/heat_method.cpp, mofem/tutorials/vec-5_free_surface/free_surface.cpp, mofem/tutorials/vec-6_dg_kirchhoff_plate/plate.cpp, mofem/tutorials/vec-7_shape_optimisation/adjoint.cpp, mofem/users_modules/basic_finite_elements/nonlinear_elasticity/nonlinear_dynamics.cpp, and mofem/users_modules/bone_remodelling/src/impl/Remodeling.cpp.

Definition at line 133 of file ProblemsManager.hpp.

Member Enumeration Documentation

◆ MarkOP

Enumerator
OR 
AND 

Definition at line 598 of file ProblemsManager.hpp.

Constructor & Destructor Documentation

◆ ProblemsManager()

MoFEM::ProblemsManager::ProblemsManager ( const MoFEM::Core &  core)

Definition at line 55 of file ProblemsManager.cpp.

56 : cOre(const_cast<MoFEM::Core &>(core)),
57 buildProblemFromFields(PETSC_FALSE),
58 synchroniseProblemEntities(PETSC_FALSE) {
59 PetscLogEventRegister("ProblemsManager", 0, &MOFEM_EVENT_ProblemsManager);
60}
Core (interface) class.
Definition Core.hpp:83
PetscLogEvent MOFEM_EVENT_ProblemsManager
PetscBool synchroniseProblemEntities
DOFs in fields, not from DOFs on elements.

◆ ~ProblemsManager()

virtual MoFEM::ProblemsManager::~ProblemsManager ( )
virtualdefault

Member Function Documentation

◆ markDofs() [1/2]

MoFEMErrorCode MoFEM::ProblemsManager::markDofs ( const std::string  problem_name,
RowColData  rc,
const enum MarkOP  op,
const Range  ents,
std::vector< unsigned char > &  marker 
) const

Create vector with marked indices.

Vector with local DOFs marked by entities

Parameters
problem_name
row
ents
marker
Returns
MoFEMErrorCode
Examples
mofem/atom_tests/boundary_marker.cpp, mofem/atom_tests/test_cache_on_entities.cpp, and mofem/tutorials/clx-0_acoustics/helmholtz.cpp.

Definition at line 3582 of file ProblemsManager.cpp.

3584 {
3585
3586 Interface &m_field = cOre;
3587 const Problem *problem_ptr;
3589 CHKERR m_field.get_problem(problem_name, &problem_ptr);
3590 boost::shared_ptr<NumeredDofEntity_multiIndex> dofs;
3591 switch (rc) {
3592 case ROW:
3593 dofs = problem_ptr->getNumeredRowDofsPtr();
3594 break;
3595 case COL:
3596 dofs = problem_ptr->getNumeredColDofsPtr();
3597 default:
3598 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE, "Should be row or column");
3599 }
3600 marker.resize(dofs->size(), 0);
3601 std::vector<unsigned char> marker_tmp;
3602
3603 switch (op) {
3604 case MarkOP::OR:
3605 for (auto p = ents.pair_begin(); p != ents.pair_end(); ++p) {
3606 auto lo = dofs->get<Ent_mi_tag>().lower_bound(p->first);
3607 auto hi = dofs->get<Ent_mi_tag>().upper_bound(p->second);
3608 for (; lo != hi; ++lo) {
3609 if ((*lo)->getPetscLocalDofIdx() < 0)
3610 continue;
3611 marker[(*lo)->getPetscLocalDofIdx()] |= 1;
3612 }
3613 }
3614 break;
3615 case MarkOP::AND:
3616 marker_tmp.resize(dofs->size(), 0);
3617 for (auto p = ents.pair_begin(); p != ents.pair_end(); ++p) {
3618 auto lo = dofs->get<Ent_mi_tag>().lower_bound(p->first);
3619 auto hi = dofs->get<Ent_mi_tag>().upper_bound(p->second);
3620 for (; lo != hi; ++lo) {
3621 if ((*lo)->getPetscLocalDofIdx() < 0)
3622 continue;
3623 marker_tmp[(*lo)->getPetscLocalDofIdx()] = 1;
3624 }
3625 }
3626 for (int i = 0; i != marker.size(); ++i) {
3627 marker[i] &= marker_tmp[i];
3628 }
3629 break;
3630 }
3631
3633}
#define ProblemManagerFunctionBegin
@ COL
@ ROW
@ MOFEM_IMPOSSIBLE_CASE
Definition definitions.h:35
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
auto marker
set bit to marker
FTensor::Index< 'i', SPACE_DIM > i
DeprecatedCoreInterface Interface
MoFEMErrorCode get_problem(const std::string &problem_name, const Problem **problem_ptr) const
Get problem database (data structure)
Definition Core.cpp:832

◆ markDofs() [2/2]

DEPRECATED MoFEMErrorCode MoFEM::ProblemsManager::markDofs ( const std::string  problem_name,
RowColData  rc,
const Range  ents,
std::vector< unsigned char > &  marker 
) const
inline
Deprecated:
use function with MarkOP

Definition at line 620 of file ProblemsManager.hpp.

621 {
622 return markDofs(problem_name, rc, MarkOP::OR, ents, marker);
623 }
MoFEMErrorCode markDofs(const std::string problem_name, RowColData rc, const enum MarkOP op, const Range ents, std::vector< unsigned char > &marker) const
Create vector with marked indices.

◆ query_interface()

MoFEMErrorCode MoFEM::ProblemsManager::query_interface ( boost::typeindex::type_index  type_index,
UnknownInterface **  iface 
) const
virtual

Implements MoFEM::UnknownInterface.

Definition at line 49 of file ProblemsManager.cpp.

50 {
51 *iface = const_cast<ProblemsManager *>(this);
52 return 0;
53}
ProblemsManager(const MoFEM::Core &core)

◆ removeDofsOnEntitiesNotDistributed() [1/2]

MoFEMErrorCode MoFEM::ProblemsManager::removeDofsOnEntitiesNotDistributed ( const std::string  problem_name,
const std::string  field_name,
const BitRefLevel  bit_ref_level,
const BitRefLevel  bit_ref_mask,
Range *  ents_ptr = nullptr,
const int  lo_coeff = 0,
const int  hi_coeff = MAX_DOFS_ON_ENTITY,
const int  lo_order = 0,
const int  hi_order = 100,
int  verb = VERBOSE,
const bool  debug = false 
)

Remove DOFs from problem.

Remove DOFs from problem which are on entities on the given range and given field name. On the finite element level, DOFs can be still accessed however local PETSc indices and global PETSc indices are marked with the index -1.

Note
If the index is marked -1 it is not assembled and dropped by VecSetValues and MatSetValues.
Todo:
Not yet implemented update for AO maps and IS ranges if removed entities in composite problem or sub-problem
Parameters
problem_namename of the problem
field_namename of the field
entsentities on which DOFs are removed
lo_coefflow dof coefficient (rank)
hi_coeffhigh dof coefficient (rank)
verbverbosity level
debugto debug and seek for inconsistencies set to true
Returns
MoFEMErrorCode
Note
Use this function for non distributed meshes

Definition at line 3554 of file ProblemsManager.cpp.

3558 {
3559 MoFEM::Interface &m_field = cOre;
3561
3562 auto bit_manager = m_field.getInterface<BitRefManager>();
3563
3564 Range ents;
3565 if (ents_ptr) {
3566 ents = *ents_ptr;
3567 CHKERR bit_manager->filterEntitiesByRefLevel(bit_ref_level, bit_ref_mask,
3568 ents, verb);
3569 } else {
3570 CHKERR bit_manager->getEntitiesByRefLevel(bit_ref_level, bit_ref_mask, ents,
3571 verb);
3572 }
3573
3575 lo_coeff, hi_coeff, lo_order,
3576 hi_order, verb, debug);
3577
3579}
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
static const bool debug
constexpr auto field_name
Deprecated interface functions.
MoFEMErrorCode removeDofsOnEntitiesNotDistributed(const std::string problem_name, const std::string field_name, const Range ents, const int lo_coeff=0, const int hi_coeff=MAX_DOFS_ON_ENTITY, const int lo_order=0, const int hi_order=100, int verb=VERBOSE, const bool debug=false)
Remove DOFs from problem.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.

◆ removeDofsOnEntitiesNotDistributed() [2/2]

MoFEMErrorCode MoFEM::ProblemsManager::removeDofsOnEntitiesNotDistributed ( const std::string  problem_name,
const std::string  field_name,
const Range  ents,
const int  lo_coeff = 0,
const int  hi_coeff = MAX_DOFS_ON_ENTITY,
const int  lo_order = 0,
const int  hi_order = 100,
int  verb = VERBOSE,
const bool  debug = false 
)

Remove DOFs from problem.

Remove DOFs from problem which are on entities on the given range and given field name. On the finite element level, DOFs can be still accessed however local PETSc indices and global PETSc indices are marked with the index -1.

Note
If the index is marked -1 it is not assembled and dropped by VecSetValues and MatSetValues.
Todo:
Not yet implemented update for AO maps and IS ranges if removed entities in composite problem or sub-problem
Parameters
problem_namename of the problem
field_namename of the field
entsentities on which DOFs are removed
lo_coefflow dof coefficient (rank)
hi_coeffhigh dof coefficient (rank)
verbverbosity level
debugto debug and seek for inconsistencies set to true
Returns
MoFEMErrorCode
Note
Use this function for non-distributed meshes
Examples
mofem/atom_tests/remove_entities_from_problem_not_partitioned.cpp.

Definition at line 3254 of file ProblemsManager.cpp.

3257 {
3258
3259 MoFEM::Interface &m_field = cOre;
3261
3262 const Problem *prb_ptr;
3263 CHKERR m_field.get_problem(problem_name, &prb_ptr);
3264
3265 decltype(prb_ptr->numeredRowDofsPtr) numered_dofs[2] = {
3266 prb_ptr->numeredRowDofsPtr, nullptr};
3267 if (prb_ptr->numeredRowDofsPtr != prb_ptr->numeredColDofsPtr)
3268 numered_dofs[1] = prb_ptr->numeredColDofsPtr;
3269
3270 int *nbdof_ptr[] = {&prb_ptr->nbDofsRow, &prb_ptr->nbDofsCol};
3271 int *local_nbdof_ptr[] = {&prb_ptr->nbLocDofsRow, &prb_ptr->nbLocDofsCol};
3272 int *ghost_nbdof_ptr[] = {&prb_ptr->nbGhostDofsRow, &prb_ptr->nbGhostDofsCol};
3273
3274 const int nb_init_row_dofs = prb_ptr->getNbDofsRow();
3275 const int nb_init_col_dofs = prb_ptr->getNbDofsCol();
3276 const int nb_init_loc_row_dofs = prb_ptr->getNbLocalDofsRow();
3277 // const int nb_init_loc_col_dofs = prb_ptr->getNbLocalDofsCol();
3278 const int nb_init_ghost_row_dofs = prb_ptr->getNbGhostDofsRow();
3279 const int nb_init_ghost_col_dofs = prb_ptr->getNbGhostDofsCol();
3280
3281 const std::array<int, 2> nb_init_dofs = {nb_init_row_dofs, nb_init_col_dofs};
3282
3283 for (int s = 0; s != 2; ++s)
3284 if (numered_dofs[s]) {
3285
3286 typedef multi_index_container<
3287
3288 NumeredDofEntity_multiIndex::iterator, indexed_by<sequenced<>>
3289
3290 >
3291 NumeredDofEntity_it_view_multiIndex;
3292
3293 const auto bit_number = m_field.get_field_bit_number(field_name);
3294 NumeredDofEntity_it_view_multiIndex dofs_it_view;
3295
3296 // Set -1 to global and local dofs indices
3297 for (auto pit = ents.const_pair_begin(); pit != ents.const_pair_end();
3298 ++pit) {
3299 auto lo = numered_dofs[s]->get<Unique_mi_tag>().lower_bound(
3300 DofEntity::getLoFieldEntityUId(bit_number, pit->first));
3301 auto hi = numered_dofs[s]->get<Unique_mi_tag>().upper_bound(
3302 DofEntity::getHiFieldEntityUId(bit_number, pit->second));
3303
3304 for (; lo != hi; ++lo)
3305 if ((*lo)->getDofCoeffIdx() >= lo_coeff &&
3306 (*lo)->getDofCoeffIdx() <= hi_coeff &&
3307 (*lo)->getDofOrder() >= lo_order &&
3308 (*lo)->getDofOrder() <= hi_order)
3309 dofs_it_view.emplace_back(numered_dofs[s]->project<0>(lo));
3310 }
3311
3312 if (verb > QUIET) {
3313 for (auto &dof : dofs_it_view)
3314 MOFEM_LOG("SYNC", Sev::noisy) << **dof;
3315 }
3316
3317 // set negative index
3318 auto mod = NumeredDofEntity_part_and_all_indices_change(-1, -1, -1, -1);
3319 for (auto dit : dofs_it_view) {
3320 bool success = numered_dofs[s]->modify(dit, mod);
3321 if (!success)
3322 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
3323 "can not set negative indices");
3324 }
3325
3326 // create weak view
3327 std::vector<boost::weak_ptr<NumeredDofEntity>> dosf_weak_view;
3328 dosf_weak_view.reserve(dofs_it_view.size());
3329 for (auto dit : dofs_it_view)
3330 dosf_weak_view.push_back(*dit);
3331
3332 if (verb >= NOISY)
3333 MOFEM_LOG_C("SYNC", Sev::noisy,
3334 "Number of DOFs in multi-index %zu and to delete %zu\n",
3335 numered_dofs[s]->size(), dofs_it_view.size());
3336
3337 // erase dofs from problem
3338 for (auto weak_dit : dosf_weak_view)
3339 if (auto dit = weak_dit.lock()) {
3340 numered_dofs[s]->erase(dit->getLocalUniqueId());
3341 }
3342
3343 if (verb >= NOISY)
3344 MOFEM_LOG_C("SYNC", Sev::noisy,
3345 "Number of DOFs in multi-index after delete %zu\n",
3346 numered_dofs[s]->size());
3347
3348 // get current number of ghost dofs
3349 int nb_global_dof = 0;
3350 int nb_local_dofs = 0;
3351 int nb_ghost_dofs = 0;
3352
3353 for (auto dit = numered_dofs[s]->begin(); dit != numered_dofs[s]->end();
3354 ++dit) {
3355
3356 if ((*dit)->getDofIdx() >= 0) {
3357
3358 if ((*dit)->getPetscLocalDofIdx() >= 0 &&
3359 (*dit)->getPetscLocalDofIdx() < *(local_nbdof_ptr[s]))
3360 ++nb_local_dofs;
3361 else if ((*dit)->getPetscLocalDofIdx() >= *(local_nbdof_ptr[s]))
3362 ++nb_ghost_dofs;
3363
3364 ++nb_global_dof;
3365 }
3366 }
3367
3368 if (debug) {
3369 MPI_Allreduce(&nb_local_dofs, nbdof_ptr[s], 1, MPI_INT, MPI_SUM,
3370 m_field.get_comm());
3371 if (*(nbdof_ptr[s]) != nb_global_dof)
3372 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
3373 "Number of local DOFs do not add up %d != %d",
3374 *(nbdof_ptr[s]), nb_global_dof);
3375 }
3376
3377 *(nbdof_ptr[s]) = nb_global_dof;
3378 *(local_nbdof_ptr[s]) = nb_local_dofs;
3379 *(ghost_nbdof_ptr[s]) = nb_ghost_dofs;
3380
3381 // get indices
3382 auto get_indices_by_tag = [&](auto tag) {
3383 std::vector<int> indices;
3384 indices.resize(nb_init_dofs[s], -1);
3385 for (auto dit = numered_dofs[s]->get<Idx_mi_tag>().lower_bound(0);
3386 dit != numered_dofs[s]->get<Idx_mi_tag>().end(); ++dit) {
3387 indices[(*dit)->getDofIdx()] = decltype(tag)::get_index(dit);
3388 }
3389 return indices;
3390 };
3391
3392 auto renumber = [&](auto tag, auto &indices) {
3394 int idx = 0;
3395 for (auto dit = numered_dofs[s]->get<decltype(tag)>().lower_bound(0);
3396 dit != numered_dofs[s]->get<decltype(tag)>().end(); ++dit) {
3397 indices[(*dit)->getDofIdx()] = idx++;
3398 }
3400 };
3401
3402 auto get_sub_ao = [&](auto sub_data) {
3403 if (s == 0) {
3404 return sub_data->getSmartRowMap();
3405 } else {
3406 return sub_data->getSmartColMap();
3407 }
3408 };
3409
3410 auto set_sub_is_and_ao = [&s, &prb_ptr](auto sub_data, auto is, auto ao) {
3411 if (s == 0) {
3412 sub_data->rowIs = is;
3413 sub_data->rowMap = ao;
3414 if (prb_ptr->numeredRowDofsPtr == prb_ptr->numeredColDofsPtr) {
3415 sub_data->colIs = is;
3416 sub_data->colMap = ao;
3417 }
3418 } else {
3419 sub_data->colIs = is;
3420 sub_data->colMap = ao;
3421 }
3422 };
3423
3424 auto apply_symmetry = [&s, &prb_ptr](auto sub_data) {
3425 if (s == 0) {
3426 if (prb_ptr->numeredRowDofsPtr == prb_ptr->numeredColDofsPtr) {
3427 sub_data->colIs = sub_data->getSmartRowIs();
3428 sub_data->colMap = sub_data->getSmartRowMap();
3429 }
3430 }
3431 };
3432
3433 auto set_sub_data = [&](auto &indices) {
3435 auto indices_ptr = [](auto &indices) {
3436 return indices.empty() ? nullptr : indices.data();
3437 };
3438 if (auto sub_data = prb_ptr->getSubData()) {
3439 // create is and then map it to main problem of sub-problem
3440 auto sub_is = createISGeneral(m_field.get_comm(), indices.size(),
3441 indices_ptr(indices), PETSC_COPY_VALUES);
3442 // get old app, i.e. oroginal befor sub indices, and ao, from
3443 // app, to petsc sub indices.
3444 auto sub_ao = get_sub_ao(sub_data);
3445 if (sub_ao.get())
3446 CHKERR AOPetscToApplicationIS(sub_ao, sub_is);
3447 sub_ao = createAOMappingIS(sub_is, PETSC_NULLPTR);
3448 // set new sub ao
3449 set_sub_is_and_ao(sub_data, sub_is, sub_ao);
3450 apply_symmetry(sub_data);
3451 } else {
3452 prb_ptr->getSubData() = boost::make_shared<Problem::SubProblemData>();
3453 auto sub_is = createISGeneral(m_field.get_comm(), indices.size(),
3454 indices_ptr(indices), PETSC_COPY_VALUES);
3455 auto sub_ao = createAOMappingIS(sub_is, PETSC_NULLPTR);
3456 // set sub is ao
3457 set_sub_is_and_ao(prb_ptr->getSubData(), sub_is, sub_ao);
3458 apply_symmetry(prb_ptr->getSubData());
3459 }
3461 };
3462
3463 auto global_indices = get_indices_by_tag(PetscGlobalIdx_mi_tag());
3464 auto local_indices = get_indices_by_tag(PetscLocalIdx_mi_tag());
3465 CHKERR set_sub_data(global_indices);
3466 CHKERR renumber(PetscGlobalIdx_mi_tag(), global_indices);
3467 CHKERR renumber(PetscLocalIdx_mi_tag(), local_indices);
3468
3469 int i = 0;
3470 for (auto dit = numered_dofs[s]->begin(); dit != numered_dofs[s]->end();
3471 ++dit) {
3472 auto idx = (*dit)->getDofIdx();
3473 if (idx >= 0) {
3474 auto mod = NumeredDofEntity_part_and_all_indices_change(
3475 (*dit)->getPart(), i++, global_indices[idx], local_indices[idx]);
3476 bool success = numered_dofs[s]->modify(dit, mod);
3477 if (!success)
3478 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
3479 "can not set negative indices");
3480 } else {
3481 auto mod = NumeredDofEntity_part_and_all_indices_change(
3482 (*dit)->getPart(), -1, -1, -1);
3483 bool success = numered_dofs[s]->modify(dit, mod);
3484 if (!success)
3485 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
3486 "can not set negative indices");
3487 }
3488 };
3489
3490 if (debug) {
3491 for (auto dof : (*numered_dofs[s])) {
3492 if (dof->getDofIdx() >= 0 && dof->getPetscGlobalDofIdx() < 0) {
3493 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
3494 "Negative global idx");
3495 }
3496 }
3497 }
3498
3499 } else {
3500
3501 *(nbdof_ptr[1]) = *(nbdof_ptr[0]);
3502 *(local_nbdof_ptr[1]) = *(local_nbdof_ptr[0]);
3503 *(ghost_nbdof_ptr[1]) = *(ghost_nbdof_ptr[0]);
3504 }
3505
3506 if (verb >= NOISY)
3508
3509 if (verb > QUIET) {
3511 "WORLD", Sev::inform,
3512 "Removed DOFs from problem %s dofs [%d / %d (before %d / %d) global]",
3513 prb_ptr->getName().c_str(), prb_ptr->getNbDofsRow(),
3514 prb_ptr->getNbDofsCol(), nb_init_row_dofs, nb_init_col_dofs);
3515 MOFEM_LOG_C("SYNC", Sev::verbose,
3516 "Removed DOFs from problem %s dofs [ %d / %d "
3517 "(before %d / %d) local, %d / %d (before %d / %d)]",
3518 prb_ptr->getName().c_str(), prb_ptr->getNbLocalDofsRow(),
3519 prb_ptr->getNbLocalDofsCol(), nb_init_loc_row_dofs,
3520 nb_init_loc_row_dofs, prb_ptr->getNbGhostDofsRow(),
3521 prb_ptr->getNbGhostDofsCol(), nb_init_ghost_row_dofs,
3522 nb_init_ghost_col_dofs);
3524 }
3526}
#define MOFEM_LOG_SYNCHRONISE(comm)
Synchronise "SYNC" channel.
#define MOFEM_LOG_C(channel, severity, format,...)
PetscInt size
@ QUIET
@ NOISY
@ MOFEM_OPERATION_UNSUCCESSFUL
Definition definitions.h:34
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
#define MOFEM_LOG(channel, severity)
Log.
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 createAOMappingIS(IS isapp, IS ispetsc)
Creates an application mapping using two index sets.
MoFEM::LogManager::SeverityLevel Sev
virtual FieldBitNumber get_field_bit_number(const std::string name) const =0
get field bit number
virtual MPI_Comm & get_comm() const =0
static UId getLoFieldEntityUId(const FieldBitNumber bit, const EntityHandle ent)
static UId getHiFieldEntityUId(const FieldBitNumber bit, const EntityHandle ent)
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredRowDofsPtr
store DOFs on rows for this problem

Member Data Documentation

◆ buildProblemFromFields

PetscBool MoFEM::ProblemsManager::buildProblemFromFields

If set to true, problem is build from

Definition at line 142 of file ProblemsManager.hpp.

◆ cOre

MoFEM::Core& MoFEM::ProblemsManager::cOre

Definition at line 138 of file ProblemsManager.hpp.

◆ MOFEM_EVENT_ProblemsManager

PetscLogEvent MoFEM::ProblemsManager::MOFEM_EVENT_ProblemsManager
private

Definition at line 688 of file ProblemsManager.hpp.

◆ synchroniseProblemEntities

PetscBool MoFEM::ProblemsManager::synchroniseProblemEntities

DOFs in fields, not from DOFs on elements.

Definition at line 145 of file ProblemsManager.hpp.


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