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

A class for mapping and quadrature related operations for linear 2-node line element. More...

#include <lineElem.h>

Inheritance diagram for fe::LineElem:
Collaboration diagram for fe::LineElem:

Public Member Functions

 LineElem (size_t order)
 Constructor for line element.
 
double elemSize (const std::vector< util::Point > &nodes) override
 Returns the length 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.
 
- 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.
 
std::vector< fe::QuadData > getQuadDatas (const std::vector< util::Point > &nodes)
 Get quadrature data mapped to the physical element (N, dN/dx, x, w, J). Shared isoparametric map; types only fill reference N, dN/dξ, and w.
 
std::vector< fe::QuadData > getQuadPoints (const std::vector< util::Point > &nodes)
 Same as getQuadDatas without transforming dN/dξ to dN/dx.
 

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 Jacobian of the map \( \Phi: T^0 \to T\).
 
void init () override
 Compute the quadrature points for line element.
 

Additional Inherited Members

- Protected Attributes inherited from fe::BaseElem
size_t d_quadOrder
 Order of quadrature point integration approximation.
 
size_t d_elemType
 Element type.
 
std::vector< fe::QuadData > d_quads
 Quadrature data collection.
 

Detailed Description

A class for mapping and quadrature related operations for linear 2-node line element.

The reference line element \(T^0 \) is given by vertices at \( v^1 = -1, v^2 = 1 \).

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

    \[N^0_1(\xi) = \frac{1 - \xi}{2}, \quad N^0_2(\xi) = \frac{1 + \xi}{2}. \]

  2. Derivative of shape functions are constant and are as follows

    \[\frac{d N^0_1(\xi)}{d\xi} = \frac{-1}{2}, \, \frac{d N^0_2(\xi)}{d\xi} = \frac{1}{2}. \]

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

    \[ x(\xi) = \sum_{i=1}^2 N^0_i(\xi) v^i_x, \]

    where \( v^1, v^2\) are vertices of element \( T \). For 1-d points, \( v^i_x = v^i \).
  4. The Jacobian of the map \( \Phi: T^0 \to T \) is given by

    \[ J = \frac{dx}{d\xi}. \]

    Since it is a 1-d case, Jacobian and its determinant are same. For line element the formula for Jacobian is as follows

    \[ J = \frac{dx}{d\xi} = \frac{v^2_x - v^1_x}{2} = \frac{length(T) }{length(T^0)}. \]

  5. Inverse map \( \Phi^{-1} \) from \( x \in T \) to \( \xi \in T^0\) is given by

    \[ \xi(x) = \frac{2}{v^2_x - v^1_x} (x - \frac{v^2_x + v^1_x}{2}) = \frac{1}{J}(x - \frac{v^2_x + v^1_x}{2}). \]

Definition at line 49 of file lineElem.h.

Constructor & Destructor Documentation

◆ LineElem()

fe::LineElem::LineElem ( size_t  order)
explicit

Constructor for line element.

Parameters
orderOrder of quadrature point approximation

Definition at line 18 of file lineElem.cpp.

20
21 // compute quad data
22 this->init();
23}
A base class which provides methods to map points to/from reference element and to compute quadrature...
Definition baseElem.h:84
void init() override
Compute the quadrature points for line element.
Definition lineElem.cpp:110
static const int vtk_type_line
Integer flag for line element.

References init().

Here is the call graph for this function:

Member Function Documentation

◆ elemSize()

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

Returns the length of element.

If line \( T \) is given by points \( v^1, v^2\) then the length is

\[ length(T) = v^2_x - v^1_x. \]

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

Implements fe::BaseElem.

Definition at line 25 of file lineElem.cpp.

25 {
26 return (nodes[1].d_x - nodes[0].d_x);
27}

◆ getDerShapes() [1/2]

std::vector< std::vector< double > > fe::LineElem::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 59 of file lineElem.cpp.

59 {
60
61 // N1 = (1 - xi)/2
62 // --> d N1/d xi = -1/2
63 //
64 // N2 = (1 + xi)/2
65 // --> d N2/d xi = 1/2
66 std::vector<std::vector<double>> r;
67 r.push_back(std::vector<double>{-0.5});
68 r.push_back(std::vector<double>{0.5});
69 return r;
70}

◆ getDerShapes() [2/2]

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

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

Let \( x\) is the point on line \( T \) and let \( \xi \) is the point on reference line \( T^0 \). Let shape functions on \( T\) are \( N_1, N_2 \) and on \( T^0 \) are \( N^0_1, N^0_2 \).

We are interested in \( \frac{\partial N_i(x_p)}{\partial x}\). By using the map \( \xi \to x \) we have

\[ N^0_i(\xi) = N_i(x(\xi)) \]

and therefore we can write

\[ \frac{\partial N^0_i(\xi)}{\partial \xi} = \frac{\partial N_i}{\partial x} \frac{\partial x}{\partial \xi}. \]

Since \( \frac{\partial x}{\partial \xi} = J \) is a Jacobian of map which follows from \( v^1, v^2 \), we can invert and obtain the formula

\[ \frac{\partial N_i(\xi)}{\partial x} = \frac{1}{J} \frac{\partial N^0_i(\xi)}{\partial \xi}. \]

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

Reimplemented from fe::BaseElem.

Definition at line 36 of file lineElem.cpp.

37 {
38 // get derivatives of shape function in reference triangle
39 auto ders_ref = getDerShapes(mapPointToRefElem(p, nodes));
40
41 // get Jacobian
42 auto detJ = getJacobian(p, nodes, nullptr);
43
44 // modify derivatives of shape function
45 ders_ref[0][0] = ders_ref[0][0] / detJ;
46 ders_ref[1][0] = ders_ref[1][0] / detJ;
47
48 return ders_ref;
49}
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 lineElem.cpp:73
double getJacobian(const util::Point &p, const std::vector< util::Point > &nodes, std::vector< std::vector< double > > *J) override
Computes Jacobian of the map .
Definition lineElem.cpp:96
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 lineElem.cpp:36

◆ getJacobian()

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

Computes Jacobian of the 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 (same as Jacobian in 1-d)

Implements fe::BaseElem.

Definition at line 96 of file lineElem.cpp.

98 {
99 // Reference line is [-1, 1], dN/dξ = ±1/2, so J = dx/dξ = L/2.
100 const double Jxi = 0.5 * (nodes[1].d_x - nodes[0].d_x);
101
102 if (J != nullptr) {
103 J->resize(1);
104 (*J)[0] = std::vector<double>{Jxi};
105 }
106
107 return Jxi;
108}

◆ getShapes() [1/2]

std::vector< double > fe::LineElem::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 51 of file lineElem.cpp.

51 {
52
53 // N1 = (1 - xi)/2
54 // N2 = (1 + xi)/2
55 return std::vector<double>{0.5 * (1. - p.d_x), 0.5 * (1. + p.d_x)};
56}
double d_x
the x coordinate
Definition point.h:33

References util::Point::d_x.

◆ getShapes() [2/2]

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

Returns the values of shape function at point p.

Line \( T \) is given by points \( v^1, v^2\). We first map the point p in \( T \) to reference line \( T^0 \) using fe::LineElem::mapPointToRefElem and then compute shape functions at the mapped point using fe::LineElem::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 30 of file lineElem.cpp.

31 {
32 return getShapes(mapPointToRefElem(p, nodes));
33}
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 lineElem.cpp:30

◆ init()

void fe::LineElem::init ( )
overrideprivatevirtual

Compute the quadrature points for line element.

Implements fe::BaseElem.

Definition at line 110 of file lineElem.cpp.

110 {
111
112 //
113 // compute quad data for reference line element with vertex at p1 = -1 and
114 // p2 = 1
115 //
116 // Shape functions are
117 // N1 = (1 - xi)/2
118 // N2 = (1 + xi)/2
119
120 if (!d_quads.empty())
121 return;
122
123 // no point in zeroth order
124 if (d_quadOrder == 0)
125 d_quads.resize(0);
126
127 // 1x1 identity matrix
128 std::vector<std::vector<double>> ident_mat;
129 ident_mat.push_back(std::vector<double>{1.});
130
131 //
132 // first order quad points
133 //
134 if (d_quadOrder == 1) {
135 d_quads.clear();
136 // 1-d points are: {0} and weights are: {2}
137 fe::QuadData qd;
138 qd.d_w = 2.;
139 qd.d_p = util::Point();
140 qd.d_shapes = getShapes(qd.d_p);
142 qd.d_J = ident_mat;
143 qd.d_detJ = 1.;
144 d_quads.push_back(qd);
145 }
146
147 //
148 // second order quad points
149 //
150 if (d_quadOrder == 2) {
151 d_quads.clear();
152 // 1-d points are: {-1/sqrt{3], 1/sqrt{3}} and weights are: {1,1}
153 fe::QuadData qd;
154 qd.d_w = 1.;
155 qd.d_p = util::Point(-1. / std::sqrt(3.), 0., 0.);
156 qd.d_shapes = getShapes(qd.d_p);
158 qd.d_J = ident_mat;
159 qd.d_detJ = 1.;
160 d_quads.push_back(qd);
161
162 qd.d_w = 1.;
163 qd.d_p = util::Point(1. / std::sqrt(3.), 0., 0.);
164 qd.d_shapes = getShapes(qd.d_p);
166 qd.d_J = ident_mat;
167 qd.d_detJ = 1.;
168 d_quads.push_back(qd);
169 }
170
171 //
172 // third order quad points for triangle
173 //
174 if (d_quadOrder == 3) {
175 d_quads.clear();
176 // 1-d points are: {-sqrt{3}/sqrt{5}, 0, sqrt{3}/sqrt{5}}
177 // weights are: {5/9, 8/9, 5/9}
178 fe::QuadData qd;
179 qd.d_w = 5. / 9.;
180 qd.d_p = util::Point(-std::sqrt(3.) / std::sqrt(5.), 0., 0.);
181 qd.d_shapes = getShapes(qd.d_p);
183 qd.d_J = ident_mat;
184 qd.d_detJ = 1.;
185 d_quads.push_back(qd);
186
187 qd.d_w = 8. / 9.;
188 qd.d_p = util::Point();
189 qd.d_shapes = getShapes(qd.d_p);
191 qd.d_J = ident_mat;
192 qd.d_detJ = 1.;
193 d_quads.push_back(qd);
194
195 qd.d_w = 5. / 9.;
196 qd.d_p = util::Point(std::sqrt(3.) / std::sqrt(5.), 0., 0.);
197 qd.d_shapes = getShapes(qd.d_p);
199 qd.d_J = ident_mat;
200 qd.d_detJ = 1.;
201 d_quads.push_back(qd);
202 }
203
204 //
205 // fourth order quad points for triangle
206 //
207 if (d_quadOrder == 4) {
208 d_quads.clear();
209 fe::QuadData qd;
210 qd.d_w = 0.6521451548625461;
211 qd.d_p = util::Point(-0.3399810435848563, 0., 0.);
212 qd.d_shapes = getShapes(qd.d_p);
214 qd.d_J = ident_mat;
215 qd.d_detJ = 1.;
216 d_quads.push_back(qd);
217
218 qd.d_w = 0.6521451548625461;
219 qd.d_p = util::Point(0.3399810435848563, 0., 0.);
220 qd.d_shapes = getShapes(qd.d_p);
222 qd.d_J = ident_mat;
223 qd.d_detJ = 1.;
224 d_quads.push_back(qd);
225
226 qd.d_w = 0.3478548451374538;
227 qd.d_p = util::Point(-0.8611363115940526, 0., 0.);
228 qd.d_shapes = getShapes(qd.d_p);
230 qd.d_J = ident_mat;
231 qd.d_detJ = 1.;
232 d_quads.push_back(qd);
233
234 qd.d_w = 0.3478548451374538;
235 qd.d_p = util::Point(0.8611363115940526, 0., 0.);
236 qd.d_shapes = getShapes(qd.d_p);
238 qd.d_J = ident_mat;
239 qd.d_detJ = 1.;
240 d_quads.push_back(qd);
241 }
242
243 //
244 // fifth order quad points for triangle
245 //
246 if (d_quadOrder == 5) {
247 d_quads.clear();
248 fe::QuadData qd;
249 qd.d_w = 0.5688888888888889;
250 qd.d_p = util::Point();
251 qd.d_shapes = getShapes(qd.d_p);
253 qd.d_J = ident_mat;
254 qd.d_detJ = 1.;
255 d_quads.push_back(qd);
256
257 qd.d_w = 0.4786286704993665;
258 qd.d_p = util::Point(-0.5384693101056831, 0., 0.);
259 qd.d_shapes = getShapes(qd.d_p);
261 qd.d_J = ident_mat;
262 qd.d_detJ = 1.;
263 d_quads.push_back(qd);
264
265 qd.d_w = 0.4786286704993665;
266 qd.d_p = util::Point(0.5384693101056831, 0., 0.);
267 qd.d_shapes = getShapes(qd.d_p);
269 qd.d_J = ident_mat;
270 qd.d_detJ = 1.;
271 d_quads.push_back(qd);
272
273 qd.d_w = 0.2369268850561891;
274 qd.d_p = util::Point(-0.9061798459386640, 0., 0.);
275 qd.d_shapes = getShapes(qd.d_p);
277 qd.d_J = ident_mat;
278 qd.d_detJ = 1.;
279 d_quads.push_back(qd);
280
281 qd.d_w = 0.2369268850561891;
282 qd.d_p = util::Point(0.9061798459386640, 0., 0.);
283 qd.d_shapes = getShapes(qd.d_p);
285 qd.d_J = ident_mat;
286 qd.d_detJ = 1.;
287 d_quads.push_back(qd);
288 }
289}
std::vector< fe::QuadData > d_quads
Quadrature data collection.
Definition baseElem.h:224
size_t d_quadOrder
Order of quadrature point integration approximation.
Definition baseElem.h:218
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
Derivatives of shape functions at the quad point.
Definition quadData.h:46
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:54
double d_detJ
Determinant of the Jacobian of the map from reference element to the element.
Definition quadData.h:60
A structure to represent 3d vectors.
Definition point.h:30

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 LineElem().

Here is the caller graph for this function:

◆ mapPointToRefElem()

util::Point fe::LineElem::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\) are vertices of element \( T\) and let \(T^0 \) is the reference element. Map \(\Phi : T^0 \to T\) is given by

\[ \xi(x) = \frac{2}{v^2_x - v^1_x} (x - \frac{v^2_x + v^1_x}{2}) = \frac{1}{J}(x - \frac{v^2_x + v^1_x}{2}). \]

If mapped point \( \xi\) does not satisfy condition

  • \[ -1 \leq \xi \leq 1 \]

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

Reimplemented from fe::BaseElem.

Definition at line 73 of file lineElem.cpp.

74 {
75 auto xi = (2. * p.d_x - nodes[0].d_x - nodes[1].d_x) /
76 (nodes[0].d_x - nodes[1].d_x);
77
78 if (util::isLess(xi, -1. - 1.0E-8) ||
79 util::isGreater(xi, 1. + 1.0E-8) ) {
80 throw std::runtime_error(
82 << "Error: Trying to map point p = " << p.d_x
83 << " in given line to reference line.\n"
84 << "But the point p does not belong to line = {"
85 << nodes[0].d_x << ", " << nodes[1].d_x << "}.\n");
86 }
87
88 if (util::isLess(xi, -1.))
89 xi = -1.;
90 if (util::isGreater(xi, 1.))
91 xi = 1.;
92
93 return {xi, 0., 0.};
94}
Collects a message with stream syntax for use in an exception.
Definition io.h:52
bool isGreater(const double &a, const double &b)
Returns true if a > b.
Definition function.cpp:17
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:22

References util::Point::d_x, util::isGreater(), and util::isLess().

Here is the call graph for this function:

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