v0.8.23
ProblemsMultiIndices.cpp
Go to the documentation of this file.
1 /** \file CoreDataStructures.cpp
2  * \brief Myltindex contains, data structures and other low-level functions
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), numeredDofsRows(new NumeredDofEntity_multiIndex()),
24  numeredDofsCols(new NumeredDofEntity_multiIndex()),
25  numeredFiniteElements(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 
61 
62 std::ostream &operator<<(std::ostream &os, const Problem &e) {
63  os << "problem id " << e.getId() << " FiniteElement id " << e.getBitFEId()
64  << " name " << e.getName();
65  return os;
66 }
67 
69 
72  const NumeredDofEntity **dof_ptr) const {
74  NumeredDofEntity_multiIndex::index<PetscGlobalIdx_mi_tag>::type::iterator dit;
75  dit = numeredDofsRows->get<PetscGlobalIdx_mi_tag>().find(idx);
76  if (dit == numeredDofsRows->get<PetscGlobalIdx_mi_tag>().end()) {
77  SETERRQ1(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "row dof <%d> not found", idx);
78  }
79  *dof_ptr = &*(*dit);
81 }
82 
85  const NumeredDofEntity **dof_ptr) const {
87  NumeredDofEntity_multiIndex::index<PetscGlobalIdx_mi_tag>::type::iterator dit;
88  dit = numeredDofsCols->get<PetscGlobalIdx_mi_tag>().find(idx);
89  if (dit == numeredDofsCols->get<PetscGlobalIdx_mi_tag>().end()) {
90  SETERRQ1(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "row dof <%d> not found", idx);
91  }
92  *dof_ptr = &*(*dit);
94 }
95 
97 Problem::getNumberOfElementsByNameAndPart(MPI_Comm comm, const std::string name,
98  PetscLayout *layout) const {
100  int size, rank;
101  MPI_Comm_size(comm, &size);
102  MPI_Comm_rank(comm, &rank);
103  CHKERR PetscLayoutCreate(comm, layout);
104  CHKERR PetscLayoutSetBlockSize(*layout, 1);
105  const NumeredEntFiniteElementbyNameAndPart &fe_by_name_and_part =
107  int nb_elems;
108  nb_elems = fe_by_name_and_part.count(boost::make_tuple(name, rank));
109  CHKERR PetscLayoutSetLocalSize(*layout, nb_elems);
110  CHKERR PetscLayoutSetUp(*layout);
112 }
113 
115  PetscLayout *layout) const {
117  int size, rank;
118  MPI_Comm_size(comm, &size);
119  MPI_Comm_rank(comm, &rank);
120  CHKERR PetscLayoutCreate(comm, layout);
121  CHKERR PetscLayoutSetBlockSize(*layout, 1);
122  typedef NumeredEntFiniteElement_multiIndex::index<Part_mi_tag>::type FeByPart;
123  const FeByPart &fe_by_part = numeredFiniteElements->get<Part_mi_tag>();
124  int nb_elems;
125  nb_elems = fe_by_part.count(rank);
126  CHKERR PetscLayoutSetLocalSize(*layout, nb_elems);
127  CHKERR PetscLayoutSetUp(*layout);
129 }
130 
132  const string name, const EntityHandle ent, const int ent_dof_idx,
133  const RowColData row_or_col,
134  boost::shared_ptr<NumeredDofEntity> &dof_ptr) const {
136  decltype(numeredDofsRows) numered_dofs;
137  switch (row_or_col) {
138  case ROW:
139  if (!numeredDofsRows) {
140  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
141  "Row numbered index in problem not allocated");
142  }
143  numered_dofs = numeredDofsRows;
144  break;
145  case COL:
146  if (!numeredDofsCols) {
147  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
148  "Col numbered index in problem not allocated");
149  }
150  numered_dofs = numeredDofsCols;
151  break;
152  default:
153  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
154  "Only ROW and COL is possible for 3rd argument");
155  }
156  auto it =
157  numered_dofs->get<Composite_Name_And_Ent_And_EntDofIdx_mi_tag>().find(
158  boost::make_tuple(name, ent, ent_dof_idx));
159  if (it !=
160  numered_dofs->get<Composite_Name_And_Ent_And_EntDofIdx_mi_tag>().end()) {
161  dof_ptr = *it;
162  } else {
163  dof_ptr = boost::shared_ptr<NumeredDofEntity>();
164  }
166 }
167 
169  *(p.tagBitFEId) |= f_id;
170 }
172  *(p.tagBitFEId) &= ~f_id;
173 }
175  e.nbDofsRow = 0;
176  e.nbLocDofsRow = 0;
177  e.nbGhostDofsRow = 0;
178  e.numeredDofsRows->clear();
179 }
181  e.nbDofsCol = 0;
182  e.nbLocDofsCol = 0;
183  e.nbGhostDofsCol = 0;
184  e.numeredDofsCols->clear();
185 }
187  e.numeredFiniteElements->clear();
188 }
189 
190 } // namespace MoFEM
Problem(Interface &moab, const EntityHandle meshset)
BitFEId getBitFEId() const
DofIdx nbLocDofsCol
Local number of DOFs in colIs.
MoFEMErrorCode getRowDofsByPetscGlobalDofIdx(DofIdx idx, const NumeredDofEntity **dof_ptr) const
int tagNameSize
Size of problem name.
DofIdx nbDofsCol
Global number of DOFs in col.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:500
DofIdx nbGhostDofsCol
Number of ghost DOFs in col.
BitProblemId * tagId
Unique problem ID.
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:476
MoFEMErrorCode getColDofsByPetscGlobalDofIdx(DofIdx idx, const NumeredDofEntity **dof_ptr) const
const char * tagName
Problem name.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:507
keeps basic data about problemThis is low level structure with information about problem,...
RowColData
RowColData.
Definition: definitions.h:185
#define MOAB_THROW(a)
Check error code of MoAB function and throw MoFEM exception.
Definition: definitions.h:601
BitFEId * tagBitFEId
IDs of finite elements in problem.
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
NumeredEntFiniteElement_multiIndex::index< Composite_Name_And_Part_mi_tag >::type NumeredEntFiniteElementbyNameAndPart
Entity finite element multi-index by finite element name and partition.
MoFEMErrorCode getDofByNameEntAndEntDofIdx(const string name, const EntityHandle ent, const int ent_dof_idx, const RowColData row_or_col, boost::shared_ptr< NumeredDofEntity > &dof_ptr) const
get DOFs from problem
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
Definition: Exceptions.hpp:84
DofIdx nbGhostDofsRow
Number of ghost DOFs in row.
std::ostream & operator<<(std::ostream &os, const DataForcesAndSourcesCore::EntData &e)
std::bitset< BITFEID_SIZE > BitFEId
Finite element Id.
Definition: Types.hpp:54
multi_index_container< boost::shared_ptr< NumeredEntFiniteElement >, indexed_by< ordered_unique< tag< Unique_mi_tag >, const_mem_fun< NumeredEntFiniteElement::interface_type_EntFiniteElement, UId, &NumeredEntFiniteElement::getGlobalUniqueId > >, 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_EntFiniteElement, 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_EntFiniteElement, 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.
DofIdx nbLocDofsRow
Local number of DOFs in row.
BitRefLevel * tagMaskBitRefLevel
BItRefMask of elements in problem.
BitRefLevel * tagBitRefLevel
BitRef level of finite elements in problem.
MoFEMErrorCode getNumberOfElementsByPart(MPI_Comm comm, PetscLayout *layout) const
Get number of finite elements on processors.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:66
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredDofsRows
store DOFs on rows for this problem
DofIdx nbDofsRow
Global number of DOFs in row.
#define CHKERR
Inline error check.
Definition: definitions.h:595
keeps information about indexed dofs for the problemFIXME: Is too many iterator, this has to be manag...
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:406
std::string getName() const
boost::shared_ptr< NumeredEntFiniteElement_multiIndex > numeredFiniteElements
store finite elements
MoFEMErrorCode getNumberOfElementsByNameAndPart(MPI_Comm comm, const std::string name, PetscLayout *layout) const
Get number of finite elements by name on processors.
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredDofsCols
store DOFs on columns for this problem
multi_index_container< boost::weak_ptr< std::vector< NumeredDofEntity > >, indexed_by< sequenced<> > > SequenceDofContainer
multi_index_container< boost::shared_ptr< NumeredDofEntity >, indexed_by< ordered_unique< tag< Unique_mi_tag >, const_mem_fun< NumeredDofEntity::interface_type_DofEntity, const UId &, &NumeredDofEntity::getGlobalUniqueId > >, ordered_non_unique< tag< Unique_Ent_mi_tag >, const_mem_fun< NumeredDofEntity::interface_type_DofEntity, const UId &, &NumeredDofEntity::getEntGlobalUniqueId > >, 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< FieldName_mi_tag >, const_mem_fun< NumeredDofEntity::interface_type_Field, boost::string_ref, &NumeredDofEntity::getNameRef > >, 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 > >, ordered_non_unique< tag< Composite_Name_And_Ent_And_EntDofIdx_mi_tag >, composite_key< NumeredDofEntity, const_mem_fun< NumeredDofEntity::interface_type_Field, boost::string_ref, &NumeredDofEntity::getNameRef >, const_mem_fun< NumeredDofEntity::interface_type_DofEntity, EntityHandle, &NumeredDofEntity::getEnt >, const_mem_fun< NumeredDofEntity::interface_type_DofEntity, DofIdx, &NumeredDofEntity::getEntDofIdx > > >, ordered_non_unique< tag< Composite_Name_And_Part_mi_tag >, composite_key< NumeredDofEntity, const_mem_fun< NumeredDofEntity::interface_type_Field, boost::string_ref, &NumeredDofEntity::getNameRef >, member< NumeredDofEntity, unsigned int, &NumeredDofEntity::pArt > > >, ordered_non_unique< tag< Composite_Name_Ent_And_Part_mi_tag >, composite_key< NumeredDofEntity, const_mem_fun< NumeredDofEntity::interface_type_Field, boost::string_ref, &NumeredDofEntity::getNameRef >, const_mem_fun< NumeredDofEntity::interface_type_DofEntity, EntityHandle, &NumeredDofEntity::getEnt >, member< NumeredDofEntity, unsigned int, &NumeredDofEntity::pArt > > > > > NumeredDofEntity_multiIndex
MultiIndex container keeps NumeredDofEntity.
BitProblemId getId() const