v0.14.0
Loading...
Searching...
No Matches
FieldEntsMultiIndices.hpp
Go to the documentation of this file.
1/** \file FieldEntsMultiIndices.hpp
2 * \brief Multi-index contains, for mofem entities data structures and other
3 * low-level functions
4 */
5
6
7
8#ifndef __FIELD_ENTSMULTIINDICES_HPP__
9#define __FIELD_ENTSMULTIINDICES_HPP__
10
11namespace MoFEM {
12
13struct EntityCacheDofs;
15
17 virtual ~EntityStorage() = default;
18};
19
20/**
21 * \brief Struct keeps handle to entity in the field.
22 * \ingroup ent_multi_indices
23 */
24struct FieldEntity : public interface_Field<Field, RefEntity> {
25
28
29 /**
30 * @brief Local unique id for this entity. Unique on CPU partition.
31 *
32 * @note Global UId use entity handle from owning processor, so is unique
33 * across all CPUs. Local UId, uses local entity handle. Local id is
34 * convenient to use, is easley accessible from MOAB.
35 *
36 */
38
39 FieldEntity(const boost::shared_ptr<Field> field_ptr,
40 const boost::shared_ptr<RefEntity> ref_ents_ptr,
41 boost::shared_ptr<double *const> field_data_adaptor_ptr,
42 boost::shared_ptr<const int> t_max_order_ptr);
43
44 virtual ~FieldEntity() = default;
45
46 /**
47 * \brief Get number of active DOFs on entity
48 * @return Number of DOFs
49 */
50 inline int getNbDofsOnEnt() const {
51 return getOrderNbDofs(getMaxOrder()) * this->getNbOfCoeffs();
52 }
53
54 /**
55 * @brief Return shared pointer to entity field data vector adaptor
56 *
57 * @return boost::shared_ptr<VectorAdaptor>
58 */
59 static boost::shared_ptr<FieldData *const> makeSharedFieldDataAdaptorPtr(
60 const boost::shared_ptr<Field> &field_ptr,
61 const boost::shared_ptr<RefEntity> &ref_ents_ptr);
62
63 /**
64 * @brief Get shared ptr to vector adaptor pointing to the field tag data on
65 * entity
66 *
67 * @return boost::shared_ptr<VectorAdaptor>&
68 */
69 inline boost::shared_ptr<FieldData *const> &getEntFieldDataPtr() const {
71 }
72
73 /**
74 * \brief Get vector of DOFs active values on entity
75 * @return Vector of DOFs values
76 */
80
81 /**
82 * \brief Get number of DOFs on entity for given order of approximation
83 * @param order Order of approximation
84 * @return Number of DOFs
85 */
87 return (this->getFieldRawPtr()->forderTable[this->getEntType()])(order);
88 }
89
90 /**
91 * \brief Get difference of number of DOFs between order and order-1
92 * @param order Approximation order
93 * @return Difference number of DOFs
94 */
98
99 /**
100 * \brief Get pinter to Tag keeping approximation order
101 * @return Pointer to Tag
102 */
103 inline const ApproximationOrder *getMaxOrderPtr() const {
104 return tagMaxOrderPtr.get();
105 }
106
107 /**
108 * \brief Get order set to the entity (Allocated tag size for such number)
109 * @return Approximation order
110 */
112 return *tagMaxOrderPtr.get();
113 }
114
115 /**
116 * @brief Get the Local Unique Id Calculate
117 *
118 * @param bit_number
119 * @param handle
120 * @return UId
121 */
122 static inline UId getLocalUniqueIdCalculate(const char bit_number,
123 const EntityHandle handle) {
124 return
125
126 (static_cast<UId>(handle) << proc_shift | static_cast<UId>(bit_number)
128 << dof_shift;
129 }
130
131 /**
132 * @brief Get the Local Unique Id Calculate object
133 *
134 * @return UId
135 */
137 return getLocalUniqueIdCalculate(this->getBitNumber(), this->getEnt());
138 }
139
140 /**
141 * \brief Get global unique id
142 * @return Global UId
143 */
145
146 /**
147 * \brief Get global unique id
148 * @return Global UId
149 */
150 const UId &getLocalUniqueId() const { return localUId; }
151
152 /**
153 * \brief Calculate UId for field entity
154 *
155 * UId is constructed such that all DOFs are ordered by processor, entity,
156 * field.
157 *
158 * UId is 128 bit
159 *
160 * @param owner_proc owning processor
161 * @param bit_number field bit number
162 * @param moab_owner_handle entity handle on owning processor
163 * meshes
164 * @return UId
165 */
166 static inline UId
167 getGlobalUniqueIdCalculate(const int owner_proc, const char bit_number,
168 const EntityHandle moab_owner_handle) {
169 return
170
171 (static_cast<UId>(owner_proc) |
172 static_cast<UId>(moab_owner_handle) << proc_shift |
173 static_cast<UId>(bit_number) << proc_shift + ent_shift)
174 << dof_shift;
175 }
176
177 static inline auto getOwnerFromUniqueId(const UId uid) {
178 constexpr int proc_mask = MAX_PROCESSORS_NUMBER - 1;
179 return static_cast<int>(
180
181 (uid & getGlobalUniqueIdCalculate(proc_mask, 0, 0)) >> dof_shift
182
183 );
184 };
185
186 /**
187 * @brief Get the Handle From Unique Id
188 *
189 * @param uid
190 * @return EntityHandle
191 */
192 static inline auto getHandleFromUniqueId(const UId uid) {
193 constexpr EntityHandle handle_mask = ~(EntityHandle(0));
194 return static_cast<EntityHandle>(
195 (uid & getGlobalUniqueIdCalculate(0, 0, handle_mask)) >> proc_shift >>
196 dof_shift);
197 };
198
199 /**
200 * @brief Get the Field Bit Number From Unique Id
201 *
202 * @param uid
203 * @return FieldId
204 */
205 static inline auto getFieldBitNumberFromUniqueId(const UId uid) {
206 constexpr int bit_field_mask = ~(char(0));
207 return static_cast<char>(
208 (uid & getGlobalUniqueIdCalculate(0, bit_field_mask, 0)) >>
210 };
211
212 /**
213 * \brief Calculate global UId
214 * @return Global UId
215 */
218 this->getBitNumber(),
219 this->getRefEntityPtr()->getOwnerEnt());
220 }
221
222 static inline UId getLoBitNumberUId(const FieldBitNumber bit_number) {
223 return
224
225 static_cast<UId>(bit_number) << dof_shift + ent_shift + proc_shift;
226 }
227
228 static inline UId getHiBitNumberUId(const FieldBitNumber bit_number) {
229 return static_cast<UId>(MAX_DOFS_ON_ENTITY - 1) |
230 static_cast<UId>(MAX_PROCESSORS_NUMBER - 1) << dof_shift |
231 static_cast<UId>(std::numeric_limits<EntityHandle>::max())
232 << dof_shift + proc_shift |
233 static_cast<UId>(bit_number) << dof_shift + ent_shift + proc_shift;
234 }
235
236 static inline UId getLoFieldEntityUId(const UId &uid) {
237 return ((~static_cast<UId>(MAX_DOFS_ON_ENTITY - 1)) & uid);
238 }
239
240 static inline UId getHiFieldEntityUId(const UId &uid) {
241 return getLoFieldEntityUId(uid) | static_cast<UId>(MAX_DOFS_ON_ENTITY - 1);
242 }
243
244 template <typename T> void getLoFieldEntityUId(T &uid) = delete;
245 template <typename T> void getHiFieldEntityUId(T &uid) = delete;
246
247 static inline UId getLoLocalEntityBitNumber(const char bit_number,
248 const EntityHandle ent) {
250
251 bit_number,
252
253 ent
254
255 );
256 }
257
258 static inline UId getHiLocalEntityBitNumber(const char bit_number,
259 const EntityHandle ent) {
260 return getLoLocalEntityBitNumber(bit_number, ent) |
261 static_cast<UId>(MAX_DOFS_ON_ENTITY - 1);
262 }
263
264 /**
265 * \brief get hash-map relating dof index on entity with its order
266 *
267 * DOFs of given field are indexed on entity
268 * of the same type, same space, approximation base and number of
269 * coefficients, are sorted in the way.
270 *
271 */
272 inline const std::array<int, MAX_DOFS_ON_ENTITY> &getDofOrderMap() const {
273 return this->getFieldRawPtr()->getDofOrderMap(this->getEntType());
274 }
275
276 friend std::ostream &operator<<(std::ostream &os, const FieldEntity &e);
277
278 mutable boost::weak_ptr<EntityCacheDofs> entityCacheDataDofs;
279 mutable boost::weak_ptr<EntityCacheNumeredDofs> entityCacheRowDofs;
280 mutable boost::weak_ptr<EntityCacheNumeredDofs> entityCacheColDofs;
281
282 /**
283 * @brief Get the Weak Storage pointer
284 *
285 * @return boost::weak_ptr<EntityStorage>&
286 */
287 template <typename T = EntityStorage>
288 inline boost::shared_ptr<T> getSharedStoragePtr() const {
289 return boost::dynamic_pointer_cast<T>(weakStoragePtr.lock());
290 }
291
292 inline boost::weak_ptr<EntityStorage> &getWeakStoragePtr() const {
293 return weakStoragePtr;
294 }
295
296 mutable boost::weak_ptr<EntityStorage> weakStoragePtr;
297
298private:
299 mutable boost::shared_ptr<const ApproximationOrder> tagMaxOrderPtr;
300 mutable boost::shared_ptr<FieldData *const> fieldDataAdaptorPtr;
301 static constexpr int dof_shift = 9; // Maximal number of DOFs on entity
302 static constexpr int ent_shift = 64; // EntityHandle size
303 static constexpr int proc_shift = 10; // Maximal number of 1024 processors
304};
305
306template <>
307inline boost::shared_ptr<EntityStorage>
308FieldEntity::getSharedStoragePtr<EntityStorage>() const {
309 return weakStoragePtr.lock();
310}
311
312/**
313 * \brief Interface to FieldEntity
314 * \ingroup ent_multi_indices
315 *
316 * interface to FieldEntity
317 */
318template <typename T>
320
321 interface_FieldEntity(const boost::shared_ptr<T> &sptr)
322 : interface_Field<T, T>(sptr) {}
323
324 /// @return get number of dofs on entity
325 inline int getNbDofsOnEnt() const { return this->sPtr->getNbDofsOnEnt(); }
326
327 /// @return get field data on entity
329 return this->sPtr->getEntFieldData();
330 }
331
332 /// @return get number of DOFs for given order
334 return this->sPtr->getOrderNbDofs(order);
335 }
336
337 /// @return get increase of DOFs by increase to this order
339 return this->sPtr->getOrderNbDofsDiff(order);
340 }
341
342 /// @return get maximal order on entity
344 return this->sPtr->getMaxOrder();
345 }
346
347 /// @return get entity UId
348 inline UId getGlobalUniqueId() const {
349 return this->sPtr->getGlobalUniqueId();
350 }
351
352 /// @return get entity UId
353 inline UId &getLocalUniqueId() const {
354 return this->sPtr->getLocalUniqueId();
355 }
356
357 /// @return return pointer to reference entity data structure
358 inline boost::shared_ptr<RefEntity> &getRefEntityPtr() const {
359 return this->sPtr->getRefEntityPtr();
360 }
361
362 /// @return get pointer to mofem entity data structure
363 inline boost::shared_ptr<FieldEntity> &getFieldEntityPtr() const {
364 return this->sPtr;
365 };
366
367 /**
368 * \brief get hash-map relating dof index on entity with its order
369 *
370 * DOFs of given field are indexed on entity
371 * of the same type, same space, approximation base and number of
372 * coefficients, are sorted in the way.
373 *
374 */
375 inline const std::array<int, MAX_DOFS_ON_ENTITY> &getDofOrderMap() const {
376 return this->sPtr->getDofOrderMap();
377 }
378
379 /// @copydoc FieldEntity::getSharedStoragePtr
380 template <typename S = EntityStorage>
381 inline boost::shared_ptr<S> getSharedStoragePtr() const {
382 return this->sPtr->template getSharedStoragePtr<S>();
383 }
384
385 inline boost::weak_ptr<EntityStorage> &getWeakStoragePtr() const {
386 return this->sPtr->getWeakStoragePtr();
387 }
388};
389
390/**
391 * \brief structure to change FieldEntity order
392 * \ingroup ent_multi_indices
393 */
395
397 const bool reduce_tag_size = false)
398 : order(order), reduceTagSize(reduce_tag_size) {}
399 inline void operator()(boost::shared_ptr<FieldEntity> &e) {
400 (*this)(e.get());
401 }
402 void operator()(FieldEntity *e);
403
404private:
406 const bool reduceTagSize;
407 std::vector<FieldData> data;
408};
409
410/**
411 * @relates multi_index_container
412 * \brief MultiIndex container keeps FieldEntity
413 * \ingroup ent_multi_indices
414 *
415 */
416using FieldEntity_multiIndex = multi_index_container<
417 boost::shared_ptr<FieldEntity>,
418 indexed_by<
419 ordered_unique<tag<Unique_mi_tag>,
420 member<FieldEntity, UId, &FieldEntity::localUId>>,
421 ordered_non_unique<tag<Ent_mi_tag>,
424
425 >>;
426
427/** \brief Entity index by field name
428 *
429 * \ingroup ent_multi_indices
430 */
431using FieldEntityByUId = FieldEntity_multiIndex::index<Unique_mi_tag>::type;
432
433/** \brief multi-index view on DofEntity by uid
434 \ingroup dof_multi_indices
435*/
436using FieldEntity_multiIndex_global_uid_view = multi_index_container<
437 boost::shared_ptr<FieldEntity>,
438 indexed_by<
439
440 ordered_unique<
441 tag<Unique_mi_tag>,
442 const_mem_fun<FieldEntity, UId, &FieldEntity::getGlobalUniqueId>>
443
444 >>;
445
446using FieldEntity_multiIndex_ent_view = multi_index_container<
447 boost::shared_ptr<FieldEntity>,
448 indexed_by<
449
450 sequenced<>,
451
452 ordered_non_unique<tag<Ent_mi_tag>,
455
456 >>;
457
458using FieldEntity_multiIndex_spaceType_view = multi_index_container<
459 boost::shared_ptr<FieldEntity>,
460 indexed_by<
461
462 sequenced<>,
463
464 ordered_non_unique<
465 tag<Composite_EntType_and_Space_mi_tag>,
466 composite_key<FieldEntity,
467
470
473
474 >>
475
476 >>;
477
478typedef std::vector<boost::weak_ptr<FieldEntity>> FieldEntity_vector_view;
479
480using FieldEntity_multiIndex = multi_index_container<
481 boost::shared_ptr<FieldEntity>,
482 indexed_by<
483 ordered_unique<tag<Unique_mi_tag>,
484 member<FieldEntity, UId, &FieldEntity::localUId>>,
485 ordered_non_unique<tag<Ent_mi_tag>,
488
489 >>;
490
491} // namespace MoFEM
492
493#endif // __FIELD_ENTSMULTIINDICES_HPP__
494
495/**
496 * \defgroup ent_multi_indices Entities structures and multi-indices
497 * \ingroup mofem
498 **/
#define MAX_DOFS_ON_ENTITY
Maximal number of DOFs on entity.
#define MAX_PROCESSORS_NUMBER
Maximal number of processors.
FieldSpace
approximation spaces
Definition definitions.h:82
constexpr int order
multi_index_container< boost::shared_ptr< FieldEntity >, indexed_by< ordered_unique< tag< Unique_mi_tag >, const_mem_fun< FieldEntity, UId, &FieldEntity::getGlobalUniqueId > > > > FieldEntity_multiIndex_global_uid_view
multi-index view on DofEntity by uid
multi_index_container< boost::shared_ptr< FieldEntity >, indexed_by< ordered_unique< tag< Unique_mi_tag >, member< FieldEntity, UId, &FieldEntity::localUId > >, ordered_non_unique< tag< Ent_mi_tag >, const_mem_fun< FieldEntity::interface_type_RefEntity, EntityHandle, &FieldEntity::getEnt > > > > FieldEntity_multiIndex
MultiIndex container keeps FieldEntity.
FieldEntity_multiIndex::index< Unique_mi_tag >::type FieldEntityByUId
Entity index by field name.
int ApproximationOrder
Approximation on the entity.
Definition Types.hpp:26
uint128_t UId
Unique Id.
Definition Types.hpp:31
VectorShallowArrayAdaptor< double > VectorAdaptor
Definition Types.hpp:115
char FieldBitNumber
Field bit number.
Definition Types.hpp:28
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
auto getVectorAdaptor(T1 ptr, const size_t n)
Get Vector adaptor.
Definition Templates.hpp:31
multi_index_container< boost::shared_ptr< FieldEntity >, indexed_by< ordered_unique< tag< Unique_mi_tag >, member< FieldEntity, UId, &FieldEntity::localUId > >, ordered_non_unique< tag< Ent_mi_tag >, const_mem_fun< FieldEntity::interface_type_RefEntity, EntityHandle, &FieldEntity::getEnt > > > > FieldEntity_multiIndex
std::vector< boost::weak_ptr< FieldEntity > > FieldEntity_vector_view
multi_index_container< boost::shared_ptr< FieldEntity >, indexed_by< sequenced<>, ordered_non_unique< tag< Ent_mi_tag >, const_mem_fun< FieldEntity::interface_type_RefEntity, EntityHandle, &FieldEntity::getEnt > > > > FieldEntity_multiIndex_ent_view
multi_index_container< boost::shared_ptr< FieldEntity >, indexed_by< sequenced<>, ordered_non_unique< tag< Composite_EntType_and_Space_mi_tag >, composite_key< FieldEntity, const_mem_fun< FieldEntity::interface_type_RefEntity, EntityType, &FieldEntity::getEntType >, const_mem_fun< FieldEntity::interface_type_Field, FieldSpace, &FieldEntity::getSpace > > > > > FieldEntity_multiIndex_spaceType_view
virtual ~EntityStorage()=default
structure to change FieldEntity order
FieldEntity_change_order(const ApproximationOrder order, const bool reduce_tag_size=false)
void operator()(boost::shared_ptr< FieldEntity > &e)
Struct keeps handle to entity in the field.
static constexpr int dof_shift
static UId getHiBitNumberUId(const FieldBitNumber bit_number)
friend std::ostream & operator<<(std::ostream &os, const FieldEntity &e)
static auto getHandleFromUniqueId(const UId uid)
Get the Handle From Unique Id.
static auto getFieldBitNumberFromUniqueId(const UId uid)
Get the Field Bit Number From Unique Id.
int getOrderNbDofsDiff(ApproximationOrder order) const
Get difference of number of DOFs between order and order-1.
int getNbDofsOnEnt() const
Get number of active DOFs on entity.
UId getLocalUniqueIdCalculate()
Get the Local Unique Id Calculate object.
static UId getHiFieldEntityUId(const UId &uid)
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 UId getLoBitNumberUId(const FieldBitNumber bit_number)
static constexpr int proc_shift
static UId getLoLocalEntityBitNumber(const char bit_number, const EntityHandle ent)
boost::shared_ptr< FieldData *const > & getEntFieldDataPtr() const
Get shared ptr to vector adaptor pointing to the field tag data on entity.
boost::weak_ptr< EntityStorage > & getWeakStoragePtr() const
boost::weak_ptr< EntityCacheDofs > entityCacheDataDofs
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)
interface_Field< Field, RefEntity > interface_type_Field
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.
interface_RefEntity< RefEntity > interface_type_RefEntity
void getHiFieldEntityUId(T &uid)=delete
UId localUId
Local unique id for this entity. Unique on CPU partition.
static UId getGlobalUniqueIdCalculate(const int owner_proc, const char bit_number, const EntityHandle moab_owner_handle)
Calculate UId for field entity.
void getLoFieldEntityUId(T &uid)=delete
static constexpr int ent_shift
static UId getLoFieldEntityUId(const UId &uid)
boost::weak_ptr< EntityCacheNumeredDofs > entityCacheRowDofs
const UId & getLocalUniqueId() const
Get global unique id.
boost::weak_ptr< EntityCacheNumeredDofs > entityCacheColDofs
boost::weak_ptr< EntityStorage > weakStoragePtr
int getOrderNbDofs(ApproximationOrder order) const
Get number of DOFs on entity for given order of approximation.
virtual ~FieldEntity()=default
static UId getLocalUniqueIdCalculate(const char bit_number, const EntityHandle handle)
Get the Local Unique Id Calculate.
UId getGlobalUniqueId() const
Get global unique id.
static UId getHiLocalEntityBitNumber(const char bit_number, const EntityHandle ent)
static auto getOwnerFromUniqueId(const UId uid)
const std::array< int, MAX_DOFS_ON_ENTITY > & getDofOrderMap() const
get hash-map relating dof index on entity with its order
VectorAdaptor getEntFieldData() const
Get vector of DOFs active values on entity.
boost::shared_ptr< const ApproximationOrder > tagMaxOrderPtr
UId getGlobalUniqueIdCalculate() const
Calculate global UId.
boost::shared_ptr< T > getSharedStoragePtr() const
Get the Weak Storage pointer.
const std::array< ApproximationOrder, MAX_DOFS_ON_ENTITY > & getDofOrderMap(const EntityType type) const
get hash-map relating dof index on entity with its order
interface_FieldEntity(const boost::shared_ptr< T > &sptr)
const std::array< int, MAX_DOFS_ON_ENTITY > & getDofOrderMap() const
get hash-map relating dof index on entity with its order
boost::weak_ptr< EntityStorage > & getWeakStoragePtr() const
int getOrderNbDofsDiff(ApproximationOrder order) const
boost::shared_ptr< S > getSharedStoragePtr() const
Get the Weak Storage pointer.
boost::shared_ptr< FieldEntity > & getFieldEntityPtr() const
int getOrderNbDofs(ApproximationOrder order) const
ApproximationOrder getMaxOrder() const
boost::shared_ptr< RefEntity > & getRefEntityPtr() const
FieldCoefficientsNumber getNbOfCoeffs() const
boost::shared_ptr< REFENT > & getRefEntityPtr() const