v0.8.20
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 #define IS_BUILDING_MB
20 #include <moab/Error.hpp>
21 
22 namespace MoFEM {
23 
24 static moab::Error error;
25 
26 inline void *get_tag_ptr(moab::Interface &moab, Tag th, EntityHandle ent,
27  int *tag_size) {
28  ApproximationOrder *ret_val;
29  rval = moab.tag_get_by_ptr(th, &ent, 1, (const void **)&ret_val, tag_size);
30  if (rval != MB_SUCCESS) {
31  *tag_size = 0;
32  return NULL;
33  } else {
34  return ret_val;
35  }
36 }
37 
38 BasicEntityData::BasicEntityData(const moab::Interface &moab,
39  const int pcomm_id)
40  : moab(const_cast<moab::Interface &>(moab)), pcommID(pcomm_id),
41  distributedMesh(true) {
42  rval = moab.tag_get_handle("_RefParentHandle", th_RefParentHandle);
44  rval = moab.tag_get_handle("_RefBitLevel", th_RefBitLevel);
46 }
48 
49 // basic moab ent
51  const boost::shared_ptr<BasicEntityData> &basic_data_ptr,
52  const EntityHandle ent)
53  : basicDataPtr(basic_data_ptr), ent(ent) {
54  switch (getEntType()) {
55  case MBVERTEX:
56  case MBEDGE:
57  case MBTRI:
58  case MBQUAD:
59  case MBTET:
60  case MBPRISM:
61  case MBENTITYSET:
62  break;
63  default:
64  THROW_MESSAGE("this entity type is currently not implemented");
65  }
66  ParallelComm *pcomm =
67  ParallelComm::get_pcomm(&basicDataPtr->moab, basicDataPtr->pcommID);
68  if (pcomm == NULL)
69  THROW_MESSAGE("pcomm is null");
70  rval = pcomm->get_owner_handle(ent, owner_proc, moab_owner_handle);
73 }
74 
75 unsigned char BasicEntity::getPStatus() const {
76  ParallelComm *pcomm =
77  ParallelComm::get_pcomm(&basicDataPtr->moab, basicDataPtr->pcommID);
78  return *((unsigned char *)MoFEM::get_tag_ptr(
79  basicDataPtr->moab, pcomm->pstatus_tag(), ent, NULL));
80 }
81 
82 // ref moab ent
84 RefEntity::RefEntity(const boost::shared_ptr<BasicEntityData> &basic_data_ptr,
85  const EntityHandle ent)
86  : BasicEntity(basic_data_ptr, ent) {}
87 
89  return static_cast<EntityHandle *>(get_tag_ptr(
90  basicDataPtr->moab, basicDataPtr->th_RefParentHandle, ent, NULL));
91 }
92 
94  return static_cast<BitRefLevel *>(
95  get_tag_ptr(basicDataPtr->moab, basicDataPtr->th_RefBitLevel, ent, NULL));
96 }
97 
98 MoFEMErrorCode getParentEnt(moab::Interface &moab, Range ents,
99  std::vector<EntityHandle> vec_patent_ent) {
100 
102  Tag th_ref_parent_handle;
103  CHKERR moab.tag_get_handle("_RefParentHandle", th_ref_parent_handle);
104  vec_patent_ent.resize(ents.size());
105  CHKERR moab.tag_get_data(th_ref_parent_handle, ents,
106  &*vec_patent_ent.begin());
108 }
109 
111 RefEntity::getBitRefLevel(moab::Interface &moab, Range ents,
112  std::vector<BitRefLevel> &vec_bit_ref_level) {
113 
115  Tag th_ref_bit_level;
116  CHKERR moab.tag_get_handle("_RefBitLevel", th_ref_bit_level);
117  vec_bit_ref_level.resize(ents.size());
118  CHKERR moab.tag_get_data(th_ref_bit_level, ents, &*vec_bit_ref_level.begin());
120 }
121 
123  moab::Interface &moab, Range ents,
124  std::vector<const BitRefLevel *> &vec_ptr_bit_ref_level) {
126  Tag th_ref_bit_level;
127  CHKERR moab.tag_get_handle("_RefBitLevel", th_ref_bit_level);
128  vec_ptr_bit_ref_level.resize(ents.size());
129  CHKERR moab.tag_get_by_ptr(
130  th_ref_bit_level, ents,
131  reinterpret_cast<const void **>(&*vec_ptr_bit_ref_level.begin()));
133 }
134 
135 std::ostream &operator<<(std::ostream &os, const RefEntity &e) {
136  os << "ent " << e.ent;
137  os << " pstatus " << std::bitset<8>(e.getPStatus());
138  os << " owner ent " << e.getOwnerEnt();
139  os << " owner proc " << e.getOwnerProc();
140  os << " parent ent " << e.getParentEnt();
141  // os << " BitRefLevel " << e.getBitRefLevel();
142  os << " ent type " << e.getEntType();
143  os << " ent parent type " << e.getParentEntType();
144  return os;
145 }
146 
147 // moab ent
148 FieldEntity::FieldEntity(const boost::shared_ptr<Field> &field_ptr,
149  const boost::shared_ptr<RefEntity> &ref_ent_ptr)
151  ref_ent_ptr) {
153  getDofOrderMap().resize(MAX_DOFS_ON_ENTITY, -1);
154 }
155 
157  return static_cast<ApproximationOrder *>(MoFEM::get_tag_ptr(
158  sFieldPtr->moab, sFieldPtr->th_AppOrder, sPtr->ent, NULL));
159 }
161  return *static_cast<ApproximationOrder *>(MoFEM::get_tag_ptr(
162  sFieldPtr->moab, sFieldPtr->th_AppOrder, sPtr->ent, NULL));
163 }
164 
169 
172  getEntFieldDataLastUid = const_cast<UId *>(&globalUId);
173  switch (getEntType()) {
174  case MBVERTEX:
177  getEntFieldDataLastPtr = static_cast<double *>(MoFEM::get_tag_ptr(
178  sFieldPtr->moab, sFieldPtr->th_FieldDataVerts, sPtr->ent, NULL));
179  break;
180  default:
182  getEntFieldDataLastPtr = static_cast<double *>(
183  MoFEM::get_tag_ptr(sFieldPtr->moab, sFieldPtr->th_FieldData,
186  }
187  }
189  ublas::shallow_array_adaptor<double>(
191 }
192 
194 std::ostream &operator<<(std::ostream &os, const FieldEntity &e) {
195  os << "ent_global_uid "
196  << (UId)e.getGlobalUniqueId()
197  // << " ent_local_uid " << (UId)e.get_local_unique_id()
198  << " entity " << e.getEnt() << " type " << e.getEntType() << " pstatus "
199  << std::bitset<8>(e.getPStatus()) << " owner handle " << e.getOwnerEnt()
200  << " owner proc " << e.getOwnerProc() << " order " << e.getMaxOrder()
201  << " " << *e.sFieldPtr;
202  return os;
203 }
204 
206 
207  moab::Interface &moab = e->sPtr->basicDataPtr->moab;
208  const EntityHandle ent = e->getEnt();
209  *(e->getMaxOrderPtr()) = order;
210  unsigned int nb_dofs = e->getOrderNbDofs(order) * e->getNbOfCoeffs();
211 
212  double *tag_field_data;
213  int tag_field_data_size;
214 
215  switch (e->getEntType()) {
216  case MBVERTEX: {
217  if (e->sFieldPtr->th_FieldDataVertsType == MB_TAG_SPARSE) {
218  // Get pointer and size of field values tag
219  rval = moab.tag_get_by_ptr(e->sFieldPtr->th_FieldDataVerts, &ent, 1,
220  (const void **)&tag_field_data,
221  &tag_field_data_size);
222  if (nb_dofs) {
223  if (nb_dofs != tag_field_data_size) {
224 
225  rval = moab.tag_set_data(e->sFieldPtr->th_FieldDataVerts, &ent, 1,
226  &*data.begin());
227  MOAB_THROW(rval);
228  }
229  } else if (rval == MB_SUCCESS) {
230  rval = moab.tag_delete_data(e->sFieldPtr->th_FieldDataVerts, &ent, 1);
231  MOAB_THROW(rval);
232  }
233  } else {
234  rval = moab.tag_get_by_ptr(e->sFieldPtr->th_FieldDataVerts, &ent, 1,
235  (const void **)&tag_field_data);
236  MOAB_THROW(rval);
237  rval = moab.tag_set_data(e->sFieldPtr->th_FieldDataVerts, &ent, 1,
238  tag_field_data);
239  MOAB_THROW(rval);
240  }
241  } break;
242  default: {
243  // Get pointer and size of field values tag
244  rval = moab.tag_get_by_ptr(e->sFieldPtr->th_FieldData, &ent, 1,
245  (const void **)&tag_field_data,
246  &tag_field_data_size);
247  // Tag exist and are some data on it
248  if (rval == MB_SUCCESS) {
249  // Check if size of filed values tag is correct
250  if (nb_dofs * sizeof(FieldData) <= (unsigned int)tag_field_data_size)
251  return;
252  else if (nb_dofs == 0) {
253  // Delete data on this entity
254  rval = moab.tag_delete_data(e->sFieldPtr->th_FieldData, &ent, 1);
255  MOAB_THROW(rval);
256  return;
257  }
258  // Size of tag is different than new seize, so copy data to new
259  // container
260  data.resize(tag_field_data_size / sizeof(FieldData));
261  FieldData *ptr_begin = (FieldData *)tag_field_data;
262  FieldData *ptr_end =
263  (FieldData *)tag_field_data + tag_field_data_size / sizeof(FieldData);
264  std::copy(ptr_begin, ptr_end, data.begin());
265  }
266  // Set new data
267  if (nb_dofs > 0) {
268  // Set field dof data
269  data.resize(nb_dofs, 0);
270  int tag_size[1];
271  tag_size[0] = data.size() * sizeof(FieldData);
272  void const *tag_data[] = {&data[0]};
273  rval = moab.tag_set_by_ptr(e->sFieldPtr->th_FieldData, &ent, 1, tag_data,
274  tag_size);
275  MOAB_THROW(rval);
276  rval = moab.tag_get_by_ptr(e->sFieldPtr->th_FieldData, &ent, 1,
277  (const void **)&tag_field_data,
278  &tag_field_data_size);
279  MOAB_THROW(rval);
280  if (nb_dofs != tag_field_data_size / sizeof(FieldData))
281  THROW_MESSAGE("Data inconsistency");
282  }
283  }
284  }
285 }
286 
287 // FEFieldEntity::FEFieldEntity(
288 // const boost::shared_ptr<SideNumber> &side_number_ptr,
289 // const boost::shared_ptr<FieldEntity> &entity_ptr)
290 // : BaseFEEntity(side_number_ptr), interface_FieldEntity<FieldEntity>(
291 // entity_ptr) {}
292 
293 } // 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.
this struct keeps basic methods for moab entity
Provide data structure for (tensor) field approximation.The Field is intended to provide support for ...
int ApproximationOrder
Approximation on the entity.
Definition: Types.hpp:37
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:475
UId getGlobalUniqueIdCalculate() const
Calculate global UId.
FieldCoefficientsNumber getNbOfCoeffs() const
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)
#define THROW_MESSAGE(a)
Throw MoFEM exception.
Definition: definitions.h:618
Struct keeps handle to entity in the field.
UId globalUId
Global unique id for this entity.
static double * getEntFieldDataLastPtr
#define MOAB_THROW(a)
Check error code of MoAB function and throw MoFEM exception.
Definition: definitions.h:600
Pointer interface for MoFEM::Field.
const UId & getGlobalUniqueId() const
Get global unique id.
Struct keeps handle to refined handle.
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
MoFEMErrorCode getParentEnt(moab::Interface &moab, Range ents, std::vector< EntityHandle > vec_patent_ent)
EntityHandle getOwnerEnt() const
std::bitset< BITREFEDGES_SIZE > BitRefEdges
Definition: Types.hpp:45
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
Definition: Exceptions.hpp:84
std::ostream & operator<<(std::ostream &os, const DataForcesAndSourcesCore::EntData &e)
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.
ApproximationOrder * getMaxOrderPtr()
Get pinter to Tag keeping approximation order.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:66
BasicEntityData(const moab::Interface &mfield, const int pcomm_id=MYPCOMM_INDEX)
static MoFEMErrorCode getParentEnt(Interface &moab, Range ents, std::vector< EntityHandle > vec_patent_ent)
VectorShallowArrayAdaptor< double > VectorAdaptor
Definition: Types.hpp:99
static int getEntFieldDataLastSize
EntityType getParentEntType() const
Get patent entity.
interface to RefEntity
static moab::Error error
EntityHandle moab_owner_handle
#define CHKERR
Inline error check.
Definition: definitions.h:594
double FieldData
Field data type.
Definition: Types.hpp:36
unsigned char getPStatus() const
void operator()(boost::shared_ptr< FieldEntity > &e)
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:51
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:296
int getNbDofsOnEnt() const
Get number of active DOFs on entity.
EntityHandle getEnt() const
Get entity handle.
static int getEntFieldDataLastTagSize
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:405
boost::shared_ptr< BasicEntityData > basicDataPtr
VectorAdaptor getEntFieldData() const
Get vector of DOFs active values on entity.
static BitRefEdges DummyBitRefEdges
uint128_t UId
Unique Id.
Definition: Types.hpp:41
boost::shared_ptr< Field > sFieldPtr
static UId * getEntFieldDataLastUid
std::vector< FieldData > data
FieldEntity(const boost::shared_ptr< Field > &field_ptr, const boost::shared_ptr< RefEntity > &ref_ent_ptr)
BitRefLevel * getBitRefLevelPtr() const
Get pointer to bit ref level tag.