v0.14.0
ProblemsMultiIndices.cpp
Go to the documentation of this file.
1 /** \file ProblemsMultiIndices.cpp
2  * \brief Multindex contains for problems
3  */
4 
5 
6 namespace MoFEM {
7 
8 // moab problem
10  : meshset(meshset), numeredRowDofsPtr(new NumeredDofEntity_multiIndex()),
11  numeredColDofsPtr(new NumeredDofEntity_multiIndex()),
12  numeredFiniteElementsPtr(new NumeredEntFiniteElement_multiIndex()),
13  sequenceRowDofContainer(new SequenceDofContainer()),
14  sequenceColDofContainer(new SequenceDofContainer()) {
15  Tag th_ProblemId;
16  MOAB_THROW(moab.tag_get_handle("_ProblemId", th_ProblemId));
17  MOAB_THROW(
18  moab.tag_get_by_ptr(th_ProblemId, &meshset, 1, (const void **)&tagId));
19  Tag th_ProblemName;
20  MOAB_THROW(moab.tag_get_handle("_ProblemName", th_ProblemName));
21  MOAB_THROW(moab.tag_get_by_ptr(th_ProblemName, &meshset, 1,
22  (const void **)&tagName, &tagNameSize));
23  Tag th_ProblemFEId;
24  MOAB_THROW(moab.tag_get_handle("_ProblemFEId", th_ProblemFEId));
25  MOAB_THROW(moab.tag_get_by_ptr(th_ProblemFEId, &meshset, 1,
26  (const void **)&tagBitFEId));
27  Tag th_RefBitLevel;
28  MOAB_THROW(moab.tag_get_handle("_RefBitLevel", th_RefBitLevel));
29  MOAB_THROW(moab.tag_get_by_ptr(th_RefBitLevel, &meshset, 1,
30  (const void **)&tagBitRefLevel));
31  Tag th_RefBitLevel_Mask;
32  MOAB_THROW(moab.tag_get_handle("_RefBitLevelMask", th_RefBitLevel_Mask));
33  MOAB_THROW(moab.tag_get_by_ptr(th_RefBitLevel_Mask, &meshset, 1,
34  (const void **)&tagBitRefLevelMask));
35 }
36 
37 std::ostream &operator<<(std::ostream &os, const Problem &e) {
38  os << "Problem id " << e.getId() << " name " << e.getName() << endl;
39  os << "FiniteElement id " << e.getBitFEId() << endl;
40  os << "BitRefLevel " << e.getBitRefLevel() << endl;
41  os << "BitRefLevelMask " << e.getBitRefLevelMask();
42  return os;
43 }
44 
46 
47 boost::weak_ptr<NumeredDofEntity>
50  boost::weak_ptr<NumeredDofEntity> dof_weak_ptr;
51  NumeredDofEntity_multiIndex::index<PetscGlobalIdx_mi_tag>::type::iterator dit;
52  dit = numeredRowDofsPtr->get<PetscGlobalIdx_mi_tag>().find(idx);
53  if (dit != numeredRowDofsPtr->get<PetscGlobalIdx_mi_tag>().end())
54  dof_weak_ptr = *dit;
55  return dof_weak_ptr;
56 }
57 
58 boost::weak_ptr<NumeredDofEntity>
61  boost::weak_ptr<NumeredDofEntity> dof_weak_ptr;
62  NumeredDofEntity_multiIndex::index<PetscGlobalIdx_mi_tag>::type::iterator dit;
63  dit = numeredColDofsPtr->get<PetscGlobalIdx_mi_tag>().find(idx);
64  if (dit != numeredColDofsPtr->get<PetscGlobalIdx_mi_tag>().end())
65  dof_weak_ptr = *dit;
66  return dof_weak_ptr;
67 }
68 
70  DofIdx idx, const NumeredDofEntity **dof_ptr, MoFEMTypes bh) const {
72  auto weak_dof_ptr = getRowDofsByPetscGlobalDofIdx(idx);
73  if (auto shared_dof_ptr = weak_dof_ptr.lock()) {
74  *dof_ptr = shared_dof_ptr.get();
75  } else {
76  if (bh == MF_EXIST)
77  SETERRQ1(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "row dof <%d> not found", idx);
78  *dof_ptr = nullptr;
79  }
81 }
82 
84  DofIdx idx, const NumeredDofEntity **dof_ptr, MoFEMTypes bh) const {
86  auto weak_dof_ptr = getColDofsByPetscGlobalDofIdx(idx);
87  if (auto shared_dof_ptr = weak_dof_ptr.lock()) {
88  *dof_ptr = shared_dof_ptr.get();
89  } else {
90  if (bh == MF_EXIST)
91  SETERRQ1(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "row dof <%d> not found", idx);
92  *dof_ptr = nullptr;
93  }
95 }
96 
98 Problem::getNumberOfElementsByNameAndPart(MPI_Comm comm, const std::string name,
99  PetscLayout *layout) const {
101  int size, rank;
102  MPI_Comm_size(comm, &size);
103  MPI_Comm_rank(comm, &rank);
104  CHKERR PetscLayoutCreate(comm, layout);
105  CHKERR PetscLayoutSetBlockSize(*layout, 1);
106  const auto &fe_by_name_and_part =
108  int nb_elems;
109  nb_elems = fe_by_name_and_part.count(boost::make_tuple(name, rank));
110  CHKERR PetscLayoutSetLocalSize(*layout, nb_elems);
111  CHKERR PetscLayoutSetUp(*layout);
113 }
114 
116  PetscLayout *layout) const {
118  int size, rank;
119  MPI_Comm_size(comm, &size);
120  MPI_Comm_rank(comm, &rank);
121  CHKERR PetscLayoutCreate(comm, layout);
122  CHKERR PetscLayoutSetBlockSize(*layout, 1);
124  const FeByPart &fe_by_part = numeredFiniteElementsPtr->get<Part_mi_tag>();
125  int nb_elems;
126  nb_elems = fe_by_part.count(rank);
127  CHKERR PetscLayoutSetLocalSize(*layout, nb_elems);
128  CHKERR PetscLayoutSetUp(*layout);
130 }
131 
133  const int field_bit_number, const EntityHandle ent, const int ent_dof_idx,
134  const RowColData row_or_col,
135  boost::shared_ptr<NumeredDofEntity> &dof_ptr) const {
137  decltype(numeredRowDofsPtr) numered_dofs;
138  switch (row_or_col) {
139  case ROW:
140  if (!numeredRowDofsPtr) {
141  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
142  "Row numbered index in problem not allocated");
143  }
144  numered_dofs = numeredRowDofsPtr;
145  break;
146  case COL:
147  if (!numeredColDofsPtr) {
148  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
149  "Col numbered index in problem not allocated");
150  }
151  numered_dofs = numeredColDofsPtr;
152  break;
153  default:
154  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
155  "Only ROW and COL is possible for 3rd argument");
156  }
157 
158  auto it =
159  numered_dofs->get<Unique_mi_tag>().find(DofEntity::getUniqueIdCalculate(
160  ent_dof_idx,
161  FieldEntity::getLocalUniqueIdCalculate(field_bit_number, ent)));
162  if (it != numered_dofs->get<Unique_mi_tag>().end()) {
163  dof_ptr = *it;
164  } else {
165  dof_ptr = boost::shared_ptr<NumeredDofEntity>();
166  }
168 }
169 
172  for (auto p = entities.pair_begin(); p != entities.pair_end(); ++p) {
173  auto lo = numeredFiniteElementsPtr->get<Ent_mi_tag>().lower_bound(p->first);
174  auto hi =
175  numeredFiniteElementsPtr->get<Ent_mi_tag>().upper_bound(p->second);
176  numeredFiniteElementsPtr->get<Ent_mi_tag>().erase(lo, hi);
177  }
179 }
180 
182  *(p.tagBitFEId) |= f_id;
183 }
185  *(p.tagBitFEId) &= ~f_id;
186 }
188  e.nbDofsRow = 0;
189  e.nbLocDofsRow = 0;
190  e.nbGhostDofsRow = 0;
191  e.numeredRowDofsPtr->clear();
192 }
194  e.nbDofsCol = 0;
195  e.nbLocDofsCol = 0;
196  e.nbGhostDofsCol = 0;
197  e.numeredColDofsPtr->clear();
198 }
200  e.numeredFiniteElementsPtr->clear();
201 }
202 
203 } // namespace MoFEM
MoFEM::ProblemClearNumeredFiniteElementsChange::operator()
void operator()(Problem &e)
Definition: ProblemsMultiIndices.cpp:199
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:460
MoFEM::operator<<
std::ostream & operator<<(std::ostream &os, const EntitiesFieldData::EntData &e)
Definition: EntitiesFieldData.cpp:240
MoFEM::Ent_mi_tag
Definition: TagMultiIndices.hpp:21
MoFEM::Problem::tagBitRefLevel
BitRefLevel * tagBitRefLevel
BitRef level of finite elements in problem.
Definition: ProblemsMultiIndices.hpp:62
MoFEM::Problem::nbGhostDofsRow
DofIdx nbGhostDofsRow
Number of ghost DOFs in row.
Definition: ProblemsMultiIndices.hpp:69
MoFEM::ProblemFiniteElementChangeBitAdd::f_id
BitFEId f_id
Definition: ProblemsMultiIndices.hpp:690
MoFEM::Problem::getNumberOfElementsByNameAndPart
MoFEMErrorCode getNumberOfElementsByNameAndPart(MPI_Comm comm, const std::string name, PetscLayout *layout) const
Get number of finite elements by name on processors.
Definition: ProblemsMultiIndices.cpp:98
EntityHandle
MoFEM::Problem::eraseElements
MoFEMErrorCode eraseElements(Range entities) const
Erase elements by entities.
Definition: ProblemsMultiIndices.cpp:170
MoFEM::ProblemZeroNbRowsChange::operator()
void operator()(Problem &e)
Definition: ProblemsMultiIndices.cpp:187
MoFEM::DofEntity::getUniqueIdCalculate
static UId getUniqueIdCalculate(const DofIdx dof, UId ent_uid)
Definition: DofsMultiIndices.hpp:54
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::Composite_Name_And_Part_mi_tag
Definition: TagMultiIndices.hpp:87
MoFEM::ProblemZeroNbColsChange::operator()
void operator()(Problem &e)
Definition: ProblemsMultiIndices.cpp:193
MoFEM::Problem::getBitFEId
BitFEId getBitFEId() const
Get the BitFEIDs in problem
Definition: ProblemsMultiIndices.cpp:45
MoFEM::Problem::getId
BitProblemId getId() const
Definition: ProblemsMultiIndices.hpp:370
MoFEM::Problem::tagBitFEId
BitFEId * tagBitFEId
IDs of finite elements in problem.
Definition: ProblemsMultiIndices.hpp:61
MOAB_THROW
#define MOAB_THROW(err)
Check error code of MoAB function and throw MoFEM exception.
Definition: definitions.h:554
MoFEM::Problem::tagNameSize
int tagNameSize
Size of problem name.
Definition: ProblemsMultiIndices.hpp:60
MoFEM::Types::BitFEId
std::bitset< BITFEID_SIZE > BitFEId
Finite element Id.
Definition: Types.hpp:43
ROW
@ ROW
Definition: definitions.h:136
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:2010
NumeredDofEntity_multiIndex
multi_index_container< boost::shared_ptr< NumeredDofEntity >, indexed_by< ordered_unique< tag< Unique_mi_tag >, const_mem_fun< NumeredDofEntity::interface_type_DofEntity, UId, &NumeredDofEntity::getLocalUniqueId > >, ordered_non_unique< tag< Part_mi_tag >, member< NumeredDofEntity, unsigned int, &NumeredDofEntity::pArt > >, ordered_non_unique< tag< Idx_mi_tag >, member< NumeredDofEntity, DofIdx, &NumeredDofEntity::dofIdx > >, ordered_non_unique< tag< PetscGlobalIdx_mi_tag >, member< NumeredDofEntity, DofIdx, &NumeredDofEntity::petscGloablDofIdx > >, ordered_non_unique< tag< PetscLocalIdx_mi_tag >, member< NumeredDofEntity, DofIdx, &NumeredDofEntity::petscLocalDofIdx > >, ordered_non_unique< tag< Ent_mi_tag >, const_mem_fun< NumeredDofEntity::interface_type_DofEntity, EntityHandle, &NumeredDofEntity::getEnt > > > > NumeredDofEntity_multiIndex
MultiIndex container keeps NumeredDofEntity.
Definition: DofsMultiIndices.hpp:469
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEM::ProblemFiniteElementChangeBitUnSet::operator()
void operator()(Problem &p)
Definition: ProblemsMultiIndices.cpp:184
MoFEM::NumeredDofEntity
keeps information about indexed dofs for the problem
Definition: DofsMultiIndices.hpp:226
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::Part_mi_tag
Definition: TagMultiIndices.hpp:53
MoFEM::Problem::SequenceDofContainer
multi_index_container< boost::weak_ptr< std::vector< NumeredDofEntity > >, indexed_by< sequenced<> > > SequenceDofContainer
Definition: ProblemsMultiIndices.hpp:494
MoFEM::Problem::numeredColDofsPtr
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredColDofsPtr
store DOFs on columns for this problem
Definition: ProblemsMultiIndices.hpp:75
RowColData
RowColData
RowColData.
Definition: definitions.h:136
convert.type
type
Definition: convert.py:64
MoFEM::FieldEntity::getLocalUniqueIdCalculate
UId getLocalUniqueIdCalculate()
Get the Local Unique Id Calculate object.
Definition: FieldEntsMultiIndices.hpp:136
COL
@ COL
Definition: definitions.h:136
MoFEM::Problem::nbDofsCol
DofIdx nbDofsCol
Global number of DOFs in col.
Definition: ProblemsMultiIndices.hpp:66
MoFEM::Problem::getColDofsByPetscGlobalDofIdx
MoFEMErrorCode getColDofsByPetscGlobalDofIdx(DofIdx idx, const NumeredDofEntity **dof_ptr, MoFEMTypes bh=MF_EXIST) const
Get the Col Dofs By Petsc Global Dof Idx object.
Definition: ProblemsMultiIndices.cpp:83
MoFEM::Problem::nbLocDofsRow
DofIdx nbLocDofsRow
Local number of DOFs in row.
Definition: ProblemsMultiIndices.hpp:67
MoFEM::Problem::tagName
const char * tagName
Problem name.
Definition: ProblemsMultiIndices.hpp:59
MoFEM::PetscGlobalIdx_mi_tag
Definition: TagMultiIndices.hpp:38
MoFEM::Problem::tagId
BitProblemId * tagId
Unique problem ID.
Definition: ProblemsMultiIndices.hpp:58
MoFEM::Problem::numeredFiniteElementsPtr
boost::shared_ptr< NumeredEntFiniteElement_multiIndex > numeredFiniteElementsPtr
store finite elements
Definition: ProblemsMultiIndices.hpp:77
MOFEM_NOT_FOUND
@ MOFEM_NOT_FOUND
Definition: definitions.h:33
NumeredEntFiniteElement_multiIndex
multi_index_container< boost::shared_ptr< NumeredEntFiniteElement >, indexed_by< ordered_unique< tag< Unique_mi_tag >, const_mem_fun< NumeredEntFiniteElement::interface_type_EntFiniteElement, UId, &NumeredEntFiniteElement::getLocalUniqueId > >, ordered_non_unique< tag< Part_mi_tag >, member< NumeredEntFiniteElement, unsigned int, &NumeredEntFiniteElement::part > >, ordered_non_unique< tag< Ent_mi_tag >, const_mem_fun< NumeredEntFiniteElement::interface_type_RefEntity, EntityHandle, &NumeredEntFiniteElement::getEnt > >, ordered_non_unique< tag< Composite_Name_And_Part_mi_tag >, composite_key< NumeredEntFiniteElement, const_mem_fun< NumeredEntFiniteElement::interface_type_FiniteElement, boost::string_ref, &NumeredEntFiniteElement::getNameRef >, member< NumeredEntFiniteElement, unsigned int, &NumeredEntFiniteElement::part > >> >> NumeredEntFiniteElement_multiIndex
MultiIndex for entities for NumeredEntFiniteElement.
Definition: FEMultiIndices.hpp:830
MoFEM::Problem::nbGhostDofsCol
DofIdx nbGhostDofsCol
Number of ghost DOFs in col.
Definition: ProblemsMultiIndices.hpp:70
MoFEM::Problem::getRowDofsByPetscGlobalDofIdx
MoFEMErrorCode getRowDofsByPetscGlobalDofIdx(DofIdx idx, const NumeredDofEntity **dof_ptr, MoFEMTypes bh=MF_EXIST) const
Get the Row Dofs By Petsc Global Dof Idx object.
Definition: ProblemsMultiIndices.cpp:69
MoFEM::Problem::numeredRowDofsPtr
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredRowDofsPtr
store DOFs on rows for this problem
Definition: ProblemsMultiIndices.hpp:73
Range
MoFEM::Problem::nbLocDofsCol
DofIdx nbLocDofsCol
Local number of DOFs in colIs.
Definition: ProblemsMultiIndices.hpp:68
MoFEM::Problem::getNumberOfElementsByPart
MoFEMErrorCode getNumberOfElementsByPart(MPI_Comm comm, PetscLayout *layout) const
Get number of finite elements on processors.
Definition: ProblemsMultiIndices.cpp:115
MoFEM::ProblemFiniteElementChangeBitAdd::operator()
void operator()(Problem &p)
Definition: ProblemsMultiIndices.cpp:181
MoFEM::Problem::nbDofsRow
DofIdx nbDofsRow
Global number of DOFs in row.
Definition: ProblemsMultiIndices.hpp:65
MoFEM::Problem::getBitRefLevelMask
BitRefLevel getBitRefLevelMask() const
Definition: ProblemsMultiIndices.hpp:384
MoFEM::Problem::getBitRefLevel
BitRefLevel getBitRefLevel() const
Definition: ProblemsMultiIndices.hpp:383
MoFEMTypes
MoFEMTypes
Those types control how functions respond on arguments, f.e. error handling.
Definition: definitions.h:110
MoFEM::Problem::meshset
EntityHandle meshset
Definition: ProblemsMultiIndices.hpp:56
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:453
MoFEM::Unique_mi_tag
Definition: TagMultiIndices.hpp:18
MoFEM::Problem
keeps basic data about problem
Definition: ProblemsMultiIndices.hpp:54
MoFEM::ProblemFiniteElementChangeBitUnSet::f_id
BitFEId f_id
Definition: ProblemsMultiIndices.hpp:708
MoFEM::Problem::getDofByNameEntAndEntDofIdx
MoFEMErrorCode getDofByNameEntAndEntDofIdx(const int field_bit_number, const EntityHandle ent, const int ent_dof_idx, const RowColData row_or_col, boost::shared_ptr< NumeredDofEntity > &dof_ptr) const
get DOFs from problem
Definition: ProblemsMultiIndices.cpp:132
MoFEM::Problem::Problem
Problem(Interface &moab, const EntityHandle meshset)
Definition: ProblemsMultiIndices.cpp:9
MoFEM::Problem::getName
auto getName() const
Definition: ProblemsMultiIndices.hpp:372
MF_EXIST
@ MF_EXIST
Definition: definitions.h:113
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
MoFEM::Problem::tagBitRefLevelMask
BitRefLevel * tagBitRefLevelMask
BItRefMask of elements in problem.
Definition: ProblemsMultiIndices.hpp:63
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
MOFEM_INVALID_DATA
@ MOFEM_INVALID_DATA
Definition: definitions.h:36
MoFEM::Types::DofIdx
int DofIdx
Index of DOF.
Definition: Types.hpp:18