PeriDEM 0.2.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.
 
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 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_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 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, we simply have \( 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 16 of file lineElem.cpp.

18
19 // compute quad data
20 this->init();
21}
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:154
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 simply

\[ 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 23 of file lineElem.cpp.

23 {
24 return (nodes[1].d_x - nodes[0].d_x);
25}

◆ 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 104 of file lineElem.cpp.

104 {
105
106 // N1 = (1 - xi)/2
107 // --> d N1/d xi = -1/2
108 //
109 // N2 = (1 + xi)/2
110 // --> d N2/d xi = 1/2
111 std::vector<std::vector<double>> r;
112 r.push_back(std::vector<double>{-0.5});
113 r.push_back(std::vector<double>{0.5});
114 return r;
115}

◆ 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 can be computed easily if \( v^1, v^2 \) are known, 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 34 of file lineElem.cpp.

35 {
36 // get derivatives of shape function in reference triangle
37 auto ders_ref = getDerShapes(mapPointToRefElem(p, nodes));
38
39 // get Jacobian
40 auto detJ = getJacobian(p, nodes, nullptr);
41
42 // modify derivatives of shape function
43 ders_ref[0][0] = ders_ref[0][0] / detJ;
44 ders_ref[1][0] = ders_ref[1][0] / detJ;
45
46 return ders_ref;
47}
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:118
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:140
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:34

◆ 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 140 of file lineElem.cpp.

142 {
143
144 if (J != nullptr) {
145 J->resize(1);
146 (*J)[0] = std::vector<double>{nodes[1].d_x - nodes[0].d_x};
147
148 return (*J)[0][0];
149 }
150
151 return (nodes[1].d_x - nodes[0].d_x);
152}

◆ getQuadDatas()

std::vector< fe::QuadData > fe::LineElem::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 for each quad point:

  • 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 line with vertices \( v^1, v^2 \) and let \( T^0 \) is the reference line.

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

    \[ w_q = w^0_q * J \]

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

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

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

Implements fe::BaseElem.

Definition at line 50 of file lineElem.cpp.

50 {
51
52 // copy quad data associated to reference element
53 auto qds = d_quads;
54
55 // modify data
56 for (auto &qd : qds) {
57
58 // get Jacobian and determinant
59 qd.d_detJ = getJacobian(qd.d_p, nodes, &(qd.d_J));
60
61 // transform quad weight
62 qd.d_w *= qd.d_detJ;
63
64 // map point to line
65 qd.d_p.d_x = qd.d_shapes[0] * nodes[0].d_x + qd.d_shapes[1] * nodes[1]
66 .d_x;
67
68 // modify derivative of shape function
69 for (size_t i=0; i<2; i++)
70 qd.d_derShapes[i][0] = qd.d_derShapes[i][0] / qd.d_detJ;
71 }
72
73 return qds;
74}
std::vector< fe::QuadData > d_quads
Quadrature data collection.
Definition baseElem.h:252

◆ getQuadPoints()

std::vector< fe::QuadData > fe::LineElem::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 for each quad point:

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

This function is a lite version of fe::LineElem::getQuadDatas.

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

Implements fe::BaseElem.

Definition at line 77 of file lineElem.cpp.

77 {
78
79 // copy quad data associated to reference element
80 auto qds = d_quads;
81
82 // modify data
83 for (auto &qd : qds) {
84
85 // transform quad weight
86 qd.d_w *= getJacobian(qd.d_p, nodes, nullptr);
87
88 // map point to line
89 qd.d_p.d_x = qd.d_shapes[0] * nodes[0].d_x + qd.d_shapes[1] * nodes[1]
90 .d_x;
91 }
92
93 return qds;
94}

◆ 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 96 of file lineElem.cpp.

96 {
97
98 // N1 = (1 - xi)/2
99 // N2 = (1 + xi)/2
100 return std::vector<double>{0.5 * (1. - p.d_x), 0.5 * (1. + p.d_x)};
101}
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 28 of file lineElem.cpp.

29 {
30 return getShapes(mapPointToRefElem(p, nodes));
31}
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:28

◆ init()

void fe::LineElem::init ( )
overrideprivatevirtual

Compute the quadrature points for line element.

Implements fe::BaseElem.

Definition at line 154 of file lineElem.cpp.

154 {
155
156 //
157 // compute quad data for reference line element with vertex at p1 = -1 and
158 // p2 = 1
159 //
160 // Shape functions are
161 // N1 = (1 - xi)/2
162 // N2 = (1 + xi)/2
163
164 if (!d_quads.empty())
165 return;
166
167 // no point in zeroth order
168 if (d_quadOrder == 0)
169 d_quads.resize(0);
170
171 // 1x1 identity matrix
172 std::vector<std::vector<double>> ident_mat;
173 ident_mat.push_back(std::vector<double>{1.});
174
175 //
176 // first order quad points
177 //
178 if (d_quadOrder == 1) {
179 d_quads.clear();
180 // 1-d points are: {0} and weights are: {2}
181 fe::QuadData qd;
182 qd.d_w = 2.;
183 qd.d_p = util::Point();
184 qd.d_shapes = getShapes(qd.d_p);
186 qd.d_J = ident_mat;
187 qd.d_detJ = 1.;
188 d_quads.push_back(qd);
189 }
190
191 //
192 // second order quad points
193 //
194 if (d_quadOrder == 2) {
195 d_quads.clear();
196 // 1-d points are: {-1/sqrt{3], 1/sqrt{3}} and weights are: {1,1}
197 fe::QuadData qd;
198 qd.d_w = 1.;
199 qd.d_p = util::Point(-1. / std::sqrt(3.), 0., 0.);
200 qd.d_shapes = getShapes(qd.d_p);
202 qd.d_J = ident_mat;
203 qd.d_detJ = 1.;
204 d_quads.push_back(qd);
205
206 qd.d_w = 1.;
207 qd.d_p = util::Point(1. / std::sqrt(3.), 0., 0.);
208 qd.d_shapes = getShapes(qd.d_p);
210 qd.d_J = ident_mat;
211 qd.d_detJ = 1.;
212 d_quads.push_back(qd);
213 }
214
215 //
216 // third order quad points for triangle
217 //
218 if (d_quadOrder == 3) {
219 d_quads.clear();
220 // 1-d points are: {-sqrt{3}/sqrt{5}, 0, sqrt{3}/sqrt{5}}
221 // weights are: {5/9, 8/9, 5/9}
222 fe::QuadData qd;
223 qd.d_w = 5. / 9.;
224 qd.d_p = util::Point(-std::sqrt(3.) / std::sqrt(5.), 0., 0.);
225 qd.d_shapes = getShapes(qd.d_p);
227 qd.d_J = ident_mat;
228 qd.d_detJ = 1.;
229 d_quads.push_back(qd);
230
231 qd.d_w = 8. / 9.;
232 qd.d_p = util::Point();
233 qd.d_shapes = getShapes(qd.d_p);
235 qd.d_J = ident_mat;
236 qd.d_detJ = 1.;
237 d_quads.push_back(qd);
238
239 qd.d_w = 5. / 9.;
240 qd.d_p = util::Point(std::sqrt(3.) / std::sqrt(5.), 0., 0.);
241 qd.d_shapes = getShapes(qd.d_p);
243 qd.d_J = ident_mat;
244 qd.d_detJ = 1.;
245 d_quads.push_back(qd);
246 }
247
248 //
249 // fourth order quad points for triangle
250 //
251 if (d_quadOrder == 4) {
252 d_quads.clear();
253 fe::QuadData qd;
254 qd.d_w = 0.6521451548625461;
255 qd.d_p = util::Point(-0.3399810435848563, 0., 0.);
256 qd.d_shapes = getShapes(qd.d_p);
258 qd.d_J = ident_mat;
259 qd.d_detJ = 1.;
260 d_quads.push_back(qd);
261
262 qd.d_w = 0.6521451548625461;
263 qd.d_p = util::Point(0.3399810435848563, 0., 0.);
264 qd.d_shapes = getShapes(qd.d_p);
266 qd.d_J = ident_mat;
267 qd.d_detJ = 1.;
268 d_quads.push_back(qd);
269
270 qd.d_w = 0.3478548451374538;
271 qd.d_p = util::Point(-0.8611363115940526, 0., 0.);
272 qd.d_shapes = getShapes(qd.d_p);
274 qd.d_J = ident_mat;
275 qd.d_detJ = 1.;
276 d_quads.push_back(qd);
277
278 qd.d_w = 0.3478548451374538;
279 qd.d_p = util::Point(0.8611363115940526, 0., 0.);
280 qd.d_shapes = getShapes(qd.d_p);
282 qd.d_J = ident_mat;
283 qd.d_detJ = 1.;
284 d_quads.push_back(qd);
285 }
286
287 //
288 // fifth order quad points for triangle
289 //
290 if (d_quadOrder == 5) {
291 d_quads.clear();
292 fe::QuadData qd;
293 qd.d_w = 0.5688888888888889;
294 qd.d_p = util::Point();
295 qd.d_shapes = getShapes(qd.d_p);
297 qd.d_J = ident_mat;
298 qd.d_detJ = 1.;
299 d_quads.push_back(qd);
300
301 qd.d_w = 0.4786286704993665;
302 qd.d_p = util::Point(-0.5384693101056831, 0., 0.);
303 qd.d_shapes = getShapes(qd.d_p);
305 qd.d_J = ident_mat;
306 qd.d_detJ = 1.;
307 d_quads.push_back(qd);
308
309 qd.d_w = 0.4786286704993665;
310 qd.d_p = util::Point(0.5384693101056831, 0., 0.);
311 qd.d_shapes = getShapes(qd.d_p);
313 qd.d_J = ident_mat;
314 qd.d_detJ = 1.;
315 d_quads.push_back(qd);
316
317 qd.d_w = 0.2369268850561891;
318 qd.d_p = util::Point(-0.9061798459386640, 0., 0.);
319 qd.d_shapes = getShapes(qd.d_p);
321 qd.d_J = ident_mat;
322 qd.d_detJ = 1.;
323 d_quads.push_back(qd);
324
325 qd.d_w = 0.2369268850561891;
326 qd.d_p = util::Point(0.9061798459386640, 0., 0.);
327 qd.d_shapes = getShapes(qd.d_p);
329 qd.d_J = ident_mat;
330 qd.d_detJ = 1.;
331 d_quads.push_back(qd);
332 }
333}
size_t d_quadOrder
Order of quadrature point integration approximation.
Definition baseElem.h:243
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
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 118 of file lineElem.cpp.

119 {
120 auto xi = (2. * p.d_x - nodes[0].d_x - nodes[1].d_x) /
121 (nodes[0].d_x - nodes[1].d_x);
122
123 if (util::isLess(xi, -1. - 1.0E-8) ||
124 util::isGreater(xi, 1. + 1.0E-8) ) {
125 std::cerr << "Error: Trying to map point p = " << p.d_x
126 << " in given line to reference line.\n"
127 << "But the point p does not belong to line = {"
128 << nodes[0].d_x << ", " << nodes[1].d_x << "}.\n";
129 exit(1);
130 }
131
132 if (util::isLess(xi, -1.))
133 xi = -1.;
134 if (util::isGreater(xi, 1.))
135 xi = 1.;
136
137 return {xi, 0., 0.};
138}
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

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: