Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Element_accessors.h
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: Element_accessors.h,v 1.12 2008/12/06 08:43:24 mtcampbe Exp $
24 
28 /* Author: Xiangmin Jiao
29  * Date: Mar. 12, 2002
30  */
31 
32 #ifndef _ELEMENT_ACCESSORS_H_
33 #define _ELEMENT_ACCESSORS_H_
34 
35 #include "roccom.h"
36 #include <cassert>
37 #include <algorithm>
38 
39 COM_BEGIN_NAME_SPACE
40 
44 public:
45  Element_node_enumerator() : _pane(NULL), _conn(NULL), _start(NULL), _res(0){}
46 
50  Element_node_enumerator( const Pane *pane, int i,
51  const Connectivity *conn=NULL);
52 
55  const std::pair<int,int> &id);
56 
58  void next();
59 
61  int type() const {
62  if ( _conn) return _conn->element_type();
63  else if ( _pane->dimension()==2) return Connectivity::ST2;
64  else return Connectivity::ST3;
65  }
66 
68  int is_quadratic() const {
69  if ( _conn) return _conn->is_quadratic();
70  else return false;
71  }
72 
74  int size_of_nodes() const {
75  if ( _conn) return _conn->size_of_nodes_pe();
76  if ( _pane->dimension()==2) return 4;
77  return 8;
78  }
79 
81  int size_of_corners() const {
82  if ( _conn) return _conn->size_of_corners_pe();
83  if ( _pane->dimension()==2) return 4;
84  return 8;
85  }
86 
88  void get_nodes( std::vector< int > &nodes);
89 
91  int size_of_edges() const {
92  if ( _conn) return _conn->size_of_edges_pe();
93  if ( _pane->dimension()==2) return 4;
94  return 12;
95  }
96 
98  int size_of_faces() const {
99  if ( _conn) return _conn->size_of_faces_pe();
100  if ( _pane->dimension()==2) return 1;
101  return 6;
102  }
103 
105  int dimension() const { return _pane->dimension(); }
106 
108  int id() const {
109  if ( _pane->is_structured()) {
110  return _base - (_base-1) / _pane->size_i();
111  }
112  else {
113  return _conn->index_offset() + 1 +
115  }
116  }
117 
119  int vertex( int lvid, bool level=false) const;
120 
124  inline int operator[]( int i) const {
125  if ( _conn) // Unstructured mesh
126  return _start[i];
127  else { // Structured mesh; Only support 2-D mesh now.
128  int t=_base;
129  if ( i>1) t+=_pane->size_i();
130  return ( i==1 || i==2)? t+1 : t;
131  }
132  }
133 
134  // Obtain a reference to the pane
135  inline const Pane* pane() const { return _pane; }
136 
137 protected:
138  const Pane *_pane; // Owner pane.
140  union {
141  const int *_start; // For unstructured mesh
142  int _base; // For structured mesh
143  };
144  int _res; // For structured or unstructured mesh
145 };
146 
149 public:
152  : Element_node_enumerator( pane, i) {}
153 
155  const std::pair<int,int> &id)
156  : Element_node_enumerator( pane, id) {}
157 
158  void next()
159  { ++_base; if ( ++_res == int(_pane->size_i()-1)) { ++_base; _res=0; } }
160 
161  int operator[]( int i) const {
162  int t=_base;
163  if ( i>1) t+=_pane->size_i();
164  return ( i==1 || i==2)? t+1 : t;
165  }
166 };
167 
170 public:
173  const Connectivity *conn=NULL)
174  : Element_node_enumerator( pane, i, conn) {}
175 
176  void next() {
177  if ( --_res==0) {
180  if ( _conn) {
181  _start = _conn->pointer();
183  }
184  else {
185  _start = NULL;
186  _res = -1;
187  }
188  }
189  else
191  }
192 
193  int operator[]( int i) const { return _start[i]; }
194  int size_of_nodes() const { return _conn->size_of_nodes_pe(); }
195 };
196 
197 
201 public:
202  // Constructor from an element and a local face ID (starting from 0).
204 
205  // Get the number of the nodes of a facet.
206  int size_of_nodes() const;
207 
208  // Get the number of the corners of a facet.
209  int size_of_corners() const { return (_ne == 1) ? 2 : _ne ; }
210 
211  // Get the number of the edges of a facet.
212  int size_of_edges() const { return _ne; }
213 
214  // Get a list of node IDs of the given facet.
215  void get_nodes( std::vector< int > &nodes, bool quad_ret);
216 
217  // Get the node ID of a particular node within a facet.
218  int operator[]( int i) const;
219 
220 protected:
221  static const int _face_node_lists_tets[4][6];
222  static const int _face_node_lists_pyra[5][8];
223  static const int _face_node_lists_pris[5][9];
224  static const int _face_node_lists_hexa[6][9];
225 
227  const int _k;
228  const int _ne; // Number of edges. 1 in 2-D.
229  const int *_fn_list; // NULL in 2-D and pointer in 3-D.
230 };
231 
233 template <class Value>
235  public:
236  enum { MAX_NODES=9};
237  typedef unsigned int Size;
238 
241  { std::fill_n( _vs, 9, reinterpret_cast<Value*>(NULL)); }
242 
244  void set( const Value *p, Element_node_enumerator &ene, int strd) {
246  _attr = NULL;
247  for ( int i=ene.size_of_nodes()-1; i>=0; --i)
248  _vs[i] = &p[(ene[i]-1)*strd];
249  }
250 
252  void set( const Attribute *a, Element_node_enumerator &ene) {
253  COM_assertion( a->is_nodal() && a->pane()->id());
254  COM_assertion( sizeof(Value)==COM_get_sizeof( a->data_type(),1));
255 
256  int ncomp = a->size_of_components();
257  int strd = a->stride();
258  int nn = ene.size_of_nodes();
259  if ( ncomp<=strd) {
260  const Value *p = reinterpret_cast<const Value*>(a->pointer());
261  _attr = NULL;
262  for ( int i=0; i<nn; ++i) _vs[i] = &p[(ene[i]-1)*strd];
263  }
264  else {
265  _attr = a;
266  for ( int i=0; i<nn; ++i) _offsets[i] = ene[i]-1;
267  }
268  }
269 
270  // Access a vector.
271  const Value &operator()( int i, int j) const {
272  if ( _attr) {
274  const Attribute *aj = _attr+j+1;
275  return reinterpret_cast<const Value*>
276  (aj->pointer())[_offsets[i]*aj->stride()];
277  }
278  else
279  return _vs[i][j];
280  }
281 
282  const Value &operator()(int i) const { return operator()(i,0); }
283 
284  const Value &operator[](int i) const { return operator()(i,0); }
285 
286 protected:
287  const Attribute *_attr;
288  union {
289  int _offsets[MAX_NODES]; // Used if _attr is not NULL
290  const Value *_vs[MAX_NODES]; // Used if _attr is NULL
291  };
292 };
293 
294 template <class Value>
297 public:
299 
300  void set( Value *p, Element_node_enumerator &ene, int strd)
301  { Base::set( p, ene, strd); }
302 
304  { Base::set( a, ene); }
305 
306  Value &operator()(int i, int j) const
307  { return const_cast<Value&>(Base::operator()(i,j)); }
308 
309  Value &operator()(int i) const
310  { return const_cast<Value&>(Base::operator()(i,0)); }
311 
312  Value &operator[](int i) const
313  { return const_cast<Value&>(Base::operator()(i,0)); }
314 };
315 
317 template <class Value>
319  public:
320  typedef unsigned int Size;
321 
323  Element_vectors_k_const() : _attr(NULL), _vs(NULL) {}
324 
326  void set( const Value *p, Element_node_enumerator &ene, int strd) {
327  _attr = NULL;
328  _vs = &p[(ene.id()-1)*strd];
329  }
330 
332  void set( const Attribute *a, Element_node_enumerator &ene) {
333  COM_assertion( a->is_elemental() && a->pane()->id());
334  COM_assertion( sizeof(Value)==COM_get_sizeof( a->data_type(),1));
335 
336  int ncomp = a->size_of_components();
337  int strd = a->stride();
338  if ( ncomp<=strd) {
339  const Value *p = reinterpret_cast<const Value*>(a->pointer());
340  _attr = NULL;
341  _vs = &p[(ene.id()-1)*strd];
342  }
343  else {
344  _attr = a;
345  _offset = ene.id()-1;
346  }
347  }
348 
349  // Access a vector.
350  const Value &operator()( int i, int j) const {
351  if ( _attr) {
353  const Attribute *aj = _attr+j+1;
354  return reinterpret_cast<const Value*>
355  (aj->pointer())[_offset*aj->stride()];
356  }
357  else
358  return _vs[j];
359  }
360 
361  const Value &operator()(int i) const { return operator()(i,0); }
362 
363  const Value &operator[](int i) const { return operator()(i,0); }
364 
365 protected:
366  const Attribute *_attr;
367  union {
368  int _offset; // Used if _attr is not NULL
369  const Value *_vs; // Used if _attr is NULL
370  };
371 };
372 
373 template <class Value>
376 public:
378 
379  void set( Value *p, Element_node_enumerator &ene, int strd)
380  { Base::set( p, ene, strd); }
381 
383  { Base::set( a, ene); }
384 
385  Value &operator()(int i, int j) const
386  { return const_cast<Value&>(Base::operator()(i,j)); }
387 
388  Value &operator()(int i) const
389  { return const_cast<Value&>(Base::operator()(i,0)); }
390 
391  Value &operator[](int i) const
392  { return const_cast<Value&>(Base::operator()(i,0)); }
393 };
394 
395 COM_END_NAME_SPACE
396 
397 #endif // _ELEMENT_ENUMERATOR_H_
398 // EOF
399 
400 
401 
402 
403 
404 
int type() const
Obtain the type of the element.
A Pane object contains a mesh, pane attribute, and field variables.
Definition: Pane.h:43
#define COM_assertion(EX)
Error checking utility similar to the assert macro of the C language.
An adaptor for enumerating node IDs of an element.
Value & operator[](int i) const
Value & operator()(int i, int j) const
const int * pointer() const
Get a constant pointer to the connectivity array.
Definition: Connectivity.h:206
Value & operator[](int i) const
An Attribute object is a data member of a window.
Definition: Attribute.h:51
j indices k indices k
Definition: Indexing.h:6
int vertex(int lvid, bool level=false) const
Get the vertex index of an vertex within the element.
Element_vectors_k_const()
Default constructor.
void get_nodes(std::vector< int > &nodes, bool quad_ret)
void set(Value *p, Element_node_enumerator &ene, int strd)
const Connectivity * _conn
This file contains the prototypes for Roccom API.
bool is_structured() const
Is mesh of the pane structured?
Definition: Pane.h:110
const Value & operator()(int i) const
Value & operator()(int i, int j) const
Size size_of_corners_pe() const
Get the number of corners per element of the current connectivity table.
Definition: Connectivity.h:139
const Value & operator[](int i) const
void set(Value *p, Element_node_enumerator &ene, int strd)
Adaptor for enumerating node IDs of a facet of an element.
bool is_quadratic() const
Determine whether the element type is quadratic.
Definition: Connectivity.h:132
static const int _face_node_lists_pris[5][9]
void get_nodes(std::vector< int > &nodes)
Get a vector of all of the nodes in the element.
Element_node_enumerator_str_2(const Pane *pane, int i)
int id() const
Get the local id of the element within the pane.
Facet_node_enumerator(const Element_node_enumerator *ene, int k)
static const int _face_node_lists_hexa[6][9]
int operator[](int i) const
Obtain the pane-scope node ID from its element-scope index.
const void * pointer() const
Obtain a constant pointer to the physical address.
Definition: Attribute.h:150
This is a helper class for accessing nodal data.
Size index_offset() const
Get the index of the first element.
Definition: Connectivity.h:189
Element_node_vectors_k_const< Value > Base
int operator[](int i) const
const Value & operator[](int i) const
int size_of_edges() const
Number of edges per element.
void set(const Value *p, Element_node_enumerator &ene, int strd)
initialize the accessor with a pointer and a specific stride.
const Value & operator()(int i, int j) const
blockLoc i
Definition: read.cpp:79
void set(Attribute *a, Element_node_enumerator &ene)
Element_node_vectors_k_const()
Default constructor.
This is a helper class for accessing elemental data.
int size_of_nodes() const
Number of nodes per element.
const Value & operator()(int i) const
int COM_get_sizeof(const COM_Type type, int c)
Definition: roccom_c++.h:560
Size size_of_edges_pe() const
Get the number of edges per element of the current connectivity table.
Definition: Connectivity.h:155
int dimension() const
Get the dimension of the base pane.
int stride() const
Obtain the stride of the attribute in base datatype.
Definition: Attribute.h:233
Value & operator()(int i) const
bool is_nodal() const
Checks whether the attribute is associated with a node.
Definition: Attribute.h:194
static const int _face_node_lists_tets[4][6]
const Pane * pane() const
Obtain a constant pointer to the owner pane of the attribute.
Definition: Attribute.h:172
const Element_node_enumerator *const _ene
j indices j
Definition: Indexing.h:6
int dimension() const
Dimension of the pane.
Definition: Pane.h:99
Size size_of_nodes_pe() const
Get the number of nodes per element of the current connectivity table.
Definition: Connectivity.h:147
Connectivity * connectivity(Size i)
Obtain the connectivity table containing the element with the given ID.
Definition: Pane.C:99
void set(const Value *p, Element_node_enumerator &ene, int strd)
initialize the accessor with a pointer and a specific stride.
int is_quadratic() const
Check whether the element is quadratic.
int size_of_faces() const
Number of faces per element.
Size size_of_elements() const
Get the total number of elements (including ghost elements) in the table.
Definition: Connectivity.C:96
int element_type() const
Obtain element type ID.
Definition: Connectivity.h:122
const Value & operator()(int i, int j) const
Element_vectors_k_const< Value > Base
const Value * _vs[MAX_NODES]
void next()
Go to the next element within the connectivity tables of a pane.
Element_node_enumerator_str_2(const Pane *pane, const std::pair< int, int > &id)
void set(const Attribute *a, Element_node_enumerator &ene)
initialize the accessor from an attribute assiciated with a pane.
COM_Type data_type() const
Obtain the data type of each component of the attribute.
Definition: Attribute.h:197
Size size_i() const
Get the number of nodes in i-dimension if the mesh is structured.
Definition: Pane.h:216
Optimized version for unstructured meshes.
void set(Attribute *a, Element_node_enumerator &ene)
Size size_of_faces_pe() const
Get the number of faces per element of the current connectivity table.
Definition: Connectivity.h:163
bool is_elemental() const
Checks whether the attribute is associated with an element.
Definition: Attribute.h:192
void set(const Attribute *a, Element_node_enumerator &ene)
initialize the accessor from an attribute assiciated with a pane.
Encapsulates an element-connectivity of a mesh.
Definition: Connectivity.h:41
int id() const
Get the ID of the pane.
Definition: Pane.h:96
static const int _face_node_lists_pyra[5][8]
Element_node_enumerator_uns(const Pane *pane, int i, const Connectivity *conn=NULL)
const Pane * pane() const
int size_of_corners() const
Number of corners per element.
Value & operator()(int i) const
Optimized version for 2-D structured meshes.
int size_of_components() const
Obtain the number of components in the attribute.
Definition: Attribute.h:203