Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Connectivity.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: Connectivity.C,v 1.11 2008/12/06 08:43:25 mtcampbe Exp $
24 
29 /* Author: Xiangmin Jiao */
30 
31 #include "Connectivity.h"
32 #include "Pane.h"
33 #include "roccom_assertion.h"
34 #include <cstring>
35 
36 COM_BEGIN_NAME_SPACE
37 
38 // Tables of pre-defined connectivity types
39 const int Connectivity::_sizes[TYPE_MAX_CONN][SIZE_MAX_CONN] =
40 {
41  /* type, dim, order, nnodes, ncorn, nedges, nfaces */
42  {ST1, 1, 1, 2, 2, 1, 0},
43  {ST2, 2, 1, 4, 4, 4, 1},
44  {ST3, 3, 1, 8, 8, 12, 6},
45  {BAR2, 1, 1, 2, 2, 1, 0},
46  {BAR3, 1, 2, 3, 2, 1, 0},
47  {TRI3, 2, 1, 3, 3, 3, 1},
48  {TRI6, 2, 2, 6, 3, 3, 1},
49  {QUAD4, 2, 1, 4, 4, 4, 1},
50  {QUAD8, 2, 2, 8, 4, 4, 1},
51  {QUAD9, 2, 2, 9, 4, 4, 1},
52  {TET4, 3, 1, 4, 4, 6, 4},
53  {TET10, 3, 2, 10, 4, 6, 4},
54  {PYRIMID5, 3, 1, 5, 5, 8, 5},
55  {PYRIMID14,3, 2, 14, 5, 8, 5},
56  {PRISM6, 3, 1, 6, 6, 9, 5},
57  {PRISM15, 3, 2, 15, 6, 9, 5},
58  {PRISM18, 3, 2, 18, 6, 9, 5},
59  {HEX8, 3, 1, 8, 8, 12, 6},
60  {HEX20, 3, 2, 20, 8, 12, 6},
61  {HEX27, 3, 2, 27, 8, 12, 6}
62 };
63 
64 const int *Connectivity::get_addr( int i, int j) const throw(COM_exception) {
65  if ( _parent) return root()->get_addr( i,j);
66 
67  // Check that i is between 0 and size_of_items-1.
68  if ( i<0 || i>=size_of_items())
70  ( fullname(), Attribute::get_addr));
71 
72  int offset = ( _strd == 1) ? (j*_cap) : j;
73  return ((const int*)_ptr)+offset+i*_strd;
74 }
75 
76 void Connectivity::set_size( int nitems, int ngitems) throw(COM_exception) {
77  if ( _parent)
79  append_frame( fullname(), Connectivity::set_size));
80 
81  if ( !is_structured()) {
82  _nitems = nitems; _ngitems = ngitems;
83  _pane->refresh_connectivity();
84  }
85  else {
86  _nitems = dimension(); _ngitems = ngitems;
87  if ( initialized()) _pane->refresh_connectivity();
88  }
89 }
90 
93  _offset = offset;
94 }
95 
97 {
98  if ( !is_structured())
99  return size_of_items();
100  else {
102  "Only unstructured meshes supports inheritance without ghost");
103 
104  const int *sizes=pointer();
105  if ( sizes==NULL) return 0;
106  int n=0;
107  switch ( _size_info[TYPE_ID]) {
108  case ST1: n=sizes[0]-1; break;
109  case ST2: n=(sizes[0]-1)*(sizes[1]-1); break;
110  case ST3: n=(sizes[0]-1)*(sizes[1]-1)*(sizes[2]-1); break;
111  default: COM_assertion(false); // Should never reach here.
112  }
113  return std::max(0,n);
114  }
115 }
116 
118 {
119  if ( !is_structured())
120  return size_of_ghost_items();
121  else {
122  const int *sizes=pointer();
123  if ( sizes==NULL) return 0;
124  int n=0;
125  switch ( _size_info[TYPE_ID]) {
126  case ST1: n=2*_ngitems; break;
127  case ST2: n=(sizes[0]-1)*(sizes[1]-1)-
128  (sizes[0]-1-2*_ngitems)*(sizes[1]-1-2*_ngitems); break;
129  case ST3: n=(sizes[0]-1)*(sizes[1]-1)*(sizes[2]-1)-
130  (sizes[0]-1-2*_ngitems)*(sizes[1]-1-2*_ngitems)*
131  (sizes[2]-1-2*_ngitems); break;
132  default: COM_assertion(false); // Should never reach here.
133  }
134  return std::max(0,n);
135  }
136 }
137 
138 
140 {
141  if ( !is_structured())
142  return size_of_real_items();
143  else {
144  const int *sizes=pointer();
145  if ( sizes==NULL) return 0;
146  int n=0;
147  switch ( _size_info[TYPE_ID]) {
148  case ST1: n=sizes[0]-1-2*_ngitems; break;
149  case ST2: n=(sizes[0]-1-2*_ngitems)*(sizes[1]-1-2*_ngitems); break;
150  case ST3: n=(sizes[0]-1-2*_ngitems)*(sizes[1]-1-2*_ngitems)*
151  (sizes[2]-1-2*_ngitems); break;
152  default: COM_assertion(false); // Should never reach here.
153  }
154  return std::max(0,n);
155  }
156 }
157 
159 {
160  if ( !is_structured())
161  return _pane->size_of_nodes();
162  else {
164  "Only unstructured meshes supports inheritance without ghost");
165 
166  const int *sizes=pointer();
167  if ( sizes==NULL) return 0;
168  switch ( _size_info[TYPE_ID]) {
169  case ST1: return sizes[0];
170  case ST2: return sizes[0]*sizes[1];
171  case ST3: return sizes[0]*sizes[1]*sizes[2];
172  default: COM_assertion(false); // Should never reach here.
173  }
174  return 0;
175  }
176 }
177 
179 {
180  if ( !is_structured())
181  return _pane->size_of_ghost_nodes();
182  else {
183  const int *sizes=pointer();
184  if ( sizes==NULL) return 0;
185  switch ( _size_info[TYPE_ID]) {
186  case ST1: return 2*_ngitems;
187  case ST2: return sizes[0]*sizes[1]-
188  (sizes[0]-2*_ngitems)*(sizes[1]-2*_ngitems);
189  case ST3: return sizes[0]*sizes[1]*sizes[2]-
190  (sizes[0]-2*_ngitems)*(sizes[1]-2*_ngitems)*
191  (sizes[2]-2*_ngitems);
192  default: COM_assertion(false); // Should never reach here.
193  }
194  return 0;
195  }
196 }
197 
199 {
200  if ( !is_structured())
201  return _pane->size_of_real_nodes();
202  else {
203  const int *sizes=pointer();
204  if ( sizes==NULL) return 0;
205  switch ( _size_info[TYPE_ID]) {
206  case ST1: return sizes[0]-2*_ngitems;
207  case ST2: return (sizes[0]-2*_ngitems)*(sizes[1]-2*_ngitems);
208  case ST3: return (sizes[0]-2*_ngitems)*(sizes[1]-2*_ngitems)*
209  (sizes[2]-2*_ngitems);
210  default: COM_assertion(false); // Should never reach here.
211  }
212  return 0;
213  }
214 }
215 
216 void Connectivity::set_pointer(void *p, int strd, int cap, bool is_const)
217  throw(COM_exception)
218 {
219  if ( !is_structured()) {
220  Attribute::set_pointer( p, strd, cap, 0, is_const);
221  }
222  else {
223  int ndims = dimension();
224  Attribute::set_size( ndims, _ngitems);
225  _ptr = Attribute::allocate( 1, ndims, true);
226  copy_array( p, strd, ndims);
227 
228  // Update number of nodes and elements
229  COM_assertion( _parent==NULL);
230  _pane->refresh_connectivity();
231  }
232 }
233 
234 const int* Connectivity::get_size_info( const std::string &aname)
235 {
236  int idx = 2;
237  switch (aname[1]) {
238  case 'b':
239  while (aname[idx]=='0') idx++;
240  if ( aname[idx]=='2')
241  { COM_assertion( _sizes[BAR2][TYPE_ID]==BAR2); return _sizes[BAR2]; }
242  if ( aname[idx]=='3')
243  { COM_assertion( _sizes[BAR3][TYPE_ID]==BAR3); return _sizes[BAR3]; }
244  break;
245  case 't':
246  while (aname[idx]=='0') idx++;
247  if ( aname[idx]=='3')
248  { COM_assertion( _sizes[TRI3][TYPE_ID]==TRI3); return _sizes[TRI3]; }
249  if ( aname[idx]=='6')
250  { COM_assertion( _sizes[TRI6][TYPE_ID]==TRI6); return _sizes[TRI6]; }
251  break;
252  case 'q':
253  while (aname[idx]=='0') idx++;
254  if ( aname[idx]=='4')
255  { COM_assertion( _sizes[QUAD4][TYPE_ID]==QUAD4); return _sizes[QUAD4]; }
256  if ( aname[idx]=='8')
257  { COM_assertion( _sizes[QUAD8][TYPE_ID]==QUAD8); return _sizes[QUAD8]; }
258  if ( aname[idx]=='9')
259  { COM_assertion( _sizes[QUAD9][TYPE_ID]==QUAD9); return _sizes[QUAD9]; }
260  break;
261  case 'T':
262  while (aname[idx]=='0') idx++;
263  if ( aname[idx]=='4')
264  { COM_assertion( _sizes[TET4][TYPE_ID]==TET4); return _sizes[TET4]; }
265  if ( aname[idx]=='1' && aname[idx+1]=='0')
266  { COM_assertion( _sizes[TET10][TYPE_ID]==TET10); return _sizes[TET10]; }
267  break;
268  case 'H':
269  case 'B':
270  while (aname[idx]=='0') idx++;
271  if ( aname[idx]=='8')
272  { COM_assertion( _sizes[HEX8][TYPE_ID]==HEX8); return _sizes[HEX8]; }
273  if ( aname[idx]=='2') {
274  if ( aname[idx+1]=='0')
275  { COM_assertion( _sizes[HEX20][TYPE_ID]==HEX20); return _sizes[HEX20]; }
276  if ( aname[idx+1]=='7')
277  { COM_assertion( _sizes[HEX27][TYPE_ID]==HEX27); return _sizes[HEX27]; }
278  }
279  break;
280  case 'P':
281  while (aname[idx]=='0') idx++;
282  if ( aname[idx]=='5') {
284  return _sizes[PYRIMID5];
285  }
286  if ( aname[idx]=='6') {
288  return _sizes[PRISM6];
289  }
290 
291  if ( aname[idx]=='1') {
292  if ( aname[idx+1] == '4') {
294  return _sizes[PYRIMID14];
295  }
296 
297  if ( aname[idx+1] == '5') {
299  return _sizes[PRISM15];
300  }
301 
302  if ( aname[idx+1] == '8') {
304  return _sizes[PRISM18];
305  }
306  }
307  break;
308  case 'W':
309  while (aname[idx]=='0') idx++;
310  if ( aname[idx]=='6') {
312  return _sizes[PRISM6];
313  }
314 
315  if ( aname[idx]=='1') {
316  if ( aname[idx+1] == '5') {
318  return _sizes[PRISM15];
319  }
320 
321  if ( aname[idx+1] == '8') {
323  return _sizes[PRISM18];
324  }
325  }
326  break;
327  case 's':
328  if ( aname[idx++]=='t') {
329  while (aname[idx]=='0') idx++;
330  if ( aname[idx]=='3')
331  { COM_assertion( _sizes[ST3][TYPE_ID]==ST3); return _sizes[ST3]; }
332 
333  if ( aname[idx]=='2')
334  { COM_assertion( _sizes[ST2][TYPE_ID]==ST2); return _sizes[ST2]; }
335 
336  if ( aname[idx]=='1')
337  { COM_assertion( _sizes[ST1][TYPE_ID]==ST1); return _sizes[ST1]; }
338  }
339  break;
340  default: break;
341  }
342 
343  return NULL;
344 }
345 
346 COM_END_NAME_SPACE
347 
348 
349 
350 
351 
352 
Size size_of_ghost_elements() const
Get the number of ghost elements.
Definition: Connectivity.C:117
int _ngitems
Size of ghost items.
Definition: Attribute.h:313
#define COM_assertion(EX)
Error checking utility similar to the assert macro of the C language.
const int * pointer() const
Get a constant pointer to the connectivity array.
Definition: Connectivity.h:206
void set_pointer(void *p, int strd, int cap, int offset, bool is_const)
Set the physical address of the attribute values.
Definition: Attribute.C:208
Contains the prototypes for the Pane object.
bool is_structured() const
Determine whether the mesh is quadratic.
Definition: Connectivity.h:128
#define COM_assertion_msg(EX, msg)
const void * get_addr(int i, int j=0) const
Obtain the address of the jth component of the ith item, where 0&lt;=i&lt;size_of_items.
Definition: Attribute.C:85
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
Size size_of_ghost_nodes() const
Get the number of ghost nodes.
Definition: Pane.h:126
real *8 function offset(vNorm, x2, y2, z2)
Definition: PlaneNorm.f90:211
Size size_of_ghost_nodes() const
Get the number of ghost nodes of the owner pane.
Definition: Connectivity.C:178
static const int * get_size_info(const std::string &aname)
Obtain the size info of pre-defined connectivity.
Definition: Connectivity.C:234
Encapsulates the states of an exception.
unsigned int Size
Unsighed int.
Definition: Attribute.h:54
int size_of_ghost_items() const
Obtain the number of ghost items in the attribute.
Definition: Attribute.C:139
Size size_of_nodes() const
Get the total number of nodes (including ghost nodes) of the owner pane.
Definition: Connectivity.C:158
bool ignore_ghost() const
Definition: Pane.h:202
Pane * _pane
Pointer to its owner pane.
Definition: Attribute.h:298
Size size_of_real_elements() const
Get the number of real elements.
Definition: Connectivity.C:139
void set_pointer(void *p, int strd, int cap, bool is_const)
Set pointer of connectivity table.
Definition: Connectivity.C:216
blockLoc i
Definition: read.cpp:79
const int * _size_info
Definition: Connectivity.h:256
This file contains a set of routines for error assertion.
const NT & n
void set_offset(Size offset)
Set the index of the first element.
Definition: Connectivity.C:92
Contains the prototype of Connectivity.
void set_size(int nitems, int ngitems=0)
Set the size of items and ghost items.
Definition: Attribute.C:191
int size_of_real_items() const
Obtain the number of real items in the attribute.
Definition: Attribute.C:167
unsigned int Size
Unsighed int.
Definition: Attribute.h:54
void set_size(int nitems, int ngitems=0)
Set the size of items and ghost items.
Definition: Connectivity.C:76
Size size_of_real_nodes() const
Get the number of real nodes in the pane (excluding ghost nodes).
Definition: Pane.h:134
#define append_frame(s, frame)
Macro for appending the information about the given frame to the string s.
j indices j
Definition: Indexing.h:6
Size size_of_nodes() const
Get the total number of nodes in the pane (including ghost nodes).
Definition: Pane.h:118
const int * get_addr(int i, int j=0) const
Obtain the address of the jth component of the ith item, where 0&lt;=i&lt;size_of_items.
Definition: Connectivity.C:64
void * allocate(int strd, int cap, bool force)
Allocate memory for the attribute.
Definition: Attribute.C:345
Size size_of_elements() const
Get the total number of elements (including ghost elements) in the table.
Definition: Connectivity.C:96
static const int _sizes[TYPE_MAX_CONN][SIZE_MAX_CONN]
Definition: Connectivity.h:258
Size size_of_real_nodes() const
Get the number of real nodes of the owner pane.
Definition: Connectivity.C:198
int size_of_items() const
Obtain the number of items in the attribute.
Definition: Attribute.C:111