Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Generic_element_2.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: Generic_element_2.C,v 1.3 2008/12/06 08:43:23 mtcampbe Exp $
24 
25 #include "Generic_element_2.h"
26 #include <cmath>
27 #include <cassert>
28 #include <algorithm>
29 
31 
33  : _nedges( ne), _nnodes( std::max(ne,nn)), _order( 1+ (_nedges!=_nnodes)) {
34  assert( ne==3 || ne==4);
35  assert( _nnodes==ne || _nnodes==ne+ne);
36 }
37 
38 
39 // This function evaluates the shape function of an element. It
40 // computes the barycentric coordinates from the natural coordinates.
41 void
43  switch ( _nnodes) {
44  case 3: {
45  N[0] = 1. - nc[0] - nc[1];
46  N[1] = nc[0];
47  N[2] = nc[1];
48  return;
49  }
50  case 4: {
51  const Real xi = nc[0], xi_minus = 1. - xi;
52  const Real eta = nc[1], eta_minus = 1. - eta;
53 
54  N[0] = xi_minus * eta_minus;
55  N[1] = xi * eta_minus;
56  N[2] = xi * eta;
57  N[3] = xi_minus * eta;
58  return;
59  }
60  case 6: {
61  const Real xi=nc[0], eta=nc[1], zeta=1.-xi-eta;
62  N[0] = 2*zeta*zeta-zeta;
63  N[1] = 2*xi*xi-xi;
64  N[2] = 2*eta*eta-eta;
65  N[3] = 4*zeta*xi;
66  N[4] = 4*xi*eta;
67  N[5] = 4*eta*zeta;
68 
69  return;
70  }
71  case 8: {
72  const Real xi = nc[0], xi_minus = 1. - xi;
73  const Real eta = nc[1], eta_minus = 1. - eta;
74 
75  N[0] = xi_minus * eta_minus * (1. - 2.*xi - 2.*eta);
76  N[1] = xi * eta_minus * (-1. + 2.*xi - 2.*eta);
77  N[2] = xi * eta * (-3. + 2.*xi + 2.*eta);
78  N[3] = xi_minus * eta * (-1. - 2.*xi + 2.*eta);
79  N[4] = 4. * xi_minus * eta_minus * xi;
80  N[5] = 4. * xi * eta_minus * eta;
81  N[6] = 4. * xi * eta * xi_minus;
82  N[7] = 4. * xi_minus * eta * eta_minus;
83 
84  return;
85  }
86  default:
87  abort(); // Should never reach here
88  }
89 }
90 
91 // This function evaluates the shape function of an element. It
92 // computes the barycentric coordinates from the natural coordinates.
93 void
95  switch ( _nnodes) {
96  case 3: {
97  Np[0][0] = -1; Np[0][1] = -1.;
98  Np[1][0] = 1; Np[1][1] = 0;
99  Np[2][0] = 0; Np[2][1] = 1;
100  return;
101  }
102  case 4: {
103  const Real xi = nc[0], xi_minus = 1. - xi;
104  const Real eta = nc[1], eta_minus = 1. - eta;
105 
106  Np[0][0] = -eta_minus; Np[0][1] = -xi_minus;
107  Np[1][0] = eta_minus; Np[1][1] = -xi;
108  Np[2][0] = eta; Np[2][1] = xi;
109  Np[3][0] = -eta; Np[3][1] = xi_minus;
110 
111  return;
112  }
113  case 6: {
114  const Real xi=nc[0], eta=nc[1], zeta=1.-xi-eta;
115 
116  Np[0][0] = 1.-4.*zeta; Np[0][1] = 1.-4.*zeta;
117  Np[1][0] = 4.*xi-1; Np[1][1] = 0;
118  Np[2][0] = 0; Np[2][1] = 4*eta-1;
119  Np[3][0] = 4*(zeta-xi); Np[3][1] = -4*xi;
120  Np[4][0] = 4*eta; Np[4][1] = 4*xi;
121  Np[5][0] = -4*eta; Np[5][1] = 4*(zeta-eta);
122 
123  return;
124  }
125  case 8: {
126  const Real xi = nc[0], xi_minus = 1. - xi;
127  const Real eta = nc[1], eta_minus = 1. - eta;
128 
129  Np[0][0] = eta_minus * ( -3+4*xi+2*eta); Np[0][1] = xi_minus * ( -3+4*eta+2*xi);
130  Np[1][0] = eta_minus * ( -1+4*xi-2*eta); Np[1][1] = xi * (1-2*xi+4.*eta);
131  Np[2][0] = eta * ( -3+4*xi+2*eta); Np[2][1] = xi * ( -3+4*eta+2*xi);
132  Np[3][0] = eta * ( 1 + 4*xi-2*eta); Np[3][1] = xi_minus * ( -1-2*xi+4.*eta);
133  Np[4][0] = eta_minus * (-8 * xi); Np[4][1] = -4*xi*xi_minus;
134  Np[5][0] = 4*eta_minus*eta; Np[5][1] = xi*(-8*eta);
135  Np[6][0] = eta * (-8 * xi); Np[6][1] = 4*xi*xi_minus;
136  Np[7][0] = -4*eta*eta_minus; Np[7][1] = xi_minus*(-8*eta);
137 
138  }
139  default:
140  abort(); // Should never reach here
141  }
142 }
143 
146  if ( std::max( doa, _order)==1) {
147  return _nedges==3 ? 1 : 4;
148  }
149  else if ( std::max( doa, _order)==2) {
150  return _nedges==3 ? 3: 9;
151  }
152  else {
153  assert( std::max( doa, _order)==4 && _nedges==3);
154  return _nedges==3 ? 6: 9;
155  }
156 }
157 
159 Generic_element_2::get_gp_weight( const Size i, const Size doa) const {
160  if ( std::max( doa, _order)==1) {
161  return (_nedges == 3) ? 1./2. : 1./4.;
162  }
163  else if ( std::max( doa, _order)==2) {
164  if ( _nedges==3)
165  return 1./6.;
166  else {
167  if (i==8) return 16./81.;
168  else if (i<4) return 25./324.;
169  else return 10./81.;
170  }
171  }
172  else {
173  assert( std::max( doa, _order)==4 && _nedges==3);
174 
175  return (i<3) ? 0.054975871827661 : 0.1116907948390055;
176  }
177 }
178 
179 // This function evaluates the natural coordinates of
180 // the Gaussian Qadrature points of an element.
181 void
183  const Size doa) const {
184  if ( std::max( doa, _order)==1) {
185  if ( _nedges==3)
186  nc = Nat_coor( 0.333333333333333, 0.333333333333333);
187  else {
188  const Real coors[4][2] = { {0.2113248654051871, 0.2113248654051871},
189  {0.2113248654051871, 0.7886751345948129},
190  {0.7886751345948129, 0.2113248654051871},
191  {0.7886751345948129, 0.7886751345948129}};
192  nc = Nat_coor( coors[i][0], coors[i][1]);
193  }
194  }
195  else if ( std::max( doa, _order)==2) {
196  if ( _nedges == 3) {
197  const Real coors[3][2] = { {0.666666666666667, 0.166666666666667},
198  {0.166666666666667, 0.666666666666667},
199  {0.166666666666667, 0.166666666666667}};
200  nc = Nat_coor( coors[i][0], coors[i][1]);
201  }
202  else {
203  const Real coors[9][2] = { {0.112701665379258, 0.112701665379258},
204  {0.887298334620742, 0.112701665379258},
205  {0.887298334620742, 0.887298334620742},
206  {0.112701665379258, 0.887298334620742},
207  {0.5, 0.112701665379258},
208  {0.887298334620742, 0.5 },
209  {0.5, 0.887298334620742},
210  {0.112701665379258, 0.5 },
211  {0.5, 0.5 }};
212  nc = Nat_coor( coors[i][0], coors[i][1]);
213  }
214  }
215  else {
216  assert( std::max( doa, _order)==4 && _nedges==3);
217 
218  const Real coors[6][2] = { {0.816847572980459, 0.091576213509771},
219  {0.091576213509771, 0.816847572980459},
220  {0.091576213509771, 0.091576213509771},
221  {0.108103018168070, 0.445948490915965},
222  {0.445948490915965, 0.108103018168070},
223  {0.445948490915965, 0.445948490915965}};
224  nc = Nat_coor( coors[i][0], coors[i][1]);
225  }
226 }
227 
228 
229 // J contains row vectors, b and x contain column vectors
231 solve( const Vector_3 J[2], Vector_3 x[], const Vector_2 b[]) const {
232  Real area_sq = Vector_3::cross_product( J[0], J[1]).squared_norm();
233  Vector_2 t[2] = { Vector_2( J[1]*J[1]/area_sq, J[0]*J[1]/-area_sq),
234  Vector_2( J[1]*J[0]/-area_sq, J[0]*J[0]/area_sq) };
235 
236  // Jinv = J'(JJ')^-1, containing column vectors
237  Vector_3 Jinv[2] = { J[0]*t[0][0]+=J[1]*t[1][0], J[0]*t[0][1]+=J[1]*t[1][1]};
238 
239  for ( unsigned int i=0; i<size_of_nodes(); ++i) {
240  x[i] = Jinv[0]*b[i][0] += Jinv[1]*b[i][1];
241  }
242 }
243 
245 
246 
247 
248 
249 
250 
SURF::Vector_2< Real > Vector_2
void shape_func_deriv(const Nat_coor &nc, Vector_2 Np[]) const
Evaluates the derivatives of the shape functions.
#define SURF_END_NAMESPACE
Definition: surfbasic.h:29
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
void get_gp_nat_coor(const Size i, Nat_coor &nc, const Size doa=0) const
Get the natrual coordinate associated with a Gauss point.
Real get_gp_weight(const Size i, const Size doa=0) const
Get the weight associated with a Gauss point.
#define SURF_BEGIN_NAMESPACE
Definition: surfbasic.h:28
Generic_element_2(Size ne, Size nn=0)
Constructor.
void solve(const Vector_3 M[2], Vector_3 x[], const Vector_2 b[]) const
void shape_func(const Nat_coor &nc, Real N[]) const
Evaluates the shape functions of the element and output the barycentric coordinates into the array N...
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
Type squared_norm() const
Definition: mapbasic.h:110
static Vector_3 cross_product(const Vector_3 &v, const Vector_3 &w)
Definition: mapbasic.h:104
Size size_of_nodes() const
Number of nodes.
Size get_num_gp(const Size doa=0) const
Get the number of Gauss points.
Some basic geometric data types.
Definition: mapbasic.h:54