INMOST
A toolkit for distributed mathematical modeling
inmost_data.h
1 #ifndef INMOST_DATA_H_INCLUDED
2 #define INMOST_DATA_H_INCLUDED
3 
4 #include "inmost_common.h"
5 #if defined(USE_AUTODIFF)
6 #include "inmost_expression.h"
7 #endif
8 #include "inmost_dense.h"
9 
10 #if defined(USE_MESH)
11 
12 
13 namespace INMOST
14 {
15  class Mesh;
16  class Storage;
17  class Element;
18  class TagManager;
19  class Node;
20  class Edge;
21  class Face;
22  class Cell;
23  class ElementSet;
24 
26  // ElementType
27 
28  typedef INMOST_DATA_BULK_TYPE ElementType;
29  static const ElementType NONE = 0x00;
30  static const ElementType NODE = 0x01;
31  static const ElementType EDGE = 0x02;
32  static const ElementType FACE = 0x04;
33  static const ElementType CELL = 0x08;
34  static const ElementType ESET = 0x10;
35  static const ElementType MESH = 0x20;
36 #define NUM_ELEMENT_TYPS 6
37 
38  __INLINE bool OneType (ElementType t) {return t > 0 && (t & (t-1)) == 0;}
39  __INLINE ElementType FirstElementType () {return NODE;}
40  __INLINE ElementType LastElementType () {return MESH << 1;}
41  __INLINE ElementType NextElementType (ElementType etype) {return etype << 1;}
42  __INLINE ElementType PrevElementType (ElementType etype) {return etype >> 1;}
43  __INLINE ElementType ElementTypeFromDim (INMOST_DATA_INTEGER_TYPE dim) {return 1 << dim;}
44  const char * ElementTypeName (ElementType t); //mesh.cpp
45  __INLINE INMOST_DATA_INTEGER_TYPE ElementNum (ElementType t)
46  {
47  unsigned int v = static_cast<unsigned int>(t); // 32-bit value to find the log2 of
48  //static const unsigned int b[] = {0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00, 0xFFFF0000};
49  static const unsigned int b[] = {0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0};
50  unsigned int r = (v & b[0]) != 0;
51  //r |= ((v & b[4]) != 0) << 4;
52  //r |= ((v & b[3]) != 0) << 3;
53  r |= ((v & b[2]) != 0) << 2;
54  r |= ((v & b[1]) != 0) << 1;
55  return static_cast<INMOST_DATA_INTEGER_TYPE>(r);
56  }
57 
59  // MarkerType
60 
62  typedef INMOST_DATA_ENUM_TYPE MarkerType;
64  static const INMOST_DATA_ENUM_TYPE MarkerFields = 16;
66  static const INMOST_DATA_ENUM_TYPE MarkerFieldsPrivate = 4;
68  static const INMOST_DATA_ENUM_TYPE MarkerPrivateBit = static_cast<INMOST_DATA_ENUM_TYPE>(1) << (sizeof(INMOST_DATA_ENUM_TYPE)*8-1);
70  static const INMOST_DATA_ENUM_TYPE MarkerMask = static_cast<INMOST_DATA_BULK_TYPE>(-1);
72  static const INMOST_DATA_ENUM_TYPE MarkerShift = sizeof(INMOST_DATA_BULK_TYPE)*8;
73  __INLINE static bool isPrivate (MarkerType n) {return (n & MarkerPrivateBit) == MarkerPrivateBit;}
74  __INLINE static MarkerType InvalidMarker (){return ENUMUNDEF;}
75 
76 
78  // HandleType
79 
80  typedef INMOST_DATA_ENUM_TYPE HandleType;
81  static const INMOST_DATA_ENUM_TYPE handle_etype_bits = 3;
82  static const INMOST_DATA_ENUM_TYPE handle_etype_shift = sizeof(HandleType)*8-handle_etype_bits;
83  static const INMOST_DATA_ENUM_TYPE handle_id_mask = (static_cast<INMOST_DATA_ENUM_TYPE>(1) << handle_etype_shift)-1;
84 
85  static const INMOST_DATA_ENUM_TYPE chunk_bits_elems = 13;
86  static const INMOST_DATA_ENUM_TYPE chunk_bits_empty = 8;
87  static const INMOST_DATA_ENUM_TYPE chunk_bits_tags = 6;
88  static const INMOST_DATA_ENUM_TYPE chunk_bits_dense = 6;
89 
90  __INLINE HandleType InvalidHandle () {return 0;}
91  __INLINE INMOST_DATA_INTEGER_TYPE GetHandleID (HandleType h) {return (h & handle_id_mask)-1;}
92  __INLINE INMOST_DATA_INTEGER_TYPE GetHandleElementNum (HandleType h) {return h >> handle_etype_shift;}
93  __INLINE ElementType GetHandleElementType(HandleType h) {return 1 << GetHandleElementNum(h);}
94  __INLINE HandleType ComposeHandle (ElementType etype, INMOST_DATA_INTEGER_TYPE ID) {return ID == -1 ? InvalidHandle() : ((ElementNum(etype) << handle_etype_shift) + (1+ID));}
95  __INLINE HandleType ComposeCellHandle (INMOST_DATA_INTEGER_TYPE ID) {return ID == -1 ? InvalidHandle() : ((ElementNum(CELL) << handle_etype_shift) + (1+ID));}
96  __INLINE HandleType ComposeFaceHandle (INMOST_DATA_INTEGER_TYPE ID) {return ID == -1 ? InvalidHandle() : ((ElementNum(FACE) << handle_etype_shift) + (1+ID));}
97  __INLINE HandleType ComposeEdgeHandle (INMOST_DATA_INTEGER_TYPE ID) {return ID == -1 ? InvalidHandle() : ((ElementNum(EDGE) << handle_etype_shift) + (1+ID));}
98  __INLINE HandleType ComposeNodeHandle (INMOST_DATA_INTEGER_TYPE ID) {return ID == -1 ? InvalidHandle() : ((ElementNum(NODE) << handle_etype_shift) + (1+ID));}
99  __INLINE HandleType ComposeSetHandle (INMOST_DATA_INTEGER_TYPE ID) {return ID == -1 ? InvalidHandle() : ((ElementNum(ESET) << handle_etype_shift) + (1+ID));}
100  __INLINE HandleType ComposeHandleNum (INMOST_DATA_INTEGER_TYPE etypenum, INMOST_DATA_INTEGER_TYPE ID) {return ID == -1 ? InvalidHandle() : ((etypenum << handle_etype_shift) + (1+ID));}
101  __INLINE bool isValidHandle (HandleType h) {return h != 0;}
102 
104  // RemoteElementType
105 
106  typedef std::pair<Mesh*,HandleType> RemoteHandleType;
108  Element MakeElement (const RemoteHandleType & rh); //storage.cpp
110  Element MakeElementRef (RemoteHandleType & rh); //storage.cpp
111 
112 
113 
114 #if defined(USE_AUTODIFF)
115  typedef array<variable> inner_variable_array;
116 #endif
117  typedef array<INMOST_DATA_REAL_TYPE> inner_real_array;
118  typedef array<INMOST_DATA_INTEGER_TYPE>
119  inner_integer_array;
120  typedef array<INMOST_DATA_BULK_TYPE> inner_bulk_array;
121  typedef array<HandleType> inner_reference_array;
122  typedef array<RemoteHandleType> inner_remote_reference_array;
123 
124  enum DataType
125  {
126  DATA_REAL = 0,
127  DATA_INTEGER = 1,
128  DATA_BULK = 2,
129  DATA_REFERENCE = 3,
130  DATA_REMOTE_REFERENCE = 4,
131 #if defined(USE_AUTODIFF)
132  DATA_VARIABLE = 5
133 #endif
134  };
135 
137  const char * DataTypeName (DataType t);
138 
139 
143  class TagMemory
144  {
145  public:
150  TagMemory(Mesh * m, const TagMemory & other);
152  TagMemory & operator =(TagMemory const & other);
153  private:
155  TagMemory();
157  INMOST_DATA_ENUM_TYPE pos[NUM_ELEMENT_TYPS];
159  DataType dtype;
161  std::string tagname;
163  INMOST_MPI_Type bulk_data_type;
166  INMOST_DATA_ENUM_TYPE size;
168  INMOST_DATA_ENUM_TYPE bytes_size;
171  bool sparse[NUM_ELEMENT_TYPS];
174  INMOST_DATA_ENUM_TYPE record_size;
181  bool print_tag;
183  Mesh * m_link;
185  friend class Tag;
187  friend class Storage;
188  };
189 
190 
192  class Tag //implemented in tag.cpp
193  {
194  private:
196  TagMemory * mem;
198  Tag (Mesh * m,std::string name, DataType _dtype, INMOST_DATA_ENUM_TYPE size);
199  __INLINE INMOST_DATA_ENUM_TYPE GetRecordSize() const;
200  __INLINE void SetSize(INMOST_DATA_ENUM_TYPE size);
201  __INLINE void SetPosition(INMOST_DATA_ENUM_TYPE pos, ElementType type);
202  __INLINE INMOST_DATA_ENUM_TYPE GetPosition(ElementType type) const;
203  __INLINE void SetSparse(ElementType type);
204  __INLINE INMOST_DATA_ENUM_TYPE GetPositionByDim(INMOST_DATA_ENUM_TYPE typenum) const;
205  __INLINE void ChangeName(std::string newname);
206  public:
207  ~Tag();
208  Tag();
209  Tag(const Tag & other);
210  __INLINE bool operator <(const Tag & other) const;
211  __INLINE bool operator >(const Tag & other) const;
212  __INLINE bool operator ==(const Tag & other) const;
213  __INLINE bool operator !=(const Tag & other) const;
214  __INLINE Tag & operator =(Tag const & other);
215  __INLINE DataType GetDataType() const;
216  __INLINE INMOST_MPI_Type GetBulkDataType() const;
220  __INLINE INMOST_DATA_ENUM_TYPE GetBytesSize() const;
223  INMOST_DATA_ENUM_TYPE GetPackedBytesSize() const;
224  __INLINE INMOST_DATA_ENUM_TYPE GetSize() const;
225  __INLINE std::string GetTagName() const;
226  __INLINE bool isDefined(ElementType type) const;
227  __INLINE bool isDefinedMask(ElementType mask) const;
228  __INLINE bool isSparse(ElementType type) const;
229  __INLINE bool isValid() const;
230  __INLINE Mesh * GetMeshLink() const;
231  __INLINE bool isSparseByDim(INMOST_DATA_INTEGER_TYPE typenum)const;
232  __INLINE bool isDefinedByDim(INMOST_DATA_INTEGER_TYPE typenum)const;
233  __INLINE void SetBulkDataType(INMOST_MPI_Type type);
234  __INLINE void SetPrint(bool print);
235  __INLINE bool GetPrint() const;
236  friend class TagManager;
237  friend class Storage;
238  friend class Mesh;
239  };
240 
241 
242 
243  class TagManager //implemented in tag.cpp
244  {
245  protected:
246  TagManager();
247  TagManager(const TagManager & other);
248  TagManager & operator = (TagManager const & other);
253  typedef struct{void * tag, * rec;} sparse_sub_record;
257  //typedef std::vector<INMOST_DATA_INTEGER_TYPE> back_links_type;
258  public:
259  typedef tag_array_type::iterator iteratorTag;
260  public:
261  virtual ~TagManager();
263  bool HaveTag(std::string name) const;
265  Tag GetTag(std::string name) const;
267  void ListTagNames(std::vector<std::string> & list) const;
269  Tag CreateTag(Mesh * m, std::string name, DataType dtype, ElementType etype, ElementType sparse, INMOST_DATA_ENUM_TYPE size = ENUMUNDEF);
271  virtual Tag DeleteTag(Tag tag, ElementType mask);
273  bool ElementDefined(Tag const & tag, ElementType etype) const;
275  bool RenameTag(std::string oldname, std::string newname);
276  protected:
278  void ReallocateData(const Tag & t, INMOST_DATA_INTEGER_TYPE etypenum,INMOST_DATA_ENUM_TYPE new_size);
280  void ReallocateData(INMOST_DATA_INTEGER_TYPE etypenum, INMOST_DATA_ENUM_TYPE new_size);
282  __INLINE sparse_sub_type const & GetSparseData(int etypenum, int local_id) const {return sparse_data[etypenum][local_id];}
284  __INLINE sparse_sub_type & GetSparseData(int etypenum, int local_id) {return sparse_data[etypenum][local_id];}
286  __INLINE dense_sub_type const & GetDenseData(int pos) const {return dense_data[pos];}
288  __INLINE dense_sub_type & GetDenseData(int pos) {return dense_data[pos];}
290  static void CopyData(const Tag & t, void * adata, const void * bdata);
292  static void DestroyVariableData(const Tag & t, void * adata);
293  protected:
294  typedef tag_array_type::iterator tag_iterator; //< Use this type to iterate over tags of the mesh.
295  typedef tag_array_type::const_iterator tag_const_iterator; //< Use this type to iterate over tags of the mesh without right for modification.
296  protected:
297  tag_array_type tags;
298  empty_data empty_dense_data;
299  dense_data_array_type dense_data;
300  sparse_data_array_type sparse_data[NUM_ELEMENT_TYPS];
301  back_links_type back_links[NUM_ELEMENT_TYPS];
302  };
303 
309  class Storage //implemented in storage.cpp
310  {
311  public:
313  typedef INMOST_DATA_REAL_TYPE real;
315  typedef INMOST_DATA_INTEGER_TYPE integer;
317  typedef INMOST_DATA_BULK_TYPE bulk;
319  typedef INMOST_DATA_ENUM_TYPE enumerator;
321  typedef HandleType reference;
323  typedef RemoteHandleType remote_reference;
330 #if defined(USE_AUTODIFF)
332  typedef variable var;
335 #endif
337  class reference_array : public shell<reference>
338  {
339  Mesh * m;
340  public:
341  reference_array() : m(NULL) {}
342  reference_array(Mesh * m, inner_reference_array & arr) : shell<reference>(arr), m(m) {}
343  reference_array(Mesh * m, reference * arr, size_type size) : shell<reference>(arr,size), m(m) {}
344  ~reference_array() {}
345  void push_back(const Storage & elem);
346  void push_back(HandleType h) {shell<reference>::push_back(h);} //is it needed?
347  Element operator[] (size_type n);
348  Element operator[] (size_type n) const;
349  class iterator : public shell<HandleType>::iterator
350  {
351  Mesh * m;
352  public:
353  iterator() :shell<HandleType>::iterator(), m(NULL) {}
354  iterator(Mesh * m, const shell<HandleType>::iterator & other) : shell<HandleType>::iterator(other), m(m) {}
355  iterator(const iterator & other) : shell<HandleType>::iterator(other), m(other.m) {}
356  iterator & operator =(iterator const & other) {m = other.m; shell<HandleType>::iterator::operator=(other); return *this;}
357  iterator & operator ++() {shell<HandleType>::iterator::operator++(); return *this;}
358  iterator operator ++(int) {iterator ret(*this); shell<HandleType>::iterator::operator++(); return ret;}
359  iterator & operator --() {shell<HandleType>::iterator::operator--(); return *this;}
360  iterator operator --(int) {iterator ret(*this); shell<HandleType>::iterator::operator--(); return ret;}
361  Element operator->();
362  };
363  class const_iterator : public shell<HandleType>::const_iterator
364  {
365  Mesh * m;
366  public:
369  const_iterator(const const_iterator & other) : shell<HandleType>::const_iterator(other), m(other.m) {}
370  const_iterator & operator =(const_iterator const & other) {m = other.m; shell<HandleType>::const_iterator::operator=(other); return *this;}
371  const_iterator & operator ++() {shell<HandleType>::const_iterator::operator++(); return *this;}
372  const_iterator operator ++(int) {const_iterator ret(*this); shell<HandleType>::const_iterator::operator++(); return ret;}
373  const_iterator & operator --() {shell<HandleType>::const_iterator::operator--(); return *this;}
374  const_iterator operator --(int) {const_iterator ret(*this); shell<HandleType>::const_iterator::operator--(); return ret;}
375  Element operator->();
376  };
377  class reverse_iterator : public shell<HandleType>::reverse_iterator
378  {
379  Mesh * m;
380  public:
383  reverse_iterator(const reverse_iterator & other) : shell<HandleType>::reverse_iterator(other), m(other.m) {}
384  reverse_iterator & operator =(reverse_iterator const & other) {m = other.m; shell<HandleType>::reverse_iterator::operator=(other); return *this;}
385  reverse_iterator & operator ++() {shell<HandleType>::reverse_iterator::operator++(); return *this;}
386  reverse_iterator operator ++(int) {reverse_iterator ret(*this); shell<HandleType>::reverse_iterator::operator++(); return ret;}
387  reverse_iterator & operator --() {shell<HandleType>::reverse_iterator::operator--(); return *this;}
388  reverse_iterator operator --(int) {reverse_iterator ret(*this); shell<HandleType>::reverse_iterator::operator--(); return ret;}
389  Element operator->();
390  };
392  {
393  Mesh * m;
394  public:
398  const_reverse_iterator & operator =(const_reverse_iterator const & other) {m = other.m; shell<HandleType>::const_reverse_iterator::operator=(other); return *this;}
403  Element operator->();
404  };
405  iterator begin() {return iterator(m,shell<HandleType>::begin());}
406  const_iterator begin() const {return const_iterator(m,shell<HandleType>::begin());}
407  reverse_iterator rbegin() {return reverse_iterator(m,shell<HandleType>::rbegin());}
408  const_reverse_iterator rbegin() const {return const_reverse_iterator(m,shell<HandleType>::rbegin());}
409  iterator end() {return iterator(m,shell<HandleType>::end());}
410  const_iterator end() const {return const_iterator(m,shell<HandleType>::end());}
411  reverse_iterator rend() {return reverse_iterator(m,shell<HandleType>::rend());}
412  const_reverse_iterator rend() const {return const_reverse_iterator(m,shell<HandleType>::rend());}
413  void SetMeshLink(Mesh * new_m) {m = new_m;}
414  Element back();
415  Element back() const;
416  Element front();
417  Element front() const;
418  iterator erase(iterator it) { return iterator(m, shell<reference>::erase(it)); }
419  };
421  class remote_reference_array : public shell<remote_reference>
422  {
423  public:
426  //~ remote_reference_array(const remote_reference_array & other) :shell<remote_reference>(other) {}
428  void push_back(const Storage & elem);
429  void push_back(Mesh * m, HandleType h) {shell<remote_reference>::push_back(RemoteHandleType(m,h));} //is it needed?
430  Element operator[] (size_type n);
431  Element operator[] (size_type n) const;
432  class iterator : public shell<remote_reference>::iterator
433  {
434  public:
437  iterator(const iterator & other) : shell<remote_reference>::iterator(other) {}
438  Element operator->();
439  };
440  class const_iterator : public shell<remote_reference>::const_iterator
441  {
442  public:
446  Element operator->();
447  };
448  class reverse_iterator : public shell<remote_reference>::reverse_iterator
449  {
450  public:
454  Element operator->();
455  };
456  class const_reverse_iterator : public shell<remote_reference>::const_reverse_iterator
457  {
458  public:
462  Element operator->();
463  };
464  Element back();
465  Element back() const;
466  Element front();
467  Element front() const;
468  };
469  //typedef shell<reference> reference_array;
470  protected:
471  HandleType handle;
472  HandleType * handle_link;
473  private:
474  Mesh * m_link;
475  public:
476  Storage(const Storage & other) : handle(other.handle), handle_link(other.handle_link), m_link(other.m_link) {}
477  Storage(Mesh * mesh, HandleType handle) : handle(handle), handle_link(NULL), m_link(mesh) {}
479  Storage(Mesh * mesh, HandleType * handle) : handle(*handle), handle_link(handle), m_link(mesh) {}
482  Storage & operator = (Storage const & other);
483  __INLINE bool operator < (const Storage & other) const {return handle < other.handle;}
484  __INLINE bool operator > (const Storage & other) const {return handle > other.handle;}
485  __INLINE bool operator <= (const Storage & other) const {return handle <= other.handle;}
486  __INLINE bool operator >= (const Storage & other) const {return handle >= other.handle;}
487  __INLINE bool operator == (const Storage & other) const {return handle == other.handle;}
488  __INLINE bool operator != (const Storage & other) const {return handle != other.handle;}
489  __INLINE Storage * operator-> () {return this;}
490  __INLINE const Storage * operator-> () const {return this;}
491  __INLINE Storage & self () {return *this;}
492  __INLINE const Storage & self () const {return *this;}
493  virtual ~Storage() {}
494  public:
497  __INLINE real & Real (const Tag & tag) const;
500  __INLINE integer & Integer (const Tag & tag) const;
503  __INLINE bulk & Bulk (const Tag & tag) const;
506  __INLINE reference & Reference (const Tag & tag) const;
509  __INLINE remote_reference & RemoteReference (const Tag & tag) const;
512  __INLINE real_array RealArray (const Tag & tag) const;
515  __INLINE integer_array IntegerArray (const Tag & tag) const;
519  __INLINE bulk_array BulkArray (const Tag & tag) const;
523  __INLINE reference_array ReferenceArray (const Tag & tag) const;
527  __INLINE remote_reference_array RemoteReferenceArray(const Tag & tag) const;
528 
529  //optimized data requests for dense data with fixed size
530  __INLINE real_array RealArrayDF (const Tag & tag) const;
531  __INLINE integer_array IntegerArrayDF (const Tag & tag) const;
532  __INLINE bulk_array BulkArrayDF (const Tag & tag) const;
533  __INLINE reference_array ReferenceArrayDF (const Tag & tag) const;
534  __INLINE remote_reference_array RemoteReferenceArrayDF(const Tag & tag) const;
535  __INLINE real & RealDF (const Tag & tag) const;
536  __INLINE integer & IntegerDF (const Tag & tag) const;
537  __INLINE bulk & BulkDF (const Tag & tag) const;
538  __INLINE reference & ReferenceDF (const Tag & tag) const;
539  __INLINE remote_reference & RemoteReferenceDF (const Tag & tag) const;
540 
541  //optimized data requests for dense data with variable size
542  __INLINE real_array RealArrayDV (const Tag & tag) const;
543  __INLINE integer_array IntegerArrayDV (const Tag & tag) const;
544  __INLINE bulk_array BulkArrayDV (const Tag & tag) const;
545  __INLINE reference_array ReferenceArrayDV (const Tag & tag) const;
546  __INLINE remote_reference_array RemoteReferenceArrayDV(const Tag & tag) const;
547  __INLINE real & RealDV (const Tag & tag) const;
548  __INLINE integer & IntegerDV (const Tag & tag) const;
549  __INLINE bulk & BulkDV (const Tag & tag) const;
550  __INLINE reference & ReferenceDV (const Tag & tag) const;
551  __INLINE remote_reference & RemoteReferenceDV (const Tag & tag) const;
552 #if defined(USE_AUTODIFF)
554  __INLINE var & Variable (const Tag & tag) const;
555  __INLINE var & VariableDF (const Tag & tag) const;
556  __INLINE var & VariableDV (const Tag & tag) const;
558  __INLINE var_array VariableArray (const Tag & tag) const;
559  __INLINE var_array VariableArrayDF (const Tag & tag) const;
560  __INLINE var_array VariableArrayDV (const Tag & tag) const;
561 #endif
562 
568  __INLINE INMOST_DATA_ENUM_TYPE GetDataSize (const Tag & tag) const;
574  __INLINE INMOST_DATA_ENUM_TYPE GetDataCapacity (const Tag & tag) const;
580  __INLINE void SetDataSize (const Tag & tag,
581  INMOST_DATA_ENUM_TYPE new_size) const;
591  __INLINE void GetData (const Tag & tag,
592  INMOST_DATA_ENUM_TYPE shift,
593  INMOST_DATA_ENUM_TYPE size,
594  void * data) const;
595  __INLINE void SetData (const Tag & tag,
596  INMOST_DATA_ENUM_TYPE shift,
597  INMOST_DATA_ENUM_TYPE size,
598  const void * data) const;
599  __INLINE void DelData (const Tag & tag) const;
601  __INLINE bool DelSparseData (const Tag & tag) const;
603  __INLINE void DelDenseData (const Tag & tag) const;
605  __INLINE bool HaveData (const Tag & tag) const;
606  __INLINE ElementType GetElementType () const;
607  __INLINE integer GetElementNum () const;
608  __INLINE void SetMarker (MarkerType n) const;
609  __INLINE bool GetMarker (MarkerType n) const;
610  __INLINE void RemMarker (MarkerType n) const;
611  __INLINE void SetPrivateMarker (MarkerType n) const;
612  __INLINE bool GetPrivateMarker (MarkerType n) const;
613  __INLINE void RemPrivateMarker (MarkerType n) const;
614  __INLINE void ClearMarkerSpace () const;
615  __INLINE void GetMarkerSpace (bulk copy[MarkerFields]) const;
616  __INLINE void SetMarkerSpace (bulk source[MarkerFields]) const;
617  __INLINE integer LocalID () const;
620  __INLINE integer DataLocalID () const;
621  __INLINE bool isValid () const;
622  __INLINE Mesh * GetMeshLink () const;
623  __INLINE HandleType GetHandle () const;
624  __INLINE Element getAsElement () const;
625  __INLINE Node getAsNode () const;
626  __INLINE Edge getAsEdge () const;
627  __INLINE Face getAsFace () const;
628  __INLINE Cell getAsCell () const;
629  __INLINE ElementSet getAsSet () const;
630  friend class Mesh;
631  };
632 
636 
637  class TagReal : public Tag
638  {
639  public:
640  TagReal() : Tag() {}
641  TagReal(const TagReal & b) : Tag(b) {}
642  TagReal(const Tag & b) : Tag(b) {}
643  TagReal & operator = (TagReal const & b) {Tag::operator =(b); return *this;}
644  TagReal & operator = (Tag const & b) {Tag::operator =(b); return *this;}
645  __INLINE Storage::real & operator [](const Storage & arg) const {return arg.Real(*static_cast<const Tag*>(this));}
646  __INLINE Storage::real & operator [](HandleType h) const;
647  };
648 
649  class TagInteger : public Tag
650  {
651  public:
652  TagInteger() : Tag() {}
653  TagInteger(const TagInteger & b) : Tag(b) {}
654  TagInteger(const Tag & b) : Tag(b) {}
655  TagInteger & operator = (TagInteger const & b) {Tag::operator =(b); return *this;}
656  TagInteger & operator = (Tag const & b) {Tag::operator =(b); return *this;}
657  __INLINE Storage::integer & operator [](const Storage & arg) const {return arg.Integer(*static_cast<const Tag*>(this));}
658  __INLINE Storage::integer & operator [](HandleType h) const;
659  };
660 
661  class TagBulk : public Tag
662  {
663  public:
664  TagBulk() : Tag() {}
665  TagBulk(const TagBulk & b) : Tag(b) {}
666  TagBulk(const Tag & b) : Tag(b) {}
667  TagBulk & operator = (TagBulk const & b) {Tag::operator =(b); return *this;}
668  TagBulk & operator = (Tag const & b) {Tag::operator =(b); return *this;}
669  __INLINE Storage::bulk & operator [](const Storage & arg) const {return arg.Bulk(*static_cast<const Tag*>(this));}
670  __INLINE Storage::bulk & operator [](HandleType h) const;
671  };
672 
673  class TagReference : public Tag
674  {
675  public:
676  TagReference() : Tag() {}
677  TagReference(const TagReference & b) : Tag(b) {}
678  TagReference(const Tag & b) : Tag(b) {}
679  TagReference & operator = (TagReference const & b) {Tag::operator =(b); return *this;}
680  TagReference & operator = (Tag const & b) {Tag::operator =(b); return *this;}
681  __INLINE Storage::reference & operator [](const Storage & arg) const {return arg.Reference(*static_cast<const Tag*>(this));}
682  __INLINE Storage::reference & operator [](HandleType h) const;
683  };
684 
685 
686  class TagRealArray : public Tag
687  {
688  public:
689  TagRealArray() : Tag() {}
690  TagRealArray(const TagRealArray & b) : Tag(b) {}
691  TagRealArray(const Tag & b) : Tag(b) {}
692  TagRealArray & operator = (TagRealArray const & b) {Tag::operator =(b); return *this;}
693  TagRealArray & operator = (Tag const & b) {Tag::operator =(b); return *this;}
694  __INLINE Storage::real_array operator [](const Storage & arg) const {return arg.RealArray(*static_cast<const Tag*>(this));}
695  __INLINE Storage::real_array operator [](HandleType h) const;
696  __INLINE Matrix<Storage::real,Storage::real_array> operator()(const Storage & arg, int n, int m) const
697  {
698  Storage::real_array data = arg.RealArray(*static_cast<const Tag*>(this));
699  assert((int)data.size() == n*m);
701  }
702  __INLINE Matrix<Storage::real,Storage::real_array> operator()(HandleType h, int n, int m) const;
703  };
704 
705  class TagIntegerArray : public Tag
706  {
707  public:
708  TagIntegerArray() : Tag() {}
709  TagIntegerArray(const TagIntegerArray & b) : Tag(b) {}
710  TagIntegerArray(const Tag & b) : Tag(b) {}
711  TagIntegerArray & operator = (TagIntegerArray const & b) {Tag::operator =(b); return *this;}
712  TagIntegerArray & operator = (Tag const & b) {Tag::operator =(b); return *this;}
713  __INLINE Storage::integer_array operator [](const Storage & arg) const {return arg.IntegerArray(*static_cast<const Tag*>(this));}
714  __INLINE Storage::integer_array operator [](HandleType h) const;
715  };
716 
717  class TagBulkArray : public Tag
718  {
719  public:
720  TagBulkArray() : Tag() {}
721  TagBulkArray(const TagBulkArray & b) : Tag(b) {}
722  TagBulkArray(const Tag & b) : Tag(b) {}
723  TagBulkArray & operator = (TagBulkArray const & b) {Tag::operator =(b); return *this;}
724  TagBulkArray & operator = (Tag const & b) {Tag::operator =(b); return *this;}
725  __INLINE Storage::bulk_array operator [](const Storage & arg) const {return arg.BulkArray(*static_cast<const Tag*>(this));}
726  __INLINE Storage::bulk_array operator [](HandleType h) const;
727  };
728 
729  class TagReferenceArray : public Tag
730  {
731  public:
732  TagReferenceArray() : Tag() {}
733  TagReferenceArray(const TagReferenceArray & b) : Tag(b) {}
734  TagReferenceArray(const Tag & b) : Tag(b) {}
735  TagReferenceArray & operator = (TagReferenceArray const & b) {Tag::operator =(b); return *this;}
736  TagReferenceArray & operator = (Tag const & b) {Tag::operator =(b); return *this;}
737  __INLINE Storage::reference_array operator [](const Storage & arg) const {return arg.ReferenceArray(*static_cast<const Tag*>(this));}
738  __INLINE Storage::reference_array operator [](HandleType h) const;
739  };
740 
741 #if defined(USE_AUTODIFF)
742  class TagVariable : public Tag
743  {
744  public:
745  TagVariable() : Tag() {}
746  TagVariable(const TagVariable & b) : Tag(b) {}
747  TagVariable(const Tag & b) : Tag(b) {}
748  TagVariable & operator = (TagVariable const & b) {Tag::operator =(b); return *this;}
749  TagVariable & operator = (Tag const & b) {Tag::operator =(b); return *this;}
750  __INLINE Storage::var & operator [](const Storage & arg) const {return arg.Variable(*static_cast<const Tag*>(this));}
751  __INLINE Storage::var & operator [](HandleType h) const;
752  };
753 
754  class TagVariableArray : public Tag
755  {
756  public:
757  TagVariableArray() : Tag() {}
758  TagVariableArray(const TagVariableArray & b) : Tag(b) {}
759  TagVariableArray(const Tag & b) : Tag(b) {}
760  TagVariableArray & operator = (TagVariableArray const & b) {Tag::operator =(b); return *this;}
761  TagVariableArray & operator = (Tag const & b) {Tag::operator =(b); return *this;}
762  __INLINE Storage::var_array operator [](const Storage & arg) const {return arg.VariableArray(*static_cast<const Tag*>(this));}
763  __INLINE Storage::var_array operator [](HandleType h) const;
764  __INLINE Matrix<Storage::var,Storage::var_array> operator()(const Storage & arg, int n, int m) const
765  {
766  Storage::var_array data = arg.VariableArray(*static_cast<const Tag*>(this));
767  assert((int)data.size() == n*m);
769  }
770  __INLINE Matrix<Storage::var,Storage::var_array> operator()(HandleType h, int n, int m) const;
771  };
772 #endif //USE_AUTODIFF
773 
777 
778  __INLINE INMOST_DATA_ENUM_TYPE Tag::GetRecordSize() const
779  {
780  return mem->record_size;
781  }
782 
783  __INLINE void Tag::SetSize(INMOST_DATA_ENUM_TYPE size)
784  {
785  mem->size = size;
786  }
787 
788  __INLINE void Tag::SetPosition(INMOST_DATA_ENUM_TYPE pos,
789  ElementType type)
790  {
791  assert(type != NONE);
792  mem->pos[ElementNum(type)] = pos;
793  }
794 
795  __INLINE INMOST_DATA_ENUM_TYPE Tag::GetPosition(ElementType type) const
796  {
797  assert(mem != NULL);
798  assert(type != NONE);
799  return mem->pos[ElementNum(type)];
800  }
801 
802  __INLINE void Tag::SetSparse(ElementType type)
803  {
804  assert(type != NONE);
805  mem->sparse[ElementNum(type)] = true;
806  }
807 
808  __INLINE void Tag::SetPrint(bool print)
809  {
810  mem->print_tag = print;
811  }
812 
813  __INLINE bool Tag::GetPrint() const
814  {
815  return mem->print_tag;
816  }
817 
818  __INLINE INMOST_DATA_ENUM_TYPE Tag::GetPositionByDim(INMOST_DATA_ENUM_TYPE typenum) const
819  {
820  return mem->pos[typenum];
821  }
822 
823  __INLINE bool Tag::operator <(const Tag & other) const
824  {
825  if( other.mem )
826  return mem->tagname < other.mem->tagname;
827  else
828  return false;
829  }
830 
831  __INLINE bool Tag::operator >(const Tag & other) const
832  {
833  if( other.mem )
834  return mem->tagname > other.mem->tagname;
835  else
836  return true;
837  }
838 
839  __INLINE bool Tag::operator ==(const Tag & other) const
840  {
841  if( other.mem )
842  return mem->tagname == other.mem->tagname;
843  else
844  return false;
845  }
846 
847  __INLINE bool Tag::operator !=(const Tag & other) const
848  {
849  if( other.mem )
850  return mem->tagname != other.mem->tagname;
851  else
852  return true;
853  }
854 
855  __INLINE Tag & Tag::operator =(Tag const & other)
856  {
857  mem = other.mem;
858  return *this;
859  }
860 
861  __INLINE DataType Tag::GetDataType() const
862  {
863  assert(mem!=NULL);
864  return mem->dtype;
865  }
866 
867  __INLINE INMOST_MPI_Type Tag::GetBulkDataType() const
868  {
869  assert(mem!=NULL);
870  return mem->bulk_data_type;
871  }
872 
873  __INLINE INMOST_DATA_ENUM_TYPE Tag::GetBytesSize() const
874  {
875  assert(mem!=NULL);
876  return mem->bytes_size;
877  }
878  __INLINE INMOST_DATA_ENUM_TYPE Tag::GetSize() const
879  {
880  assert(mem!=NULL);
881  return mem->size;
882  }
883  __INLINE std::string Tag::GetTagName() const
884  {
885  assert(mem!=NULL);
886  return mem->tagname;
887  }
888  __INLINE bool Tag::isDefined(ElementType type) const
889  {
890  assert(mem!=NULL);
891  assert(OneType(type));
892  return GetPosition(type) != ENUMUNDEF;
893  }
894  __INLINE bool Tag::isDefinedMask(ElementType mask) const
895  {
896  assert(mem!=NULL);
897  bool ret = true;
898  for(ElementType etype = NODE; etype <= MESH; etype = NextElementType(etype))
899  if( etype & mask ) ret &= isDefined(etype&mask);
900  return ret;
901  }
902  __INLINE bool Tag::isSparse(ElementType type) const
903  {
904  assert(mem!=NULL);
905  assert(OneType(type));
906  return mem->sparse[ElementNum(type)];
907  }
908  __INLINE bool Tag::isValid() const
909  {
910  return mem != NULL;
911  }
912  __INLINE Mesh * Tag::GetMeshLink() const
913  {
914  assert(mem!=NULL);
915  return mem->m_link;
916  }
917  __INLINE bool Tag::isSparseByDim(INMOST_DATA_INTEGER_TYPE typenum) const
918  {
919  assert(mem!=NULL);
920  return mem->sparse[typenum];
921  }
922  __INLINE bool Tag::isDefinedByDim(INMOST_DATA_INTEGER_TYPE typenum) const
923  {
924  assert(mem!=NULL);
925  return GetPositionByDim(typenum) != ENUMUNDEF;
926  }
927  __INLINE void Tag::SetBulkDataType(INMOST_MPI_Type type)
928  {
929  assert(mem!=NULL);
930  assert(mem->dtype == DATA_BULK );
931  mem->bulk_data_type = type;
932  }
933 
934 }
935 
936 //Implementation of inlined functions
937 //#include "../Data/tag_inline.hpp"
938 
939 
940 #endif
941 
942 
943 
944 #endif //INMOST_DATA_H_INCLUDED
Class for linear algebra operations on dense matrices.
Storage type for representing arrays of Element references.
Definition: inmost_data.h:338
Storage type for representing arrays of Element references on another Mesh.
Definition: inmost_data.h:422
Base class for Mesh, Element, and ElementSet classes.
Definition: inmost_data.h:310
__INLINE integer & Integer(const Tag &tag) const
Retrieve integer value associated with Tag.
Definition: inmost_mesh.h:3733
Storage & operator=(Storage const &other)
If there is a link to handle provided (automatically by ElementArray and reference_array),...
RemoteHandleType remote_reference
Storage type for representing references to Element in another Mesh.
Definition: inmost_data.h:323
variable var
Storage type for representing real value with vector of variations.
Definition: inmost_data.h:332
__INLINE void DelDenseData(const Tag &tag) const
Frees variable array or fills field with zeroes.
Definition: inmost_mesh.h:3965
__INLINE var_array VariableArray(const Tag &tag) const
Retrieve array of variables associated with Tag.
Definition: inmost_mesh.h:3900
shell< real > real_array
Storage type for representing arrays of real values.
Definition: inmost_data.h:325
__INLINE INMOST_DATA_ENUM_TYPE GetDataCapacity(const Tag &tag) const
Return the size of the structure required to represent the data on current element.
Definition: inmost_mesh.h:3937
shell< integer > integer_array
Storage type for representing arrays of integer values.
Definition: inmost_data.h:327
__INLINE var & Variable(const Tag &tag) const
Retrieve variable reference associated with Tag.
Definition: inmost_mesh.h:3888
__INLINE bulk_array BulkArray(const Tag &tag) const
Retrieve abstract data associated with Tag as a series of bytes.
Definition: inmost_mesh.h:3757
shell< bulk > bulk_array
Storage type for representing abstract data as a series of bytes.
Definition: inmost_data.h:329
shell< variable > var_array
Storage type for representing array of values with vectors of variations.
Definition: inmost_data.h:334
__INLINE remote_reference_array RemoteReferenceArray(const Tag &tag) const
Retrieve array of Element references associated with Tag.
Definition: inmost_mesh.h:3765
__INLINE reference & Reference(const Tag &tag) const
Retrieve Element reference associated with Tag.
Definition: inmost_mesh.h:3741
INMOST_DATA_REAL_TYPE real
Storage type for representing real values.
Definition: inmost_data.h:313
HandleType reference
Storage type for representing references to Element.
Definition: inmost_data.h:321
__INLINE integer_array IntegerArray(const Tag &tag) const
Retrieve array of integer values associated with Tag.
Definition: inmost_mesh.h:3753
Storage(Mesh *mesh, HandleType *handle)
This constructor allows for remote handle modification.
Definition: inmost_data.h:479
__INLINE remote_reference & RemoteReference(const Tag &tag) const
Retrieve remote Element reference associated with Tag.
Definition: inmost_mesh.h:3745
__INLINE void GetData(const Tag &tag, INMOST_DATA_ENUM_TYPE shift, INMOST_DATA_ENUM_TYPE size, void *data) const
Extract part of the data associated with Tag.
Definition: inmost_mesh.h:3953
__INLINE void SetDataSize(const Tag &tag, INMOST_DATA_ENUM_TYPE new_size) const
Set the length of data associated with Tag.
Definition: inmost_mesh.h:3941
__INLINE real & Real(const Tag &tag) const
Retrieve real value associated with Tag.
Definition: inmost_mesh.h:3729
__INLINE reference_array ReferenceArray(const Tag &tag) const
Retrieve array of Element references associated with Tag.
Definition: inmost_mesh.h:3761
__INLINE bulk & Bulk(const Tag &tag) const
Retrieve one byte of abstract data associated with Tag.
Definition: inmost_mesh.h:3737
__INLINE real_array RealArray(const Tag &tag) const
Retrieve array of real values associated with Tag.
Definition: inmost_mesh.h:3749
__INLINE INMOST_DATA_ENUM_TYPE GetDataSize(const Tag &tag) const
Return the data length associated with Tag.
Definition: inmost_mesh.h:3933
INMOST_DATA_ENUM_TYPE enumerator
type for representing unsigned integer values.
Definition: inmost_data.h:319
INMOST_DATA_BULK_TYPE bulk
Storage type for representing one byte of abstract data.
Definition: inmost_data.h:317
__INLINE integer DataLocalID() const
This number is guaranteed to be between 0 and Mesh::NumberOf(type of element) after Mesh::ReorderEmpt...
Definition: inmost_mesh.h:4023
__INLINE bool DelSparseData(const Tag &tag) const
Deallocates space allocated for sparse data, frees variable array if necessary.
Definition: inmost_mesh.h:3969
__INLINE bool HaveData(const Tag &tag) const
Check if any data is associated with Tag.
Definition: inmost_mesh.h:3928
INMOST_DATA_INTEGER_TYPE integer
Storage type for representing integer values.
Definition: inmost_data.h:315
bool RenameTag(std::string oldname, std::string newname)
Change tag name.
static void CopyData(const Tag &t, void *adata, const void *bdata)
Copy data from one element to another.
void ReallocateData(INMOST_DATA_INTEGER_TYPE etypenum, INMOST_DATA_ENUM_TYPE new_size)
Reallocate all the data for all the tags.
__INLINE sparse_sub_type const & GetSparseData(int etypenum, int local_id) const
Retrieve substructure for representation of the sparse data without permission for modification.
Definition: inmost_data.h:282
Tag GetTag(std::string name) const
Retrieve a data tag by it's name.
bool ElementDefined(Tag const &tag, ElementType etype) const
Check that the tag was defined on certain elements.
void ReallocateData(const Tag &t, INMOST_DATA_INTEGER_TYPE etypenum, INMOST_DATA_ENUM_TYPE new_size)
Shrink or enlarge arrays for a dense data.
void ListTagNames(std::vector< std::string > &list) const
Retrieve names for all the tags present on the mesh.
static void DestroyVariableData(const Tag &t, void *adata)
Destroy data that represents array of variable size.
__INLINE sparse_sub_type & GetSparseData(int etypenum, int local_id)
Retrieve substructure for representation of the sparse data.
Definition: inmost_data.h:284
Tag CreateTag(Mesh *m, std::string name, DataType dtype, ElementType etype, ElementType sparse, INMOST_DATA_ENUM_TYPE size=ENUMUNDEF)
Create tag with prescribed attributes.
__INLINE dense_sub_type const & GetDenseData(int pos) const
Retrieve substructure for representation of the dense data without permission for modification.
Definition: inmost_data.h:286
__INLINE dense_sub_type & GetDenseData(int pos)
Retrieve substructure for representation of the dense data.
Definition: inmost_data.h:288
virtual Tag DeleteTag(Tag tag, ElementType mask)
Delete tag from certain elements.
bool HaveTag(std::string name) const
Check existence of a data tag by it's name.
This class is a data container for class Tag, contains all the necessary information to access mesh d...
Definition: inmost_data.h:144
~TagMemory()
Destructor should not do anything.
Definition: inmost_data.h:147
TagMemory & operator=(TagMemory const &other)
Assignment operator should not be ever used, but is here for convinience.
TagMemory(Mesh *m, const TagMemory &other)
Copy constructor, copies all the data except for m_link.
Helper classes for class Tag //.
Definition: inmost_data.h:638
This class provides the access to the individual mesh datum and general information about it.
Definition: inmost_data.h:193
INMOST_DATA_ENUM_TYPE GetPackedBytesSize() const
Amount of bytes necessary for one record in packed form that is used in GetData.
__INLINE INMOST_DATA_ENUM_TYPE GetBytesSize() const
Amount of bytes necessary to support one record referred by the tag on one element.
Definition: inmost_data.h:873
A class that represents a variable with multiple first order variations.