PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
fe::TetElem Class Reference

A class for mapping and quadrature related operations for linear tetrahedron element. More...

#include <tetElem.h>

Inheritance diagram for fe::TetElem:
Collaboration diagram for fe::TetElem:

Public Member Functions

 TetElem (size_t order)
 Constructor.
 
double elemSize (const std::vector< util::Point > &nodes) override
 Returns the volume of element.
 
std::vector< double > getShapes (const util::Point &p, const std::vector< util::Point > &nodes) override
 Returns the values of shape function at point p.
 
std::vector< std::vector< double > > getDerShapes (const util::Point &p, const std::vector< util::Point > &nodes) override
 Returns the values of derivative of shape function at point p.
 
std::vector< fe::QuadDatagetQuadDatas (const std::vector< util::Point > &nodes) override
 Get vector of quadrature data.
 
std::vector< fe::QuadDatagetQuadPoints (const std::vector< util::Point > &nodes) override
 Get vector of quadrature data.
 
- Public Member Functions inherited from fe::BaseElem
 BaseElem (size_t order, size_t element_type)
 Constructor.
 
size_t getElemType ()
 Get element type.
 
size_t getQuadOrder ()
 Get order of quadrature approximation.
 
size_t getNumQuadPoints ()
 Get number of quadrature points in the data.
 

Private Member Functions

std::vector< double > getShapes (const util::Point &p) override
 Returns the values of shape function at point p on reference element.
 
std::vector< std::vector< double > > getDerShapes (const util::Point &p) override
 Returns the values of derivative of shape function at point p on reference element.
 
util::Point mapPointToRefElem (const util::Point &p, const std::vector< util::Point > &nodes) override
 Maps point p in a given element to the reference element.
 
double getJacobian (const util::Point &p, const std::vector< util::Point > &nodes, std::vector< std::vector< double > > *J) override
 Computes the Jacobian of map \( \Phi: T^0 \to T \).
 
void init () override
 Compute the quadrature points for triangle element.
 

Additional Inherited Members

- Protected Attributes inherited from fe::BaseElem
size_t d_quadOrder
 Order of quadrature point integration approximation.
 
size_t d_numQuadPts
 Number of quadrature points for order d_quadOrder.
 
size_t d_elemType
 Element type.
 
std::vector< fe::QuadDatad_quads
 Quadrature data collection.
 

Detailed Description

A class for mapping and quadrature related operations for linear tetrahedron element.

The reference tetrahedron element \( T^0 \) is given by vertices \( (0,0,0), \, (1,0,0), \, (0,1,0), \, (0,0,1) \).

  1. The shape functions at point \( (\xi, \eta, \zeta) \in T^0 \) are

    \[N^0_1(\xi, \eta, \zeta) = 1- \xi - \eta - \zeta, \quad N^0_2(\xi, \eta, \zeta) = \xi, \quad N^0_3(\xi, \eta, \zeta) = \eta, \quad N^0_4(\xi, \eta, \zeta) = \zeta. \]

  2. For linear tetrahedron element, derivative of shape functions are constant and are as follows

    \[\frac{d N^0_1(\xi, \eta, \zeta)}{d\xi} = -1, \, \frac{d N^0_1(\xi, \eta, \zeta) }{d\eta} = -1, \, \frac{d N^0_1(\xi, \eta, \zeta) }{d\zeta} = -1, \]

    \[\frac{d N^0_2(\xi, \eta, \zeta)}{d\xi} = 1, \, \frac{d N^0_2(\xi, \eta, \zeta)}{d\eta} = 0, \, \frac{d N^0_2(\xi, \eta, \zeta)}{d\zeta} = 0, \]

    \[\frac{d N^0_2(\xi, \eta, \zeta)}{d\xi} = 0, \, \frac{d N^0_2(\xi, \eta, \zeta)}{d\eta} = 1, \, \frac{d N^0_2(\xi, \eta, \zeta)}{d\zeta} = 0, \]

    \[\frac{d N^0_2(\xi, \eta, \zeta)}{d\xi} = 0, \, \frac{d N^0_2(\xi, \eta, \zeta)}{d\eta} = 0, \, \frac{d N^0_2(\xi, \eta, \zeta)}{d\zeta} = 1. \]

  3. Map \( \Phi: T^0 \to T\) is given by

    \[ x(\xi, \eta, \zeta) = \sum_{i=1}^4 N^0_i(\xi, \eta, \zeta) v^i_x, \quad y (\xi, \eta, \zeta) = \sum_{i=1}^4 N^0_i(\xi, \eta, \zeta) v^i_y, \quad z (\xi, \eta, \zeta) = \sum_{i=1}^4 N^0_i(\xi, \eta, \zeta) v^i_z \]

    where \( v^1, v^2, v^3, v^4\) are vertices of element \( T \).
  4. The Jacobian of the map \( \Phi: T^0 \to T\) is given by

    \[ J = \left[ { \begin{array}{ccc} \frac{dx}{d\xi} &\frac{dy}{d\xi} &\frac{dz}{d\xi} \\ \frac{dx}{d\eta} & \frac{dy}{d\eta} &\frac{dz}{d\eta} \\ \frac{dx}{d\zeta} & \frac{dy}{d\zeta} &\frac{dz}{d\zeta} \\ \end{array} } \right] \]

    and determinant of Jacobian is

    \[ det(J) = \frac{dx}{d\xi} (\frac{dy}{d\eta} \times \frac{dz}{d\zeta} - \frac{dy}{d\zeta}\times \frac{dz}{d\eta}) - \frac{dy}{d\xi} (\frac{dx}{d\eta} \times \frac{dz}{d\zeta} - \frac{dx}{d\zeta}\times \frac{dz}{d\eta}) + \frac{dz}{d\xi} (\frac{dx}{d\eta} \times \frac{dy}{d\zeta} - \frac{dx}{d\zeta}\times \frac{dy}{d\eta}). \]

    For linear triangle element, Jacobian (and so \( det(J) \)) is constant. For linear tetrahedron elements, we simply have

    \[ \frac{dx}{d\xi} = v^2_x - v^1_x, \quad \frac{dx}{d\eta} = v^3_x - v^1_x, \quad \frac{dx}{d\zeta} = v^4_x - v^1_x, \]

    \[ \frac{dy}{d\xi} = v^2_y - v^1_y, \quad \frac{dy}{d\eta} = v^3_y - v^1_y, \quad \frac{dy}{d\zeta} = v^4_y - v^1_y, \]

    \[ \frac{dz}{d\xi} = v^2_z - v^1_z, \quad \frac{dz}{d\eta} = v^3_z - v^1_z, \quad \frac{dz}{d\zeta} = v^4_z - v^1_z \]

    and \( det(J) = \frac{volume(T)}{volume(T^0)} = 6\times volume(T) \).
  5. Inverse map \( \Phi^{-1} : T \to T^0 \) for linear tetrahedron element can be easily derived. The derivation of the map is provided below:

From map \( (\xi, \eta, \zeta)\in T^0 \to (x,y,z) \in T \) we have

\[ x = \sum_{i=1}^4 N^0_i(\xi, \eta, \zeta) v^i_x, \quad y = \sum_{i=1}^4 N^0_i(\xi, \eta, \zeta) v^i_y, \quad z = \sum_{i=1}^4 N^0_i(\xi, \eta, \zeta) v^i_z. \]

Substituting formula for \( N^0_i \) in above to get

\[ x = (1 - \xi - \eta - \zeta) v^1_x + \xi v^2_x + \eta v^3_x + \zeta v^4_x, \quad y = (1 - \xi - \eta - \zeta) v^1_y + \xi v^2_y + \eta v^3_y + \zeta v^4_y, \quad z = (1 - \xi - \eta - \zeta) v^1_z + \xi v^2_z + \eta v^3_z + \zeta v^4_z \]

or

\[ x - v^1_x = \xi (v^2_x - v^1_x) + \eta (v^3_x - v^1_x) + \zeta (v^4_x - v^1_x), \quad y - v^1_y = \xi (v^2_y - v^1_y) + \eta (v^3_y - v^1_y) + \zeta (v^4_y - v^1_y), \quad z - v^1_z = \xi (v^2_z - v^1_z) + \eta (v^3_z - v^1_z) + \zeta (v^4_z - v^1_z). \]

Writing above in matrix form, we have

\[ \left[ {\begin{array}{c} x - v^1_x \\ y - v^1_y \\ z - v^1_z \end{array}}\right] = \left[ {\begin{array}{ccc} v^2_x - v^1_x & v^3_x - v^1_x & v^4_x - v^1_x\\ v^2_y - v^1_y & v^3_y - v^1_y & v^3_y - v^1_y \\ v^2_z - v^1_z & v^3_z - v^1_z & v^3_z - v^1_z \end{array}}\right] \, \left[ {\begin{array}{c} \xi \\ \eta \\ \zeta \end{array}}\right]. \]

Denoting the matrix as \( B \)

\[ B = \left[ {\begin{array}{ccc} v^2_x - v^1_x & v^3_x - v^1_x & v^4_x - v^1_x\\ v^2_y - v^1_y & v^3_y - v^1_y & v^4_y - v^1_y \\ v^2_z - v^1_z & v^3_z - v^1_z & v^4_z - v^1_z \end{array}}\right] \]

. Note that \( B \) is transpose of jacobian of map \(\Phi\) therefore \( det(B) = det(J)\). Inverse of \( B\) is

\[ C := B^{-1} = \frac{1}{det(B)} \left[ {\begin{array}{ccc} B_{22}B_{33} - B_{32}B_{23} & B_{13}B_{32} - B_{33}B_{12} & B_{12}B_{23} - B_{22}B_{13} \\ B_{23}B_{31} - B_{33}B_{21} & B_{11}B_{33} - B_{31}B_{13} & B_{13}B_{21} - B_{23}B_{11} \\ B_{21}B_{32} - B_{31}B_{22} & B_{12}B_{31} - B_{32}B_{11} & B_{11}B_{22} - B_{21}B_{12} \\ \end{array}}\right]. \]

With \( C \) we have inverse map given by

\[ \xi(x,y,z) = C_{11} (x - v^1_x) + C_{12} (y - v^1_y) + C_{13} (z - v^1_z), \quad \eta(x,y,z) = C_{21} (x - v^1_x) + C_{22} (y - v^1_y) + C_{23} (z - v^1_z), \quad \zeta (x,y,z) = C_{31} (x - v^1_x) + C_{32} (y - v^1_y) + C_{33} (z - v^1_z). \]

Definition at line 141 of file tetElem.h.

Constructor & Destructor Documentation

◆ TetElem()

fe::TetElem::TetElem ( size_t  order)
explicit

Constructor.

Parameters
orderOrder of quadrature point approximation

Definition at line 68 of file tetElem.cpp.

70
71 if (d_quadOrder > 3) {
72 std::cout << "Error: For linear tet element, we only support upto 3 quad "
73 "order approximation.\n";
74 exit(1);
75 }
76
77 // compute quad data
78 this->init();
79}
A base class which provides methods to map points to/from reference element and to compute quadrature...
Definition baseElem.h:84
size_t d_quadOrder
Order of quadrature point integration approximation.
Definition baseElem.h:243
void init() override
Compute the quadrature points for triangle element.
Definition tetElem.cpp:270
static const int vtk_type_triangle
Integer flag for triangle element.

References fe::BaseElem::d_quadOrder, and init().

Here is the call graph for this function:

Member Function Documentation

◆ elemSize()

double fe::TetElem::elemSize ( const std::vector< util::Point > &  nodes)
overridevirtual

Returns the volume of element.

If tetrahedron \( T \) is given by points \( v^1, v^2, v^3, v^4 \) then the volume is

\[ volume(T) =\frac{1}{3!} \left\vert \left[ {\begin{array}{cccc} v^1_x & v^1_y & v^1_z & 1 \\ v^2_x & v^2_y & v^2_z & 1 \\ v^3_x & v^3_y & v^3_z & 1 \\ v^4_x & v^4_y & v^4_z & 1 \\ \end{array}}\right] \right\vert \]

where \( v^i_x, v^i_y, v^i_z \) are the x, y, z component of point \( v^i \).

Note that volume and Jacobian of map \( \Phi: T^0 \to T \) are related as

\[ volume(T) = volume(T^0) \times det(J). \]

Here, \( volume(T^0) = 1/6 \).

Parameters
nodesVertices of element
Returns
vector Vector of shape functions at point p

Implements fe::BaseElem.

Definition at line 81 of file tetElem.cpp.

81 {
82 // volume of tet element is (1/6) a * (b x c),
83 // where a = v2 - v1, b = v3 - v1, c = v4 - v1
84 auto a = nodes[1] - nodes[0];
85 auto b = nodes[2] - nodes[0];
86 auto c = nodes[3] - nodes[0];
87 return (1. / 6.) * a * (b.cross(c));
88}

◆ getDerShapes() [1/2]

std::vector< std::vector< double > > fe::TetElem::getDerShapes ( const util::Point p)
overrideprivatevirtual

Returns the values of derivative of shape function at point p on reference element.

Parameters
pLocation of point
Returns
vector Vector of derivative of shape functions

Implements fe::BaseElem.

Definition at line 186 of file tetElem.cpp.

187 {
188
189 // d N1/d xi = -1, d N1/d eta = -1, d N1/d zeta = -1,
190 // d N2/ d xi = 1, d N2/d eta = 0, d N2/d zeta = 0,
191 // d N3/ d xi = 0, d N3/d eta = 1, d N3/d zeta = 0,
192 // d N4/ d xi = 0, d N4/d eta = 0, d N4/d zeta = 1,
193 std::vector<std::vector<double>> r;
194 r.push_back(std::vector<double>{-1., -1., -1.});
195 r.push_back(std::vector<double>{1., 0., 0.});
196 r.push_back(std::vector<double>{0., 1., 0.});
197 r.push_back(std::vector<double>{0., 0., 1.});
198
199 return r;
200}

◆ getDerShapes() [2/2]

std::vector< std::vector< double > > fe::TetElem::getDerShapes ( const util::Point p,
const std::vector< util::Point > &  nodes 
)
overridevirtual

Returns the values of derivative of shape function at point p.

Below, we present the derivation of the formula:

We are interested in \( \frac{\partial N_i(x_p, y_p, z_p)}{\partial x}\), \( \frac{\partial N_i(x_p, y_p, z_p)}{\partial y}\) and \( \frac{\partial N_i(x_p, y_p, z_p)}{\partial z}\). By using the map \( \Phi : T^0 \to T\) we have

\[ N^0_i(\xi, \eta, \zeta) = N_i(x(\xi,\eta,\zeta), y(\xi, \eta,\eta), z(\xi, \eta,\eta)) \]

and therefore we can write

\[ \frac{\partial N^0_i(\xi, \eta, \zeta)}{\partial \xi} = \frac{\partial N_i}{\partial x} \frac{\partial x}{\partial \xi} + \frac{\partial N_i}{\partial y} \frac{\partial y}{\partial \xi} + \frac{\partial N_i}{\partial z} \frac{\partial z}{\partial \xi}, \]

\[ \frac{\partial N^0_i(\xi, \eta, \zeta)}{\partial \eta} = \frac{\partial N_i}{\partial x} \frac{\partial x}{\partial \eta} + \frac{\partial N_i}{\partial y} \frac{\partial y}{\partial \eta} + \frac{\partial N_i}{\partial z} \frac{\partial z}{\partial \eta} \]

and

\[ \frac{\partial N^0_i(\xi, \eta, \zeta)}{\partial \zeta} = \frac{\partial N_i}{\partial x} \frac{\partial x}{\partial \zeta} + \frac{\partial N_i}{\partial y} \frac{\partial y}{\partial \zeta} + \frac{\partial N_i}{\partial z} \frac{\partial z}{\partial \zeta} \]

which can be written in the matrix form as

\[ \left[ {\begin{array}{c} \frac{\partial N^0_i}{\partial \xi} \\ \frac{\partial N^0_i}{\partial \eta} \\ \frac{\partial N^0_i}{\partial \zeta} \end{array}}\right] = \left[ { \begin{array}{ccc} \frac{dx}{d\xi} &\frac{dy}{d\xi} &\frac{dz}{d\xi} \\ \frac{dx}{d\eta} & \frac{dy}{d\eta} &\frac{dz}{d\eta} \\ \frac{dx}{d\zeta} & \frac{dy}{d\zeta} &\frac{dz}{d\zeta} \\ \end{array} } \right] \, \left[ {\begin{array}{c} \frac{\partial N_i}{\partial x} \\ \frac{\partial N_i}{\partial y} \\ \frac{\partial N_i}{\partial z}\end{array}}\right]. \]

The matrix is the Jacobian matrix \( J \) and can be computed easily if vertices of elements are known. Using \( J^{-1} \) we have following formula for derivatives of the shape function

\[ \left[ {\begin{array}{c} \frac{\partial N_i}{\partial x} \\ \frac{\partial N_i}{\partial y} \\ \frac{\partial N_i}{\partial z}\end{array}}\right] = J^{-1} \left[ {\begin{array}{c} \frac{\partial N^0_i}{\partial \xi} \\ \frac{\partial N^0_i}{\partial \eta} \\ \frac{\partial N^0_i}{\partial \zeta}\end{array}}\right]. \]

Here, derivatives \( \frac{\partial N^0_i}{ \partial \xi} \), \( \frac{\partial N^0_i} {\partial \eta } \) and \( \frac{\partial N^0_i} {\partial \zeta } \) correspond to reference element and are easy to compute.

Parameters
pLocation of point
nodesVertices of element
Returns
vector Vector of derivative of shape functions

Reimplemented from fe::BaseElem.

Definition at line 95 of file tetElem.cpp.

96 {
97
98 // get derivatives of shape function in reference tet element
99 auto ders_ref = getDerShapes(mapPointToRefElem(p, nodes));
100
101 // get Jacobian and its determinant
102 std::vector<std::vector<double>> J;
103 auto detJ = getJacobian(p, nodes, &J);
104
105 auto J_inv = util::inv(J);
106
107 // to hold derivatives
108 std::vector<std::vector<double>> ders(ders_ref.size(),
109 std::vector<double>(3, 0.));
110
111 // grad N_i = J_inv * grad N_i^ref
112 for (size_t i = 0; i < 4; i++)
113 ders[i] = util::dot(J_inv, ders_ref[i]);
114
115 return ders;
116}
std::vector< std::vector< double > > getDerShapes(const util::Point &p, const std::vector< util::Point > &nodes) override
Returns the values of derivative of shape function at point p.
Definition tetElem.cpp:95
double getJacobian(const util::Point &p, const std::vector< util::Point > &nodes, std::vector< std::vector< double > > *J) override
Computes the Jacobian of map .
Definition tetElem.cpp:237
util::Point mapPointToRefElem(const util::Point &p, const std::vector< util::Point > &nodes) override
Maps point p in a given element to the reference element.
Definition tetElem.cpp:203
std::vector< std::vector< double > > inv(const std::vector< std::vector< double > > &m)
Computes the determinant of matrix.
Definition matrix.cpp:93
std::vector< double > dot(const std::vector< std::vector< double > > &m, const std::vector< double > &v)
Computes the dot product between matrix and vector.
Definition matrix.cpp:38

References util::dot(), and util::inv().

Here is the call graph for this function:

◆ getJacobian()

double fe::TetElem::getJacobian ( const util::Point p,
const std::vector< util::Point > &  nodes,
std::vector< std::vector< double > > *  J 
)
overrideprivatevirtual

Computes the Jacobian of map \( \Phi: T^0 \to T \).

Parameters
pLocation of point in reference element
nodesVertices of element
JMatrix to store the Jacobian (if not nullptr)
Returns
det(J) Determinant of the Jacobain

Implements fe::BaseElem.

Definition at line 237 of file tetElem.cpp.

239 {
240 if (J != nullptr) {
241 J->resize(3);
242 (*J)[0] = std::vector<double>{nodes[1].d_x - nodes[0].d_x,
243 nodes[1].d_y - nodes[0].d_y,
244 nodes[1].d_z - nodes[0].d_z};
245 (*J)[1] = std::vector<double>{nodes[2].d_x - nodes[0].d_x,
246 nodes[2].d_y - nodes[0].d_y,
247 nodes[2].d_z - nodes[0].d_z};
248 (*J)[2] = std::vector<double>{nodes[3].d_x - nodes[0].d_x,
249 nodes[3].d_y - nodes[0].d_y,
250 nodes[3].d_z - nodes[0].d_z};
251
252 return util::det(*J);
253 } else {
254 std::vector<std::vector<double>> J_local;
255 J_local.resize(3);
256 J_local[0] = std::vector<double>{nodes[1].d_x - nodes[0].d_x,
257 nodes[1].d_y - nodes[0].d_y,
258 nodes[1].d_z - nodes[0].d_z};
259 J_local[1] = std::vector<double>{nodes[2].d_x - nodes[0].d_x,
260 nodes[2].d_y - nodes[0].d_y,
261 nodes[2].d_z - nodes[0].d_z};
262 J_local[2] = std::vector<double>{nodes[3].d_x - nodes[0].d_x,
263 nodes[3].d_y - nodes[0].d_y,
264 nodes[3].d_z - nodes[0].d_z};
265
266 return util::det(J_local);
267 }
268}
double det(const std::vector< std::vector< double > > &m)
Computes the determinant of matrix.
Definition matrix.cpp:75

References util::det().

Here is the call graph for this function:

◆ getQuadDatas()

std::vector< fe::QuadData > fe::TetElem::getQuadDatas ( const std::vector< util::Point > &  nodes)
overridevirtual

Get vector of quadrature data.

Given element vertices, this method returns the list of quadrature point and essential quantities at quadrature points. Here, order of quadrature approximation is set in the constructor. List of data

  • quad point
  • quad weight
  • shape function evaluated at quad point
  • derivative of shape function evaluated at quad point
  • Jacobian matrix
  • determinant of the Jacobian

Let \( T \) is the given tetrahedron with vertices \( v^1, v^2, v^3, v^4 \) and let \( T^0 \) is the reference tetrahedron.

  1. To compute quadrature points, we first compute the quadrature points on reference tetrahedron \( T^0 \), and then we use the map \( \Phi: T^0 \to T\) to map the points on reference tetrahedron to the given triangle \( T \).
  2. To compute the quadrature weight, we compute the quadrature weight associated to the quadrature point in reference tetrahedron \( T^0 \). Suppose \( w^0_q \) is the quadrature weight associated to quadrature point \( (\xi_q, \eta_q) \in T^0 \), then the quadrature point \( w_q \) associated to the mapped point \( (x(\xi_q, \eta_q), y(\xi_q, \eta_q)) \in T \) is given by

    \[ w_q = w^0_q * det(J) \]

    where \( det(J) \) is the determinant of the Jacobian of map \( \Phi \).
  3. We compute shape functions \( N_1, N_2, N_3\) associated to \( T \) at the quadrature point \( (x(\xi_q, \eta_q), y(\xi_q,\eta_q)) \) using formula

    \[ N_i(x(\xi_q, \eta_q), y(\xi_q, \eta_q)) = N^0_i(\xi_q, \eta_q). \]

  4. To compute derivative of shape functions such as \( \frac{\partial N_i}{\partial x}, \frac{\partial N_i}{\partial y}\) associated to \( T \), we use the relation between derivatives of shape function in \( T \) and \( T^0 \) described in fe::TetElem::getDerShapes.
Parameters
nodesVector of vertices of an element
Returns
vector Vector of QuadData

Implements fe::BaseElem.

Definition at line 118 of file tetElem.cpp.

119 {
120
121 // copy quad data associated to reference element
122 auto qds = d_quads;
123
124 // modify data
125 for (auto &qd : qds) {
126
127 // get Jacobian and determinant
128 qd.d_detJ = getJacobian(qd.d_p, nodes, &(qd.d_J));
129
130 // transform quad weight
131 qd.d_w *= qd.d_detJ;
132
133 // map point to triangle
134 qd.d_p = util::Point();
135 for (size_t i=0; i<4; i++) {
136 qd.d_p.d_x += qd.d_shapes[i] * nodes[i].d_x;
137 qd.d_p.d_y += qd.d_shapes[i] * nodes[i].d_y;
138 qd.d_p.d_z += qd.d_shapes[i] * nodes[i].d_z;
139 }
140
141 // get inverse of Jacobian
142 auto J_inv = util::inv(qd.d_J);
143
144 // to hold derivatives
145 std::vector<std::vector<double>> ders(qd.d_derShapes.size(),
146 std::vector<double>(3, 0.));
147
148 // grad N_i = J_inv * grad N_i^ref
149 for (size_t i = 0; i < 4; i++)
150 ders[i] = util::dot(J_inv, qd.d_derShapes[i]);
151
152 qd.d_derShapes = ders;
153 }
154
155 return qds;
156}
std::vector< fe::QuadData > d_quads
Quadrature data collection.
Definition baseElem.h:252
A structure to represent 3d vectors.
Definition point.h:30

References util::dot(), and util::inv().

Here is the call graph for this function:

◆ getQuadPoints()

std::vector< fe::QuadData > fe::TetElem::getQuadPoints ( const std::vector< util::Point > &  nodes)
overridevirtual

Get vector of quadrature data.

Given element vertices, this method returns the list of quadrature point and essential quantities at quadrature points. Here, order of quadrature approximation is set in the constructor. List of data

  • quad point
  • quad weight
  • shape function evaluated at quad point

This function is lite version of fe::TetElem::getQuadDatas.

Parameters
nodesVector of vertices of an element
Returns
vector Vector of QuadData

Implements fe::BaseElem.

Definition at line 158 of file tetElem.cpp.

159 {
160 // copy quad data associated to reference element
161 auto qds = d_quads;
162
163 // modify data
164 for (auto &qd : qds) {
165
166 // transform quad weight
167 qd.d_w *= getJacobian(qd.d_p, nodes, nullptr);
168
169 // map point to triangle
170 qd.d_p = util::Point();
171 for (size_t i=0; i<4; i++) {
172 qd.d_p.d_x += qd.d_shapes[i] * nodes[i].d_x;
173 qd.d_p.d_y += qd.d_shapes[i] * nodes[i].d_y;
174 qd.d_p.d_z += qd.d_shapes[i] * nodes[i].d_z;
175 }
176 }
177
178 return qds;
179}

◆ getShapes() [1/2]

std::vector< double > fe::TetElem::getShapes ( const util::Point p)
overrideprivatevirtual

Returns the values of shape function at point p on reference element.

Parameters
pLocation of point
Returns
vector Vector of shape functions at point p

Implements fe::BaseElem.

Definition at line 181 of file tetElem.cpp.

181 {
182 // N1 = 1 - xi - eta - zeta, N2 = xi, N3 = eta, N4 = zeta
183 return std::vector<double>{1. - p.d_x - p.d_y - p.d_z, p.d_x, p.d_y, p.d_z};
184}
double d_y
the y coordinate
Definition point.h:36
double d_z
the z coordinate
Definition point.h:39
double d_x
the x coordinate
Definition point.h:33

References util::Point::d_x, util::Point::d_y, and util::Point::d_z.

◆ getShapes() [2/2]

std::vector< double > fe::TetElem::getShapes ( const util::Point p,
const std::vector< util::Point > &  nodes 
)
overridevirtual

Returns the values of shape function at point p.

We first map the point p in \( T \) to reference tetrahedron \( T^0 \) using fe::TetElem::mapPointToRefElem and then compute shape functions at the mapped point using fe::TetElem::getShapes(const util::Point &).

Parameters
pLocation of point
nodesVertices of element
Returns
vector Vector of shape functions at point p

Reimplemented from fe::BaseElem.

Definition at line 90 of file tetElem.cpp.

91 {
92 return getShapes(mapPointToRefElem(p, nodes));
93}
std::vector< double > getShapes(const util::Point &p, const std::vector< util::Point > &nodes) override
Returns the values of shape function at point p.
Definition tetElem.cpp:90

◆ init()

void fe::TetElem::init ( )
overrideprivatevirtual

Compute the quadrature points for triangle element.

Implements fe::BaseElem.

Definition at line 270 of file tetElem.cpp.

270 {
271 //
272 // compute quad data for reference triangle with vertex at
273 // (0,0), (1,0), (0,1)
274 //
275
276 if (!d_quads.empty()) return;
277
278 // no point in zeroth order
279 if (d_quadOrder == 0) {
280 d_quads.resize(0);
281 }
282
283 // 3x3 identity matrix
284 std::vector<std::vector<double>> ident_mat;
285 ident_mat.push_back(std::vector<double>{1., 0., 0.});
286 ident_mat.push_back(std::vector<double>{0., 1., 0.});
287 ident_mat.push_back(std::vector<double>{0., 0., 1.});
288
289 //
290 // These datas are from LibMesh code
291 // See: https://libmesh.github.io/doxygen/quadrature__gauss__3D_8C_source.html
292
293 //
294 // first order quad points for triangle
295 //
296 if (d_quadOrder == 1) {
297 d_quads.clear();
298 fe::QuadData qd;
299 qd.d_w = 1. / 6.;
300 qd.d_p = util::Point(1. / 4., 1. / 4., 1. / 4.);
301 // N1 = 1 - xi - eta, N2 = xi, N3 = eta
302 qd.d_shapes = getShapes(qd.d_p);
303 // d N1/d xi = -1, d N1/d eta = -1, d N2/ d xi = 1, d N2/d eta = 0,
304 // d N3/ d xi = 0, d N3/d eta = 1
306 qd.d_J = ident_mat;
307 qd.d_detJ = 1.;
308 d_quads.push_back(qd);
309 }
310
311 //
312 // second order quad points for triangle
313 //
314 if (d_quadOrder == 2) {
315 d_quads.clear();
316 fe::QuadData qd;
317
318 double w = 1. / 24.;
319 double a = 0.585410196624969;
320 double b = 0.138196601125011;
321 // point 1
322 qd.d_w = w;
323 qd.d_p = util::Point(a, b, b);
324 qd.d_shapes = getShapes(qd.d_p);
326 qd.d_J = ident_mat;
327 qd.d_detJ = 1.;
328 d_quads.push_back(qd);
329 // point 2
330 qd.d_w = w;
331 qd.d_p = util::Point(b, a, b);
332 qd.d_shapes = getShapes(qd.d_p);
334 qd.d_J = ident_mat;
335 qd.d_detJ = 1.;
336 d_quads.push_back(qd);
337 // point 3
338 qd.d_w = w;
339 qd.d_p = util::Point(b, b, a);
340 qd.d_shapes = getShapes(qd.d_p);
342 qd.d_J = ident_mat;
343 qd.d_detJ = 1.;
344 d_quads.push_back(qd);
345 // point 4
346 qd.d_w = w;
347 qd.d_p = util::Point(b, b, b);
348 qd.d_shapes = getShapes(qd.d_p);
350 qd.d_J = ident_mat;
351 qd.d_detJ = 1.;
352 d_quads.push_back(qd);
353 }
354
355 //
356 // third order quad points for triangle
357 //
358 if (d_quadOrder == 3) {
359 d_quads.clear();
360 fe::QuadData qd;
361
362 double w1 = -2. / 15.;
363 double w2 = 0.075;
364
365 double a = 0.25;
366 double b = 0.5;
367 double c = 1. / 6.;
368
369 // point 1
370 qd.d_w = w1;
371 qd.d_p = util::Point(a, a, a);
372 qd.d_shapes = getShapes(qd.d_p);
374 qd.d_J = ident_mat;
375 qd.d_detJ = 1.;
376 d_quads.push_back(qd);
377 // point 2
378 qd.d_w = w2;
379 qd.d_p = util::Point(b, c, c);
380 qd.d_shapes = getShapes(qd.d_p);
382 qd.d_J = ident_mat;
383 qd.d_detJ = 1.;
384 d_quads.push_back(qd);
385 // point 3
386 qd.d_w = w2;
387 qd.d_p = util::Point(c, b, c);
388 qd.d_shapes = getShapes(qd.d_p);
390 qd.d_J = ident_mat;
391 qd.d_detJ = 1.;
392 d_quads.push_back(qd);
393 // point 4
394 qd.d_w = w2;
395 qd.d_p = util::Point(c, c, b);
396 qd.d_shapes = getShapes(qd.d_p);
398 qd.d_J = ident_mat;
399 qd.d_detJ = 1.;
400 d_quads.push_back(qd);
401 // point 5
402 qd.d_w = w2;
403 qd.d_p = util::Point(c, c, c);
404 qd.d_shapes = getShapes(qd.d_p);
406 qd.d_J = ident_mat;
407 qd.d_detJ = 1.;
408 d_quads.push_back(qd);
409 }
410}
A struct to store the quadrature data. List of data are.
Definition quadData.h:23
std::vector< double > d_shapes
Value of shape functions at quad point p.
Definition quadData.h:37
std::vector< std::vector< double > > d_derShapes
Value of derivative of shape functions at quad point p.
Definition quadData.h:50
double d_w
Quadrature weight.
Definition quadData.h:26
util::Point d_p
Quadrature point in 1-d, 2-d or 3-d.
Definition quadData.h:29
std::vector< std::vector< double > > d_J
Jacobian of the map from reference element to the element.
Definition quadData.h:58
double d_detJ
Determinant of the Jacobian of the map from reference element to the element.
Definition quadData.h:64

References fe::QuadData::d_derShapes, fe::QuadData::d_detJ, fe::QuadData::d_J, fe::QuadData::d_p, fe::QuadData::d_shapes, and fe::QuadData::d_w.

Referenced by TetElem().

Here is the caller graph for this function:

◆ mapPointToRefElem()

util::Point fe::TetElem::mapPointToRefElem ( const util::Point p,
const std::vector< util::Point > &  nodes 
)
overrideprivatevirtual

Maps point p in a given element to the reference element.

Let \( v^1, v^2, v^3\) are three vertices of triangle \( T\) and let \(T^0 \) is the reference triangle. Following the introduction to fe::TriElem, the map \( (x,y) \in T \) to \( (\xi, \eta) \in T^0 \) is given by

\[ \xi = C_{11} (x - v^1_x) + C_{12} (y - v^1_y), \quad \eta = C_{21} (x - v^1_x) + C_{22} (y - v^1_y). \]

\( C\) is the inverse of matrix

\[ B = \left[ {\begin{array}{cc} v^2_x - v^1_x & v^3_x - v^1_x \\ v^2_y - v^1_y & v^3_y - v^1_y \end{array}}\right], \]

i.e.

\[ C := B^{-1} = \frac{1}{(v^2_x - v^1_x)(v^3_y - v^1_y) - (v^3_x - v^1_x) (v^2_y - v^1_y)} \left[ {\begin{array}{cc} v^3_y - v^1_y & -(v^3_x - v^1_x) \\ -(v^2_y - v^1_y) & v^2_x - v^1_x \end{array}}\right]. \]

If mapped point \( (\xi, \eta)\) does not satisfy following conditions

  • \[ 0\leq \xi, \eta \]

  • \[ \xi \leq 1 - \eta \quad (or\, equivalently) \quad \eta \leq 1 - \xi \]

    then the point \( (\xi,\eta) \) does not belong to the reference triangle or equivalently point \((x,y) \) does not belong to the triangle \( T \) and the method issues error. Otherwise the method returns point \( (\xi, \eta)\).
Parameters
pLocation of point
nodesVertices of element
Returns
vector Vector of shape functions at point p

Reimplemented from fe::BaseElem.

Definition at line 203 of file tetElem.cpp.

204 {
205
206 // get Jacobian matrix and compute its transpose
207 std::vector<std::vector<double>> J(3, std::vector<double>(3, 0.));
208 auto detJ = getJacobian(p, nodes, &J);
209
210 // get transpose of Jacobian
211 auto B = util::transpose(J);
212 auto detB = detJ;
213
214 // get inverse of B
215 auto B_inv = util::inv(B);
216
217 // get vector from first vertex to point p
218 std::vector<double> vec_p = {p.d_x - nodes[0].d_x,
219 p.d_y - nodes[0].d_y,
220 p.d_z - nodes[0].d_z};
221 // multiply B_inv to vector to transform point
222 auto p_ref = util::dot(B_inv, vec_p);
223
224 // check point
225 checkPoint(p_ref, nodes);
226
227 if (util::isLess(p_ref[0], 0.)) p_ref[0] = 0.;
228 if (util::isLess(p_ref[1], 0.)) p_ref[1] = 0.;
229 if (util::isLess(p_ref[2], 0.)) p_ref[2] = 0.;
230 if (util::isGreater(p_ref[0], 1.)) p_ref[0] = 1.;
231 if (util::isGreater(p_ref[1], 1.)) p_ref[1] = 1.;
232 if (util::isGreater(p_ref[2], 1.)) p_ref[2] = 1.;
233
234 return util::Point(p_ref);
235}
void checkPoint(const std::vector< double > &p, const std::vector< util::Point > &nodes)
Definition tetElem.cpp:21
bool isGreater(const double &a, const double &b)
Returns true if a > b.
Definition function.cpp:15
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:20
std::vector< std::vector< double > > transpose(const std::vector< std::vector< double > > &m)
Computes the tranpose of matrix.
Definition matrix.cpp:56

References util::Point::d_x, util::Point::d_y, util::Point::d_z, util::dot(), util::inv(), util::isGreater(), util::isLess(), and util::transpose().

Here is the call graph for this function:

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