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 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 field 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 field 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
69 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 FieldContinuity *tagFieldContinuityData; ///< tag keeps field continuity
84 FieldApproximationBase *tagBaseData; ///< tag keeps field base
85
86 /// tag keeps field rank (dimension, f.e. Temperature field has rank 1,
87 /// displacements field in 3d has rank 3)
89 const void *tagName; ///< tag keeps name of the field
90 int tagNameSize; ///< number of bits necessary to keep field name
91 const void *tagNamePrefixData; ///< tag keeps name prefix of the field
92 int tagNamePrefixSize; ///< number of bits necessary to keep field name
93 ///< prefix
94 FieldOrderTable forderTable; ///< nb. DOFs table for entities
95
96 /**
97 * @brief Get the Field Order Table
98 *
99 * @return FieldOrderTable&
100 */
102
103 /**
104 * Field Id is bit set. Each field has only one bit on, bitNumber stores
105 * number of set bit
106 */
107 unsigned int bitNumber;
108
109 /**
110 * \brief Get field meshset
111 *
112
113 * To meshsets entity are attached Tags which keeps basic information about
114 * field. Those information is field name, approximation base, approximation
115 * space, id, etc.
116
117 * In meshset contains entities on which given field is sparing. Type of
118 entities
119 * depended on approximations space.
120
121 * @return EntityHandle
122 */
123 inline EntityHandle getMeshset() const { return meshSet; }
124
125 /**
126 * \brief Get unique field id.
127 * @return Filed ID
128 */
129 inline const BitFieldId &getId() const { return *((BitFieldId *)tagId); }
130
131 /**
132 * \brief Get string reference to field name
133 * @return Field name
134 */
135 inline boost::string_ref getNameRef() const {
136 return boost::string_ref((char *)tagName, tagNameSize);
137 }
138
139 /**
140 * \brief Get field name
141 * @return Field name
142 */
143 inline std::string getName() const {
144 return std::string((char *)tagName, tagNameSize);
145 }
146
147 /**
148 * \brief Get field approximation space
149 * @return approximation space
150 */
151 inline FieldSpace getSpace() const { return *tagSpaceData; }
152
153 /**
154 * \brief Get field approximation space
155 * @return approximation space name
156 */
157 inline auto getSpaceName() const {
158 return std::string(FieldSpaceNames[getSpace()]);
159 }
160
161 /** \brief Get field space continuity */
164 }
165
166 /**
167 * @brief Get field space continuity name
168 *
169 */
170 inline auto getContinuityName() const {
171 return std::string(FieldContinuityNames[getContinuity()]);
172 }
173
174 /**
175 * \brief Get approximation base
176 * @return Approximation base
177 */
179
180 /**
181 * \brief Get approximation base
182 * @return Approximation base name
183 */
184 inline auto getApproxBaseName() const {
185 return std::string(ApproximationBaseNames[getApproxBase()]);
186 }
187
188 /** \brief Get number of field coefficients
189 *
190
191 * Scalar field has only one coefficient, vector field in 3D has three. In
192 * general number determine space needed to keep data on entities. What
193 coefficient
194 * means depend on interpretation and associated coordinate system. For
195 example
196 * 3 coefficient means could be covariant or contravariant, or mean three
197 temperatures
198 * for mixture of solid, air and water, etc.
199
200
201 */
203 return *tagNbCoeffData;
204 };
205
206 /**
207 * \brief Get number of set bit in Field ID.
208 * Each field has uid, get getBitNumber get number of bit set for given field.
209 * Field ID has only one bit set for each field.
210 */
211 inline FieldBitNumber getBitNumber() const { return bitNumber; }
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 static_assert(BITFIELDID_SIZE >= 32,
220 "Too many fields allowed, can be more but ...");
221 FieldBitNumber b = ffsl(id.to_ulong());
222 if (b != 0)
223 return b;
224 return 0;
225 }
226
227 /**
228 * \brief Calculate number of set bit in Field ID.
229 * Each field has uid, get getBitNumber get number of bit set for given field.
230 * Field ID has only one bit set for each field.
231 */
233 return getBitNumberCalculate(static_cast<BitFieldId &>(*tagId));
234 }
235
236 /**
237 * \brief Get reference to sequence data container
238 *
239 * In sequence data container data are physically stored. The purpose of this
240 * is to allocate DofEntity data in bulk, having only one allocation instead
241 * each time entity is inserted. That makes code efficient.
242 *
243 * The vector in sequence is destroyed if last entity inside that vector is
244 * destroyed. All MoFEM::MoFEMEntities have aliased shared_ptr which points to
245 the vector.
246
247 * Not all DOFs are stored in this way, currently such cases are considered;
248 * - DOFs on vertices. That is exploited that for H1 space, there is some
249 * fixed number of DOFs on each vertex
250
251 * For other cases, DOFs are stored locally in each MoFEM::MoFEMEntities.
252
253 * @return MoFEM::Field::SequenceDofContainer
254 */
258
259 /**
260 * \brief get hash-map relating dof index on entity with its order
261 *
262 * Dofs of given field are indexed on entity
263 * of the same type, same space, approximation base and number of
264 * coefficients, are sorted in the way.
265 *
266 */
267 inline const std::array<ApproximationOrder, MAX_DOFS_ON_ENTITY> &
268 getDofOrderMap(const EntityType type) const {
269 return dofOrderMap[type];
270 }
271
272 /**
273 * \brief get hash-map relating dof index on entity with its order
274 *
275 * Dofs of given field are indexed on entity
276 * of the same type, same space, approximation base and number of
277 * coefficients, are sorted in the way.
278 *
279 */
280 inline const DofsOrderMap &getDofOrderMap() const { return dofOrderMap; }
281
282 static constexpr int maxBrokenDofsOrder = 10; ///< max number of broken dofs
283
284 /**
285 * @brief Get the dofs side map
286 *
287 * This establish connection between dofs in the interior of broken specs and
288 * entity on which trace of the dof is nonzero.
289 *
290 * @return const BaseFunction::DofsSideMap&
291 */
292 inline std::map<int, BaseFunction::DofsSideMap> &getDofSideMap() const {
293 return dofSideMap;
294 }
295
297
298 friend std::ostream &operator<<(std::ostream &os, const Field &e);
299
300 inline const Field *getFieldRawPtr() const { return this; };
301
302private:
305 mutable std::map<int, BaseFunction::DofsSideMap> dofSideMap;
306};
307
308/**
309 * \brief Pointer interface for MoFEM::Field
310 *
311 * MoFEM::Field class is keeps data and methods. This class is interface to
312 * that class, and all other classes, like MoFEMEntities, DofEntity and
313 * derived form them inherits pointer interface, not MoFEM::Field class
314 * directly.
315 *
316 * \ingroup dof_multi_indices
317 */
318template <typename FIELD, typename REFENT>
320
322
323 interface_FieldImpl(const boost::shared_ptr<FIELD> &field_ptr,
324 const boost::shared_ptr<REFENT> &ref_ents_ptr)
325 : interface_RefEntity<REFENT>(ref_ents_ptr) {}
326 virtual ~interface_FieldImpl() = default;
327};
328
329template <typename FIELD, typename REFENT>
330struct interface_Field : public interface_FieldImpl<FIELD, REFENT> {
331
332 interface_Field(const boost::shared_ptr<FIELD> &field_ptr,
333 const boost::shared_ptr<REFENT> &ref_ents_ptr)
334 : interface_FieldImpl<FIELD, REFENT>(field_ptr, ref_ents_ptr),
335 sFieldPtr(field_ptr) {}
336
337 inline EntityHandle getMeshset() const {
338 return getFieldRawPtr()->getMeshset();
339 }
340
341 inline int getCoordSysDim(const int d = 0) const {
342 return getFieldRawPtr()->getCoordSysDim(d);
343 }
344
345 /// @return get field Id
346 inline const BitFieldId &getId() const {
347 return getFieldRawPtr()->getId();
348 }
349
350 /// @return get field name
351 inline boost::string_ref getNameRef() const {
352 return getFieldRawPtr()->getNameRef();
353 }
354
355 /// @return get field name
356 inline std::string getName() const {
357 return getFieldRawPtr()->getName();
358 }
359
360 /// @return get approximation space
361 inline FieldSpace getSpace() const {
362 return getFieldRawPtr()->getSpace();
363 }
364
365 /// @return get approximation base
367 return getFieldRawPtr()->getApproxBase();
368 }
369
370 /// @return get space continuity
372 return getFieldRawPtr()->getContinuity();
373 }
374
375 /// @return get space continuity name
376 inline auto getContinuityName() const {
378 }
379
380 /// @return get number of coefficients for DOF
382 return getFieldRawPtr()->getNbOfCoeffs();
383 }
384
385 /// @return get bit number if field Id
387 return getFieldRawPtr()->getBitNumber();
388 }
389
390 /**
391 * \brief get hash-map relating dof index on entity with its order
392 *
393 * Dofs of given field are indexed on entity
394 * of the same type, same space, approximation base and number of
395 * coefficients, are sorted in the way.
396 *
397 */
398 inline std::array<ApproximationOrder, MAX_DOFS_ON_ENTITY> &
399 getDofOrderMap(const EntityType type) const {
400 return getFieldRawPtr()->getDofOrderMap(type);
401 }
402
403 inline const Field *getFieldRawPtr() const {
404 return sFieldPtr->getFieldRawPtr();
405 };
406
408 return sFieldPtr->getFieldOrderTable();
409 };
410
411 inline auto &getDofSideMap() { return sFieldPtr->getDofSideMap(); }
412
413private:
414 mutable boost::shared_ptr<FIELD> sFieldPtr;
415};
416
417template <typename T>
418struct interface_Field<T, T> : public interface_FieldImpl<T, T> {
419 interface_Field(const boost::shared_ptr<T> &ptr)
420 : interface_FieldImpl<T, T>(ptr, ptr) {}
421
423
424 inline EntityHandle getMeshset() const {
425 return getFieldRawPtr()->getMeshset();
426 }
427
428 /// @return get field Id
429 inline const BitFieldId &getId() const {
430 return getFieldRawPtr()->getId();
431 }
432
433 /// @return get field name
434 inline boost::string_ref getNameRef() const {
435 return getFieldRawPtr()->getNameRef();
436 }
437
438 /// @return get field name
439 inline std::string getName() const {
440 return getFieldRawPtr()->getName();
441 }
442
443 /// @return get approximation space
444 inline FieldSpace getSpace() const {
445 return getFieldRawPtr()->getSpace();
446 }
447
448 /// @return get approximation base
449 inline auto getSpaceName() const { return getFieldRawPtr()->getSpaceName(); }
450
451 /// @return get approximation base
453 return getFieldRawPtr()->getApproxBase();
454 }
455
456 /// @return get approximation base
457 inline auto getApproxBaseName() const {
459 }
460
461 /// @return get number of coefficients for DOF
463 return getFieldRawPtr()->getNbOfCoeffs();
464 }
465
466 /// @return get bit number if field Id
468 return getFieldRawPtr()->getBitNumber();
469 }
470
471 /**
472 * \brief get hash-map relating dof index on entity with its order
473 *
474 * Dofs of given field are indexed on entity
475 * of the same type, same space, approximation base and number of
476 * coefficients, are sorted in the way.
477 *
478 */
479 inline std::array<ApproximationOrder, MAX_DOFS_ON_ENTITY> &
480 getDofOrderMap(const EntityType type) const {
481 return getFieldRawPtr()->getDofOrderMap(type);
482 }
483
484 inline const Field *getFieldRawPtr() const {
485 return boost::static_pointer_cast<T>(this->getRefEntityPtr())
486 ->getFieldRawPtr();
487 };
488};
489
490/**
491 * @relates multi_index_container
492 * \brief Field_multiIndex for Field
493 *
494 */
495typedef multi_index_container<
496 boost::shared_ptr<Field>,
497 indexed_by<
498 hashed_unique<tag<BitFieldId_mi_tag>,
499 const_mem_fun<Field, const BitFieldId &, &Field::getId>,
500 HashBit<BitFieldId>, EqBit<BitFieldId>>,
501 ordered_unique<tag<Meshset_mi_tag>,
502 member<Field, EntityHandle, &Field::meshSet>>,
503 ordered_unique<
504 tag<FieldName_mi_tag>,
505 const_mem_fun<Field, boost::string_ref, &Field::getNameRef>>,
506 ordered_non_unique<tag<BitFieldId_space_mi_tag>,
507 const_mem_fun<Field, FieldSpace, &Field::getSpace>>>>
509
510typedef multi_index_container<
511 boost::shared_ptr<Field>,
512 indexed_by<
513 ordered_unique<tag<BitFieldId_mi_tag>,
514 const_mem_fun<Field, const BitFieldId &, &Field::getId>,
515 LtBit<BitFieldId>>>>
517
518} // namespace MoFEM
519
520#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
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]
user adjacency function table
boost::function< int(const int order)> FieldOrderFunct
user adjacency function
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
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
FieldContinuity getContinuity() const
Get field space continuity.
multi_index_container< boost::weak_ptr< std::vector< DofEntity > >, indexed_by< sequenced<> > > SequenceDofContainer
EntityHandle getMeshset() const
Get field meshset.
std::map< int, BaseFunction::DofsSideMap > & getDofSideMap() const
Get the dofs side map.
EntityHandle meshSet
keeps entities for this meshset
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...
std::array< std::array< int, MAX_DOFS_ON_ENTITY >, MBMAXTYPE > DofsOrderMap
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()
FieldContinuity * tagFieldContinuityData
tag keeps field continuity
FieldCoefficientsNumber * tagNbCoeffData
BitFieldId * tagId
Tag field rank.
FieldSpace getSpace() const
Get field approximation space.
static constexpr int maxBrokenDofsOrder
max number of broken dofs
Field(moab::Interface &moab, const EntityHandle meshset)
constructor for moab field
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.
std::map< int, BaseFunction::DofsSideMap > dofSideMap
auto getContinuityName() const
Get field space continuity name.
const Field * getFieldRawPtr() const
TagType tagFieldDataVertsType
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.
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
const BitFieldId & getId() const
FieldBitNumber getBitNumber() const
interface_Field(const boost::shared_ptr< T > &ptr)
FieldApproximationBase getApproxBase() const
FieldCoefficientsNumber getNbOfCoeffs() 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
FieldContinuity getContinuity() 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
boost::shared_ptr< REFENT > & getRefEntityPtr() const