Processing math: 16%
Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
moab::Element::SpectralHex Class Reference

#include <ElemUtil.hpp>

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

Public Member Functions

 SpectralHex (const std::vector< CartVect > &vertices)
 
 SpectralHex (int order, double *x, double *y, double *z)
 
 SpectralHex (int order)
 
 SpectralHex ()
 
virtual ~SpectralHex ()
 
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 ()
 
- 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 [3]
 
static lagrange_data _ld [3]
 
static opt_data_3 _data
 
static realType_odwork
 
static bool _init = false
 

Detailed Description

Definition at line 243 of file ElemUtil.hpp.

Constructor & Destructor Documentation

◆ SpectralHex() [1/4]

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

Definition at line 246 of file ElemUtil.hpp.

246  : Map( vertices ) 247  { 248  _xyz[0] = _xyz[1] = _xyz[2] = NULL; 249  };

References _xyz.

◆ SpectralHex() [2/4]

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

Definition at line 955 of file ElemUtil.cpp.

955  : Map( 0 ) 956  { 957  Init( order ); 958  _xyz[0] = x; 959  _xyz[1] = y; 960  _xyz[2] = z; 961  }

References _xyz, and Init().

◆ SpectralHex() [3/4]

moab::Element::SpectralHex::SpectralHex ( int  order)

Definition at line 962 of file ElemUtil.cpp.

962  : Map( 0 ) 963  { 964  Init( order ); 965  _xyz[0] = _xyz[1] = _xyz[2] = NULL; 966  }

References _xyz, and Init().

◆ SpectralHex() [4/4]

moab::Element::SpectralHex::SpectralHex ( )

Definition at line 950 of file ElemUtil.cpp.

950  : Map( 0 ) 951  { 952  _xyz[0] = _xyz[1] = _xyz[2] = NULL; 953  }

References _xyz.

◆ ~SpectralHex()

moab::Element::SpectralHex::~SpectralHex ( )
virtual

Definition at line 967 of file ElemUtil.cpp.

968  { 969  if( _init ) freedata(); 970  _init = false; 971  }

References _init, and freedata().

Member Function Documentation

◆ evaluate()

CartVect moab::Element::SpectralHex::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 58 of file SpectralHex.cpp.

59 { 60  // piece that we shouldn't want to cache 61  int d = 0; 62  for( d = 0; d < 3; d++ ) 63  { 64  lagrange_0( &_ld[d], params[d] ); 65  } 66  CartVect result; 67  for( d = 0; d < 3; d++ ) 68  { 69  result[d] = tensor_i3( _ld[0].J, _ld[0].n, _ld[1].J, _ld[1].n, _ld[2].J, _ld[2].n, 70  _xyz[d], // this is the "field" 71  _odwork ); 72  } 73  return result; 74 }

References moab::SpectralHex::_ld, moab::SpectralHex::_odwork, lagrange_0(), and tensor_i3().

Referenced by test_spectral_hex().

◆ evaluate_scalar_field()

double moab::Element::SpectralHex::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 1073 of file ElemUtil.cpp.

1074  { 1075  // piece that we shouldn't want to cache 1076  int d; 1077  for( d = 0; d < 3; d++ ) 1078  { 1079  lagrange_0( &_ld[d], xi[d] ); 1080  } 1081  1082  double value = tensor_i3( _ld[0].J, _ld[0].n, _ld[1].J, _ld[1].n, _ld[2].J, _ld[2].n, field, _odwork ); 1083  return value; 1084  }

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

Referenced by moab::Coupler::interp_field(), and test_spectral_hex().

◆ freedata()

void moab::Element::SpectralHex::freedata ( )

Definition at line 41 of file SpectralHex.cpp.

42 { 43  for( int d = 0; d < 3; d++ ) 44  { 45  free( _z[d] ); 46  lagrange_free( &_ld[d] ); 47  } 48  opt_free_3( &_data ); 49  free( _odwork ); 50 }

References moab::SpectralHex::_data, moab::SpectralHex::_ld, moab::SpectralHex::_odwork, moab::SpectralHex::_z, lagrange_free(), and opt_free_3().

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

◆ ievaluate()

CartVect moab::Element::SpectralHex::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 1030 of file ElemUtil.cpp.

1031  { 1032  // find nearest point 1033  realType x_star[3]; 1034  xyz.get( x_star ); 1035  1036  realType r[3] = { 0, 0, 0 }; // initial guess for parametric coords 1037  x0.get( r ); 1038  unsigned c = opt_no_constraints_3; 1039  realType dist = opt_findpt_3( &_data, (const realType**)_xyz, x_star, r, &c ); 1040  // if it did not converge, get out with throw... 1041  if( dist > 10 * tol ) // outside the element 1042  { 1043  std::vector< CartVect > dummy; 1044  throw Map::EvaluationError( xyz, dummy ); 1045  } 1046  // c tells us if we landed inside the element or exactly on a face, edge, or node 1047  // also, dist shows the distance to the computed point. 1048  // copy parametric coords back 1049  return CartVect( r ); 1050  }

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

Referenced by moab::Coupler::nat_param(), and test_spectral_hex().

◆ Init()

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

Definition at line 972 of file ElemUtil.cpp.

973  { 974  if( _init && _n == order ) return; 975  if( _init && _n != order ) 976  { 977  // TODO: free data cached 978  freedata(); 979  } 980  // compute stuff that depends only on order 981  _init = true; 982  _n = order; 983  // triplicates! n is the same in all directions !!! 984  for( int d = 0; d < 3; d++ ) 985  { 986  _z[d] = tmalloc( realType, _n ); 987  lobatto_nodes( _z[d], _n ); 988  lagrange_setup( &_ld[d], _z[d], _n ); 989  } 990  opt_alloc_3( &_data, _ld ); 991  992  unsigned int nf = _n * _n, ne = _n, nw = 2 * _n * _n + 3 * _n; 993  _odwork = tmalloc( realType, 6 * nf + 9 * ne + nw ); 994  }

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

Referenced by SpectralHex().

◆ inside_nat_space()

bool moab::Element::SpectralHex::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 1134 of file ElemUtil.cpp.

1135  { 1136  // just look at the box+tol here 1137  return ( xi[0] >= -1. - tol ) && ( xi[0] <= 1. + tol ) && ( xi[1] >= -1. - tol ) && ( xi[1] <= 1. + tol ) && 1138  ( xi[2] >= -1. - tol ) && ( xi[2] <= 1. + tol ); 1139  }

Referenced by moab::Coupler::nat_param().

◆ integrate_scalar_field()

double moab::Element::SpectralHex::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 1085 of file ElemUtil.cpp.

1086  { 1087  // set the position of GL points 1088  // set the positions of GL nodes, before evaluations 1089  _data.elx[0] = _xyz[0]; 1090  _data.elx[1] = _xyz[1]; 1091  _data.elx[2] = _xyz[2]; 1092  double xi[3]; 1093  // triple loop; the most inner loop is in r direction, then s, then t 1094  double integral = 0.; 1095  // double volume = 0; 1096  int index = 0; // used fr the inner loop 1097  for( int k = 0; k < _n; k++ ) 1098  { 1099  xi[2] = _ld[2].z[k]; 1100  // double wk= _ld[2].w[k]; 1101  for( int j = 0; j < _n; j++ ) 1102  { 1103  xi[1] = _ld[1].z[j]; 1104  // double wj= _ld[1].w[j]; 1105  for( int i = 0; i < _n; i++ ) 1106  { 1107  xi[0] = _ld[0].z[i]; 1108  // double wi= _ld[0].w[i]; 1109  opt_vol_set_intp_3( &_data, xi ); 1110  double wk = _ld[2].J[k]; 1111  double wj = _ld[1].J[j]; 1112  double wi = _ld[0].J[i]; 1113  Matrix3 J( 0. ); 1114  // it is organized differently 1115  J( 0, 0 ) = _data.jac[0]; // dx/dr 1116  J( 0, 1 ) = _data.jac[1]; // dx/ds 1117  J( 0, 2 ) = _data.jac[2]; // dx/dt 1118  J( 1, 0 ) = _data.jac[3]; // dy/dr 1119  J( 1, 1 ) = _data.jac[4]; // dy/ds 1120  J( 1, 2 ) = _data.jac[5]; // dy/dt 1121  J( 2, 0 ) = _data.jac[6]; // dz/dr 1122  J( 2, 1 ) = _data.jac[7]; // dz/ds 1123  J( 2, 2 ) = _data.jac[8]; // dz/dt 1124  double bm = wk * wj * wi * J.determinant(); 1125  integral += bm * field_vertex_values[index++]; 1126  // volume +=bm; 1127  } 1128  } 1129  } 1130  // std::cout << "volume: " << volume << "\n"; 1131  return integral; 1132  }

References _data, _ld, _n, _xyz, moab::Matrix3::determinant(), opt_data_3::elx, lagrange_data::J, opt_data_3::jac, opt_vol_set_intp_3(), and lagrange_data::z.

Referenced by test_spectral_hex().

◆ jacobian()

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

Evaluate the map's Jacobi matrix.

Implements moab::Element::Map.

Definition at line 100 of file SpectralHex.cpp.

101 { 102  real x_i[3]; 103  params.get( x_i ); 104  // set the positions of GL nodes, before evaluations 105  _data.elx[0] = _xyz[0]; 106  _data.elx[1] = _xyz[1]; 107  _data.elx[2] = _xyz[2]; 108  opt_vol_set_intp_3( &_data, x_i ); 109  Matrix3 J( 0. ); 110  // it is organized differently 111  J( 0, 0 ) = _data.jac[0]; // dx/dr 112  J( 0, 1 ) = _data.jac[1]; // dx/ds 113  J( 0, 2 ) = _data.jac[2]; // dx/dt 114  J( 1, 0 ) = _data.jac[3]; // dy/dr 115  J( 1, 1 ) = _data.jac[4]; // dy/ds 116  J( 1, 2 ) = _data.jac[5]; // dy/dt 117  J( 2, 0 ) = _data.jac[6]; // dz/dr 118  J( 2, 1 ) = _data.jac[7]; // dz/ds 119  J( 2, 2 ) = _data.jac[8]; // dz/dt 120  return J; 121 }

References moab::SpectralHex::_data, opt_data_3::elx, moab::CartVect::get(), opt_data_3::jac, and opt_vol_set_intp_3().

Referenced by test_spectral_hex().

◆ set_gl_points()

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

Definition at line 52 of file SpectralHex.cpp.

53 { 54  _xyz[0] = x; 55  _xyz[1] = y; 56  _xyz[2] = z; 57 }

Referenced by moab::Coupler::nat_param(), and test_spectral_hex().

Member Data Documentation

◆ _data

opt_data_3 moab::Element::SpectralHex::_data
staticprotected

Definition at line 272 of file ElemUtil.hpp.

Referenced by ievaluate(), Init(), and integrate_scalar_field().

◆ _init

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

Definition at line 276 of file ElemUtil.hpp.

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

◆ _ld

lagrange_data moab::Element::SpectralHex::_ld
staticprotected

Definition at line 271 of file ElemUtil.hpp.

Referenced by evaluate_scalar_field(), Init(), and integrate_scalar_field().

◆ _n

int moab::Element::SpectralHex::_n
staticprotected

Definition at line 269 of file ElemUtil.hpp.

Referenced by Init(), and integrate_scalar_field().

◆ _odwork

realType * moab::Element::SpectralHex::_odwork
staticprotected

Definition at line 273 of file ElemUtil.hpp.

Referenced by evaluate_scalar_field(), and Init().

◆ _xyz

realType* moab::Element::SpectralHex::_xyz[3]
protected

Definition at line 278 of file ElemUtil.hpp.

Referenced by ievaluate(), integrate_scalar_field(), and SpectralHex().

◆ _z

realType * moab::Element::SpectralHex::_z
staticprotected

Definition at line 270 of file ElemUtil.hpp.

Referenced by Init().


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