v0.13.1
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 ()
 
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. More...
 
MoFEMErrorCode buildProblem (const std::string name, const bool square_matrix, int verb=VERBOSE)
 build problem data structures More...
 
MoFEMErrorCode buildProblem (Problem *problem_ptr, const bool square_matrix, int verb=VERBOSE)
 build problem data structures More...
 
MoFEMErrorCode buildProblemOnDistributedMesh (const std::string name, const bool square_matrix, int verb=VERBOSE)
 build problem data structures, assuming that mesh is distributed (collective) More...
 
MoFEMErrorCode buildProblemOnDistributedMesh (Problem *problem_ptr, const bool square_matrix=true, int verb=VERBOSE)
 build problem data structures, assuming that mesh is distributed (collective) More...
 
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, std::pair< EntityType, EntityType > > *entityMapRow=nullptr, const map< std::string, std::pair< EntityType, EntityType > > *entityMapCol=nullptr, int verb=VERBOSE)
 build sub problem More...
 
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 More...
 
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 More...
 
MoFEMErrorCode partitionSimpleProblem (const std::string name, int verb=VERBOSE)
 partition problem dofs More...
 
MoFEMErrorCode partitionProblem (const std::string name, int verb=VERBOSE)
 partition problem dofs (collective) More...
 
MoFEMErrorCode printPartitionedProblem (const Problem *problem_ptr, int verb=VERBOSE)
 
MoFEMErrorCode debugPartitionedProblem (const Problem *problem_ptr, int verb=VERBOSE)
 
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 More...
 
MoFEMErrorCode partitionGhostDofs (const std::string name, int verb=VERBOSE)
 determine ghost nodes More...
 
MoFEMErrorCode partitionGhostDofsOnDistributedMesh (const std::string name, int verb=VERBOSE)
 determine ghost nodes on distributed meshes More...
 
MoFEMErrorCode getFEMeshset (const std::string prb_name, const std::string fe_name, EntityHandle *meshset) const
 create add entities of finite element in the problem More...
 
MoFEMErrorCode getProblemElementsLayout (const std::string name, const std::string fe_name, PetscLayout *layout) const
 Get layout of elements in the problem. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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
 Mark DOFs. More...
 
MoFEMErrorCode addFieldToEmptyFieldBlocks (const std::string problem_name, const std::string row_field, const std::string col_field) const
 add empty block to problem More...
 
- Public Member Functions inherited from MoFEM::UnknownInterface
virtual MoFEMErrorCode query_interface (boost::typeindex::type_index type_index, UnknownInterface **iface) const =0
 
template<class IFACE >
MoFEMErrorCode registerInterface (bool error_if_registration_failed=true)
 Register interface. More...
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE *&iface) const
 Get interface refernce to pointer of interface. More...
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE **const iface) const
 Get interface pointer to pointer of interface. More...
 
template<class IFACE , typename boost::enable_if< boost::is_pointer< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get interface pointer to pointer of interface. More...
 
template<class IFACE , typename boost::enable_if< boost::is_reference< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get reference to interface. More...
 
template<class IFACE >
IFACE * getInterface () const
 Function returning pointer to interface. More...
 
virtual ~UnknownInterface ()=default
 

Public Attributes

MoFEM::CorecOre
 
PetscBool buildProblemFromFields
 
PetscBool synchroniseProblemEntities
 DOFs in fields, not from DOFs on elements. More...
 

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. More...
 
static MoFEMErrorCode getFileVersion (moab::Interface &moab, Version &version)
 Get database major version. More...
 
static MoFEMErrorCode setFileVersion (moab::Interface &moab, Version version=Version(MoFEM_VERSION_MAJOR, MoFEM_VERSION_MINOR, MoFEM_VERSION_BUILD))
 Get database major version. More...
 
static MoFEMErrorCode getInterfaceVersion (Version &version)
 Get database major version. More...
 

Detailed Description

Problem manager is used to build and partition problems.

Examples
EshelbianPlasticity.cpp, Remodeling.cpp, boundary_marker.cpp, build_large_problem.cpp, build_problems.cpp, child_and_parent.cpp, continuity_check_on_contact_prism_side_ele.cpp, continuity_check_on_skeleton_3d.cpp, forces_and_sources_testing_edge_element.cpp, forces_and_sources_testing_flat_prism_element.cpp, forces_and_sources_testing_users_base.cpp, hanging_node_approx.cpp, hcurl_divergence_operator_2d.cpp, heat_method.cpp, helmholtz.cpp, mesh_insert_interface_atom.cpp, mixed_poisson.cpp, nonlinear_dynamics.cpp, photon_diffusion.cpp, plastic.cpp, plate.cpp, poisson_2d_homogeneous.cpp, prism_elements_from_surface.cpp, prism_polynomial_approximation.cpp, quad_polynomial_approximation.cpp, reaction_diffusion.cpp, remove_entities_from_problem.cpp, remove_entities_from_problem_not_partitioned.cpp, and test_cache_on_entities.cpp.

Definition at line 21 of file ProblemsManager.hpp.

Member Enumeration Documentation

◆ MarkOP

Enumerator
OR 
AND 

Definition at line 367 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:82
PetscLogEvent MOFEM_EVENT_ProblemsManager
PetscBool synchroniseProblemEntities
DOFs in fields, not from DOFs on elements.

◆ ~ProblemsManager()

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

Member Function Documentation

◆ addFieldToEmptyFieldBlocks()

MoFEMErrorCode MoFEM::ProblemsManager::addFieldToEmptyFieldBlocks ( const std::string  problem_name,
const std::string  row_field,
const std::string  col_field 
) const

add empty block to problem

MatrixManager assumes that all blocks, i.e. all fields combinations are non zero. This is not always the case, to optimise code and reduce memory usage user can specifi which blocks are empty.

Parameters
problem_nameproblem name
row_fieldrow filed name
col_fieldcol field name
Returns
MoFEMErrorCode

Definition at line 3180 of file ProblemsManager.cpp.

3182 {
3183
3184 Interface &m_field = cOre;
3186
3187 const auto problem_ptr = m_field.get_problem(problem_name);
3188 auto get_field_id = [&](const std::string field_name) {
3189 return m_field.get_field_structure(field_name)->getId();
3190 };
3191 const auto row_id = get_field_id(row_field);
3192 const auto col_id = get_field_id(col_field);
3193
3194 problem_ptr->addFieldToEmptyFieldBlocks(EmptyFieldBlocks(row_id, col_id));
3195
3197}
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
Problem::EmptyFieldBlocks EmptyFieldBlocks
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1955
constexpr auto field_name

◆ debugPartitionedProblem()

MoFEMErrorCode MoFEM::ProblemsManager::debugPartitionedProblem ( const Problem problem_ptr,
int  verb = VERBOSE 
)

Definition at line 2074 of file ProblemsManager.cpp.

2074 {
2075 MoFEM::Interface &m_field = cOre;
2077
2078 auto save_ent = [](moab::Interface &moab, const std::string name,
2079 const EntityHandle ent) {
2081 EntityHandle out_meshset;
2082 CHKERR moab.create_meshset(MESHSET_SET, out_meshset);
2083 CHKERR moab.add_entities(out_meshset, &ent, 1);
2084 CHKERR moab.write_file(name.c_str(), "VTK", "", &out_meshset, 1);
2085 CHKERR moab.delete_entities(&out_meshset, 1);
2087 };
2088
2089 if (debug > 0) {
2090
2091 typedef NumeredDofEntity_multiIndex::index<Idx_mi_tag>::type
2092 NumeredDofEntitysByIdx;
2093 NumeredDofEntitysByIdx::iterator dit, hi_dit;
2094 const NumeredDofEntitysByIdx *numered_dofs_ptr[] = {
2095 &(problem_ptr->numeredRowDofsPtr->get<Idx_mi_tag>()),
2096 &(problem_ptr->numeredColDofsPtr->get<Idx_mi_tag>())};
2097
2098 int *nbdof_ptr[] = {&problem_ptr->nbDofsRow, &problem_ptr->nbDofsCol};
2099 int *local_nbdof_ptr[] = {&problem_ptr->nbLocDofsRow,
2100 &problem_ptr->nbLocDofsCol};
2101
2102 for (int ss = 0; ss < 2; ss++) {
2103
2104 dit = numered_dofs_ptr[ss]->begin();
2105 hi_dit = numered_dofs_ptr[ss]->end();
2106 for (; dit != hi_dit; dit++) {
2107 if ((*dit)->getPart() == (unsigned int)m_field.get_comm_rank()) {
2108 if ((*dit)->getPetscLocalDofIdx() < 0) {
2109 std::ostringstream zz;
2110 zz << "rank " << m_field.get_comm_rank() << " " << **dit;
2111 SETERRQ2(PETSC_COMM_SELF, MOFEM_IMPOSIBLE_CASE,
2112 "local dof index for %d (0-row, 1-col) not set, i.e. has "
2113 "negative value\n %s",
2114 ss, zz.str().c_str());
2115 }
2116 if ((*dit)->getPetscLocalDofIdx() >= *local_nbdof_ptr[ss]) {
2117 std::ostringstream zz;
2118 zz << "rank " << m_field.get_comm_rank() << " " << **dit;
2119 SETERRQ2(PETSC_COMM_SELF, MOFEM_IMPOSIBLE_CASE,
2120 "local dofs for %d (0-row, 1-col) out of range\n %s", ss,
2121 zz.str().c_str());
2122 }
2123 } else {
2124 if ((*dit)->getPetscGlobalDofIdx() < 0) {
2125
2126 const EntityHandle ent = (*dit)->getEnt();
2127 CHKERR save_ent(
2128 m_field.get_moab(),
2129 "debug_part" +
2130 boost::lexical_cast<std::string>(m_field.get_comm_rank()) +
2131 "_negative_global_index.vtk",
2132 ent);
2133
2134 std::ostringstream zz;
2135 zz << "rank " << m_field.get_comm_rank() << " "
2136 << dit->get()->getBitRefLevel() << " " << **dit;
2137 SETERRQ2(PETSC_COMM_SELF, MOFEM_IMPOSIBLE_CASE,
2138 "global dof index for %d (0-row, 1-col) row not set, i.e. "
2139 "has negative value\n %s",
2140 ss, zz.str().c_str());
2141 }
2142 if ((*dit)->getPetscGlobalDofIdx() >= *nbdof_ptr[ss]) {
2143 std::ostringstream zz;
2144 zz << "rank " << m_field.get_comm_rank() << " nb_dofs "
2145 << *nbdof_ptr[ss] << " " << **dit;
2146 SETERRQ2(PETSC_COMM_SELF, MOFEM_IMPOSIBLE_CASE,
2147 "global dofs for %d (0-row, 1-col) out of range\n %s", ss,
2148 zz.str().c_str());
2149 }
2150 }
2151 }
2152 }
2153 }
2155}
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
@ MOFEM_IMPOSIBLE_CASE
Definition: definitions.h:35
#define CHKERR
Inline error check.
Definition: definitions.h:535
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
static const bool debug
virtual moab::Interface & get_moab()=0
virtual int get_comm_rank() const =0
Deprecated interface functions.

◆ getOptions()

MoFEMErrorCode MoFEM::ProblemsManager::getOptions ( )

Definition at line 62 of file ProblemsManager.cpp.

62 {
63 MoFEM::Interface &m_field = cOre;
65 CHKERR PetscOptionsBegin(m_field.get_comm(), "", "Problem manager", "none");
66 {
67 CHKERR PetscOptionsBool(
68 "-problem_build_from_fields",
69 "Add DOFs to problem directly from fields not through DOFs on elements",
71 }
72 ierr = PetscOptionsEnd();
75}
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:483
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:76
virtual MPI_Comm & get_comm() const =0

◆ 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
helmholtz.cpp, and test_cache_on_entities.cpp.

Definition at line 3084 of file ProblemsManager.cpp.

3086 {
3087
3088 Interface &m_field = cOre;
3089 const Problem *problem_ptr;
3091 CHKERR m_field.get_problem(problem_name, &problem_ptr);
3092 boost::shared_ptr<NumeredDofEntity_multiIndex> dofs;
3093 switch (rc) {
3094 case ROW:
3095 dofs = problem_ptr->getNumeredRowDofsPtr();
3096 break;
3097 case COL:
3098 dofs = problem_ptr->getNumeredColDofsPtr();
3099 default:
3100 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSIBLE_CASE, "Should be row or column");
3101 }
3102 marker.resize(dofs->size(), 0);
3103 std::vector<unsigned char> marker_tmp;
3104
3105 switch (op) {
3106 case MarkOP::OR:
3107 for (auto p = ents.pair_begin(); p != ents.pair_end(); ++p) {
3108 auto lo = dofs->get<Ent_mi_tag>().lower_bound(p->first);
3109 auto hi = dofs->get<Ent_mi_tag>().upper_bound(p->second);
3110 for (; lo != hi; ++lo)
3111 marker[(*lo)->getPetscLocalDofIdx()] |= 1;
3112 }
3113 break;
3114 case MarkOP::AND:
3115 marker_tmp.resize(dofs->size(), 0);
3116 for (auto p = ents.pair_begin(); p != ents.pair_end(); ++p) {
3117 auto lo = dofs->get<Ent_mi_tag>().lower_bound(p->first);
3118 auto hi = dofs->get<Ent_mi_tag>().upper_bound(p->second);
3119 for (; lo != hi; ++lo)
3120 marker_tmp[(*lo)->getPetscLocalDofIdx()] = 1;
3121 }
3122 for (int i = 0; i != marker.size(); ++i) {
3123 marker[i] &= marker_tmp[i];
3124 }
3125 break;
3126 }
3127
3129}
static Index< 'p', 3 > p
#define ProblemManagerFunctionBegin
@ COL
Definition: definitions.h:123
@ ROW
Definition: definitions.h:123
auto marker
set bit to marker
FTensor::Index< 'i', SPACE_DIM > i

◆ 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 389 of file ProblemsManager.hpp.

390 {
391 return markDofs(problem_name, rc, MarkOP::OR, ents, marker);
392 }
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.

◆ modifyMarkDofs()

MoFEMErrorCode MoFEM::ProblemsManager::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

Mark DOFs.

Parameters
problem_name
rc
field_name
lo
hi
op
marker
Returns
MoFEMErrorCode

Definition at line 3131 of file ProblemsManager.cpp.

3134 {
3135
3136 Interface &m_field = cOre;
3137 const Problem *problem_ptr;
3139 CHKERR m_field.get_problem(problem_name, &problem_ptr);
3140 boost::shared_ptr<NumeredDofEntity_multiIndex> dofs;
3141 switch (rc) {
3142 case ROW:
3143 dofs = problem_ptr->getNumeredRowDofsPtr();
3144 break;
3145 case COL:
3146 dofs = problem_ptr->getNumeredColDofsPtr();
3147 default:
3148 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSIBLE_CASE, "Should be row or column");
3149 }
3150 marker.resize(dofs->size(), 0);
3151
3152 auto dof_lo = dofs->get<Unique_mi_tag>().lower_bound(
3153 FieldEntity::getLoBitNumberUId(m_field.get_field_bit_number(field_name)));
3154 auto dof_hi = dofs->get<Unique_mi_tag>().upper_bound(
3155 FieldEntity::getHiBitNumberUId(m_field.get_field_bit_number(field_name)));
3156
3157 auto marker_ref = [marker](auto &it) -> unsigned int & {
3158 return marker[(*it)->getPetscLocalDofIdx()];
3159 };
3160
3161 switch (op) {
3162 case MarkOP::OR:
3163 for (; dof_lo != dof_hi; ++dof_lo)
3164 if ((*dof_lo)->getDofCoeffIdx() >= lo &&
3165 (*dof_lo)->getDofCoeffIdx() <= hi)
3166 marker[(*dof_lo)->getPetscLocalDofIdx()] |= c;
3167 break;
3168 case MarkOP::AND:
3169 for (; dof_lo != dof_hi; ++dof_lo)
3170 if ((*dof_lo)->getDofCoeffIdx() >= lo &&
3171 (*dof_lo)->getDofCoeffIdx() <= hi)
3172 marker[(*dof_lo)->getPetscLocalDofIdx()] &= c;
3173 break;
3174 }
3175
3177}
const double c
speed of light (cm/ns)
static UId getHiBitNumberUId(const FieldBitNumber bit_number)
static UId getLoBitNumberUId(const FieldBitNumber bit_number)

◆ printPartitionedProblem()

MoFEMErrorCode MoFEM::ProblemsManager::printPartitionedProblem ( const Problem problem_ptr,
int  verb = VERBOSE 
)

Definition at line 2055 of file ProblemsManager.cpp.

2055 {
2056 MoFEM::Interface &m_field = cOre;
2058
2059 if (verb > QUIET) {
2060
2061 MOFEM_LOG("SYNC", Sev::inform)
2062 << problem_ptr->getName() << " Nb. local dof "
2063 << problem_ptr->getNbLocalDofsRow() << " by "
2064 << problem_ptr->getNbLocalDofsCol() << " nb global dofs "
2065 << problem_ptr->getNbDofsRow() << " by " << problem_ptr->getNbDofsCol();
2066
2068 }
2069
2071}
#define MOFEM_LOG_SYNCHRONISE(comm)
Synchronise "SYNC" channel.
Definition: LogManager.hpp:338
@ QUIET
Definition: definitions.h:208
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:301

◆ 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 nondistributed meshes

Definition at line 3056 of file ProblemsManager.cpp.

3060 {
3061 MoFEM::Interface &m_field = cOre;
3063
3064 auto bit_manager = m_field.getInterface<BitRefManager>();
3065
3066 Range ents;
3067 if (ents_ptr) {
3068 ents = *ents_ptr;
3069 CHKERR bit_manager->filterEntitiesByRefLevel(bit_ref_level, bit_ref_mask,
3070 ents, verb);
3071 } else {
3072 CHKERR bit_manager->getEntitiesByRefLevel(bit_ref_level, bit_ref_mask, ents,
3073 verb);
3074 }
3075
3077 lo_coeff, hi_coeff, lo_order,
3078 hi_order, verb, debug);
3079
3081}
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 refernce 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 nondistributed meshes
Examples
remove_entities_from_problem_not_partitioned.cpp.

Definition at line 2811 of file ProblemsManager.cpp.

2814 {
2815
2816 MoFEM::Interface &m_field = cOre;
2818
2819 const Problem *prb_ptr;
2820 CHKERR m_field.get_problem(problem_name, &prb_ptr);
2821
2822 decltype(prb_ptr->numeredRowDofsPtr) numered_dofs[2] = {
2823 prb_ptr->numeredRowDofsPtr, nullptr};
2824 if (prb_ptr->numeredRowDofsPtr != prb_ptr->numeredColDofsPtr)
2825 numered_dofs[1] = prb_ptr->numeredColDofsPtr;
2826
2827 int *nbdof_ptr[] = {&prb_ptr->nbDofsRow, &prb_ptr->nbDofsCol};
2828 int *local_nbdof_ptr[] = {&prb_ptr->nbLocDofsRow, &prb_ptr->nbLocDofsCol};
2829 int *ghost_nbdof_ptr[] = {&prb_ptr->nbGhostDofsRow, &prb_ptr->nbGhostDofsCol};
2830
2831 const int nb_init_row_dofs = prb_ptr->getNbDofsRow();
2832 const int nb_init_col_dofs = prb_ptr->getNbDofsCol();
2833 const int nb_init_loc_row_dofs = prb_ptr->getNbLocalDofsRow();
2834 const int nb_init_loc_col_dofs = prb_ptr->getNbLocalDofsCol();
2835 const int nb_init_ghost_row_dofs = prb_ptr->getNbGhostDofsRow();
2836 const int nb_init_ghost_col_dofs = prb_ptr->getNbGhostDofsCol();
2837
2838 const std::array<int, 2> nb_init_dofs = {nb_init_row_dofs, nb_init_col_dofs};
2839
2840 for (int s = 0; s != 2; ++s)
2841 if (numered_dofs[s]) {
2842
2843 typedef multi_index_container<
2844
2845 NumeredDofEntity_multiIndex::iterator, indexed_by<sequenced<>>
2846
2847 >
2848 NumeredDofEntity_it_view_multiIndex;
2849
2850 const auto bit_number = m_field.get_field_bit_number(field_name);
2851 NumeredDofEntity_it_view_multiIndex dofs_it_view;
2852
2853 // Set -1 to global and local dofs indices
2854 for (auto pit = ents.const_pair_begin(); pit != ents.const_pair_end();
2855 ++pit) {
2856 auto lo = numered_dofs[s]->get<Unique_mi_tag>().lower_bound(
2857 DofEntity::getLoFieldEntityUId(bit_number, pit->first));
2858 auto hi = numered_dofs[s]->get<Unique_mi_tag>().upper_bound(
2859 DofEntity::getHiFieldEntityUId(bit_number, pit->second));
2860
2861 for (; lo != hi; ++lo)
2862 if ((*lo)->getDofCoeffIdx() >= lo_coeff &&
2863 (*lo)->getDofCoeffIdx() <= hi_coeff &&
2864 (*lo)->getDofOrder() >= lo_order &&
2865 (*lo)->getDofOrder() <= hi_order)
2866 dofs_it_view.emplace_back(numered_dofs[s]->project<0>(lo));
2867 }
2868
2869 if (verb > QUIET) {
2870 for (auto &dof : dofs_it_view)
2871 MOFEM_LOG("SYNC", Sev::noisy) << **dof;
2872 }
2873
2874 // set negative index
2875 auto mod = NumeredDofEntity_part_and_all_indices_change(-1, -1, -1, -1);
2876 for (auto dit : dofs_it_view) {
2877 bool success = numered_dofs[s]->modify(dit, mod);
2878 if (!success)
2879 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
2880 "can not set negative indices");
2881 }
2882
2883 // create weak view
2884 std::vector<boost::weak_ptr<NumeredDofEntity>> dosf_weak_view;
2885 dosf_weak_view.reserve(dofs_it_view.size());
2886 for (auto dit : dofs_it_view)
2887 dosf_weak_view.push_back(*dit);
2888
2889 if (verb >= NOISY)
2890 MOFEM_LOG_C("SYNC", Sev::noisy,
2891 "Number of DOFs in multi-index %d and to delete %d\n",
2892 numered_dofs[s]->size(), dofs_it_view.size());
2893
2894 // erase dofs from problem
2895 for (auto weak_dit : dosf_weak_view)
2896 if (auto dit = weak_dit.lock()) {
2897 numered_dofs[s]->erase(dit->getLocalUniqueId());
2898 }
2899
2900 if (verb >= NOISY)
2901 MOFEM_LOG_C("SYNC", Sev::noisy,
2902 "Number of DOFs in multi-index after delete %d\n",
2903 numered_dofs[s]->size());
2904
2905 // get current number of ghost dofs
2906 int nb_global_dof = 0;
2907 int nb_local_dofs = 0;
2908 int nb_ghost_dofs = 0;
2909
2910 for (auto dit = numered_dofs[s]->begin(); dit != numered_dofs[s]->end();
2911 ++dit) {
2912
2913 if ((*dit)->getDofIdx() >= 0) {
2914
2915 if ((*dit)->getPetscLocalDofIdx() >= 0 &&
2916 (*dit)->getPetscLocalDofIdx() < *(local_nbdof_ptr[s]))
2917 ++nb_local_dofs;
2918 else if ((*dit)->getPetscLocalDofIdx() >= *(local_nbdof_ptr[s]))
2919 ++nb_ghost_dofs;
2920
2921 ++nb_global_dof;
2922 }
2923 }
2924
2925 if (debug) {
2926 MPI_Allreduce(&nb_local_dofs, nbdof_ptr[s], 1, MPI_INT, MPI_SUM,
2927 m_field.get_comm());
2928 if (*(nbdof_ptr[s]) != nb_global_dof)
2929 SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
2930 "Number of local DOFs do not add up %d != %d",
2931 *(nbdof_ptr[s]), nb_global_dof);
2932 }
2933
2934 *(nbdof_ptr[s]) = nb_global_dof;
2935 *(local_nbdof_ptr[s]) = nb_local_dofs;
2936 *(ghost_nbdof_ptr[s]) = nb_ghost_dofs;
2937
2938 // get indices
2939 auto get_indices_by_tag = [&](auto tag, int check) {
2940 std::vector<int> indices;
2941 indices.resize(nb_init_dofs[s], -1);
2942 int i = 0;
2943 for (auto dit = numered_dofs[s]->get<decltype(tag)>().begin();
2944 dit != numered_dofs[s]->get<decltype(tag)>().end(); ++dit) {
2945 const int current_idx = decltype(tag)::get_index(dit);
2946 const int idx = (*dit)->getDofIdx();
2947 if (current_idx >= 0 && idx >= 0) {
2948 indices[idx] = i++;
2949 }
2950 }
2951 if (i != check) {
2952 MOFEM_LOG("SELF", Sev::error) << "i != check " << i << "!=" << check;
2953 THROW_MESSAGE("Wrong number of indices");
2954 }
2955 return indices;
2956 };
2957
2958 auto global_indices =
2959 get_indices_by_tag(PetscGlobalIdx_mi_tag(), nb_global_dof);
2960 auto local_indices = get_indices_by_tag(PetscLocalIdx_mi_tag(),
2961 nb_local_dofs + nb_ghost_dofs);
2962
2963 int i = 0;
2964 for (auto dit = numered_dofs[s]->begin(); dit != numered_dofs[s]->end();
2965 ++dit) {
2966 auto idx = (*dit)->getDofIdx();
2967 if (idx >= 0) {
2968 auto mod = NumeredDofEntity_part_and_all_indices_change(
2969 (*dit)->getPart(), i++, global_indices[idx], local_indices[idx]);
2970 bool success = numered_dofs[s]->modify(dit, mod);
2971 if (!success)
2972 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
2973 "can not set negative indices");
2974 } else {
2975 auto mod = NumeredDofEntity_part_and_all_indices_change(
2976 (*dit)->getPart(), -1, -1, -1);
2977 bool success = numered_dofs[s]->modify(dit, mod);
2978 if (!success)
2979 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
2980 "can not set negative indices");
2981
2982 }
2983 };
2984
2985 if (debug) {
2986 for (auto dof : (*numered_dofs[s])) {
2987 if (dof->getDofIdx() >= 0 && dof->getPetscGlobalDofIdx() < 0) {
2988 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
2989 "Negative global idx");
2990 }
2991 }
2992
2993 }
2994
2995 } else {
2996
2997 *(nbdof_ptr[1]) = *(nbdof_ptr[0]);
2998 *(local_nbdof_ptr[1]) = *(local_nbdof_ptr[0]);
2999 *(ghost_nbdof_ptr[1]) = *(ghost_nbdof_ptr[0]);
3000 }
3001
3002 if (verb >= NOISY)
3004
3005 if (verb > QUIET) {
3006 auto log = [&](auto str, auto level) {
3007 MOFEM_LOG_C(str, level,
3008 "removed ents on rank %d from problem %s dofs [ %d / %d "
3009 "(before %d / "
3010 "%d) local, %d / %d (before %d / %d) "
3011 "ghost, %d / %d (before %d / %d) global]",
3012 m_field.get_comm_rank(), prb_ptr->getName().c_str(),
3013 prb_ptr->getNbLocalDofsRow(), prb_ptr->getNbLocalDofsCol(),
3014 nb_init_row_dofs, nb_init_col_dofs,
3015 prb_ptr->getNbGhostDofsRow(), prb_ptr->getNbGhostDofsCol(),
3016 nb_init_ghost_row_dofs, nb_init_ghost_col_dofs,
3017 prb_ptr->getNbDofsRow(), prb_ptr->getNbDofsCol(),
3018 nb_init_loc_row_dofs, nb_init_loc_col_dofs);
3019 };
3020
3021 log("WORLD", Sev::verbose);
3022 if (m_field.get_comm_rank() > 0)
3023 log("SYNC", Sev::noisy);
3024
3026 }
3028}
#define MOFEM_LOG_C(channel, severity, format,...)
Definition: LogManager.hpp:304
@ NOISY
Definition: definitions.h:211
@ MOFEM_OPERATION_UNSUCCESSFUL
Definition: definitions.h:34
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
Definition: definitions.h:561
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
virtual FieldBitNumber get_field_bit_number(const std::string name) const =0
get field bit number
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 30 of file ProblemsManager.hpp.

◆ cOre

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

Definition at line 26 of file ProblemsManager.hpp.

◆ MOFEM_EVENT_ProblemsManager

PetscLogEvent MoFEM::ProblemsManager::MOFEM_EVENT_ProblemsManager
private

Definition at line 429 of file ProblemsManager.hpp.

◆ synchroniseProblemEntities

PetscBool MoFEM::ProblemsManager::synchroniseProblemEntities

DOFs in fields, not from DOFs on elements.

Definition at line 33 of file ProblemsManager.hpp.


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