PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
util Namespace Reference

Collection of methods useful in simulation. More...

Namespaces

namespace  io
 Provides geometrical methods such as point inside rectangle.
 
namespace  methods
 Provides fast methods to add/subtract list of data, to find maximum/minimum from list of data.
 
namespace  parallel
 Implements some key functions and classes regularly used in the code when running with MPI.
 

Data Structures

class  DistributionSample
 Templated probability distribution. More...
 
struct  Matrix3
 A structure to represent 3d matrices. More...
 
struct  Point
 A structure to represent 3d vectors. More...
 
struct  SymMatrix3
 A structure to represent 3d matrices. More...
 

Functions

bool isGreater (const double &a, const double &b)
 Returns true if a > b.
 
bool isLess (const double &a, const double &b)
 Returns true if a < b.
 
double hatFunction (const double &x, const double &x_min, const double &x_max)
 Computes hat function at given point.
 
double hatFunctionQuick (const double &x, const double &x_min, const double &x_max)
 Computes hat function at given point.
 
double linearStepFunc (const double &x, const double &x1, const double &x2)
 Compute linear step function.
 
double gaussian (const double &r, const double &a, const double &beta)
 Compute gaussian function in 1-d.
 
double gaussian2d (const util::Point &x, const size_t &dof, const std::vector< double > &params)
 Compute gaussian function in 2-d.
 
double doubleGaussian2d (const util::Point &x, const size_t &dof, const std::vector< double > &params)
 Compute sum of two gaussian function in 2-d.
 
double equivalentMass (const double &m1, const double &m2)
 Compute harmonic mean of m1 and m2.
 
double harmonicMean (const double &m1, const double &m2)
 
double normalContactStiffness (const double &K1, const double &K2, const double &horizon, int horizonPower=5)
 Silling normal contact stiffness from two bulk moduli and the horizon.
 
double selfContactStiffness (const double &K, const double &horizon, int horizonPower=5)
 Contact stiffness for a body against itself.
 
bool checkMatrix (const std::vector< std::vector< double > > &m)
 Checks matrix.
 
std::vector< double > dot (const std::vector< std::vector< double > > &m, const std::vector< double > &v)
 Computes the dot product between matrix and vector.
 
std::vector< std::vector< double > > transpose (const std::vector< std::vector< double > > &m)
 Computes the tranpose of matrix.
 
double det (const std::vector< std::vector< double > > &m)
 Computes the determinant of matrix.
 
std::vector< std::vector< double > > inv (const std::vector< std::vector< double > > &m)
 Computes the determinant of matrix.
 
RandGenerator get_rd_gen (int seed=-1)
 Return random number generator.
 
std::default_random_engine get_rd_engine (int &seed)
 Return random number generator.
 
double transform_to_normal_dist (double mean, double std, double sample)
 Transform sample from N(0,1) to N(mean, std^2)
 
double transform_to_uniform_dist (double min, double max, double sample)
 Transform sample from U(0,1) to U(a,b)
 
Rotation
std::vector< double > rotateCW2D (const std::vector< double > &x, const double &theta)
 Rotates a vector in xy-plane in clockwise direction.
 
util::Point rotateCW2D (const util::Point &x, const double &theta)
 Rotates a vector in xy-plane in clockwise direction.
 
std::vector< double > rotateACW2D (const std::vector< double > &x, const double &theta)
 Rotates a vector in xy-plane in anti-clockwise direction.
 
util::Point rotateACW2D (const util::Point &x, const double &theta)
 Rotates a vector in xy-plane in anti-clockwise direction.
 
std::vector< double > rotate2D (const std::vector< double > &x, const double &theta)
 Rotates a vector in xy-plane assuming ACW convention.
 
util::Point rotate2D (const util::Point &x, const double &theta)
 Rotates a vector in xy-plane assuming ACW convention.
 
util::Point derRotate2D (const util::Point &x, const double &theta)
 Computes derivative of rotation wrt to time.
 
util::Point rotate (const util::Point &p, const double &theta, const util::Point &axis)
 Returns the vector after rotating by desired angle.
 
double angle (util::Point a, util::Point b)
 Computes angle between two vectors.
 
double angle (util::Point a, util::Point b, util::Point axis, bool is_axis=true)
 Computes angle between two vectors.
 

Variables

VTK Element types
static const int vtk_type_vertex = 1
 Integer flag for vertex (point) element.
 
static const int vtk_type_poly_vertex = 2
 Integer flag for poly vertex element.
 
static const int vtk_type_line = 3
 Integer flag for line element.
 
static const int vtk_type_poly_line = 4
 Integer flag for poly line element.
 
static const int vtk_type_triangle = 5
 Integer flag for triangle element.
 
static const int vtk_type_triangle_strip = 6
 Integer flag for triangle strip element.
 
static const int vtk_type_polygon = 7
 Integer flag for polygon element.
 
static const int vtk_type_pixel = 8
 Integer flag for pixel element.
 
static const int vtk_type_quad = 9
 Integer flag for quad element.
 
static const int vtk_type_tetra = 10
 Integer flag for tetrahedron element.
 
static const int vtk_type_voxel = 11
 Integer flag for voxel element.
 
static const int vtk_type_hexahedron = 12
 Integer flag for hexahedron element.
 
static const int vtk_type_wedge = 13
 Integer flag for wedge element.
 
static const int vtk_type_pyramid = 14
 Integer flag for pyramid element.
 
static int vtk_map_element_to_num_nodes [16]
 Map from element type to number of nodes (for vtk)
 
static int vtk_to_msh_element_type_map [16]
 Map from vtk element type to msh element type.
 
Gmsh Element types
static const int msh_type_line = 1
 Integer flag for line element.
 
static const int msh_type_triangle = 2
 Integer flag for triangle element.
 
static const int msh_type_quadrangle = 3
 Integer flag for quadrangle element.
 
static const int msh_type_tetrahedron = 4
 Integer flag for tetrahedron element.
 
static const int msh_type_hexahedron = 5
 Integer flag for hexahedron element.
 
static const int msh_type_prism = 6
 Integer flag for prism element.
 
static const int msh_type_pyramid = 7
 Integer flag for pyramid element.
 
static const int msh_type_line_second_order = 8
 Integer flag for line (second order) element.
 
static const int msh_type_traingle_second_order = 9
 Integer flag for traingle (second order) element.
 
static const int msh_type_quadrangle_second_order = 10
 Integer flag for quadrangle (second order) element.
 
static const int msh_type_vertex = 15
 Integer flag for vertex (point) element.
 
static int msh_map_element_to_num_nodes [16]
 Map from element type to number of nodes (for msh)
 

Detailed Description

Collection of methods useful in simulation.

This namespace provides number of useful functions and struct definition.

See also
Point, Matrix3, SymMatrix3, compare, transformation

Function Documentation

◆ angle() [1/2]

double util::angle ( util::Point  a,
util::Point  b 
)

Computes angle between two vectors.

Parameters
aVector 1
bVector 2
Returns
angle Angle between vector a and b

Definition at line 81 of file transformationFunctions.cpp.

81 {
82
83 if ((a - b).lengthSq() < 1.0E-12)
84 return 0.;
85
86 // since we do not know which side of plane given by normal
87 // a x b / |a x b| is +ve, we compute the angle using cosine
88 return std::acos(b * a / (b.length() * a.length()));
89}
double length() const
Computes the Euclidean length of the vector.
Definition point.h:124

References util::Point::length().

Referenced by angle(), geom::distanceBetweenPlanes(), geom::doLinesIntersect(), and test::testUtilMethods().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ angle() [2/2]

double util::angle ( util::Point  a,
util::Point  b,
util::Point  axis,
bool  is_axis = true 
)

Computes angle between two vectors.

Parameters
aVector 1
bVector 2
axisAxis of rotation
is_axisIf true then axis is the axis of orientation, otherwise axis specifies the +ve side of the plane in which a and b are
Returns
angle Angle between vector a and b

Definition at line 91 of file transformationFunctions.cpp.

91 {
92
93 if ((a - b).lengthSq() < 1.0E-12)
94 return 0.;
95
96 if (is_axis) {
97
98 // normal to plane of rotation
99 util::Point n = axis / axis.length();
100
101 util::Point na = n.cross(a);
102
103 double theta = std::atan(b * na / (a * b - (b * n) * (a * n)));
104 if (theta < 0.)
105 theta += M_PI;
106
107 if (b * na < 0.)
108 theta = M_PI + theta;
109
110 return theta;
111 } else {
112
113 auto theta = angle(a, b);
114
115 // TODO below only works in specific cases such as when vectors in xy
116 // plane and vector x gives the positive plane direction, i.e. whether
117 // (0, 0, 1) is +ve or (0, 0, -1) is +ve. Similar is true for yz, zx
118 // planes.
119
120 // normal to a and b
121 util::Point n_ab = a.cross(b);
122
123 double orient = axis * n_ab;
124 if (orient < 0.)
125 return 2. * M_PI - theta;
126 else
127 return theta;
128 }
129}
A structure to represent 3d vectors.
Definition point.h:30
Point cross(const Point &b) const
Computes the cross product between this vector and given vector.
Definition point.h:157

References angle(), util::Point::cross(), and util::Point::length().

Here is the call graph for this function:

◆ checkMatrix()

bool util::checkMatrix ( const std::vector< std::vector< double > > &  m)

Checks matrix.

Parameters
mMatrix
Returns
true If matrix is okay

Definition at line 15 of file matrix.cpp.

15 {
16
17 size_t row_size = m.size();
18 // if (row_size > 3) {
19 // std::cerr << "Error: Determinant of matrix above size 3 is not "
20 // "implemented\n";
21 // exit(1);
22 // }
23
24 if (m.size() != m[0].size()) {
25 std::ostringstream oss;
26 oss << "Error in matrix = [";
27 for (auto a : m)
28 oss << util::io::printStr(a) << "\n";
29 oss << "].\n";
30 std::cout << oss.str();
31 // exit(1);
32 return false;
33 }
34
35 return true;
36}
Collection of methods useful in simulation.
Definition constants.h:14

References util::io::printStr().

Here is the call graph for this function:

◆ derRotate2D()

util::Point util::derRotate2D ( const util::Point &  x,
const double &  theta 
)

Computes derivative of rotation wrt to time.

If \( R(x,t) = Q(at)x \) then \( dR/dt = a Q' x \). This function returns \( Q' x \).

Parameters
xPoint
thetaAngle
Returns
Point after rotation

Definition at line 60 of file transformationFunctions.cpp.

61 {
62
63 return {-x.d_x * std::sin(theta) - x.d_y * std::cos(theta),
64 x.d_x * std::cos(theta) - x.d_y * std::sin(theta), 0.0};
65}
double d_y
the y coordinate
Definition point.h:36
double d_x
the x coordinate
Definition point.h:33

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

Referenced by loading::ParticleULoading::apply().

Here is the caller graph for this function:

◆ det()

double util::det ( const std::vector< std::vector< double > > &  m)

Computes the determinant of matrix.

Parameters
mMatrix
Returns
det Determinant

Definition at line 75 of file matrix.cpp.

75 {
76
77 //checkMatrix(m);
78 assert((m.size() == m[0].size()) && "Matrix must be a square matrix");
79 assert((m.size() <= 3) && "Square of matrix of size 3 or below");
80
81 size_t row_size = m.size();
82 if (row_size == 1)
83 return m[0][0];
84 else if (row_size == 2)
85 return m[0][0] * m[1][1] - m[0][1] * m[1][0];
86 else
87 return m[0][0] * (m[1][1] * m[2][2] - m[2][1] * m[1][2]) -
88 m[0][1] * (m[1][0] * m[2][2] - m[2][0] * m[1][2]) +
89 m[0][2] * (m[1][0] * m[2][1] - m[2][0] * m[1][1]);
90}

Referenced by fe::HexElem::getJacobian(), fe::TetElem::getJacobian(), inv(), and fe::mapToPhysical().

Here is the caller graph for this function:

◆ dot()

std::vector< double > util::dot ( const std::vector< std::vector< double > > &  m,
const std::vector< double > &  v 
)

Computes the dot product between matrix and vector.

Parameters
mMatrix
vvector
Returns
vector Dot product

Definition at line 38 of file matrix.cpp.

39 {
40
41 //checkMatrix(m);
42 size_t row_size = m.size();
43 size_t col_size = m[0].size();
44
45 assert((col_size == v.size()) && "Column size of matrix must match row of vector for dot product");
46
47 std::vector<double> r(row_size, 0.);
48
49 for (size_t i=0; i<row_size; i++)
50 for (size_t j = 0; j < col_size; j++)
51 r[i] += m[i][j] * v[j];
52
53 return r;
54}

Referenced by fe::TetElem::getDerShapes(), fe::TetElem::mapPointToRefElem(), and fe::mapToPhysical().

Here is the caller graph for this function:

◆ doubleGaussian2d()

double util::doubleGaussian2d ( const util::Point &  x,
const size_t &  dof,
const std::vector< double > &  params 
)

Compute sum of two gaussian function in 2-d.

Double guassian (2-d) function:

\[ f(x,y) = (f_1(x,y), f_2(x,y)) + (g_1(x,y), g_2(x,y)), \]

where \( (f_1,f_2)\) and \((g_1, g_2)\) are two guassian 2-d function as described in guassian2d() with different values of \( (x_c, y_c), a, (d_1, d_2)\).

Parameters
xCoordinates of point
paramsList of parameters
dofComponent of guassian function
Returns
value Component of guassian 2-d vector function along dof

Definition at line 110 of file function.cpp.

112 {
113
114 if (params.size() < 10) {
115 throw std::runtime_error(
117 << "Error: Not enough parameters to compute guassian 2-d "
118 "function.\n");
119 }
120
121 return util::gaussian(
122 x.dist(util::Point(params[0], params[1], 0.)), params[9],
123 params[8]) *
124 params[4 + dof] +
126 x.dist(util::Point(params[2], params[3], 0.)), params[9],
127 params[8]) *
128 params[6 + dof];
129}
Collects a message with stream syntax for use in an exception.
Definition io.h:52
double gaussian(const double &r, const double &a, const double &beta)
Compute gaussian function in 1-d.
Definition function.cpp:89
double dist(const Point &b) const
Computes the distance between a given point from this point.
Definition point.h:146

References util::Point::dist(), and gaussian().

Here is the call graph for this function:

◆ equivalentMass()

double util::equivalentMass ( const double &  m1,
const double &  m2 
)

Compute harmonic mean of m1 and m2.

Parameters
m1Mass 1
m2Mass 2
Returns
m Harmonic mean

Definition at line 131 of file function.cpp.

131 {
132 return 2. * m1 * m2 / (m1 + m2);
133}

Referenced by contact::Damping::apply(), contact::PairForce::nodeDampingForce(), and contact::Contact::setup().

Here is the caller graph for this function:

◆ gaussian()

double util::gaussian ( const double &  r,
const double &  a,
const double &  beta 
)

Compute gaussian function in 1-d.

Guassian (1-d) function: \( f(r) = a \exp(-\frac{r^2}{\beta}). \)

Here \( a\) is the amplitude and \( \beta \) is the exponential factor.

Parameters
rDistance from origin
aAmplitude
betaFactor in exponential function
Returns
value Component of guassian 1-d function

Definition at line 89 of file function.cpp.

90 {
91 return a * std::exp(-std::pow(r, 2) / beta);
92}

Referenced by doubleGaussian2d(), and gaussian2d().

Here is the caller graph for this function:

◆ gaussian2d()

double util::gaussian2d ( const util::Point &  x,
const size_t &  dof,
const std::vector< double > &  params 
)

Compute gaussian function in 2-d.

Guassian (2-d) function:

\[ f(x,y) = (f_1(x,y), f_2(x,y)), \]

where

\[ f_1(x,y) = a \exp(-\frac{(x-x_c)^2 + (y-y_c)^2}{\beta}) d_1, \quad f_1(x,y) = a \exp(-\frac{(x-x_c)^2 + (y-y_c)^2}{\beta}) d_2. \]

Here \( (x_c,y_c) \) is the center of the pulse, \( a\) is the amplitude, \( \beta \) is the exponential factor, and \( (d_1,d_2)\) is the direction of the pulse.

Parameters
xCoordinates of point
paramsList of parameters
dofComponent of guassian function
Returns
value Component of guassian 2-d vector function along dof

Definition at line 94 of file function.cpp.

95 {
96
97 if (params.size() < 6) {
98 throw std::runtime_error(
100 << "Error: Not enough parameters to compute guassian 2-d "
101 "function.\n");
102 }
103
104 return util::gaussian(
105 x.dist(util::Point(params[0], params[1], 0.)), params[5],
106 params[4]) *
107 params[2 + dof];
108}

References util::Point::dist(), and gaussian().

Here is the call graph for this function:

◆ get_rd_engine()

std::default_random_engine util::get_rd_engine ( int &  seed)
inline

Return random number generator.

Parameters
seedSeed
Returns
Random number generator

Definition at line 48 of file randomDist.h.

48 {
49
50 //return std::default_random_engine();
51
52 if (seed < 0) {
53 std::random_device rd;
54 seed = rd();
55 }
56
57 return std::default_random_engine(seed);
58}

◆ get_rd_gen()

RandGenerator util::get_rd_gen ( int  seed = -1)
inline

Return random number generator.

Parameters
seedSeed
Returns
Random number generator

Definition at line 30 of file randomDist.h.

30 {
31
32 //return RandGenerator();
33
34 if (seed < 0) {
35 std::random_device rd;
36 seed = rd();
37 }
38
39 return RandGenerator(seed);
40}
std::mt19937 RandGenerator
Definition randomDist.h:16

Referenced by anonymous_namespace{testNSearchLib.cpp}::assignRandomTags(), util::DistributionSample< T >::init(), anonymous_namespace{testNSearchLib.cpp}::lattice(), anonymous_namespace{testNSearchLib.cpp}::neighSearchTreeClosestPointSizet(), and test::testTaskflow().

Here is the caller graph for this function:

◆ harmonicMean()

double util::harmonicMean ( const double &  m1,
const double &  m2 
)

Definition at line 135 of file function.cpp.

135 {
136 return 2. * m1 * m2 / (m1 + m2);
137}

Referenced by anonymous_namespace{main.cpp}::buildInputJson(), anonymous_namespace{main.cpp}::buildInputJson(), normalContactStiffness(), and test::testContactStiffness().

Here is the caller graph for this function:

◆ hatFunction()

double util::hatFunction ( const double &  x,
const double &  x_min,
const double &  x_max 
)

Computes hat function at given point.

Hat function: f ^ | | 1 o | /|\ | / | \ | / | \ | / | \ | / | \ | / | \ o____________o____________o______\ x / x_min x_max

Parameters
xPoint in real line
x_minLeft side point in real line
x_maxRight side point in real line
Returns
value Evaluation of hat function at x

Definition at line 27 of file function.cpp.

28 {
29
30 if (util::isGreater(x, x_min - 1.0E-12) and
31 util::isLess(x, x_max + 1.0E-12)) {
32
33 double x_mid = 0.5 * (x_min + x_max);
34 double l = x_mid - x_min;
35
36 // support below this width is treated as a point load (dirac)
37 if (l < 1.0E-12)
38 return 1.0;
39
40 if (util::isLess(x, x_mid))
41 return (x - x_min) / l;
42 else
43 return (x_max - x) / l;
44 } else
45 return 0.0;
46}
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 isGreater(), and isLess().

Referenced by loading::ParticleFLoading::apply(), and loading::ParticleULoading::apply().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hatFunctionQuick()

double util::hatFunctionQuick ( const double &  x,
const double &  x_min,
const double &  x_max 
)

Computes hat function at given point.

This version does not test if point x is in valid interval.

Hat function: f ^ | | 1 o | /|\ | / | \ | / | \ | / | \ | / | \ | / | \ o____________o____________o______\ x / x_min x_max

Parameters
xPoint in real line
x_minLeft side point in real line
x_maxRight side point in real line
Returns
value Evaluation of hat function at x

Definition at line 48 of file function.cpp.

49 {
50
51 double x_mid = 0.5 * (x_min + x_max);
52 double l = x_mid - x_min;
53
54 // support below this width is treated as a point load (dirac)
55 if (l < 1.0E-12)
56 return 1.0;
57
58 if (util::isLess(x, x_mid))
59 return (x - x_min) / l;
60 else
61 return (x_max - x) / l;
62}

References isLess().

Here is the call graph for this function:

◆ inv()

std::vector< std::vector< double > > util::inv ( const std::vector< std::vector< double > > &  m)

Computes the determinant of matrix.

Parameters
mMatrix
Returns
inv Inverse of m

Definition at line 93 of file matrix.cpp.

93 {
94
95 //checkMatrix(m);
96 assert((m.size() == m[0].size()) && "Matrix must be a square matrix");
97 assert((m.size() <= 3) && "Square of matrix of size 3 or below");
98
99 size_t row_size = m.size();
100
101 std::vector<std::vector<double>> n(row_size);
102 for (size_t i =0; i<row_size; i++)
103 n[i] = std::vector<double>(row_size, 0.);
104
105 if (row_size == 1) {
106 n[0][0] = 1. / m[0][0];
107
108 return n;
109 } else if (row_size == 2) {
110
111 auto det_inv = 1. / det(m);
112
113 n[0][0] = det_inv * m[1][1];
114 n[1][1] = det_inv * m[0][0];
115
116 n[0][1] = -det_inv * m[0][1];
117 n[1][0] = -det_inv * m[1][0];
118
119 return n;
120 } else {
121
122 auto det_inv = 1. / det(m);
123
124 n[0][0] = det_inv *
125 (m[1][1] * m[2][2] - m[2][1] * m[1][2]);
126 n[0][1] = -det_inv *
127 (m[0][1] * m[2][2] - m[2][1] * m[0][2]);
128 n[0][2] = det_inv *
129 (m[0][1] * m[1][2] - m[1][1] * m[0][2]);
130
131 n[1][0] = -det_inv *
132 (m[1][0] * m[2][2] - m[2][0] * m[1][2]);
133 n[1][1] = det_inv *
134 (m[0][0] * m[2][2] - m[2][0] * m[0][2]);
135 n[1][2] = -det_inv *
136 (m[0][0] * m[1][2] - m[1][0] * m[0][2]);
137
138 n[2][0] = det_inv *
139 (m[1][0] * m[2][1] - m[2][0] * m[1][1]);
140 n[2][1] = -det_inv *
141 (m[0][0] * m[2][1] - m[2][0] * m[0][1]);
142 n[2][2] = det_inv *
143 (m[0][0] * m[1][1] - m[1][0] * m[0][1]);
144
145 return n;
146 }
147}
double det(const std::vector< std::vector< double > > &m)
Computes the determinant of matrix.
Definition matrix.cpp:75

References det().

Referenced by fe::TetElem::getDerShapes(), fe::TetElem::mapPointToRefElem(), and fe::mapToPhysical().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isGreater()

bool util::isGreater ( const double &  a,
const double &  b 
)

Returns true if a > b.

Parameters
aValue a
bValue b
Returns
True if a is definitely greater than b

Definition at line 17 of file function.cpp.

17 {
18 return (a - b) > ((std::abs(a) < std::abs(b) ? std::abs(b) : std::abs(a)) *
20}
#define COMPARE_EPS
Definition function.h:18

References COMPARE_EPS.

Referenced by loading::ParticleFLoading::apply(), contact::Damping::apply(), geom::AnnulusGeomObject::center(), geom::ComplexGeomObject::center(), anonymous_namespace{tetElem.cpp}::checkPoint(), postprocess::Postprocess::checkStop(), geom::circumscribedRadiusInBox(), anonymous_namespace{materialUtil.cpp}::computeHydrostaticStrainI(), material::RnpMaterial::computeParameters(), material::PmbMaterial::computeParameters(), material::PdElastic::computeParameters(), material::PdState::computeParameters(), anonymous_namespace{materialUtil.cpp}::computeStateMxI(), anonymous_namespace{materialUtil.cpp}::computeStateThetaxI(), contact::correctedContactVolume(), material::RnpMaterial::getBondEF(), material::PmbMaterial::getBondEF(), hatFunction(), geom::inscribedRadiusInBox(), geom::Line::isInside(), geom::Cylinder::isInside(), geom::BoxPartition::isNear(), geom::Line::isNear(), geom::Cylinder::isNear(), geom::Line::isNearBoundary(), geom::Cylinder::isNearBoundary(), geom::isPointInsideAngledRectangle(), geom::isPointInsideBox(), geom::isPointInsideCuboid(), geom::isPointInsideRectangle(), geom::isPointInsideRectangle(), fe::LineElem::mapPointToRefElem(), fe::TetElem::mapPointToRefElem(), fe::TriElem::mapPointToRefElem(), contact::Contact::setup(), contact::PairForce::springForce(), contact::StickSlipPairForce::springForce(), postprocess::Postprocess::twoParticle(), anonymous_namespace{materialUtil.cpp}::updateBondFractureDataI(), and contact::Contact::updateSearchParameters().

Here is the caller graph for this function:

◆ isLess()

bool util::isLess ( const double &  a,
const double &  b 
)

Returns true if a < b.

Parameters
aValue a
bValue b
Returns
True if a is definitely less than b

Definition at line 22 of file function.cpp.

22 {
23 return (b - a) > ((std::abs(a) < std::abs(b) ? std::abs(b) : std::abs(a)) *
25}

References COMPARE_EPS.

Referenced by contact::Damping::apply(), geom::areBoxesNear(), anonymous_namespace{tetElem.cpp}::checkPoint(), mesh::Mesh::computeBBox(), geom::computeBBox(), contact::Contact::computeForces(), mesh::Mesh::computeMeshSize(), geom::computeMeshSize(), geom::computeMeshSize(), material::RnpMaterial::computeParameters(), material::PmbMaterial::computeParameters(), material::PdElastic::computeParameters(), material::PdState::computeParameters(), anonymous_namespace{materialUtil.cpp}::computeStateMxI(), geom::anonymous_namespace{geomObjects.cpp}::ellipseMetricInside(), mesh::getMaxShearStressAndLoc(), mesh::getStrainStress(), hatFunction(), hatFunctionQuick(), geom::Rectangle::inscribedRadius(), geom::Cuboid::inscribedRadius(), geom::Line::isInside(), geom::Circle::isInside(), geom::Sphere::isInside(), geom::Ellipsoid::isInside(), geom::Cylinder::isInside(), geom::Circle::isNear(), geom::Ellipse::isNear(), geom::Sphere::isNear(), geom::BoxPartition::isNear(), geom::Line::isNear(), geom::Circle::isNear(), geom::Sphere::isNear(), geom::Ellipsoid::isNear(), geom::Cylinder::isNear(), geom::Line::isNearBoundary(), geom::Square::isNearBoundary(), geom::Rectangle::isNearBoundary(), geom::Cube::isNearBoundary(), geom::Cuboid::isNearBoundary(), geom::Circle::isNearBoundary(), geom::Sphere::isNearBoundary(), geom::Cylinder::isNearBoundary(), geom::OpenRectChannel2D::isNearBoundary(), geom::isPointInsideAngledRectangle(), geom::isPointInsideBox(), geom::isPointInsideCuboid(), geom::isPointInsideRectangle(), geom::isPointInsideRectangle(), linearStepFunc(), fe::LineElem::mapPointToRefElem(), fe::TetElem::mapPointToRefElem(), fe::TriElem::mapPointToRefElem(), contact::PairForce::nodeDampingForce(), particle::RefParticle::RefParticle(), contact::PairForce::springForce(), contact::StickSlipPairForce::springForce(), postprocess::Postprocess::twoParticle(), and contact::Contact::updateSearchParameters().

◆ linearStepFunc()

double util::linearStepFunc ( const double &  x,
const double &  x1,
const double &  x2 
)

Compute linear step function.

Step function:

f ^ | __________ | / | / | _______/ | / | / |/_________________________ t x1 x1+x2

  • Linear (with slope 1) in [0,l1), constant in [l1,l1+l2)
  • Periodic with periodicity l1+l2
Parameters
xPoint in real line
x1Point such that function is linear with slope 1 in [0, x1)
x2Point such that function is constant in [x1, x1 + x2)
Returns
value Evaluation of step function at x

Definition at line 64 of file function.cpp.

65 {
66
67 //
68 // a = floor(x/(x1+x2))
69 // xl = a * (x1 + x2), xm = xl + x1, xr = xm + x2
70 // fl = a * x1
71 //
72 // At xl, value of the function is = period number \times x1
73 //
74 // From xl to xm, the function grows linear with slope 1
75 // so the value in between [xl, xm) will be
76 // fl + (x - xl) = a*x1 + (x - a*(x1+x2)) = x - a*x2
77 //
78 // In [xm, xr) function is constant and the value is
79 // fl + (xm - xl) = a*x1 + (xl + x1 - xl) = (a+1)*x1
80
81 double period = std::floor(x / (x1 + x2));
82
83 if (util::isLess(x, period * (x1 + x2) + x1))
84 return x - period * x2;
85 else
86 return (period + 1.) * x1;
87}

References isLess().

Referenced by loading::ParticleFLoading::apply().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ normalContactStiffness()

double util::normalContactStiffness ( const double &  K1,
const double &  K2,
const double &  horizon,
int  horizonPower = 5 
)

Silling normal contact stiffness from two bulk moduli and the horizon.

\[ K_n = \frac{18\,\bar{K}}{\pi \delta^{p}}, \quad \bar{K} = \mathrm{harmonicMean}(K_1, K_2) \]

The contact force density in PairForce is \( K_n V_j \, \mathrm{overlap} \), so \( K_n \) carries one power of the horizon per spatial dimension of the nodal weight: \( p = 5 \) with 3D weights \( h^3 \), \( p = 4 \) with 2D weights \( h^2 \cdot 1\,\mathrm{m} \).

Note
The two-dimensional examples and the internal-contact stiffness in BaseParticle use \( p = 5 \), while the notched-impact driver uses \( p = 4 \) in two dimensions. That difference is older than this function. The exponent is an argument so that each caller keeps the value it had, and changing the default would change the contact force in every example.
Parameters
K1Bulk modulus of the first body
K2Bulk modulus of the second body
horizonPeridynamic horizon
horizonPowerPower of the horizon in the denominator
Returns
Kn Normal contact stiffness

Definition at line 139 of file function.cpp.

140 {
141 if (!(horizon > 0.))
142 throw std::invalid_argument(
143 "normalContactStiffness: horizon must be positive");
144 return 18. * util::harmonicMean(K1, K2) /
145 (M_PI * std::pow(horizon, horizonPower));
146}
double harmonicMean(const double &m1, const double &m2)
Definition function.cpp:135

References harmonicMean().

Referenced by anonymous_namespace{main.cpp}::buildInputJson(), anonymous_namespace{main.cpp}::buildInputJson(), anonymous_namespace{main.cpp}::buildInputJson(), anonymous_namespace{main.cpp}::buildInputJson(), anonymous_namespace{main.cpp}::buildInputJson(), getInputJson(), anonymous_namespace{main.cpp}::KnFromBulk(), main(), and test::testContactStiffness().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rotate()

util::Point util::rotate ( const util::Point &  p,
const double &  theta,
const util::Point &  axis 
)

Returns the vector after rotating by desired angle.

Parameters
pVector
thetaAngle of rotation
axisAxis of rotation
Returns
x Vector after rotation

Definition at line 67 of file transformationFunctions.cpp.

67 {
68
69 auto ct = std::cos(theta);
70 auto st = std::sin(theta);
71
72 // dot
73 double p_dot_n = p * axis;
74
75 // cross
76 util::Point n_cross_p = axis.cross(p);
77
78 return (1. - ct) * p_dot_n * axis + ct * p + st * n_cross_p;
79}

References util::Point::cross().

Referenced by geom::ParticleTransform::apply(), geom::Drum2D::Drum2D(), geom::Hexagon::Hexagon(), geom::Drum2D::isInside(), geom::mapSimilarity(), test::testUtilMethods(), geom::Plane::transform(), geom::Triangle::transform(), geom::Hexagon::transform(), geom::Drum2D::transform(), geom::Cylinder::transform(), geom::OpenRectChannel2D::transform(), and geom::Triangle::Triangle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rotate2D() [1/2]

std::vector< double > util::rotate2D ( const std::vector< double > &  x,
const double &  theta 
)

Rotates a vector in xy-plane assuming ACW convention.

Parameters
xPoint
thetaAngle
Returns
Point after rotation

Definition at line 45 of file transformationFunctions.cpp.

46 {
47
48 return std::vector<double>{x[0] * std::cos(theta) - x[1] * std::sin(theta),
49 x[0] * std::sin(theta) + x[1] * std::cos(theta),
50 0.0};
51}

Referenced by loading::ParticleULoading::apply().

Here is the caller graph for this function:

◆ rotate2D() [2/2]

util::Point util::rotate2D ( const util::Point &  x,
const double &  theta 
)

Rotates a vector in xy-plane assuming ACW convention.

Parameters
xPoint
thetaAngle
Returns
Point after rotation

Definition at line 53 of file transformationFunctions.cpp.

54 {
55
56 return {x.d_x * std::cos(theta) - x.d_y * std::sin(theta),
57 x.d_x * std::sin(theta) + x.d_y * std::cos(theta), 0.0};
58}

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

◆ rotateACW2D() [1/2]

std::vector< double > util::rotateACW2D ( const std::vector< double > &  x,
const double &  theta 
)

Rotates a vector in xy-plane in anti-clockwise direction.

Parameters
xPoint
thetaAngle
Returns
Point after rotation

Definition at line 31 of file transformationFunctions.cpp.

32 {
33
34 return rotateCW2D(x, -theta);
35}
std::vector< double > rotateCW2D(const std::vector< double > &x, const double &theta)
Rotates a vector in xy-plane in clockwise direction.

References rotateCW2D().

Referenced by test::testUtilMethods().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rotateACW2D() [2/2]

util::Point util::rotateACW2D ( const util::Point &  x,
const double &  theta 
)

Rotates a vector in xy-plane in anti-clockwise direction.

Parameters
xPoint
thetaAngle
Returns
Point after rotation

Definition at line 37 of file transformationFunctions.cpp.

38 {
39
40 return rotateCW2D(x, -theta);
41}

References rotateCW2D().

Here is the call graph for this function:

◆ rotateCW2D() [1/2]

std::vector< double > util::rotateCW2D ( const std::vector< double > &  x,
const double &  theta 
)

Rotates a vector in xy-plane in clockwise direction.

Parameters
xPoint
thetaAngle
Returns
Point after rotation

Definition at line 15 of file transformationFunctions.cpp.

16 {
17
18 return std::vector<double>{x[0] * std::cos(theta) + x[1] * std::sin(theta),
19 -x[0] * std::sin(theta) + x[1] * std::cos(theta),
20 0.0};
21}

Referenced by geom::isPointInsideAngledRectangle(), rotateACW2D(), rotateACW2D(), and test::testUtilMethods().

Here is the caller graph for this function:

◆ rotateCW2D() [2/2]

util::Point util::rotateCW2D ( const util::Point &  x,
const double &  theta 
)

Rotates a vector in xy-plane in clockwise direction.

Parameters
xPoint
thetaAngle
Returns
Point after rotation

Definition at line 23 of file transformationFunctions.cpp.

24 {
25
26 return {x.d_x * std::cos(theta) + x.d_y * std::sin(theta),
27 -x.d_x * std::sin(theta) + x.d_y * std::cos(theta), 0.0};
28}

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

◆ selfContactStiffness()

double util::selfContactStiffness ( const double &  K,
const double &  horizon,
int  horizonPower = 5 
)

Contact stiffness for a body against itself.

\[ K_n = \frac{18}{\pi \delta^{p}} K \]

Analytically this equals normalContactStiffness(K, K, horizon), because harmonicMean(K, K) == K. The two are separate functions because the order of operations is not the same in floating point. BaseParticle evaluates \( (18 / (\pi \delta^5)) \cdot K \). Over the 36 combinations of bulk modulus and horizon that the examples and tests use, the regrouped form \( 18 K / (\pi \delta^5) \) differs from it in the last bit in 8 cases, by 2e-16 relative. This function keeps the original order of operations so that the internal contact stiffness is unchanged.

Parameters
KBulk modulus
horizonPeridynamic horizon
horizonPowerPower of the horizon in the denominator
Returns
Kn Normal contact stiffness

Definition at line 148 of file function.cpp.

149 {
150 if (!(horizon > 0.))
151 throw std::invalid_argument(
152 "selfContactStiffness: horizon must be positive");
153 // Grouping preserved from BaseParticle for bit-for-bit equality.
154 return (18. / (M_PI * std::pow(horizon, horizonPower))) * K;
155}

Referenced by particle::BaseParticle::BaseParticle(), and test::testContactStiffness().

Here is the caller graph for this function:

◆ transform_to_normal_dist()

double util::transform_to_normal_dist ( double  mean,
double  std,
double  sample 
)
inline

Transform sample from N(0,1) to N(mean, std^2)

Parameters
meanMean of normal distribution
stdStd of normal distribution
sampleSample from N(0,1)
Returns
sample Transformed sample

Definition at line 68 of file randomDist.h.

68 {
69 return std * sample + mean;
70}

◆ transform_to_uniform_dist()

double util::transform_to_uniform_dist ( double  min,
double  max,
double  sample 
)
inline

Transform sample from U(0,1) to U(a,b)

Parameters
minMin of uniform distribution
maxMax of uniform distribution
sampleSample from U(0,1)
Returns
sample Transformed sample

Definition at line 80 of file randomDist.h.

80 {
81 return min + sample * (max - min);
82}

Referenced by particle::createParticlesFromFile().

Here is the caller graph for this function:

◆ transpose()

std::vector< std::vector< double > > util::transpose ( const std::vector< std::vector< double > > &  m)

Computes the tranpose of matrix.

Parameters
mMatrix
Returns
Matrix Transpose of m

Definition at line 56 of file matrix.cpp.

57 {
58
59 //checkMatrix(m);
60
61 size_t row_size = m.size();
62 size_t col_size = m[0].size();
63
64 std::vector<std::vector<double>> n(col_size);
65
66 for (size_t i=0; i<row_size; i++) {
67 n[i].resize(row_size);
68 for (size_t j=0; j<=col_size; j++)
69 n[j][i] = m[i][j];
70 }
71
72 return n;
73}

Referenced by fe::TetElem::mapPointToRefElem().

Here is the caller graph for this function: