v0.14.0
FieldEntsMultiIndices.cpp
Go to the documentation of this file.
1 /** \file FieldEntsMultiIndices.cpp
2  * \brief Multi-index containers for entities
3  */
4 
5 
6 #define IS_BUILDING_MB
7 #include <moab/Error.hpp>
8 
9 namespace MoFEM {
10 
11 constexpr int FieldEntity::dof_shift; // Maximal number of DOFs on entity
12 constexpr int FieldEntity::ent_shift; // EntityHandle size
13 constexpr int FieldEntity::proc_shift; // Maximal number of 1024 processors
14 
16  const boost::shared_ptr<Field> field_ptr,
17  const boost::shared_ptr<RefEntity> ref_ents_ptr,
18  boost::shared_ptr<double *const> field_data_adaptor_ptr,
19  boost::shared_ptr<const int> t_max_order_ptr)
20  : interface_Field<Field, RefEntity>(field_ptr, ref_ents_ptr),
21  tagMaxOrderPtr(t_max_order_ptr),
22  fieldDataAdaptorPtr(field_data_adaptor_ptr) {
23 
24  localUId = getLocalUniqueIdCalculate(field_ptr->getBitNumber(),
25  ref_ents_ptr->getEnt());
26 #ifndef NDEBUG
27  if (PetscUnlikely(!fieldDataAdaptorPtr))
28  THROW_MESSAGE("Pointer to field data adaptor not set");
29 
30  if (PetscUnlikely(!tagMaxOrderPtr))
31  THROW_MESSAGE("Pointer to max order not set");
32 #endif
33 }
34 
35 boost::shared_ptr<FieldData *const> FieldEntity::makeSharedFieldDataAdaptorPtr(
36  const boost::shared_ptr<Field> &field_ptr,
37  const boost::shared_ptr<RefEntity> &ref_ents_ptr) {
38  int size;
39  FieldData *ptr;
40  switch (ref_ents_ptr->getEntType()) {
41  case MBVERTEX:
42  size = field_ptr->getNbOfCoeffs();
43  ptr = static_cast<FieldData *>(
44  MoFEM::get_tag_ptr(field_ptr->moab, field_ptr->th_FieldDataVerts,
45  ref_ents_ptr->ent, &size));
46  break;
47  default:
48  ptr = static_cast<FieldData *>(MoFEM::get_tag_ptr(
49  field_ptr->moab, field_ptr->th_FieldData, ref_ents_ptr->ent, &size));
50  }
51  return boost::make_shared<FieldData *const>(ptr);
52 }
53 
54 std::ostream &operator<<(std::ostream &os, const FieldEntity &e) {
55  os << "ent_global_uid " << e.getLocalUniqueId() << " entity " << e.getEnt()
56  << " type " << e.getEntTypeName() << " pstatus "
57  << std::bitset<8>(e.getPStatus()) << " owner handle " << e.getOwnerEnt()
58  << " owner proc " << e.getOwnerProc() << " order " << e.getMaxOrder()
59  << " " << *e.getFieldRawPtr();
60  return os;
61 }
62 
64 
65  moab::Interface &moab = e->sPtr->getBasicDataPtr()->moab;
66  const EntityHandle ent = e->getEnt();
67  *const_cast<ApproximationOrder *>(e->getMaxOrderPtr()) = order;
68  std::size_t nb_dofs = e->getOrderNbDofs(order) * e->getNbOfCoeffs();
69 
70  double *tag_field_data = nullptr;
71  int tag_field_data_size = 0;
72 
73  auto set_verts = [&]() {
74  if (e->getFieldRawPtr()->tagFieldDataVertsType == MB_TAG_SPARSE) {
75  // Get pointer and size of field values tag
76  rval = moab.tag_get_by_ptr(e->getFieldRawPtr()->th_FieldDataVerts, &ent,
77  1, (const void **)&tag_field_data,
78  &tag_field_data_size);
79  if (nb_dofs) {
80  if (nb_dofs != tag_field_data_size) {
81  rval = moab.tag_set_data(e->getFieldRawPtr()->th_FieldDataVerts, &ent,
82  1, &*data.begin());
84  }
85  } else if (rval == MB_SUCCESS) {
86  rval = moab.tag_delete_data(e->getFieldRawPtr()->th_FieldDataVerts,
87  &ent, 1);
89  }
90  } else {
91  rval = moab.tag_get_by_ptr(e->getFieldRawPtr()->th_FieldDataVerts, &ent,
92  1, (const void **)&tag_field_data);
94  rval = moab.tag_set_data(e->getFieldRawPtr()->th_FieldDataVerts, &ent, 1,
95  tag_field_data);
97  }
98  };
99 
100  auto set_default = [&]() {
101  if (reduceTagSize || nb_dofs) {
102 
103  // Get pointer and size of field values tag
104  rval = moab.tag_get_by_ptr(e->getFieldRawPtr()->th_FieldData, &ent, 1,
105  (const void **)&tag_field_data,
106  &tag_field_data_size);
107 
108  if ((reduceTagSize && nb_dofs != tag_field_data_size) ||
109  nb_dofs > tag_field_data_size) {
110 
111  // Tag exist and are some data on it
112  if (rval == MB_SUCCESS) {
113  // Size of tag is different than new size, so copy data to new
114  // container
115  data.resize(tag_field_data_size);
116  FieldData *ptr_begin = static_cast<FieldData *>(tag_field_data);
117  FieldData *ptr_end =
118  static_cast<FieldData *>(tag_field_data) + tag_field_data_size;
119  std::copy(ptr_begin, ptr_end, data.begin());
120  }
121 
122  if (rval != MB_SUCCESS || nb_dofs) {
123 
124  // Set field dof data
125  data.resize(nb_dofs, 0);
126  int tag_size[1];
127  tag_size[0] = data.size();
128  void const *tag_data[] = {&data[0]};
129  rval = moab.tag_set_by_ptr(e->getFieldRawPtr()->th_FieldData, &ent, 1,
130  tag_data, tag_size);
131  MOAB_THROW(rval);
132  rval = moab.tag_get_by_ptr(e->getFieldRawPtr()->th_FieldData, &ent, 1,
133  (const void **)&tag_field_data,
134  &tag_field_data_size);
135  MOAB_THROW(rval);
136 
137  } else {
138 
139  rval =
140  moab.tag_delete_data(e->getFieldRawPtr()->th_FieldData, &ent, 1);
141  MOAB_THROW(rval);
142  }
143  }
144  }
145  };
146 
147  switch (e->getEntType()) {
148  case MBVERTEX:
149  set_verts();
150  break;
151  default:
152  set_default();
153  }
154 
155  if (nb_dofs)
156  const_cast<double *&>(*(e->getEntFieldDataPtr())) = tag_field_data;
157  else
158  const_cast<double *&>(*(e->getEntFieldDataPtr())) = nullptr;
159 }
160 
161 } // namespace MoFEM
MoFEM::operator<<
std::ostream & operator<<(std::ostream &os, const EntitiesFieldData::EntData &e)
Definition: EntitiesFieldData.cpp:240
MoFEM::Field::tagFieldDataVertsType
TagType tagFieldDataVertsType
Definition: FieldMultiIndices.hpp:75
MoFEM::get_tag_ptr
void * get_tag_ptr(moab::Interface &moab, Tag th, EntityHandle ent, int *tag_size)
Get the tag ptr object.
Definition: RefEntsMultiIndices.hpp:40
EntityHandle
MoFEM::FieldEntity::getOrderNbDofs
int getOrderNbDofs(ApproximationOrder order) const
Get number of DOFs on entity for given order of approximation.
Definition: FieldEntsMultiIndices.hpp:86
MoFEM::FieldEntity_change_order::order
const ApproximationOrder order
Definition: FieldEntsMultiIndices.hpp:405
MoFEM::RefEntityTmp< 0 >
Struct keeps handle to refined handle.
Definition: RefEntsMultiIndices.hpp:141
MoFEM::interface_RefEntity::sPtr
boost::shared_ptr< T > sPtr
Definition: RefEntsMultiIndices.hpp:711
MoFEM::Field::th_FieldData
Tag th_FieldData
Tag storing field values on entity in the field.
Definition: FieldMultiIndices.hpp:77
MoFEM::interface_RefEntity::getEnt
EntityHandle getEnt() const
Get the entity handle.
Definition: RefEntsMultiIndices.hpp:603
MOAB_THROW
#define MOAB_THROW(err)
Check error code of MoAB function and throw MoFEM exception.
Definition: definitions.h:554
MoFEM::interface_RefEntity::getPStatus
unsigned char getPStatus() const
Definition: RefEntsMultiIndices.hpp:690
THROW_MESSAGE
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
Definition: definitions.h:574
MoFEM::FieldEntity::getEntFieldDataPtr
boost::shared_ptr< FieldData *const > & getEntFieldDataPtr() const
Get shared ptr to vector adaptor pointing to the field tag data on entity.
Definition: FieldEntsMultiIndices.hpp:69
MoFEM::Field
Provide data structure for (tensor) field approximation.
Definition: FieldMultiIndices.hpp:51
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:2010
MoFEM::interface_RefEntity::getEntTypeName
const char * getEntTypeName() const
Get the Ent Type Name.
Definition: RefEntsMultiIndices.hpp:653
MoFEM::Exceptions::rval
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
Definition: Exceptions.hpp:74
MoFEM::FieldEntity_change_order::reduceTagSize
const bool reduceTagSize
Definition: FieldEntsMultiIndices.hpp:406
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::Field::th_FieldDataVerts
Tag th_FieldDataVerts
Tag storing field values on vertices in the field.
Definition: FieldMultiIndices.hpp:76
MoFEM::FieldEntity::makeSharedFieldDataAdaptorPtr
static boost::shared_ptr< FieldData *const > makeSharedFieldDataAdaptorPtr(const boost::shared_ptr< Field > &field_ptr, const boost::shared_ptr< RefEntity > &ref_ents_ptr)
Return shared pointer to entity field data vector adaptor.
Definition: FieldEntsMultiIndices.cpp:35
double
MoFEM::FieldEntity::getLocalUniqueIdCalculate
UId getLocalUniqueIdCalculate()
Get the Local Unique Id Calculate object.
Definition: FieldEntsMultiIndices.hpp:136
MoFEM::FieldEntity::tagMaxOrderPtr
boost::shared_ptr< const ApproximationOrder > tagMaxOrderPtr
Definition: FieldEntsMultiIndices.hpp:299
MoFEM::FieldEntity
Struct keeps handle to entity in the field.
Definition: FieldEntsMultiIndices.hpp:24
MoFEM::interface_RefEntity::getOwnerProc
int getOwnerProc() const
Definition: RefEntsMultiIndices.hpp:675
MoFEM::FieldEntity::FieldEntity
FieldEntity(const boost::shared_ptr< Field > field_ptr, const boost::shared_ptr< RefEntity > ref_ents_ptr, boost::shared_ptr< double *const > field_data_adaptor_ptr, boost::shared_ptr< const int > t_max_order_ptr)
Definition: FieldEntsMultiIndices.cpp:15
MoFEM::interface_Field::getNbOfCoeffs
FieldCoefficientsNumber getNbOfCoeffs() const
Definition: FieldMultiIndices.hpp:381
MoFEM::FieldEntity::proc_shift
static constexpr int proc_shift
Definition: FieldEntsMultiIndices.hpp:303
MoFEM::FieldEntity::fieldDataAdaptorPtr
boost::shared_ptr< FieldData *const > fieldDataAdaptorPtr
Definition: FieldEntsMultiIndices.hpp:300
MoFEM::FieldEntity_change_order::operator()
void operator()(boost::shared_ptr< FieldEntity > &e)
Definition: FieldEntsMultiIndices.hpp:399
MoFEM::FieldEntity::getMaxOrder
ApproximationOrder getMaxOrder() const
Get order set to the entity (Allocated tag size for such number)
Definition: FieldEntsMultiIndices.hpp:111
MoFEM::Types::ApproximationOrder
int ApproximationOrder
Approximation on the entity.
Definition: Types.hpp:26
MoFEM::FieldEntity::ent_shift
static constexpr int ent_shift
Definition: FieldEntsMultiIndices.hpp:302
MoFEM::FieldEntity::dof_shift
static constexpr int dof_shift
Definition: FieldEntsMultiIndices.hpp:301
MoFEM::FieldEntity::getMaxOrderPtr
const ApproximationOrder * getMaxOrderPtr() const
Get pinter to Tag keeping approximation order.
Definition: FieldEntsMultiIndices.hpp:103
MoFEM::interface_RefEntity::getEntType
EntityType getEntType() const
Get entity type.
Definition: RefEntsMultiIndices.hpp:643
MoFEM::FieldEntity_change_order::data
std::vector< FieldData > data
Definition: FieldEntsMultiIndices.hpp:407
MoFEM::interface_Field::getFieldRawPtr
const Field * getFieldRawPtr() const
Definition: FieldMultiIndices.hpp:403
MoFEM::interface_RefEntity::getOwnerEnt
EntityHandle getOwnerEnt() const
Definition: RefEntsMultiIndices.hpp:665
MoFEM::interface_Field
Definition: FieldMultiIndices.hpp:330
MoFEM::FieldEntity::localUId
UId localUId
Local unique id for this entity. Unique on CPU partition.
Definition: FieldEntsMultiIndices.hpp:37
MoFEM::FieldEntity::getLocalUniqueId
const UId & getLocalUniqueId() const
Get global unique id.
Definition: FieldEntsMultiIndices.hpp:150