Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
moab::Element::SpectralQuad Class Reference

#include <ElemUtil.hpp>

+ Inheritance diagram for moab::Element::SpectralQuad:
+ Collaboration diagram for moab::Element::SpectralQuad:

Public Member Functions

 SpectralQuad (const std::vector< CartVect > &vertices)
 
 SpectralQuad (int order, double *x, double *y, double *z)
 
 SpectralQuad (int order)
 
 SpectralQuad ()
 
virtual ~SpectralQuad ()
 
void set_gl_points (double *x, double *y, double *z)
 
virtual CartVect evaluate (const CartVect &xi) const
 Evaluate the map on \(x_i\) (calculate \(\vec x = F($\vec \xi)\) ) More...
 
virtual CartVect ievaluate (const CartVect &x, double tol=1e-6, const CartVect &x0=CartVect(0.0)) const
 Evaluate the inverse map (calculate \(\vec \xi = F^-1($\vec x)\) to given tolerance) More...
 
virtual Matrix3 jacobian (const CartVect &xi) const
 Evaluate the map's Jacobi matrix. More...
 
double evaluate_scalar_field (const CartVect &xi, const double *field_vertex_values) const
 Evaluate a scalar field at a point given field values at the vertices. More...
 
double integrate_scalar_field (const double *field_vertex_values) const
 Integrate a scalar field over the element given field values at the vertices. More...
 
bool inside_nat_space (const CartVect &xi, double &tol) const
 decide if within the natural param space, with a tolerance More...
 
void Init (int order)
 
void freedata ()
 
void compute_gl_positions ()
 
void get_gl_points (double *&x, double *&y, double *&z, int &size)
 
- Public Member Functions inherited from moab::Element::Map
 Map (const std::vector< CartVect > &v)
 Construct a Map defined by the given std::vector of vertices. More...
 
 Map (const unsigned int n)
 Construct a Map defined by n vertices. More...
 
virtual ~Map ()
 
virtual Matrix3 ijacobian (const CartVect &xi) const
 Evaluate the inverse of the Jacobi matrix. More...
 
virtual double det_jacobian (const CartVect &xi) const
 Evaluate the determinate of the Jacobi matrix. More...
 
virtual double det_ijacobian (const CartVect &xi) const
 Evaluate the determinate of the inverse Jacobi matrix. More...
 
unsigned int size ()
 Size of the vertices vector. More...
 
const std::vector< CartVect > & get_vertices ()
 Retrieve vertices. More...
 
virtual void set_vertices (const std::vector< CartVect > &v)
 Set vertices.
More...
 
virtual bool inside_box (const CartVect &xi, double &tol) const
 

Protected Attributes

realType_xyz [3]
 
- Protected Attributes inherited from moab::Element::Map
std::vector< CartVectvertex
 

Static Protected Attributes

static int _n
 
static realType_z [2]
 
static lagrange_data _ld [2]
 
static opt_data_2 _data
 
static realType_odwork
 
static bool _init = false
 
static realType_glpoints
 

Detailed Description

Definition at line 421 of file ElemUtil.hpp.

Constructor & Destructor Documentation

◆ SpectralQuad() [1/4]

moab::Element::SpectralQuad::SpectralQuad ( const std::vector< CartVect > &  vertices)
inline

Definition at line 424 of file ElemUtil.hpp.

424  : Map( vertices )
425  {
426  _xyz[0] = _xyz[1] = _xyz[2] = NULL;
427  };

References _xyz.

◆ SpectralQuad() [2/4]

moab::Element::SpectralQuad::SpectralQuad ( int  order,
double *  x,
double *  y,
double *  z 
)

Definition at line 18 of file SpectralQuad.cpp.

18  : Map( 0 )
19 {
20  Init( order );
21  _xyz[0] = x;
22  _xyz[1] = y;
23  _xyz[2] = z;
24 }

References _xyz, and Init().

◆ SpectralQuad() [3/4]

moab::Element::SpectralQuad::SpectralQuad ( int  order)

Definition at line 25 of file SpectralQuad.cpp.

25  : Map( 4 )
26 {
27  Init( order );
28  _xyz[0] = _xyz[1] = _xyz[2] = NULL;
29 }

References _xyz, and Init().

◆ SpectralQuad() [4/4]

moab::Element::SpectralQuad::SpectralQuad ( )

Definition at line 16 of file SpectralQuad.cpp.

16 : Map( 0 ) {}

◆ ~SpectralQuad()

moab::Element::SpectralQuad::~SpectralQuad ( )
virtual

Definition at line 30 of file SpectralQuad.cpp.

31 {
32  if( _init ) freedata();
33  _init = false;
34 }

References _init, and freedata().

Member Function Documentation

◆ compute_gl_positions()

void moab::Element::SpectralQuad::compute_gl_positions ( )

Definition at line 173 of file SpectralQuad.cpp.

174 {
175  // will need to use shape functions on a simple linear quad to compute gl points
176  // so we know the position of gl points in parametric space, we will just compute those
177  // from the 3d vertex position (corner nodes of the quad), using simple mapping
178  assert( this->vertex.size() == 4 );
179  static double corner_params[4][2] = { { -1., -1. }, { 1., -1. }, { 1., 1. }, { -1., 1. } };
180  // we will use the cached lobatto nodes in parametric space _z[d] (the same in both directions)
181  int indexGL = 0;
182  int n2 = _n * _n;
183  for( int i = 0; i < _n; i++ )
184  {
185  double csi = _z[0][i];
186  for( int j = 0; j < _n; j++ )
187  {
188  double eta = _z[1][j]; // we could really use the same _z[0] array of lobatto nodes
189  CartVect pos( 0.0 );
190  for( int k = 0; k < 4; k++ )
191  {
192  const double N_k = ( 1 + csi * corner_params[k][0] ) * ( 1 + eta * corner_params[k][1] );
193  pos += N_k * vertex[k];
194  }
195  pos *= 0.25; // these are x, y, z of gl points; reorder them
196  _glpoints[indexGL] = pos[0]; // x
197  _glpoints[indexGL + n2] = pos[1]; // y
198  _glpoints[indexGL + 2 * n2] = pos[2]; // z
199  indexGL++;
200  }
201  }
202  // now, we can set the _xyz pointers to internal memory allocated to these!
203  _xyz[0] = &( _glpoints[0] );
204  _xyz[1] = &( _glpoints[n2] );
205  _xyz[2] = &( _glpoints[2 * n2] );
206 }

References _glpoints, _n, _xyz, and _z.

Referenced by test_spectral_quad().

◆ evaluate()

CartVect moab::Element::SpectralQuad::evaluate ( const CartVect xi) const
virtual

Evaluate the map on \(x_i\) (calculate \(\vec x = F($\vec \xi)\) )

Implements moab::Element::Map.

Definition at line 1298 of file ElemUtil.cpp.

1299  {
1300  // piece that we shouldn't want to cache
1301  int d = 0;
1302  for( d = 0; d < 2; d++ )
1303  {
1304  lagrange_0( &_ld[d], xi[d] );
1305  }
1306  CartVect result;
1307  for( d = 0; d < 3; d++ )
1308  {
1309  result[d] = tensor_i2( _ld[0].J, _ld[0].n, _ld[1].J, _ld[1].n, _xyz[d], _odwork );
1310  }
1311  return result;
1312  }

References _ld, _odwork, _xyz, lagrange_0(), and tensor_i2().

◆ evaluate_scalar_field()

double moab::Element::SpectralQuad::evaluate_scalar_field ( const CartVect xi,
const double *  field_vertex_values 
) const
virtual

Evaluate a scalar field at a point given field values at the vertices.

Implements moab::Element::Map.

Definition at line 1343 of file ElemUtil.cpp.

1344  {
1345  // piece that we shouldn't want to cache
1346  int d;
1347  for( d = 0; d < 2; d++ )
1348  {
1349  lagrange_0( &_ld[d], xi[d] );
1350  }
1351 
1352  double value = tensor_i2( _ld[0].J, _ld[0].n, _ld[1].J, _ld[1].n, field, _odwork );
1353  return value;
1354  }

References _ld, _odwork, lagrange_0(), and tensor_i2().

◆ freedata()

void moab::Element::SpectralQuad::freedata ( )

Definition at line 60 of file SpectralQuad.cpp.

61 {
62  for( int d = 0; d < 2; d++ )
63  {
64  free( _z[d] );
65  lagrange_free( &_ld[d] );
66  }
67  opt_free_2( &_data );
68  free( _odwork );
69  free( _glpoints );
70 }

References _data, _glpoints, _ld, _odwork, _z, lagrange_free(), and opt_free_2().

Referenced by Init(), and ~SpectralQuad().

◆ get_gl_points()

void moab::Element::SpectralQuad::get_gl_points ( double *&  x,
double *&  y,
double *&  z,
int &  size 
)

Definition at line 207 of file SpectralQuad.cpp.

208 {
209  x = (double*)_xyz[0];
210  y = (double*)_xyz[1];
211  z = (double*)_xyz[2];
212  size = _n * _n;
213 }

References _n, _xyz, and moab::Element::Map::size().

Referenced by test_spectral_quad().

◆ ievaluate()

CartVect moab::Element::SpectralQuad::ievaluate ( const CartVect x,
double  tol = 1e-6,
const CartVect x0 = CartVect( 0.0 ) 
) const
virtual

Evaluate the inverse map (calculate \(\vec \xi = F^-1($\vec x)\) to given tolerance)

Reimplemented from moab::Element::Map.

Definition at line 1314 of file ElemUtil.cpp.

1315  {
1316  // find nearest point
1317  realType x_star[3];
1318  xyz.get( x_star );
1319 
1320  realType r[2] = { 0, 0 }; // initial guess for parametric coords
1321  unsigned c = opt_no_constraints_3;
1322  realType dist = opt_findpt_2( &_data, (const realType**)_xyz, x_star, r, &c );
1323  // if it did not converge, get out with throw...
1324  if( dist > 0.9e+30 )
1325  {
1326  std::vector< CartVect > dummy;
1327  throw Map::EvaluationError( xyz, dummy );
1328  }
1329 
1330  // c tells us if we landed inside the element or exactly on a face, edge, or node
1331  // also, dist shows the distance to the computed point.
1332  // copy parametric coords back
1333  return CartVect( r[0], r[1], 0. );
1334  }

References _data, _xyz, moab::CartVect::get(), opt_findpt_2(), and opt_no_constraints_3.

◆ Init()

void moab::Element::SpectralQuad::Init ( int  order)

Definition at line 35 of file SpectralQuad.cpp.

36 {
37  if( _init && _n == order ) return;
38  if( _init && _n != order )
39  {
40  // TODO: free data cached
41  freedata();
42  }
43  // compute stuff that depends only on order
44  _init = true;
45  _n = order;
46  // duplicates! n is the same in all directions !!!
47  for( int d = 0; d < 2; d++ )
48  {
49  _z[d] = tmalloc( double, _n );
50  lobatto_nodes( _z[d], _n );
51  lagrange_setup( &_ld[d], _z[d], _n );
52  }
53  opt_alloc_2( &_data, _ld );
54 
55  unsigned int nf = _n * _n, ne = _n, nw = 2 * _n * _n + 3 * _n;
56  _odwork = tmalloc( double, 6 * nf + 9 * ne + nw );
57  _glpoints = tmalloc( double, 3 * nf );
58 }

References _data, _glpoints, _init, _ld, _n, _odwork, _z, freedata(), lagrange_setup(), lobatto_nodes(), opt_alloc_2(), and tmalloc.

Referenced by SpectralQuad().

◆ inside_nat_space()

bool moab::Element::SpectralQuad::inside_nat_space ( const CartVect xi,
double &  tol 
) const
virtual

decide if within the natural param space, with a tolerance

Implements moab::Element::Map.

Definition at line 1360 of file ElemUtil.cpp.

1361  {
1362  // just look at the box+tol here
1363  return ( xi[0] >= -1. - tol ) && ( xi[0] <= 1. + tol ) && ( xi[1] >= -1. - tol ) && ( xi[1] <= 1. + tol );
1364  }

◆ integrate_scalar_field()

double moab::Element::SpectralQuad::integrate_scalar_field ( const double *  field_vertex_values) const
virtual

Integrate a scalar field over the element given field values at the vertices.

Implements moab::Element::Map.

Definition at line 1355 of file ElemUtil.cpp.

1356  {
1357  return 0.; // not implemented
1358  }

◆ jacobian()

Matrix3 moab::Element::SpectralQuad::jacobian ( const CartVect xi) const
virtual

Evaluate the map's Jacobi matrix.

Implements moab::Element::Map.

Definition at line 132 of file SpectralQuad.cpp.

138 {
139  // not implemented
140  Matrix3 J( 0. );
141  return J;
142 }

◆ set_gl_points()

void moab::Element::SpectralQuad::set_gl_points ( double *  x,
double *  y,
double *  z 
)

Definition at line 72 of file SpectralQuad.cpp.

73 {
74  _xyz[0] = x;
75  _xyz[1] = y;
76  _xyz[2] = z;
77 }

References _xyz.

Member Data Documentation

◆ _data

opt_data_2 moab::Element::SpectralQuad::_data
staticprotected

Definition at line 456 of file ElemUtil.hpp.

Referenced by freedata(), ievaluate(), Init(), and moab::SpectralQuad::reverseEvalFcn().

◆ _glpoints

realType * moab::Element::SpectralQuad::_glpoints
staticprotected

Definition at line 461 of file ElemUtil.hpp.

Referenced by compute_gl_positions(), freedata(), and Init().

◆ _init

bool moab::Element::SpectralQuad::_init = false
staticprotected

Definition at line 460 of file ElemUtil.hpp.

Referenced by Init(), and ~SpectralQuad().

◆ _ld

lagrange_data moab::Element::SpectralQuad::_ld
staticprotected

◆ _n

int moab::Element::SpectralQuad::_n
staticprotected

Definition at line 453 of file ElemUtil.hpp.

Referenced by compute_gl_positions(), get_gl_points(), and Init().

◆ _odwork

realType * moab::Element::SpectralQuad::_odwork
staticprotected

◆ _xyz

◆ _z

realType * moab::Element::SpectralQuad::_z
staticprotected

Definition at line 454 of file ElemUtil.hpp.

Referenced by compute_gl_positions(), freedata(), and Init().


The documentation for this class was generated from the following files: