v0.9.0
CoreDataStructures.cpp
Go to the documentation of this file.
1 /** \file CoreDataStructures.cpp
2  * \brief Multi-index containers, 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 #include <CoreDataStructures.hpp>
20 
21 namespace MoFEM {
22 
23 // Not partitioned
24 const bool Idx_mi_tag::IamNotPartitioned = true;
25 
26 // This tag is used for partitioned problems
29 
30 // fields
31 Field::Field(const moab::Interface &moab, const EntityHandle meshset,
32  const boost::shared_ptr<CoordSys> coord_sys_ptr)
33  : moab(const_cast<moab::Interface &>(moab)), meshSet(meshset),
34  coordSysPtr(coord_sys_ptr), tagId(NULL), tagSpaceData(NULL),
35  tagNbCoeffData(NULL), tagName(NULL), tagNameSize(0) {
36 
37  auto get_tag_data_ptr = [&](const auto name, auto &tag_data) {
39  Tag th;
40  CHKERR moab.tag_get_handle(name, th);
41  CHKERR moab.tag_get_by_ptr(th, &meshset, 1, (const void **)&tag_data);
43  };
44 
45  // id
46  ierr = get_tag_data_ptr("_FieldId", tagId);
47  CHKERRABORT(PETSC_COMM_SELF, ierr);
48  // space
49  ierr = get_tag_data_ptr("_FieldSpace", tagSpaceData);
50  CHKERRABORT(PETSC_COMM_SELF, ierr);
51 
52  // approx. base
53  ierr = get_tag_data_ptr("_FieldBase", tagBaseData);
54  CHKERRABORT(PETSC_COMM_SELF, ierr);
55 
56  auto get_all_tags = [&]() {
58  // name
59  Tag th_field_name;
60  CHKERR moab.tag_get_handle("_FieldName", th_field_name);
61  CHKERR moab.tag_get_by_ptr(th_field_name, &meshSet, 1,
62  (const void **)&tagName, &tagNameSize);
63  // name prefix
64  Tag th_field_name_data_name_prefix;
65  CHKERR moab.tag_get_handle("_FieldName_DataNamePrefix",
66  th_field_name_data_name_prefix);
67  CHKERR moab.tag_get_by_ptr(th_field_name_data_name_prefix, &meshSet, 1,
68  (const void **)&tagNamePrefixData,
70  std::string name_data_prefix((char *)tagNamePrefixData, tagNamePrefixSize);
71  // data
72  std::string tag_data_name = name_data_prefix + getName();
73  CHKERR moab.tag_get_handle(tag_data_name.c_str(), th_FieldData);
74  std::string tag_data_name_verts = name_data_prefix + getName() + "V";
75  CHKERR moab.tag_get_handle(tag_data_name_verts.c_str(), th_FieldDataVerts);
77  // order
78  std::string tag_approximation_order_name = "_App_Order_" + getName();
79  CHKERR moab.tag_get_handle(tag_approximation_order_name.c_str(),
80  th_AppOrder);
81  // rank
82  Tag th_rank;
83  std::string Tag_rank_name = "_Field_Rank_" + getName();
84  CHKERR moab.tag_get_handle(Tag_rank_name.c_str(), th_rank);
85  CHKERR moab.tag_get_by_ptr(th_rank, &meshSet, 1,
86  (const void **)&tagNbCoeffData);
88  };
89 
90  ierr = get_all_tags();
91  CHKERRABORT(PETSC_COMM_SELF, ierr);
92 
94 
95  auto reset_entity_order_table = [&]() {
96  for (int tt = 0; tt != MBMAXTYPE; ++tt)
97  forderTable[tt] = NULL;
98  };
99 
100  auto set_entity_order_table = [&]() {
101  switch (*tagBaseData) {
104  switch (*tagSpaceData) {
105  case H1:
106  forderTable[MBVERTEX] = fNBVERTEX_H1;
107  forderTable[MBEDGE] = fNBEDGE_H1;
108  forderTable[MBTRI] = fNBFACETRI_H1;
109  forderTable[MBQUAD] = fNBFACEQUAD_H1;
110  forderTable[MBTET] = fNBVOLUMETET_H1;
111  forderTable[MBPRISM] = fNBVOLUMEPRISM_H1;
112  break;
113  case HCURL:
114  forderTable[MBVERTEX] = fNBVERTEX_HCURL;
118  break;
119  case HDIV:
120  forderTable[MBVERTEX] = fNBVERTEX_HDIV;
121  forderTable[MBEDGE] = fNBEDGE_HDIV;
124  break;
125  case L2:
126  forderTable[MBVERTEX] = fNBVERTEX_L2;
127  forderTable[MBEDGE] = fNBEDGE_L2;
128  forderTable[MBTRI] = fNBFACETRI_L2;
129  forderTable[MBTET] = fNBVOLUMETET_L2;
130  break;
131  default:
132  THROW_MESSAGE("unknown approximation space");
133  }
134  break;
136  switch (*tagSpaceData) {
137  case H1:
138  forderTable[MBVERTEX] = fNBVERTEX_H1;
139  forderTable[MBEDGE] = fNBEDGE_H1;
140  forderTable[MBTRI] = fNBFACETRI_H1;
141  forderTable[MBQUAD] = fNBFACEQUAD_H1;
142  forderTable[MBTET] = fNBVOLUMETET_H1;
143  forderTable[MBPRISM] = fNBVOLUMEPRISM_H1;
144  break;
145  default:
146  THROW_MESSAGE("unknown approximation space or not yet implemented");
147  }
148  break;
150  switch (*tagSpaceData) {
151  case HCURL:
152  forderTable[MBVERTEX] = fNBVERTEX_HCURL;
156  break;
157  case HDIV:
158  forderTable[MBVERTEX] = fNBVERTEX_HDIV;
159  forderTable[MBEDGE] = fNBEDGE_HDIV;
162  break;
163  default:
164  THROW_MESSAGE("unknown approximation space or not yet implemented");
165  }
166  break;
167  case USER_BASE:
168  for (int ee = 0; ee < MBMAXTYPE; ee++) {
170  }
171  break;
172  default:
173  if (*tagSpaceData != NOFIELD) {
174  THROW_MESSAGE("unknown approximation base");
175  } else {
176  for (EntityType t = MBVERTEX; t < MBMAXTYPE; t++)
178  }
179  }
180  };
181 
182  reset_entity_order_table();
183  set_entity_order_table();
185  CHKERRABORT(PETSC_COMM_SELF, ierr);
186 };
187 
190 
191  for (auto t = MBVERTEX; t != MBMAXTYPE; ++t) {
192 
193  int DD = 0;
194  int nb_last_order_dofs = 0;
195  const int rank = (*tagNbCoeffData);
196 
197  if (forderTable[t]) {
198 
199  for (int oo = 0; oo < MAX_DOFS_ON_ENTITY; ++oo) {
200 
201  const int nb_order_dofs = forderTable[t](oo);
202  const int diff_oo = nb_order_dofs - nb_last_order_dofs;
203  if (diff_oo >= 0) {
204 
205  if ((DD + rank * diff_oo) < MAX_DOFS_ON_ENTITY)
206  for (int dd = 0; dd < diff_oo; ++dd)
207  for (int rr = 0; rr != rank; ++rr, ++DD)
208  dofOrderMap[t][DD] = oo;
209  else
210  break;
211 
212  nb_last_order_dofs = nb_order_dofs;
213 
214  } else {
215  break;
216  }
217  }
218  }
219 
220  std::fill(&dofOrderMap[t][DD], dofOrderMap[t].end(), -1);
221  }
222 
224 }
225 
226 std::ostream &operator<<(std::ostream &os, const Field &e) {
227  os << "name " << e.getNameRef() << " BitFieldId " << e.getId().to_ulong()
228  << " bit number " << e.getBitNumber() << " space "
229  << FieldSpaceNames[e.getSpace()] << " approximation base "
230  << ApproximationBaseNames[e.getApproxBase()] << " rank "
231  << e.getNbOfCoeffs() << " meshset " << e.meshSet;
232  return os;
233 }
234 
235 // FieldEntityEntFiniteElementAdjacencyMap
238  const boost::shared_ptr<FieldEntity> &ent_field_ptr,
239  const boost::shared_ptr<EntFiniteElement> &ent_fe_ptr)
240  : byWhat(0), entFieldPtr(ent_field_ptr), entFePtr(ent_fe_ptr) {}
241 
242 std::ostream &operator<<(std::ostream &os,
244  os << "byWhat " << std::bitset<3>(e.byWhat) << " " << *e.entFieldPtr
245  << std::endl
246  << *e.entFePtr->sFePtr;
247  return os;
248 }
249 
250 MoFEMErrorCode test_moab(moab::Interface &moab, const EntityHandle ent) {
252  // tets type
253  EntityType type = (EntityType)((ent & MB_TYPE_MASK) >> MB_ID_WIDTH);
254  if (type != moab.type_from_handle(ent))
255  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
256  "inconsistencies with type_from_handle");
257  // tets id
258  EntityID id = (EntityType)(ent & MB_ID_MASK);
259  if (id != moab.id_from_handle(ent))
260  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
261  "inconsistencies with id_from_handle");
263 }
264 
265 } // namespace MoFEM
int fNBFACETRI_AINSWORTH_HDIV(int P)
number of approx. functions for HDIV space on face
FieldEntityEntFiniteElementAdjacencyMap of mofem finite element and entities.
Tag th_AppOrder
Tag storing approximation order on entity.
std::string getName() const
Get field name.
const void * tagName
tag keeps name of the field
field with continuous normal traction
Definition: definitions.h:173
user implemented approximation base
Definition: definitions.h:154
int fNBVERTEX_L2(int P)
Myltindex containers, data structures and other low-level functions.
int fNBEDGE_DEMKOWICZ_HCURL(int P)
Provide data structure for (tensor) field approximation.The Field is intended to provide support for ...
const void * tagNamePrefixData
tag keeps name prefix of the field
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:501
TagType th_FieldDataVertsType
scalar or vector of scalars describe (no true field)
Definition: definitions.h:170
int fNBEDGE_H1(int P)
number of approx. functions for H1 space on edge
#define MB_TYPE_MASK
Definition: definitions.h:290
int fNBENTITY_GENERIC(int P)
int fNBFACETRI_AINSWORTH_HCURL(int P)
int fNBVOLUMEPRISM_H1(int P)
EntityHandle meshSet
keeps entities for this meshset
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:477
MoFEMErrorCode test_moab(Interface &moab, const EntityHandle ent)
Test MoAB entity handle if has structure as is assumed by MoFEM.
int fNBVOLUMETET_L2(int P)
FieldCoefficientsNumber getNbOfCoeffs() const
Get number of field coefficients.
boost::string_ref getNameRef() const
Get string reference to field name.
#define THROW_MESSAGE(a)
Throw MoFEM exception.
Definition: definitions.h:620
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:508
Field(const moab::Interface &moab, const EntityHandle meshset, const boost::shared_ptr< CoordSys > coord_sys_ptr)
constructor for moab field
int fNBFACETRI_DEMKOWICZ_HDIV(int P)
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
int fNBEDGE_AINSWORTH_HCURL(int P)
FieldEntityEntFiniteElementAdjacencyMap(const boost::shared_ptr< FieldEntity > &ent_field_ptr, const boost::shared_ptr< EntFiniteElement > &ent_fe_ptr)
FieldSpace getSpace() const
Get field approximation space.
int fNBVOLUMETET_H1(int P)
number of approx. functions for H1 space on volume
MoFEMErrorCode rebuildDofsOrderMap() const
int fNBVOLUMETET_DEMKOWICZ_HCURL(int P)
FieldOrderTable forderTable
nb. DOFs table for entities
static const char *const ApproximationBaseNames[]
Definition: definitions.h:158
std::ostream & operator<<(std::ostream &os, const DataForcesAndSourcesCore::EntData &e)
FieldSpace * tagSpaceData
tag keeps field space
const boost::shared_ptr< FieldEntity > entFieldPtr
field entity
const Tensor2_symmetric_Expr< const ddTensor0< T, Dim, i, j >, typename promote< T, double >::V, Dim, i, j > dd(const Tensor0< T * > &a, const Index< i, Dim > index1, const Index< j, Dim > index2, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition: ddTensor0.hpp:33
int fNBFACEQUAD_H1(int P)
int fNBVOLUMETET_DEMKOWICZ_HDIV(int P)
number of approx. functions for HDIV space on volume
FieldCoefficientsNumber * tagNbCoeffData
int fNBEDGE_L2(int P)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:66
const BitFieldId & getId() const
Get unique field id.
FieldApproximationBase getApproxBase() const
Get approximation base.
const boost::shared_ptr< EntFiniteElement > entFePtr
finite element entity
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:146
#define MB_ID_MASK
Definition: definitions.h:296
static const bool IamNotPartitioned
static const bool IamNotPartitioned
static const char *const FieldSpaceNames[]
Definition: definitions.h:178
field with continuous tangents
Definition: definitions.h:172
Tag th_FieldDataVerts
Tag storing field values on vertices in the field.
int fNBFACETRI_DEMKOWICZ_HCURL(int P)
FieldApproximationBase * tagBaseData
tag keeps field base
#define CHKERR
Inline error check.
Definition: definitions.h:596
int fNBFACETRI_H1(int P)
number of approx. functions for H1 space on face
DofsOrderMap dofOrderMap
unsigned int getBitNumberCalculate() const
Calculate number of set bit in Field ID. Each field has uid, get getBitNumber get number of bit set f...
unsigned int getBitNumber() const
Get number of set bit in Field ID. Each field has uid, get getBitNumber get number of bit set for giv...
int fNBVERTEX_HCURL(int P)
number of approx. functions for HCURL space on vertex
int fNBVOLUMETET_AINSWORTH_HCURL(int P)
static const bool IamNotPartitioned
#define MAX_DOFS_ON_ENTITY
Maximal number of DOFs on entity.
Definition: definitions.h:298
int tagNameSize
number of bits necessary to keep field name
int fNBVERTEX_H1(int P)
number of approx. functions for H1 space on vertex
moab::Interface & moab
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:407
continuous field
Definition: definitions.h:171
int fNBFACETRI_L2(int P)
#define MB_ID_WIDTH
Definition: definitions.h:289
int fNBENTITYSET_NOFIELD(int P)
int fNBVERTEX_HDIV(int P)
number of approx. functions for HDIV space on vertex
unsigned int bitNumber
Tag th_FieldData
Tag storing field values on entity in the field.
int fNBVOLUMETET_AINSWORTH_HDIV(int P)
number of approx. functions for HDIV space on volume
int fNBEDGE_HDIV(int P)
number of approx. functions for HDIV space on edge
BitFieldId * tagId
tag keeps field id
field with C-1 continuity
Definition: definitions.h:174