Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Element_accessors.C
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.C,v 1.11 2008/12/06 08:43:25 mtcampbe Exp $
24 
25 #include "Element_accessors.h"
26 #include "roccom_assertion.h"
27 #include <cstdlib>
28 
29 COM_BEGIN_NAME_SPACE
30 
32 Element_node_enumerator( const Pane *pane, int i,
33  const Connectivity *conn)
34  : _pane(pane), _conn( _pane->is_structured()?NULL:
35  (conn==NULL?pane->connectivity(i):conn))
36 {
37  if ( _pane->is_unstructured()) {
38  if ( conn == NULL && _conn != NULL) i -= _conn->index_offset()+1;
39  else --i;
40 
41  if ( _conn) {
42  COM_assertion( i>=0 && i<std::max(int(_conn->size_of_elements()),1));
45  }
46  else {
47  _pane = NULL;
48  _conn = NULL;
49  _start = NULL;
50  _res = -1;
51  }
52  }
53  else if ( _pane->dimension()==2) {
54  COM_assertion( i>=1 && i<=int(_pane->size_of_elements()));
55  _res = (i-1) % (_pane->size_i()-1);
56  _base = i + (i-1) / (_pane->size_i()-1);
57  }
58  else {
59  COM_assertion(false); // Not yet supported.
60  }
61 }
62 
69  const std::pair<int,int> &id)
70  : _pane(pane), _conn(NULL) {
71  COM_assertion( _pane != NULL && _pane->is_structured());
72  COM_assertion( id.first>0 && id.first<=int(_pane->size_i()));
73  COM_assertion( id.second>0 && id.second<=int(_pane->size_j()));
74 
75  _res = id.first-1;
76  _base = (id.second-1)*_pane->size_i()+id.first;
77 }
78 
80  if ( _conn) {
81  if ( --_res==0) {
84  if ( _conn) {
85  _start = _conn->pointer();
87  }
88  else {
89  _pane = NULL;
90  _conn = NULL;
91  _start = NULL;
92  _res = -1;
93  }
94  }
95  else
97  }
98  else if (_pane->dimension()==2) { // Structured mesh
99  ++_base;
100  if ( ++_res == int(_pane->size_i()-1)) { ++_base; _res=0; }
101  }
102  else {
103  COM_assertion(false); // Not yet supported.
104  }
105 }
106 
107 int
108 Element_node_enumerator::vertex( int lvid, bool level) const {
109  if ( _pane->is_structured()) { // Structured mesh
110  if ( lvid == _base) return 0;
111  if ( lvid == _base+1) return 1;
112  const int nr = _pane->size_i();
113  if ( lvid == int(_base+nr)) return 3;
114  if ( lvid == int(_base+nr+1)) return 2;
115 
116  // There is a branch cut in the pane. Resort to more expensive step.
117  // Check which boundary lvid is on.
118  if ( !level) {
119  COM_assertion( nr>2 && _pane->size_j()>2);
120  const int c1 = (_base-1)/nr, r1 = (_base-1)%nr;
121  const int c2 = (lvid-1)/nr, r2 = (lvid-1)%nr;
122 
123  if ( std::abs( r1-r2)<=1) {
124  const int nc = _pane->size_j();
125  if ( c2 == 0) return vertex( (nc-1)*nr+r2+1, true);
126  if ( c2 == nc-1) return vertex( r2+1, true);
127  }
128  else {
129  COM_assertion( std::abs( c1-c2)<=1);
130  if ( r2 == 0) return vertex( (c2+1)*nr, true);
131  if ( r2 == nr-1) return vertex( c2*nr+1, true);
132  }
133  }
134  COM_assertion( false); return -1;
135  }
136  else { // Unstructured
137  const int *p=_start;
138  for ( int i=0, size=_conn->size_of_nodes_pe(); i<size; ++i,++p) {
139  if ( lvid == *p) return i;
140  }
141 
142  return -1; // The node is not in the table
143  }
144 }
145 
146 void Element_node_enumerator::get_nodes( std::vector< int > &nodes) {
147  int num_nodes = size_of_nodes();
148  nodes.resize( num_nodes);
149 
150  for (int i=0; i<num_nodes; i++) nodes[i] = (*this)[i];
151 }
152 
155  : _ene(ene), _k(k), _ne(0) {
156  if ( ene->dimension() == 2) {
157  const_cast<int&>(_ne) = 1;
158  _fn_list = NULL;
159  }
160  else {
161  switch ( ene->size_of_nodes()) {
162  case 4: // Tetrahedra
163  case 10: {
164  const_cast<int&>(_ne) = 3;
166  break;
167  }
168  case 5: // Pyramids
169  case 14: {
170  const_cast<int&>(_ne) = (_k==0)? 4 : 3;
172  break;
173  }
174  case 6: // Prisms (Pentahedra)
175  case 15:
176  case 18: {
177  const_cast<int&>(_ne) = (_k<3)? 4 : 3;
179  break;
180  }
181  case 8: // Hexahedra
182  case 20:
183  case 27: {
184  const_cast<int&>(_ne) = 4;
186  break;
187  }
188  default: COM_assertion_msg(false, "Not supported yet.");
189  }
190  }
191 }
192 
194  if ( _ne == 1)
195  return _ene->is_quadratic() ? 3 : 2;
196  else {
197  int nn = _ne; // Number of nodes per face
198 
199  if ( _ene->is_quadratic()) {
200  int num_nodes = _ene->size_of_nodes();
201  nn += _ne + (num_nodes == 18 && _k<3 || num_nodes == 27);
202  }
203  return nn;
204  }
205 }
206 
208  if ( _ne > 1)
209  return (*_ene)[_fn_list[i]];
210  else {
211  if ( i<2) return (*_ene)[(_k+i)%_ene->size_of_edges()];
212  else return (*_ene)[_ene->size_of_edges()+_k];
213  }
214 }
215 
217 get_nodes( std::vector< int > &nodes, bool quad_ret) {
218  int nn = quad_ret ? size_of_nodes() : size_of_corners();
219  nodes.resize( nn);
220 
221  if ( _ne == 1) {
222  int num_edges = _ene->size_of_edges();
223  // Retrun the nodes on each edge.
224  nodes[0] = (*_ene)[(_k)%num_edges];
225  nodes[1] = (*_ene)[(_k+1)%num_edges];
226 
227  if (nn>2) nodes[2] = (*_ene)[num_edges+_k];
228  }
229  else {
230  for ( int i=0; i<nn; ++i) nodes[i] = (*_ene)[_fn_list[i]];
231  }
232 }
233 
235 { {0, 2, 1, 6, 5, 4}, { 0, 1, 3, 4, 8, 7},
236  {1, 2, 3, 5, 9, 8}, {2, 0, 3, 6, 7, 9}};
237 
239 { {0,3,2,1,8,7,6,5}, {0,1,4,5,10,9,-1,-1}, {1,2,4,6,11,10,-1,-1},
240  {2,3,4,7,12,11,-1,-1}, {3,0,4,8,9,12,-1,-1}};
241 
243 { {0,1,4,3,6,10,12,9,15}, {1,2,5,4,7,11,13,10,16}, {2,0,3,5,8,9,14,11,17},
244  {0,2,1,8,7,6,-1,-1,-1}, {3,4,5,12,13,14,-1,-1,-1}};
245 
247 { {0,3,2,1,11,10,9, 8, 20}, {0,1,5,4,8, 13,16,12,21},
248  {1,2,6,5,9, 14,17,13,22}, {2,3,7,6,10,15,18,14,23},
249  {0,4,7,3,12,19,15,11,24}, {4,5,6,7,16,17,18,19,25}};
250 
251 COM_END_NAME_SPACE
252 
253 
254 
255 
256 
257 
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.
const int * pointer() const
Get a constant pointer to the connectivity array.
Definition: Connectivity.h:206
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.
#define COM_assertion_msg(EX, msg)
void get_nodes(std::vector< int > &nodes, bool quad_ret)
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
const Connectivity * _conn
bool is_structured() const
Is mesh of the pane structured?
Definition: Pane.h:110
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.
Size size_of_elements() const
Get the total number of elements in the pane (including ghost elements).
Definition: Pane.h:142
Facet_node_enumerator(const Element_node_enumerator *ene, int k)
static const int _face_node_lists_hexa[6][9]
const int num_nodes
Definition: ex1.C:96
Size index_offset() const
Get the index of the first element.
Definition: Connectivity.h:189
int operator[](int i) const
int size_of_edges() const
Number of edges per element.
blockLoc i
Definition: read.cpp:79
Size size_j() const
Get the number of nodes in j-dimension if the mesh is structured.
Definition: Pane.h:219
int size_of_nodes() const
Number of nodes per element.
This file contains a set of routines for error assertion.
int dimension() const
Get the dimension of the base pane.
bool is_unstructured() const
Is mesh of the pane unstructured?
Definition: Pane.h:103
static const int _face_node_lists_tets[4][6]
const Element_node_enumerator *const _ene
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
int is_quadratic() const
Check whether the element is quadratic.
Size size_of_elements() const
Get the total number of elements (including ghost elements) in the table.
Definition: Connectivity.C:96
NT abs(const NT &x)
Definition: number_utils.h:130
void next()
Go to the next element within the connectivity tables of a pane.
Size size_i() const
Get the number of nodes in i-dimension if the mesh is structured.
Definition: Pane.h:216
Encapsulates an element-connectivity of a mesh.
Definition: Connectivity.h:41
static const int _face_node_lists_pyra[5][8]