v0.15.0
Loading...
Searching...
No Matches
FieldMultiIndices.hpp
Go to the documentation of this file.
1/** \file FieldMultiIndices.hpp
2 * \brief Field data structure for finite element approximation spaces
3 *
4 * Stores field information including approximation space, basis functions,
5 * coordinate systems, and DOF management data.
6 */
7
8
9
10#ifndef __FIELDMULTIINDICES_HPP__
11#define __FIELDMULTIINDICES_HPP__
12
13namespace MoFEM {
14
15template <typename T> struct interface_RefEntity;
16struct DofEntity;
17
18/** \brief Function returning number of DOFs for given approximation order
19 * \ingroup fe_multi_indices
20 */
21typedef boost::function<int(const int order)> FieldOrderFunct;
22
23/** \brief Array of functions defining DOF count for each entity type
24 * \ingroup dof_multi_indices
25 */
27
28/**
29 * \brief Field data structure for finite element approximation
30 * \ingroup dof_multi_indices
31 *
32 * Stores field information including approximation space, basis functions,
33 * coordinate systems, and DOF management. Each field has a unique ID and name.
34 * Data is shared between mesh entities and their associated DOFs.
35 */
36struct Field {
37
38 /**
39 * \brief Constructor for MOAB field
40 * \param moab MOAB interface reference
41 * \param meshset EntityHandle containing field entities
42 */
43 Field(moab::Interface &moab, const EntityHandle meshset);
44
45 /** \brief Virtual destructor */
46 virtual ~Field() = default;
47
48 /** \brief Container for bulk DOF allocation */
49 using SequenceDofContainer = multi_index_container<
50 boost::weak_ptr<std::vector<DofEntity>>,
51 indexed_by<sequenced<>>>;
52
53 /** \brief Array mapping entity types to DOF order arrays */
55 std::array<std::array<int, MAX_DOFS_ON_ENTITY>, MBMAXTYPE>;
56
57 moab::Interface &moab; ///< MOAB interface reference
58
59 EntityHandle meshSet; ///< Meshset containing field entities
60
61 TagType tagFieldDataVertsType; ///< Tag type for vertex data storage
62 Tag th_FieldDataVerts; ///< Tag for field values on vertices
63 Tag th_FieldData; ///< Tag for field values on entities
64 Tag th_AppOrder; ///< Tag for approximation order on entities
65 Tag th_FieldRank; ///< Tag for field rank (vector dimension)
66
67 BitFieldId *tagId; ///< Field unique identifier
68 FieldSpace *tagSpaceData; ///< Field approximation space
69 FieldContinuity *tagFieldContinuityData; ///< Field continuity type
70 FieldApproximationBase *tagBaseData; ///< Field basis functions
71
72 /// Field rank (e.g. Temperature=1, displacement in 3D=3)
74 const void *tagName; ///< Field name
75 int tagNameSize; ///< Field name size in bytes
76 const void *tagNamePrefixData; ///< Field name prefix
77 int tagNamePrefixSize; ///< Field name prefix size in bytes
78 FieldOrderTable forderTable; ///< DOF count functions for each entity type
79
80 /**
81 * \brief Get field order table
82 * \return Reference to DOF count functions for each entity type
83 */
85
86 /** \brief Bit number corresponding to this field's unique ID */
87 unsigned int bitNumber;
88
89 /**
90 * \brief Get field meshset handle
91 *
92 * On this meshset handle are stored tags with field data about base, space,
93 * number of coefficients, continuity, etc.
94 *
95 * Meshset contains entities on which the field is defined.
96 *
97 * \return EntityHandle containing field entities
98 */
99 inline EntityHandle getMeshset() const { return meshSet; }
100
101 /**
102 * \brief Get unique field identifier
103 * \return Field ID bitset
104 */
105 inline const BitFieldId &getId() const { return *((BitFieldId *)tagId); }
106
107 /**
108 * \brief Get field name as string reference
109 * \return Field name string reference
110 */
111 inline boost::string_ref getNameRef() const {
112 return boost::string_ref((char *)tagName, tagNameSize);
113 }
114
115 /**
116 * \brief Get field name as string
117 * \return Field name string
118 */
119 inline std::string getName() const {
120 return std::string((char *)tagName, tagNameSize);
121 }
122
123 /**
124 * \brief Get field approximation space
125 * \return Approximation space enumeration
126 */
127 inline FieldSpace getSpace() const { return *tagSpaceData; }
128
129 /**
130 * \brief Get field approximation space name
131 * \return Approximation space name string
132 */
133 inline auto getSpaceName() const {
134 return std::string(FieldSpaceNames[getSpace()]);
135 }
136
137 /**
138 * \brief Get field continuity type
139 *
140 * There are two types of continuity: CONTINUOUS and DISCONTINUOUS.
141 * Discontinuous is used to indicate broken spaces.
142 *
143 * \return Field continuity enumeration
144 */
147 }
148
149 /**
150 * \brief Get field continuity name
151 * \return Field continuity name string
152 */
153 inline auto getContinuityName() const {
154 return std::string(FieldContinuityNames[getContinuity()]);
155 }
156
157 /**
158 * \brief Get approximation basis type
159 * \return Approximation basis enumeration
160 */
162
163 /**
164 * \brief Get approximation basis name
165 * \return Approximation basis name string
166 */
167 inline auto getApproxBaseName() const {
168 return std::string(ApproximationBaseNames[getApproxBase()]);
169 }
170
171 /**
172 * \brief Get number of field coefficients per DOF
173 *
174 * Scalar fields have 1 coefficient, vector fields in 3D have 3.
175 * Coefficients may represent spatial components, physical quantities,
176 * or mixed formulations depending on the field interpretation.
177 *
178 * \return Number of coefficients
179 */
181 return *tagNbCoeffData;
182 };
183
184 /**
185 * \brief Get bit number for this field's ID
186 * \return Bit position in field ID bitset
187 */
188 inline FieldBitNumber getBitNumber() const { return bitNumber; }
189
190 /**
191 * \brief Calculate bit number from field ID bitset
192 * \param id Field ID bitset
193 * \return Bit position (1-based) or 0 if no bits set
194 */
196 static_assert(BITFIELDID_SIZE >= 32,
197 "Too many fields allowed, can be more but ...");
198 FieldBitNumber b = ffsl(id.to_ulong());
199 if (b != 0)
200 return b;
201 return 0;
202 }
203
204 /**
205 * \brief Calculate bit number for this field's ID
206 * \return Bit position (1-based) or 0 if no bits set
207 */
209 return getBitNumberCalculate(static_cast<BitFieldId &>(*tagId));
210 }
211
212 /**
213 * \brief Get sequence container for bulk DOF allocation
214 *
215 * Container stores DOF data in bulk for efficiency. Vectors are destroyed
216 * when last entity referencing them is removed. Used primarily for vertex
217 * DOFs in H1 spaces where DOF count per vertex is fixed.
218 *
219 * \return Reference to DOF sequence container
220 */
224
225 /**
226 * \brief Get DOF order mapping for specific entity type
227 * \param type Entity type (vertex, edge, face, volume)
228 * \return Array mapping DOF index to approximation order
229 */
230 inline const std::array<ApproximationOrder, MAX_DOFS_ON_ENTITY> &
231 getDofOrderMap(const EntityType type) const {
232 return dofOrderMap[type];
233 }
234
235 /**
236 * \brief Get complete DOF order mapping for all entity types
237 * \return Full DOF order mapping array
238 */
239 inline const DofsOrderMap &getDofOrderMap() const { return dofOrderMap; }
240
241 static constexpr int maxBrokenDofsOrder = 10; ///< Maximum order for broken space DOFs
242
243 /**
244 * \brief Get DOF side mapping for broken spaces
245 *
246 * Maps interior DOFs in broken spaces to entities where their traces
247 * are non-zero. Used for discontinuous Galerkin methods.
248 *
249 * \return Reference to DOF side mapping
250 */
251 inline std::map<int, BaseFunction::DofsSideMap> &getDofSideMap() const {
252 return dofSideMap;
253 }
254
255 /**
256 * \brief Rebuild DOF order mapping arrays
257 * \return Error code
258 */
260
261 /** \brief Output stream operator for field information */
262 friend std::ostream &operator<<(std::ostream &os, const Field &e);
263
264 /**
265 * \brief Get raw pointer to this field
266 * \return Pointer to this field object
267 */
268 inline const Field *getFieldRawPtr() const { return this; };
269
270private:
273 mutable std::map<int, BaseFunction::DofsSideMap> dofSideMap;
274};
275
276/**
277 * \brief Base template interface for field pointer management
278 *
279 * Provides interface layer between Field class and derived entities.
280 * Inherits from reference entity interface for pointer management.
281 *
282 * \tparam FIELD Field type
283 * \tparam REFENT Reference entity type
284 * \ingroup dof_multi_indices
285 */
286template <typename FIELD, typename REFENT>
288
290
291 /**
292 * \brief Constructor with field and reference entity pointers
293 * \param field_ptr Shared pointer to field
294 * \param ref_ents_ptr Shared pointer to reference entity
295 */
296 interface_FieldImpl(const boost::shared_ptr<FIELD> &field_ptr,
297 const boost::shared_ptr<REFENT> &ref_ents_ptr)
298 : interface_RefEntity<REFENT>(ref_ents_ptr) {}
299
300 /** \brief Virtual destructor */
301 virtual ~interface_FieldImpl() = default;
302};
303
304/**
305 * \brief Field interface with separate field and reference entity types
306 * \tparam FIELD Field type
307 * \tparam REFENT Reference entity type
308 */
309template <typename FIELD, typename REFENT>
310struct interface_Field : public interface_FieldImpl<FIELD, REFENT> {
311
312 /**
313 * \brief Constructor
314 * \param field_ptr Shared pointer to field
315 * \param ref_ents_ptr Shared pointer to reference entity
316 */
317 interface_Field(const boost::shared_ptr<FIELD> &field_ptr,
318 const boost::shared_ptr<REFENT> &ref_ents_ptr)
319 : interface_FieldImpl<FIELD, REFENT>(field_ptr, ref_ents_ptr),
320 sFieldPtr(field_ptr) {}
321
322 /** \brief Get field meshset handle */
323 inline EntityHandle getMeshset() const {
324 return getFieldRawPtr()->getMeshset();
325 }
326
327 /** \brief Get coordinate system dimension */
328 inline int getCoordSysDim(const int d = 0) const {
329 return getFieldRawPtr()->getCoordSysDim(d);
330 }
331
332 /** \brief Get field ID */
333 inline const BitFieldId &getId() const {
334 return getFieldRawPtr()->getId();
335 }
336
337 /** \brief Get field name reference */
338 inline boost::string_ref getNameRef() const {
339 return getFieldRawPtr()->getNameRef();
340 }
341
342 /** \brief Get field name */
343 inline std::string getName() const {
344 return getFieldRawPtr()->getName();
345 }
346
347 /** \brief Get approximation space */
348 inline FieldSpace getSpace() const {
349 return getFieldRawPtr()->getSpace();
350 }
351
352 /** \brief Get approximation basis */
354 return getFieldRawPtr()->getApproxBase();
355 }
356
357 /** \brief Get space continuity */
359 return getFieldRawPtr()->getContinuity();
360 }
361
362 /** \brief Get space continuity name */
363 inline auto getContinuityName() const {
365 }
366
367 /** \brief Get number of coefficients per DOF */
369 return getFieldRawPtr()->getNbOfCoeffs();
370 }
371
372 /** \brief Get bit number for field ID */
374 return getFieldRawPtr()->getBitNumber();
375 }
376
377 /**
378 * \brief Get DOF order mapping for entity type
379 * \param type Entity type
380 * \return DOF order array
381 */
382 inline std::array<ApproximationOrder, MAX_DOFS_ON_ENTITY> &
383 getDofOrderMap(const EntityType type) const {
384 return getFieldRawPtr()->getDofOrderMap(type);
385 }
386
387 /** \brief Get raw field pointer */
388 inline const Field *getFieldRawPtr() const {
389 return sFieldPtr->getFieldRawPtr();
390 };
391
392 /** \brief Get field order table */
394 return sFieldPtr->getFieldOrderTable();
395 };
396
397 /**
398 * \brief Get DOF side mapping for broken spaces
399 *
400 * Maps interior DOFs in broken spaces to entities where their traces
401 * are non-zero. Used for discontinuous Galerkin methods.
402 *
403 * \return Reference to DOF side mapping
404 */
405 inline auto &getDofSideMap() { return sFieldPtr->getDofSideMap(); }
406
407private:
408 mutable boost::shared_ptr<FIELD> sFieldPtr;
409};
410
411/**
412 * \brief Field interface specialization for same field and reference types
413 * \tparam T Field/reference type
414 */
415template <typename T>
416struct interface_Field<T, T> : public interface_FieldImpl<T, T> {
417
418 /**
419 * \brief Constructor
420 * \param ptr Shared pointer to field/reference object
421 */
422 interface_Field(const boost::shared_ptr<T> &ptr)
423 : interface_FieldImpl<T, T>(ptr, ptr) {}
424
426
427 /** \brief Get field meshset handle */
428 inline EntityHandle getMeshset() const {
429 return getFieldRawPtr()->getMeshset();
430 }
431
432 /** \brief Get field ID */
433 inline const BitFieldId &getId() const {
434 return getFieldRawPtr()->getId();
435 }
436
437 /** \brief Get field name reference */
438 inline boost::string_ref getNameRef() const {
439 return getFieldRawPtr()->getNameRef();
440 }
441
442 /** \brief Get field name */
443 inline std::string getName() const {
444 return getFieldRawPtr()->getName();
445 }
446
447 /** \brief Get approximation space */
448 inline FieldSpace getSpace() const {
449 return getFieldRawPtr()->getSpace();
450 }
451
452 /** \brief Get approximation space name */
453 inline auto getSpaceName() const { return getFieldRawPtr()->getSpaceName(); }
454
455 /** \brief Get approximation basis */
457 return getFieldRawPtr()->getApproxBase();
458 }
459
460 /** \brief Get approximation basis name */
461 inline auto getApproxBaseName() const {
463 }
464
465 /** \brief Get number of coefficients per DOF */
467 return getFieldRawPtr()->getNbOfCoeffs();
468 }
469
470 /** \brief Get bit number for field ID */
472 return getFieldRawPtr()->getBitNumber();
473 }
474
475 /**
476 * \brief Get DOF order mapping for entity type
477 * \param type Entity type
478 * \return DOF order array
479 */
480 inline std::array<ApproximationOrder, MAX_DOFS_ON_ENTITY> &
481 getDofOrderMap(const EntityType type) const {
482 return getFieldRawPtr()->getDofOrderMap(type);
483 }
484
485 /** \brief Get raw field pointer */
486 inline const Field *getFieldRawPtr() const {
487 return boost::static_pointer_cast<T>(this->getRefEntityPtr())
488 ->getFieldRawPtr();
489 };
490};
491
492/**
493 * \brief Multi-index container for field storage and retrieval
494 *
495 * Provides multiple indexed access patterns:
496 * - By field ID (hash-based unique access)
497 * - By meshset handle (ordered unique access)
498 * - By field name (ordered unique access)
499 * - By field space (ordered non-unique access)
500 *
501 * \relates multi_index_container
502 */
503typedef multi_index_container<
504 boost::shared_ptr<Field>,
505 indexed_by<
506 hashed_unique<tag<BitFieldId_mi_tag>,
507 const_mem_fun<Field, const BitFieldId &, &Field::getId>,
508 HashBit<BitFieldId>, EqBit<BitFieldId>>,
509 ordered_unique<tag<Meshset_mi_tag>,
510 member<Field, EntityHandle, &Field::meshSet>>,
511 ordered_unique<
512 tag<FieldName_mi_tag>,
513 const_mem_fun<Field, boost::string_ref, &Field::getNameRef>>,
514 ordered_non_unique<tag<BitFieldId_space_mi_tag>,
515 const_mem_fun<Field, FieldSpace, &Field::getSpace>>>>
517
518/**
519 * \brief Simplified field container with ID-based ordering
520 *
521 * Single-index container providing ordered access by field ID only.
522 * Used for efficient field iteration and subset operations.
523 */
524typedef multi_index_container<
525 boost::shared_ptr<Field>,
526 indexed_by<
527 ordered_unique<tag<BitFieldId_mi_tag>,
528 const_mem_fun<Field, const BitFieldId &, &Field::getId>,
529 LtBit<BitFieldId>>>>
531
532} // namespace MoFEM
533
534#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
Multi-index container for field storage and retrieval.
FieldApproximationBase
approximation base
Definition definitions.h:58
static const char *const FieldContinuityNames[]
FieldSpace
approximation spaces
Definition definitions.h:82
FieldContinuity
Field continuity.
Definition definitions.h:99
static const char *const FieldSpaceNames[]
Definition definitions.h:92
#define BITFIELDID_SIZE
max number of fields
static const char *const ApproximationBaseNames[]
Definition definitions.h:72
constexpr int order
FieldOrderFunct FieldOrderTable[MBMAXTYPE]
Array of functions defining DOF count for each entity type.
boost::function< int(const int order)> FieldOrderFunct
Function returning number of DOFs for given approximation order.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
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
Simplified field container with ID-based ordering.
Field data structure for finite element approximation.
FieldCoefficientsNumber getNbOfCoeffs() const
Get number of field coefficients per DOF.
const void * tagNamePrefixData
Field name prefix.
FieldOrderTable forderTable
DOF count functions for each entity type.
const void * tagName
Field name.
int tagNameSize
Field name size in bytes.
std::string getName() const
Get field name as string.
auto getSpaceName() const
Get field approximation space name.
int tagNamePrefixSize
Field name prefix size in bytes.
DofsOrderMap dofOrderMap
FieldApproximationBase getApproxBase() const
Get approximation basis type.
friend std::ostream & operator<<(std::ostream &os, const Field &e)
Output stream operator for field information.
unsigned int bitNumber
Bit number corresponding to this field's unique ID.
FieldContinuity getContinuity() const
Get field continuity type.
EntityHandle getMeshset() const
Get field meshset handle.
std::map< int, BaseFunction::DofsSideMap > & getDofSideMap() const
Get DOF side mapping for broken spaces.
EntityHandle meshSet
Meshset containing field entities.
FieldSpace * tagSpaceData
Field approximation space.
FieldBitNumber getBitNumberCalculate() const
Calculate bit number for this field's ID.
auto getApproxBaseName() const
Get approximation basis name.
const std::array< ApproximationOrder, MAX_DOFS_ON_ENTITY > & getDofOrderMap(const EntityType type) const
Get DOF order mapping for specific entity type.
static FieldBitNumber getBitNumberCalculate(const BitFieldId &id)
Calculate bit number from field ID bitset.
Tag th_FieldData
Tag for field values on entities.
const DofsOrderMap & getDofOrderMap() const
Get complete DOF order mapping for all entity types.
FieldOrderTable & getFieldOrderTable()
Get field order table.
MoFEMErrorCode rebuildDofsOrderMap()
Rebuild DOF order mapping arrays.
FieldContinuity * tagFieldContinuityData
Field continuity type.
FieldCoefficientsNumber * tagNbCoeffData
Field rank (e.g. Temperature=1, displacement in 3D=3)
BitFieldId * tagId
Field unique identifier.
FieldSpace getSpace() const
Get field approximation space.
static constexpr int maxBrokenDofsOrder
Maximum order for broken space DOFs.
Tag th_FieldDataVerts
Tag for field values on vertices.
SequenceDofContainer sequenceDofContainer
FieldApproximationBase * tagBaseData
Field basis functions.
SequenceDofContainer & getDofSequenceContainer() const
Get sequence container for bulk DOF allocation.
std::map< int, BaseFunction::DofsSideMap > dofSideMap
auto getContinuityName() const
Get field continuity name.
const Field * getFieldRawPtr() const
Get raw pointer to this field.
std::array< std::array< int, MAX_DOFS_ON_ENTITY >, MBMAXTYPE > DofsOrderMap
Array mapping entity types to DOF order arrays.
TagType tagFieldDataVertsType
Tag type for vertex data storage.
multi_index_container< boost::weak_ptr< std::vector< DofEntity > >, indexed_by< sequenced<> > > SequenceDofContainer
Container for bulk DOF allocation.
Tag th_FieldRank
Tag for field rank (vector dimension)
Tag th_AppOrder
Tag for approximation order on entities.
moab::Interface & moab
MOAB interface reference.
boost::string_ref getNameRef() const
Get field name as string reference.
virtual ~Field()=default
Virtual destructor.
FieldBitNumber getBitNumber() const
Get bit number for this field's ID.
const BitFieldId & getId() const
Get unique field identifier.
Base template interface for field pointer management.
interface_FieldImpl(const boost::shared_ptr< FIELD > &field_ptr, const boost::shared_ptr< REFENT > &ref_ents_ptr)
Constructor with field and reference entity pointers.
virtual ~interface_FieldImpl()=default
Virtual destructor.
const BitFieldId & getId() const
Get field ID.
FieldBitNumber getBitNumber() const
Get bit number for field ID.
interface_Field(const boost::shared_ptr< T > &ptr)
Constructor.
auto getApproxBaseName() const
Get approximation basis name.
FieldApproximationBase getApproxBase() const
Get approximation basis.
FieldSpace getSpace() const
Get approximation space.
EntityHandle getMeshset() const
Get field meshset handle.
FieldCoefficientsNumber getNbOfCoeffs() const
Get number of coefficients per DOF.
const Field * getFieldRawPtr() const
Get raw field pointer.
std::array< ApproximationOrder, MAX_DOFS_ON_ENTITY > & getDofOrderMap(const EntityType type) const
Get DOF order mapping for entity type.
auto getSpaceName() const
Get approximation space name.
std::string getName() const
Get field name.
boost::string_ref getNameRef() const
Get field name reference.
Field interface with separate field and reference entity types.
FieldBitNumber getBitNumber() const
Get bit number for field ID.
FieldContinuity getContinuity() const
Get space continuity.
FieldCoefficientsNumber getNbOfCoeffs() const
Get number of coefficients per DOF.
auto getContinuityName() const
Get space continuity name.
boost::string_ref getNameRef() const
Get field name reference.
FieldApproximationBase getApproxBase() const
Get approximation basis.
std::string getName() const
Get field name.
std::array< ApproximationOrder, MAX_DOFS_ON_ENTITY > & getDofOrderMap(const EntityType type) const
Get DOF order mapping for entity type.
EntityHandle getMeshset() const
Get field meshset handle.
const Field * getFieldRawPtr() const
Get raw field pointer.
auto & getDofSideMap()
Get DOF side mapping for broken spaces.
FieldSpace getSpace() const
Get approximation space.
const BitFieldId & getId() const
Get field ID.
interface_Field(const boost::shared_ptr< FIELD > &field_ptr, const boost::shared_ptr< REFENT > &ref_ents_ptr)
Constructor.
FieldOrderTable & getFieldOrderTable()
Get field order table.
boost::shared_ptr< FIELD > sFieldPtr
int getCoordSysDim(const int d=0) const
Get coordinate system dimension.
boost::shared_ptr< REFENT > & getRefEntityPtr() const