v0.13.1
Loading...
Searching...
No Matches
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
9namespace MoFEM {
10
11constexpr int FieldEntity::dof_shift; // Maximal number of DOFs on entity
12constexpr int FieldEntity::ent_shift; // EntityHandle size
13constexpr 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
35boost::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
54std::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);
132 rval = moab.tag_get_by_ptr(e->getFieldRawPtr()->th_FieldData, &ent, 1,
133 (const void **)&tag_field_data,
134 &tag_field_data_size);
136
137 } else {
138
139 rval =
140 moab.tag_delete_data(e->getFieldRawPtr()->th_FieldData, &ent, 1);
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
#define MOAB_THROW(err)
Check error code of MoAB function and throw MoFEM exception.
Definition: definitions.h:541
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
Definition: definitions.h:561
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
Definition: Exceptions.hpp:74
int ApproximationOrder
Approximation on the entity.
Definition: Types.hpp:26
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
std::ostream & operator<<(std::ostream &os, const EntitiesFieldData::EntData &e)
void * get_tag_ptr(moab::Interface &moab, Tag th, EntityHandle ent, int *tag_size)
Get the tag ptr object.
void operator()(boost::shared_ptr< FieldEntity > &e)
Struct keeps handle to entity in the field.
static constexpr int dof_shift
UId getLocalUniqueIdCalculate()
Get the Local Unique Id Calculate object.
boost::shared_ptr< FieldData *const > fieldDataAdaptorPtr
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.
static constexpr int proc_shift
boost::shared_ptr< FieldData *const > & getEntFieldDataPtr() const
Get shared ptr to vector adaptor pointing to the field tag data on entity.
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)
ApproximationOrder getMaxOrder() const
Get order set to the entity (Allocated tag size for such number)
const ApproximationOrder * getMaxOrderPtr() const
Get pinter to Tag keeping approximation order.
UId localUId
Global unique id for this entity.
static constexpr int ent_shift
const UId & getLocalUniqueId() const
Get global unique id.
int getOrderNbDofs(ApproximationOrder order) const
Get number of DOFs on entity for given order of approximation.
boost::shared_ptr< const ApproximationOrder > tagMaxOrderPtr
Provide data structure for (tensor) field approximation.
Tag th_FieldData
Tag storing field values on entity in the field.
Tag th_FieldDataVerts
Tag storing field values on vertices in the field.
TagType tagFieldDataVertsType
Struct keeps handle to refined handle.
FieldCoefficientsNumber getNbOfCoeffs() const
const Field * getFieldRawPtr() const
const char * getEntTypeName() const
EntityHandle getOwnerEnt() const
unsigned char getPStatus() const