PeriDEM 0.2.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  geometry
 Provides geometrical methods such as point inside rectangle.
 
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.
 
std::vector< util::PointgetCornerPoints (size_t dim, const std::pair< util::Point, util::Point > &box)
 Returns all corner points in the box.
 
std::vector< std::pair< util::Point, util::Point > > getEdges (size_t dim, const std::pair< util::Point, util::Point > &box)
 Returns all corner points in the box.
 
util::Point getCenter (size_t dim, const std::pair< util::Point, util::Point > &box)
 Returns center point.
 
double inscribedRadiusInBox (size_t dim, const std::pair< util::Point, util::Point > &box)
 Computes the radius of biggest circle/sphere completely within the object.
 
double circumscribedRadiusInBox (size_t dim, const std::pair< util::Point, util::Point > &box)
 Computes the radius of smallest circle/sphere which can have the box inside.
 
util::Point getPointOnLine (const util::Point &p1, const util::Point &p2, const double &s)
 Returns point in line formed by points p1 and p2.
 
double computeMeshSize (const std::vector< util::Point > &nodes)
 Computes minimum distance between any two nodes.
 
double computeMeshSize (const std::vector< util::Point > &nodes, size_t start, size_t end)
 Computes minimum distance between any two nodes.
 
std::pair< util::Point, util::PointcomputeBBox (const std::vector< util::Point > &nodes)
 Computes bounding box for vector nodes.
 
double computeInscribedRadius (const std::pair< util::Point, util::Point > &box)
 Computes maximum radius of circle/sphere within a given box.
 
std::pair< util::Point, util::PointtoPointBox (const std::vector< double > &p1, const std::vector< double > &p2)
 Create box from two coordinate data.
 
double triangleArea (const util::Point &x1, const util::Point &x2, const util::Point &x3)
 Compute area of triangle.
 
template<class T >
l2Dist (const std::vector< T > &x1, const std::vector< T > &x2)
 Computes l2 distance between two vectors.
 
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)
 
 print_const (arg, fmt='%4.6e', prefix="")
 
 print_list (arg, fmt='%4.6e', delim=', ')
 
 print_bool (arg, prefix="")
 
 print_dbl (arg, prefix="")
 
 print_int (arg, prefix="")
 
 print_dbl_list (arg, prefix="")
 
 print_int_list (arg, prefix="")
 
 print_point_gmsh (arg, n)
 
 print_cir_gmsh (arg, n)
 
 print_line_gmsh (arg, n)
 
 print_lineloop_gmsh (arg, n)
 
 gmsh_file_hdr (f)
 
 get_E (K, nu)
 
 get_G (E, nu)
 
 get_eff_k (k1, k2)
 
 get_max (l)
 
 rotate (p, theta, axis)
 
 get_ref_hex_points (center, radius, add_center=False)
 
 get_ref_drum_points (center, radius, width, add_center=False)
 
 does_intersect (p, particles, padding)
 
 does_intersect_rect (p, particles, padding, rect, is_3d=False)
 
 generate_circle_gmsh_input (filename, center, radius, mesh_size, pp_tag=None)
 
 generate_rectangle_gmsh_input (filename, rectangle, mesh_size, pp_tag=None)
 
 generate_hexagon_gmsh_input (filename, center, radius, mesh_size, pp_tag=None)
 
 generate_drum_gmsh_input (filename, center, radius, width, mesh_size, pp_tag=None)
 
Methods to check point in domain
bool isPointInsideBox (util::Point x, size_t dim, const std::pair< util::Point, util::Point > &box)
 Returns true if point is inside box.
 
bool isPointInsideRectangle (util::Point x, double x_min, double x_max, double y_min, double y_max)
 Checks if point is inside a rectangle.
 
bool isPointInsideRectangle (util::Point x, util::Point x_lb, util::Point x_rt)
 Checks if point is inside a rectangle.
 
bool isPointInsideAngledRectangle (util::Point x, double x_min, double x_max, double y_min, double y_max, double theta)
 Checks if point is inside an angled rectangle.
 
bool isPointInsideCuboid (util::Point x, util::Point x_lbb, util::Point x_rtf)
 Checks if point is inside a cuboid.
 
bool isPointInsideCylinder (const util::Point &p, const double &length, const double &radius, const util::Point &axis)
 Returns true if point is inside the cylinder.
 
bool isPointInsideCylinder (const util::Point &p, const double &radius, const util::Point &x1, const util::Point &x2)
 Returns true if point is inside the cylinder.
 
bool isPointInsideEllipse (const util::Point &p, const util::Point &center, const std::vector< double > &radius_vec, unsigned int dim)
 Returns true if point is inside the ellipsoid.
 
bool isPointInsideEllipse (const util::Point &p, const util::Point &center, const std::vector< double > &radius_vec, unsigned int dim, double &d)
 Returns true if point is inside the ellipsoid.
 
Methods to check intersection of various objects
bool areBoxesNear (const std::pair< util::Point, util::Point > &b1, const std::pair< util::Point, util::Point > &b2, const double &tol, size_t dim)
 Checks if given two boxes are within given distance from each other.
 
bool doLinesIntersect (const std::pair< util::Point, util::Point > &line_1, const std::pair< util::Point, util::Point > &line_2)
 Do lines intersect.
 
double distanceBetweenLines (const std::pair< util::Point, util::Point > &line_1, const std::pair< util::Point, util::Point > &line_2)
 Compute distance between lines.
 
double distanceBetweenSegments (const std::pair< util::Point, util::Point > &line_1, const std::pair< util::Point, util::Point > &line_2)
 Compute distance between lines.
 
double distanceBetweenPlanes (const std::pair< util::Point, util::Point > &plane_1, const std::pair< util::Point, util::Point > &plane_2)
 Compute distance between planes.
 
double pointDistanceLine (const util::Point &p, const std::pair< util::Point, util::Point > &line)
 Compute distance between point and line.
 
double pointDistanceSegment (const util::Point &p, const std::pair< util::Point, util::Point > &line)
 Compute distance between point and line.
 
double pointDistancePlane (const util::Point &p, const std::pair< util::Point, util::Point > &plane)
 Compute distance between point and plane.
 
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 transformation.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:118

References util::Point::length().

Referenced by angle(), distanceBetweenPlanes(), 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 transformation.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:151

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

Here is the call graph for this function:

◆ areBoxesNear()

bool util::areBoxesNear ( const std::pair< util::Point, util::Point > &  b1,
const std::pair< util::Point, util::Point > &  b2,
const double &  tol,
size_t  dim 
)

Checks if given two boxes are within given distance from each other.

Parameters
b1Box 1
b2Box 2
tolTolerance for checking
dimDimension of the objects
Returns
True If within given distance
Note
TODO This is not precise and can be improved.

Definition at line 109 of file geom.cpp.

113 {
114
115 auto cp1 = getCornerPoints(dim, b1);
116 auto cp2 = getCornerPoints(dim, b2);
117
118 for (auto p : cp1) {
119
120 // check 1: If any of the corner points of box 1 are inside box 2
121 if (isPointInsideBox(p, dim, b2))
122 return true;
123
124 // check 2: If any pair of corner points of box 1 and box 2 are at
125 // distance smaller than the tolerance
126 for (auto pp : cp2) {
127 auto dx = pp - p;
128 if (util::isLess(dx.length(), tol))
129 return true;
130 }
131 }
132
133 // check 3: Check if distance between centers of box 1 and box 2 are below
134 // sum of tolerance, radius of circle inscribed in box 1, and radius of
135 // circle inscribed in box 2
136 auto dxc = getCenter(dim, b2) - getCenter(dim, b1);
137 auto dist = tol + inscribedRadiusInBox(dim, b1) + inscribedRadiusInBox(dim,
138 b2);
139
140 if (util::isLess(dxc.length(), dist))
141 return true;
142
143 // check 4: Check if distance between centers of box 1 and box 2 are below
144 // sum of tolerance, radius of circle inscribed in box 1, and radius of
145 // circle circumscribed in box 2
146 dist = tol + inscribedRadiusInBox(dim, b1) + circumscribedRadiusInBox(dim,
147 b2);
148 if (util::isLess(dxc.length(), dist))
149 return true;
150
151 dist = tol + circumscribedRadiusInBox(dim, b1) + inscribedRadiusInBox(dim,
152 b2);
153 if (util::isLess(dxc.length(), dist))
154 return true;
155
156 return false;
157}
bool isPointInsideBox(util::Point x, size_t dim, const std::pair< util::Point, util::Point > &box)
Returns true if point is inside box.
Definition geom.cpp:159
std::vector< util::Point > getCornerPoints(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns all corner points in the box.
Definition geom.cpp:14
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:20
util::Point getCenter(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns center point.
Definition geom.cpp:91
double inscribedRadiusInBox(size_t dim, const std::pair< util::Point, util::Point > &box)
Computes the radius of biggest circle/sphere completely within the object.
Definition geom.cpp:183
double circumscribedRadiusInBox(size_t dim, const std::pair< util::Point, util::Point > &box)
Computes the radius of smallest circle/sphere which can have the box inside.
Definition geom.cpp:208

References circumscribedRadiusInBox(), getCenter(), getCornerPoints(), inscribedRadiusInBox(), isLess(), and isPointInsideBox().

Referenced by util::geometry::Triangle::isNear(), util::geometry::Square::isNear(), util::geometry::Rectangle::isNear(), util::geometry::Hexagon::isNear(), util::geometry::Drum2D::isNear(), util::geometry::Cube::isNear(), util::geometry::Cuboid::isNear(), and util::geometry::Cylinder::isNear().

Here is the call graph for this function:
Here is the caller 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.

References util::io::printStr().

Here is the call graph for this function:

◆ circumscribedRadiusInBox()

double util::circumscribedRadiusInBox ( size_t  dim,
const std::pair< util::Point, util::Point > &  box 
)

Computes the radius of smallest circle/sphere which can have the box inside.

Parameters
dimDimension of the box
boxPair of corner points of the box
Returns
Radius Radius of inscribed circle/sphere

Definition at line 208 of file geom.cpp.

209 {
210
211 auto xc = getCenter(dim, box);
212 auto cp = getCornerPoints(dim, box);
213
214 auto dx = cp[0] - xc;
215 auto r = dx.length();
216
217 if (dim == 1)
218 return r;
219 else {
220 for (auto p : cp) {
221 dx = p - xc;
222 if (util::isGreater(dx.length(), r))
223 r = dx.length();
224 }
225
226 return r;
227 }
228}
bool isGreater(const double &a, const double &b)
Returns true if a > b.
Definition function.cpp:15

References getCenter(), getCornerPoints(), and isGreater().

Referenced by areBoxesNear(), util::geometry::Circle::isNear(), and util::geometry::Sphere::isNear().

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

◆ computeBBox()

std::pair< util::Point, util::Point > util::computeBBox ( const std::vector< util::Point > &  nodes)

Computes bounding box for vector nodes.

Parameters
nodesList of nodal coordinates
Returns
Box Pair of corner points of box

Definition at line 606 of file geom.cpp.

606 {
607
608 auto p1 = util::Point();
609 auto p2 = util::Point();
610 for (const auto& x : nodes) {
611 if (util::isLess(x.d_x, p1.d_x))
612 p1.d_x = x.d_x;
613 if (util::isLess(x.d_y, p1.d_y))
614 p1.d_y = x.d_y;
615 if (util::isLess(x.d_z, p1.d_z))
616 p1.d_z = x.d_z;
617 if (util::isLess(p2.d_x, x.d_x))
618 p2.d_x = x.d_x;
619 if (util::isLess(p2.d_y, x.d_y))
620 p2.d_y = x.d_y;
621 if (util::isLess(p2.d_z, x.d_z))
622 p2.d_z = x.d_z;
623 }
624
625 return {p1, p2};
626}

References isLess().

Here is the call graph for this function:

◆ computeInscribedRadius()

double util::computeInscribedRadius ( const std::pair< util::Point, util::Point > &  box)

Computes maximum radius of circle/sphere within a given box.

Parameters
boxPair of corner points of box
Returns
Radius Radius of circle/sphere

Definition at line 628 of file geom.cpp.

629 {
630
631 return 0.5 * (box.first - box.second).length();
632}

◆ computeMeshSize() [1/2]

double util::computeMeshSize ( const std::vector< util::Point > &  nodes)

Computes minimum distance between any two nodes.

Parameters
nodesList of nodal coordinates
Returns
h Minimum distance

Definition at line 551 of file geom.cpp.

551 {
552
553 double guess = 0.;
554 if (nodes.size() < 2)
555 return guess;
556
557 guess = (nodes[0] - nodes[1]).length();
558 for (size_t i = 0; i < nodes.size(); i++)
559 for (size_t j = 0; j < nodes.size(); j++)
560 if (i != j) {
561 double val = nodes[i].dist(nodes[j]);
562
563 if (util::isLess(val, 1.0E-12)) {
564
565 std::cout << "Check nodes are too close = "
566 << util::io::printStr<util::Point>({nodes[i],
567 nodes[j]})
568 << "\n";
569 std::cout << "Distance = " << val << ", guess = " << guess << "\n";
570 }
571 if (util::isLess(val, guess))
572 guess = val;
573 }
574
575 return guess;
576}

References isLess().

Referenced by particle::BaseParticle::BaseParticle().

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

◆ computeMeshSize() [2/2]

double util::computeMeshSize ( const std::vector< util::Point > &  nodes,
size_t  start,
size_t  end 
)

Computes minimum distance between any two nodes.

This only considers the nodes between start and end

Parameters
nodesList of nodal coordinates
startStart index from where to start
endEnd index
Returns
h Minimum distance

Definition at line 578 of file geom.cpp.

579 {
580
581 double guess = 0.;
582 if (nodes.size() < 2 or (end - start) < 2)
583 return guess;
584
585 guess = (nodes[start] - nodes[start + 1]).length();
586 for (size_t i = start; i < end; i++)
587 for (size_t j = start; j < end; j++)
588 if (i != j) {
589 double val = nodes[i].dist(nodes[j]);
590
591 if (util::isLess(val, 1.0E-12)) {
592
593 std::cout << "Check nodes are too close = "
594 << util::io::printStr<util::Point>({nodes[i],
595 nodes[j]})
596 << "\n";
597 std::cout << "Distance = " << val << ", guess = " << guess << "\n";
598 }
599 if (util::isLess(val, guess))
600 guess = val;
601 }
602
603 return guess;
604}

References isLess().

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 transformation.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::TetElem::getJacobian(), and inv().

Here is the caller graph for this function:

◆ distanceBetweenLines()

double util::distanceBetweenLines ( const std::pair< util::Point, util::Point > &  line_1,
const std::pair< util::Point, util::Point > &  line_2 
)

Compute distance between lines.

Parameters
line_1Line 1
line_2Line 2
Returns
Value Distance

Definition at line 387 of file geom.cpp.

389 {
390
391 // let line 1 is l1(s) = p + s u
392 // and line 2 is l2(r) = q + r v
393 // and let normal to the plane containing line 1 and 2 is
394 // n = u x v / |u x v|
395
396 auto u = line_1.second - line_1.first;
397 auto v = line_2.second - line_2.first;
398 auto w0 = line_1.first - line_2.first;
399
400 double a = u * u;
401 double b = u * v;
402 double c = v * v;
403 double d = u * w0;
404 double e = v * w0;
405
406 auto dp = w0 + ((b * e - c * d) * u + (a * e - b * d) * v) / (a * c - b * b);
407
408 return dp.length();
409}

◆ distanceBetweenPlanes()

double util::distanceBetweenPlanes ( const std::pair< util::Point, util::Point > &  plane_1,
const std::pair< util::Point, util::Point > &  plane_2 
)

Compute distance between planes.

Parameters
plane_1Plane 1 given by pair of normal and one point which it contains
plane_2Plane 2 given by pair of normal and one point which it contains
Returns
Value Distance

Definition at line 490 of file geom.cpp.

492 {
493
494 // check if planes are parallel
495 if (util::angle(plane_1.first, plane_2.first) < 1.0E-8)
496 return 0.;
497
498 return std::abs(plane_1.first * (plane_1.second - plane_2.second)) /
499 plane_1.first.length();
500}
double angle(util::Point a, util::Point b)
Computes angle between two vectors.

References angle().

Here is the call graph for this function:

◆ distanceBetweenSegments()

double util::distanceBetweenSegments ( const std::pair< util::Point, util::Point > &  line_1,
const std::pair< util::Point, util::Point > &  line_2 
)

Compute distance between lines.

Parameters
line_1Line 1
line_2Line 2
Returns
Value Distance

Definition at line 412 of file geom.cpp.

413 {
414
415 // let line 1 is l1(s) = p + s u
416 // and line 2 is l2(r) = q + r v
417 // and let normal to the plane containing line 1 and 2 is
418 // n = u x v / |u x v|
419
420 auto u = line_1.second - line_1.first;
421 auto v = line_2.second - line_2.first;
422 auto w0 = line_1.first - line_2.first;
423
424 double a = u * u;
425 double b = u * v;
426 double c = v * v;
427 double d = u * w0;
428 double e = v * w0;
429 double D = a * c - b * b;
430 double sc, sN, sD = D;
431 double tc, tN, tD = D;
432
433 // compute line parameters of two closest points
434 if (D < 1.0E-12) {
435
436 sN = 0.;
437 sD = 1.;
438 tN = e;
439 tD = c;
440 } else {
441
442 sN = b * e - c * d;
443 tN = a * e - b * d;
444
445 if (sN < 0.) {
446 sN = 0.;
447 tN = e;
448 tD = c;
449 } else if (sN > sD) {
450 sN = sD;
451 tN = e + b;
452 tD = c;
453 }
454 }
455
456 if (tN < 0.) {
457
458 tN = 0.;
459
460 if (-d < 0.)
461 sN = 0.;
462 else if (-d > a)
463 sN = sD;
464 else {
465 sN = -d;
466 sD = a;
467 }
468 } else if (tN > tD) {
469
470 tN = tD;
471
472 if (-d + b < 0.)
473 sN = 0.;
474 else if (-d + b > a)
475 sN = sD;
476 else {
477 sN = -d + b;
478 sD = a;
479 }
480 }
481
482 sc = std::abs(sN) < 1.0E-12 ? 0. : sN / sD;
483 tc = std::abs(tN) < 1.0E-12 ? 0. : tN / tD;
484
485 auto dp = w0 + sc * u - tc * v;
486
487 return dp.length();
488}
float d
initial distance between particle and wall

◆ does_intersect()

util.does_intersect (   p,
  particles,
  padding 
)
Returns true if particle p intersects or is near enough to existing particles

Parameters
----------
p : list
    Coordinates of center and radius of particle [x,y,z,r]
particles : list
    List of center + radius of multiple particles. E.g. particles[0] is a list containing coordinates of center and radius.
padding: float
    Minimum distance between circle boundaries such that if two circles

Returns
-------
bool
    True if particle intersects or is near enough to one of the particle in the list

Definition at line 251 of file util.py.

251def does_intersect(p, particles, padding):
252 """
253 Returns true if particle p intersects or is near enough to existing particles
254
255 Parameters
256 ----------
257 p : list
258 Coordinates of center and radius of particle [x,y,z,r]
259 particles : list
260 List of center + radius of multiple particles. E.g. particles[0] is a list containing coordinates of center and radius.
261 padding: float
262 Minimum distance between circle boundaries such that if two circles
263
264 Returns
265 -------
266 bool
267 True if particle intersects or is near enough to one of the particle in the list
268 """
269 if len(p) < 4: raise Exception('p = {} must have atleast 4 elements'.format(p))
270 if len(particles) == 0: raise Exception('particles = {} can not be empty'.format(particles))
271 if padding < 0.: raise Exception('padding = {} can not be negative'.format(padding))
272
273 for q in particles:
274 if len(q) < 4: raise Exception('q = {} in particles must have atleast 4 elements'.format(q))
275 pq = np.array([p[i] - q[i] for i in range(3)])
276 if np.linalg.norm(pq) <= p[3] + q[3] + padding:
277 return True
278 return False
279

◆ does_intersect_rect()

util.does_intersect_rect (   p,
  particles,
  padding,
  rect,
  is_3d = False 
)
Returns true if particle p is sufficiently close or outside the rectangle (in 2d) or cuboid (in 3d)

Parameters
----------
p : list
    Coordinates of center and radius of particle [x,y,z,r]
particles : list
    List of center + radius of multiple particles. E.g. particles[0] is a list containing coordinates of center and radius.
padding: float
    Minimum distance between circle boundaries such that if two circles
rect: list
    Coordinates of left-bottom and right-top corner points of rectangle (2d) or cuboid (3d). E.g. [x1 y1, z1, x2, y2, z2]
is_3d: bool
    True if we are dealing with cuboid

Returns
-------
bool
    True if particle intersects or is near enough to the rectangle

Definition at line 280 of file util.py.

280def does_intersect_rect(p, particles, padding, rect, is_3d = False):
281 """
282 Returns true if particle p is sufficiently close or outside the rectangle (in 2d) or cuboid (in 3d)
283
284 Parameters
285 ----------
286 p : list
287 Coordinates of center and radius of particle [x,y,z,r]
288 particles : list
289 List of center + radius of multiple particles. E.g. particles[0] is a list containing coordinates of center and radius.
290 padding: float
291 Minimum distance between circle boundaries such that if two circles
292 rect: list
293 Coordinates of left-bottom and right-top corner points of rectangle (2d) or cuboid (3d). E.g. [x1 y1, z1, x2, y2, z2]
294 is_3d: bool
295 True if we are dealing with cuboid
296
297 Returns
298 -------
299 bool
300 True if particle intersects or is near enough to the rectangle
301 """
302 if len(p) < 4: raise Exception('p = {} must have atleast 4 elements'.format(p))
303 if len(particles) == 0: raise Exception('particles = {} can not be empty'.format(particles))
304 if padding < 0.: raise Exception('padding = {} can not be negative'.format(padding))
305 if len(rect) < 6: raise Exception('rect = {} must have 6 elements'.format(rect))
306
307 pr = [p[0] - p[3], p[1] - p[3], p[2], p[0] + p[3], p[1] + p[3], p[2]]
308 if is_3d:
309 pr[2] -= p[3]
310 pr[5] += p[3]
311
312 if pr[0] < rect[0] + padding or pr[1] < rect[1] + padding or pr[3] > rect[3] - padding or pr[4] > rect[4] - padding:
313 if is_3d:
314 if pr[2] < rect[2] + padding or pr[5] > rect[5] - padding:
315 return True
316 else:
317 return True
318 return False
319

◆ doLinesIntersect()

bool util::doLinesIntersect ( const std::pair< util::Point, util::Point > &  line_1,
const std::pair< util::Point, util::Point > &  line_2 
)

Do lines intersect.

Parameters
line_1Line 1
line_2Line 2
Returns
True If lines intersect, else false

Definition at line 356 of file geom.cpp.

357 {
358
359 // change of variable so that first point of line_1 is at origin
360 // After change of variables:
361 // a is the second point of line_1
362 // b is the first point of line_2
363 // c is the difference of second and first point of line_2
364 auto a = line_1.second - line_1.first;
365 auto b = line_2.first - line_1.first;
366 auto c = line_2.second - line_2.first;
367
368 // check if the two lines are parallel
369 if (util::angle(a / a.length(), c / c.length()) < 1.0E-8)
370 return false;
371
372 double a_dot_a = a.lengthSq();
373 double a_dot_b = a * b;
374 double a_dot_c = a * c;
375 double b_dot_c = b * c;
376 double c_dot_c = c.lengthSq();
377
378 double r = (a_dot_a * b_dot_c - a_dot_b * a_dot_c) /
379 (a_dot_c * a_dot_c - c_dot_c * a_dot_a);
380
381 // if r is in (0,1) then this gives the intersection point
382 // otherwise b + r c gives the point where two vectors originating from
383 // a and originating from b would intersect
384 return r > 0. and r < 1.;
385}

References angle(), and util::Point::lengthSq().

Here is the call 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::getQuadDatas(), util::geometry::Line::isInside(), util::geometry::Line::isNear(), util::geometry::Line::isNearBoundary(), and fe::TetElem::mapPointToRefElem().

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 107 of file function.cpp.

109 {
110
111 if (params.size() < 10) {
112 std::cerr << "Error: Not enough parameters to compute guassian 2-d "
113 "function.\n";
114 exit(1);
115 }
116
117 return util::gaussian(
118 x.dist(util::Point(params[0], params[1], 0.)), params[9],
119 params[8]) *
120 params[4 + dof] +
122 x.dist(util::Point(params[2], params[3], 0.)), params[9],
123 params[8]) *
124 params[6 + dof];
125}
double gaussian(const double &r, const double &a, const double &beta)
Compute gaussian function in 1-d.
Definition function.cpp:87
double dist(const Point &b) const
Computes the distance between a given point from this point.
Definition point.h:140

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 127 of file function.cpp.

127 {
128 return 2. * m1 * m2 / (m1 + m2);
129}

Referenced by model::DEMModel::setupContact().

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 87 of file function.cpp.

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

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 92 of file function.cpp.

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

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

Here is the call graph for this function:

◆ generate_circle_gmsh_input()

util.generate_circle_gmsh_input (   filename,
  center,
  radius,
  mesh_size,
  pp_tag = None 
)
Creates .geo file for discretization of circle using gmsh

Parameters
----------
filename : str
    Filename of .geo file to be created
center : list
    Coordinates of center of circle
radius: float
    Radius of circle
mesh_size: float
    Mesh size
pp_tag: str, optional
    Postfix .geo file with this tag

Definition at line 320 of file util.py.

320def generate_circle_gmsh_input(filename, center, radius, mesh_size, pp_tag = None):
321 """
322 Creates .geo file for discretization of circle using gmsh
323
324 Parameters
325 ----------
326 filename : str
327 Filename of .geo file to be created
328 center : list
329 Coordinates of center of circle
330 radius: float
331 Radius of circle
332 mesh_size: float
333 Mesh size
334 pp_tag: str, optional
335 Postfix .geo file with this tag
336 """
337 pp_tag_str = '_{}'.format(str(pp_tag)) if pp_tag is not None else ''
338 geof = open(filename + pp_tag_str + '.geo','w')
339 gmsh_file_hdr(geof)
340
341
342 points = []
343 points.append([center[0], center[1], center[2]])
344 points.append([center[0] + radius, center[1], center[2]])
345 points.append([center[0] - radius, center[1], center[2]])
346 points.append([center[0], center[1] + radius, center[2]])
347 points.append([center[0], center[1] - radius, center[2]])
348 for i in range(len(points)):
349 geof.write(print_point_gmsh([points[i][0], points[i][1], points[i][2], mesh_size], i+1))
350
351
352 geof.write(print_cir_gmsh([2,1,4], 1))
353 geof.write(print_cir_gmsh([4,1,3], 2))
354 geof.write(print_cir_gmsh([3,1,5], 3))
355 geof.write(print_cir_gmsh([5,1,2], 4))
356
357
358 geof.write(print_lineloop_gmsh([2, 3, 4, 1], 1))
359
360
361 geof.write("Plane Surface(1) = {1};\n")
362
363
364 geof.write("Point{1} In Surface {1};")
365
366
367 geof.close()
368

References gmsh_file_hdr(), print_cir_gmsh(), print_lineloop_gmsh(), and print_point_gmsh().

Here is the call graph for this function:

◆ generate_drum_gmsh_input()

util.generate_drum_gmsh_input (   filename,
  center,
  radius,
  width,
  mesh_size,
  pp_tag = None 
)
Creates .geo file for discretization of drum (concave polygon, see get_ref_drum_points) using gmsh

Parameters
----------
filename : str
    Filename of .geo file to be created
center : list
    Coordinates of center
radius: float
    Radius 
width: float
    Neck width (see get_ref_drum_points())
mesh_size: float
    Mesh size
pp_tag: str, optional
    Postfix .geo file with this tag

Definition at line 466 of file util.py.

466def generate_drum_gmsh_input(filename, center, radius, width, mesh_size, pp_tag = None):
467 """
468 Creates .geo file for discretization of drum (concave polygon, see get_ref_drum_points) using gmsh
469
470 Parameters
471 ----------
472 filename : str
473 Filename of .geo file to be created
474 center : list
475 Coordinates of center
476 radius: float
477 Radius
478 width: float
479 Neck width (see get_ref_drum_points())
480 mesh_size: float
481 Mesh size
482 pp_tag: str, optional
483 Postfix .geo file with this tag
484 """
485 pp_tag_str = '_{}'.format(str(pp_tag)) if pp_tag is not None else ''
486 geof = open(filename + pp_tag_str + '.geo','w')
487 gmsh_file_hdr(geof)
488
489
490 points = get_ref_drum_points(center, radius, width, True)
491 for i in range(len(points)):
492 geof.write(print_point_gmsh([points[i][0], points[i][1], points[i][2], mesh_size], i+1))
493
494
495 for i in range(6):
496 if i < 5:
497 geof.write(print_line_gmsh([i+2,i+3], i+1))
498 else:
499 geof.write(print_line_gmsh([i+2,2], i+1))
500
501
502 geof.write(print_lineloop_gmsh([i+1 for i in range(6)], 1))
503
504
505 geof.write("Plane Surface(1) = {1};\n")
506
507
508 geof.write("Point{1} In Surface {1};")
509
510
511 geof.close()

References get_ref_drum_points(), gmsh_file_hdr(), print_line_gmsh(), print_lineloop_gmsh(), and print_point_gmsh().

Here is the call graph for this function:

◆ generate_hexagon_gmsh_input()

util.generate_hexagon_gmsh_input (   filename,
  center,
  radius,
  mesh_size,
  pp_tag = None 
)
Creates .geo file for discretization of hexagon using gmsh

Parameters
----------
filename : str
    Filename of .geo file to be created
center : list
    Coordinates of center of hexagon
radius: float
    Radius 
mesh_size: float
    Mesh size
pp_tag: str, optional
    Postfix .geo file with this tag

Definition at line 420 of file util.py.

420def generate_hexagon_gmsh_input(filename, center, radius, mesh_size, pp_tag = None):
421 """
422 Creates .geo file for discretization of hexagon using gmsh
423
424 Parameters
425 ----------
426 filename : str
427 Filename of .geo file to be created
428 center : list
429 Coordinates of center of hexagon
430 radius: float
431 Radius
432 mesh_size: float
433 Mesh size
434 pp_tag: str, optional
435 Postfix .geo file with this tag
436 """
437 pp_tag_str = '_{}'.format(str(pp_tag)) if pp_tag is not None else ''
438 geof = open(filename + pp_tag_str + '.geo','w')
439 gmsh_file_hdr(geof)
440
441
442 points = get_ref_hex_points(center, radius, True)
443 for i in range(len(points)):
444 geof.write(print_point_gmsh([points[i][0], points[i][1], points[i][2], mesh_size], i+1))
445
446
447 for i in range(6):
448 if i < 5:
449 geof.write(print_line_gmsh([i+2,i+3], i+1))
450 else:
451 geof.write(print_line_gmsh([i+2,2], i+1))
452
453
454 geof.write(print_lineloop_gmsh([i+1 for i in range(6)], 1))
455
456
457 geof.write("Plane Surface(1) = {1};\n")
458
459
460 geof.write("Point{1} In Surface {1};")
461
462
463 geof.close()
464
465

References get_ref_hex_points(), gmsh_file_hdr(), print_line_gmsh(), print_lineloop_gmsh(), and print_point_gmsh().

Here is the call graph for this function:

◆ generate_rectangle_gmsh_input()

util.generate_rectangle_gmsh_input (   filename,
  rectangle,
  mesh_size,
  pp_tag = None 
)
Creates .geo file for discretization of rectangle using gmsh

Parameters
----------
filename : str
    Filename of .geo file to be created
rectangle : list
    Coordinates of left-bottom and right-top corner points of rectangle
mesh_size: float
    Mesh size
pp_tag: str, optional
    Postfix .geo file with this tag

Definition at line 369 of file util.py.

369def generate_rectangle_gmsh_input(filename, rectangle, mesh_size, pp_tag = None):
370 """
371 Creates .geo file for discretization of rectangle using gmsh
372
373 Parameters
374 ----------
375 filename : str
376 Filename of .geo file to be created
377 rectangle : list
378 Coordinates of left-bottom and right-top corner points of rectangle
379 mesh_size: float
380 Mesh size
381 pp_tag: str, optional
382 Postfix .geo file with this tag
383 """
384 pp_tag_str = '_{}'.format(str(pp_tag)) if pp_tag is not None else ''
385 geof = open(filename + pp_tag_str + '.geo','w')
386 gmsh_file_hdr(geof)
387
388
389 points = []
390 points.append([rectangle[0], rectangle[1], rectangle[2]])
391 points.append([rectangle[3], rectangle[1], rectangle[2]])
392 points.append([rectangle[3], rectangle[4], rectangle[2]])
393 points.append([rectangle[0], rectangle[4], rectangle[2]])
394 for i in range(len(points)):
395 geof.write(print_point_gmsh([points[i][0], points[i][1], points[i][2], mesh_size], i+1))
396
397
398 for i in range(4):
399 if i < 3:
400 geof.write(print_line_gmsh([i+1,i+2], i+1))
401 else:
402 geof.write(print_line_gmsh([i+1,1], i+1))
403
404
405 geof.write(print_lineloop_gmsh([i+1 for i in range(4)], 1))
406
407
408 geof.write("Plane Surface(1) = {1};\n")
409
410
411 geof.write("Point{1} In Surface {1};")
412
413
414 tag = '"' + "a" + '"'
415 geof.write("Physical Surface(%s) = {1};\n" % (tag))
416
417
418 geof.close()
419

References gmsh_file_hdr(), print_line_gmsh(), print_lineloop_gmsh(), and print_point_gmsh().

Here is the call graph for this function:

◆ get_E()

util.get_E (   K,
  nu 
)
Returns Young's modulus given bulk modulus and Poisson's ratio

Parameters
----------
K : float
    Bulk modulus
nu : float
    Poisson's ratio

Returns
-------
float
    Young's modulus

Definition at line 49 of file util.py.

49def get_E(K, nu):
50 """
51 Returns Young's modulus given bulk modulus and Poisson's ratio
52
53 Parameters
54 ----------
55 K : float
56 Bulk modulus
57 nu : float
58 Poisson's ratio
59
60 Returns
61 -------
62 float
63 Young's modulus
64 """
65 return 3. * K * (1. - 2. * nu)
66

◆ get_eff_k()

util.get_eff_k (   k1,
  k2 
)
Returns effective bulk modulus

Parameters
----------
k1: float
    First bulk modulus
k2 : float
    Second bulk modulus

Returns
-------
float
    Effective bulk modulus

Definition at line 86 of file util.py.

86def get_eff_k(k1, k2):
87 """
88 Returns effective bulk modulus
89
90 Parameters
91 ----------
92 k1: float
93 First bulk modulus
94 k2 : float
95 Second bulk modulus
96
97 Returns
98 -------
99 float
100 Effective bulk modulus
101 """
102 return 2. * k1 * k2 / (k1 + k2)
103

◆ get_G()

util.get_G (   E,
  nu 
)
Returns shear modulus given Young's modulus and Poisson's ratio

Parameters
----------
E: float
    Young's modulus
nu : float
    Poisson's ratio

Returns
-------
float
    Shear modulus

Definition at line 67 of file util.py.

67def get_G(E, nu):
68 """
69 Returns shear modulus given Young's modulus and Poisson's ratio
70
71 Parameters
72 ----------
73 E: float
74 Young's modulus
75 nu : float
76 Poisson's ratio
77
78 Returns
79 -------
80 float
81 Shear modulus
82 """
83 return E / (2. * (1. + nu))
84
85

◆ get_max()

util.get_max (   l)
Returns maximum value in list

Parameters
----------
l: list
   List of values

Returns
-------
float
    Maximum value

Definition at line 104 of file util.py.

104def get_max(l):
105 """
106 Returns maximum value in list
107
108 Parameters
109 ----------
110 l: list
111 List of values
112
113 Returns
114 -------
115 float
116 Maximum value
117 """
118 l = np.array(l)
119 return l.max()
120

◆ 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:

◆ get_ref_drum_points()

util.get_ref_drum_points (   center,
  radius,
  width,
  add_center = False 
)
Returns size points on reference concave polygon (we refer to it as drum)

Reference concave polygon:

             v3                                v2
               + -------------------------------- +
                \                               /
                   \                         /
                     +         o           +
                    /v4        x          v1 \
                 /                              \ 
               + -------------------------------- +
               v5                               v6

Axis is a vector from x to v1, radius is distance between x and v2, and width of neck is the distance between v2 and v4.

Parameters
----------
center: list
    Coordinates of center of polygon
radius : float
    Radius of polygon (distance between center x and vertex v2)
width : float
    Width of neck, i.e. distance between vertex v2 and v4
add_center : bool
    True if we include the center to the returned list (first point in the returned list will be the center if the flag is true)

Returns
-------
list
    Coordinates of points

Definition at line 190 of file util.py.

190def get_ref_drum_points(center, radius, width, add_center = False):
191 """
192 Returns size points on reference concave polygon (we refer to it as drum)
193
194 Reference concave polygon:
195
196 v3 v2
197 + -------------------------------- +
198 \ /
199 \ /
200 + o +
201 /v4 x v1 \
202 / \
203 + -------------------------------- +
204 v5 v6
205
206 Axis is a vector from x to v1, radius is distance between x and v2, and width of neck is the distance between v2 and v4.
207
208 Parameters
209 ----------
210 center: list
211 Coordinates of center of polygon
212 radius : float
213 Radius of polygon (distance between center x and vertex v2)
214 width : float
215 Width of neck, i.e. distance between vertex v2 and v4
216 add_center : bool
217 True if we include the center to the returned list (first point in the returned list will be the center if the flag is true)
218
219 Returns
220 -------
221 list
222 Coordinates of points
223 """
224 axis = [1., 0., 0.]
225 rotate_axis = [0., 0., 1.]
226
227 x1 = rotate(axis, np.pi/3., rotate_axis)
228 x2 = rotate(axis, -np.pi/3., rotate_axis)
229
230 points = []
231 if add_center:
232 points.append(center)
233
234 # v1
235 points.append([center[i] + width*0.5*axis[i] for i in range(3)])
236 # v2
237 points.append([center[i] + radius*x1[i] for i in range(3)])
238 # v3
239 points.append([center[i] + radius*x1[i] - radius*axis[i] for i in range(3)])
240 # v4
241 points.append([center[i] - width*0.5*axis[i] for i in range(3)])
242 # v5
243 v6 = [center[i] + radius*x2[i] for i in range(3)]
244 points.append([v6[i] - radius*axis[i] for i in range(3)])
245 # v6
246 points.append(v6)
247
248 return points
249
250

References rotate().

Referenced by generate_drum_gmsh_input().

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

◆ get_ref_hex_points()

util.get_ref_hex_points (   center,
  radius,
  add_center = False 
)
Returns size points on reference hexagon

Reference hexagon:

                        v3           v2
                         +           +


                      +         o           +
                     v4         x            v1

                         +           +
                        v5           v6

Axis is a vector from x to v1 and radius is distance between x and v1.

Parameters
----------
center: list
    Coordinates of center of hexagon
radius : float
    Radius of hexagon
add_center : bool
    True if we include the center to the returned list (first point in the returned list will be the center if the flag is true)

Returns
-------
list
    Coordinates of points

Definition at line 146 of file util.py.

146def get_ref_hex_points(center, radius, add_center = False):
147 """
148 Returns size points on reference hexagon
149
150 Reference hexagon:
151
152 v3 v2
153 + +
154
155
156 + o +
157 v4 x v1
158
159 + +
160 v5 v6
161
162 Axis is a vector from x to v1 and radius is distance between x and v1.
163
164 Parameters
165 ----------
166 center: list
167 Coordinates of center of hexagon
168 radius : float
169 Radius of hexagon
170 add_center : bool
171 True if we include the center to the returned list (first point in the returned list will be the center if the flag is true)
172
173 Returns
174 -------
175 list
176 Coordinates of points
177 """
178 axis = [1., 0., 0.]
179 rotate_axis = [0., 0., 1.]
180 points = []
181 if add_center:
182 points.append(center)
183
184 for i in range(6):
185 xi = rotate(axis, i*np.pi/3., rotate_axis)
186 points.append([center[i] + radius * xi[i] for i in range(3)])
187
188 return points
189

References rotate().

Referenced by generate_hexagon_gmsh_input().

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

◆ getCenter()

util::Point util::getCenter ( size_t  dim,
const std::pair< util::Point, util::Point > &  box 
)

Returns center point.

Parameters
dimDimension of the box
boxPair of points representing cuboid (rectangle in 2d)
Returns
Point Coordinates of center point

Definition at line 91 of file geom.cpp.

92 {
93
94 if (dim == 1)
95 return {0.5 * box.second.d_x + 0.5 * box.first.d_x, 0., 0.};
96 else if (dim == 2)
97 return {0.5 * box.second.d_x + 0.5 * box.first.d_x,
98 0.5 * box.second.d_y + 0.5 * box.first.d_y, 0.};
99 else if (dim == 3)
100 return {0.5 * box.second.d_x + 0.5 * box.first.d_x,
101 0.5 * box.second.d_y + 0.5 * box.first.d_y,
102 0.5 * box.second.d_z + 0.5 * box.first.d_z};
103 else {
104 std::cerr << "Error: Check dimension = " << dim << ".\n";
105 exit(1);
106 }
107}

References util::Point::d_x.

Referenced by areBoxesNear(), circumscribedRadiusInBox(), util::geometry::Circle::isNear(), util::geometry::Sphere::isNear(), and test::testUtilMethods().

Here is the caller graph for this function:

◆ getCornerPoints()

std::vector< util::Point > util::getCornerPoints ( size_t  dim,
const std::pair< util::Point, util::Point > &  box 
)

Returns all corner points in the box.

Parameters
dimDimension of the box
boxPair of points representing cuboid (rectangle in 2d)
Returns
Vector Vector of corner points

Definition at line 14 of file geom.cpp.

15 {
16
17 if (dim == 1)
18 return {box.first, box.second};
19 else if (dim == 2)
20 return {box.first,
21 util::Point(box.second.d_x, box.first.d_y, 0.),
22 box.second,
23 util::Point(box.first.d_x, box.second.d_y, 0.)};
24 else if (dim == 3) {
25 double a = box.second.d_x - box.first.d_x;
26 double b = box.second.d_y - box.first.d_y;
27 double c = box.second.d_z - box.first.d_z;
28 return {box.first,
29 box.first + util::Point(a, 0., 0.),
30 box.first + util::Point(a, b, 0.),
31 box.first + util::Point(0., b, 0.),
32 box.first + util::Point(0., 0., c),
33 box.first + util::Point(a, 0., c),
34 box.first + util::Point(a, b, c),
35 box.first + util::Point(0., b, c)};
36 }
37 else {
38 std::cerr << "Error: Check dimension = " << dim << ".\n";
39 exit(1);
40 }
41}

References util::Point::d_x.

Referenced by areBoxesNear(), circumscribedRadiusInBox(), util::geometry::Triangle::doesIntersect(), util::geometry::Square::doesIntersect(), util::geometry::Rectangle::doesIntersect(), util::geometry::Hexagon::doesIntersect(), util::geometry::Drum2D::doesIntersect(), util::geometry::Cube::doesIntersect(), util::geometry::Cuboid::doesIntersect(), util::geometry::Circle::doesIntersect(), util::geometry::Sphere::doesIntersect(), util::geometry::Cylinder::doesIntersect(), util::geometry::AnnulusGeomObject::doesIntersect(), util::geometry::ComplexGeomObject::doesIntersect(), getEdges(), util::geometry::Triangle::isInside(), util::geometry::Square::isInside(), util::geometry::Rectangle::isInside(), util::geometry::Hexagon::isInside(), util::geometry::Drum2D::isInside(), util::geometry::Cube::isInside(), util::geometry::Cuboid::isInside(), util::geometry::Circle::isInside(), util::geometry::Sphere::isInside(), util::geometry::Cylinder::isInside(), util::geometry::AnnulusGeomObject::isInside(), util::geometry::ComplexGeomObject::isInside(), util::geometry::Circle::isNear(), util::geometry::Sphere::isNear(), util::geometry::Triangle::isOutside(), util::geometry::Square::isOutside(), util::geometry::Rectangle::isOutside(), util::geometry::Hexagon::isOutside(), util::geometry::Drum2D::isOutside(), util::geometry::Cube::isOutside(), util::geometry::Cuboid::isOutside(), util::geometry::Circle::isOutside(), util::geometry::Sphere::isOutside(), util::geometry::Cylinder::isOutside(), util::geometry::AnnulusGeomObject::isOutside(), util::geometry::ComplexGeomObject::isOutside(), and test::testUtilMethods().

Here is the caller graph for this function:

◆ getEdges()

std::vector< std::pair< util::Point, util::Point > > util::getEdges ( size_t  dim,
const std::pair< util::Point, util::Point > &  box 
)

Returns all corner points in the box.

Parameters
dimDimension of the box
boxPair of points representing cuboid (rectangle in 2d)
Returns
Vector Vector of corner points

Definition at line 43 of file geom.cpp.

44 {
45
46 std::vector<std::pair<util::Point, util::Point>> data;
47 if (dim == 1) {
48 data.emplace_back(box);
49 return data;
50 } else if (dim == 2) {
51
52 // points returned by below function is in anti-clockwise order
53 auto corner_pts = util::getCornerPoints(dim, box);
54
55 data.emplace_back(corner_pts[0], corner_pts[1]);
56 data.emplace_back(corner_pts[1], corner_pts[2]);
57 data.emplace_back(corner_pts[2], corner_pts[3]);
58 data.emplace_back(corner_pts[3], corner_pts[0]);
59 return data;
60 } else if (dim == 3) {
61
62 // points returned by below function is in anti-clockwise order
63 // first 4 points are on lower z-plane, and remaining are in upper z-plane
64 auto corner_pts = util::getCornerPoints(dim, box);
65
66 // edges in lower plane
67 data.emplace_back(corner_pts[0], corner_pts[1]);
68 data.emplace_back(corner_pts[1], corner_pts[2]);
69 data.emplace_back(corner_pts[2], corner_pts[3]);
70 data.emplace_back(corner_pts[3], corner_pts[0]);
71
72 // edges in upper plane
73 data.emplace_back(corner_pts[4], corner_pts[5]);
74 data.emplace_back(corner_pts[5], corner_pts[6]);
75 data.emplace_back(corner_pts[6], corner_pts[7]);
76 data.emplace_back(corner_pts[7], corner_pts[4]);
77
78 // edges parrallel to z-axis
79 data.emplace_back(corner_pts[0], corner_pts[4]);
80 data.emplace_back(corner_pts[1], corner_pts[5]);
81 data.emplace_back(corner_pts[2], corner_pts[6]);
82 data.emplace_back(corner_pts[3], corner_pts[7]);
83
84 return data;
85 } else {
86 std::cerr << "getEdges(): Function implemented for dim = 1,2,3 only.\n";
87 exit(EXIT_FAILURE);
88 }
89}

References getCornerPoints().

Referenced by test::testUtilMethods().

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

◆ getPointOnLine()

util::Point util::getPointOnLine ( const util::Point p1,
const util::Point p2,
const double &  s 
)

Returns point in line formed by points p1 and p2.

Parameters
p1Point 1
p2Point 2
sParametric coordinate
Returns
p Point

Definition at line 350 of file geom.cpp.

352 {
353 return (1. - s) * p1 + s * p2;
354}

◆ gmsh_file_hdr()

util.gmsh_file_hdr (   f)

Definition at line 45 of file util.py.

45def gmsh_file_hdr(f):
46 f.write('cl__1 = 1;\n')
47 f.write('Mesh.MshFileVersion = 2.2;\n')
48

Referenced by generate_circle_gmsh_input(), generate_drum_gmsh_input(), generate_hexagon_gmsh_input(), and generate_rectangle_gmsh_input().

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 25 of file function.cpp.

26 {
27
28 if (util::isGreater(x, x_min - 1.0E-12) and
29 util::isLess(x, x_max + 1.0E-12)) {
30
31 double x_mid = 0.5 * (x_min + x_max);
32 double l = x_mid - x_min;
33
34 // check if this is essentially a point load (dirac)
35 if (l < 1.0E-12)
36 return 1.0;
37
38 if (util::isLess(x, x_mid))
39 return (x - x_min) / l;
40 else
41 return (x_max - x) / l;
42 } else
43 return 0.0;
44}

References isGreater(), and isLess().

Here is the call 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 46 of file function.cpp.

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

References isLess().

Here is the call graph for this function:

◆ inscribedRadiusInBox()

double util::inscribedRadiusInBox ( size_t  dim,
const std::pair< util::Point, util::Point > &  box 
)

Computes the radius of biggest circle/sphere completely within the object.

Parameters
dimDimension of the box
boxPair of corner points of the box
Returns
Radius Radius of inscribed circle/sphere

Definition at line 183 of file geom.cpp.

184 {
185
186 double r = 0.5 * std::abs(box.second.d_x - box.first.d_x);
187 if (dim == 1)
188 return r;
189 else if (dim == 2) {
190 if (util::isGreater(r, 0.5 * std::abs(box.second.d_y - box.first.d_y)))
191 return 0.5 * std::abs(box.second.d_y - box.first.d_y);
192 else
193 return r;
194 } else if (dim == 3) {
195 if (util::isGreater(r, 0.5 * std::abs(box.second.d_y - box.first.d_y)))
196 r = 0.5 * std::abs(box.second.d_y - box.first.d_y);
197
198 if (util::isGreater(r, 0.5 * std::abs(box.second.d_z - box.first.d_z)))
199 return 0.5 * std::abs(box.second.d_z - box.first.d_z);
200 else
201 return r;
202 } else {
203 std::cerr << "inscribedRadiusInBox(): Function implemented for dim = 1,2,3 only.\n";
204 exit(EXIT_FAILURE);
205 }
206}

References isGreater().

Referenced by areBoxesNear(), util::geometry::Circle::isNear(), and util::geometry::Sphere::isNear().

Here is the call graph for this function:
Here is the caller 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::getQuadDatas(), and fe::TetElem::mapPointToRefElem().

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 15 of file function.cpp.

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

References COMPARE_EPS.

Referenced by loading::ParticleFLoading::apply(), util::geometry::AnnulusGeomObject::center(), util::geometry::ComplexGeomObject::center(), anonymous_namespace{tetElem.cpp}::checkPoint(), model::DEMModel::checkStop(), 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(), material::RnpMaterial::getBondEF(), material::PmbMaterial::getBondEF(), hatFunction(), inscribedRadiusInBox(), util::geometry::Line::isInside(), util::geometry::Cylinder::isInside(), util::geometry::BoxPartition::isNear(), util::geometry::Line::isNear(), util::geometry::Cylinder::isNear(), util::geometry::Line::isNearBoundary(), util::geometry::Cylinder::isNearBoundary(), isPointInsideAngledRectangle(), isPointInsideBox(), isPointInsideCuboid(), isPointInsideRectangle(), isPointInsideRectangle(), fe::LineElem::mapPointToRefElem(), fe::TetElem::mapPointToRefElem(), fe::TriElem::mapPointToRefElem(), model::DEMModel::ppTwoParticleTest(), model::DEMModel::setupContact(), twoparticle_demo::Model::twoParticleTestMaxShearStress(), twoparticle_demo::Model::twoParticleTestPenetrationDist(), anonymous_namespace{materialUtil.cpp}::updateBondFractureDataI(), and model::DEMModel::updateContactNeighborSearchParameters().

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 20 of file function.cpp.

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

References COMPARE_EPS.

Referenced by areBoxesNear(), anonymous_namespace{tetElem.cpp}::checkPoint(), fe::Mesh::computeBBox(), computeBBox(), fe::Mesh::computeMeshSize(), computeMeshSize(), computeMeshSize(), material::RnpMaterial::computeParameters(), material::PmbMaterial::computeParameters(), material::PdElastic::computeParameters(), material::PdState::computeParameters(), anonymous_namespace{materialUtil.cpp}::computeStateMxI(), fe::getMaxShearStressAndLoc(), fe::getStrainStress(), hatFunction(), hatFunctionQuick(), util::geometry::Rectangle::inscribedRadius(), util::geometry::Cuboid::inscribedRadius(), util::geometry::Line::isInside(), util::geometry::Circle::isInside(), util::geometry::Sphere::isInside(), util::geometry::Cylinder::isInside(), util::geometry::Circle::isNear(), util::geometry::Sphere::isNear(), util::geometry::BoxPartition::isNear(), util::geometry::Line::isNear(), util::geometry::Circle::isNear(), util::geometry::Sphere::isNear(), util::geometry::Cylinder::isNear(), util::geometry::Line::isNearBoundary(), util::geometry::Square::isNearBoundary(), util::geometry::Rectangle::isNearBoundary(), util::geometry::Cube::isNearBoundary(), util::geometry::Cuboid::isNearBoundary(), util::geometry::Circle::isNearBoundary(), util::geometry::Sphere::isNearBoundary(), util::geometry::Cylinder::isNearBoundary(), isPointInsideAngledRectangle(), isPointInsideBox(), isPointInsideCuboid(), isPointInsideRectangle(), isPointInsideRectangle(), linearStepFunc(), fe::LineElem::mapPointToRefElem(), fe::TetElem::mapPointToRefElem(), fe::TriElem::mapPointToRefElem(), model::DEMModel::ppTwoParticleTest(), particle::RefParticle::RefParticle(), inp::Input::setContactDeck(), twoparticle_demo::Model::twoParticleTestPenetrationDist(), and model::DEMModel::updateContactNeighborSearchParameters().

◆ isPointInsideAngledRectangle()

bool util::isPointInsideAngledRectangle ( util::Point  x,
double  x_min,
double  x_max,
double  y_min,
double  y_max,
double  theta 
)

Checks if point is inside an angled rectangle.

Parameters
xPoint
x_minX coordinate of left-bottom corner point
x_maxX coordinate of right-top corner point
y_minY coordinate of left-bottom corner point
y_maxY coordinate of right-top corner point
thetaAngle of orientation of rectangle from x-axis
Returns
bool True if point inside rectangle, else false

Definition at line 249 of file geom.cpp.

251 {
252 // we assume that the rectangle has passed the test
253
254 //
255 // (x2,y2)
256 // o
257 //
258 //
259 //
260 //
261 //
262 // o
263 // (x1,y1)
264
265 // get divisors
267 util::Point(x2 - x1, y2 - y1, 0.0), theta);
268
269 // double lam1 = (x2-x1) * std::cos(theta) + (y2-y1) * std::sin(theta);
270 // double lam2 = -(x2-x1) * std::sin(theta) + (y2-y1) * std::cos(theta);
271
272 // get mapped coordinate of x
274 util::Point(x[0] - x1, x[1] - y1, 0.0), theta);
275
276 // double xmap = (x[0]-x1) * std::cos(theta) + (x[1]-y1) * std::sin(theta);
277 // double ymap = -(x[0]-x1) * std::sin(theta) + (x[1]-y1) * std::cos(theta);
278
279 // check if mapped coordinate are out of range [0, lam1] and [0, lam2]
280 return !(util::isLess(xmap[0], -1.0E-12) or
281 util::isLess(xmap[1], -1.0E-12) or
282 util::isGreater(xmap[0], lam[0] + 1.0E-12) or
283 util::isGreater(xmap[1], lam[1] + 1.0E-12));
284}
std::vector< double > rotateCW2D(const std::vector< double > &x, const double &theta)
Rotates a vector in xy-plane in clockwise direction.

References isGreater(), isLess(), and rotateCW2D().

Here is the call graph for this function:

◆ isPointInsideBox()

bool util::isPointInsideBox ( util::Point  x,
size_t  dim,
const std::pair< util::Point, util::Point > &  box 
)

Returns true if point is inside box.

Parameters
xPoint
dimDimension of the box
boxPair of points representing cuboid (rectangle in 2d)
Returns
True If point is inside box

Definition at line 159 of file geom.cpp.

160 {
161
162 if (dim == 1)
163 return !(util::isLess(x.d_x, box.first.d_x - 1.0E-12) or
164 util::isGreater(x.d_x, box.second.d_x + 1.0E-12));
165 else if (dim == 2)
166 return !(util::isLess(x.d_x, box.first.d_x - 1.0E-12) or
167 util::isLess(x.d_y, box.first.d_y - 1.0E-12) or
168 util::isGreater(x.d_x, box.second.d_x + 1.0E-12) or
169 util::isGreater(x.d_y, box.second.d_y + 1.0E-12));
170 else if (dim == 3)
171 return !(util::isLess(x.d_x, box.first.d_x - 1.0E-12) or
172 util::isLess(x.d_y, box.first.d_y - 1.0E-12) or
173 util::isLess(x.d_z, box.first.d_z - 1.0E-12) or
174 util::isGreater(x.d_x, box.second.d_x + 1.0E-12) or
175 util::isGreater(x.d_y, box.second.d_y + 1.0E-12) or
176 util::isGreater(x.d_z, box.second.d_z + 1.0E-12));
177 else {
178 std::cerr << "isPointInsideBox(): Function implemented for dim = 1,2,3 only.\n";
179 exit(EXIT_FAILURE);
180 }
181}

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

Referenced by areBoxesNear(), util::geometry::Triangle::isNear(), util::geometry::Square::isNear(), util::geometry::Rectangle::isNear(), util::geometry::Hexagon::isNear(), util::geometry::Drum2D::isNear(), util::geometry::Cube::isNear(), and util::geometry::Cuboid::isNear().

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

◆ isPointInsideCuboid()

bool util::isPointInsideCuboid ( util::Point  x,
util::Point  x_lbb,
util::Point  x_rtf 
)

Checks if point is inside a cuboid.

Parameters
xPoint
x_lbbCoordinate of left-bottom-back corner point
x_rtfCoordinate of right-top-front corner point
Returns
bool True if point inside cuboid, else false

Definition at line 286 of file geom.cpp.

287 {
288 return !(util::isLess(x.d_x, x_lbb.d_x - 1.0E-12) or
289 util::isLess(x.d_y, x_lbb.d_y - 1.0E-12) or
290 util::isLess(x.d_z, x_lbb.d_z - 1.0E-12) or
291 util::isGreater(x.d_x, x_rtf.d_x + 1.0E-12) or
292 util::isGreater(x.d_y, x_rtf.d_y + 1.0E-12) or
293 util::isGreater(x.d_z, x_rtf.d_z + 1.0E-12));
294}

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

Referenced by util::geometry::Cube::isInside(), and util::geometry::Cuboid::isInside().

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

◆ isPointInsideCylinder() [1/2]

bool util::isPointInsideCylinder ( const util::Point p,
const double &  length,
const double &  radius,
const util::Point axis 
)

Returns true if point is inside the cylinder.

Parameters
pPoint
lengthLength of cylinder
radiusRadius of cylinder
axisAxis of cylinder
Returns
True If point inside cylinder otherwise false

Definition at line 296 of file geom.cpp.

297 {
298
299 double p_dot_a = p * axis;
300 if (p_dot_a > length or p_dot_a < 0.)
301 return false;
302 else {
303
304 auto p_parallel = p - p_dot_a * axis;
305
306 return p_parallel.lengthSq() < radius * radius;
307 }
308}
double lengthSq() const
Computes the Euclidean length of the vector.
Definition point.h:124

References util::Point::lengthSq().

Here is the call graph for this function:

◆ isPointInsideCylinder() [2/2]

bool util::isPointInsideCylinder ( const util::Point p,
const double &  radius,
const util::Point x1,
const util::Point x2 
)

Returns true if point is inside the cylinder.

Parameters
pPoint
radiusRadius of cylinder
x1Point at the center of cross-section at s=0
x2Point at the center of cross-section at s=L
Returns
True If point inside cylinder otherwise false

Definition at line 310 of file geom.cpp.

311 {
312
313 auto p_new = p - x1;
314 auto a = x2 - x1;
315 double p_dot_a = p_new * a;
316
317 // note here we should 1 if a is not normalized
318 if (p_dot_a > 1. or p_dot_a < 0.)
319 return false;
320 else {
321
322 auto p_parallel = p_new - p_dot_a * a;
323
324 return p_parallel.lengthSq() < radius * radius;
325 }
326}

References util::Point::lengthSq().

Here is the call graph for this function:

◆ isPointInsideEllipse() [1/2]

bool util::isPointInsideEllipse ( const util::Point p,
const util::Point center,
const std::vector< double > &  radius_vec,
unsigned int  dim 
)

Returns true if point is inside the ellipsoid.

Parameters
pPoint
centerCenter of ellipse
radius_vecVector of radius describing ellipse
dimDimension
Returns
True If point inside otherwise false

Definition at line 328 of file geom.cpp.

329 {
330
331 double d = 0.;
332 auto x = p - center;
333 for (unsigned int i=0; i<dim; i++)
334 d += x[i] * x[i] / (radius_vec[i] * radius_vec[i]);
335
336 return d < 1.;
337}

◆ isPointInsideEllipse() [2/2]

bool util::isPointInsideEllipse ( const util::Point p,
const util::Point center,
const std::vector< double > &  radius_vec,
unsigned int  dim,
double &  d 
)

Returns true if point is inside the ellipsoid.

Also computes d = x^2 / r1^2 + y^2 / r2^2 + z^2 / r3^2

Parameters
pPoint
centerCenter of ellipse
radius_vecVector of radius describing ellipse
dimDimension
d
Returns
True If point inside otherwise false

Definition at line 339 of file geom.cpp.

340 {
341
342 d = 0.;
343 auto x = p - center;
344 for (unsigned int i=0; i<dim; i++)
345 d += x[i] * x[i] / (radius_vec[i] * radius_vec[i]);
346
347 return d < 1.;
348}

◆ isPointInsideRectangle() [1/2]

bool util::isPointInsideRectangle ( util::Point  x,
double  x_min,
double  x_max,
double  y_min,
double  y_max 
)

Checks if point is inside a rectangle.

Parameters
xPoint
x_minX coordinate of left-bottom corner point
x_maxX coordinate of right-top corner point
y_minY coordinate of left-bottom corner point
y_maxY coordinate of right-top corner point
Returns
bool True if point inside rectangle, else false

Definition at line 231 of file geom.cpp.

233 {
234
235 return !(util::isLess(x.d_x, x_min - 1.0E-12) or
236 util::isLess(x.d_y, y_min - 1.0E-12) or
237 util::isGreater(x.d_x, x_max + 1.0E-12) or
238 util::isGreater(x.d_y, y_max + 1.0E-12));
239}

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

Referenced by util::geometry::Square::isInside(), and util::geometry::Rectangle::isInside().

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

◆ isPointInsideRectangle() [2/2]

bool util::isPointInsideRectangle ( util::Point  x,
util::Point  x_lb,
util::Point  x_rt 
)

Checks if point is inside a rectangle.

Parameters
xPoint
x_lbCoordinate of left-bottom corner point
x_rtCoordinate of right-top corner point
Returns
bool True if point inside rectangle, else false

Definition at line 241 of file geom.cpp.

242 {
243 return !(util::isLess(x.d_x, x_lb.d_x - 1.0E-12) or
244 util::isLess(x.d_y, x_lb.d_y - 1.0E-12) or
245 util::isGreater(x.d_x, x_rt.d_x + 1.0E-12) or
246 util::isGreater(x.d_y, x_rt.d_y + 1.0E-12));
247}

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

Here is the call graph for this function:

◆ l2Dist()

template<class T >
T util::l2Dist ( const std::vector< T > &  x1,
const std::vector< T > &  x2 
)
inline

Computes l2 distance between two vectors.

Parameters
x1Vector 1
x2Vector 2
Returns
l2_dist L2 distance

Definition at line 357 of file geom.h.

357 {
358
359 if (x1.size() != x2.size())
360 throw std::invalid_argument("size of two vectors not matching");
361
362 T sum = 0.;
363 for (size_t i=0; i<x1.size(); i++)
364 sum += (x1[i] - x2[i]) * (x1[i] - x2[i]);
365
366 return std::sqrt(sum);
367}

Referenced by test::testUtilMethods().

Here is the caller graph for this function:

◆ 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 62 of file function.cpp.

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

References isLess().

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

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

◆ pointDistanceLine()

double util::pointDistanceLine ( const util::Point p,
const std::pair< util::Point, util::Point > &  line 
)

Compute distance between point and line.

Parameters
pPoint
lineLine
Returns
Value Distance

Definition at line 502 of file geom.cpp.

503 {
504
505 // line vector
506 auto v = line.second - line.first;
507
508 // vector from 1st point of line to p
509 auto w = p - line.first;
510
511 // project w onto v and add 1st point to get projected point's location
512 auto w_on_line = line.first + (w * v) * v / v.lengthSq();
513
514 return (p - w_on_line).length();
515}

References util::Point::lengthSq().

Here is the call graph for this function:

◆ pointDistancePlane()

double util::pointDistancePlane ( const util::Point p,
const std::pair< util::Point, util::Point > &  plane 
)

Compute distance between point and plane.

Parameters
pPoint
planePlane given by pair of normal and one point which it contains
Returns
Value Distance

Definition at line 540 of file geom.cpp.

541 {
542
543 // if plane is given by unit normal n and a point a which is contained in it
544 // then the distance of point p from plane is
545 // |(p - a) dot n| / |n|
546
547 auto pa = p - plane.second;
548 return std::abs(pa * plane.first) / plane.first.length();
549}

References util::Point::length().

Here is the call graph for this function:

◆ pointDistanceSegment()

double util::pointDistanceSegment ( const util::Point p,
const std::pair< util::Point, util::Point > &  line 
)

Compute distance between point and line.

Parameters
pPoint
lineLine
Returns
Value Distance

Definition at line 517 of file geom.cpp.

518 {
519
520 // line vector
521 auto v = line.second - line.first;
522
523 // vector from 1st point of line to p
524 auto w = p - line.first;
525
526 // determine if w is on left side or right side of line
527 double w_dot_v = w * v;
528 if (w_dot_v < 1.0E-12)
529 return (p - line.first).length();
530
531 if (w_dot_v > v.lengthSq() - 1.0E-12)
532 return (p - line.second).length();
533
534 // project w onto v and add 1st point to get projected point's location
535 auto w_on_line = line.first + w_dot_v * v / v.lengthSq();
536
537 return (p - w_on_line).length();
538}

References util::Point::length().

Here is the call graph for this function:

◆ print_bool()

util.print_bool (   arg,
  prefix = "" 
)

Definition at line 16 of file util.py.

16def print_bool(arg, prefix = ""):
17 return prefix + 'True\n' if arg == True else 'False\n'
18

◆ print_cir_gmsh()

util.print_cir_gmsh (   arg,
  n 
)

Definition at line 36 of file util.py.

36def print_cir_gmsh(arg, n):
37 return 'Circle(%d) = {' % n + print_list(arg, '%d') + '};\n'
38

References print_list().

Referenced by generate_circle_gmsh_input().

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

◆ print_const()

util.print_const (   arg,
  fmt = '%4.6e',
  prefix = "" 
)

Definition at line 5 of file util.py.

5def print_const(arg, fmt = '%4.6e', prefix = ""):
6 return prefix + fmt % arg + '\n'
7

Referenced by print_dbl(), and print_int().

Here is the caller graph for this function:

◆ print_dbl()

util.print_dbl (   arg,
  prefix = "" 
)

Definition at line 19 of file util.py.

19def print_dbl(arg, prefix = ""):
20 return print_const(arg, '%4.6e', prefix)
21

References print_const().

Here is the call graph for this function:

◆ print_dbl_list()

util.print_dbl_list (   arg,
  prefix = "" 
)

Definition at line 25 of file util.py.

25def print_dbl_list(arg, prefix = ""):
26 a = prefix + '[' + print_list(arg, '%4.6e') + ']\n'
27 return a
28

References print_list().

Here is the call graph for this function:

◆ print_int()

util.print_int (   arg,
  prefix = "" 
)

Definition at line 22 of file util.py.

22def print_int(arg, prefix = ""):
23 return print_const(arg, '%d', prefix)
24

References print_const().

Here is the call graph for this function:

◆ print_int_list()

util.print_int_list (   arg,
  prefix = "" 
)

Definition at line 29 of file util.py.

29def print_int_list(arg, prefix = ""):
30 a = prefix + '[' + print_list(arg, '%4.6e') + ']\n'
31 return a
32

References print_list().

Here is the call graph for this function:

◆ print_line_gmsh()

util.print_line_gmsh (   arg,
  n 
)

Definition at line 39 of file util.py.

39def print_line_gmsh(arg, n):
40 return 'Line(%d) = {' % n + print_list(arg, '%d') + '};\n'
41

References print_list().

Referenced by generate_drum_gmsh_input(), generate_hexagon_gmsh_input(), and generate_rectangle_gmsh_input().

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

◆ print_lineloop_gmsh()

util.print_lineloop_gmsh (   arg,
  n 
)

Definition at line 42 of file util.py.

42def print_lineloop_gmsh(arg, n):
43 return 'Line Loop(%d) = {' % n + print_list(arg, '%d') + '};\n'
44

References print_list().

Referenced by generate_circle_gmsh_input(), generate_drum_gmsh_input(), generate_hexagon_gmsh_input(), and generate_rectangle_gmsh_input().

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

◆ print_list()

util.print_list (   arg,
  fmt = '%4.6e',
  delim = ', ' 
)

Definition at line 8 of file util.py.

8def print_list(arg, fmt = '%4.6e', delim = ', '):
9 a = ''
10 for i in range(len(arg)):
11 a += fmt % arg[i]
12 if i < len(arg) - 1:
13 a += delim
14 return a
15

Referenced by particle_wall.particle_locations(), print_cir_gmsh(), print_dbl_list(), print_int_list(), print_line_gmsh(), print_lineloop_gmsh(), and print_point_gmsh().

Here is the caller graph for this function:

◆ print_point_gmsh()

util.print_point_gmsh (   arg,
  n 
)

Definition at line 33 of file util.py.

33def print_point_gmsh(arg, n):
34 return 'Point(%d) = {' % n + print_list(arg) + '};\n'
35

References print_list().

Referenced by generate_circle_gmsh_input(), generate_drum_gmsh_input(), generate_hexagon_gmsh_input(), and generate_rectangle_gmsh_input().

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

◆ rotate() [1/2]

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 transformation.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 particle::ParticleTransform::apply(), util::geometry::Drum2D::Drum2D(), get_ref_drum_points(), get_ref_hex_points(), util::geometry::Hexagon::Hexagon(), util::geometry::Drum2D::isInside(), test::testUtilMethods(), and util::geometry::Triangle::Triangle().

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

◆ rotate() [2/2]

util.rotate (   p,
  theta,
  axis 
)
Returns rotation of vector about specified axis by specified angle

Parameters
----------
p: list
    Coordinates of vector
theta : float
    Angle of rotation
axis : list
    Axis of rotation

Returns
-------
list
    Coordinates of rotated vector

Definition at line 121 of file util.py.

121def rotate(p, theta, axis):
122 """
123 Returns rotation of vector about specified axis by specified angle
124
125 Parameters
126 ----------
127 p: list
128 Coordinates of vector
129 theta : float
130 Angle of rotation
131 axis : list
132 Axis of rotation
133
134 Returns
135 -------
136 list
137 Coordinates of rotated vector
138 """
139 p_np, axis_np = np.array(p), np.array(axis)
140 ct, st = np.cos(theta), np.sin(theta)
141 p_dot_n = np.dot(p_np,axis_np)
142 n_cross_p = np.cross(axis_np, p_np)
143
144 return (1. - ct) * p_dot_n * axis_np + ct * p_np + st * n_cross_p
145

◆ 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 transformation.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 transformation.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 transformation.cpp.

32 {
33
34 return rotateCW2D(x, -theta);
35}

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 transformation.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 transformation.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 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 transformation.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.

◆ toPointBox()

std::pair< util::Point, util::Point > util::toPointBox ( const std::vector< double > &  p1,
const std::vector< double > &  p2 
)

Create box from two coordinate data.

Parameters
p1Point 1
p2Point 2
Returns
Box Pair of corner points of box

Definition at line 634 of file geom.cpp.

636 {
637 auto q1 = util::Point(p1[0], p1[1], p1[2]);
638 auto q2 = util::Point(p2[0], p2[1], p2[2]);
639 return {q1, q2};
640}

◆ 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 model::DEMModel::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:

◆ triangleArea()

double util::triangleArea ( const util::Point x1,
const util::Point x2,
const util::Point x3 
)

Compute area of triangle.

Parameters
x1Vertex 1
x2Vertex 2
x3Vertex 3
Returns
area Area of triangle

Definition at line 642 of file geom.cpp.

643 {
644 return 0.5 * ((x2.d_x - x1.d_x) * (x3.d_y - x1.d_y) -
645 (x3.d_x - x1.d_x) * (x2.d_y - x1.d_y));
646}

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

Referenced by util::geometry::Triangle::isInside(), util::geometry::Triangle::isNearBoundary(), and test::testUtilMethods().

Here is the caller graph for this function: