v0.14.0
Loading...
Searching...
No Matches
FieldMultiIndices.hpp
Go to the documentation of this file.
1/** \file FieldMultiIndices.hpp
2 * \brief Field data structure storing information about space, approximation
3 * base, coordinate systems, etc.
4 *
5 * Also, it stores data needed for book keeping, like tags to data on the
6 * mesh.
7 *
8 * Each filed has unique ID and name. This data structure is shared between
9 * entities on which is spanning and DOFs on those entities.
10 */
11
12
13
14#ifndef __FIELDMULTIINDICES_HPP__
15#define __FIELDMULTIINDICES_HPP__
16
17namespace MoFEM {
18
19template <typename T> struct interface_RefEntity;
20struct DofEntity;
21
22/** \brief user adjacency function
23 * \ingroup fe_multi_indices
24 */
25typedef boost::function<int(const int order)> FieldOrderFunct;
26
27/** \brief user adjacency function table
28 * \ingroup dof_multi_indices
29 */
31
32/**
33 * \brief Provide data structure for (tensor) field approximation.
34 * \ingroup dof_multi_indices
35 *
36 * The Field is intended to provide support for fields, with a strong bias
37 * towards supporting first and best the capabilities required for scientific
38 * computing applications. Since we work with discrete spaces, data structure
39 * has to carry information about type of approximation space, its regularity.
40 *
41 *
42 * Field data structure storing information about space, approximation base,
43 * coordinate systems, etc. It stores additional data needed for book keeping,
44 * like tags to data on the mesh.
45 *
46 * Each filed has unique ID and name. This
47 * data structure is shared between entities on which is spanning and DOFs on
48 * those entities.
49 *
50 */
51struct Field {
52
53 /**
54 * \brief constructor for moab field
55 *
56 * \param meshset which keeps entities for this field
57 */
58 Field(moab::Interface &moab, const EntityHandle meshset);
59
60 virtual ~Field() = default;
61
62 using SequenceDofContainer = multi_index_container<
63
64 boost::weak_ptr<std::vector<DofEntity>>,
65
66 indexed_by<sequenced<>>>;
67
68 typedef std::array<std::array<int, MAX_DOFS_ON_ENTITY>, MBMAXTYPE>
70
71 moab::Interface &moab;
72
73 EntityHandle meshSet; ///< keeps entities for this meshset
74
75 TagType tagFieldDataVertsType; // Tag type for storing data on vertices
76 Tag th_FieldDataVerts; ///< Tag storing field values on vertices in the field
77 Tag th_FieldData; ///< Tag storing field values on entity in the field
78 Tag th_AppOrder; ///< Tag storing approximation order on entity
79 Tag th_FieldRank; /// Tag field rank
80
81 BitFieldId *tagId; ///< tag keeps field id
82 FieldSpace *tagSpaceData; ///< tag keeps field space
83 FieldApproximationBase *tagBaseData; ///< tag keeps field base
84
85 /// tag keeps field rank (dimension, f.e. Temperature field has rank 1,
86 /// displacements field in 3d has rank 3)
88 const void *tagName; ///< tag keeps name of the field
89 int tagNameSize; ///< number of bits necessary to keep field name
90 const void *tagNamePrefixData; ///< tag keeps name prefix of the field
91 int tagNamePrefixSize; ///< number of bits necessary to keep field name
92 ///< prefix
93 FieldOrderTable forderTable; ///< nb. DOFs table for entities
94
95 /**
96 * @brief Get the Field Order Table
97 *
98 * @return FieldOrderTable&
99 */
101
102 /**
103 * Field Id is bit set. Each field has only one bit on, bitNumber stores
104 * number of set bit
105 */
106 unsigned int bitNumber;
107
108 /**
109 * \brief Get field meshset
110 *
111
112 * To meshsets entity are attached Tags which keeps basic information about
113 * field. Those information is field name, approximation base, approximation
114 * space, id, etc.
115
116 * In meshset contains entities on which given filed is sparing. Type of
117 entities
118 * depended on approximations space.
119
120 * @return EntityHandle
121 */
122 inline EntityHandle getMeshset() const { return meshSet; }
123
124 /**
125 * \brief Get unique field id.
126 * @return Filed ID
127 */
128 inline const BitFieldId &getId() const { return *((BitFieldId *)tagId); }
129
130 /**
131 * \brief Get string reference to field name
132 * @return Field name
133 */
134 inline boost::string_ref getNameRef() const {
135 return boost::string_ref((char *)tagName, tagNameSize);
136 }
137
138 /**
139 * \brief Get field name
140 * @return Field name
141 */
142 inline std::string getName() const {
143 return std::string((char *)tagName, tagNameSize);
144 }
145
146 /**
147 * \brief Get field approximation space
148 * @return approximation space
149 */
150 inline FieldSpace getSpace() const { return *tagSpaceData; }
151
152 /**
153 * \brief Get field approximation space
154 * @return approximation space name
155 */
156 inline auto getSpaceName() const {
157 return std::string(FieldSpaceNames[getSpace()]);
158 }
159
160 /**
161 * \brief Get approximation base
162 * @return Approximation base
163 */
165
166 /**
167 * \brief Get approximation base
168 * @return Approximation base name
169 */
170 inline auto getApproxBaseName() const {
171 return std::string(ApproximationBaseNames[getApproxBase()]);
172 }
173
174 /** \brief Get number of field coefficients
175 *
176
177 * Scalar field has only one coefficient, vector field in 3D has three. In
178 * general number determine space needed to keep data on entities. What
179 coefficient
180 * means depend on interpretation and associated coordinate system. For
181 example
182 * 3 coefficient means could be covariant or contravariant, or mean three
183 temperatures
184 * for mixture of solid, air and water, etc.
185
186
187 */
189 return *tagNbCoeffData;
190 };
191
192 /**
193 * \brief Get number of set bit in Field ID.
194 * Each field has uid, get getBitNumber get number of bit set for given field.
195 * Field ID has only one bit set for each field.
196 */
197 inline FieldBitNumber getBitNumber() const { return bitNumber; }
198
199 /**
200 * \brief Calculate number of set bit in Field ID.
201 * Each field has uid, get getBitNumber get number of bit set for given field.
202 * Field ID has only one bit set for each field.
203 */
205 static_assert(BITFIELDID_SIZE >= 32,
206 "Too many fields allowed, can be more but ...");
207 FieldBitNumber b = ffsl(id.to_ulong());
208 if (b != 0)
209 return b;
210 return 0;
211 }
212
213 /**
214 * \brief Calculate number of set bit in Field ID.
215 * Each field has uid, get getBitNumber get number of bit set for given field.
216 * Field ID has only one bit set for each field.
217 */
219 return getBitNumberCalculate(static_cast<BitFieldId &>(*tagId));
220 }
221
222 /**
223 * \brief Get reference to sequence data container
224 *
225 * In sequence data container data are physically stored. The purpose of this
226 * is to allocate DofEntity data in bulk, having only one allocation instead
227 * each time entity is inserted. That makes code efficient.
228 *
229 * The vector in sequence is destroyed if last entity inside that vector is
230 * destroyed. All MoFEM::MoFEMEntities have aliased shared_ptr which points to
231 the vector.
232
233 * Not all DOFs are starred in this way, currently such cases are considered;
234 * - DOFs on vertices. That is exploited that for H1 space, there is some
235 * fixed number of DOFs on each vertex
236
237 * For other cases, DOFs are stored locally in each MoFEM::MoFEMEntities.
238
239 * @return MoFEM::Field::SequenceDofContainer
240 */
243 }
244
245 /**
246 * \brief get hash-map relating dof index on entity with its order
247 *
248 * Dofs of given field are indexed on entity
249 * of the same type, same space, approximation base and number of
250 * coefficients, are sorted in the way.
251 *
252 */
253 inline const std::array<ApproximationOrder, MAX_DOFS_ON_ENTITY> &
254 getDofOrderMap(const EntityType type) const {
255 return dofOrderMap[type];
256 }
257
258 /**
259 * \brief get hash-map relating dof index on entity with its order
260 *
261 * Dofs of given field are indexed on entity
262 * of the same type, same space, approximation base and number of
263 * coefficients, are sorted in the way.
264 *
265 */
266 inline const DofsOrderMap &getDofOrderMap() const { return dofOrderMap; }
267
269
270 friend std::ostream &operator<<(std::ostream &os, const Field &e);
271
272 inline const Field *getFieldRawPtr() const { return this; };
273
274private:
277};
278
279/**
280 * \brief Pointer interface for MoFEM::Field
281 *
282 * MoFEM::Field class is keeps data and methods. This class is interface to
283 * that class, and all other classes, like MoFEMEntities, DofEntity and
284 * derived form them inherits pointer interface, not MoFEM::Field class
285 * directly.
286 *
287 * \ingroup dof_multi_indices
288 */
289template <typename FIELD, typename REFENT>
291
293
294 interface_FieldImpl(const boost::shared_ptr<FIELD> &field_ptr,
295 const boost::shared_ptr<REFENT> &ref_ents_ptr)
296 : interface_RefEntity<REFENT>(ref_ents_ptr) {}
297 virtual ~interface_FieldImpl() = default;
298};
299
300template <typename FIELD, typename REFENT>
301struct interface_Field : public interface_FieldImpl<FIELD, REFENT> {
302
303 interface_Field(const boost::shared_ptr<FIELD> &field_ptr,
304 const boost::shared_ptr<REFENT> &ref_ents_ptr)
305 : interface_FieldImpl<FIELD, REFENT>(field_ptr, ref_ents_ptr),
306 sFieldPtr(field_ptr) {}
307
308 inline EntityHandle getMeshset() const {
309 return getFieldRawPtr()->getMeshset();
310 }
311
312 inline int getCoordSysDim(const int d = 0) const {
313 return getFieldRawPtr()->getCoordSysDim(d);
314 }
315
316 /// @return get field Id
317 inline const BitFieldId &getId() const {
318 return getFieldRawPtr()->getId();
319 }
320
321 /// @return get field name
322 inline boost::string_ref getNameRef() const {
323 return getFieldRawPtr()->getNameRef();
324 }
325
326 /// @return get field name
327 inline std::string getName() const {
328 return getFieldRawPtr()->getName();
329 }
330
331 /// @return get approximation space
332 inline FieldSpace getSpace() const {
333 return getFieldRawPtr()->getSpace();
334 }
335
336 /// @return get approximation base
338 return getFieldRawPtr()->getApproxBase();
339 }
340
341 /// @return get number of coefficients for DOF
343 return getFieldRawPtr()->getNbOfCoeffs();
344 }
345
346 /// @return get bit number if filed Id
348 return getFieldRawPtr()->getBitNumber();
349 }
350
351 /**
352 * \brief get hash-map relating dof index on entity with its order
353 *
354 * Dofs of given field are indexed on entity
355 * of the same type, same space, approximation base and number of
356 * coefficients, are sorted in the way.
357 *
358 */
359 inline std::array<ApproximationOrder, MAX_DOFS_ON_ENTITY> &
360 getDofOrderMap(const EntityType type) const {
361 return getFieldRawPtr()->getDofOrderMap(type);
362 }
363
364 inline const Field *getFieldRawPtr() const {
365 return sFieldPtr->getFieldRawPtr();
366 };
367
369 return sFieldPtr->getFieldOrderTable();
370 };
371
372private:
373 mutable boost::shared_ptr<FIELD> sFieldPtr;
374};
375
376template <typename T>
377struct interface_Field<T, T> : public interface_FieldImpl<T, T> {
378 interface_Field(const boost::shared_ptr<T> &ptr)
379 : interface_FieldImpl<T, T>(ptr, ptr) {}
380
382
383 inline EntityHandle getMeshset() const {
384 return getFieldRawPtr()->getMeshset();
385 }
386
387 /// @return get field Id
388 inline const BitFieldId &getId() const {
389 return getFieldRawPtr()->getId();
390 }
391
392 /// @return get field name
393 inline boost::string_ref getNameRef() const {
394 return getFieldRawPtr()->getNameRef();
395 }
396
397 /// @return get field name
398 inline std::string getName() const {
399 return getFieldRawPtr()->getName();
400 }
401
402 /// @return get approximation space
403 inline FieldSpace getSpace() const {
404 return getFieldRawPtr()->getSpace();
405 }
406
407 /// @return get approximation base
408 inline auto getSpaceName() const { return getFieldRawPtr()->getSpaceName(); }
409
410 /// @return get approximation base
412 return getFieldRawPtr()->getApproxBase();
413 }
414
415 /// @return get approximation base
416 inline auto getApproxBaseName() const {
418 }
419
420 /// @return get number of coefficients for DOF
422 return getFieldRawPtr()->getNbOfCoeffs();
423 }
424
425 /// @return get bit number if filed Id
427 return getFieldRawPtr()->getBitNumber();
428 }
429
430 /**
431 * \brief get hash-map relating dof index on entity with its order
432 *
433 * Dofs of given field are indexed on entity
434 * of the same type, same space, approximation base and number of
435 * coefficients, are sorted in the way.
436 *
437 */
438 inline std::array<ApproximationOrder, MAX_DOFS_ON_ENTITY> &
439 getDofOrderMap(const EntityType type) const {
440 return getFieldRawPtr()->getDofOrderMap(type);
441 }
442
443 inline const Field *getFieldRawPtr() const {
444 return boost::static_pointer_cast<T>(this->getRefEntityPtr())
445 ->getFieldRawPtr();
446 };
447};
448
449/**
450 * @relates multi_index_container
451 * \brief Field_multiIndex for Field
452 *
453 */
454typedef multi_index_container<
455 boost::shared_ptr<Field>,
456 indexed_by<
457 hashed_unique<tag<BitFieldId_mi_tag>,
458 const_mem_fun<Field, const BitFieldId &, &Field::getId>,
459 HashBit<BitFieldId>, EqBit<BitFieldId>>,
460 ordered_unique<tag<Meshset_mi_tag>,
461 member<Field, EntityHandle, &Field::meshSet>>,
462 ordered_unique<
463 tag<FieldName_mi_tag>,
464 const_mem_fun<Field, boost::string_ref, &Field::getNameRef>>,
465 ordered_non_unique<tag<BitFieldId_space_mi_tag>,
466 const_mem_fun<Field, FieldSpace, &Field::getSpace>>>>
468
469typedef multi_index_container<
470 boost::shared_ptr<Field>,
471 indexed_by<
472 ordered_unique<tag<BitFieldId_mi_tag>,
473 const_mem_fun<Field, const BitFieldId &, &Field::getId>,
474 LtBit<BitFieldId>>>>
476
477} // namespace MoFEM
478
479#endif // __FIELDMULTIINDICES_HPP__
multi_index_container< boost::shared_ptr< Field >, indexed_by< hashed_unique< tag< BitFieldId_mi_tag >, const_mem_fun< Field, const BitFieldId &, &Field::getId >, HashBit< BitFieldId >, EqBit< BitFieldId > >, ordered_unique< tag< Meshset_mi_tag >, member< Field, EntityHandle, &Field::meshSet > >, ordered_unique< tag< FieldName_mi_tag >, const_mem_fun< Field, boost::string_ref, &Field::getNameRef > >, ordered_non_unique< tag< BitFieldId_space_mi_tag >, const_mem_fun< Field, FieldSpace, &Field::getSpace > > > > Field_multiIndex
Field_multiIndex for Field.
FieldApproximationBase
approximation base
Definition: definitions.h:58
FieldSpace
approximation spaces
Definition: definitions.h:82
static const char *const FieldSpaceNames[]
Definition: definitions.h:92
#define BITFIELDID_SIZE
max number of fields
Definition: definitions.h:220
static const char *const ApproximationBaseNames[]
Definition: definitions.h:72
constexpr int order
FieldOrderFunct FieldOrderTable[MBMAXTYPE]
user adjacency function table
boost::function< int(const int order)> FieldOrderFunct
user adjacency function
const double T
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
std::bitset< BITFIELDID_SIZE > BitFieldId
Field Id.
Definition: Types.hpp:42
int FieldCoefficientsNumber
Number of field coefficients.
Definition: Types.hpp:27
char FieldBitNumber
Field bit number.
Definition: Types.hpp:28
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
multi_index_container< boost::shared_ptr< Field >, indexed_by< ordered_unique< tag< BitFieldId_mi_tag >, const_mem_fun< Field, const BitFieldId &, &Field::getId >, LtBit< BitFieldId > > > > Field_multiIndex_view
Provide data structure for (tensor) field approximation.
FieldCoefficientsNumber getNbOfCoeffs() const
Get number of field coefficients.
const void * tagNamePrefixData
tag keeps name prefix of the field
FieldOrderTable forderTable
nb. DOFs table for entities
const void * tagName
tag keeps name of the field
int tagNameSize
number of bits necessary to keep field name
std::string getName() const
Get field name.
auto getSpaceName() const
Get field approximation space.
DofsOrderMap dofOrderMap
FieldApproximationBase getApproxBase() const
Get approximation base.
friend std::ostream & operator<<(std::ostream &os, const Field &e)
unsigned int bitNumber
EntityHandle getMeshset() const
Get field meshset.
EntityHandle meshSet
keeps entities for this meshset
std::array< std::array< int, MAX_DOFS_ON_ENTITY >, MBMAXTYPE > DofsOrderMap
FieldSpace * tagSpaceData
tag keeps field space
FieldBitNumber getBitNumberCalculate() const
Calculate number of set bit in Field ID. Each field has uid, get getBitNumber get number of bit set f...
auto getApproxBaseName() const
Get approximation base.
const std::array< ApproximationOrder, MAX_DOFS_ON_ENTITY > & getDofOrderMap(const EntityType type) const
get hash-map relating dof index on entity with its order
static FieldBitNumber getBitNumberCalculate(const BitFieldId &id)
Calculate number of set bit in Field ID. Each field has uid, get getBitNumber get number of bit set f...
Tag th_FieldData
Tag storing field values on entity in the field.
const DofsOrderMap & getDofOrderMap() const
get hash-map relating dof index on entity with its order
FieldOrderTable & getFieldOrderTable()
Get the Field Order Table.
MoFEMErrorCode rebuildDofsOrderMap()
FieldCoefficientsNumber * tagNbCoeffData
BitFieldId * tagId
Tag field rank.
FieldSpace getSpace() const
Get field approximation space.
Tag th_FieldDataVerts
Tag storing field values on vertices in the field.
SequenceDofContainer sequenceDofContainer
FieldApproximationBase * tagBaseData
tag keeps field base
SequenceDofContainer & getDofSequenceContainer() const
Get reference to sequence data container.
const Field * getFieldRawPtr() const
TagType tagFieldDataVertsType
multi_index_container< boost::weak_ptr< std::vector< DofEntity > >, indexed_by< sequenced<> > > SequenceDofContainer
Tag th_AppOrder
Tag storing approximation order on entity.
moab::Interface & moab
boost::string_ref getNameRef() const
Get string reference to field name.
virtual ~Field()=default
FieldBitNumber getBitNumber() const
Get number of set bit in Field ID. Each field has uid, get getBitNumber get number of bit set for giv...
const BitFieldId & getId() const
Get unique field id.
const BitFieldId & getId() const
FieldBitNumber getBitNumber() const
interface_Field(const boost::shared_ptr< T > &ptr)
FieldApproximationBase getApproxBase() const
FieldCoefficientsNumber getNbOfCoeffs() const
const Field * getFieldRawPtr() const
std::array< ApproximationOrder, MAX_DOFS_ON_ENTITY > & getDofOrderMap(const EntityType type) const
get hash-map relating dof index on entity with its order
boost::string_ref getNameRef() const
FieldBitNumber getBitNumber() const
FieldCoefficientsNumber getNbOfCoeffs() const
boost::string_ref getNameRef() const
FieldApproximationBase getApproxBase() const
std::string getName() const
std::array< ApproximationOrder, MAX_DOFS_ON_ENTITY > & getDofOrderMap(const EntityType type) const
get hash-map relating dof index on entity with its order
EntityHandle getMeshset() const
const Field * getFieldRawPtr() const
FieldSpace getSpace() const
const BitFieldId & getId() const
interface_Field(const boost::shared_ptr< FIELD > &field_ptr, const boost::shared_ptr< REFENT > &ref_ents_ptr)
FieldOrderTable & getFieldOrderTable()
boost::shared_ptr< FIELD > sFieldPtr
int getCoordSysDim(const int d=0) const
Pointer interface for MoFEM::Field.
interface_FieldImpl(const boost::shared_ptr< FIELD > &field_ptr, const boost::shared_ptr< REFENT > &ref_ents_ptr)
virtual ~interface_FieldImpl()=default
boost::shared_ptr< REFENT > & getRefEntityPtr() const