INMOST
A toolkit for distributed mathematical modeling
inmost_mesh.h
1 
2 #ifndef INMOST_MESH_H_INCLUDED
3 #define INMOST_MESH_H_INCLUDED
4 
5 #include "inmost_common.h"
6 #include "inmost_data.h"
7 
8 #if defined(USE_MESH)
9 
10 
11 
12 namespace INMOST
13 {
14  class Mesh;
15  class Storage;
16  class Element;
17  class TagManager;
18  class Node;
19  class Edge;
20  class Face;
21  class Cell;
22  class ElementSet;
23 
24 
25 
26  typedef INMOST_DATA_BULK_TYPE GeometricData;
27  static const GeometricData CENTROID = 0;
28  static const GeometricData NORMAL = 1;
29  static const GeometricData ORIENTATION = 2;
30  static const GeometricData MEASURE = 3;
31  static const GeometricData BARYCENTER = 4;
32 
33  typedef INMOST_DATA_BULK_TYPE SyncBitOp; //< This type is used for marker synchronization
34  static const SyncBitOp SYNC_BIT_SET = 0;
35  static const SyncBitOp SYNC_BIT_OR = 1;
36  static const SyncBitOp SYNC_BIT_XOR = 2;
37  static const SyncBitOp SYNC_BIT_AND = 3;
38 
39 
40 
43  typedef INMOST_DATA_ENUM_TYPE TopologyCheck;
45  static const TopologyCheck THROW_EXCEPTION = 0x00000001;
47  static const TopologyCheck PRINT_NOTIFY = 0x00000002;
49  static const TopologyCheck DELETE_ON_ERROR = 0x00000004;
52  static const TopologyCheck MARK_ON_ERROR = 0x00000008;
54  static const TopologyCheck DUPLICATE_EDGE = 0x00000010;
56  static const TopologyCheck DUPLICATE_FACE = 0x00000020;
58  static const TopologyCheck DUPLICATE_CELL = 0x00000040;
60  static const TopologyCheck DEGENERATE_EDGE = 0x00000080;
62  static const TopologyCheck DEGENERATE_FACE = 0x00000100;
64  static const TopologyCheck DEGENERATE_CELL = 0x00000200;
66  static const TopologyCheck FACE_ORIENTATION = 0x00000400;
68  static const TopologyCheck FACE_PLANARITY = 0x00000800;
70  static const TopologyCheck INTERLEAVED_FACES = 0x00001000;
73  static const TopologyCheck TRIPLE_SHARED_FACE = 0x00002000;
75  static const TopologyCheck FLATTENED_CELL = 0x00004000;
77  static const TopologyCheck ADJACENT_DUPLICATE = 0x00008000;
79  static const TopologyCheck ADJACENT_HIDDEN = 0x00010000;
81  static const TopologyCheck ADJACENT_VALID = 0x00020000;
83  static const TopologyCheck ADJACENT_DIMENSION = 0x00040000;
86  static const TopologyCheck PROHIBIT_MULTILINE = 0x00080000;
88  static const TopologyCheck PROHIBIT_POLYGON = 0x00100000;
91  static const TopologyCheck PROHIBIT_MULTIPOLYGON = 0x00200000;
93  static const TopologyCheck PROHIBIT_POLYHEDRON = 0x00400000;
95  static const TopologyCheck FACE_EDGES_ORDER = 0x00800000;
98  static const TopologyCheck PROHIBIT_CONCAVE_FACE = 0x01000000;
101  static const TopologyCheck PROHIBIT_CONCAVE_CELL = 0x02000000;
104  static const TopologyCheck PROHIBIT_NONSTAR_FACE = 0x04000000;
107  static const TopologyCheck PROHIBIT_NONSTAR_CELL = 0x08000000;
110  static const TopologyCheck FACE_SELF_INTERSECTION = 0x10000000;
113  static const TopologyCheck CELL_SELF_INTERSECTION = 0x20000000;
116  static const TopologyCheck NEED_TEST_CLOSURE = 0x40000000;
118  static const TopologyCheck DISABLE_2D = 0x80000000;
120  static const TopologyCheck GRID_CONFORMITY = NEED_TEST_CLOSURE
121  | PROHIBIT_MULTILINE
122  | PROHIBIT_MULTIPOLYGON
123  // | INTERLEAVED_FACES
124  | TRIPLE_SHARED_FACE;
126  static const TopologyCheck DEFAULT_CHECK = THROW_EXCEPTION
127  | DUPLICATE_EDGE
128  | DUPLICATE_FACE
129  | DUPLICATE_CELL
130  | PRINT_NOTIFY;
133  const char * TopologyCheckNotifyString(TopologyCheck c);
134 
135 
136 
137  template <typename StorageType>
139  {
140  public:
141  typedef std::vector<HandleType> cont_t;
142  typedef cont_t::size_type size_type;
143  private:
144  Mesh * m_link;
145  cont_t container;
146  public:
147  const cont_t & GetContainer() {return container;}
148  ~ElementArray() {}
149  ElementArray() : m_link(NULL) {}
150  ElementArray(Mesh * m_link) : m_link(m_link) {}
151  ElementArray(Mesh * m_link, size_type n, HandleType h = InvalidHandle()) : m_link(m_link), container(n,h) {}
152  ElementArray(Mesh * m_link, const cont_t & c) : m_link(m_link), container(c) {}
153  ElementArray(const ElementArray & other) : m_link(other.m_link), container(other.container) {}
154  template<class InputIterator>
155  ElementArray(Mesh * m_link, InputIterator first, InputIterator last) :m_link(m_link), container(first,last) {}
156  ElementArray & operator=(ElementArray const & other) {m_link = other.m_link; container = other.container; return *this;}
157  public:
158  class iterator : public cont_t::iterator
159  {
160  Mesh * m_link;
161  public:
162  iterator(Mesh * m, const cont_t::iterator & other ) : cont_t::iterator(other) , m_link(m){assert(m_link);}
163  iterator(const iterator & other ) : cont_t::iterator(other), m_link(other.m_link) {assert(m_link);}
164  ptrdiff_t operator -(const iterator & other) const {return static_cast<const cont_t::iterator>(*this)-static_cast<const cont_t::iterator>(other);}
165  iterator operator +(size_t n) const{return iterator(m_link,cont_t::iterator::operator +(n));}
166  iterator operator -(size_t n) const{return iterator(m_link,cont_t::iterator::operator -(n));}
167  iterator & operator ++() {cont_t::iterator::operator++(); return *this;}
168  iterator operator ++(int) {iterator ret(*this); cont_t::iterator::operator++(); return ret;}
169  iterator & operator --() {cont_t::iterator::operator--(); return *this;}
170  iterator operator --(int) {iterator ret(*this); cont_t::iterator::operator--(); return ret;}
171  iterator & operator =(iterator const & other) {m_link = other.m_link; cont_t::iterator::operator=(static_cast<cont_t::iterator const &>(other)); return *this; }
172  HandleType & operator *() const { return cont_t::iterator::operator *(); }
173  StorageType operator->() const { return StorageType(m_link,&cont_t::iterator::operator *()); }
174  };
175  class reverse_iterator : public cont_t::reverse_iterator
176  {
177  Mesh * m_link;
178  public:
179  reverse_iterator(Mesh * m, const cont_t::reverse_iterator & other ) : cont_t::reverse_iterator(other), m_link(m) {assert(m_link);}
180  reverse_iterator(const reverse_iterator & other ) : cont_t::reverse_iterator(other), m_link(other.m_link) {assert(m_link);}
181  ptrdiff_t operator -(const reverse_iterator & other) const {return static_cast<const cont_t::reverse_iterator>(*this)-static_cast<const cont_t::reverse_iterator>(other);}
182  reverse_iterator operator +(size_t n) const {return reverse_iterator(m_link,cont_t::reverse_iterator::operator+(n));}
183  reverse_iterator operator -(size_t n) const {return reverse_iterator(m_link,cont_t::reverse_iterator::operator-(n));}
184  reverse_iterator & operator ++() {cont_t::reverse_iterator::operator++(); return *this;}
185  reverse_iterator operator ++(int) {reverse_iterator ret(*this); cont_t::reverse_iterator::operator++(); return ret;}
186  reverse_iterator & operator --() {cont_t::reverse_iterator::operator--(); return *this;}
187  reverse_iterator operator --(int) {reverse_iterator ret(*this); cont_t::reverse_iterator::operator--(); return ret;}
188  reverse_iterator & operator =(reverse_iterator const & other) {m_link = other.m_link; cont_t::reverse_iterator::operator=(static_cast<cont_t::reverse_iterator const &>(other)); return *this; }
189  HandleType & operator *() const { return cont_t::reverse_iterator::operator *(); }
190  StorageType operator->() const { return StorageType(m_link,&cont_t::reverse_iterator::operator *()); }
191  };
192  class const_iterator : public cont_t::const_iterator
193  {
194  Mesh * m_link;
195  public:
196  const_iterator(Mesh * m, const cont_t::const_iterator & other ) : cont_t::const_iterator(other), m_link(m) {assert(m_link);}
197  const_iterator(const const_iterator & other ) : cont_t::const_iterator(other), m_link(other.m_link) {assert(m_link);}
198  ptrdiff_t operator -(const const_iterator & other) const {return static_cast<const cont_t::const_iterator>(*this)-static_cast<const cont_t::const_iterator>(other);}
199  const_iterator & operator ++() {cont_t::const_iterator::operator++(); return *this;}
200  const_iterator operator ++(int) {const_iterator ret(*this); cont_t::const_iterator::operator++(); return ret;}
201  const_iterator & operator --() {cont_t::const_iterator::operator--(); return *this;}
202  const_iterator operator --(int) {const_iterator ret(*this); cont_t::const_iterator::operator--(); return ret;}
203  const_iterator & operator =(const_iterator const & other) {m_link = other.m_link; cont_t::const_iterator::operator=(static_cast<cont_t::const_iterator const &>(other)); return *this; }
204  const HandleType & operator *() const { return cont_t::const_iterator::operator *(); }
205  StorageType operator->() const { return StorageType(m_link,cont_t::const_iterator::operator *()); }
206  };
207  class const_reverse_iterator : public cont_t::const_reverse_iterator
208  {
209  Mesh * m_link;
210  public:
211  const_reverse_iterator(Mesh * m, const cont_t::const_reverse_iterator & other) : cont_t::const_reverse_iterator(other), m_link(m) {assert(m_link);}
212  const_reverse_iterator(const const_reverse_iterator & other ) : cont_t::const_reverse_iterator(other), m_link(other.m_link) {assert(m_link);}
213  ptrdiff_t operator -(const const_reverse_iterator & other) const {return static_cast<const cont_t::const_reverse_iterator>(*this)-static_cast<const cont_t::const_reverse_iterator>(other);}
214  const_reverse_iterator & operator ++() {cont_t::const_reverse_iterator::operator++(); return *this;}
215  const_reverse_iterator operator ++(int) {const_reverse_iterator ret(*this); cont_t::const_reverse_iterator::operator++(); return ret;}
216  const_reverse_iterator & operator --() {cont_t::const_reverse_iterator::operator--(); return *this;}
217  const_reverse_iterator operator --(int) {const_reverse_iterator ret(*this); cont_t::const_reverse_iterator::operator--(); return ret;}
218  const_reverse_iterator & operator =(const_reverse_iterator const & other) { cont_t::const_reverse_iterator::operator=(static_cast<cont_t::const_reverse_iterator const &>(other)); return *this; }
219  const HandleType & operator *() const { return cont_t::const_reverse_iterator::operator *(); }
220  StorageType operator->() const { return StorageType(m_link,cont_t::const_reverse_iterator::operator *()); }
221  };
222  public:
223  template<class InputIterator>
224  __INLINE void insert (iterator pos,InputIterator pbeg, InputIterator pend) {container.insert(static_cast<cont_t::iterator>(pos),pbeg,pend);}
225  __INLINE iterator erase (iterator pos) {return iterator(m_link,container.erase(static_cast<cont_t::iterator>(pos)));}
226 
227  __INLINE iterator begin () { return iterator(m_link,container.begin()); }
228  __INLINE iterator end () { return iterator(m_link,container.end()); }
229  __INLINE reverse_iterator rbegin () { return reverse_iterator(m_link,container.rbegin()); }
230  __INLINE reverse_iterator rend () { return reverse_iterator(m_link,container.rend()); }
231  __INLINE const_iterator begin () const { return const_iterator(m_link,container.begin()); }
232  __INLINE const_iterator end () const { return const_iterator(m_link,container.end()); }
233  __INLINE const_reverse_iterator rbegin() const { return const_reverse_iterator(m_link,container.rbegin()); }
234  __INLINE const_reverse_iterator rend () const { return const_reverse_iterator(m_link,container.rend()); }
235 
236  __INLINE StorageType operator [] (size_type n) {assert(m_link); return StorageType(m_link,&container[n]);}
237  __INLINE StorageType operator [] (size_type n) const {assert(m_link); return StorageType(m_link,container[n]);}
238  __INLINE StorageType front () {assert(m_link); return StorageType(m_link,&container.front()); }
239  __INLINE StorageType front () const {assert(m_link); return StorageType(m_link,container.front()); }
240  __INLINE StorageType back () {assert(m_link); return StorageType(m_link,&container.back()); }
241  __INLINE StorageType back () const {assert(m_link); return StorageType(m_link,container.back()); }
242  __INLINE HandleType atfront () const { return container.front(); }
243  __INLINE HandleType atback () const { return container.back(); }
244  __INLINE HandleType & atfront () { return container.front(); }
245  __INLINE HandleType & atback () { return container.back(); }
246  __INLINE HandleType & at (size_type n) { return container.at(n); }
247  __INLINE HandleType at (size_type n) const { return container.at(n); }
248  __INLINE void swap (ElementArray<StorageType> & other) {Mesh * t = m_link; m_link = other.m_link; other.m_link = t; container.swap(other.container);}
249  __INLINE void push_back (const Storage & x) {if( m_link == NULL ) m_link = x.GetMeshLink(); assert(x.GetMeshLink() == m_link); container.push_back(x.GetHandle());}
250  //__INLINE void push_back (const StorageType & x) {container.push_back(x.GetHandle());}
251  __INLINE void push_back (HandleType x) {assert(m_link != NULL); container.push_back(x);}
252  __INLINE void pop_back () {container.pop_back();}
253  __INLINE void resize (size_type n) {container.resize(n);}
254  __INLINE bool empty () const {return container.empty();}
255  __INLINE void clear () {container.clear();}
256  __INLINE void reserve (size_type n) {container.reserve(n);}
257  __INLINE size_type size () const {return container.size(); }
258  __INLINE HandleType * data () {return container.empty() ? NULL : &container[0];}
259  __INLINE const HandleType*data () const {return container.empty() ? NULL : &container[0];}
260  __INLINE Mesh * GetMeshLink () const {assert(m_link); return m_link;}
261  __INLINE void SetMeshLink (Mesh * m) {m_link = m;}
262  //implemented in mesh_array.cpp
263  void Unite (const HandleType * h, INMOST_DATA_ENUM_TYPE num);
264  void Subtract (const HandleType * h, INMOST_DATA_ENUM_TYPE num);
265  void Intersect (const HandleType * h, INMOST_DATA_ENUM_TYPE num);
266  template<typename EType>
267  void Unite (const ElementArray<EType> & other) {Unite(other.data(),static_cast<INMOST_DATA_ENUM_TYPE>(other.size()));}
268  template<typename EType>
269  void Subtract (const ElementArray<EType> & other) {Subtract(other.data(),static_cast<INMOST_DATA_ENUM_TYPE>(other.size()));}
270  template<typename EType>
271  void Intersect (const ElementArray<EType> & other) {Intersect(other.data(),static_cast<INMOST_DATA_ENUM_TYPE>(other.size()));}
272  void SetMarker (MarkerType n) const;
273  void RemMarker (MarkerType n) const;
274  void SetPrivateMarker (MarkerType n) const;
275  void RemPrivateMarker (MarkerType n) const;
276  template<typename Etype>
277  ElementArray<Etype> Convert() {return ElementArray<Etype>(m_link,container);}
278  };
279 
280  // Abstract function for calculation of mean value on element
281  struct MeanFunc { virtual Storage::real func(Storage::real* x, Storage::real t) const = 0; };
282  struct MeanFuncRaw : public MeanFunc
283  {
285  MeanFuncRaw(Storage::real(*pfunc)(Storage::real* x, Storage::real t)) : pfunc(pfunc) {}
286  Storage::real func(Storage::real* x, Storage::real t) const { return pfunc(x, t); }
287  };
288 
289  class Element : public Storage //implemented in element.cpp
290  {
291  public:
292  typedef INMOST_DATA_BULK_TYPE GeometricType;
293  static const GeometricType Unset = 0;
294  static const GeometricType Vertex = 1;
295  static const GeometricType Line = 2;
296  static const GeometricType MultiLine = 3;
297  static const GeometricType Tri = 4;
298  static const GeometricType Quad = 5;
299  static const GeometricType Polygon = 6;
300  static const GeometricType MultiPolygon = 7;
301  static const GeometricType Tet = 8;
302  static const GeometricType Hex = 9;
303  static const GeometricType Prism = 10;
304  static const GeometricType Pyramid = 11;
305  static const GeometricType Polyhedron = 12;
306  static const GeometricType Set = 253;
307  static const GeometricType MeshPart = 254;
308  static const GeometricType MaxType = 255;
309  //enum GeometricType {Unset,Vertex,Line,MultiLine,Tri,Quad,Polygon,MultiPolygon,Tet,Hex,Prism,Pyramid,Polyhedron,Set};
310  static const char * GeometricTypeName(GeometricType t);
311  static integer GetGeometricDimension(GeometricType m_type);
312  typedef INMOST_DATA_BULK_TYPE Status;
313  static const Status Owned = 1;
314  static const Status Shared = 2;
315  static const Status Ghost = 4;
316  static const Status Any = 0;
317  static const char * StatusName(Status s);
318  public:
324  public:
325  //adj_type & HighConn () const;
326  //adj_type & LowConn () const;
327  protected:
328  void SetGeometricType (GeometricType t);
329  public:
330  Element() : Storage(NULL,InvalidHandle()) {}
331  Element(Mesh * m, HandleType h) : Storage(m,h) {}
332  Element(Mesh * m, HandleType * h) : Storage(m,h) {}
333  Element(const Element & other) : Storage(other) {}
334  Element & operator =(Element const & other) {Storage::operator =(other); return *this;}
335  Element * operator ->() {return this;}
336  const Element * operator ->() const {return this;}
337  Element & self() {return *this;}
338  const Element & self() const {return *this;}
339  virtual ~Element() {}
340  public:
346  virtual enumerator nbAdjElements (ElementType etype) const;
353  virtual ElementArray<Element> getAdjElements (ElementType etype) const; //unordered
361  virtual enumerator nbAdjElements (ElementType etype, MarkerType mask, bool invert_mask = false) const;
367  virtual ElementArray<Element> getAdjElements (ElementType etype, MarkerType mask, bool invert_mask = false) const; //unordered
368  ElementArray<Element> BridgeAdjacencies (ElementType Bridge, ElementType Dest, MarkerType bridge_mask = 0, bool bridge_invert = false, MarkerType target_mask = 0, bool target_invert = false) const;
369  ElementArray<Node> BridgeAdjacencies2Node (ElementType Bridge, MarkerType bridge_mask = 0, bool bridge_invert = false, MarkerType target_mask = 0, bool target_invert = false) const;
370  ElementArray<Edge> BridgeAdjacencies2Edge (ElementType Bridge, MarkerType bridge_mask = 0, bool bridge_invert = false, MarkerType target_mask = 0, bool target_invert = false) const;
371  ElementArray<Face> BridgeAdjacencies2Face (ElementType Bridge, MarkerType bridge_mask = 0, bool bridge_invert = false, MarkerType target_mask = 0, bool target_invert = false) const;
372  ElementArray<Cell> BridgeAdjacencies2Cell (ElementType Bridge, MarkerType bridge_mask = 0, bool bridge_invert = false, MarkerType target_mask = 0, bool target_invert = false) const;
391  virtual ElementArray<Node> getNodes () const; //unordered
403  virtual ElementArray<Edge> getEdges () const; //unordered
415  virtual ElementArray<Face> getFaces () const; //unordered
429  virtual ElementArray<Cell> getCells () const; //unordered
430  virtual ElementArray<Node> getNodes (MarkerType mask,bool invert_mask = false) const; //unordered
431  virtual ElementArray<Edge> getEdges (MarkerType mask,bool invert_mask = false) const; //unordered
432  virtual ElementArray<Face> getFaces (MarkerType mask,bool invert_mask = false) const; //unordered
433  virtual ElementArray<Cell> getCells (MarkerType mask,bool invert_mask = false) const; //unordered
434  GeometricType GetGeometricType () const;
435  unsigned int GetElementDimension () const {return GetGeometricDimension(GetGeometricType());}
436  Status GetStatus () const;
437  void SetStatus (Status status) const;
438  Storage::integer & GlobalID () const;
439  bool CheckElementConnectivity() const;
440  void PrintElementConnectivity() const;
441  static bool CheckConnectivity (Mesh * m);
442  //implemented in geometry.cpp
443  void CastRay (const real * pos, const real * dir, std::map<HandleType, real> & hits) const;
444 
445  void ComputeGeometricType () const;
446  void Centroid (real * cnt) const;
447  void Barycenter (real * cnt) const;
448  Storage::real Mean (const MeanFunc & f, real time) const;
449  Storage::real Mean (real(*func)(real* x, real t), real time) const { return Mean(MeanFuncRaw(func), time); }
458  bool Boundary () const;
459  bool Planarity () const; // check that all nodes lay on one plane
460  //implemented in modify.cpp
466  bool Hide () const;
472  bool Show () const; // if true then element was recovered
480  bool Delete (); // if true then element was deleted, otherwise it was hidden
481  bool Hidden () const;
482  bool New () const;
483  void Disconnect (bool delete_upper_adjacent) const; //disconnect all elements, delete upper dependent
488  void Disconnect (const HandleType * adjacent, INMOST_DATA_ENUM_TYPE num) const;
496  void Connect (const HandleType * adjacent, INMOST_DATA_ENUM_TYPE num) const;
498  //void UpdateGeometricData () const;
501  void SendTo (std::set<Storage::integer> & procs) const;
502  void SendTo (std::vector<Storage::integer> & procs) const;
503  void SendTo (Storage::integer_array procs) const;
504  };
505 
506  __INLINE const Element & InvalidElement() {static Element ret(NULL,InvalidHandle()); return ret;}
507 
508  class Node : public Element //implemented in node.cpp
509  {
510  public:
511  Node() : Element() {}
512  Node(const Node & other) : Element(other) {}
513  Node(Mesh * m, HandleType h) : Element(m,h) {}
514  Node(Mesh * m, HandleType * h) : Element(m,h) {}
515  Node & operator =(Node const & other) {Element::operator =(other); return *this;}
516  Node * operator ->() {return this;}
517  const Node * operator ->() const {return this;}
518  Node & self() {return *this;}
519  const Node & self() const {return *this;}
520  public:
521  ElementArray<Edge> getEdges () const; //unordered
522  ElementArray<Face> getFaces () const; //unordered
523  ElementArray<Cell> getCells () const; //unordered
524 
525  ElementArray<Edge> getEdges (MarkerType mask,bool invert_mask = false) const; //unordered
526  ElementArray<Face> getFaces (MarkerType mask,bool invert_mask = false) const; //unordered
527  ElementArray<Cell> getCells (MarkerType mask,bool invert_mask = false) const; //unordered
528 
529  Storage::real_array Coords () const;
530  };
531 
532  __INLINE const Node & InvalidNode() {static Node ret(NULL,InvalidHandle()); return ret;}
533 
534  class Edge : public Element //implemented in edge.cpp
535  {
536  public:
537  Edge() : Element() {}
538  Edge(const Edge & other) : Element(other) {}
539  Edge(Mesh * m, HandleType h) : Element(m,h) {}
540  Edge(Mesh * m, HandleType * h) : Element(m,h) {}
541  Edge & operator =(Edge const & other) {Element::operator =(other); return *this;}
542  Edge * operator ->() {return this;}
543  const Edge * operator ->() const {return this;}
544  Edge & self() {return *this;}
545  const Edge & self() const {return *this;}
546  public:
547 
548  ElementArray<Node> getNodes () const; //ordered
549  ElementArray<Face> getFaces () const; //unordered
550  ElementArray<Cell> getCells () const; //unordered
551 
552  ElementArray<Node> getNodes (MarkerType mask,bool invert_mask = false) const; //ordered
553  ElementArray<Face> getFaces (MarkerType mask,bool invert_mask = false) const; //unordered
554  ElementArray<Cell> getCells (MarkerType mask,bool invert_mask = false) const; //unordered
555 
556  Node getBeg () const;
557  Node getEnd () const;
558  //implemented in modify.cpp
559  static Edge UniteEdges (const ElementArray<Edge> & edges, MarkerType del_protect);
560  static bool TestUniteEdges (const ElementArray<Edge> & edges, MarkerType del_protect);
561  static ElementArray<Edge> SplitEdge (Edge e, const ElementArray<Node> & nodes, MarkerType del_protect); //provide ordered array of nodes, that lay between former nodes of the edge
562  static bool TestSplitEdge (Edge e, const ElementArray<Node> & nodes, MarkerType del_protect);
563  static Node CollapseEdge (Edge e);
564  bool SameLine (const ElementArray<Node>& nodes) const;
565  static bool SameLine (const ElementArray<Edge>& edges);
566  //implemented in geometry.cpp
567  Storage::real Length () const;
569  void SwapEnds ();
570  };
571 
572  __INLINE const Edge & InvalidEdge() {static Edge ret(NULL,InvalidHandle()); return ret;}
573 
574 
595  class Face : public Element //implemented in face.cpp
596  {
597  public:
598  Face() : Element() {}
599  Face(const Face & other) : Element(other) {}
600  Face(Mesh * m, HandleType h) : Element(m,h) {}
601  Face(Mesh * m, HandleType * h) : Element(m,h) {}
602  Face & operator =(Face const & other) {Element::operator =(other); return *this;}
603  Face * operator ->() {return this;}
604  const Face * operator ->() const {return this;}
605  Face & self() {return *this;}
606  const Face & self() const {return *this;}
607  public:
608 
609  ElementArray<Node> getNodes () const; //ordered
610  ElementArray<Edge> getEdges () const; //ordered
611  ElementArray<Cell> getCells () const; //unordered
612 
613  ElementArray<Node> getNodes (MarkerType mask,bool invert_mask = false) const; //ordered
614  ElementArray<Edge> getEdges (MarkerType mask,bool invert_mask = false) const; //ordered
615  ElementArray<Cell> getCells (MarkerType mask,bool invert_mask = false) const; //unordered
616 
617  //this is for 2d case when the face is represented by segment
618  Node getBeg () const;
619  Node getEnd () const;
627  Cell BackCell () const;
635  Cell FrontCell () const;
636  bool FaceOrientedOutside (Cell c) const;
637  void ReorderEdges () const;
638  bool CheckEdgeOrder () const; // returns true if edges of face form an ordered closed loop
639  bool FixEdgeOrder () const; // returns true if edges were successfully reordered to form a closed loop
640  //implemented in modify.cpp
641  static Face UniteFaces (const ElementArray<Face> & faces, MarkerType del_protect);
642  static bool TestUniteFaces (const ElementArray<Face> & faces, MarkerType del_protect);
643  static ElementArray<Face> SplitFace (Face face, const ElementArray<Edge> & edges, MarkerType del_protect); //provide all edges that lay inside face
644  static bool TestSplitFace (Face face, const ElementArray<Edge> & edges, MarkerType del_protect);
648  void SwapCells () const;
649  //implemented in geometry.cpp
650  Storage::real Area () const;
651  void Normal (real * nrm) const;
652  void UnitNormal (real * nrm) const;
653  void OrientedNormal (Cell c, real * nrm) const;
654  void OrientedUnitNormal (Cell c, real * nrm) const;
655  bool FixNormalOrientation (bool allow_swap = true) const; //returns true if orientation was corrected, otherwise returns false
656  bool CheckNormalOrientation () const; //returns true if orientation is correct, otherwise returns false
657  bool Closure () const;
658  bool SamePlane (const ElementArray<Edge>& edges) const;
659  bool SamePlane (const ElementArray<Node>& nodes) const;
660  static bool SamePlane (const ElementArray<Face>& faces);
661  // test integrity of polygon
662  bool Inside (const real * point) const; //is point inside face
663  };
664 
665  __INLINE const Face & InvalidFace() {static Face ret(NULL,InvalidHandle()); return ret;}
666 
667  //implemented in cell.cpp
688  class Cell : public Element
689  {
690  public:
694  Cell() : Element() {}
701  Cell(Mesh * m, HandleType h) : Element(m,h) {}
712  Cell(Mesh * m, HandleType * h) : Element(m,h) {}
718  Cell(const Cell & other) : Element(other) {}
727  Cell & operator =(Cell const & other) {Element::operator =(other); return *this;}
733  Cell * operator ->() {return this;}
739  const Cell * operator ->() const {return this;}
745  Cell & self() {return *this;}
751  const Cell & self() const {return *this;}
752  public:
815  ElementArray<Node> getNodes (MarkerType mask,bool invert_mask = false) const;
829  ElementArray<Edge> getEdges (MarkerType mask,bool invert_mask = false) const;
844  ElementArray<Face> getFaces (MarkerType mask,bool invert_mask = false) const;
853  bool CheckEdgeOrder () const; //not implemented//2D only, returns true if edges of face form an ordered closed loop
864  bool FixEdgeOrder () const; //not implemented//2D only, returns true if edges were successfully reordered to form a closed loop
865  //implemented in modify.cpp
875  static Cell UniteCells (const ElementArray<Cell> & cells, MarkerType del_protect);
880  static bool TestUniteCells (const ElementArray<Cell> & cells, MarkerType del_protect);
906  static ElementArray<Cell> SplitCell (Cell cell, const ElementArray<Face> & faces, MarkerType del_protect); //provide all faces, that lay inside cell
913  static bool TestSplitCell (Cell cell, const ElementArray<Face> & faces, MarkerType del_protect);
914  //implemented in geometry.cpp
922  Cell Neighbour (Face face) const;
925  ElementArray<Cell> NeighbouringCells () const; // get all cells that share any face with current
937  bool Inside (const real * point) const; //is point inside cell, check for 2d case
938  bool InsidePrint (const real * point, std::ostream & sout = std::cout) const; //is point inside cell, check for 2d case
944  real Volume () const;
950  bool Closure () const;
952  void SwapBackCell () const;
953 
954  bool CheckConvexity () const;
955  };
956 
958  __INLINE const Cell & InvalidCell() {static Cell ret(NULL,InvalidHandle()); return ret;}
959 
960  class ElementSet : public Element //implemented in eset.cpp
961  {
962  public:
969  static const enumerator high_conn_reserved = 4;
970  __INLINE static HandleType & hParent (Element::adj_type & arr) {return arr[0];}
971  __INLINE static HandleType & hSibling (Element::adj_type & arr) {return arr[1];}
972  __INLINE static HandleType & hChild (Element::adj_type & arr) {return arr[2];}
973  __INLINE static HandleType & hSorted (Element::adj_type & arr) {return arr[3];}
974  typedef INMOST_DATA_BULK_TYPE ComparatorType;
975  static const ComparatorType UNSORTED_COMPARATOR = 0;
976  static const ComparatorType GLOBALID_COMPARATOR = 1;
977  static const ComparatorType CENTROID_COMPARATOR = 2;
978  static const ComparatorType HIERARCHY_COMPARATOR= 3;
979  static const ComparatorType HANDLE_COMPARATOR = 4;
980  //typedef INMOST_DATA_BULK_TYPE ExchangeType;
981  //static const ExchangeType SYNC_ELEMENTS_NONE = 0; //elements are not synced in parallel set
982  //static const ExchangeType SYNC_ELEMENTS_ALL = 1; //all elements are synchronized in parallel set
983  //static const ExchangeType SYNC_ELEMENTS_SHARED= 2; //only shared elements are present
984  ElementSet () : Element() {}
985  ElementSet (Mesh * m, HandleType h) : Element(m,h) {}
986  ElementSet (Mesh * m, HandleType * h) : Element(m,h) {}
987  ElementSet (const ElementSet & other) : Element(other) {}
988  __INLINE ElementSet & operator = (ElementSet const & other) {Element::operator =(other); return *this;}
989  __INLINE ElementSet * operator -> () {return this;}
990  __INLINE const ElementSet * operator -> () const {return this;}
991  __INLINE ElementSet & self () {return *this;}
992  __INLINE const ElementSet & self () const {return *this;}
993  private:
997  void CollectProcessors (std::set<Storage::integer> & procs, char dir) const;
1001  void SetSendTo(std::set<Storage::integer> & procs, char dir) const;
1002  void SetSendTo(std::vector<Storage::integer> & procs, char dir) const;
1003  void SetSendTo(Storage::integer_array procs, char dir) const;
1004  public:
1006  std::string GetName() const;
1015 
1017  void AddSibling(const ElementSet & sibling) const;
1019  void AddChild(const ElementSet & child) const;
1020 
1022  void RemSibling(const ElementSet & sibling) const;
1024  void RemChild(const ElementSet & child) const;
1029 
1030  bool HaveSibling() const;
1031  bool HaveParent() const;
1032  bool HaveChild() const;
1033 
1037  HandleType * getHandles() const;
1045  enumerator nbAdjElements(ElementType etype) const;
1046  enumerator nbAdjElements(ElementType etype, MarkerType select, bool invert = false) const;
1048  ElementArray<Element> getAdjElements(ElementType etype) const;
1049  ElementArray<Element> getAdjElements(ElementType etype, MarkerType select, bool invert = false) const;
1050 
1053  ElementArray<Node> getNodes(MarkerType select, bool invert = false) const;
1056  ElementArray<Edge> getEdges(MarkerType select, bool invert = false) const;
1059  ElementArray<Face> getFaces(MarkerType select, bool invert = false) const;
1062  ElementArray<Cell> getCells(MarkerType select, bool invert = false) const;
1065  void PutElement(HandleType e) const;
1068  void PutElement(const Storage & e) const {PutElement(e->GetHandle());}
1070  void PutElements(const HandleType * handles, enumerator num) const;
1072  void PutElements(const ElementSet & other) const {PutElements(other->getHandles(),other->nbHandles());}
1074  template<typename EType>
1075  void PutElements(const ElementArray<EType> & elems) const {PutElements(elems.data(),static_cast<enumerator>(elems.size()));}
1078  void AddElement(HandleType e) const;
1081  void AddElement(const Storage & e) const {AddElement(e->GetHandle());}
1088  void AddElements(const HandleType * handles, enumerator num) const;
1090  void AddElements(const ElementSet & other) {Unite(other);}
1092  template<typename EType>
1093  void AddElements(const ElementArray<EType> & elems) const {AddElements(elems.data(),static_cast<enumerator>(elems.size()));}
1094 
1095  void RemoveElement(const Storage & e) const;
1096  void RemoveElements(const HandleType * handles, enumerator num) const;
1098  template<typename EType>
1099  void RemoveElements(const ElementArray<EType> & elems) const {RemoveElements(elems.data(),static_cast<enumerator>(elems.size()));}
1100 
1108  ElementArray<Element> Union(const HandleType * handles, enumerator num) const;
1110  template<typename EType>
1111  ElementArray<Element> Union(const ElementArray<EType> & elems) const {return Union(elems.data(),static_cast<enumerator>(elems.size()));}
1112 
1113  ElementArray<Element> Difference(const ElementSet & other) const;
1117  ElementArray<Element> Difference(const HandleType * handles, enumerator num) const;
1119  template<typename EType>
1120  ElementArray<Element> Difference(const ElementArray<EType> & elems) const {return Difference(elems.data(),static_cast<enumerator>(elems.size()));}
1121 
1122  ElementArray<Element> Intersection(const ElementSet & other) const;
1126  ElementArray<Element> Intersection(const HandleType * handles, enumerator num) const;
1128  template<typename EType>
1129  ElementArray<Element> Intersection(const ElementArray<EType> & elems) const {return Intersection(elems.data(),static_cast<enumerator>(elems.size()));}
1130 
1132  void Unite(const ElementSet & other) const;
1134  void Unite(const HandleType * handles, enumerator num) const;
1136  template<typename EType>
1137  void Unite(const ElementArray<EType> & elems) const {Unite(elems.data(),static_cast<enumerator>(elems.size()));}
1138 
1144  void Subtract(const ElementSet & other) const;
1146  void Subtract(const HandleType * handles, enumerator num) const;
1148  template<typename EType>
1149  void Subtract(const ElementArray<EType> & elems) const {Subtract(elems.data(),static_cast<enumerator>(elems.size()));}
1150 
1151 
1153  void Intersect(const ElementSet & other) const;
1155  void Intersect(const HandleType * handles, enumerator num) const;
1157  template<typename EType>
1158  void Intersect(const ElementArray<EType> & elems) const {Intersect(elems.data(),static_cast<enumerator>(elems.size()));}
1185  void SortSet(ComparatorType comp) const;
1188  //void SetExchange(ExchangeType comp) const;
1210  bool FindHandle(HandleType h, bool use_comparator) const;
1212  void SetMarkerElements(MarkerType m, ElementType etype = ESET|CELL|FACE|EDGE|NODE) const;
1213  void SetPrivateMarkerElements(MarkerType m, ElementType etype = ESET|CELL|FACE|EDGE|NODE) const;
1215  void RemMarkerElements(MarkerType m, ElementType etype = ESET|CELL|FACE|EDGE|NODE) const;
1216  void RemPrivateMarkerElements(MarkerType m, ElementType etype = ESET|CELL|FACE|EDGE|NODE) const;
1217  class iterator
1218  {
1219  Mesh * m;
1220  Element::adj_type const * ptr;
1221  Element::adj_type::size_type pos;
1222  public:
1223  typedef std::forward_iterator_tag iterator_category;
1224  iterator() : m(NULL), ptr(NULL), pos(0) {}
1225  iterator(const iterator & other) : m(other.m), ptr(other.ptr), pos(other.pos) {}
1226  iterator(Mesh * m, Element::adj_type const * ptr, Element::adj_type::size_type pos) : m(m), ptr(ptr), pos(pos) {}
1227  iterator & operator = (iterator const & other) {m = other.m; ptr = other.ptr; pos = other.pos; return *this;}
1228  iterator & operator ++();
1229  iterator & operator ++(int) {iterator ret(*this); operator++(); return *this;}
1230  bool operator ==(const iterator & other) const {assert(ptr == other.ptr); return pos == other.pos;}
1231  bool operator !=(const iterator & other) const {assert(ptr == other.ptr); return pos != other.pos;}
1232  bool operator < (const iterator & other) const {assert(ptr == other.ptr); return pos < other.pos;}
1233  bool operator > (const iterator & other) const {assert(ptr == other.ptr); return pos > other.pos;}
1234  bool operator <=(const iterator & other) const {assert(ptr == other.ptr); return pos <= other.pos;}
1235  bool operator >=(const iterator & other) const {assert(ptr == other.ptr); return pos >= other.pos;}
1236  const HandleType & operator *() const {return ptr->at(pos);}
1237  Element operator->() const {return Element(m,ptr->at(pos));}
1238  friend class ElementSet;
1239  };
1249  iterator Begin() const;
1252  iterator End() const;
1260  void Erase(iterator beg, iterator end) const;
1262  ComparatorType GetComparator() const;
1264  //ExchangeType GetExchange() const;
1266  void ReorderEmpty() const;
1268  bool Empty() const;
1270  enumerator Size() const;
1272  void Clear();
1277  bool DeleteSet();
1299  };
1300 
1301  __INLINE const ElementSet & InvalidElementSet() {static ElementSet ret(NULL,InvalidHandle()); return ret;}
1302 
1303  class Mesh : public TagManager, public Storage //implemented in mesh.cpp
1304  {
1305  public:
1306 #if defined(CHECKS_MARKERS)
1307  bool check_shared_mrk, check_private_mrk;
1308 #endif
1309  enum MeshState {Serial, Parallel};
1314  //typedef std::vector<integer> empty_container;
1315  //typedef std::vector<integer> links_container;
1317  sparse_type;
1319  sparse_rec;
1320  typedef sparse_type::size_type
1321  senum;
1322  private:
1323  std::string name;
1324  std::map<std::string,HandleType> set_search;
1325  std::vector<Tag> orient_tags; // tags that follow normal orientation
1326  real epsilon;
1327  empty_container empty_space[6];
1328  empty_container empty_links[6];
1329  links_container links[6];
1330  Tag tag_global_id;
1331  Tag tag_coords;
1332  Tag tag_low_conn;
1333  Tag tag_high_conn;
1334  Tag tag_markers;
1335  Tag * tag_private_markers;
1336  Tag tag_geom_type;
1337  Tag tag_setname;
1338  Tag tag_setcomparator;
1339  //Tag tag_setexchange;
1340  MeshState m_state;
1341  integer dim;
1342  HandleType last_created;
1343  integer hidden_count[6];
1344  integer hidden_count_zero[6];
1345  private:
1346  INMOST_DATA_BIG_ENUM_TYPE parallel_mesh_unique_id;
1347  INMOST_MPI_Comm comm;
1348  //INMOST_MPI_Group group;
1349  Tag tag_shared;
1350  Tag tag_owner;
1351  Tag tag_layers;
1352  Tag tag_bridge;
1353  Tag tag_redistribute;
1354  private:
1355  //double dist(Cell a, Cell b);
1356  void AllocatePrivateMarkers();
1357  void DeallocatePrivateMarkers();
1358  __INLINE static sparse_rec mkrec (const Tag & t) {sparse_rec ret; ret.tag = t.mem; ret.rec = NULL; return ret;}
1359  __INLINE sparse_type const & MGetSparseLink (integer etypenum, integer ID) const {assert(links[etypenum][ID] != -1); return GetSparseData(etypenum,links[etypenum][ID]);}
1360  __INLINE sparse_type & MGetSparseLink (integer etypenum, integer ID) {assert(links[etypenum][ID] != -1); return GetSparseData(etypenum,links[etypenum][ID]);}
1361  __INLINE sparse_type const & MGetSparseLink (HandleType h) const {return MGetSparseLink(GetHandleElementNum(h),GetHandleID(h));}
1362  __INLINE sparse_type & MGetSparseLink (HandleType h) {return MGetSparseLink(GetHandleElementNum(h),GetHandleID(h));}
1363  __INLINE const void * MGetSparseLink (HandleType h, const Tag & t) const {sparse_type const & s = MGetSparseLink(GetHandleElementNum(h),GetHandleID(h)); for(senum i = 0; i < s.size(); ++i) if( s[i].tag == t.mem ) return s[i].rec; return NULL;}
1364  void*& MGetSparseLink (HandleType h, const Tag& t);// {sparse_type& s = MGetSparseLink(GetHandleElementNum(h), GetHandleID(h)); for (senum i = 0; i < s.size(); ++i) if (s[i].tag == t.mem) return s[i].rec; s.push_back(mkrec(t)); return s.back().rec; }
1365  __INLINE const void * MGetDenseLink (integer n, integer ID, const Tag & t) const {assert(links[n][ID] != -1); return &(GetDenseData(t.GetPositionByDim(n))[links[n][ID]]);}
1366  __INLINE void * MGetDenseLink (integer n, integer ID, const Tag & t) {assert(links[n][ID] != -1); return &(GetDenseData(t.GetPositionByDim(n))[links[n][ID]]);}
1367  __INLINE const void * MGetDenseLink (HandleType h, const Tag & t) const {return MGetDenseLink(GetHandleElementNum(h),GetHandleID(h),t);}
1368  __INLINE void * MGetDenseLink (HandleType h, const Tag & t) {return MGetDenseLink(GetHandleElementNum(h),GetHandleID(h),t);}
1369  __INLINE const void * MGetLink (HandleType h, const Tag & t) const {if( !t.isSparseByDim(GetHandleElementNum(h)) ) return MGetDenseLink(h,t); else return MGetSparseLink(h,t);}
1370  __INLINE void * MGetLink (HandleType h, const Tag & t) {if( !t.isSparseByDim(GetHandleElementNum(h)) ) return MGetDenseLink(h,t); else {void * & q = MGetSparseLink(h,t); if( q == NULL ) AllocateSparseData(q,t); return q;}}
1371  void AllocateSparseData (void * & q, const Tag & t);
1372  void Init (std::string name);
1373  public:
1374  Tag tag_sendto;
1375  Tag tag_processors;
1377  void AddOrientedTag(Tag t) { assert(t.isValid() && t.isDefined(FACE)); orient_tags.push_back(t); }
1381  void OrientTags(Face f);
1383  void OrientTag(Face f, Tag t);
1386  void ReportConnection(HandleType h);
1391  bool HaveGlobalID (ElementType types) const;
1394  void Clear ();
1397  enumerator MemoryUsage (HandleType h);
1398  Mesh ();
1399  Mesh (std::string name);
1400  Mesh (const Mesh & other);
1401  Mesh & operator = (Mesh const & other);
1402  virtual ~Mesh ();
1410  MarkerType CreateMarker ();
1411  MarkerType CreatePrivateMarker ();
1421  void ReleaseMarker (MarkerType n, ElementType cleanup = NONE);
1422  void ReleasePrivateMarker(MarkerType n, ElementType cleanup = NONE);
1427  __INLINE void SetEpsilon (real e) {epsilon = e;}
1430  __INLINE real GetEpsilon () const {return epsilon;}
1440  __INLINE integer GetDimensions () const {return dim;}
1443  __INLINE MeshState GetMeshState () const {return m_state;}
1444  __INLINE const Tag & GlobalIDTag () const {return tag_global_id;}
1445  __INLINE const Tag & CoordsTag () const {return tag_coords;}
1446  __INLINE const Tag & LowConnTag () const {return tag_low_conn;}
1447  __INLINE const Tag & HighConnTag () const {return tag_high_conn;}
1448  __INLINE const Tag & MarkersTag () const {return tag_markers;}
1449  __INLINE const Tag & GeomTypeTag () const {return tag_geom_type;}
1450  __INLINE const Tag & SendtoTag () const {return tag_sendto;}
1451  __INLINE const Tag & SharedTag () const {return tag_shared;}
1452  __INLINE const Tag & OwnerTag () const {return tag_owner;}
1453  __INLINE const Tag & LayersTag () const {return tag_layers;}
1454  __INLINE const Tag & BridgeTag () const {return tag_bridge;}
1455  __INLINE const Tag & ProcessorsTag () const {return tag_processors;}
1456  __INLINE const Tag & SetNameTag () const {return tag_setname;}
1457  __INLINE const Tag & SetComparatorTag () const {return tag_setcomparator;}
1458  //__INLINE const Tag & SetExchangeTag () const {return tag_setexchange;}
1461  __INLINE Tag RedistributeTag () {return CreateTag("TEMPORARY_NEW_OWNER",DATA_INTEGER,CELL,NONE,1);}
1482  Tag CreateTag (std::string name, DataType dtype, ElementType etype,ElementType sparse, INMOST_DATA_ENUM_TYPE size = ENUMUNDEF);
1488  Tag DeleteTag (Tag tag, ElementType mask = NODE | EDGE | FACE | CELL | ESET | MESH);
1492  __INLINE iteratorTag BeginTag () {return tags.begin(); }
1495  __INLINE enumerator NumberOfTags () const { return static_cast<INMOST_DATA_ENUM_TYPE>(tags.size()); }
1498  __INLINE iteratorTag EndTag () {return tags.end(); }
1507  Node CreateNode (const real * coords);
1508  std::pair<Edge,bool> CreateEdge (const ElementArray<Node> & nodes);
1509  std::pair<Face,bool> CreateFace (const ElementArray<Edge> & edges);
1510  std::pair<Face,bool> CreateFace (const ElementArray<Node> & nodes);
1511  std::pair<Cell,bool> CreateCell (const ElementArray<Face> & faces, const ElementArray<Node> & suggest_nodes = ElementArray<Node>(NULL));
1512  std::pair<Cell,bool> CreateCell (const ElementArray<Node> & c_f_nodes, const integer * c_f_numnodes, integer num_c_faces,
1513  const ElementArray<Node> & suggest_nodes = ElementArray<Node>(NULL));
1514  std::pair<Cell,bool> CreateCell (const ElementArray<Node> & c_nodes, const integer * c_f_nodeinds, const integer * c_f_numnodes, integer num_c_faces,
1515  const ElementArray<Node> & suggest_nodes = ElementArray<Node>(NULL));
1516  std::pair<ElementSet,bool> CreateSet (std::string name);
1518  std::pair<ElementSet,bool> CreateSetUnique (std::string name);
1522  ElementSet GetSet (std::string name);
1525  HandleType LastCreated () const {return last_created;}
1526 
1527  bool isValidHandleRange (HandleType h) const; //for asserts
1528  bool isValidElementNum (integer etypenum, integer lid) const {return links[etypenum][lid] != -1;}
1529  bool isValidElement (ElementType etype, integer lid) const {return links[ElementNum(etype)][lid] != -1;}
1530  bool isValidCell (integer lid) const {return links[ElementNum(CELL)][lid] != -1;}
1531  bool isValidFace (integer lid) const {return links[ElementNum(FACE)][lid] != -1;}
1532  bool isValidEdge (integer lid) const {return links[ElementNum(EDGE)][lid] != -1;}
1533  bool isValidNode (integer lid) const {return links[ElementNum(NODE)][lid] != -1;}
1534  bool isValidElementSet (integer lid) const {return links[ElementNum(ESET)][lid] != -1;}
1535  bool isValidElement (HandleType h) const {return isValidHandleRange(h) && isValidElementNum(GetHandleElementNum(h),GetHandleID(h));}
1538  HandleType FindSharedAdjacency(const HandleType * arr, enumerator num) const;
1539  void ReorderEmpty (ElementType reordertypes);
1540  //Bug inside: sort would not work on chunk_array, because it is not contiguous in memory
1541  void ReorderApply (Tag index, ElementType mask);
1542  void RestoreCellNodes (HandleType hc, ElementArray<Node> & ret);
1543  private:
1544  //those functions contain asserts for debug purposes, in release mode (NDEBUG is set) they are empty and call should be optimized out in worst case by linker
1545  void Asserts (HandleType h, const Tag & tag, DataType expected) const;
1546  void AssertsDF (HandleType h, const Tag & tag, DataType expected) const;
1547  void AssertsDV (HandleType h, const Tag & tag, DataType expected) const;
1548  public:
1562  real & Real (HandleType h, const Tag & tag);
1574  integer & Integer (HandleType h, const Tag & tag);
1586  bulk & Bulk (HandleType h, const Tag & tag);
1602  reference & Reference (HandleType h, const Tag & tag);
1619  remote_reference & RemoteReference (HandleType h, const Tag & tag);
1628  real_array RealArray (HandleType h, const Tag & tag);
1638  integer_array IntegerArray (HandleType h, const Tag & tag);
1648  bulk_array BulkArray (HandleType h, const Tag & tag);
1681  reference_array ReferenceArray (HandleType h, const Tag & tag);
1723  real & RealDF (HandleType h, const Tag & tag) {AssertsDF(h,tag,DATA_REAL ); return static_cast<real *>(MGetDenseLink(h,tag))[0];}
1732  integer & IntegerDF (HandleType h, const Tag & tag) {AssertsDF(h,tag,DATA_INTEGER ); return static_cast<integer *>(MGetDenseLink(h,tag))[0];}
1741  bulk & BulkDF (HandleType h, const Tag & tag) {AssertsDF(h,tag,DATA_BULK ); return static_cast<bulk *>(MGetDenseLink(h,tag))[0];}
1754  reference & ReferenceDF (HandleType h, const Tag & tag) {AssertsDF(h,tag,DATA_REFERENCE); return static_cast<reference*>(MGetDenseLink(h,tag))[0];}
1767  remote_reference & RemoteReferenceDF (HandleType h, const Tag & tag) {AssertsDF(h,tag,DATA_REMOTE_REFERENCE); return static_cast<remote_reference*>(MGetDenseLink(h,tag))[0];}
1780  real_array RealArrayDF (HandleType h, const Tag & tag) {AssertsDF(h,tag,DATA_REAL ); return real_array (static_cast<real *>(MGetDenseLink(h,tag)),tag.GetSize());}
1793  integer_array IntegerArrayDF (HandleType h, const Tag & tag) {AssertsDF(h,tag,DATA_INTEGER ); return integer_array (static_cast<integer *>(MGetDenseLink(h,tag)),tag.GetSize());}
1806  bulk_array BulkArrayDF (HandleType h, const Tag & tag) {AssertsDF(h,tag,DATA_BULK ); return bulk_array (static_cast<bulk *>(MGetDenseLink(h,tag)),tag.GetSize());}
1835  reference_array ReferenceArrayDF (HandleType h, const Tag & tag) {AssertsDF(h,tag,DATA_REFERENCE); return reference_array(this,static_cast<reference*>(MGetDenseLink(h,tag)),tag.GetSize());}
1864  remote_reference_array RemoteReferenceArrayDF(HandleType h, const Tag & tag) {AssertsDF(h,tag,DATA_REMOTE_REFERENCE); return remote_reference_array(static_cast<remote_reference*>(MGetDenseLink(h,tag)),tag.GetSize());}
1876  real & RealDV (HandleType h, const Tag & tag) {AssertsDV(h,tag,DATA_REAL ); return static_cast<inner_real_array *>(MGetDenseLink(h,tag))->at_safe(0);}
1888  integer & IntegerDV (HandleType h, const Tag & tag) {AssertsDV(h,tag,DATA_INTEGER ); return static_cast<inner_integer_array *>(MGetDenseLink(h,tag))->at_safe(0);}
1901  bulk & BulkDV (HandleType h, const Tag & tag) {AssertsDV(h,tag,DATA_BULK ); return static_cast<inner_bulk_array *>(MGetDenseLink(h,tag))->at_safe(0);}
1917  reference & ReferenceDV (HandleType h, const Tag & tag) {AssertsDV(h,tag,DATA_REFERENCE); return static_cast<inner_reference_array*>(MGetDenseLink(h,tag))->at_safe(0);}
1933  remote_reference & RemoteReferenceDV (HandleType h, const Tag & tag) {AssertsDV(h,tag,DATA_REMOTE_REFERENCE); return static_cast<inner_remote_reference_array*>(MGetDenseLink(h,tag))->at_safe(0);}
1942  real_array RealArrayDV (HandleType h, const Tag & tag) {AssertsDV(h,tag,DATA_REAL ); return real_array (*static_cast<inner_real_array *>(MGetDenseLink(h,tag)));}
1951  integer_array IntegerArrayDV (HandleType h, const Tag & tag) {AssertsDV(h,tag,DATA_INTEGER ); return integer_array (*static_cast<inner_integer_array *>(MGetDenseLink(h,tag)));}
1960  bulk_array BulkArrayDV (HandleType h, const Tag & tag) {AssertsDV(h,tag,DATA_BULK ); return bulk_array (*static_cast<inner_bulk_array *>(MGetDenseLink(h,tag)));}
1985  reference_array ReferenceArrayDV (HandleType h, const Tag & tag) {AssertsDV(h,tag,DATA_REFERENCE); return reference_array(this,*static_cast<inner_reference_array*>(MGetDenseLink(h,tag)));}
2010  remote_reference_array RemoteReferenceArrayDV(HandleType h, const Tag & tag) {AssertsDV(h,tag,DATA_REMOTE_REFERENCE); return remote_reference_array(*static_cast<inner_remote_reference_array*>(MGetDenseLink(h,tag)));}
2011 
2012 #if defined(USE_AUTODIFF)
2013  var & Variable (HandleType h, const Tag & tag);
2014  var & VariableDF (HandleType h, const Tag & tag) {AssertsDF(h,tag,DATA_VARIABLE); return static_cast<var *>(MGetDenseLink(h,tag))[0];}
2015  var & VariableDV (HandleType h, const Tag & tag) {AssertsDV(h,tag,DATA_VARIABLE); return static_cast<inner_variable_array *>(MGetDenseLink(h,tag))->at_safe(0);}
2016  var_array VariableArray (HandleType h, const Tag & tag);
2017  var_array VariableArrayDF (HandleType h, const Tag & tag) {AssertsDF(h,tag,DATA_VARIABLE); return var_array(static_cast<var *>(MGetDenseLink(h,tag)),tag.GetSize());}
2018  var_array VariableArrayDV (HandleType h, const Tag & tag) {AssertsDV(h,tag,DATA_VARIABLE); return var_array(*static_cast<inner_variable_array*>(MGetDenseLink(h,tag)));}
2019 #endif
2023  __INLINE void SetMarker (HandleType h,MarkerType n) {assert(!isPrivate(n)); static_cast<bulk *>(MGetDenseLink(h,MarkersTag()))[n >> MarkerShift] |= static_cast<bulk>(n & MarkerMask);}
2024  void SetPrivateMarker (HandleType h,MarkerType n);
2025  __INLINE void SetAnyMarker (HandleType h, MarkerType n) { return isPrivate(n) ? SetPrivateMarker(h, n) : SetMarker(h, n); }
2026 
2032  __INLINE void SetMarkerArray (const HandleType * h, enumerator n, MarkerType m) {for(enumerator i = 0; i < n; ++i) if( h[i] != InvalidHandle() )SetMarker(h[i],m);}
2033  __INLINE void SetPrivateMarkerArray (const HandleType * h, enumerator n, MarkerType m) {for(enumerator i = 0; i < n; ++i) if( h[i] != InvalidHandle() )SetPrivateMarker(h[i],m);}
2034  __INLINE void SetAnyMarkerArray (const HandleType* h, enumerator n, MarkerType m) { return isPrivate(n) ? SetPrivateMarkerArray(h, n, m) : SetMarkerArray(h, n, m); }
2038  __INLINE bool GetMarker (HandleType h,MarkerType n) const {assert(!isPrivate(n)); return (static_cast<const bulk *>(MGetDenseLink(h,MarkersTag()))[n >> MarkerShift] & static_cast<bulk>(n & MarkerMask)) != 0;}
2039  bool GetPrivateMarker (HandleType h,MarkerType n) const;
2040  __INLINE bool GetAnyMarker (HandleType h, MarkerType n) const { return isPrivate(n) ? GetPrivateMarker(h, n) : GetMarker(h, n); }
2044  __INLINE void RemMarker (HandleType h,MarkerType n) {assert(!isPrivate(n)); static_cast<bulk *>(MGetDenseLink(h,MarkersTag()))[n >> MarkerShift] &= ~static_cast<bulk>(n & MarkerMask);}
2045  void RemPrivateMarker (HandleType h,MarkerType n);
2046  __INLINE void RemAnyMarker (HandleType h, MarkerType n) { return isPrivate(n) ? RemPrivateMarker(h, n) : RemMarker(h, n); }
2052  void RemMarkerArray (const HandleType * h, enumerator n, MarkerType m) {for(enumerator i = 0; i < n; ++i) if( h[i] != InvalidHandle() ) RemMarker(h[i],m);}
2053  void RemPrivateMarkerArray (const HandleType * h, enumerator n, MarkerType m) {for(enumerator i = 0; i < n; ++i) if( h[i] != InvalidHandle() ) RemPrivateMarker(h[i],m);}
2055  void ClearMarkerSpace (HandleType h);
2059  void GetMarkerSpace (HandleType h,bulk copy [MarkerFields]) const;
2063  void SetMarkerSpace (HandleType h,bulk source[MarkerFields]);
2095  Element::adj_type & HighConn (HandleType h) {return *static_cast<inner_reference_array*>(MGetDenseLink(h,HighConnTag()));}
2097  ElementType HaveUpperAdjacencies() const;
2099  void RemoveUpperAdjacencies(ElementType mask = (NODE|EDGE|FACE));
2101  void RestoreUpperAdjacencies(ElementType mask = (NODE|EDGE|FACE));
2103  ElementType HaveLowerAdjacencies() const;
2105  void RemoveLowerAdjacencies(ElementType mask = (EDGE|FACE|CELL));
2107  void RestoreLowerAdjacencies(ElementType mask = (EDGE|FACE|CELL));
2109  Element::adj_type const& HighConn (HandleType h) const {return *static_cast<const inner_reference_array*>(MGetDenseLink(h,HighConnTag()));}
2121  Element::adj_type & LowConn (HandleType h) {return *static_cast<inner_reference_array*>(MGetDenseLink(h,LowConnTag()));}
2123  Element::adj_type const& LowConn (HandleType h) const {return *static_cast<const inner_reference_array*>(MGetDenseLink(h,LowConnTag()));}
2130  INMOST_DATA_ENUM_TYPE GetDataSize (HandleType h,const Tag & tag) const; //For DATA_BULK return number of bytes, otherwise return the length of array
2136  INMOST_DATA_ENUM_TYPE GetDataCapacity (HandleType h,const Tag & tag) const;
2139  INMOST_DATA_ENUM_TYPE GetDataCapacity (const INMOST_DATA_BULK_TYPE * data, INMOST_DATA_ENUM_TYPE size, const Tag & tag) const;
2147  void SetDataSize (HandleType h,const Tag & tag, enumerator new_size);
2155  void GetData (HandleType h,const Tag & tag, enumerator shift, enumerator size, void * data) const;
2162  void SetData (HandleType h,const Tag & tag, enumerator shift, enumerator size, const void * data);
2168  void DelData (HandleType h,const Tag & tag);
2172  void DelDenseData (HandleType h,const Tag & tag);
2176  void DelDenseData (void * data,const Tag & tag);
2180  bool DelSparseData (HandleType h,const Tag & tag);
2186  bool HaveData (HandleType h,const Tag & tag) const;
2187 
2188  Element::GeometricType GetGeometricType (HandleType h) const {return static_cast<const bulk *>(MGetDenseLink(h,GeomTypeTag()))[0];}
2189  void SetGeometricType (HandleType h, Element::GeometricType type) {static_cast<bulk *>(MGetDenseLink(h,GeomTypeTag()))[0] = type;}
2196  integer & GlobalID (HandleType h) {return static_cast<integer *>(MGetDenseLink(h,GlobalIDTag()))[0];}
2203  integer GlobalID (HandleType h) const {return static_cast<const integer *>(MGetDenseLink(h,GlobalIDTag()))[0];}
2208  integer DataLocalID (HandleType h) const {return static_cast<integer>(links[GetHandleElementNum(h)][GetHandleID(h)]);}
2217  Element::Status GetStatus (HandleType h) const { if( SharedTag().isValid() ) return static_cast<const bulk *>(MGetDenseLink(h,SharedTag()))[0]; return Element::Owned;}
2229  void SetStatus (HandleType h, Element::Status s) {BulkDF(h,SharedTag()) = s;}
2230  //implemented in modify.
2238  void Destroy (HandleType h);
2240  void Destroy (const Storage & e) {Destroy(e->GetHandle());}
2249  bool Hide (HandleType h);
2254  bool Show (HandleType h);
2263  bool Delete (HandleType h);
2267  bool Hidden (HandleType h) const;
2273  bool New (HandleType h) const;
2274  //geometry.cpp
2277  void ComputeGeometricType(HandleType h);
2278  //mesh.cpp
2281  INMOST_DATA_ENUM_TYPE GetArrayCapacity (integer etypenum);
2282  private:
2284  void SyncDimensions ();
2286  void MoveStorage (integer etypenum, integer old_addr, integer new_addr);
2288  void UntieElement (integer etypenum, integer ID);
2290  integer TieElement (integer etypenum);
2291  public:
2292  //implemented in parallel.cpp
2293  enum Action {AGhost, AMigrate};
2294  enum Prepare {UnknownSize, UnknownSource};
2295  typedef void (*ReduceOperation)(const Tag & tag, const Element & element, const INMOST_DATA_BULK_TYPE * recv_data, INMOST_DATA_ENUM_TYPE recv_size);
2296  typedef std::vector<Tag> tag_set;
2297  typedef std::vector<HandleType> element_set;
2298  typedef std::vector<INMOST_DATA_BULK_TYPE> buffer_type;
2299  typedef std::map<int, element_set > proc_elements;
2300  typedef std::pair<int, buffer_type > proc_buffer_type;
2301  typedef std::vector< proc_buffer_type > exch_buffer_type;
2302  typedef std::vector<INMOST_MPI_Request> exch_reqs_type;
2303  typedef struct exch_recv_reqs_t
2304  {
2305  std::vector<unsigned> buf;
2306  std::vector<unsigned> cnt;
2307  std::vector<INMOST_MPI_Request> requests;
2308  unsigned count()
2309  {
2310  unsigned ret = 0;
2311  for(size_t i = 0; i < cnt.size(); ++i)
2312  ret += cnt[i];
2313  return ret;
2314  }
2315  void clear()
2316  {
2317  buf.clear();
2318  buf.push_back(0);
2319  cnt.clear();
2320  requests.clear();
2321  }
2323 
2325  {
2326  public:
2327  exch_reqs_type send_reqs;
2328  exch_recv_reqs_type recv_reqs;
2329  exch_buffer_type send_buffers, recv_buffers;
2330  };
2331  private:
2332  class Random // random generator to provide tag for communication
2333  {
2334  private: unsigned int n,a,c,m;
2335  public:
2336  Random(unsigned int seed = 50);
2337  //~ Random(const Random & other);
2338  unsigned int Number();
2339  } randomizer;
2340  public:
2342  {
2343  private:
2344  element_set container[6];
2345  public:
2346  elements_by_type() {}
2347  elements_by_type(const elements_by_type & other) {for(int i = 0; i < 6; i++) container[i] = other.container[i];}
2348  ~elements_by_type(){}
2349  element_set & operator [](int i){ return container[i]; }
2350  const element_set & operator [](int i) const { return container[i]; }
2351  bool empty() {bool ret = true; for(int i = 0; i < 6 && ret; i++) ret &= container[i].empty(); return ret;}
2352  unsigned size() {unsigned ret = 0; for(int i = 0; i < 6; ++i) ret += (unsigned)container[i].size(); return ret;}
2353  };
2354  typedef std::map<int, elements_by_type > parallel_storage;
2355 
2356  typedef std::map<int, elements_by_type > proc_elements_by_type;
2357  private:
2358 #if defined(USE_PARALLEL_STORAGE)
2359  parallel_storage shared_elements;
2360  parallel_storage ghost_elements;
2361 #endif
2362 #if defined(USE_PARALLEL_WRITE_TIME)
2363  int num_exchanges;
2364  public:
2365  mutable std::fstream out_time;
2366  private:
2367  mutable int tab;
2368  mutable int func_id;
2369 #endif
2370 #if defined(USE_MPI_P2P)
2371  INMOST_MPI_Win window;
2372  INMOST_DATA_BIG_ENUM_TYPE * shared_space;
2373 #endif
2374  int parallel_file_strategy;
2375  private:
2376  void ListTags (tag_set & list);
2377  std::vector<int> ComputeSharedProcs (const parallel_storage & from, const parallel_storage & to);
2378  std::vector<int> ComputeSharedProcs (ElementType etype);
2379  proc_elements ComputeSharedSkinSet(ElementType bridge, MarkerType marker = 0);
2380  void PackElementsGather (elements_by_type & selems, const elements_by_type & elements, int destination, ElementType mask, MarkerType select, const tag_set & tag_list, bool force_send, bool send_links_to_owner, bool pack_by_gids);
2381  void PackElementsEnumerate (elements_by_type & selems, TagInteger pack_position);
2382  void PackElementsUnenumerate (elements_by_type & selems, TagInteger pack_position);
2383  void PackTagData (const Tag & tag, const elements_by_type & elements, int destination, ElementType mask, MarkerType select, buffer_type & buffer, TagInteger pack_position);
2384  void UnpackTagData (const Tag & tag, const elements_by_type & elements, int source, ElementType mask, MarkerType select, buffer_type & buffer, size_t & buffer_position, ReduceOperation op, const elements_by_type & unpack_elements);//, proc_elements_by_type * send_elements = NULL);
2385  void PackElementsData (elements_by_type & input, buffer_type & buffer, int destination, const tag_set & tag_list,TagInteger pack_position, bool pack_gids);
2386  void UnpackElementsData (elements_by_type & output, buffer_type & buffer, int source, size_t & buffer_position, tag_set & tag_list);
2387  void PrepareReceiveInner(Prepare todo, exch_buffer_type & send_bufs, exch_buffer_type & recv_bufs);
2388  void ExchangeDataInnerBegin(const tag_set & tag, const parallel_storage & from, const parallel_storage & to, ElementType mask, MarkerType select, exchange_data & storage);
2389  void ExchangeDataInnerEnd(const tag_set & tag, const parallel_storage & from, const parallel_storage & to, ElementType mask, MarkerType select, ReduceOperation op, exchange_data & storage);
2390  void ExchangeBuffersInner(exch_buffer_type & send_bufs, exch_buffer_type & recv_bufs, exch_reqs_type & send_reqs, exch_recv_reqs_type & recv_reqs);
2391  std::vector<int> FinishRequests (exch_recv_reqs_type & recv_reqs);
2392  void SortParallelStorage(parallel_storage & ghost, parallel_storage & shared,ElementType mask);
2393  void ReportParallelStorage();
2394  void GatherParallelStorage(parallel_storage & ghost, parallel_storage & shared, ElementType mask);
2395  void InformElementsOwners(proc_elements_by_type & send_elements, exchange_data & storage);
2396  void RemoveLinksToDeletedElements(MarkerType mrk);
2397  public:
2398  HandleType FindSharedGhost(ElementType etype, Storage::integer global_id, int source_proc, int owner_proc);
2399 #if defined(USE_PARALLEL_WRITE_TIME)
2400  //this part is needed to test parallel performance
2401  void Enter () const;
2402  void Exit () const;
2403  int & GetFuncID () const {return func_id;}
2404  std::fstream & GetStream ();
2405  std::ostream & WriteTab (std::ostream & f) const;
2406  void FinalizeFile ();
2407  static void AtExit (void);
2408 #endif
2409  void ClearFile ();
2415  static void Initialize (int * argc, char *** argv);
2417  static void Finalize ();
2491  //no longer used
2492  //void SetParallelStrategy(int strategy){assert( !(strategy < 0 || strategy > 3) ); parallel_strategy = strategy;}
2495  //no longer used
2496  //int GetParallelStrategy() {return parallel_strategy;}
2537  void SetParallelFileStrategy(int strategy){assert( !(strategy < 0 || strategy > 1) ); parallel_file_strategy = strategy;}
2540  int GetParallelFileStrategy() const {return parallel_file_strategy;}
2542  int GetProcessorRank () const;
2544  int GetProcessorsNumber() const;
2550  INMOST_MPI_Comm GetCommunicator () const;
2552  INMOST_MPI_Group GetGroup () const;
2554  void SetCommunicator (INMOST_MPI_Comm _comm);
2556  void ResolveShared (bool only_new = false);
2558  void ResolveSets ();
2560  void RemoveGhost (MarkerType marker = 0);
2579  void RemoveGhostElements(const HandleType * ghost, enumerator num);
2580  template<typename EType>
2581  void RemoveGhostElements(const ElementArray<EType> & ghost) {RemoveGhostElements(ghost.data(),static_cast<enumerator>(ghost.size()));}
2582  void RemoveGhostElements(const ElementSet & ghost) {RemoveGhostElements(ghost.getHandles(),ghost.nbHandles());}
2595  void AssignGlobalID (ElementType mask);
2611  void ExchangeData (const Tag & tag, ElementType mask, MarkerType select = 0);
2624  void ExchangeOrientedData(const Tag& tag, ElementType mask, MarkerType select = 0, MarkerType orient = 0);
2643  void ExchangeDataBegin (const Tag & tag, ElementType mask, MarkerType select, exchange_data & storage);
2653  void ExchangeDataEnd (const Tag & tag, ElementType mask, MarkerType select, exchange_data & storage);
2661  void ExchangeData (const tag_set & tags, ElementType mask, MarkerType select = 0);
2673  void ExchangeOrientedData(const tag_set& tags, ElementType mask, MarkerType select = 0, MarkerType orient = 0);
2683  void ExchangeDataBegin (const tag_set & tags, ElementType mask, MarkerType select, exchange_data & storage);
2692  void ExchangeDataEnd (const tag_set & tags, ElementType mask, MarkerType select, exchange_data & storage);
2732  void ReduceData (const Tag & tag, ElementType mask, MarkerType select, ReduceOperation op );
2744  void ReduceDataBegin (const Tag & tag, ElementType mask, MarkerType select, exchange_data & storage);
2756  void ReduceDataEnd (const Tag & tag, ElementType mask, MarkerType select, ReduceOperation op, exchange_data & storage );
2767  void ReduceData (const tag_set & tags, ElementType mask, MarkerType select, ReduceOperation op );
2776  void ReduceDataBegin (const tag_set & tags, ElementType mask, MarkerType select, exchange_data & storage);
2786  void ReduceDataEnd (const tag_set & tags, ElementType mask, MarkerType select, ReduceOperation op, exchange_data & storage );
2818  void ExchangeMarked (enum Action action = AGhost);
2840  void ExchangeGhost (integer layers, ElementType bridge, MarkerType select = 0, bool delete_ghost = true);
2873  void Redistribute ();
2883  integer Enumerate (ElementType mask, Tag num_tag, integer start = 0, bool define_sparse = false);
2894  integer Enumerate (const HandleType * h, enumerator num, const Tag & num_tag, integer start = 0, bool define_sparse = true);
2904  template<typename EType>
2905  integer Enumerate (const ElementArray<EType> & elements, const Tag & num_tag, integer start = 0, bool define_sparse = true) {return Enumerate(elements.data(),static_cast<enumerator>(elements.size()),num_tag,start,define_sparse);}
2915  integer EnumerateSet (const ElementSet & set, const Tag & num_tag, integer start = 0, bool define_sparse = true);
2924  integer TotalNumberOf (ElementType mask);
2953  void Integrate (real * input, integer size);
2961  void Integrate (enumerator * input, integer size);
2969  void Integrate (integer * input, integer size);
2979  real Integrate (const Tag & t, enumerator entry, ElementType mask);
2988 
2989  real AggregateMax (real input);
2990  integer AggregateMax (integer input);
2991  enumerator AggregateMax (enumerator input);
2992  void AggregateMax (real * input, integer size);
2993  void AggregateMax (integer * input, integer size);
2994  void AggregateMax (enumerator * input, integer size);
2995 
2996  real AggregateMin (real input);
2997  integer AggregateMin (integer input);
2998  enumerator AggregateMin (enumerator input);
2999  void AggregateMin (real * input, integer size);
3000  void AggregateMin (integer * input, integer size);
3001  void AggregateMin (enumerator * input, integer size);
3017  void RecomputeParallelStorage(ElementType mask);
3028  void SortParallelStorage(ElementType mask);
3032  void RecordParallelStorage(ElementType mask);
3039  ElementType SynchronizeElementType(ElementType etype);
3049  void SynchronizeMarker (MarkerType marker, ElementType mask, SyncBitOp op);
3050  //for debug
3051  void Barrier ();
3052  void BeginSequentialCode();
3053  void EndSequentialCode ();
3054  //iterator.cpp::::::::::::::::::::::::::::::::::::::::::::::::::
3055  public:
3056  Element ElementByLocalIDNum(integer etypenum, integer lid) {assert((etypenum < 5 && (lid >= 0 && lid < static_cast<integer>(links[etypenum].size()))) || (etypenum == 5 && lid == 0)); return Element(this,ComposeHandleNum(etypenum,lid));}
3057  Element ElementByLocalID (ElementType etype, integer lid) {return ElementByLocalIDNum(ElementNum(etype),lid);}
3058  Element ElementByHandle (HandleType h) {return Element(this,h);}
3059 
3060  HandleType NextHandle (HandleType h) const;
3061  HandleType PrevHandle (HandleType h) const; //returns InvalidHandle() when go beyond first element
3062  HandleType NextHandle (HandleType h, ElementType mask) const;
3063  HandleType PrevHandle (HandleType h, ElementType mask) const; //returns InvalidHandle() when go beyond first element
3064  HandleType FirstHandle () const {return ComposeHandleNum(ElementNum(NODE),0);}
3065  HandleType LastHandle () const {return ComposeHandleNum(ElementNum(MESH),1);}
3066  HandleType FirstHandle (ElementType etype) const {return ComposeHandleNum(ElementNum(etype),0);}
3067  HandleType LastHandle (ElementType etype) const {integer num = ElementNum(etype); return ComposeHandleNum(num,static_cast<integer>(links[num].size()));}
3068 
3069  Node NodeByLocalID (integer lid) { assert(lid >= 0 && lid < static_cast<integer>(links[0].size())); return Node(this,ComposeHandleNum(0,lid)); }
3070  Edge EdgeByLocalID (integer lid) { assert(lid >= 0 && lid < static_cast<integer>(links[1].size())); return Edge(this,ComposeHandleNum(1,lid)); }
3071  Face FaceByLocalID (integer lid) { assert(lid >= 0 && lid < static_cast<integer>(links[2].size())); return Face(this,ComposeHandleNum(2,lid));}
3072  Cell CellByLocalID (integer lid) { assert(lid >= 0 && lid < static_cast<integer>(links[3].size())); return Cell(this,ComposeHandleNum(3,lid)); }
3073  ElementSet EsetByLocalID (integer lid) { assert(lid >= 0 && lid < static_cast<integer>(links[4].size())); return ElementSet(this,ComposeHandleNum(4,lid)); }
3074 
3075  integer NodeNextLocalID (integer lid) const {++lid; while(lid < static_cast<integer>(links[0].size()) && links[0][lid] == -1) ++lid; return lid;}
3076  integer EdgeNextLocalID (integer lid) const {++lid; while(lid < static_cast<integer>(links[1].size()) && links[1][lid] == -1) ++lid; return lid;}
3077  integer FaceNextLocalID (integer lid) const {++lid; while(lid < static_cast<integer>(links[2].size()) && links[2][lid] == -1) ++lid; return lid;}
3078  integer CellNextLocalID (integer lid) const {++lid; while(lid < static_cast<integer>(links[3].size()) && links[3][lid] == -1) ++lid; return lid;}
3079  integer EsetNextLocalID (integer lid) const {++lid; while(lid < static_cast<integer>(links[4].size()) && links[4][lid] == -1) ++lid; return lid;}
3080 
3081  integer NodePrevLocalID (integer lid) const {--lid; while(lid >= 0 && links[0][lid] == -1) --lid; return lid;}
3082  integer EdgePrevLocalID (integer lid) const {--lid; while(lid >= 0 && links[1][lid] == -1) --lid; return lid;}
3083  integer FacePrevLocalID (integer lid) const {--lid; while(lid >= 0 && links[2][lid] == -1) --lid; return lid;}
3084  integer CellPrevLocalID (integer lid) const {--lid; while(lid >= 0 && links[3][lid] == -1) --lid; return lid;}
3085  integer EsetPrevLocalID (integer lid) const {--lid; while(lid >= 0 && links[4][lid] == -1) --lid; return lid;}
3086 
3087  __INLINE integer NodeLastLocalID () const {return static_cast<integer>(links[0].size());}
3088  __INLINE integer EdgeLastLocalID () const {return static_cast<integer>(links[1].size());}
3089  __INLINE integer FaceLastLocalID () const {return static_cast<integer>(links[2].size());}
3090  __INLINE integer CellLastLocalID () const {return static_cast<integer>(links[3].size());}
3091  __INLINE integer EsetLastLocalID () const {return static_cast<integer>(links[4].size());}
3092 
3093  integer LastLocalIDNum (integer n) const {assert(n >= 0 && n < 6); return n == 5 ? 1 : static_cast<integer>(links[n].size());}
3094 
3095  integer NextLocalID (ElementType etype, integer lid) const {integer q = ElementNum(etype); ++lid; while(lid < static_cast<integer>(links[q].size()) && links[q][lid] == -1) ++lid; return lid;}
3096  integer PrevLocalID (ElementType etype, integer lid) const {integer q = ElementNum(etype); --lid; while(lid > 0 && links[q][lid] == -1) --lid; return lid;}
3097  integer FirstLocalID (ElementType etype) const;
3098  integer LastLocalID (ElementType etype) const {assert(OneType(etype)); return LastLocalIDNum(ElementNum(etype));}
3099 
3100  integer NextLocalIDIter (ElementType etype, integer lid) const;
3101  integer PrevLocalIDIter (ElementType etype, integer lid) const;
3102  //integer FirstLocalIDIter (ElementType etype) const;
3103  //integer LastLocalIDIter (ElementType etype) const;
3104 
3105  integer LastLocalIDThr (ElementType etype) const;
3106  integer FirstLocalIDThr (ElementType etype) const;
3107 
3108  __INLINE integer NumberOfSets () const { return static_cast<integer>(links[4].size() - empty_links[4].size()) - hidden_count[4]; }
3109  __INLINE integer NumberOfCells () const { return static_cast<integer>(links[3].size() - empty_links[3].size()) - hidden_count[3];}
3110  __INLINE integer NumberOfFaces () const { return static_cast<integer>(links[2].size() - empty_links[2].size()) - hidden_count[2]; }
3111  __INLINE integer NumberOfEdges () const { return static_cast<integer>(links[1].size() - empty_links[1].size()) - hidden_count[1]; }
3112  __INLINE integer NumberOfNodes () const { return static_cast<integer>(links[0].size() - empty_links[0].size()) - hidden_count[0]; }
3113  __INLINE integer NumberOfElements () const { return NumberOfCells() + NumberOfFaces() + NumberOfEdges() + NumberOfNodes(); }
3114  __INLINE integer NumberOfAll () const { return NumberOfSets() + NumberOfElements(); }
3115  integer NumberOf (ElementType t) const;
3116 
3117  template<typename EType> class base_iterator;
3118  typedef base_iterator<Storage> iteratorStorage;
3119  typedef base_iterator<Element> iteratorElement;
3120  typedef base_iterator<ElementSet> iteratorSet;
3121  typedef base_iterator<Cell> iteratorCell;
3122  typedef base_iterator<Face> iteratorFace;
3123  typedef base_iterator<Edge> iteratorEdge;
3124  typedef base_iterator<Node> iteratorNode;
3126  iteratorStorage Begin (ElementType Types);
3127  iteratorStorage End ();
3128  iteratorElement BeginElement (ElementType Types);
3129  iteratorElement EndElement ();
3130  iteratorSet BeginSet ();
3131  iteratorSet EndSet ();
3132  iteratorCell BeginCell ();
3133  iteratorCell EndCell ();
3134  iteratorFace BeginFace ();
3135  iteratorFace EndFace ();
3136  iteratorEdge BeginEdge ();
3137  iteratorEdge EndEdge ();
3138  iteratorNode BeginNode ();
3139  iteratorNode EndNode ();
3140 
3141 
3142  template<typename EType>
3144  {
3145  protected:
3146  Mesh * m;
3147  Storage::integer lid;
3148  ElementType etype;
3149  ElementType types;
3150  base_iterator(ElementType Types, Mesh * mesh, bool last);
3151  base_iterator(Mesh * mesh) {m = mesh; etype = NONE; types = NONE; lid = -1;}
3152  public:
3153  typedef HandleType * pointer;
3154  typedef HandleType & reference;
3155  typedef HandleType value_type;
3156  typedef ptrdiff_t difference_type;
3157  typedef std::bidirectional_iterator_tag iterator_category;
3158  base_iterator() {m = NULL; lid = -1; etype = types = NONE;}
3159  base_iterator(const base_iterator & other) {m = other.m; lid = other.lid; types = other.types; etype = other.etype;}
3160  virtual ~base_iterator() {}
3161  base_iterator & operator ++();
3162  __INLINE base_iterator operator ++(int) {Mesh::base_iterator<EType> ret(*this); operator++(); return ret;}
3163  base_iterator & operator --();
3164  __INLINE base_iterator operator --(int) {Mesh::base_iterator<EType> ret(*this); operator--(); return ret;}
3165  __INLINE value_type operator * () {return ComposeHandle(etype,lid);}
3166  __INLINE EType operator ->() {return EType(m,ComposeHandle(etype,lid));}
3167  __INLINE base_iterator & operator = (base_iterator const & other) {m = other.m; lid = other.lid; types = other.types; etype = other.etype; return *this;}
3168  __INLINE bool operator ==(const base_iterator & other) const {return lid == other.lid && etype == other.etype;}
3169  __INLINE bool operator !=(const base_iterator & other) const {return lid != other.lid || etype != other.etype;}
3170  __INLINE bool operator < (const base_iterator & other) const {return (etype < other.etype) || (etype == other.etype && lid < other.lid);}
3171  __INLINE bool operator > (const base_iterator & other) const {return (etype > other.etype) || (etype == other.etype && lid > other.lid);}
3172  __INLINE bool operator <=(const base_iterator & other) const {return (etype < other.etype) || (etype == other.etype && lid <= other.lid);}
3173  __INLINE bool operator >=(const base_iterator & other) const {return (etype > other.etype) || (etype == other.etype && lid >= other.lid);}
3174  void Print();
3175  friend iteratorStorage Mesh::Begin(ElementType Types);
3176  friend iteratorStorage Mesh::End();
3177  friend iteratorElement Mesh::BeginElement(ElementType Types);
3178  friend iteratorElement Mesh::EndElement();
3179  friend iteratorSet Mesh::BeginSet();
3180  friend iteratorSet Mesh::EndSet();
3181  friend iteratorCell Mesh::BeginCell();
3182  friend iteratorCell Mesh::EndCell();
3183  friend iteratorFace Mesh::BeginFace();
3184  friend iteratorFace Mesh::EndFace();
3185  friend iteratorEdge Mesh::BeginEdge();
3186  friend iteratorEdge Mesh::EndEdge();
3187  friend iteratorNode Mesh::BeginNode();
3188  friend iteratorNode Mesh::EndNode();
3189  };
3190  private:
3191  std::vector< std::pair<std::string, std::string> > file_options;
3192  public:
3226  void SetFileOption(std::string,std::string);
3229  std::string GetFileOption(std::string key) const;
3233  std::set<std::string> TagOptions(std::string name) const;
3235  bool CheckLoadSkip(std::string name, const std::set<std::string> & noload, const std::set<std::string> & loadonly) const;
3237  bool CheckSaveSkip(std::string name, const std::set<std::string> & noload, const std::set<std::string> & loadonly) const;
3253  void Load(std::string File);
3254  void LoadMSH(std::string File);
3255  void LoadECL(std::string File);
3256  void LoadXML(std::string File);
3257  void LoadPMF(std::string File);
3258  void LoadVTK(std::string File);
3259  void LoadVTU(std::string File);
3260  void LoadPVTK(std::string File);
3261  void LoadPVTU(std::string File);
3262  void LoadMKF(std::string File);
3276  void Save(std::string File);
3277  void SaveXML(std::string File);
3278  void SavePMF(std::string File);
3279  void SaveVTK(std::string File);
3280  void SaveVTU(std::string File);
3281  void SavePVTK(std::string File);
3282  void SavePVTU(std::string File);
3283  void SaveGMV(std::string File);
3284  bool isParallelFileFormat(std::string File);
3285  public:
3286 
3287  //implemented in geometry.cpp
3288  private:
3289  Tag measure_tag;
3290  Tag centroid_tag;
3291  Tag normal_tag;
3292  Tag barycenter_tag;
3293  Tag boundary_tag;
3294  bool remember[5][3];
3295  private:
3296  void RestoreGeometricTags();
3297  public:
3298  void RepairGeometricTags();
3299  public:
3300  bool HideGeometricData(GeometricData type, ElementType mask) { remember[type][ElementNum(mask) - 1] = false; return remember[type][ElementNum(mask) - 1]; }
3301  bool ShowGeometricData(GeometricData type, ElementType mask) { remember[type][ElementNum(mask) - 1] = true; return remember[type][ElementNum(mask) - 1]; }
3302  public:
3303  typedef std::map<GeometricData, ElementType> GeomParam;
3304  // types for MEASURE: EDGE | FACE | CELL (length, area, volume)
3305  // types for CENTROID: EDGE | FACE | CELL
3306  // types for BARYCENTER: EDGE | FACE | CELL
3307  // types for NORMAL: FACE | CELL (may precompute normal for cells in 2d case)
3308  // types for ORIENTATION: FACE
3312  void FacesOrientation(const ElementArray<Face>& faces, MarkerType rev) { return FacesOrientation(faces.data(),(enumerator)faces.size(),rev); }
3313  void FacesOrientation(const HandleType * faces, enumerator size, MarkerType rev, bool check_convexity = true, enumerator start = 0);
3314  void CollectCentroidsNormals(const HandleType * faces, enumerator size, real* x, real* n);
3315  bool CheckConvexity(const real* x, const real* n, enumerator size) const;
3316  bool CheckConvexity(const ElementArray<Face>& faces) { return CheckConvexity(faces.data(),(enumerator)faces.size()); };
3317  bool CheckConvexity(const HandleType * faces, enumerator size);
3318  void PrepareGeometricData(GeomParam table);
3319  void RemoveGeometricData(GeomParam table);
3320  bool HaveGeometricData (GeometricData type, ElementType mask) const {return remember[type][ElementNum(mask)-1];} // requests to only one geometric and element type allowed
3321  void GetGeometricData (HandleType e, GeometricData type, real * ret);
3322  const Tag & GetGeometricTag (GeometricData type) const;
3323  bool TestClosure (const HandleType * elements, integer num) const;
3324  ElementArray<Face> GatherBoundaryFaces();
3325  ElementArray<Face> GatherInteriorFaces();
3326  integer CountBoundaryFaces ();
3327  integer CountInteriorFaces ();
3328  bool FixEdgeOrder(HandleType* edges, enumerator nedges) const;
3329  void RecomputeGeometricData(HandleType e); // Update all stored geometric data, runs automatically on element construction
3330  void RecomputeGeometricData(HandleType e, GeometricData d);
3331  Element::GeometricType ComputeGeometricType(ElementType element_type, const HandleType * lower_adjacent, INMOST_DATA_ENUM_TYPE lower_adjacent_size);
3332  void ComputeCentroid(Element e, TagRealArray coords, real * x) const;
3333  void ComputeBarycenter(Element e, TagRealArray coords, real * x) const;
3334  void ComputeNormal(Element e, TagRealArray coords, real * n) const;
3335  void ComputeMeasure(Element e, TagRealArray coords, real & m) const;
3336 #if defined(USE_AUTODIFF)
3337  void ComputeCentroid(Element e, TagVariableArray coords, variable * x) const;
3338  void ComputeBarycenter(Element e, TagVariableArray coords, variable * x) const;
3339  void ComputeNormal(Element e, TagVariableArray coords, variable * n) const;
3340  void ComputeMeasure(Element e, TagVariableArray coords, variable & m) const;
3341 #endif
3342 
3348  void WachspressInterpolation2D (const real * x, const Face & f, std::map<HandleType,real> & nodes_stencil) const;
3354  void WachspressInterpolation3D (const real * x, const Cell & c, std::map<HandleType,real> & nodes_stencil) const;
3357  void MarkBoundaryFaces(MarkerType boundary_marker);
3367  void MarkNormalOrientation(MarkerType mrk);
3368  //implemented in modify.cpp
3369  private:
3370  MarkerType hide_element, new_element, temp_hide_element;
3371  //MarkerType update_geometry;
3372  public:
3377  bool isMeshModified () const {return new_element != 0;}
3378  MarkerType HideMarker () const {return hide_element;}
3379  MarkerType NewMarker () const {return new_element;}
3380  //MarkerType UpdateGeometryMarker() const {return update_geometry;}
3381  void SwapModification (bool recompute_geometry); // swap hidden and new elements, so that old mesh is recovered
3382  void BeginModification (); //allow elements to be hidden
3395  void ApplyModification (); //modify DATA_REFERENCE, tags so that links to hidden elements are converted to NULL and removed from sets
3400  void ResolveModification(); //resolve parallel state of newly created elements, restore ghost layers; not implemented, reuse ResolveShared code
3401  void EndModification (); //delete hidden elements
3402  enumerator getNext (const HandleType * arr, enumerator size, enumerator k, MarkerType marker) const;
3403  enumerator Count (const HandleType * arr, enumerator size, MarkerType marker) const;
3404  void EquilibrateGhost ();//bool only_new = false); //Use in ResolveShared
3405  //void CheckFaces();
3408  void CheckCentroids (std::string file, int line);
3410  void CheckProcsSorted (std::string file, int line);
3413  void CheckGhostSharedCount(std::string file, int line, ElementType etype = ESET | CELL | FACE | EDGE | NODE);
3415  void CheckOwners (std::string file, int line);
3417  void CheckGIDs(std::string file, int line, ElementType mask = NODE | EDGE | FACE | CELL | ESET);
3421  void CheckSetLinks (std::string file, int line);
3426  static void CopyData(Element a, Element b);
3427  //implemented in mesh.cpp
3428  private:
3429  Tag tag_topologyerror;
3430  TopologyCheck checkset;
3431  TopologyCheck errorset;
3432  public:
3440  TopologyCheck BeginTopologyCheck (ElementType etype, const HandleType * adj, enumerator num);
3446  bool EndTopologyCheck (HandleType e, TopologyCheck begin_check); //check created element
3451  Tag TopologyErrorTag () const {return tag_topologyerror;}
3453  TopologyCheck GetTopologyCheck (TopologyCheck mask = ENUMUNDEF) const {return checkset & mask;}
3455  void SetTopologyCheck (TopologyCheck mask);
3457  void RemTopologyCheck (TopologyCheck mask);
3459  void SetTopologyError (TopologyCheck mask) {errorset = errorset | mask;}
3461  TopologyCheck GetTopologyError (TopologyCheck mask = ENUMUNDEF) const {return errorset & mask;}
3463  void ClearTopologyError (TopologyCheck mask = ENUMUNDEF) {errorset = errorset & ~mask;}
3464  //implemented in comparator.cpp
3465  public:
3467  {
3468  Mesh * m;
3469  public:
3470  CentroidComparator(Mesh * m) :m(m) {}
3471  CentroidComparator(const CentroidComparator & other) :m(other.m){}
3472  CentroidComparator & operator = (CentroidComparator const & other) { m = other.m; return *this;}
3473  int Compare(const real * a, const real * b) const;
3474  int Compare(HandleType a, HandleType b) const;
3475  bool operator() (HandleType a, HandleType b) const;
3476  bool operator() (HandleType a, const real * b) const;
3477  bool operator() (const real * a, HandleType b) const;
3478  };
3479 
3481  {
3482  Mesh * m;
3483  public:
3484  GlobalIDComparator(Mesh * m) :m(m) {}
3485  GlobalIDComparator(const GlobalIDComparator & other) :m(other.m){}
3486  GlobalIDComparator & operator = (GlobalIDComparator const & other) { m = other.m; return *this;}
3487  bool operator() (HandleType a, HandleType b) const {if( a == InvalidHandle() || b == InvalidHandle() ) return a > b; return m->GlobalID(a) < m->GlobalID(b);}
3488  bool operator() (HandleType a, integer gid) const {if( a == InvalidHandle() ) return false; return m->GlobalID(a) < gid;}
3489  };
3490 
3492  {
3493  Mesh * m;
3494  public:
3495  SetNameComparator(Mesh * m) :m(m) {}
3496  bool operator()(HandleType a, HandleType b) const
3497  {
3498  if( a == InvalidHandle() || b == InvalidHandle() ) return a > b;
3499  return ElementSet(m,a).GetName() < ElementSet(m,b).GetName();
3500  }
3501  int Compare(const std::string& a, const std::string& b) const;
3502  int Compare(HandleType a, HandleType b) const;
3503  };
3504 
3506  {
3507  Mesh * m;
3508  public:
3509  HierarchyComparator(Mesh * m) :m(m) {}
3510  HierarchyComparator(const HierarchyComparator & other) :m(other.m){}
3511  HierarchyComparator & operator = (HierarchyComparator const & other) { m = other.m; return *this;}
3512  int CompareNodes(HandleType a, HandleType b) const;
3513  int CompareElements(HandleType a, HandleType b) const;
3514  bool operator() (HandleType a, HandleType b) const {if( a == InvalidHandle() || b == InvalidHandle() ) return a > b; return CompareElements(a,b) < 0;}
3515  };
3516 
3518  {
3519  Mesh * m; Tag t;
3520  public:
3521  RealComparator(Mesh * m, Tag t) :m(m), t(t) {}
3522  RealComparator(const RealComparator & other) :m(other.m), t(other.t){}
3523  RealComparator & operator = (RealComparator const & other) { m = other.m; t = other.t; return *this;}
3524  bool operator() (HandleType a, HandleType b) const {if( a == InvalidHandle() || b == InvalidHandle() ) return a > b; return m->Real(a,t) < m->Real(b,t);}
3525  bool operator() (HandleType a, real b) const {if( a == InvalidHandle() ) return true; return m->Real(a,t) < b;}
3526  };
3527 
3529  {
3530  Mesh * m; Tag t;
3531  public:
3532  IntegerComparator(Mesh * m, Tag t) :m(m), t(t) {}
3533  IntegerComparator(const IntegerComparator & other) :m(other.m), t(other.t){}
3534  IntegerComparator & operator = (IntegerComparator const & other) { m = other.m; t = other.t; return *this;}
3535  bool operator() (HandleType a, HandleType b) const {if( a == InvalidHandle() || b == InvalidHandle() ) return a > b; return m->Integer(a,t) < m->Integer(b,t);}
3536  bool operator() (HandleType a, integer b) const {if( a == InvalidHandle() ) return true; return m->Integer(a,t) < b;}
3537  };
3538 
3540  {
3541  Mesh * m; Tag t;
3542  public:
3543  BulkComparator(Mesh * m, Tag t) :m(m), t(t) {}
3544  BulkComparator(const BulkComparator & other) :m(other.m), t(other.t){}
3545  BulkComparator & operator = (BulkComparator const & other) { m = other.m; t = other.t; return *this;}
3546  bool operator() (HandleType a, HandleType b) const {if( a == InvalidHandle() || b == InvalidHandle() ) return a > b; return m->Bulk(a,t) < m->Bulk(b,t);}
3547  bool operator() (HandleType a, bulk b) const {if( a == InvalidHandle() ) return true; return m->Bulk(a,t) < b;}
3548  };
3549 
3551  {
3552  Mesh * m; Tag t;
3553  public:
3554  RealDFComparator(Mesh * m, Tag t) :m(m), t(t) {}
3555  RealDFComparator(const RealDFComparator & other) :m(other.m), t(other.t){}
3556  RealDFComparator & operator = (RealDFComparator const & other) { m = other.m; t = other.t; return *this;}
3557  bool operator() (HandleType a, HandleType b) const {if( a == InvalidHandle() || b == InvalidHandle() ) return a > b; return m->RealDF(a,t) < m->RealDF(b,t);}
3558  bool operator() (HandleType a, real b) const {if( a == InvalidHandle() ) return true; return m->RealDF(a,t) < b;}
3559  };
3560 
3562  {
3563  Mesh * m; Tag t;
3564  public:
3565  IntegerDFComparator(Mesh * m, Tag t) :m(m), t(t) {}
3566  IntegerDFComparator(const IntegerDFComparator & other) :m(other.m), t(other.t){}
3567  IntegerDFComparator & operator = (IntegerDFComparator const & other) { m = other.m; t = other.t; return *this;}
3568  bool operator() (HandleType a, HandleType b) const {if( a == InvalidHandle() || b == InvalidHandle() ) return a > b; return m->IntegerDF(a,t) < m->IntegerDF(b,t);}
3569  bool operator() (HandleType a, integer b) const {if( a == InvalidHandle() ) return true; return m->IntegerDF(a,t) < b;}
3570  };
3571 
3573  {
3574  Mesh * m; Tag t;
3575  public:
3576  BulkDFComparator(Mesh * m, Tag t) :m(m), t(t) {}
3577  BulkDFComparator(const BulkDFComparator & other) :m(other.m), t(other.t){}
3578  BulkDFComparator & operator = (BulkDFComparator const & other) { m = other.m; t = other.t; return *this;}
3579  bool operator() (HandleType a, HandleType b) const {if( a == InvalidHandle() || b == InvalidHandle() ) return a > b; return m->BulkDF(a,t) < m->BulkDF(b,t);}
3580  bool operator() (HandleType a, bulk b) const {if( a == InvalidHandle() ) return true; return m->BulkDF(a,t) < b;}
3581  };
3582 
3584  {
3585  Mesh * m;
3586  public:
3587  MeasureComparator(Mesh * m) :m(m) {}
3588  MeasureComparator(const MeasureComparator & other) :m(other.m) {}
3589  MeasureComparator & operator = (MeasureComparator const & other) { m = other.m; return *this;}
3590  bool operator() (HandleType a, HandleType b) const
3591  {
3592  if( a == InvalidHandle() || b == InvalidHandle() )
3593  return a > b;
3594  INMOST_DATA_REAL_TYPE ma, mb;
3595  m->GetGeometricData(a,MEASURE,&ma);
3596  m->GetGeometricData(b,MEASURE,&mb);
3597  return ma < mb;
3598  }
3599  bool operator() (HandleType a, bulk b) const
3600  {
3601  if( a == InvalidHandle() )
3602  return true;
3603  INMOST_DATA_REAL_TYPE ma;
3604  m->GetGeometricData(a,MEASURE,&ma);
3605  return ma < b;
3606  }
3607  };
3608 
3610  {
3611  Mesh * m; MarkerType mrk; bool inverse;
3612  public:
3613  MarkerComparator(Mesh * m, MarkerType mrk, bool inverse = false) :m(m), mrk(mrk), inverse(inverse) {assert(!isPrivate(mrk));}
3614  MarkerComparator(const MarkerComparator & other) :m(other.m), mrk(other.mrk), inverse(other.inverse){}
3615  MarkerComparator & operator = (MarkerComparator const & other) { m = other.m; mrk = other.mrk; inverse = other.inverse; return *this;}
3616  bool operator() (HandleType a, HandleType b) const {if( a == InvalidHandle() || b == InvalidHandle() ) return a > b; return ((inverse ^ m->GetMarker(a,mrk))? 1 : 0) < ((inverse ^ m->GetMarker(b,mrk)) ? 1 : 0);}
3617  bool operator() (HandleType a, bool b) const {if( a == InvalidHandle() ) return true; return ((inverse ^ m->GetMarker(a,mrk))? 1 : 0) < (b ? 1 : 0);}
3618  };
3619 
3621  {
3622  Mesh * m; MarkerType mrk; bool inverse;
3623  public:
3624  PrivateMarkerComparator(Mesh * m, MarkerType mrk, bool inverse = false) :m(m), mrk(mrk), inverse(inverse) {assert(isPrivate(mrk));}
3625  PrivateMarkerComparator(const PrivateMarkerComparator & other) :m(other.m), mrk(other.mrk), inverse(other.inverse){}
3626  PrivateMarkerComparator & operator = (PrivateMarkerComparator const & other) { m = other.m; mrk = other.mrk; inverse = other.inverse; return *this;}
3627  bool operator() (HandleType a, HandleType b) const {if( a == InvalidHandle() || b == InvalidHandle() ) return a > b; return ((inverse ^ m->GetPrivateMarker(a,mrk))? 1 : 0) < ((inverse ^ m->GetPrivateMarker(b,mrk))? 1 : 0);}
3628  bool operator() (HandleType a, bool b) const {if( a == InvalidHandle() ) return true; return ((inverse ^ m->GetPrivateMarker(a,mrk))? 1 : 0) < (b ? 1 : 0);}
3629  };
3630 
3631 
3632  void SortHandles(HandleType * h, enumerator num);
3635  void SortByGlobalID(HandleType * h, enumerator num);
3636 
3638  std::string GetMeshName();
3640  void SetMeshName(std::string new_name);
3642  static Mesh * GetMesh(std::string name);
3643  };
3644 
3645 
3646 
3647 
3651 
3653  {
3654  public:
3655 
3656  inline static bool cell_point(const Cell & c, const Storage::real p[3]) {return c.Inside(p);}
3657  inline static bool cell_point_print(const Cell& c, const Storage::real p[3], std::ostream & sout) { return c.InsidePrint(p,sout); }
3658  template<typename bbox_type>
3659  inline static int bbox_point(const Storage::real p[3], const bbox_type bbox[6]);
3660  template<typename bbox_type>
3661  inline static int bbox_point_print(const Storage::real p[3], const bbox_type bbox[6], std::ostream& sout = std::cout);
3662  template<typename bbox_type>
3663  inline static void bbox_closest_point(const Storage::real p[3], const bbox_type bbox[6], Storage::real pout[3]);
3664  template<typename bbox_type>
3665  inline static int bbox_sphere(const Storage::real p[3], Storage::real r, const bbox_type bbox[6]);
3666  inline static Storage::real segment_distance(const Storage::real x1[3], const Storage::real x2[3], const Storage::real p[3]);
3667  inline static Storage::real triangle_distance(const Storage::real x1[3], const Storage::real x2[3], const Storage::real x3[3], const Storage::real p[3]);
3668  private:
3669  struct entry
3670  {
3671  HandleType e;
3672  float xyz[3];
3673  struct entry & operator =(const struct entry & other)
3674  {
3675  e = other.e;
3676  xyz[0] = other.xyz[0];
3677  xyz[1] = other.xyz[1];
3678  xyz[2] = other.xyz[2];
3679  return *this;
3680  }
3681  } * set;
3682  Mesh * m;
3683  INMOST_DATA_ENUM_TYPE size;
3684  float bbox[6];
3685  SearchKDTree * children;
3686  static int cmpElements0(const void * a,const void * b);
3687  static int cmpElements1(const void * a,const void * b);
3688  static int cmpElements2(const void * a,const void * b);
3689  inline static unsigned int flip(const unsigned int * fp);
3690  void radix_sort(int dim, struct entry * temp);
3691  void kdtree_build(int dim, int & done, int total, struct entry * temp);
3692  SearchKDTree() : set(NULL), m(NULL), size(0), bbox(), children(NULL) {}
3693 
3694  Cell SubSearchCell(const Storage::real p[3]) const;
3695  Cell SubSearchCellPrint(const Storage::real p[3], std::ostream & sout) const;
3696  void clear_children();
3697 
3698  inline int ray_bbox(double pos[3], double ray[3], double closest) const;
3699  inline int sphere_bbox(const Storage::real p[3], Storage::real r) const;
3700  inline int segment_bbox(const Storage::real p1[3], const Storage::real p2[3]) const;
3701  inline int segment_tri(const Storage::real tri[3][3], const Storage::real p1[3], const Storage::real p2[3]) const;
3702  inline int segment_tri_print(const Storage::real tri[3][3], const Storage::real p1[3], const Storage::real p2[3], std::ostream & sout) const;
3703  inline bool segment_face(const Element & f, const Storage::real p1[3], const Storage::real p2[3]) const;
3704  inline bool segment_face_print(const Element& f, const Storage::real p1[3], const Storage::real p2[3], std::ostream& sout) const;
3705  inline bool segment_cell(const Element & c, const Storage::real p1[3], const Storage::real p2[3]) const;
3706  inline int sphere_tri(const Storage::real tri[3][3], const Storage::real p[3], Storage::real r) const;
3707  inline bool sphere_face(const Element& f, const Storage::real p[3], Storage::real r) const;
3708  inline bool sphere_cell(const Element& c, const Storage::real p[3], Storage::real r) const;
3709  void sub_intersect_segment(ElementArray<Element> & hits, MarkerType mrk, const Storage::real p1[3], const Storage::real p2[3]) const;
3710  void sub_intersect_segment_print(ElementArray<Element>& hits, MarkerType mrk, const Storage::real p1[3], const Storage::real p2[3], std::ostream & sout) const;
3711  void sub_intersect_sphere(ElementArray<Element>& hits, MarkerType mrk, const Storage::real p[3], Storage::real r) const;
3712  public:
3713  SearchKDTree(Mesh * m);
3714  SearchKDTree(Mesh * m, HandleType * _set, unsigned set_size);
3715  ~SearchKDTree();
3716  Cell SearchCell(const Storage::real * point) const;
3717  Cell SearchCellPrint(const Storage::real* point, std::ostream & sout = std::cout) const;
3718  void IntersectSphere(ElementArray<Cell>& cells, const Storage::real p[3], Storage::real r) const;
3719  void IntersectSphere(ElementArray<Face>& faces, const Storage::real p[3], Storage::real r) const;
3720  void IntersectSegment(ElementArray<Cell>& cells, const Storage::real p1[3], const Storage::real p2[3]) const;
3721  void IntersectSegment(ElementArray<Face>& faces, const Storage::real p1[3], const Storage::real p2[3]) const;
3722  void IntersectSegmentPrint(ElementArray<Face>& faces, const Storage::real p1[3], const Storage::real p2[3], std::ostream& sout) const;
3723  };
3724 
3725 
3729  __INLINE Storage::real & Storage::Real(const Tag & tag) const
3730  {
3731  return GetMeshLink()->Real(GetHandle(),tag);
3732  }
3733  __INLINE Storage::integer & Storage::Integer(const Tag & tag) const
3734  {
3735  return GetMeshLink()->Integer(GetHandle(),tag);
3736  }
3737  __INLINE Storage::bulk & Storage::Bulk(const Tag & tag) const
3738  {
3739  return GetMeshLink()->Bulk(GetHandle(),tag);
3740  }
3741  __INLINE Storage::reference & Storage::Reference(const Tag & tag) const
3742  {
3743  return GetMeshLink()->Reference(GetHandle(),tag);
3744  }
3746  {
3747  return GetMeshLink()->RemoteReference(GetHandle(),tag);
3748  }
3749  __INLINE Storage::real_array Storage::RealArray(const Tag & tag) const
3750  {
3751  return GetMeshLink()->RealArray(GetHandle(),tag);
3752  }
3754  {
3755  return GetMeshLink()->IntegerArray(GetHandle(),tag);
3756  }
3757  __INLINE Storage::bulk_array Storage::BulkArray(const Tag & tag) const
3758  {
3759  return GetMeshLink()->BulkArray(GetHandle(),tag);
3760  }
3762  {
3763  return GetMeshLink()->ReferenceArray(GetHandle(),tag);
3764  }
3766  {
3767  return GetMeshLink()->RemoteReferenceArray(GetHandle(),tag);
3768  }
3769  __INLINE Storage::real_array Storage::RealArrayDF(const Tag & tag) const
3770  {
3771  return GetMeshLink()->RealArrayDF(GetHandle(),tag);
3772  }
3773  __INLINE Storage::integer_array Storage::IntegerArrayDF(const Tag & tag) const
3774  {
3775  return GetMeshLink()->IntegerArrayDF(GetHandle(),tag);
3776  }
3777  __INLINE Storage::bulk_array Storage::BulkArrayDF(const Tag & tag) const
3778  {
3779  return GetMeshLink()->BulkArrayDF(GetHandle(),tag);
3780  }
3781  __INLINE Storage::reference_array Storage::ReferenceArrayDF(const Tag & tag) const
3782  {
3783  return GetMeshLink()->ReferenceArrayDF(GetHandle(),tag);
3784  }
3785  __INLINE Storage::remote_reference_array Storage::RemoteReferenceArrayDF(const Tag & tag) const
3786  {
3787  return GetMeshLink()->RemoteReferenceArrayDF(GetHandle(),tag);
3788  }
3789  __INLINE Storage::real & Storage::RealDF(const Tag & tag) const
3790  {
3791  return GetMeshLink()->RealDF(GetHandle(),tag);
3792  }
3793  __INLINE Storage::integer & Storage::IntegerDF(const Tag & tag) const
3794  {
3795  return GetMeshLink()->IntegerDF(GetHandle(),tag);
3796  }
3797  __INLINE Storage::bulk & Storage::BulkDF(const Tag & tag) const
3798  {
3799  return GetMeshLink()->BulkDF(GetHandle(),tag);
3800  }
3801  __INLINE Storage::reference & Storage::ReferenceDF(const Tag & tag) const
3802  {
3803  return GetMeshLink()->ReferenceDF(GetHandle(),tag);
3804  }
3805  __INLINE Storage::remote_reference & Storage::RemoteReferenceDF(const Tag & tag) const
3806  {
3807  return GetMeshLink()->RemoteReferenceDF(GetHandle(),tag);
3808  }
3809  __INLINE Storage::real_array Storage::RealArrayDV(const Tag & tag) const
3810  {
3811  return GetMeshLink()->RealArrayDV(GetHandle(),tag);
3812  }
3813  __INLINE Storage::integer_array Storage::IntegerArrayDV(const Tag & tag) const
3814  {
3815  return GetMeshLink()->IntegerArrayDV(GetHandle(),tag);
3816  }
3817  __INLINE Storage::bulk_array Storage::BulkArrayDV(const Tag & tag) const
3818  {
3819  return GetMeshLink()->BulkArrayDV(GetHandle(),tag);
3820  }
3821  __INLINE Storage::reference_array Storage::ReferenceArrayDV(const Tag & tag) const
3822  {
3823  return GetMeshLink()->ReferenceArrayDV(GetHandle(),tag);
3824  }
3825  __INLINE Storage::remote_reference_array Storage::RemoteReferenceArrayDV(const Tag & tag) const
3826  {
3827  return GetMeshLink()->RemoteReferenceArrayDV(GetHandle(),tag);
3828  }
3829  __INLINE Storage::real & Storage::RealDV(const Tag & tag) const
3830  {
3831  return GetMeshLink()->RealDV(GetHandle(),tag);
3832  }
3833  __INLINE Storage::integer & Storage::IntegerDV(const Tag & tag) const
3834  {
3835  return GetMeshLink()->IntegerDV(GetHandle(),tag);
3836  }
3837  __INLINE Storage::bulk & Storage::BulkDV(const Tag & tag) const
3838  {
3839  return GetMeshLink()->BulkDV(GetHandle(),tag);
3840  }
3841  __INLINE Storage::reference & Storage::ReferenceDV(const Tag & tag) const
3842  {
3843  return GetMeshLink()->ReferenceDV(GetHandle(),tag);
3844  }
3845  __INLINE Storage::remote_reference & Storage::RemoteReferenceDV(const Tag & tag) const
3846  {
3847  return GetMeshLink()->RemoteReferenceDV(GetHandle(),tag);
3848  }
3849  __INLINE Storage::real & TagReal::operator [](HandleType h) const
3850  {
3851  return GetMeshLink()->Real(h,*static_cast<const Tag*>(this));
3852  }
3853  __INLINE Storage::integer & TagInteger::operator [](HandleType h) const
3854  {
3855  return GetMeshLink()->Integer(h,*static_cast<const Tag*>(this));
3856  }
3857  __INLINE Storage::bulk & TagBulk::operator [](HandleType h) const
3858  {
3859  return GetMeshLink()->Bulk(h,*static_cast<const Tag*>(this));
3860  }
3861  __INLINE Storage::reference & TagReference::operator [](HandleType h) const
3862  {
3863  return GetMeshLink()->Reference(h,*static_cast<const Tag*>(this));
3864  }
3865  __INLINE Storage::real_array TagRealArray::operator [](HandleType h) const
3866  {
3867  return GetMeshLink()->RealArray(h,*static_cast<const Tag*>(this));
3868  }
3869  __INLINE Matrix<Storage::real,Storage::real_array> TagRealArray::operator ()(HandleType h, int n, int m) const
3870  {
3871  Storage::real_array data = GetMeshLink()->RealArray(h,*static_cast<const Tag*>(this));
3872  assert((int)data.size() == n*m);
3873  return Matrix<Storage::real,Storage::real_array>(data,n,m);
3874  }
3875  __INLINE Storage::integer_array TagIntegerArray::operator [](HandleType h) const
3876  {
3877  return GetMeshLink()->IntegerArray(h,*static_cast<const Tag*>(this));
3878  }
3879  __INLINE Storage::bulk_array TagBulkArray::operator [](HandleType h) const
3880  {
3881  return GetMeshLink()->BulkArray(h,*static_cast<const Tag*>(this));
3882  }
3883  __INLINE Storage::reference_array TagReferenceArray::operator [](HandleType h) const
3884  {
3885  return GetMeshLink()->ReferenceArray(h,*static_cast<const Tag*>(this));
3886  }
3887 #if defined(USE_AUTODIFF)
3888  __INLINE Storage::var & Storage::Variable(const Tag & tag) const
3889  {
3890  return GetMeshLink()->Variable(GetHandle(),tag);
3891  }
3892  __INLINE Storage::var & Storage::VariableDF(const Tag & tag) const
3893  {
3894  return GetMeshLink()->VariableDF(GetHandle(),tag);
3895  }
3896  __INLINE Storage::var & Storage::VariableDV(const Tag & tag) const
3897  {
3898  return GetMeshLink()->VariableDV(GetHandle(),tag);
3899  }
3900  __INLINE Storage::var_array Storage::VariableArray(const Tag & tag) const
3901  {
3902  return GetMeshLink()->VariableArray(GetHandle(),tag);
3903  }
3904  __INLINE Storage::var_array Storage::VariableArrayDF(const Tag & tag) const
3905  {
3906  return GetMeshLink()->VariableArrayDF(GetHandle(),tag);
3907  }
3908  __INLINE Storage::var_array Storage::VariableArrayDV(const Tag & tag) const
3909  {
3910  return GetMeshLink()->VariableArrayDV(GetHandle(),tag);
3911  }
3912  __INLINE Storage::var & TagVariable::operator [](HandleType h) const
3913  {
3914  return GetMeshLink()->Variable(h,*static_cast<const Tag*>(this));
3915  }
3916  __INLINE Storage::var_array TagVariableArray::operator [](HandleType h) const
3917  {
3918  return GetMeshLink()->VariableArray(h,*static_cast<const Tag*>(this));
3919  }
3920  __INLINE Matrix<Storage::var,Storage::var_array> TagVariableArray::operator ()(HandleType h, int n, int m) const
3921  {
3922  Storage::var_array data = GetMeshLink()->VariableArray(h,*static_cast<const Tag*>(this));
3923  assert((int)data.size() == n*m);
3924  return Matrix<Storage::var,Storage::var_array>(data,n,m);
3925  }
3926 
3927 #endif
3928  __INLINE bool Storage::HaveData(const Tag & tag) const
3929  {
3930  assert(isValid());
3931  return GetMeshLink()->HaveData(GetHandle(),tag);
3932  }
3933  __INLINE INMOST_DATA_ENUM_TYPE Storage::GetDataSize(const Tag & tag) const
3934  {
3935  return GetMeshLink()->GetDataSize(GetHandle(),tag);
3936  }
3937  __INLINE INMOST_DATA_ENUM_TYPE Storage::GetDataCapacity(const Tag & tag) const
3938  {
3939  return GetMeshLink()->GetDataCapacity(GetHandle(),tag);
3940  }
3941  __INLINE void Storage::SetDataSize(const Tag & tag,INMOST_DATA_ENUM_TYPE new_size) const
3942  {
3943  GetMeshLink()->SetDataSize(GetHandle(),tag,new_size);
3944  }
3945  __INLINE ElementType Storage::GetElementType() const
3946  {
3947  return GetHandleElementType(handle);
3948  }
3949  __INLINE Storage::integer Storage::GetElementNum () const
3950  {
3951  return GetHandleElementNum(handle);
3952  }
3953  __INLINE void Storage::GetData(const Tag & tag,INMOST_DATA_ENUM_TYPE shift, INMOST_DATA_ENUM_TYPE size, void * data_out) const
3954  {
3955  GetMeshLink()->GetData(GetHandle(),tag,shift,size,data_out);
3956  }
3957  __INLINE void Storage::SetData(const Tag & tag,INMOST_DATA_ENUM_TYPE shift, INMOST_DATA_ENUM_TYPE size, const void * data_in) const
3958  {
3959  GetMeshLink()->SetData(GetHandle(),tag,shift,size,data_in);
3960  }
3961  __INLINE void Storage::DelData(const Tag & tag) const
3962  {
3963  GetMeshLink()->DelData(GetHandle(),tag);
3964  }
3965  __INLINE void Storage::DelDenseData(const Tag & tag) const
3966  {
3967  GetMeshLink()->DelDenseData(GetHandle(),tag);
3968  }
3969  __INLINE bool Storage::DelSparseData(const Tag & tag) const
3970  {
3971  return GetMeshLink()->DelSparseData(GetHandle(),tag);
3972  }
3973  __INLINE void Storage::SetMarker(MarkerType n) const
3974  {
3975  assert( isValid() );
3976  GetMeshLink()->SetMarker(GetHandle(),n);
3977  }
3978  __INLINE bool Storage::GetMarker(MarkerType n) const
3979  {
3980  assert( isValid() );
3981  return GetMeshLink()->GetMarker(GetHandle(),n);
3982  }
3983  __INLINE void Storage::RemMarker(MarkerType n) const
3984  {
3985  assert( isValid() );
3986  GetMeshLink()->RemMarker(GetHandle(),n);
3987  }
3988  __INLINE void Storage::SetPrivateMarker(MarkerType n) const
3989  {
3990  assert( isValid() );
3991  GetMeshLink()->SetPrivateMarker(GetHandle(),n);
3992  }
3993  __INLINE bool Storage::GetPrivateMarker(MarkerType n) const
3994  {
3995  assert( isValid() );
3996  return GetMeshLink()->GetPrivateMarker(GetHandle(),n);
3997  }
3998  __INLINE void Storage::RemPrivateMarker(MarkerType n) const
3999  {
4000  assert( isValid() );
4001  GetMeshLink()->RemPrivateMarker(GetHandle(),n);
4002  }
4003  __INLINE void Storage::ClearMarkerSpace() const
4004  {
4005  GetMeshLink()->ClearMarkerSpace(GetHandle());
4006  }
4007  __INLINE void Storage::GetMarkerSpace(Storage::bulk copy[MarkerFields]) const
4008  {
4009  GetMeshLink()->GetMarkerSpace(GetHandle(),copy);
4010  }
4011  __INLINE void Storage::SetMarkerSpace(Storage::bulk source[MarkerFields]) const
4012  {
4013  GetMeshLink()->SetMarkerSpace(GetHandle(),source);
4014  }
4015  __INLINE bool Storage::isValid() const
4016  {
4017  return handle != InvalidHandle() && GetMeshLink() != NULL && GetMeshLink()->isValidElement(handle);
4018  }
4019  __INLINE Storage::integer Storage::LocalID() const
4020  {
4021  return GetHandleID(handle);
4022  }
4024  {
4025  return GetMeshLink()->DataLocalID(GetHandle());
4026  }
4027  __INLINE Element Storage::getAsElement() const
4028  {
4029  assert(GetElementType() & (NODE | EDGE | FACE | CELL | ESET) );
4030  return Element(GetMeshLink(), GetHandle());
4031  }
4032  __INLINE Node Storage::getAsNode() const
4033  {
4034  assert(GetElementType() == NODE);
4035  return Node(GetMeshLink(),GetHandle());
4036  }
4037  __INLINE Edge Storage::getAsEdge() const
4038  {
4039  assert(GetElementType() == EDGE);
4040  return Edge(GetMeshLink(),GetHandle());
4041  }
4042  __INLINE Face Storage::getAsFace() const
4043  {
4044  assert(GetElementType() == FACE);
4045  return Face(GetMeshLink(),GetHandle());
4046  }
4047  __INLINE Cell Storage::getAsCell() const
4048  {
4049  assert(GetElementType() == CELL);
4050  return Cell(GetMeshLink(),GetHandle());
4051  }
4052  __INLINE ElementSet Storage::getAsSet() const
4053  {
4054  assert(GetElementType() == ESET);
4055  return ElementSet(GetMeshLink(),GetHandle());
4056  }
4057  __INLINE Mesh * Storage::GetMeshLink() const
4058  {
4059  return m_link;
4060  }
4061  __INLINE HandleType Storage::GetHandle() const
4062  {
4063  return handle;
4064  }
4065 
4066 
4067 
4068 }
4069 
4070  //Implementation of inlined functions
4071 //#include "../Data/storage_inline.hpp"
4072 
4073 #endif
4074 
4075 #endif // INMOST_MESH_H_INCLUDED
An interface for elements of type CELL.
Definition: inmost_mesh.h:689
bool Inside(const real *point) const
Determine, if point lies inside element.
void SwapBackCell() const
For each adjacent cell make me a front cell and fix normal orientation accordingly.
bool FixEdgeOrder() const
Repair the sequence of edges so that each edge have node that matches one of the nodes at the next ed...
Cell(const Cell &other)
Copy constructor.
Definition: inmost_mesh.h:718
Cell(Mesh *m, HandleType *h)
Basic constructor with an assignable handle.
Definition: inmost_mesh.h:712
Cell & operator=(Cell const &other)
Assignment operator.
Definition: inmost_mesh.h:727
ElementArray< Node > getNodes() const
Get all the nodes of the current cell.
Cell()
Basic constructor.
Definition: inmost_mesh.h:694
Cell * operator->()
Operator of dereference to pointer.
Definition: inmost_mesh.h:733
ElementArray< Edge > getEdges(MarkerType mask, bool invert_mask=false) const
Get the subset of the edges of the current cell that are (not) marked by provided marker.
ElementArray< Face > getFaces() const
Get all the faces of the current cell.
Cell Neighbour(Face face) const
Get a cell that share a face with the current cell.
Cell(Mesh *m, HandleType h)
Basic constructor with fixed handle.
Definition: inmost_mesh.h:701
ElementArray< Cell > NeighbouringCells() const
Get all cells that share the face with the current cell.
static bool TestUniteCells(const ElementArray< Cell > &cells, MarkerType del_protect)
Test that no marked element will be deleted during union of given cells.
real Volume() const
Return volume of the cell.
static Cell UniteCells(const ElementArray< Cell > &cells, MarkerType del_protect)
Unite a set of given cells into one cell.
bool CheckEdgeOrder() const
Check that sequence of edges form a closed loop and each edge have a node that matches one of the nod...
ElementArray< Face > getFaces(MarkerType mask, bool invert_mask=false) const
Get the subset of the faces of the current cell that are (not) marked by provided marker.
ElementArray< Edge > getEdges() const
Get all the edges of the current cell.
static bool TestSplitCell(Cell cell, const ElementArray< Face > &faces, MarkerType del_protect)
This functions checks is it possible to split the cell by the given set of faces without deleting mar...
ElementArray< Node > getNodes(MarkerType mask, bool invert_mask=false) const
Get the subset of the nodes of the current cell that are (not) marked by provided marker.
static ElementArray< Cell > SplitCell(Cell cell, const ElementArray< Face > &faces, MarkerType del_protect)
Separate a cell according to the set of provided faces.
bool Closure() const
Test that faces of the cell form the closed set.
ElementArray< Node > getNodes() const
Retrieve all the nodes of the element.
void SwapEnds()
Swap positions of first node and last node.
ElementArray< Face > getFaces() const
Retrieve all the faces of the element.
ElementArray< Cell > getCells() const
Return all the cells of the element.
iterator Begin() const
Provides forward iterator that skips deleted and hidden elements within set.
void SynchronizeSetElements()
Asks all the elements to be sent to other processors.
void PutElements(const ElementSet &other) const
Put multiple handles of the other set without checking of the existence of duplicate.
Definition: inmost_mesh.h:1072
void RemMarkerElements(MarkerType m, ElementType etype=ESET|CELL|FACE|EDGE|NODE) const
Remove markers from all the elements of given type.
void RemChild(const ElementSet &child) const
This will erase my child.
bool DeleteSet()
Remove the set and resolve it's hierarchical structure.
ElementArray< Cell > getCells() const
Retrieve only cells.
std::string GetName() const
Get name of the set.
void SetMarkerElements(MarkerType m, ElementType etype=ESET|CELL|FACE|EDGE|NODE) const
Set markers on all the elements of given type.
void Intersect(const ElementSet &other) const
Compute and store intersection with raw handles.
void Subtract(const ElementSet &other) const
Compute and store difference with raw handles.
ElementArray< Element > Intersection(const HandleType *handles, enumerator num) const
Compute and return intersection with raw handles.
void AddElements(const HandleType *handles, enumerator num) const
Add multiple elements with checking of the existence of duplicate.
void Unite(const HandleType *handles, enumerator num) const
Compute and store union with raw handles.
static const enumerator high_conn_reserved
Number of reserved positions in HighConn array.
Definition: inmost_mesh.h:969
void RemSibling(const ElementSet &sibling) const
This will erase sibling or parent's child.
ElementArray< Element > Union(const ElementSet &other) const
Compute and return union with other set.
enumerator Size() const
Get total number of elements.
void ReorderEmpty() const
Retrieve current set exchange type.
ElementArray< Element > Intersection(const ElementArray< EType > &elems) const
Compute and return intersection with elements.
Definition: inmost_mesh.h:1129
ElementArray< Node > getNodes() const
Retrieve only nodes.
void Intersect(const HandleType *handles, enumerator num) const
Compute and store intersection with raw handles.
void AddElements(const ElementArray< EType > &elems) const
Add multiple elements with checking of the existence of duplicate.
Definition: inmost_mesh.h:1093
void RemoveElements(const ElementArray< EType > &elems) const
Remove multiple elements from the set.
Definition: inmost_mesh.h:1099
void PutElements(const ElementArray< EType > &elems) const
Put multiple handles without checking.
Definition: inmost_mesh.h:1075
void AddChild(const ElementSet &child) const
Add child to current set.
iterator Erase(iterator pos) const
Erase one element pointed by iterator and return next valid element.
ElementArray< Edge > getEdges() const
Retrieve only edges.
ElementArray< Element > getAdjElements(ElementType etype, MarkerType select, bool invert=false) const
Retrieve unordered array of adjacent elements with marker.
enumerator nbAdjElements(ElementType etype, MarkerType select, bool invert=false) const
Retrieve number of adjacent elements with marker.
void AddSibling(const ElementSet &sibling) const
This will create new child for the parent.
HandleType * getHandles() const
Direct raw access to stored elements, no copy involved.
ElementArray< Element > getAdjElements(ElementType etype) const
Retrieve all elements by type.
ElementArray< Element > Union(const HandleType *handles, enumerator num) const
Compute and return union with raw handles.
Element FindElementByGlobalID(integer global_id) const
Sets the synchronization regime for set elements.
enumerator nbHandles() const
Retrieve number of stored handles, including invalid.
void Erase(iterator beg, iterator end) const
Erase set of elements pointed by iterators.
void SortSet(ComparatorType comp) const
Performs sort of the set of elements.
void Unite(const ElementArray< EType > &elems) const
Compute and store union with elements.
Definition: inmost_mesh.h:1137
void PutElement(HandleType e) const
Put one element without checking of the existence of duplicate.
void PutElement(const Storage &e) const
Put one element without checking of the existence of duplicate.
Definition: inmost_mesh.h:1068
void Intersect(const ElementArray< EType > &elems) const
Compute and store intersection with elements.
Definition: inmost_mesh.h:1158
ComparatorType GetComparator() const
Retrieve current set comparator.
ElementArray< Element > Union(const ElementArray< EType > &elems) const
Compute and return union with elements.
Definition: inmost_mesh.h:1111
ElementSet GetParent() const
Retrieve parent of the set.
Element FindElementByCentroid(real *centroid) const
Perform binary search by centroid.
enumerator nbAdjElements(ElementType etype) const
Retrieve all elements by type.
enumerator nbSorted() const
Retrieve position after last sorted element.
void SynchronizeSetChildren()
Asks all the children to be sent to other processors.
enumerator CountChildren() const
How many children I have.
void PutElements(const HandleType *handles, enumerator num) const
Put multiple handles without checking of the existence of duplicate.
ElementSet GetChild() const
Retrieve child set of the set.
bool Empty() const
Is there any elements in the set.
void SynchronizeSetParents()
Asks all the parents upwards to be sent to other processors.
bool FindHandle(HandleType h, bool use_comparator) const
Performs linear search in unsorted set.
enumerator CountSiblings() const
How many there are siblings to the right of me including me.
iterator End() const
Provides end for forward iterator to stop the loop.
bool DeleteSetTree()
Remove the set and all it's children.
void AddElement(HandleType e) const
Put one element with checking of the existence of duplicate.
void AddElement(const Storage &e) const
Put one element with checking of the existence of duplicate.
Definition: inmost_mesh.h:1081
void Clear()
Remove all elements, clear all data, removes sorted marker.
void AddElements(const ElementSet &other)
Add elements of other set.
Definition: inmost_mesh.h:1090
iterator EndSorted() const
Provides iterator that points to element located after the last element that belong to presorted part...
void Subtract(const ElementArray< EType > &elems) const
Compute and store difference with elements.
Definition: inmost_mesh.h:1149
void SynchronizeSetElementsWithOwner()
Asks all the elements of ghost sets to be sent to the owner processors.
ElementArray< Element > Difference(const ElementArray< EType > &elems) const
Compute and return difference with elements.
Definition: inmost_mesh.h:1120
void Subtract(const HandleType *handles, enumerator num) const
Compute and store difference with raw handles.
ElementArray< Element > Difference(const HandleType *handles, enumerator num) const
Compute and return difference with raw handles.
ElementArray< Face > getFaces() const
Retrieve only faces.
ElementSet GetSibling() const
Retrieve sibling set of the set, this will be next child for the parent.
void Unite(const ElementSet &other) const
Compute and store union with raw handles.
virtual ElementArray< Face > getFaces() const
Retrieve all the faces of the element.
virtual ElementArray< Cell > getCells() const
Return all the cells of the element.
virtual enumerator nbAdjElements(ElementType etype, MarkerType mask, bool invert_mask=false) const
Retrieve number of adjacent elements with marker.
bool Hide() const
If the function returns true then element was hidden, works only inside BeginModification and EndModi...
void SendTo(std::set< Storage::integer > &procs) const
Update geometric data for element, calls RecomputeGeometricData from Mesh.
virtual ElementArray< Edge > getEdges() const
Retrieve all the edges of the element.
void Connect(const HandleType *adjacent, INMOST_DATA_ENUM_TYPE num) const
Connects lower adjacencies to current element.
virtual ElementArray< Element > getAdjElements(ElementType etype) const
Retrieve unordered array of adjacent elements.
virtual enumerator nbAdjElements(ElementType etype) const
Retrieve number of adjacent elements.
bool Delete()
Remove element from mesh.
virtual ElementArray< Node > getNodes() const
Retrieve all the nodes of the element.
bool Show() const
If the function returns true then element was recovered from hidden state, works only inside BeginMod...
void Disconnect(const HandleType *adjacent, INMOST_DATA_ENUM_TYPE num) const
Disconnect element.
virtual ElementArray< Element > getAdjElements(ElementType etype, MarkerType mask, bool invert_mask=false) const
Retrieve unordered array of adjacent elements with marker.
bool Boundary() const
Determine that the element is on the boundary.
An interface for elements of type FACE.
Definition: inmost_mesh.h:596
Cell BackCell() const
Retrieve the cell for which the normal points outwards.
ElementArray< Node > getNodes() const
Retrieve all the nodes of the element.
Cell FrontCell() const
Retrieve the cell for which the normal points inwards.
ElementArray< Edge > getEdges() const
Retrieve all the edges of the element.
void SwapCells() const
This function changes Face::BackCell() with Face::FrontCell().
ElementArray< Cell > getCells() const
Return all the cells of the element.
integer EnumerateSet(const ElementSet &set, const Tag &num_tag, integer start=0, bool define_sparse=true)
Enumerate all elements in the set.
Tag CreateTag(std::string name, DataType dtype, ElementType etype, ElementType sparse, INMOST_DATA_ENUM_TYPE size=ENUMUNDEF)
Create the tag by name, type and size.
ElementArray< ElementSet > GetSetsByPrefix(std::string prefix)
Retrieve all the sets whose names start with given prefix.
bulk_array BulkArrayDV(HandleType h, const Tag &tag)
Returns an array of bytes in dense array of variable size.
Definition: inmost_mesh.h:1960
void SetDimensions(integer dim)
Set number of dimensions for mesh.
void FacesOrientation(const ElementArray< Face > &faces, MarkerType rev)
Marks face with the orientation direction by marker.
Definition: inmost_mesh.h:3312
void ReduceDataBegin(const Tag &tag, ElementType mask, MarkerType select, exchange_data &storage)
This function intializes data reduction.
void GetData(HandleType h, const Tag &tag, enumerator shift, enumerator size, void *data) const
Copy inner data array of size elements to provided array beginning from shift element.
INMOST_DATA_ENUM_TYPE GetDataSize(HandleType h, const Tag &tag) const
Return the size of the array.
real_array RealArray(HandleType h, const Tag &tag)
Returns an array of real values.
void SetFileOption(std::string, std::string)
Set file option.
INMOST_DATA_ENUM_TYPE GetArrayCapacity(integer etypenum)
This function is needed by TagManager, may be made private in future follows definition of chunk_arra...
void ResolveSets()
Find sets that are common between processors.
void ResolveShared(bool only_new=false)
Find elements that are common between processors.
void Destroy(HandleType h)
Completely destroy element from mesh.
void ExchangeData(const Tag &tag, ElementType mask, MarkerType select=0)
Update data from Shared elements to Ghost elements.
void CheckProcsSorted(std::string file, int line)
Check that processors are sorted on every element.
void RemMarkerArray(const HandleType *h, enumerator n, MarkerType m)
Remove the marker from the set of handles.
Definition: inmost_mesh.h:2052
integer DataLocalID(HandleType h) const
Retrieve position of the data position of current element.
Definition: inmost_mesh.h:2208
__INLINE Tag RedistributeTag()
Don't put this shortcut to any function directly, as it creates tag inside assign to other object of ...
Definition: inmost_mesh.h:1461
void ClearTopologyError(TopologyCheck mask=ENUMUNDEF)
Revert mesh to clean topology error state.
Definition: inmost_mesh.h:3463
bool HaveGlobalID(ElementType types) const
Test whether global identificator was set on certain type of elements.
void CheckProcessors()
Let ghost elements send owner processor to master elements and see if they match.
__INLINE enumerator NumberOfTags() const
Retrieve the total number of valid tags.
Definition: inmost_mesh.h:1495
Element::adj_type & HighConn(HandleType h)
Access directly higher order adjacencies of current element with right of modification.
Definition: inmost_mesh.h:2095
void ApplyModification()
After this function any link to deleted element will be replaced by InvalidHandle().
void RecordParallelStorage(ElementType mask)
Outputs parallel storage into xml log files.
void SetMeshName(std::string new_name)
Be careful changing mesh name if you have already established remote links.
__INLINE void RemMarker(HandleType h, MarkerType n)
Remove the marker from the element.
Definition: inmost_mesh.h:2044
INMOST_DATA_ENUM_TYPE GetDataCapacity(HandleType h, const Tag &tag) const
Return the size of the structure in bytes required to represent the data on current element.
void Integrate(enumerator *input, integer size)
Integrate an array of unsigned integer values over all processors.
__INLINE iteratorTag BeginTag()
Returns the first tag defined on the mesh.
Definition: inmost_mesh.h:1492
std::pair< ElementSet, bool > CreateSetUnique(std::string name)
Same as Mesh::CreateSet without checking existence of the set.
bool Hide(HandleType h)
Hide element from mesh.
void ReduceData(const Tag &tag, ElementType mask, MarkerType select, ReduceOperation op)
Accumulation of data from ghost elements to shared elements.
void SetData(HandleType h, const Tag &tag, enumerator shift, enumerator size, const void *data)
Copy into inner data array of size elements from provided array beginning from shift element.
void SetParallelFileStrategy(int strategy)
Set parallel strategy for inner communications.
Definition: inmost_mesh.h:2537
Node CreateNode(const real *coords)
Create node by given coordinates.
bulk & BulkDV(HandleType h, const Tag &tag)
Returns a reference in dense array to the first element of variable size array of bytes.
Definition: inmost_mesh.h:1901
void ExchangeDataBegin(const Tag &tag, ElementType mask, MarkerType select, exchange_data &storage)
Start asynchronous synchronization of data.
void RemTopologyCheck(TopologyCheck mask)
Remove topology checks.
int GetLocalProcessorNumber() const
Get number of processors in shared environment (OpenMP)
void RemoveLowerAdjacencies(ElementType mask=(EDGE|FACE|CELL))
Delete all upper adjacencies, access to HighConn should fire assertion and retrieval of upper adjacen...
std::string GetMeshName()
Retrieve the name of the current mesh.
bool Show(HandleType h)
Show element from mesh.
void RestoreUpperAdjacencies(ElementType mask=(NODE|EDGE|FACE))
Restore all upper adjacencies.
MarkerType CreateMarker()
Allocate a new marker.
integer & IntegerDF(HandleType h, const Tag &tag)
Returns a reference to inner memory location of the first element of the array of integer values.
Definition: inmost_mesh.h:1732
void SortParallelStorage(ElementType mask)
Sort parallel storage.
void ReleaseMarker(MarkerType n, ElementType cleanup=NONE)
Release marker back for reuse.
void ExchangeDataBegin(const tag_set &tags, ElementType mask, MarkerType select, exchange_data &storage)
This function will initialize exchange of multiple data tags.
void CheckSetLinks(std::string file, int line)
Checks that there are no invalid links in sets.
ElementType HaveLowerAdjacencies() const
Check that upper adjacencies are stored.
void ExchangeDataEnd(const Tag &tag, ElementType mask, MarkerType select, exchange_data &storage)
Complete asynchronous synchronization of data.
bool New(HandleType h) const
Check whether element is new.
void ExchangeData(const tag_set &tags, ElementType mask, MarkerType select=0)
This function will perform exchange of multiple data tags.
Element::adj_type const & HighConn(HandleType h) const
Access directly higher order adjacencies of current element without right of modification.
Definition: inmost_mesh.h:2109
void ClearMarkerSpace(HandleType h)
Remove all the markers from the element.
bool DelSparseData(HandleType h, const Tag &tag)
Removes data of variable size and sparse tag data.
void MarkNormalOrientation(MarkerType mrk)
This function should be used to detect normal inversion on ghost interfaces with respect to normal or...
remote_reference & RemoteReferenceDF(HandleType h, const Tag &tag)
Returns a reference in dense array to the first element of constant size array of element remote hand...
Definition: inmost_mesh.h:1767
ElementSet GetSet(std::string name)
Retrieve set by name.
bulk_array BulkArrayDF(HandleType h, const Tag &tag)
Returns an array of bytes in dense array.
Definition: inmost_mesh.h:1806
integer Integrate(integer input)
Integrate integer value over all processors.
TopologyCheck BeginTopologyCheck(ElementType etype, const HandleType *adj, enumerator num)
This function allows you to perform some topological checks before you create an element.
void WachspressInterpolation2D(const real *x, const Face &f, std::map< HandleType, real > &nodes_stencil) const
Compute node-centered interpolation on 2d face for point.
__INLINE void SetMarker(HandleType h, MarkerType n)
Set a marker on the element represented by handle.
Definition: inmost_mesh.h:2023
void RecomputeParallelStorage(ElementType mask)
Regather ghost and shared element sets for data exchange.
bool Delete(HandleType h)
This function will hide element in modification state (between BeginModification and EndModification)...
void ReportConnection(HandleType h)
Go through all elements and detect presence of prescribed element in any reference data tag.
void OrientTag(Face f, Tag t)
Swap sign for oriented data of a single tag.
void SetTopologyError(TopologyCheck mask)
This will turn mesh into the state indicating that some topology error occurred.
Definition: inmost_mesh.h:3459
void RemoveGhostElements(const HandleType *ghost, enumerator num)
Delete some ghost cells provided in array.
void DelDenseData(void *data, const Tag &tag)
Removes data of variable size, clears to zero data of fixed size.
integer Enumerate(const HandleType *h, enumerator num, const Tag &num_tag, integer start=0, bool define_sparse=true)
Enumerate all elements beginning with start and put numeration to data associated with num_tag.
void Load(std::string File)
Acceptable file formats for reading.
bool CheckSaveSkip(std::string name, const std::set< std::string > &noload, const std::set< std::string > &loadonly) const
Check if tag saving should be skipped.
void RemoveUpperAdjacencies(ElementType mask=(NODE|EDGE|FACE))
Delete all upper adjacencies, access to HighConn should fire assertion and retrieval of upper adjacen...
void ResolveModification()
This function is not yet implemented.
remote_reference_array RemoteReferenceArrayDV(HandleType h, const Tag &tag)
Returns an array of element remote handles in dense array of variable size.
Definition: inmost_mesh.h:2010
int GetProcessorRank() const
Get rank of current processor.
void CheckGhostSharedCount(std::string file, int line, ElementType etype=ESET|CELL|FACE|EDGE|NODE)
Check that number of ghost and shared elements match to each other.
void Destroy(const Storage &e)
Shortcut for typed elements.
Definition: inmost_mesh.h:2240
void SetStatus(HandleType h, Element::Status s)
Set parallel status of the element.
Definition: inmost_mesh.h:2229
real & RealDV(HandleType h, const Tag &tag)
Returns a reference in dense array to the first element of variable size array of real values.
Definition: inmost_mesh.h:1876
TopologyCheck GetTopologyCheck(TopologyCheck mask=ENUMUNDEF) const
Retrieve currently set topology checks.
Definition: inmost_mesh.h:3453
void CheckGIDs(std::string file, int line, ElementType mask=NODE|EDGE|FACE|CELL|ESET)
Let ghost elements send global ids to master elements and see if they match.
void RemOrientedTag(Tag t)
Remove a data tag that follows normal orientation.
remote_reference & RemoteReference(HandleType h, const Tag &tag)
Returns a reference in an inner representation to the first element of array of element remote handle...
void ReduceDataBegin(const tag_set &tags, ElementType mask, MarkerType select, exchange_data &storage)
This function will initialize reduction of multiple data tags.
void MarkBoundaryFaces(MarkerType boundary_marker)
Sets marker for all the faces that have only one neighbouring cell, works correctly in parallel envir...
__INLINE integer GetDimensions() const
Get number of dimensions of mesh.
Definition: inmost_mesh.h:1440
int GetParallelFileStrategy() const
Retrieve currently set parallel strategy for ".pmf" files.
Definition: inmost_mesh.h:2540
remote_reference & RemoteReferenceDV(HandleType h, const Tag &tag)
Returns a reference in dense array to the first element of variable size array of element remote hand...
Definition: inmost_mesh.h:1933
bool Hidden(HandleType h) const
Check whether element is hidden.
remote_reference_array RemoteReferenceArray(HandleType h, const Tag &tag)
Returns an array of element remote handles.
bool HaveData(HandleType h, const Tag &tag) const
Check whether data is present on given element.
void ReduceData(const tag_set &tags, ElementType mask, MarkerType select, ReduceOperation op)
This function will perform reduction of multiple data tags.
INMOST_MPI_Group GetGroup() const
Retrieve MPI group corresponding to the communicator.
void GetMarkerSpace(HandleType h, bulk copy[MarkerFields]) const
Get a copy of the bytes that store markers on the element.
real_array RealArrayDF(HandleType h, const Tag &tag)
Returns an array of real values in dense array.
Definition: inmost_mesh.h:1780
int GetLocalProcessorRank() const
Get rank of current processor in shared environment (OpenMP)
bulk & BulkDF(HandleType h, const Tag &tag)
Returns a reference in dense array to the first element of constant size array of bytes.
Definition: inmost_mesh.h:1741
void ComputeGeometricType(HandleType h)
Recompute geometrical type of current element and set it to element.
integer ExclusiveSum(integer input)
Compute sum of integer values for all processors with rank lower then current, excluding current proc...
void SetDataSize(HandleType h, const Tag &tag, enumerator new_size)
Sets the size of the array for data of variable size.
void SynchronizeMarker(MarkerType marker, ElementType mask, SyncBitOp op)
Synchronize marker on elements between processors using provided operation.
__INLINE void SetEpsilon(real e)
Set tolerance for coordinates comparison.
Definition: inmost_mesh.h:1427
static void Initialize(int *argc, char ***argv)
Initial initialization.
void Integrate(integer *input, integer size)
Integrate an array of integer values over all processors.
real & RealDF(HandleType h, const Tag &tag)
Returns a reference to inner memory location of the first element of the array of real values.
Definition: inmost_mesh.h:1723
void RestoreLowerAdjacencies(ElementType mask=(EDGE|FACE|CELL))
Restore all upper adjacencies.
__INLINE bool GetMarker(HandleType h, MarkerType n) const
Check whether the marker is set one the element.
Definition: inmost_mesh.h:2038
reference_array ReferenceArrayDF(HandleType h, const Tag &tag)
Returns an array of element handles in dense array.
Definition: inmost_mesh.h:1835
integer Enumerate(const ElementArray< EType > &elements, const Tag &num_tag, integer start=0, bool define_sparse=true)
Enumerate all elements beginning with start and put numeration to data associated with num_tag.
Definition: inmost_mesh.h:2905
bool EndTopologyCheck(HandleType e, TopologyCheck begin_check)
This function performs some topological checks after construction of element.
integer Enumerate(ElementType mask, Tag num_tag, integer start=0, bool define_sparse=false)
Enumerate all elements beginning with start and put numeration to data associated with num_tag for al...
HandleType FindSharedAdjacency(const HandleType *arr, enumerator num) const
Retrieve upper adjacent that is shared by multiple lower adjacencies.
void ExchangeOrientedData(const tag_set &tags, ElementType mask, MarkerType select=0, MarkerType orient=0)
This function is similar to ExchangeData, except that it will change the orientation of recieved data...
static Mesh * GetMesh(std::string name)
Find mesh by name.
ElementType SynchronizeElementType(ElementType etype)
Synchronize bitwise mask of element types between processors.
integer_array IntegerArrayDF(HandleType h, const Tag &tag)
Returns an array of integer values in dense array.
Definition: inmost_mesh.h:1793
bulk & Bulk(HandleType h, const Tag &tag)
Returns a reference in inner representation to the first element of array of bytes.
void ExchangeGhost(integer layers, ElementType bridge, MarkerType select=0, bool delete_ghost=true)
Form several layers of ghost cells that are adjacent through bridge elements to current cells.
void SortByGlobalID(HandleType *h, enumerator num)
INMOST_DATA_ENUM_TYPE GetDataCapacity(const INMOST_DATA_BULK_TYPE *data, INMOST_DATA_ENUM_TYPE size, const Tag &tag) const
Returns the number of bytes in data used for given type of tag.
reference_array ReferenceArrayDV(HandleType h, const Tag &tag)
Returns an array of element handles in dense array of variable size.
Definition: inmost_mesh.h:1985
std::string GetFileOption(std::string key) const
Get current option corresponding to key.
INMOST_MPI_Comm GetCommunicator() const
Retrieve MPI communicator.
void ExchangeDataEnd(const tag_set &tags, ElementType mask, MarkerType select, exchange_data &storage)
This function will finalize exchange of multiple data tags.
void ReduceDataEnd(const Tag &tag, ElementType mask, MarkerType select, ReduceOperation op, exchange_data &storage)
This function completes data reduction.
remote_reference_array RemoteReferenceArrayDF(HandleType h, const Tag &tag)
Returns an array of element remote handles in dense array.
Definition: inmost_mesh.h:1864
integer & Integer(HandleType h, const Tag &tag)
Returns a reference to inner memory location of the first element of the array of integer values.
void Clear()
Remove all data and all elements from the mesh Reset geometry service and topology check flags.
void ReduceDataEnd(const tag_set &tags, ElementType mask, MarkerType select, ReduceOperation op, exchange_data &storage)
This function will finalize exchange of multiple data tags.
void SetMarkerSpace(HandleType h, bulk source[MarkerFields])
Overwrite the bytes that store markers on the element.
static void Finalize()
Finalizes operation with MPI, recommended to call, otherwise MPI may produce warnings.
iteratorStorage Begin(ElementType Types)
These iterators skip invalid elements but don't skip modified elements.
void CheckCentroids(std::string file, int line)
Check that centroids of ghost and shared elements match to each other.
void Integrate(real *input, integer size)
Integrate an array of real values over all processors.
TopologyCheck GetTopologyError(TopologyCheck mask=ENUMUNDEF) const
Retrieve topology error state, this indicates that some error have occurred.
Definition: inmost_mesh.h:3461
enumerator MemoryUsage(HandleType h)
For parmetis return total number in bytes of occupied memory by element and its data.
ElementType HaveUpperAdjacencies() const
Check that upper adjacencies are stored.
reference & ReferenceDF(HandleType h, const Tag &tag)
Returns a reference in dense array to the first element of constant size array of element handles.
Definition: inmost_mesh.h:1754
void SetCommunicator(INMOST_MPI_Comm _comm)
Set MPI communicator.
std::set< std::string > TagOptions(std::string name) const
Collect file options related to records Tag:TAGNAME.
void OrientTags(Face f)
Swap sign for oriented data.
void AddOrientedTag(Tag t)
Add a data tag that follows normal orientation.
Definition: inmost_mesh.h:1377
real Integrate(real input)
Integrate real value over all processors.
integer & GlobalID(HandleType h)
Retrieve global id of the element with right of modification (dangerous to modify).
Definition: inmost_mesh.h:2196
void DelDenseData(HandleType h, const Tag &tag)
Removes data of variable size, clears to zero data of fixed size.
real Integrate(const Tag &t, enumerator entry, ElementType mask)
Integrate data corresponding to tag between all processors.
integer_array IntegerArray(HandleType h, const Tag &tag)
Returns an array of integer values.
void Save(std::string File)
Acceptable file formats for writing.
reference_array ReferenceArray(HandleType h, const Tag &tag)
Returns an array of element handles.
bool isMeshModified() const
Check whether code runs between Mesh::BeginModification, Mesh::EndModification scope.
Definition: inmost_mesh.h:3377
Element::Status GetStatus(HandleType h) const
Retrieve parallel status of the element.
Definition: inmost_mesh.h:2217
reference & ReferenceDV(HandleType h, const Tag &tag)
Returns a reference in dense array to the first element of variable size array of element handles.
Definition: inmost_mesh.h:1917
__INLINE void SetMarkerArray(const HandleType *h, enumerator n, MarkerType m)
Set a marker on the set of handles.
Definition: inmost_mesh.h:2032
void RemoveGhost(MarkerType marker=0)
Delete all the ghost cells.
integer TotalNumberOf(ElementType mask)
Sum of all physical elements, it excludes ghost copies.
reference & Reference(HandleType h, const Tag &tag)
Returns a reference in an inner representation to the first element of array of element handles.
void WachspressInterpolation3D(const real *x, const Cell &c, std::map< HandleType, real > &nodes_stencil) const
Compute node-centered interpolation on 3d cell for point Point should be inside cell or on its bounda...
static void CopyData(Element a, Element b)
Copy all the data from b to a (a = b).
Element::adj_type & LowConn(HandleType h)
Access directly lower order adjacencies of current element with right of modification.
Definition: inmost_mesh.h:2121
integer_array IntegerArrayDV(HandleType h, const Tag &tag)
Returns an array of integer values in dense array of variable size.
Definition: inmost_mesh.h:1951
enumerator Integrate(enumerator input)
Integrate unsigned integer value over all processors.
__INLINE MeshState GetMeshState() const
Get parallel state of the mesh.
Definition: inmost_mesh.h:1443
void Redistribute()
Migrate all the elements to the new owners prescribed in data corresponding to RedistributeTag.
integer GlobalID(HandleType h) const
Retrieve global id of the element without right of modification.
Definition: inmost_mesh.h:2203
void CheckOwners(std::string file, int line)
Let ghost elements send processors list to master elements and see if they match.
void AssignGlobalID(ElementType mask)
Assign unique numbers to elements.
__INLINE real GetEpsilon() const
Retrieve tolerance for coordinates comparison.
Definition: inmost_mesh.h:1430
Tag DeleteTag(Tag tag, ElementType mask=NODE|EDGE|FACE|CELL|ESET|MESH)
Remove the data that is represented by the tag from elements of selected type.
void ExchangeMarked(enum Action action=AGhost)
This function realizes two algorithms: ghosting of elements and migration of elements.
bulk_array BulkArray(HandleType h, const Tag &tag)
Returns an array of bytes.
void ExchangeOrientedData(const Tag &tag, ElementType mask, MarkerType select=0, MarkerType orient=0)
This function is similar to ExchangeData, except that it will change the orientation of recieved data...
__INLINE iteratorTag EndTag()
Returns the indicator for loop to end iteration over tags.
Definition: inmost_mesh.h:1498
real_array RealArrayDV(HandleType h, const Tag &tag)
Returns an array of real values in dense array of variable size.
Definition: inmost_mesh.h:1942
integer & IntegerDV(HandleType h, const Tag &tag)
Returns a reference in dense array to the first element of variable size array of integer values.
Definition: inmost_mesh.h:1888
int GetProcessorsNumber() const
Get number of processors.
bool CheckLoadSkip(std::string name, const std::set< std::string > &noload, const std::set< std::string > &loadonly) const
Check if tag loading should be skipped.
Tag TopologyErrorTag() const
This will return tag by which you can retrieve error mark to any element on which topology check fail...
Definition: inmost_mesh.h:3451
void SetTopologyCheck(TopologyCheck mask)
Set topology checks.
real & Real(HandleType h, const Tag &tag)
Returns a reference to inner memory location of the first element of the array of real values.
void DelData(HandleType h, const Tag &tag)
Remove tag data from given element.
Element::adj_type const & LowConn(HandleType h) const
Access directly lower order adjacencies of current element without right of modification.
Definition: inmost_mesh.h:2123
ElementArray< Cell > getCells() const
Return all the cells of the element.
ElementArray< Face > getFaces() const
Retrieve all the faces of the element.
ElementArray< Edge > getEdges() const
Retrieve all the edges of the element.
This structure is a helper structure to aid with search of cells by position.
Definition: inmost_mesh.h:3653
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
__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
__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
__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
This class provides the access to the individual mesh datum and general information about it.
Definition: inmost_data.h:193
A class that represents a variable with multiple first order variations.