v0.8.23
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 
101  auto set_entity_order_table = [&]() {
102  switch (*tagBaseData) {
105  switch (*tagSpaceData) {
106  case H1:
107  forderTable[MBVERTEX] = fNBVERTEX_H1;
108  forderTable[MBEDGE] = fNBEDGE_H1;
109  forderTable[MBTRI] = fNBFACETRI_H1;
110  forderTable[MBQUAD] = fNBFACEQUAD_H1;
111  forderTable[MBTET] = fNBVOLUMETET_H1;
112  forderTable[MBPRISM] = fNBVOLUMEPRISM_H1;
113  break;
114  case HCURL:
115  forderTable[MBVERTEX] = fNBVERTEX_HCURL;
119  break;
120  case HDIV:
121  forderTable[MBVERTEX] = fNBVERTEX_HDIV;
122  forderTable[MBEDGE] = fNBEDGE_HDIV;
125  break;
126  case L2:
127  forderTable[MBVERTEX] = fNBVERTEX_L2;
128  forderTable[MBEDGE] = fNBEDGE_L2;
129  forderTable[MBTRI] = fNBFACETRI_L2;
130  forderTable[MBTET] = fNBVOLUMETET_L2;
131  break;
132  case NOFIELD:
133  for (EntityType t = MBVERTEX; t < MBMAXTYPE; t++) {
134  // Concept of approximation order make no sense if there is no field
136  }
137  break;
138  default:
139  THROW_MESSAGE("unknown approximation space");
140  }
141  break;
143  switch (*tagSpaceData) {
144  case HCURL:
145  forderTable[MBVERTEX] = fNBVERTEX_HCURL;
149  break;
150  case HDIV:
151  forderTable[MBVERTEX] = fNBVERTEX_HDIV;
152  forderTable[MBEDGE] = fNBEDGE_HDIV;
155  break;
156  default:
157  THROW_MESSAGE("unknown approximation space or not yet implemented");
158  }
159  break;
161  THROW_MESSAGE("AINSWORTH_BERNSTEIN_BEZIER_BASE not implemented yer")
162  break;
163  case USER_BASE:
164  for (int ee = 0; ee < MBMAXTYPE; ee++) {
166  }
167  break;
168  default:
169  if (*tagSpaceData != NOFIELD) {
170  THROW_MESSAGE("unknown approximation base");
171  } else {
172  for (EntityType t = MBVERTEX; t < MBMAXTYPE; t++) {
174  }
175  }
176  }
177  };
178 
179  reset_entity_order_table();
180  set_entity_order_table();
182  CHKERRABORT(PETSC_COMM_SELF, ierr);
183 };
184 
187 
188  for (auto t = MBVERTEX; t != MBMAXTYPE; ++t) {
189 
190  int DD = 0;
191  int nb_last_order_dofs = 0;
192  const int rank = (*tagNbCoeffData);
193 
194  if (forderTable[t]) {
195 
196  for (int oo = 0; oo < MAX_DOFS_ON_ENTITY; ++oo) {
197 
198  const int nb_order_dofs = forderTable[t](oo);
199  const int diff_oo = nb_order_dofs - nb_last_order_dofs;
200  if (diff_oo >= 0) {
201 
202  if ((DD + rank * diff_oo) < MAX_DOFS_ON_ENTITY)
203  for (int dd = 0; dd < diff_oo; ++dd)
204  for (int rr = 0; rr != rank; ++rr, ++DD)
205  dofOrderMap[t][DD] = oo;
206  else
207  break;
208 
209  nb_last_order_dofs = nb_order_dofs;
210 
211  } else {
212  break;
213  }
214  }
215  }
216 
217  std::fill(&dofOrderMap[t][DD], dofOrderMap[t].end(), -1);
218  }
219 
221 }
222 
223 std::ostream &operator<<(std::ostream &os, const Field &e) {
224  os << "name " << e.getNameRef() << " BitFieldId " << e.getId().to_ulong()
225  << " bit number " << e.getBitNumber() << " space "
226  << FieldSpaceNames[e.getSpace()] << " approximation base "
227  << ApproximationBaseNames[e.getApproxBase()] << " rank "
228  << e.getNbOfCoeffs() << " meshset " << e.meshSet;
229  return os;
230 }
231 
232 // FieldEntityEntFiniteElementAdjacencyMap
235  const boost::shared_ptr<FieldEntity> &ent_field_ptr,
236  const boost::shared_ptr<EntFiniteElement> &ent_fe_ptr)
237  : byWhat(0), entFieldPtr(ent_field_ptr), entFePtr(ent_fe_ptr) {}
238 
239 std::ostream &operator<<(std::ostream &os,
241  os << "byWhat " << std::bitset<3>(e.byWhat) << " " << *e.entFieldPtr
242  << std::endl
243  << *e.entFePtr->sFePtr;
244  return os;
245 }
246 
247 MoFEMErrorCode test_moab(moab::Interface &moab, const EntityHandle ent) {
249  // tets type
250  EntityType type = (EntityType)((ent & MB_TYPE_MASK) >> MB_ID_WIDTH);
251  if (type != moab.type_from_handle(ent))
252  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
253  "inconsistencies with type_from_handle");
254  // tets id
255  EntityID id = (EntityType)(ent & MB_ID_MASK);
256  if (id != moab.id_from_handle(ent))
257  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
258  "inconsistencies with id_from_handle");
260 }
261 
262 } // 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:145
#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