v0.11.1
ProblemsMultiIndices.cpp
Go to the documentation of this file.
1 /** \file ProblemsMultiIndices.cpp
2  * \brief Multindex contains for problems
3  */
4 
5 /* MoFEM is free software: you can redistribute it and/or modify it under
6  * the terms of the GNU Lesser General Public License as published by the
7  * Free Software Foundation, either version 3 of the License, or (at your
8  * option) any later version.
9  *
10  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13  * License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>
17  */
18 
19 namespace MoFEM {
20 
21 // moab problem
22 Problem::Problem(moab::Interface &moab, const EntityHandle meshset)
23  : meshset(meshset), numeredRowDofsPtr(new NumeredDofEntity_multiIndex()),
24  numeredColDofsPtr(new NumeredDofEntity_multiIndex()),
25  numeredFiniteElementsPtr(new NumeredEntFiniteElement_multiIndex()),
26  sequenceRowDofContainer(new SequenceDofContainer()),
27  sequenceColDofContainer(new SequenceDofContainer()) {
28  ErrorCode rval;
29  Tag th_ProblemId;
30  rval = moab.tag_get_handle("_ProblemId", th_ProblemId);
32  rval = moab.tag_get_by_ptr(th_ProblemId, &meshset, 1, (const void **)&tagId);
34  Tag th_ProblemName;
35  rval = moab.tag_get_handle("_ProblemName", th_ProblemName);
37  rval = moab.tag_get_by_ptr(th_ProblemName, &meshset, 1,
38  (const void **)&tagName, &tagNameSize);
40  Tag th_ProblemFEId;
41  rval = moab.tag_get_handle("_ProblemFEId", th_ProblemFEId);
43  rval = moab.tag_get_by_ptr(th_ProblemFEId, &meshset, 1,
44  (const void **)&tagBitFEId);
46  Tag th_RefBitLevel;
47  rval = moab.tag_get_handle("_RefBitLevel", th_RefBitLevel);
49  rval = moab.tag_get_by_ptr(th_RefBitLevel, &meshset, 1,
50  (const void **)&tagBitRefLevel);
52  Tag th_RefBitLevel_Mask;
53  rval = moab.tag_get_handle("_RefBitLevelMask", th_RefBitLevel_Mask);
55  rval = moab.tag_get_by_ptr(th_RefBitLevel_Mask, &meshset, 1,
56  (const void **)&tagMaskBitRefLevel);
58 }
59 
60 std::ostream &operator<<(std::ostream &os, const Problem &e) {
61  os << "problem id " << e.getId() << " FiniteElement id " << e.getBitFEId()
62  << " name " << e.getName();
63  return os;
64 }
65 
67 
68 boost::weak_ptr<NumeredDofEntity>
71  boost::weak_ptr<NumeredDofEntity> dof_weak_ptr;
72  NumeredDofEntity_multiIndex::index<PetscGlobalIdx_mi_tag>::type::iterator dit;
73  dit = numeredRowDofsPtr->get<PetscGlobalIdx_mi_tag>().find(idx);
74  if (dit != numeredRowDofsPtr->get<PetscGlobalIdx_mi_tag>().end())
75  dof_weak_ptr = *dit;
76  return dof_weak_ptr;
77 }
78 
79 boost::weak_ptr<NumeredDofEntity>
82  boost::weak_ptr<NumeredDofEntity> dof_weak_ptr;
83  NumeredDofEntity_multiIndex::index<PetscGlobalIdx_mi_tag>::type::iterator dit;
84  dit = numeredColDofsPtr->get<PetscGlobalIdx_mi_tag>().find(idx);
85  if (dit != numeredColDofsPtr->get<PetscGlobalIdx_mi_tag>().end())
86  dof_weak_ptr = *dit;
87  return dof_weak_ptr;
88 }
89 
91  DofIdx idx, const NumeredDofEntity **dof_ptr, MoFEMTypes bh) const {
93  auto weak_dof_ptr = getRowDofsByPetscGlobalDofIdx(idx);
94  if (auto shared_dof_ptr = weak_dof_ptr.lock()) {
95  *dof_ptr = shared_dof_ptr.get();
96  } else {
97  if (bh == MF_EXIST)
98  SETERRQ1(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "row dof <%d> not found", idx);
99  *dof_ptr = nullptr;
100  }
102 }
103 
105  DofIdx idx, const NumeredDofEntity **dof_ptr, MoFEMTypes bh) const {
107  auto weak_dof_ptr = getColDofsByPetscGlobalDofIdx(idx);
108  if (auto shared_dof_ptr = weak_dof_ptr.lock()) {
109  *dof_ptr = shared_dof_ptr.get();
110  } else {
111  if (bh == MF_EXIST)
112  SETERRQ1(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "row dof <%d> not found", idx);
113  *dof_ptr = nullptr;
114  }
116 }
117 
119 Problem::getNumberOfElementsByNameAndPart(MPI_Comm comm, const std::string name,
120  PetscLayout *layout) const {
122  int size, rank;
123  MPI_Comm_size(comm, &size);
124  MPI_Comm_rank(comm, &rank);
125  CHKERR PetscLayoutCreate(comm, layout);
126  CHKERR PetscLayoutSetBlockSize(*layout, 1);
127  const NumeredEntFiniteElementbyNameAndPart &fe_by_name_and_part =
129  int nb_elems;
130  nb_elems = fe_by_name_and_part.count(boost::make_tuple(name, rank));
131  CHKERR PetscLayoutSetLocalSize(*layout, nb_elems);
132  CHKERR PetscLayoutSetUp(*layout);
134 }
135 
137  PetscLayout *layout) const {
139  int size, rank;
140  MPI_Comm_size(comm, &size);
141  MPI_Comm_rank(comm, &rank);
142  CHKERR PetscLayoutCreate(comm, layout);
143  CHKERR PetscLayoutSetBlockSize(*layout, 1);
145  const FeByPart &fe_by_part = numeredFiniteElementsPtr->get<Part_mi_tag>();
146  int nb_elems;
147  nb_elems = fe_by_part.count(rank);
148  CHKERR PetscLayoutSetLocalSize(*layout, nb_elems);
149  CHKERR PetscLayoutSetUp(*layout);
151 }
152 
154  const int field_bit_number, const EntityHandle ent, const int ent_dof_idx,
155  const RowColData row_or_col,
156  boost::shared_ptr<NumeredDofEntity> &dof_ptr) const {
158  decltype(numeredRowDofsPtr) numered_dofs;
159  switch (row_or_col) {
160  case ROW:
161  if (!numeredRowDofsPtr) {
162  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
163  "Row numbered index in problem not allocated");
164  }
165  numered_dofs = numeredRowDofsPtr;
166  break;
167  case COL:
168  if (!numeredColDofsPtr) {
169  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
170  "Col numbered index in problem not allocated");
171  }
172  numered_dofs = numeredColDofsPtr;
173  break;
174  default:
175  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
176  "Only ROW and COL is possible for 3rd argument");
177  }
178 
179  auto it =
180  numered_dofs->get<Unique_mi_tag>().find(DofEntity::getUniqueIdCalculate(
181  ent_dof_idx,
182  FieldEntity::getLocalUniqueIdCalculate(field_bit_number, ent)));
183  if (it != numered_dofs->get<Unique_mi_tag>().end()) {
184  dof_ptr = *it;
185  } else {
186  dof_ptr = boost::shared_ptr<NumeredDofEntity>();
187  }
189 }
190 
192  *(p.tagBitFEId) |= f_id;
193 }
195  *(p.tagBitFEId) &= ~f_id;
196 }
198  e.nbDofsRow = 0;
199  e.nbLocDofsRow = 0;
200  e.nbGhostDofsRow = 0;
201  e.numeredRowDofsPtr->clear();
202 }
204  e.nbDofsCol = 0;
205  e.nbLocDofsCol = 0;
206  e.nbGhostDofsCol = 0;
207  e.numeredColDofsPtr->clear();
208 }
210  e.numeredFiniteElementsPtr->clear();
211 }
212 
213 } // namespace MoFEM
static Index< 'p', 3 > p
RowColData
RowColData.
Definition: definitions.h:192
@ COL
Definition: definitions.h:192
@ ROW
Definition: definitions.h:192
MoFEMTypes
Those types control how functions respond on arguments, f.e. error handling.
Definition: definitions.h:189
@ MF_EXIST
Definition: definitions.h:189
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:516
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:415
@ MOFEM_NOT_FOUND
Definition: definitions.h:125
@ MOFEM_INVALID_DATA
Definition: definitions.h:128
#define MOAB_THROW(a)
Check error code of MoAB function and throw MoFEM exception.
Definition: definitions.h:610
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:485
#define CHKERR
Inline error check.
Definition: definitions.h:604
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:509
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.
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< FiniteElement_name_mi_tag >, const_mem_fun< NumeredEntFiniteElement::interface_type_FiniteElement, boost::string_ref, &NumeredEntFiniteElement::getNameRef > >, ordered_non_unique< tag< Ent_mi_tag >, const_mem_fun< NumeredEntFiniteElement::interface_type_RefEntity, EntityHandle, &NumeredEntFiniteElement::getEnt > >, ordered_non_unique< tag< Composite_Name_And_Ent_mi_tag >, composite_key< NumeredEntFiniteElement, const_mem_fun< NumeredEntFiniteElement::interface_type_FiniteElement, boost::string_ref, &NumeredEntFiniteElement::getNameRef >, 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.
NumeredEntFiniteElement_multiIndex::index< Composite_Name_And_Part_mi_tag >::type NumeredEntFiniteElementbyNameAndPart
Entity finite element multi-index by finite element name and partition.
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
Definition: Exceptions.hpp:85
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:67
std::bitset< BITFEID_SIZE > BitFEId
Finite element Id.
Definition: Types.hpp:54
int DofIdx
Index of DOF.
Definition: Types.hpp:29
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1953
std::ostream & operator<<(std::ostream &os, const DataForcesAndSourcesCore::EntData &e)
static UId getUniqueIdCalculate(const DofIdx dof, UId ent_uid)
UId getLocalUniqueIdCalculate()
Get the Local Unique Id Calculate object.
keeps information about indexed dofs for the problem
keeps basic data about problem
MoFEMErrorCode getNumberOfElementsByPart(MPI_Comm comm, PetscLayout *layout) const
Get number of finite elements on processors.
std::string getName() const
MoFEMErrorCode getNumberOfElementsByNameAndPart(MPI_Comm comm, const std::string name, PetscLayout *layout) const
Get number of finite elements by name on processors.
const char * tagName
Problem name.
BitProblemId * tagId
Unique problem ID.
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
BitRefLevel * tagMaskBitRefLevel
BItRefMask of elements in problem.
DofIdx nbGhostDofsCol
Number of ghost DOFs in col.
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredRowDofsPtr
store DOFs on rows for this problem
boost::shared_ptr< NumeredEntFiniteElement_multiIndex > numeredFiniteElementsPtr
store finite elements
Problem(Interface &moab, const EntityHandle meshset)
MoFEMErrorCode getRowDofsByPetscGlobalDofIdx(DofIdx idx, const NumeredDofEntity **dof_ptr, MoFEMTypes bh=MF_EXIST) const
Get the Row Dofs By Petsc Global Dof Idx object.
DofIdx nbLocDofsRow
Local number of DOFs in row.
BitFEId getBitFEId() const
BitProblemId getId() const
DofIdx nbDofsCol
Global number of DOFs in col.
DofIdx nbGhostDofsRow
Number of ghost DOFs in row.
DofIdx nbLocDofsCol
Local number of DOFs in colIs.
int tagNameSize
Size of problem name.
MoFEMErrorCode getColDofsByPetscGlobalDofIdx(DofIdx idx, const NumeredDofEntity **dof_ptr, MoFEMTypes bh=MF_EXIST) const
Get the Col Dofs By Petsc Global Dof Idx object.
BitFEId * tagBitFEId
IDs of finite elements in problem.
DofIdx nbDofsRow
Global number of DOFs in row.
multi_index_container< boost::weak_ptr< std::vector< NumeredDofEntity > >, indexed_by< sequenced<> > > SequenceDofContainer
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredColDofsPtr
store DOFs on columns for this problem
BitRefLevel * tagBitRefLevel
BitRef level of finite elements in problem.