v0.8.14
EntsMultiIndices.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 <Common.hpp>
20 #include <Includes.hpp>
21 #include <definitions.h>
22 
23 #include <h1_hdiv_hcurl_l2.h>
24 
25 #include <BCData.hpp>
26 #include <CoordSysMultiIndices.hpp>
27 #include <DofsMultiIndices.hpp>
28 #include <EntsMultiIndices.hpp>
29 #include <FEMultiIndices.hpp>
30 #include <FieldMultiIndices.hpp>
31 #include <MaterialBlocks.hpp>
32 #include <TagMultiIndices.hpp>
33 
34 #define IS_BUILDING_MB
35 #include <moab/Error.hpp>
36 
37 namespace MoFEM {
38 
39 static moab::Error error;
40 
41 inline void *get_tag_ptr(moab::Interface &moab, Tag th, EntityHandle ent,
42  int *tag_size) {
43  ApproximationOrder *ret_val;
44  rval = moab.tag_get_by_ptr(th, &ent, 1, (const void **)&ret_val, tag_size);
45  if (rval != MB_SUCCESS) {
46  *tag_size = 0;
47  return NULL;
48  } else {
49  return ret_val;
50  }
51 }
52 
53 BasicEntityData::BasicEntityData(const moab::Interface &moab,
54  const int pcomm_id)
55  : moab(const_cast<moab::Interface &>(moab)), pcommID(pcomm_id),
56  distributedMesh(true) {
57  rval = moab.tag_get_handle("_RefParentHandle", th_RefParentHandle);
59  rval = moab.tag_get_handle("_RefBitLevel", th_RefBitLevel);
61 }
63 
64 // basic moab ent
66  const boost::shared_ptr<BasicEntityData> &basic_data_ptr,
67  const EntityHandle ent)
68  : basicDataPtr(basic_data_ptr), ent(ent) {
69  switch (getEntType()) {
70  case MBVERTEX:
71  case MBEDGE:
72  case MBTRI:
73  case MBQUAD:
74  case MBTET:
75  case MBPRISM:
76  case MBENTITYSET:
77  break;
78  default:
79  THROW_MESSAGE("this entity type is currently not implemented");
80  }
81  ParallelComm *pcomm =
82  ParallelComm::get_pcomm(&basicDataPtr->moab, basicDataPtr->pcommID);
83  if (pcomm == NULL)
84  THROW_MESSAGE("pcomm is null");
85  rval = pcomm->get_owner_handle(ent, owner_proc, moab_owner_handle);
88 }
89 
90 unsigned char BasicEntity::getPStatus() const {
91  ParallelComm *pcomm =
92  ParallelComm::get_pcomm(&basicDataPtr->moab, basicDataPtr->pcommID);
93  return *((unsigned char *)MoFEM::get_tag_ptr(
94  basicDataPtr->moab, pcomm->pstatus_tag(), ent, NULL));
95 }
96 
97 // ref moab ent
99 RefEntity::RefEntity(const boost::shared_ptr<BasicEntityData> &basic_data_ptr,
100  const EntityHandle ent)
101  : BasicEntity(basic_data_ptr, ent) {}
102 
104  return static_cast<EntityHandle *>(get_tag_ptr(
105  basicDataPtr->moab, basicDataPtr->th_RefParentHandle, ent, NULL));
106 }
107 
109  return static_cast<BitRefLevel *>(
110  get_tag_ptr(basicDataPtr->moab, basicDataPtr->th_RefBitLevel, ent, NULL));
111 }
112 
114  std::vector<EntityHandle> vec_patent_ent) {
115 
117  Tag th_ref_parent_handle;
118  CHKERR moab.tag_get_handle("_RefParentHandle", th_ref_parent_handle);
119  vec_patent_ent.resize(ents.size());
120  CHKERR moab.tag_get_data(th_ref_parent_handle, ents,
121  &*vec_patent_ent.begin());
123 }
124 
127  std::vector<BitRefLevel> &vec_bit_ref_level) {
128 
130  Tag th_ref_bit_level;
131  CHKERR moab.tag_get_handle("_RefBitLevel", th_ref_bit_level);
132  vec_bit_ref_level.resize(ents.size());
133  CHKERR moab.tag_get_data(th_ref_bit_level, ents, &*vec_bit_ref_level.begin());
135 }
136 
138  Interface &moab, Range ents,
139  std::vector<const BitRefLevel *> &vec_ptr_bit_ref_level) {
141  Tag th_ref_bit_level;
142  CHKERR moab.tag_get_handle("_RefBitLevel", th_ref_bit_level);
143  vec_ptr_bit_ref_level.resize(ents.size());
144  CHKERR moab.tag_get_by_ptr(
145  th_ref_bit_level, ents,
146  reinterpret_cast<const void **>(&*vec_ptr_bit_ref_level.begin()));
148 }
149 
150 std::ostream &operator<<(std::ostream &os, const RefEntity &e) {
151  os << "ent " << e.ent;
152  os << " pstatus " << std::bitset<8>(e.getPStatus());
153  os << " owner ent " << e.getOwnerEnt();
154  os << " owner proc " << e.getOwnerProc();
155  os << " parent ent " << e.getParentEnt();
156  // os << " BitRefLevel " << e.getBitRefLevel();
157  os << " ent type " << e.getEntType();
158  os << " ent parent type " << e.getParentEntType();
159  return os;
160 }
161 
162 // moab ent
163 FieldEntity::FieldEntity(const boost::shared_ptr<Field> &field_ptr,
164  const boost::shared_ptr<RefEntity> &ref_ent_ptr)
166  ref_ent_ptr) {
168  getDofOrderMap().resize(MAX_DOFS_ON_ENTITY, -1);
169 }
170 
172  return static_cast<ApproximationOrder *>(MoFEM::get_tag_ptr(
173  sFieldPtr->moab, sFieldPtr->th_AppOrder, sPtr->ent, NULL));
174 }
176  return *static_cast<ApproximationOrder *>(MoFEM::get_tag_ptr(
177  sFieldPtr->moab, sFieldPtr->th_AppOrder, sPtr->ent, NULL));
178 }
179 
181  int size = getNbDofsOnEnt();
182  int tag_size;
183  double *ptr = static_cast<double *>(MoFEM::get_tag_ptr(
184  sFieldPtr->moab, sFieldPtr->th_FieldData, sPtr->ent, &tag_size));
185  tag_size /= sizeof(FieldData);
186  return VectorAdaptor(size,
187  ublas::shallow_array_adaptor<FieldData>(tag_size, ptr));
188 }
189 
191 std::ostream &operator<<(std::ostream &os, const FieldEntity &e) {
192  os << "ent_global_uid "
193  << (UId)e.getGlobalUniqueId()
194  // << " ent_local_uid " << (UId)e.get_local_unique_id()
195  << " entity " << e.getEnt() << " type " << e.getEntType() << " pstatus "
196  << std::bitset<8>(e.getPStatus()) << " owner handle " << e.getOwnerEnt()
197  << " owner proc " << e.getOwnerProc() << " order " << e.getMaxOrder()
198  << " " << *e.sFieldPtr;
199  return os;
200 }
202  moab::Interface &moab = e->sPtr->basicDataPtr->moab;
203  *(e->getMaxOrderPtr()) = order;
204  unsigned int nb_dofs = e->getOrderNbDofs(order) * e->getNbOfCoeffs();
205  EntityHandle ent = e->getEnt();
206  // Get pointer and size of field values tag
207  double *tag_field_data;
208  int tag_field_data_size;
209  rval =
210  moab.tag_get_by_ptr(e->sFieldPtr->th_FieldData, &ent, 1,
211  (const void **)&tag_field_data, &tag_field_data_size);
212  // Tag exist and are some data on it
213  if (rval == MB_SUCCESS) {
214  // Check if size of filed values tag is correct
215  if (nb_dofs * sizeof(FieldData) <= (unsigned int)tag_field_data_size) {
216  return;
217  } else if (nb_dofs == 0) {
218  // Delete data on this entity
219  rval = moab.tag_delete_data(e->sFieldPtr->th_FieldData, &ent, 1);
220  MOAB_THROW(rval);
221  return;
222  }
223  // Size of tag is different than new seize, so copy data to new container
224  data.resize(tag_field_data_size / sizeof(FieldData));
225  FieldData *ptr_begin = (FieldData *)tag_field_data;
226  FieldData *ptr_end =
227  (FieldData *)tag_field_data + tag_field_data_size / sizeof(FieldData);
228  std::copy(ptr_begin, ptr_end, data.begin());
229  }
230  // Set new data
231  if (nb_dofs > 0) {
232  // Set field dof data
233  data.resize(nb_dofs, 0);
234  int tag_size[1];
235  tag_size[0] = data.size() * sizeof(FieldData);
236  void const *tag_data[] = {&data[0]};
237  rval = moab.tag_set_by_ptr(e->sFieldPtr->th_FieldData, &ent, 1, tag_data,
238  tag_size);
239  MOAB_THROW(rval);
240  rval = moab.tag_get_by_ptr(e->sFieldPtr->th_FieldData, &ent, 1,
241  (const void **)&tag_field_data,
242  &tag_field_data_size);
243  MOAB_THROW(rval);
244  if (nb_dofs != tag_field_data_size / sizeof(FieldData))
245  THROW_MESSAGE("Data inconsistency");
246  }
247 }
248 
249 } // namespace MoFEM
const BitRefLevel & getBitRefLevel() const
Get entity ref bit refinement signature.
unsigned char getPStatus() const
get pstatus This tag stores various aspects of parallel status in bits; see also define following...
boost::shared_ptr< RefEntity > sPtr
RefEntity(const boost::shared_ptr< BasicEntityData > &basic_data_ptr, const EntityHandle ent)
int getOrderNbDofs(int order) const
Get number of DOFs on entity for given order of approximation.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Common.hpp:60
Multi-index contains, for mofem entities data structures and other low-level functions.
Data structures for Meshset/Blocsk with material data.
this struct keeps basic methods for moab entity
MoFEMErrorCode getParentEnt(Interface &moab, Range ents, std::vector< EntityHandle > vec_patent_ent)
Provide data structure for (tensor) field approximation.The Field is intended to provide support for ...
double FieldData
Field data type.
Definition: Common.hpp:130
EntityHandle * getParentEntPtr() const
Get pointer to parent entity tag.
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:459
UId globalUid
Global unique id for this entity.
UId getGlobalUniqueIdCalculate() const
Calculate global UId.
Basic structures and data.
FieldCoefficientsNumber getNbOfCoeffs() const
std::bitset< BITREFEDGES_SIZE > BitRefEdges
Definition: Common.hpp:141
std::vector< ApproximationOrder > & getDofOrderMap() const
get hash-map relating dof index on entity with its order
BasicEntity(const boost::shared_ptr< BasicEntityData > &basic_data_ptr, const EntityHandle ent)
Tags for Multi-index containers.
#define THROW_MESSAGE(a)
Throw MoFEM exception.
Definition: definitions.h:602
Struct keeps handle to entity in the field.
#define MOAB_THROW(a)
Check error code of MoAB function and throw MoFEM exception.
Definition: definitions.h:584
Pointer interface for MoFEM::Field.
const UId & getGlobalUniqueId() const
Get global unique id.
Struct keeps handle to refined handle.
uint128_t UId
Unique Id.
Definition: Common.hpp:136
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
EntityHandle getOwnerEnt() const
VectorShallowArrayAdaptor< double > VectorAdaptor
Definition: Common.hpp:234
std::ostream & operator<<(std::ostream &os, const DataForcesAndSourcesCore::EntData &e)
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Common.hpp:147
ApproximationOrder getMaxOrder() const
Get order set to the entity (Allocated tag size for such number)
int part_proc
this can be changed on distributed
EntityType getEntType() const
Get entity type.
int owner_proc
this never can not be changed if distributed mesh
EntityHandle getOwnerEnt() const
Owner handle on this or other processors.
Coordinate systems attached to DOFs.
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
Definition: Common.hpp:78
ApproximationOrder * getMaxOrderPtr()
Get pinter to Tag keeping approximation order.
useful compiler directives and definitions
BasicEntityData(const moab::Interface &mfield, const int pcomm_id=MYPCOMM_INDEX)
static MoFEMErrorCode getParentEnt(Interface &moab, Range ents, std::vector< EntityHandle > vec_patent_ent)
EntityType getParentEntType() const
Get patent entity.
interface to RefEntity
static moab::Error error
Multi-index contains, data structures for mofem finite elements and other low-level functions...
EntityHandle moab_owner_handle
#define CHKERR
Inline error check.
Definition: definitions.h:578
Field data structure storing information about space, approximation base, coordinate systems...
unsigned char getPStatus() const
int ApproximationOrder
Approximation on the entity.
Definition: Common.hpp:131
void operator()(boost::shared_ptr< FieldEntity > &e)
Functions to approximate hierarchical spaces.
void * get_tag_ptr(moab::Interface &moab, Tag th, EntityHandle ent, int *tag_size)
#define MAX_DOFS_ON_ENTITY
Maximal number of DOFs on entity.
Definition: definitions.h:295
int getNbDofsOnEnt() const
Get number of active DOFs on entity.
EntityHandle getEnt() const
Get entity handle.
int getOwnerProc() const
Get processor owning entity.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:403
boost::shared_ptr< BasicEntityData > basicDataPtr
VectorAdaptor getEntFieldData() const
Get vector of DOFs active values on entity.
static BitRefEdges DummyBitRefEdges
boost::shared_ptr< Field > sFieldPtr
std::vector< FieldData > data
FieldEntity(const boost::shared_ptr< Field > &field_ptr, const boost::shared_ptr< RefEntity > &ref_ent_ptr)
Data structure with Cubit native blocks/meshet with boundary conditions.
Multi-Index contains, data structures for mofem dofs and other low-level functions.
BitRefLevel * getBitRefLevelPtr() const
Get pointer to bit ref level tag.