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

Namespaces

namespace  anonymous_namespace{geomObjects.cpp}
 
namespace  anonymous_namespace{openCuboidChannel3D.cpp}
 
namespace  anonymous_namespace{openRectChannel2D.cpp}
 

Data Structures

class  AnnulusGeomObject
 Defines annulus rectangle. More...
 
struct  BoxPartition
 Defines simple rectangle domain. More...
 
class  Circle
 Defines circle. More...
 
class  ComplexGeomObject
 Defines complex geometrical object. More...
 
class  Cube
 Defines cube. More...
 
class  Cuboid
 Defines cuboid. More...
 
class  Cylinder
 Defines cylinder. More...
 
class  Drum2D
 Defines Drum2D. More...
 
class  Ellipse
 Filled ellipse in the plane z = center.d_z, semi-axes in the xy plane. More...
 
class  Ellipsoid
 Ellipsoid: center \(\mathbf c\), semi-axes \(r_1,r_2,r_3\) in a body frame rotated from world by axis–angle \((\hat{\mathbf a},\theta)\) (Rodrigues). Axis-aligned case: \(\theta=0\) (axis ignored). More...
 
struct  GeomData
 Input data for geometrical objects. More...
 
class  GeomObject
 Defines abstract geometrical domain. More...
 
class  Hexagon
 Defines Hexagon. More...
 
class  Line
 Defines Line. More...
 
class  NullGeomObject
 Defines null (empty) geom object. More...
 
class  OpenCuboidChannel3D
 Hollow axis-aligned cuboid shell with uniform wall thickness and one outer face open. More...
 
class  OpenRectChannel2D
 2D U-shaped cavity: thick rectangular frame with the top (+y) side open. More...
 
struct  ParticleTransform
 A struct that stores transformation parameters and provides method to transform the particle. Given a reference particle, this provides method to translate, rotate, and scale the reference particle. More...
 
class  Plane
 Infinite plane: free space is the half-space in the normal direction. More...
 
class  Rectangle
 Defines Rectangle. More...
 
class  Sphere
 Defines sphere. More...
 
class  Square
 Defines Square. More...
 
class  Triangle
 Defines Triangle. More...
 
struct  WallContactHit
 Result of a wall-contact query against a geom (analytical walls). More...
 

Functions

size_t getGeomTypeToDim (std::string type)
 Returns list of acceptable geometries for PeriDEM simulation.
 
util::Point mapSimilarity (const util::Point &x, const util::Point &pivotDefault, const util::Point &t, double scale, double angle, const util::Point &axis, const util::Point *rotationPoint)
 
std::vector< size_t > getNumParamsRequired (std::string geom_type)
 Get num params required for creation of object.
 
bool isNumberOfParamForGeometryValid (size_t n, std::string geom_type)
 Ascertain if number of parameters are correct for the given geometry.
 
bool isNumberOfParamForComplexGeometryValid (size_t n, std::string geom_type, std::vector< std::string > vec_type)
 Ascertain if number of parameters are correct for the given geometry.
 
bool checkParamForGeometry (size_t n, std::string geom_type)
 Check parameter data for validity.
 
bool checkParamForComplexGeometry (size_t n, std::string geom_type, std::vector< std::string > vec_type)
 Check parameter data for validity.
 
void createGeomObjectOld (const std::string &type, const std::vector< double > &params, const std::vector< std::string > &vec_type, const std::vector< std::string > &vec_flag, std::shared_ptr< geom::GeomObject > &obj, bool perform_check=true)
 Create geometrical object from the given data.
 
void createGeomObject (const std::string &geom_type, const std::vector< double > &params, const std::vector< std::string > &vec_type, const std::vector< std::string > &vec_flag, std::shared_ptr< geom::GeomObject > &obj, bool perform_check)
 
void createGeomObject (GeomData &geomData, bool perform_check)
 
std::vector< double > exampleGeomParams (const std::string &geom_type, const util::Point &c=util::Point(0., 0., 0.), double s=0.001)
 Canonical parameter vector for examples, mesh generation tests, and demos.
 
std::shared_ptr< GeomObject > makeExampleGeomObject (const std::string &geom_type, const util::Point &c=util::Point(0., 0., 0.), double s=0.001)
 One-liner: createGeomObject(exampleGeomParams(...)). Prefer this over per-class static factories so annulus and composite types stay in one place.
 
void writeGeometry (json &j, const geom::GeomData &geomData)
 
void readGeometry (const json &j, geom::GeomData &geomData)
 
GeomObject * createGeomDeepCopy (GeomObject *obj)
 Creates a deep copy of a geometric object.
 
const std::vector< std::string > & getAcceptableGeometries ()
 Returns list of acceptable geometries for PeriDEM simulation.
 
std::vector< util::Point > getCornerPoints (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::Point > computeBBox (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::Point > toPointBox (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.
 
void computeNonlocalNeighborhood (const std::vector< util::Point > &nodes, double horizon, std::vector< std::vector< size_t > > &nodeNeighs)
 Partitions the nodes based on node neighborlist supplied. Function first creates a graph with nodes as vertices and edges given by node neighbors. Then the metis function is called to partition the graph into specified number of parts.
 
void ellipsoidRotationMatrix (const Ellipsoid &e, double R[9])
 Row-major 3×3 rotation \(\mathbf R\) from ellipsoid axis–angle (identity if \(\theta=0\)).
 
Methods to check intersection of geometric 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.
 
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.
 

Variables

const std::map< std::string, size_t > geom_type_to_dim
 Geometry type to dimension map.
 
const std::vector< std::string > acceptable_geometries
 List of acceptable geometries for particles in PeriDEM.
 

Function Documentation

◆ areBoxesNear()

bool geom::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 124 of file geomUtilFunctions.cpp.

128 {
129
130 auto cp1 = getCornerPoints(dim, b1);
131 auto cp2 = getCornerPoints(dim, b2);
132
133 for (auto p : cp1) {
134
135 // check 1: If any of the corner points of box 1 are inside box 2
136 if (isPointInsideBox(p, dim, b2))
137 return true;
138
139 // check 2: If any pair of corner points of box 1 and box 2 are at
140 // distance smaller than the tolerance
141 for (auto pp : cp2) {
142 auto dx = pp - p;
143 if (util::isLess(dx.length(), tol))
144 return true;
145 }
146 }
147
148 // check 3: Check if distance between centers of box 1 and box 2 are below
149 // sum of tolerance, radius of circle inscribed in box 1, and radius of
150 // circle inscribed in box 2
151 auto dxc = getCenter(dim, b2) - getCenter(dim, b1);
152 auto dist = tol + inscribedRadiusInBox(dim, b1) + inscribedRadiusInBox(dim,
153 b2);
154
155 if (util::isLess(dxc.length(), dist))
156 return true;
157
158 // check 4: Check if distance between centers of box 1 and box 2 are below
159 // sum of tolerance, radius of circle inscribed in box 1, and radius of
160 // circle circumscribed in box 2
161 dist = tol + inscribedRadiusInBox(dim, b1) + circumscribedRadiusInBox(dim,
162 b2);
163 if (util::isLess(dxc.length(), dist))
164 return true;
165
166 dist = tol + circumscribedRadiusInBox(dim, b1) + inscribedRadiusInBox(dim,
167 b2);
168 if (util::isLess(dxc.length(), dist))
169 return true;
170
171 return false;
172}
util::Point getCenter(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns center point.
bool isPointInsideBox(util::Point x, size_t dim, const std::pair< util::Point, util::Point > &box)
Returns true if point is inside box.
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.
std::vector< util::Point > getCornerPoints(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns all corner points in the box.
double inscribedRadiusInBox(size_t dim, const std::pair< util::Point, util::Point > &box)
Computes the radius of biggest circle/sphere completely within the object.
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:22

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

Referenced by geom::Triangle::isNear(), geom::Square::isNear(), geom::Rectangle::isNear(), geom::Hexagon::isNear(), geom::Drum2D::isNear(), geom::Cube::isNear(), geom::Cuboid::isNear(), geom::Ellipsoid::isNear(), geom::Cylinder::isNear(), geom::OpenCuboidChannel3D::isNear(), and geom::OpenRectChannel2D::isNear().

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

◆ checkParamForComplexGeometry()

bool geom::checkParamForComplexGeometry ( size_t  n,
std::string  geom_type,
std::vector< std::string >  vec_type 
)

Check parameter data for validity.

Parameters
nNumber of parameters available
geom_typeGeometry type of object
vec_typeFor complex objects, specify types of sub-objects
Returns
bool True if number of parameter is incorrect so require further checks

Definition at line 134 of file geomObjectsUtil.cpp.

136 {
137
138 return !isNumberOfParamForComplexGeometryValid(n, geom_type, vec_type);
139 }
bool isNumberOfParamForComplexGeometryValid(size_t n, std::string geom_type, std::vector< std::string > vec_type)
Ascertain if number of parameters are correct for the given geometry.

References isNumberOfParamForComplexGeometryValid().

Here is the call graph for this function:

◆ checkParamForGeometry()

bool geom::checkParamForGeometry ( size_t  n,
std::string  geom_type 
)

Check parameter data for validity.

Parameters
nNumber of parameters available
geom_typeGeometry type of object
Returns
bool True if number of parameter is incorrect so require further checks

Definition at line 129 of file geomObjectsUtil.cpp.

129 {
130
131 return !isNumberOfParamForGeometryValid(n, geom_type);
132 }
bool isNumberOfParamForGeometryValid(size_t n, std::string geom_type)
Ascertain if number of parameters are correct for the given geometry.

References isNumberOfParamForGeometryValid().

Here is the call graph for this function:

◆ circumscribedRadiusInBox()

double geom::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 225 of file geomUtilFunctions.cpp.

226 {
227
228 auto xc = getCenter(dim, box);
229 auto cp = getCornerPoints(dim, box);
230
231 auto dx = cp[0] - xc;
232 auto r = dx.length();
233
234 if (dim == 1)
235 return r;
236 else {
237 for (auto p : cp) {
238 dx = p - xc;
239 if (util::isGreater(dx.length(), r))
240 r = dx.length();
241 }
242
243 return r;
244 }
245}
bool isGreater(const double &a, const double &b)
Returns true if a > b.
Definition function.cpp:17

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

Referenced by areBoxesNear(), geom::Circle::isNear(), geom::Ellipse::isNear(), and geom::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 > geom::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 623 of file geomUtilFunctions.cpp.

623 {
624
625 auto p1 = util::Point();
626 auto p2 = util::Point();
627 for (const auto& x : nodes) {
628 if (util::isLess(x.d_x, p1.d_x))
629 p1.d_x = x.d_x;
630 if (util::isLess(x.d_y, p1.d_y))
631 p1.d_y = x.d_y;
632 if (util::isLess(x.d_z, p1.d_z))
633 p1.d_z = x.d_z;
634 if (util::isLess(p2.d_x, x.d_x))
635 p2.d_x = x.d_x;
636 if (util::isLess(p2.d_y, x.d_y))
637 p2.d_y = x.d_y;
638 if (util::isLess(p2.d_z, x.d_z))
639 p2.d_z = x.d_z;
640 }
641
642 return {p1, p2};
643}
A structure to represent 3d vectors.
Definition point.h:30

References util::isLess().

Here is the call graph for this function:

◆ computeInscribedRadius()

double geom::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 645 of file geomUtilFunctions.cpp.

646 {
647
648 return 0.5 * (box.first - box.second).length();
649}

◆ computeMeshSize() [1/2]

double geom::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 568 of file geomUtilFunctions.cpp.

568 {
569
570 double guess = 0.;
571 if (nodes.size() < 2)
572 return guess;
573
574 guess = (nodes[0] - nodes[1]).length();
575 for (size_t i = 0; i < nodes.size(); i++)
576 for (size_t j = 0; j < nodes.size(); j++)
577 if (i != j) {
578 double val = nodes[i].dist(nodes[j]);
579
580 if (util::isLess(val, 1.0E-12)) {
581
582 std::cout << "Check nodes are too close = "
583 << util::io::printStr<util::Point>({nodes[i],
584 nodes[j]})
585 << "\n";
586 std::cout << "Distance = " << val << ", guess = " << guess << "\n";
587 }
588 if (util::isLess(val, guess))
589 guess = val;
590 }
591
592 return guess;
593}

References util::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 geom::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 595 of file geomUtilFunctions.cpp.

596 {
597
598 double guess = 0.;
599 if (nodes.size() < 2 or (end - start) < 2)
600 return guess;
601
602 guess = (nodes[start] - nodes[start + 1]).length();
603 for (size_t i = start; i < end; i++)
604 for (size_t j = start; j < end; j++)
605 if (i != j) {
606 double val = nodes[i].dist(nodes[j]);
607
608 if (util::isLess(val, 1.0E-12)) {
609
610 std::cout << "Check nodes are too close = "
611 << util::io::printStr<util::Point>({nodes[i],
612 nodes[j]})
613 << "\n";
614 std::cout << "Distance = " << val << ", guess = " << guess << "\n";
615 }
616 if (util::isLess(val, guess))
617 guess = val;
618 }
619
620 return guess;
621}

References util::isLess().

Here is the call graph for this function:

◆ computeNonlocalNeighborhood()

void geom::computeNonlocalNeighborhood ( const std::vector< util::Point > &  nodes,
double  horizon,
std::vector< std::vector< size_t > > &  nodeNeighs 
)

Partitions the nodes based on node neighborlist supplied. Function first creates a graph with nodes as vertices and edges given by node neighbors. Then the metis function is called to partition the graph into specified number of parts.

Parameters
nodesNodal coordinates
horizonNonlocal radius
nodeNeighsNeighborlist of nodes

Definition at line 665 of file geomUtilFunctions.cpp.

667 {
668 nodeNeighs.resize(nodes.size());
669
670 auto nsearch_p = std::make_unique<NSearch>(nodes);
671 double set_tree_time = nsearch_p->updatePointCloud(nodes, true);
672 set_tree_time += nsearch_p->setInputCloud();
673 std::cout << std::format("Tree setup time (ms) = {}. \n", set_tree_time);
674
675 for (size_t i=0; i<nodes.size(); i++) {
676 std::vector<size_t> neighs;
677 std::vector<double> sqr_dist;
678 nodeNeighs[i].resize(0);
679
680 if (nsearch_p->radiusSearch(nodes[i], horizon, neighs, sqr_dist) > 0) {
681 for (std::size_t j = 0; j < neighs.size(); ++j)
682 if (neighs[j] != i) {
683 nodeNeighs[i].push_back(neighs[j]);
684 }
685 }
686 }
687}

Referenced by test::testGraphPartitioning(), and test::testMPI().

Here is the caller graph for this function:

◆ createGeomDeepCopy()

GeomObject * geom::createGeomDeepCopy ( GeomObject *  obj)

Creates a deep copy of a geometric object.

Parameters
objPointer to the object to copy
Returns
Pointer to the newly created copy

Definition at line 1429 of file geomObjectsUtil.cpp.

1429 {
1430 if (!obj)
1431 return nullptr;
1432
1433 const std::string &type = obj->d_name;
1434 if (type == "null")
1435 return new NullGeomObject(*dynamic_cast<const NullGeomObject *>(obj));
1436 if (type == "plane")
1437 return new Plane(*dynamic_cast<const Plane *>(obj));
1438 if (type == "line")
1439 return new Line(*dynamic_cast<const Line *>(obj));
1440 if (type == "triangle")
1441 return new Triangle(*dynamic_cast<const Triangle *>(obj));
1442 if (type == "square")
1443 return new Square(*dynamic_cast<const Square *>(obj));
1444 if (type == "rectangle")
1445 return new Rectangle(*dynamic_cast<const Rectangle *>(obj));
1446 if (type == "hexagon")
1447 return new Hexagon(*dynamic_cast<const Hexagon *>(obj));
1448 if (type == "drum2d")
1449 return new Drum2D(*dynamic_cast<const Drum2D *>(obj));
1450 if (type == "cube")
1451 return new Cube(*dynamic_cast<const Cube *>(obj));
1452 if (type == "cuboid")
1453 return new Cuboid(*dynamic_cast<const Cuboid *>(obj));
1454 if (type == "circle")
1455 return new Circle(*dynamic_cast<const Circle *>(obj));
1456 if (type == "sphere")
1457 return new Sphere(*dynamic_cast<const Sphere *>(obj));
1458 if (type == "cylinder")
1459 return new Cylinder(*dynamic_cast<const Cylinder *>(obj));
1460 if (type == "ellipse")
1461 return new Ellipse(*dynamic_cast<const Ellipse *>(obj));
1462 if (type == "ellipsoid")
1463 return new Ellipsoid(*dynamic_cast<const Ellipsoid *>(obj));
1464 if (type == "annulus_object")
1465 return new AnnulusGeomObject(*dynamic_cast<const AnnulusGeomObject *>(obj));
1466 if (type == "open_rect_channel_2d")
1467 return new OpenRectChannel2D(*dynamic_cast<const OpenRectChannel2D *>(obj));
1468 if (type == "open_cuboid_channel_3d")
1469 return new OpenCuboidChannel3D(*dynamic_cast<const OpenCuboidChannel3D *>(obj));
1470 if (type == "complex")
1471 return new ComplexGeomObject(*dynamic_cast<const ComplexGeomObject *>(obj));
1472
1473 throw std::invalid_argument(
1475 << "Error: Unsupported object type '" << type << "' in createGeomDeepCopy\n");
1476 }
Defines annulus rectangle.
Defines circle.
Defines complex geometrical object.
Defines cube.
Defines cuboid.
Defines cylinder.
Defines Drum2D.
Filled ellipse in the plane z = center.d_z, semi-axes in the xy plane.
Ellipsoid: center , semi-axes in a body frame rotated from world by axis–angle (Rodrigues)....
const std::string d_name
name of object
Defines Hexagon.
Defines Line.
Defines null (empty) geom object.
Hollow axis-aligned cuboid shell with uniform wall thickness and one outer face open.
2D U-shaped cavity: thick rectangular frame with the top (+y) side open.
Infinite plane: free space is the half-space in the normal direction.
Defines Rectangle.
Defines sphere.
Defines Square.
Defines Triangle.
Collects a message with stream syntax for use in an exception.
Definition io.h:52

References geom::GeomObject::d_name.

Referenced by geom::AnnulusGeomObject::AnnulusGeomObject(), geom::ComplexGeomObject::ComplexGeomObject(), particle::createParticlesFromFile(), geom::AnnulusGeomObject::operator=(), and geom::ComplexGeomObject::operator=().

Here is the caller graph for this function:

◆ createGeomObject() [1/2]

void geom::createGeomObject ( const std::string &  geom_type,
const std::vector< double > &  params,
const std::vector< std::string > &  vec_type,
const std::vector< std::string > &  vec_flag,
std::shared_ptr< geom::GeomObject > &  obj,
bool  perform_check 
)

Definition at line 688 of file geomObjectsUtil.cpp.

693 {
694
695 std::vector<size_t> num_params_needed;
696
697 if (geom_type == "line") {
698
699 num_params_needed = {1, 4, 6};
700
701 for (auto n: num_params_needed) {
702 if (params.size() == n) {
703 if (n == 1) {
704 obj = std::make_shared<geom::Line>(params[0]);
705 return;
706 } else if (n == 4) {
707 obj = std::make_shared<geom::Line>(params[0],
709 params[1],
710 params[2],
711 params[3]));
712
713 return;
714 } else if (n == 6) {
715 obj = std::make_shared<geom::Line>(
716 util::Point(params[0], params[1], params[2]),
717 util::Point(params[3], params[4], params[5]));
718
719 return;
720 }
721 } // if params.size() == n
722 } // loop over n
723 } // Line
724 else if (geom_type == "plane") {
725 if (params.size() == 6) {
726 obj = std::make_shared<geom::Plane>(
727 util::Point(params[0], params[1], params[2]),
728 util::Point(params[3], params[4], params[5]));
729 return;
730 }
731 }
732 else if (geom_type == "triangle") {
733
734 num_params_needed = {1, 4, 7, 9};
735
736 for (auto n: num_params_needed) {
737 if (params.size() == n) {
738 if (n == 1) {
739 obj = std::make_shared<geom::Triangle>(params[0]);
740 return;
741 } else if (n == 4) {
742 obj = std::make_shared<geom::Triangle>(
743 params[0],
744 util::Point(params[1], params[2], params[3]));
745
746 return;
747 } else if (n == 7) {
748 obj = std::make_shared<geom::Triangle>(
749 params[0],
750 util::Point(params[1],params[2],params[3]),
751 util::Point(params[4],params[5],params[6]));
752
753 return;
754 } else if (n == 9) {
755 obj = std::make_shared<geom::Triangle>(
756 util::Point(params[0], params[1], params[2]),
757 util::Point(params[3], params[4], params[5]),
758 util::Point(params[6], params[7], params[8]));
759 return;
760 }
761 } // if params.size() == n
762 } // loop over n
763 } // Triangle
764 else if (geom_type == "square") {
765
766 num_params_needed = {1, 4, 6};
767
768 for (auto n: num_params_needed) {
769 if (params.size() == n) {
770 if (n == 1) {
771 obj = std::make_shared<geom::Square>(params[0]);
772 return;
773 } else if (n == 4) {
774 obj = std::make_shared<geom::Square>(params[0],
776 params[1],
777 params[2],
778 params[3]));
779 return;
780 } else if (n == 6) {
781 obj = std::make_shared<geom::Square>(
782 util::Point(params[0], params[1], params[2]),
783 util::Point(params[3], params[4], params[5]));
784 return;
785 }
786 } // if params.size() == n
787 } // loop over n
788 } // Square
789 else if (geom_type == "rectangle") {
790
791 num_params_needed = {2, 5, 6};
792
793 for (auto n: num_params_needed) {
794 if (params.size() == n) {
795 if (n == 2) {
796 obj = std::make_shared<geom::Rectangle>(params[0],
797 params[1]);
798 return;
799 } else if (n == 5) {
800 obj = std::make_shared<geom::Rectangle>(
801 params[0], params[1],
802 util::Point(params[2], params[3], params[4]));
803 return;
804 } else if (n == 6) {
805 obj = std::make_shared<geom::Rectangle>(
806 util::Point(params[0], params[1], params[2]),
807 util::Point(params[3], params[4], params[5]));
808 return;
809 }
810 } // if params.size() == n
811 } // loop over n
812 } // Rectangle
813 else if (geom_type == "hexagon") {
814
815 num_params_needed = {1, 4, 7};
816
817 for (auto n: num_params_needed) {
818 if (params.size() == n) {
819 if (n == 1) {
820 obj = std::make_shared<geom::Hexagon>(params[0]);
821 return;
822 } else if (n == 4) {
823 // r, cx, cy, cz — same layout as triangle/circle 4-param branches (not params[2..4]).
824 obj = std::make_shared<geom::Hexagon>(
825 params[0], util::Point(params[1], params[2], params[3]));
826 return;
827 } else if (n == 7) {
828 obj = std::make_shared<geom::Hexagon>(
829 params[0],
830 util::Point(params[1], params[2], params[3]),
831 util::Point(params[4], params[5], params[6]));
832 return;
833 }
834 } // if params.size() == n
835 } // loop over n
836 } // Hexagon
837 else if (geom_type == "drum2d") {
838
839 num_params_needed = {2, 5, 8};
840
841 for (auto n: num_params_needed) {
842 if (params.size() == n) {
843 if (n == 2) {
844 obj = std::make_shared<geom::Drum2D>(
845 params[0], params[1]);
846 return;
847 } else if (n == 5) {
848 obj = std::make_shared<geom::Drum2D>(
849 params[0], params[1],
850 util::Point(params[2], params[3], params[4]));
851 return;
852 } else if (n == 8) {
853 obj = std::make_shared<geom::Drum2D>(
854 params[0], params[1],
855 util::Point(params[2], params[3], params[4]),
856 util::Point(params[5], params[6], params[7]));
857 return;
858 }
859 } // if params.size() == n
860 } // loop over n
861 } // Drum2D
862 else if (geom_type == "cube") {
863
864 num_params_needed = {1, 4, 6};
865
866 for (auto n: num_params_needed) {
867 if (params.size() == n) {
868 if (n == 1) {
869 obj = std::make_shared<geom::Cube>(params[0]);
870 return;
871 } else if (n == 4) {
872 obj = std::make_shared<geom::Cube>(
873 params[0],
874 util::Point(params[1], params[2], params[3]));
875 return;
876 } else if (n == 6) {
877 obj = std::make_shared<geom::Cube>(
878 util::Point(params[0], params[1], params[2]),
879 util::Point(params[3], params[4], params[5]));
880 return;
881 }
882 } // if params.size() == n
883 } // loop over n
884 } // Cube
885 else if (geom_type == "cuboid") {
886
887 num_params_needed = {3, 6};
888
889 for (auto n: num_params_needed) {
890 if (params.size() == n) {
891 if (n == 3) {
892 obj = std::make_shared<geom::Cuboid>(
893 params[0], params[1], params[2]);
894 return;
895 } else if (n == 6) {
896 obj = std::make_shared<geom::Cuboid>(
897 util::Point(params[0], params[1], params[2]),
898 util::Point(params[3], params[4], params[5]));
899 return;
900 }
901 } // if params.size() == n
902 } // loop over n
903 } // Cuboid
904 else if (geom_type == "circle") {
905
906 num_params_needed = {1, 4};
907
908 for (auto n: num_params_needed) {
909 if (params.size() == n) {
910 if (n == 1) {
911 obj = std::make_shared<geom::Circle>(params[0]);
912 return;
913 } else if (n == 4) {
914 obj = std::make_shared<geom::Circle>(
915 params[0],
916 util::Point(params[1], params[2], params[3]));
917 return;
918 }
919 } // if params.size() == n
920 } // loop over n
921 } // Circle
922 else if (geom_type == "sphere") {
923
924 num_params_needed = {1, 4};
925
926 for (auto n: num_params_needed) {
927 if (params.size() == n) {
928 if (n == 1) {
929 obj = std::make_shared<geom::Sphere>(params[0]);
930 return;
931 } else if (n == 4) {
932 obj = std::make_shared<geom::Sphere>(
933 params[0],
934 util::Point(params[1], params[2], params[3]));
935 return;
936 }
937 } // if params.size() == n
938 } // loop over n
939 } // Sphere
940 else if (geom_type == "ellipse") {
941
942 num_params_needed = {6};
943
944 for (auto n: num_params_needed) {
945 if (params.size() == n) {
946 if (n == 6) {
947 obj = std::make_shared<geom::Ellipse>(
948 params[0], params[1], params[2],
949 util::Point(params[3], params[4], params[5]));
950 return;
951 }
952 }
953 }
954 } // Ellipse
955 else if (geom_type == "ellipsoid") {
956
957 num_params_needed = {6, 10};
958
959 for (auto n: num_params_needed) {
960 if (params.size() == n) {
961 if (n == 6) {
962 obj = std::make_shared<geom::Ellipsoid>(
963 params[0], params[1], params[2],
964 util::Point(params[3], params[4], params[5]));
965 return;
966 }
967 if (n == 10) {
968 obj = std::make_shared<geom::Ellipsoid>(
969 params[0], params[1], params[2], params[3],
970 util::Point(params[4], params[5], params[6]),
971 util::Point(params[7], params[8], params[9]));
972 return;
973 }
974 }
975 }
976 } // Ellipsoid
977 else if (geom_type == "cylinder") {
978
979 num_params_needed = {7, 8};
980
981 for (auto n: num_params_needed) {
982 if (params.size() == n) {
983 if (n == 7) {
984 // r, center begin, axis vector (no normalization as length of axis is length of cylinder)
985 obj = std::make_shared<geom::Cylinder>(
986 params[0],
987 util::Point(params[1], params[2], params[3]),
988 util::Point(params[4], params[5], params[6]));
989 return;
990 } else if (n == 8) {
991 // r, length, center begin, unit axis vector
992 obj = std::make_shared<geom::Cylinder>(
993 params[0], params[1],
994 util::Point(params[2], params[3], params[4]),
995 util::Point(params[5], params[6], params[7]));
996 return;
997 }
998 } // if params.size() == n
999 } // loop over n
1000 } // Cylinder
1001 else if (geom_type == "angled_rectangle") {
1002
1003 num_params_needed = {6};
1004
1005 for (auto n: num_params_needed) {
1006 if (params.size() == n) {
1007 if (n == 6) {
1008 obj = std::make_shared<geom::Rectangle>(
1009 util::Point(params[0], params[1], params[2]),
1010 util::Point(params[3], params[4], params[5]));
1011
1012 return;
1013 }
1014 } // if params.size() == n
1015 } // loop over n
1016 } // angled_rectangle
1017 else if (geom_type == "angled_cuboid") {
1018
1019 num_params_needed = {6};
1020
1021 for (auto n: num_params_needed) {
1022 if (params.size() == n) {
1023 if (n == 6) {
1024 obj = std::make_shared<geom::Cuboid>(
1025 util::Point(params[0], params[1], params[2]),
1026 util::Point(params[3], params[4], params[5]));
1027
1028 return;
1029 }
1030 } // if params.size() == n
1031 } // loop over n
1032 } // angled_cuboid
1033 else if (geom_type == "rectangle_minus_rectangle") {
1034
1035 num_params_needed = {12};
1036
1037 for (auto n: num_params_needed) {
1038 if (params.size() == n) {
1039 if (n == 12) {
1040
1041 auto rin = new geom::Rectangle(
1042 util::Point(params[0], params[1], params[2]),
1043 util::Point(params[3], params[4], params[5]));
1044 auto rout = new geom::Rectangle(
1045 util::Point(params[6], params[7], params[8]),
1046 util::Point(params[9], params[10], params[11]));
1047
1048 obj = std::make_shared<geom::AnnulusGeomObject>
1049 (rin, rout);
1050
1051 return;
1052 }
1053 } // if params.size() == n
1054 } // loop over n
1055 } // rectangle_minus_rectangle
1056 else if (geom_type == "cuboid_minus_cuboid") {
1057
1058 num_params_needed = {12};
1059
1060 for (auto n: num_params_needed) {
1061 if (params.size() == n) {
1062 if (n == 12) {
1063
1064 auto rin = new geom::Cuboid(
1065 util::Point(params[0], params[1], params[2]),
1066 util::Point(params[3], params[4], params[5]));
1067 auto rout = new geom::Cuboid(
1068 util::Point(params[6], params[7], params[8]),
1069 util::Point(params[9], params[10], params[11]));
1070
1071 obj = std::make_shared<geom::AnnulusGeomObject>
1072 (rin, rout);
1073
1074 return;
1075 }
1076 } // if params.size() == n
1077 } // loop over n
1078 } // cuboid_minus_cuboid
1079 else if (geom_type == "circle_minus_circle") {
1080
1081 num_params_needed = {5};
1082
1083 for (auto n: num_params_needed) {
1084 if (params.size() == n) {
1085 if (n == 5) {
1086 const double cx = params[0];
1087 const double cy = params[1];
1088 const double cz = params[2];
1089 const double r_outer = params[3];
1090 const double r_inner = params[4];
1091 if (r_inner <= 0. || r_outer <= r_inner)
1092 throw std::runtime_error(
1093 "circle_minus_circle: require 0 < r_inner < r_outer (cx,cy,cz,r_outer,r_inner).");
1094 auto *cin = new geom::Circle(r_inner, util::Point(cx, cy, cz));
1095 auto *cout = new geom::Circle(r_outer, util::Point(cx, cy, cz));
1096 obj = std::make_shared<geom::AnnulusGeomObject>(cin, cout);
1097 return;
1098 }
1099 }
1100 }
1101 } // circle_minus_circle
1102 else if (geom_type == "ellipse_minus_ellipse") {
1103
1104 num_params_needed = {8};
1105
1106 for (auto n: num_params_needed) {
1107 if (params.size() == n) {
1108 if (n == 8) {
1109 const double a_out = params[0];
1110 const double b_out = params[1];
1111 const double a_in = params[2];
1112 const double b_in = params[3];
1113 const double theta = params[4];
1114 const util::Point c(params[5], params[6], params[7]);
1115 if (a_in <= 0. || b_in <= 0. || a_out <= a_in || b_out <= b_in)
1116 throw std::runtime_error(
1117 "ellipse_minus_ellipse: require 0 < a_in < a_out and 0 < b_in < b_out.");
1118 auto *ein = new geom::Ellipse(a_in, b_in, theta, c);
1119 auto *eout = new geom::Ellipse(a_out, b_out, theta, c);
1120 obj = std::make_shared<geom::AnnulusGeomObject>(ein, eout);
1121 return;
1122 }
1123 }
1124 }
1125 } // ellipse_minus_ellipse
1126 else if (geom_type == "sphere_minus_sphere") {
1127
1128 num_params_needed = {5};
1129
1130 for (auto n: num_params_needed) {
1131 if (params.size() == n) {
1132 if (n == 5) {
1133 const double cx = params[0];
1134 const double cy = params[1];
1135 const double cz = params[2];
1136 const double r_outer = params[3];
1137 const double r_inner = params[4];
1138 if (r_inner <= 0. || r_outer <= r_inner)
1139 throw std::runtime_error(
1140 "sphere_minus_sphere: require 0 < r_inner < r_outer (cx,cy,cz,r_outer,r_inner).");
1141 auto *cin = new geom::Sphere(r_inner, util::Point(cx, cy, cz));
1142 auto *cout = new geom::Sphere(r_outer, util::Point(cx, cy, cz));
1143 obj = std::make_shared<geom::AnnulusGeomObject>(cin, cout);
1144 return;
1145 }
1146 }
1147 }
1148 } // sphere_minus_sphere
1149 else if (geom_type == "open_rect_channel_2d") {
1150
1151 num_params_needed = {6};
1152
1153 for (auto n: num_params_needed) {
1154 if (params.size() == n) {
1155 if (n == 6) {
1156 obj = std::make_shared<geom::OpenRectChannel2D>(
1157 params[0], params[1], params[2], params[3], params[4], params[5]);
1158 return;
1159 }
1160 }
1161 }
1162 } // open_rect_channel_2d
1163 else if (geom_type == "open_cuboid_channel_3d") {
1164
1165 num_params_needed = {8};
1166
1167 for (auto n: num_params_needed) {
1168 if (params.size() == n) {
1169 if (n == 8) {
1170 const int face = static_cast<int>(params[7]);
1171 if (face < 0 || face > 5)
1172 throw std::runtime_error(
1173 "open_cuboid_channel_3d: open_face must be 0..5 (±x,±y,±z).");
1174 obj = std::make_shared<geom::OpenCuboidChannel3D>(
1175 params[0], params[1], params[2], params[3], params[4], params[5], params[6],
1176 face);
1177 return;
1178 }
1179 }
1180 }
1181 } // open_cuboid_channel_3d
1182 else if (geom_type == "complex") {
1183
1184 /*
1185 std::cout << "vec_type = " << util::io::printStr(vec_type, 0)
1186 << ", vec_flag = " << util::io::printStr(vec_flag, 0)
1187 << "\n";
1188 */
1189
1190 num_params_needed = {0};
1191 std::vector<size_t> params_level(vec_type.size());
1192 for (size_t i = 0; i < vec_type.size(); i++) {
1193
1194 // only consider the biggest parameter set from the list
1195 auto nps = getNumParamsRequired(vec_type[i]);
1196 if (nps.size() > 0)
1197 params_level[i] = nps[nps.size() - 1];
1198 else {
1199 throw std::invalid_argument(
1201 << "Error: Geometry type = " << vec_type[i]
1202 << " has zero number of parameters required. \n");
1203 }
1204
1205 //std::cout << "Geom type = " << vec_type[i]
1206 // << ", params required = " << params_level[i] << "\n";
1207
1208 num_params_needed[0] += params_level[i];
1209 }
1210
1211 std::vector<std::shared_ptr<geom::GeomObject>> objs(vec_type.size());
1212 std::vector<std::string> obj_flags(vec_type.size());
1213
1214 if (params.size() == num_params_needed[0]) {
1215
1216 // loop over objects and create
1217 size_t param_start = 0;
1218 for (size_t i = 0; i < vec_type.size(); i++) {
1219
1220 auto geom_type_temp = vec_type[i];
1221 auto geom_flag_temp = vec_flag[i];
1222
1223 std::vector<std::string> vec_type_temp;
1224 std::vector<std::string> vec_flag_temp;
1225
1226 // find what range of parameters we need to provide
1227 std::vector<double> params_temp;
1228 for (size_t j=0; j<params_level[i]; j++)
1229 params_temp.push_back(params[j + param_start]);
1230
1231 // call this function recursively
1232 obj_flags[i] = vec_flag[i];
1234 geom_type_temp, params_temp, vec_type_temp, vec_flag_temp,
1235 objs[i], perform_check);
1236
1237 param_start += params_level[i];
1238 } // loop over objects
1239
1240 // now create a composite object
1241 obj = std::make_shared<geom::ComplexGeomObject>(objs, obj_flags);
1242
1243 return;
1244 } // if params.size() == n
1245 } // complex
1246 else {
1247 throw std::invalid_argument(
1249 << "Error: Invalid geometry type: " << geom_type << std::endl);
1250 }
1251
1252
1253 throw std::invalid_argument(
1255 << printErrMsg(geom_type, params, num_params_needed));
1256 }
std::string printErrMsg(const std::string &geom_type, const std::vector< double > &params, const std::vector< size_t > &num_params_needed)
void createGeomObject(const std::string &geom_type, const std::vector< double > &params, const std::vector< std::string > &vec_type, const std::vector< std::string > &vec_flag, std::shared_ptr< geom::GeomObject > &obj, bool perform_check)
std::vector< size_t > getNumParamsRequired(std::string geom_type)
Get num params required for creation of object.

References createGeomObject(), and getNumParamsRequired().

Referenced by inp::BCBaseDeck::BCBaseDeck(), anonymous_namespace{main.cpp}::buildInputJson(), anonymous_namespace{main.cpp}::buildInputJson(), anonymous_namespace{main.cpp}::buildInputJson(), geom::GeomData::copyGeometry(), geom::GeomData::copyGeometry(), createGeomObject(), createGeomObject(), createGeomObjectOld(), makeExampleGeomObject(), inp::BCBaseDeck::readFromJson(), inp::ParticleDeck::readParticleGeomFromJson(), and anonymous_namespace{testDeckRoundTrip.cpp}::testBCBaseDeck().

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

◆ createGeomObject() [2/2]

void geom::createGeomObject ( GeomData &  geomData,
bool  perform_check 
)

Definition at line 1258 of file geomObjectsUtil.cpp.

1259 {
1260
1261 createGeomObject(geomData.d_geomName, geomData.d_geomParams,
1262 geomData.d_geomComplexInfo.first,
1263 geomData.d_geomComplexInfo.second,
1264 geomData.d_geom_p, perform_check);
1265 }
std::shared_ptr< geom::GeomObject > d_geom_p
Zone geometry.
std::vector< double > d_geomParams
Zone parameters.
std::string d_geomName
Zone type.
std::pair< std::vector< std::string >, std::vector< std::string > > d_geomComplexInfo
Zone geometry info if it is a complex type.

References createGeomObject(), geom::GeomData::d_geom_p, geom::GeomData::d_geomComplexInfo, geom::GeomData::d_geomName, and geom::GeomData::d_geomParams.

Here is the call graph for this function:

◆ createGeomObjectOld()

void geom::createGeomObjectOld ( const std::string &  type,
const std::vector< double > &  params,
const std::vector< std::string > &  vec_type,
const std::vector< std::string > &  vec_flag,
std::shared_ptr< geom::GeomObject > &  obj,
bool  perform_check = true 
)

Create geometrical object from the given data.

Parameter ordering matches GeomData / getNumParamsRequired (see struct GeomData above).

Parameters
typeType of object
paramsVector of parameters
vec_typeSub-types of complex object
vec_flagFlags of sub-types of complex object
objPointer to object to which new object will be associated
perform_checkPerform check for sufficient parameters

std::cout << "creating complex object\n";

Definition at line 143 of file geomObjectsUtil.cpp.

148 {
149
150 // for any of the objects below, issue error if number of parameters not
151 // sufficient regardless of perform_check value
152 std::vector<std::string> no_default_obj = {"cylinder", "complex",
153 "rectangle_minus_rectangle",
154 "cuboid_minus_cuboid",
155 "circle_minus_circle",
156 "ellipse_minus_ellipse",
157 "sphere_minus_sphere",
158 "open_rect_channel_2d",
159 "open_cuboid_channel_3d"};
160
161 bool check_passed; // true means check passed
162 if (type != "complex")
163 check_passed = isNumberOfParamForGeometryValid(params.size(), type);
164 else
165 check_passed = isNumberOfParamForComplexGeometryValid(params.size(), type,
166 vec_type);
167
168 std::ostringstream oss;
169 if (!check_passed) {
170 oss << "Error: Data maybe invalid. Can not create geometrical object: "
171 << type << " with params: " << util::io::printStr(params)
172 << ", vec type: " << util::io::printStr(vec_type)
173 << ", vec flag: " << util::io::printStr(vec_flag) << std::endl;
174 }
175
176 // issue error
177 if (!check_passed) {
178 if (perform_check || util::methods::isTagInList(type, no_default_obj)) {
179 throw std::invalid_argument(
181 << oss.str());
182 }
183 }
184
185 // create object
186 if (type == "circle") {
187
188 if (check_passed) {
189 // if check is passed
190 obj = std::make_shared<geom::Circle>(
191 params[0], util::Point(params[1], params[2], params[3]));
192 } else {
193 // if check is failed check if we can use other constructor
194 if (params.size() < 1) {
195 // if params are not adequate
196 throw std::invalid_argument(
198 << "Error: need at least " << 1
199 << " parameters for creating circle. "
200 "Number of params provided = "
201 << params.size()
202 << ", params = "
203 << util::io::printStr(params) << " \n");
204 }
205
206 // reached here it means we have adequate parameters
207 obj = std::make_shared<geom::Circle>(params[0],
208 util::Point());
209 } // if else check_failed
210 } // if circle
211 else if (type == "rectangle") {
212
213 if (check_passed) {
214 // if check is passed
215 obj = std::make_shared<geom::Rectangle>(
216 params[0], params[1],
217 util::Point(params[2], params[3], params[4]));
218 } else {
219 // if check is failed check if we can use other constructor
220 if (params.size() != 6 or params.size() != 5) {
221 // if params are not adequate
222 throw std::invalid_argument(
224 << "Error: need either 5 or 6"
225 << " parameters for creating Rectangle. "
226 "Number of params provided = "
227 << params.size()
228 << ", params = "
229 << util::io::printStr(params) << " \n");
230 }
231
232 // reached here it means we have adequate parameters
233 if (params.size() == 6)
234 obj = std::make_shared<geom::Rectangle>(
235 util::Point(params[0], params[1], params[2]),
236 util::Point(params[3], params[4], params[5]));
237 else if (params.size() == 5)
238 obj = std::make_shared<geom::Rectangle>(
239 params[0], params[1],
240 util::Point(params[2], params[3], params[4]));
241 } // if else check_failed
242 } // if rectangle
243 else if (type == "square") {
244
245 if (check_passed) {
246 // if check is passed
247 obj = std::make_shared<geom::Square>(
248 params[0],
249 util::Point(params[2], params[3], params[4]));
250 } else {
251 // if check is failed check if we can use other constructor
252 if (params.size() != 6) {
253 // if params are not adequate
254 throw std::invalid_argument(
256 << "Error: need " << 6
257 << " parameters for creating Square. "
258 "Number of params provided = "
259 << params.size()
260 << ", params = "
261 << util::io::printStr(params) << " \n");
262 }
263
264 // reached here it means we have adequate parameters
265 obj = std::make_shared<geom::Square>(
266 util::Point(params[0], params[1], params[2]),
267 util::Point(params[3], params[4], params[5]));
268 } // if else check_failed
269 } // if square
270 else if (type == "triangle") {
271
272 if (check_passed) {
273 // if check is passed
274 obj = std::make_shared<geom::Triangle>(
275 params[0], util::Point(params[1], params[2], params[3]),
276 util::Point(params[4], params[5], params[6]));
277 } else {
278 // if check is failed check if we can use other constructor
279 if (params.size() != 4) {
280 // if params are not adequate
281 throw std::invalid_argument(
283 << "Error: need at least " << 4
284 << " parameters for creating triangle. "
285 "Number of params provided = "
286 << params.size()
287 << ", params = "
288 << util::io::printStr(params) << " \n");
289 }
290
291 // reached here it means we have adequate parameters
292 obj = std::make_shared<geom::Triangle>(
293 params[0], util::Point(params[1], params[2], params[3]));
294 }// if else check_failed
295 }// if triangle
296 else if (type == "hexagon") {
297
298 if (check_passed) {
299 // if check is passed
300 obj = std::make_shared<geom::Hexagon>(
301 params[0], util::Point(params[1], params[2], params[3]),
302 util::Point(params[4], params[5], params[6]));
303 } else {
304 // if check is failed check if we can use other constructor
305 if (params.size() != 4) {
306 // if params are not adequate
307 throw std::invalid_argument(
309 << "Error: need at least " << 4
310 << " parameters for creating hexagon. "
311 "Number of params provided = "
312 << params.size()
313 << ", params = "
314 << util::io::printStr(params) << " \n");
315 }
316
317 // reached here it means we have adequate parameters
318 obj = std::make_shared<geom::Hexagon>(
319 params[0], util::Point(params[1], params[2], params[3]));
320 }// if else check_failed
321 }// if hexagon
322 else if (type == "drum2d") {
323
324 if (check_passed) {
325 // if check is passed
326 obj = std::make_shared<geom::Drum2D>(
327 params[0], params[1],
328 util::Point(params[2], params[3], params[4]),
329 util::Point(params[5], params[6], params[7]));
330 } else {
331 // if check is failed check if we can use other constructor
332 if (params.size() < 5) {
333 // if params are not adequate
334 throw std::invalid_argument(
336 << "Error: need at least " << 5
337 << " parameters for creating drum2d. "
338 "Number of params provided = "
339 << params.size()
340 << ", params = "
341 << util::io::printStr(params) << " \n");
342 }
343
344 // reached here it means we have adequate parameters
345 obj = std::make_shared<geom::Drum2D>(
346 params[0], params[1],
347 util::Point(params[2], params[3], params[4]));
348 }// if else check_failed
349 }// if drum2d
350 else if (type == "sphere") {
351
352 if (check_passed) {
353 // if check is passed
354 obj = std::make_shared<geom::Sphere>(
355 params[0], util::Point(params[1], params[2], params[3]));
356 } else {
357 // if check is failed check if we can use other constructor
358 if (params.size() < 1) {
359 // if params are not adequate
360 throw std::invalid_argument(
362 << "Error: need at least " << 1
363 << " parameters for creating sphere. "
364 "Number of params provided = "
365 << params.size()
366 << ", params = "
367 << util::io::printStr(params) << " \n");
368 }
369
370 // reached here it means we have adequate parameters
371 obj = std::make_shared<geom::Sphere>(params[0],
372 util::Point());
373 }// if else check_failed
374 }// if sphere
375 else if (type == "ellipse") {
376
377 if (check_passed) {
378 obj = std::make_shared<geom::Ellipse>(
379 params[0], params[1], params[2],
380 util::Point(params[3], params[4], params[5]));
381 } else {
382 throw std::invalid_argument(
384 << "Error: need at least " << 6
385 << " parameters for creating ellipse (a, b, theta, cx, cy, cz). "
386 "Number of params provided = "
387 << params.size()
388 << ", params = "
389 << util::io::printStr(params) << " \n");
390 }
391 } // ellipse
392 else if (type == "ellipsoid") {
393
394 if (check_passed) {
395 if (params.size() == 6) {
396 obj = std::make_shared<geom::Ellipsoid>(
397 params[0], params[1], params[2],
398 util::Point(params[4], params[5], params[6]));
399 } else {
400 obj = std::make_shared<geom::Ellipsoid>(
401 params[0], params[1], params[2], params[3],
402 util::Point(params[4], params[5], params[6]),
403 util::Point(params[7], params[8], params[9]));
404 }
405 } else {
406 throw std::invalid_argument(
408 << "Error: need 6 parameters (cx, cy, cz, r1, r2, r3) or 10 parameters "
409 "(cx, cy, cz, r1, r2, r3, ax, ay, az, theta) for creating ellipsoid. "
410 "Number of params provided = "
411 << params.size()
412 << ", params = "
413 << util::io::printStr(params) << " \n");
414 }
415 } // ellipsoid
416 else if (type == "cuboid") {
417
418 if (check_passed) {
419 // if check is passed
420 obj = std::make_shared<geom::Cuboid>(
421 params[0], params[1], params[2],
422 util::Point(params[3], params[4], params[5]));
423 } else {
424 throw std::invalid_argument(
426 << "Error: need at least " << 6
427 << " parameters for creating cuboid. "
428 "Number of params provided = "
429 << params.size()
430 << ", params = "
431 << util::io::printStr(params) << " \n");
432 }// if else check_failed
433 }// if cuboid
434 else if (type == "cube") {
435
436 if (check_passed) {
437 // if check is passed
438 obj = std::make_shared<geom::Cube>(
439 params[0],
440 util::Point(params[2], params[3], params[4]));
441 } else {
442 // if check is failed check if we can use other constructor
443 if (params.size() < 6) {
444 // if params are not adequate
445 throw std::invalid_argument(
447 << "Error: need " << 6
448 << " parameters for creating Cube. "
449 "Number of params provided = "
450 << params.size()
451 << ", params = "
452 << util::io::printStr(params) << " \n");
453 }
454
455 // reached here it means we have adequate parameters
456 obj = std::make_shared<geom::Cube>(
457 util::Point(params[0], params[1], params[2]),
458 util::Point(params[3], params[4], params[5]));
459 } // if else check_failed
460 } // if cube
461 else if (type == "cylinder") {
462
463 if (check_passed) {
464 // Seven params: r, center of beginning cross-section, vector from beginning to end of cylinder
465 obj = std::make_shared<geom::Cylinder>(
466 params[0], util::Point(params[1], params[2], params[3]),
467 util::Point(params[4], params[5], params[6]));
468 } else {
469 throw std::invalid_argument(
471 << "Error: need at least " << 7
472 << " parameters for creating Cylinder. "
473 "Number of params provided = "
474 << params.size()
475 << ", params = "
476 << util::io::printStr(params) << " \n");
477 }// if else check_failed
478 }// if cylinder
479 else if (type == "rectangle_minus_rectangle") {
480
481 if (check_passed) {
482 // if check is passed
483 auto rin = new geom::Rectangle(
484 util::Point(params[0], params[1],
485 params[2]),
486 util::Point(params[3], params[4], params[5]));
487 auto rout = new geom::Rectangle(
488 util::Point(params[6], params[7],
489 params[8]),
490 util::Point(params[9], params[10],
491 params[11]));
492
493 obj = std::make_shared<geom::AnnulusGeomObject>
494 (rin, rout);
495 } else {
496 throw std::invalid_argument(
498 << "Error: need at least " << 12
499 << " parameters for creating rectangle_minus_rectangle. "
500 "Number of params provided = "
501 << params.size()
502 << ", params = "
503 << util::io::printStr(params) << " \n");
504 }// if else check_failed
505 }// if rectangle_minus_rectangle
506 else if (type == "cuboid_minus_cuboid") {
507
508 if (check_passed) {
509 // if check is passed
510 auto rin = new geom::Cuboid(
511 util::Point(params[0], params[1],
512 params[2]),
513 util::Point(params[3], params[4],
514 params[5]));
515 auto rout = new geom::Cuboid(
516 util::Point(params[6], params[7],
517 params[8]),
518 util::Point(params[9], params[10],
519 params[11]));
520
521 obj = std::make_shared<geom::AnnulusGeomObject>
522 (rin, rout);
523 } else {
524 throw std::invalid_argument(
526 << "Error: need at least " << 12
527 << " parameters for creating cuboid_minus_cuboid. "
528 "Number of params provided = "
529 << params.size()
530 << ", params = "
531 << util::io::printStr(params) << " \n");
532 }// if else check_failed
533 }// if cuboid_minus_cuboid
534 else if (type == "circle_minus_circle") {
535
536 if (check_passed) {
537 const double cx = params[0];
538 const double cy = params[1];
539 const double cz = params[2];
540 const double r_outer = params[3];
541 const double r_inner = params[4];
542 if (r_inner <= 0. || r_outer <= r_inner)
543 throw std::runtime_error(
544 "circle_minus_circle: require 0 < r_inner < r_outer (params: cx,cy,cz,r_outer,r_inner).");
545 auto *cin = new geom::Circle(r_inner, util::Point(cx, cy, cz));
546 auto *cout = new geom::Circle(r_outer, util::Point(cx, cy, cz));
547 obj = std::make_shared<geom::AnnulusGeomObject>(cin, cout);
548 } else {
549 throw std::invalid_argument(
551 << "Error: need " << 5
552 << " parameters for creating circle_minus_circle (cx, cy, cz, r_outer, r_inner). "
553 "Number of params provided = "
554 << params.size()
555 << ", params = "
556 << util::io::printStr(params) << " \n");
557 }
558 } // circle_minus_circle
559 else if (type == "ellipse_minus_ellipse") {
560
561 if (check_passed) {
562 // a_out, b_out, a_in, b_in, theta, cx, cy, cz (concentric, same θ)
563 const double a_out = params[0];
564 const double b_out = params[1];
565 const double a_in = params[2];
566 const double b_in = params[3];
567 const double theta = params[4];
568 const util::Point c(params[5], params[6], params[7]);
569 if (a_in <= 0. || b_in <= 0. || a_out <= a_in || b_out <= b_in)
570 throw std::runtime_error(
571 "ellipse_minus_ellipse: require 0 < a_in < a_out and 0 < b_in < b_out.");
572 auto *ein = new geom::Ellipse(a_in, b_in, theta, c);
573 auto *eout = new geom::Ellipse(a_out, b_out, theta, c);
574 obj = std::make_shared<geom::AnnulusGeomObject>(ein, eout);
575 } else {
576 throw std::invalid_argument(
578 << "Error: need " << 8
579 << " parameters for creating ellipse_minus_ellipse "
580 "(a_out, b_out, a_in, b_in, theta, cx, cy, cz). "
581 "Number of params provided = "
582 << params.size()
583 << ", params = "
584 << util::io::printStr(params) << " \n");
585 }
586 } // ellipse_minus_ellipse
587 else if (type == "sphere_minus_sphere") {
588
589 if (check_passed) {
590 const double cx = params[0];
591 const double cy = params[1];
592 const double cz = params[2];
593 const double r_outer = params[3];
594 const double r_inner = params[4];
595 if (r_inner <= 0. || r_outer <= r_inner)
596 throw std::runtime_error(
597 "sphere_minus_sphere: require 0 < r_inner < r_outer (params: cx,cy,cz,r_outer,r_inner).");
598 auto *cin = new geom::Sphere(r_inner, util::Point(cx, cy, cz));
599 auto *cout = new geom::Sphere(r_outer, util::Point(cx, cy, cz));
600 obj = std::make_shared<geom::AnnulusGeomObject>(cin, cout);
601 } else {
602 throw std::invalid_argument(
604 << "Error: need " << 5
605 << " parameters for creating sphere_minus_sphere (cx, cy, cz, r_outer, r_inner). "
606 "Number of params provided = "
607 << params.size()
608 << ", params = "
609 << util::io::printStr(params) << " \n");
610 }
611 } // sphere_minus_sphere
612 else if (type == "open_rect_channel_2d") {
613
614 if (check_passed) {
615 obj = std::make_shared<geom::OpenRectChannel2D>(
616 params[0], params[1], params[2], params[3], params[4], params[5]);
617 } else {
618 throw std::invalid_argument(
620 << "Error: need " << 6
621 << " parameters for open_rect_channel_2d (x0,y0,x1,y1,t,z). "
622 "Number of params provided = "
623 << params.size()
624 << ", params = "
625 << util::io::printStr(params) << " \n");
626 }
627 } // open_rect_channel_2d
628 else if (type == "open_cuboid_channel_3d") {
629
630 if (check_passed) {
631 obj = std::make_shared<geom::OpenCuboidChannel3D>(
632 params[0], params[1], params[2], params[3], params[4], params[5], params[6],
633 static_cast<int>(params[7]));
634 } else {
635 throw std::invalid_argument(
637 << "Error: need " << 8
638 << " parameters for open_cuboid_channel_3d "
639 "(x0,y0,z0,x1,y1,z1,t,open_face 0..5). "
640 "Number of params provided = "
641 << params.size()
642 << ", params = "
643 << util::io::printStr(params) << " \n");
644 }
645 } // open_cuboid_channel_3d
646 else if (type == "complex") {
647
648 if (check_passed) {
649 // if check is passed
650 std::vector<std::shared_ptr<geom::GeomObject>> vec_obj(
651 vec_type.size());
652
653 size_t param_start = 0;
654 for (size_t i = 0; i < vec_type.size(); i++) {
655 auto geom_type = vec_type[i];
656 auto geom_flag = vec_flag[i];
657 auto num_params = getNumParamsRequired(geom_type)[0];
658
659 // get slice of full param vector
660 auto p1 = params.begin() + param_start;
661 auto p2 = params.begin() + param_start + num_params;
662 auto geom_param = std::vector<double>(p1, p2);
663
664 // create geom object
665 createGeomObject(geom_type, geom_param, std::vector<std::string>(),
666 std::vector<std::string>(), vec_obj[i]);
667
668 param_start += num_params;
669 }
670
671 // create complex geom object
673 obj = std::make_shared<geom::ComplexGeomObject>(vec_obj,
674 vec_flag);
675 //obj->print();
676 } else {
677 throw std::invalid_argument(
679 << "Error: Not enough parameters for creating complex. "
680 "Number of params provided = "
681 << params.size()
682 << ", params = "
683 << util::io::printStr(params) << " \n");
684 }// if else check_failed
685 }// if complex
686 }
std::string str() const
The message built so far.
Definition io.h:67
std::string printStr(const T &msg, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:96
bool isTagInList(const std::string &tag, const std::vector< std::string > &tags)
Returns true if tag is found in the list of tags.
Definition vecMethods.h:284

References createGeomObject(), getNumParamsRequired(), isNumberOfParamForComplexGeometryValid(), isNumberOfParamForGeometryValid(), util::methods::isTagInList(), util::io::printStr(), and util::io::Msg::str().

Here is the call graph for this function:

◆ distanceBetweenLines()

double geom::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 404 of file geomUtilFunctions.cpp.

406 {
407
408 // let line 1 is l1(s) = p + s u
409 // and line 2 is l2(r) = q + r v
410 // and let normal to the plane containing line 1 and 2 is
411 // n = u x v / |u x v|
412
413 auto u = line_1.second - line_1.first;
414 auto v = line_2.second - line_2.first;
415 auto w0 = line_1.first - line_2.first;
416
417 double a = u * u;
418 double b = u * v;
419 double c = v * v;
420 double d = u * w0;
421 double e = v * w0;
422
423 auto dp = w0 + ((b * e - c * d) * u + (a * e - b * d) * v) / (a * c - b * b);
424
425 return dp.length();
426}

◆ distanceBetweenPlanes()

double geom::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 507 of file geomUtilFunctions.cpp.

509 {
510
511 // check if planes are parallel
512 if (util::angle(plane_1.first, plane_2.first) < 1.0E-8)
513 return 0.;
514
515 return std::abs(plane_1.first * (plane_1.second - plane_2.second)) /
516 plane_1.first.length();
517}
double angle(util::Point a, util::Point b)
Computes angle between two vectors.

References util::angle().

Here is the call graph for this function:

◆ distanceBetweenSegments()

double geom::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 429 of file geomUtilFunctions.cpp.

430 {
431
432 // let line 1 is l1(s) = p + s u
433 // and line 2 is l2(r) = q + r v
434 // and let normal to the plane containing line 1 and 2 is
435 // n = u x v / |u x v|
436
437 auto u = line_1.second - line_1.first;
438 auto v = line_2.second - line_2.first;
439 auto w0 = line_1.first - line_2.first;
440
441 double a = u * u;
442 double b = u * v;
443 double c = v * v;
444 double d = u * w0;
445 double e = v * w0;
446 double D = a * c - b * b;
447 double sc, sN, sD = D;
448 double tc, tN, tD = D;
449
450 // compute line parameters of two closest points
451 if (D < 1.0E-12) {
452
453 sN = 0.;
454 sD = 1.;
455 tN = e;
456 tD = c;
457 } else {
458
459 sN = b * e - c * d;
460 tN = a * e - b * d;
461
462 if (sN < 0.) {
463 sN = 0.;
464 tN = e;
465 tD = c;
466 } else if (sN > sD) {
467 sN = sD;
468 tN = e + b;
469 tD = c;
470 }
471 }
472
473 if (tN < 0.) {
474
475 tN = 0.;
476
477 if (-d < 0.)
478 sN = 0.;
479 else if (-d > a)
480 sN = sD;
481 else {
482 sN = -d;
483 sD = a;
484 }
485 } else if (tN > tD) {
486
487 tN = tD;
488
489 if (-d + b < 0.)
490 sN = 0.;
491 else if (-d + b > a)
492 sN = sD;
493 else {
494 sN = -d + b;
495 sD = a;
496 }
497 }
498
499 sc = std::abs(sN) < 1.0E-12 ? 0. : sN / sD;
500 tc = std::abs(tN) < 1.0E-12 ? 0. : tN / tD;
501
502 auto dp = w0 + sc * u - tc * v;
503
504 return dp.length();
505}

◆ doLinesIntersect()

bool geom::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 373 of file geomUtilFunctions.cpp.

374 {
375
376 // change of variable so that first point of line_1 is at origin
377 // After change of variables:
378 // a is the second point of line_1
379 // b is the first point of line_2
380 // c is the difference of second and first point of line_2
381 auto a = line_1.second - line_1.first;
382 auto b = line_2.first - line_1.first;
383 auto c = line_2.second - line_2.first;
384
385 // check if the two lines are parallel
386 if (util::angle(a / a.length(), c / c.length()) < 1.0E-8)
387 return false;
388
389 double a_dot_a = a.lengthSq();
390 double a_dot_b = a * b;
391 double a_dot_c = a * c;
392 double b_dot_c = b * c;
393 double c_dot_c = c.lengthSq();
394
395 double r = (a_dot_a * b_dot_c - a_dot_b * a_dot_c) /
396 (a_dot_c * a_dot_c - c_dot_c * a_dot_a);
397
398 // if r is in (0,1) then this gives the intersection point
399 // otherwise b + r c gives the point where two vectors originating from
400 // a and originating from b would intersect
401 return r > 0. and r < 1.;
402}

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

Here is the call graph for this function:

◆ ellipsoidRotationMatrix()

void geom::ellipsoidRotationMatrix ( const Ellipsoid &  e,
double  R[9] 
)

Row-major 3×3 rotation \(\mathbf R\) from ellipsoid axis–angle (identity if \(\theta=0\)).

Definition at line 689 of file geomUtilFunctions.cpp.

689 {
690
691 if (std::abs(e.d_theta) < 1.0e-15) {
692 R[0] = R[4] = R[8] = 1.;
693 R[1] = R[2] = R[3] = R[5] = R[6] = R[7] = 0.;
694 return;
695 }
696
697 const double kx = e.d_axis.d_x;
698 const double ky = e.d_axis.d_y;
699 const double kz = e.d_axis.d_z;
700 const double c = std::cos(e.d_theta);
701 const double s = std::sin(e.d_theta);
702 const double t = 1.0 - c;
703
704 R[0] = t * kx * kx + c;
705 R[1] = t * kx * ky - kz * s;
706 R[2] = t * kx * kz + ky * s;
707 R[3] = t * kx * ky + kz * s;
708 R[4] = t * ky * ky + c;
709 R[5] = t * ky * kz - kx * s;
710 R[6] = t * kx * kz - ky * s;
711 R[7] = t * ky * kz + kx * s;
712 R[8] = t * kz * kz + c;
713}
double d_theta
Rotation angle (radians) about d_axis.
util::Point d_axis
Unit rotation axis (axis–angle); default (0,0,1) when .
double d_y
the y coordinate
Definition point.h:36
double d_z
the z coordinate
Definition point.h:39
double d_x
the x coordinate
Definition point.h:33

References geom::Ellipsoid::d_axis, geom::Ellipsoid::d_theta, util::Point::d_x, util::Point::d_y, and util::Point::d_z.

Referenced by geom::Ellipsoid::box(), mesh_gen::buildEllipsoidOcc(), and geom::anonymous_namespace{geomObjects.cpp}::ellipsoidBodyCoords().

Here is the caller graph for this function:

◆ exampleGeomParams()

std::vector< double > geom::exampleGeomParams ( const std::string &  geom_type,
const util::Point &  c = util::Point(0., 0., 0.),
double  s = 0.001 
)

Canonical parameter vector for examples, mesh generation tests, and demos.

Convention matches twop_general_inbuilt: reference center c and length scale s (typical outer half-width). Names must be from getAcceptableGeometries().

Definition at line 1267 of file geomObjectsUtil.cpp.

1268 {
1269 if (geom_type == "circle")
1270 return {s, c.d_x, c.d_y, c.d_z};
1271 if (geom_type == "plane")
1272 return {0., 1., 0., c.d_x, c.d_y, c.d_z};
1273 if (geom_type == "square")
1274 return {c.d_x - s, c.d_y - s, c.d_z, c.d_x + s, c.d_y + s, c.d_z};
1275 if (geom_type == "rectangle")
1276 return {c.d_x - 1.2 * s, c.d_y - 0.8 * s, c.d_z, c.d_x + 1.2 * s, c.d_y + 0.8 * s, c.d_z};
1277 if (geom_type == "triangle")
1278 return {s, c.d_x, c.d_y, c.d_z, 1.0, 0.0, 0.0};
1279 if (geom_type == "hexagon")
1280 return {s, c.d_x, c.d_y, c.d_z, 1.0, 0.0, 0.0};
1281 if (geom_type == "drum2d") {
1282 const double r = 1.2 * s;
1283 const double w = 0.35 * s;
1284 return {r, w, c.d_x, c.d_y, c.d_z, 1.0, 0.0, 0.0};
1285 }
1286 if (geom_type == "sphere")
1287 return {s, c.d_x, c.d_y, c.d_z};
1288 if (geom_type == "cube")
1289 return {2.0 * s, c.d_x, c.d_y, c.d_z};
1290 if (geom_type == "cuboid")
1291 return {c.d_x - s, c.d_y - 0.75 * s, c.d_z - 0.6 * s, c.d_x + s, c.d_y + 0.75 * s,
1292 c.d_z + 0.6 * s};
1293 if (geom_type == "cylinder")
1294 return {0.5 * s, c.d_x, c.d_y - s, c.d_z, 0., 2. * s, 0.};
1295 if (geom_type == "ellipse")
1296 return {1.2 * s, 0.85 * s, 0.25, c.d_x, c.d_y, c.d_z};
1297 if (geom_type == "ellipsoid")
1298 return {2. * s, 1. * s, 1.5 * s, c.d_x, c.d_y, c.d_z};
1299 if (geom_type == "circle_minus_circle")
1300 return {c.d_x, c.d_y, c.d_z, s, 0.35 * s};
1301 if (geom_type == "ellipse_minus_ellipse")
1302 return {1.2 * s, 0.85 * s, 0.7 * s, 0.5 * s, 0.25, c.d_x, c.d_y, c.d_z};
1303 if (geom_type == "sphere_minus_sphere")
1304 return {c.d_x, c.d_y, c.d_z, s, 0.35 * s};
1305 if (geom_type == "rectangle_minus_rectangle") {
1306 const double ri = 0.35 * s;
1307 const double lo_ix = c.d_x - ri, lo_iy = c.d_y - ri, lo_iz = c.d_z;
1308 const double hi_ix = c.d_x + ri, hi_iy = c.d_y + ri, hi_iz = c.d_z;
1309 const double lo_ox = c.d_x - s, lo_oy = c.d_y - s, lo_oz = c.d_z;
1310 const double hi_ox = c.d_x + s, hi_oy = c.d_y + s, hi_oz = c.d_z;
1311 return {lo_ix, lo_iy, lo_iz, hi_ix, hi_iy, hi_iz, lo_ox, lo_oy, lo_oz, hi_ox, hi_oy, hi_oz};
1312 }
1313 if (geom_type == "cuboid_minus_cuboid") {
1314 const double sx = s, sy = 0.75 * s, sz = 0.6 * s;
1315 const double f = 0.35;
1316 const double lo_ix = c.d_x - f * sx, lo_iy = c.d_y - f * sy, lo_iz = c.d_z - f * sz;
1317 const double hi_ix = c.d_x + f * sx, hi_iy = c.d_y + f * sy, hi_iz = c.d_z + f * sz;
1318 const double lo_ox = c.d_x - sx, lo_oy = c.d_y - sy, lo_oz = c.d_z - sz;
1319 const double hi_ox = c.d_x + sx, hi_oy = c.d_y + sy, hi_oz = c.d_z + sz;
1320 return {lo_ix, lo_iy, lo_iz, hi_ix, hi_iy, hi_iz, lo_ox, lo_oy, lo_oz, hi_ox, hi_oy, hi_oz};
1321 }
1322 if (geom_type == "open_rect_channel_2d") {
1323 const double wall_t = 0.35 * s;
1324 return {c.d_x - s, c.d_y - s, c.d_x + s, c.d_y + s, wall_t, c.d_z};
1325 }
1326 if (geom_type == "open_cuboid_channel_3d") {
1327 const double wall_t = 0.35 * s;
1328 const double open_face = 4.; // +z (matches 2D “open up”)
1329 return {c.d_x - s, c.d_y - s, c.d_z - s, c.d_x + s, c.d_y + s, c.d_z + s, wall_t, open_face};
1330 }
1331 throw std::runtime_error("exampleGeomParams: unknown geometry \"" + geom_type + "\"");
1332 }

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

Referenced by anonymous_namespace{main.cpp}::buildInputJson(), and makeExampleGeomObject().

Here is the caller graph for this function:

◆ getAcceptableGeometries()

const std::vector< std::string > & geom::getAcceptableGeometries ( )
inline

Returns list of acceptable geometries for PeriDEM simulation.

Definition at line 151 of file geomObjectsUtil.h.

151 {
153};
const std::vector< std::string > acceptable_geometries
List of acceptable geometries for particles in PeriDEM.

References acceptable_geometries.

Referenced by mesh_gen::generateBuiltinParticleMeshGmsh(), anonymous_namespace{main.cpp}::isAcceptableGeometryName(), main(), and main().

Here is the caller graph for this function:

◆ getCenter()

util::Point geom::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 105 of file geomUtilFunctions.cpp.

106 {
107
108 if (dim == 1)
109 return {0.5 * box.second.d_x + 0.5 * box.first.d_x, 0., 0.};
110 else if (dim == 2)
111 return {0.5 * box.second.d_x + 0.5 * box.first.d_x,
112 0.5 * box.second.d_y + 0.5 * box.first.d_y, 0.};
113 else if (dim == 3)
114 return {0.5 * box.second.d_x + 0.5 * box.first.d_x,
115 0.5 * box.second.d_y + 0.5 * box.first.d_y,
116 0.5 * box.second.d_z + 0.5 * box.first.d_z};
117 else {
118 throw std::invalid_argument(
120 << "Error: Check dimension = " << dim << ".\n");
121 }
122}

References util::Point::d_x.

Referenced by areBoxesNear(), circumscribedRadiusInBox(), geom::Circle::isNear(), geom::Ellipse::isNear(), geom::Sphere::isNear(), and test::testUtilMethods().

Here is the caller graph for this function:

◆ getCornerPoints()

std::vector< util::Point > geom::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 26 of file geomUtilFunctions.cpp.

27 {
28
29 if (dim == 1)
30 return {box.first, box.second};
31 else if (dim == 2)
32 return {box.first,
33 util::Point(box.second.d_x, box.first.d_y, 0.),
34 box.second,
35 util::Point(box.first.d_x, box.second.d_y, 0.)};
36 else if (dim == 3) {
37 double a = box.second.d_x - box.first.d_x;
38 double b = box.second.d_y - box.first.d_y;
39 double c = box.second.d_z - box.first.d_z;
40 return {box.first,
41 box.first + util::Point(a, 0., 0.),
42 box.first + util::Point(a, b, 0.),
43 box.first + util::Point(0., b, 0.),
44 box.first + util::Point(0., 0., c),
45 box.first + util::Point(a, 0., c),
46 box.first + util::Point(a, b, c),
47 box.first + util::Point(0., b, c)};
48 }
49 else {
50 throw std::invalid_argument(
52 << "Error: Check dimension = " << dim << ".\n");
53 }
54}

References util::Point::d_x.

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

◆ getEdges()

std::vector< std::pair< util::Point, util::Point > > geom::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 56 of file geomUtilFunctions.cpp.

57 {
58
59 std::vector<std::pair<util::Point, util::Point>> data;
60 if (dim == 1) {
61 data.emplace_back(box);
62 return data;
63 } else if (dim == 2) {
64
65 // points returned by below function is in anti-clockwise order
66 auto corner_pts = getCornerPoints(dim, box);
67
68 data.emplace_back(corner_pts[0], corner_pts[1]);
69 data.emplace_back(corner_pts[1], corner_pts[2]);
70 data.emplace_back(corner_pts[2], corner_pts[3]);
71 data.emplace_back(corner_pts[3], corner_pts[0]);
72 return data;
73 } else if (dim == 3) {
74
75 // points returned by below function is in anti-clockwise order
76 // first 4 points are on lower z-plane, and remaining are in upper z-plane
77 auto corner_pts = getCornerPoints(dim, box);
78
79 // edges in lower plane
80 data.emplace_back(corner_pts[0], corner_pts[1]);
81 data.emplace_back(corner_pts[1], corner_pts[2]);
82 data.emplace_back(corner_pts[2], corner_pts[3]);
83 data.emplace_back(corner_pts[3], corner_pts[0]);
84
85 // edges in upper plane
86 data.emplace_back(corner_pts[4], corner_pts[5]);
87 data.emplace_back(corner_pts[5], corner_pts[6]);
88 data.emplace_back(corner_pts[6], corner_pts[7]);
89 data.emplace_back(corner_pts[7], corner_pts[4]);
90
91 // edges parrallel to z-axis
92 data.emplace_back(corner_pts[0], corner_pts[4]);
93 data.emplace_back(corner_pts[1], corner_pts[5]);
94 data.emplace_back(corner_pts[2], corner_pts[6]);
95 data.emplace_back(corner_pts[3], corner_pts[7]);
96
97 return data;
98 } else {
99 throw std::invalid_argument(
101 << "getEdges(): Function implemented for dim = 1,2,3 only.\n");
102 }
103}
Definition contact.h:20

References getCornerPoints().

Referenced by test::testUtilMethods().

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

◆ getGeomTypeToDim()

size_t geom::getGeomTypeToDim ( std::string  type)
inline

Returns list of acceptable geometries for PeriDEM simulation.

Definition at line 47 of file geomObjects.h.

47 {
48 return geom_type_to_dim.at(type);
49 };
const std::map< std::string, size_t > geom_type_to_dim
Geometry type to dimension map.
Definition geomObjects.h:27

References geom_type_to_dim.

Referenced by geom::AnnulusGeomObject::AnnulusGeomObject(), geom::ComplexGeomObject::ComplexGeomObject(), and anonymous_namespace{testMeshGen.cpp}::meshDimForBuiltin().

Here is the caller graph for this function:

◆ getNumParamsRequired()

std::vector< size_t > geom::getNumParamsRequired ( std::string  geom_type)

Get num params required for creation of object.

Parameters
geom_typeGeometry type of object
Returns
n Number of parameters required

Definition at line 47 of file geomObjectsUtil.cpp.

47 {
48
49 if (geom_type == "line")
50 return {1, 4, 6};
51 else if (geom_type == "plane")
52 return {6};
53 else if (geom_type == "triangle")
54 return {1, 4, 7, 9};
55 else if (geom_type == "square")
56 return {1, 4, 6};
57 else if (geom_type == "rectangle")
58 return {2, 5, 6};
59 else if (geom_type == "hexagon")
60 return {1, 4, 7};
61 else if (geom_type == "drum2d")
62 return {2, 5, 8};
63 else if (geom_type == "cube")
64 return {1, 4, 6};
65 else if (geom_type == "cuboid")
66 return {3, 6};
67 else if (geom_type == "circle")
68 return {1, 4};
69 else if (geom_type == "sphere")
70 return {1, 4};
71 else if (geom_type == "ellipse")
72 return {6};
73 else if (geom_type == "ellipsoid")
74 return {6, 10};
75 else if (geom_type == "cylinder")
76 return {7, 8};
77 else if (geom_type == "angled_rectangle")
78 return {6};
79 else if (geom_type == "angled_cuboid")
80 return {6};
81 else if (geom_type == "rectangle_minus_rectangle")
82 return {12};
83 else if (geom_type == "cuboid_minus_cuboid")
84 return {12};
85 else if (geom_type == "circle_minus_circle")
86 return {5};
87 else if (geom_type == "ellipse_minus_ellipse")
88 return {8};
89 else if (geom_type == "sphere_minus_sphere")
90 return {5};
91 else if (geom_type == "open_rect_channel_2d")
92 return {6};
93 else if (geom_type == "open_cuboid_channel_3d")
94 return {8};
95 else {
96 throw std::invalid_argument(
98 << "Error: Invalid geometry type: " << geom_type << std::endl);
99 }
100 }

Referenced by createGeomObject(), createGeomObjectOld(), isNumberOfParamForComplexGeometryValid(), and isNumberOfParamForGeometryValid().

Here is the caller graph for this function:

◆ getPointOnLine()

util::Point geom::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 367 of file geomUtilFunctions.cpp.

369 {
370 return (1. - s) * p1 + s * p2;
371}

◆ inscribedRadiusInBox()

double geom::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 199 of file geomUtilFunctions.cpp.

200 {
201
202 double r = 0.5 * std::abs(box.second.d_x - box.first.d_x);
203 if (dim == 1)
204 return r;
205 else if (dim == 2) {
206 if (util::isGreater(r, 0.5 * std::abs(box.second.d_y - box.first.d_y)))
207 return 0.5 * std::abs(box.second.d_y - box.first.d_y);
208 else
209 return r;
210 } else if (dim == 3) {
211 if (util::isGreater(r, 0.5 * std::abs(box.second.d_y - box.first.d_y)))
212 r = 0.5 * std::abs(box.second.d_y - box.first.d_y);
213
214 if (util::isGreater(r, 0.5 * std::abs(box.second.d_z - box.first.d_z)))
215 return 0.5 * std::abs(box.second.d_z - box.first.d_z);
216 else
217 return r;
218 } else {
219 throw std::invalid_argument(
221 << "inscribedRadiusInBox(): Function implemented for dim = 1,2,3 only.\n");
222 }
223}

References util::isGreater().

Referenced by areBoxesNear(), geom::Circle::isNear(), geom::Ellipse::isNear(), and geom::Sphere::isNear().

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

◆ isNumberOfParamForComplexGeometryValid()

bool geom::isNumberOfParamForComplexGeometryValid ( size_t  n,
std::string  geom_type,
std::vector< std::string >  vec_type 
)

Ascertain if number of parameters are correct for the given geometry.

Parameters
nNumber of parameters available
geom_typeGeometry type of object
vec_typeFor complex objects, specify types of sub-objects
Returns
bool True if number of parameter is correct

Definition at line 108 of file geomObjectsUtil.cpp.

110 {
111
112 int num_params = 0;
113 for (const auto &s: vec_type) {
114 // only consider the biggest parameter set from the list
115 auto nps = getNumParamsRequired(s);
116 if (nps.size() > 0)
117 num_params += nps[nps.size() - 1];
118 else {
119 throw std::invalid_argument(
121 << "Error: Geometry type = " << s
122 << " has zero number of parameters required. \n");
123 }
124 }
125 return n == num_params;
126 }

References getNumParamsRequired().

Referenced by checkParamForComplexGeometry(), and createGeomObjectOld().

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

◆ isNumberOfParamForGeometryValid()

bool geom::isNumberOfParamForGeometryValid ( size_t  n,
std::string  geom_type 
)

Ascertain if number of parameters are correct for the given geometry.

Parameters
nNumber of parameters available
geom_typeGeometry type of object
Returns
bool True if number of parameter is correct

Definition at line 103 of file geomObjectsUtil.cpp.

103 {
104
105 return util::methods::isInList(n, getNumParamsRequired(geom_type));
106 }
bool isInList(const T &i, const std::vector< T > &list)
Find if data is in the list.
Definition vecMethods.h:270

References getNumParamsRequired(), and util::methods::isInList().

Referenced by checkParamForGeometry(), and createGeomObjectOld().

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

◆ isPointInsideAngledRectangle()

bool geom::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 266 of file geomUtilFunctions.cpp.

268 {
269 // we assume that the rectangle has passed the test
270
271 //
272 // (x2,y2)
273 // o
274 //
275 //
276 //
277 //
278 //
279 // o
280 // (x1,y1)
281
282 // get divisors
284 util::Point(x2 - x1, y2 - y1, 0.0), theta);
285
286 // double lam1 = (x2-x1) * std::cos(theta) + (y2-y1) * std::sin(theta);
287 // double lam2 = -(x2-x1) * std::sin(theta) + (y2-y1) * std::cos(theta);
288
289 // get mapped coordinate of x
291 util::Point(x[0] - x1, x[1] - y1, 0.0), theta);
292
293 // double xmap = (x[0]-x1) * std::cos(theta) + (x[1]-y1) * std::sin(theta);
294 // double ymap = -(x[0]-x1) * std::sin(theta) + (x[1]-y1) * std::cos(theta);
295
296 // check if mapped coordinate are out of range [0, lam1] and [0, lam2]
297 return !(util::isLess(xmap[0], -1.0E-12) or
298 util::isLess(xmap[1], -1.0E-12) or
299 util::isGreater(xmap[0], lam[0] + 1.0E-12) or
300 util::isGreater(xmap[1], lam[1] + 1.0E-12));
301}
Collection of methods useful in simulation.
Definition constants.h:14
std::vector< double > rotateCW2D(const std::vector< double > &x, const double &theta)
Rotates a vector in xy-plane in clockwise direction.

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

Here is the call graph for this function:

◆ isPointInsideBox()

bool geom::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 174 of file geomUtilFunctions.cpp.

175 {
176
177 if (dim == 1)
178 return !(util::isLess(x.d_x, box.first.d_x - 1.0E-12) or
179 util::isGreater(x.d_x, box.second.d_x + 1.0E-12));
180 else if (dim == 2)
181 return !(util::isLess(x.d_x, box.first.d_x - 1.0E-12) or
182 util::isLess(x.d_y, box.first.d_y - 1.0E-12) or
183 util::isGreater(x.d_x, box.second.d_x + 1.0E-12) or
184 util::isGreater(x.d_y, box.second.d_y + 1.0E-12));
185 else if (dim == 3)
186 return !(util::isLess(x.d_x, box.first.d_x - 1.0E-12) or
187 util::isLess(x.d_y, box.first.d_y - 1.0E-12) or
188 util::isLess(x.d_z, box.first.d_z - 1.0E-12) or
189 util::isGreater(x.d_x, box.second.d_x + 1.0E-12) or
190 util::isGreater(x.d_y, box.second.d_y + 1.0E-12) or
191 util::isGreater(x.d_z, box.second.d_z + 1.0E-12));
192 else {
193 throw std::invalid_argument(
195 << "isPointInsideBox(): Function implemented for dim = 1,2,3 only.\n");
196 }
197}

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

Referenced by areBoxesNear(), geom::Triangle::isNear(), geom::Square::isNear(), geom::Rectangle::isNear(), geom::Hexagon::isNear(), geom::Drum2D::isNear(), geom::Cube::isNear(), geom::Cuboid::isNear(), geom::OpenCuboidChannel3D::isNear(), and geom::OpenRectChannel2D::isNear().

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

◆ isPointInsideCuboid()

bool geom::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 303 of file geomUtilFunctions.cpp.

304 {
305 return !(util::isLess(x.d_x, x_lbb.d_x - 1.0E-12) or
306 util::isLess(x.d_y, x_lbb.d_y - 1.0E-12) or
307 util::isLess(x.d_z, x_lbb.d_z - 1.0E-12) or
308 util::isGreater(x.d_x, x_rtf.d_x + 1.0E-12) or
309 util::isGreater(x.d_y, x_rtf.d_y + 1.0E-12) or
310 util::isGreater(x.d_z, x_rtf.d_z + 1.0E-12));
311}

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

Referenced by geom::Cube::isInside(), and geom::Cuboid::isInside().

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

◆ isPointInsideCylinder() [1/2]

bool geom::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 313 of file geomUtilFunctions.cpp.

314 {
315
316 double p_dot_a = p * axis;
317 if (p_dot_a > length or p_dot_a < 0.)
318 return false;
319 else {
320
321 auto p_parallel = p - p_dot_a * axis;
322
323 return p_parallel.lengthSq() < radius * radius;
324 }
325}
double lengthSq() const
Computes the Euclidean length of the vector.
Definition point.h:130

References util::Point::lengthSq().

Here is the call graph for this function:

◆ isPointInsideCylinder() [2/2]

bool geom::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 327 of file geomUtilFunctions.cpp.

328 {
329
330 auto p_new = p - x1;
331 auto a = x2 - x1;
332 double p_dot_a = p_new * a;
333
334 // note here we should 1 if a is not normalized
335 if (p_dot_a > 1. or p_dot_a < 0.)
336 return false;
337 else {
338
339 auto p_parallel = p_new - p_dot_a * a;
340
341 return p_parallel.lengthSq() < radius * radius;
342 }
343}

References util::Point::lengthSq().

Here is the call graph for this function:

◆ isPointInsideEllipse() [1/2]

bool geom::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 345 of file geomUtilFunctions.cpp.

346 {
347
348 double d = 0.;
349 auto x = p - center;
350 for (unsigned int i=0; i<dim; i++)
351 d += x[i] * x[i] / (radius_vec[i] * radius_vec[i]);
352
353 return d < 1.;
354}

◆ isPointInsideEllipse() [2/2]

bool geom::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 356 of file geomUtilFunctions.cpp.

357 {
358
359 d = 0.;
360 auto x = p - center;
361 for (unsigned int i=0; i<dim; i++)
362 d += x[i] * x[i] / (radius_vec[i] * radius_vec[i]);
363
364 return d < 1.;
365}

◆ isPointInsideRectangle() [1/2]

bool geom::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 248 of file geomUtilFunctions.cpp.

250 {
251
252 return !(util::isLess(x.d_x, x_min - 1.0E-12) or
253 util::isLess(x.d_y, y_min - 1.0E-12) or
254 util::isGreater(x.d_x, x_max + 1.0E-12) or
255 util::isGreater(x.d_y, y_max + 1.0E-12));
256}

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

Referenced by geom::Square::isInside(), and geom::Rectangle::isInside().

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

◆ isPointInsideRectangle() [2/2]

bool geom::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 258 of file geomUtilFunctions.cpp.

259 {
260 return !(util::isLess(x.d_x, x_lb.d_x - 1.0E-12) or
261 util::isLess(x.d_y, x_lb.d_y - 1.0E-12) or
262 util::isGreater(x.d_x, x_rt.d_x + 1.0E-12) or
263 util::isGreater(x.d_y, x_rt.d_y + 1.0E-12));
264}

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

Here is the call graph for this function:

◆ makeExampleGeomObject()

std::shared_ptr< GeomObject > geom::makeExampleGeomObject ( const std::string &  geom_type,
const util::Point &  c,
double  s 
)

One-liner: createGeomObject(exampleGeomParams(...)). Prefer this over per-class static factories so annulus and composite types stay in one place.

Definition at line 1334 of file geomObjectsUtil.cpp.

1335 {
1336 std::shared_ptr<GeomObject> obj;
1337 createGeomObject(geom_type, exampleGeomParams(geom_type, c, s), {}, {}, obj, false);
1338 return obj;
1339 }
std::vector< double > exampleGeomParams(const std::string &geom_type, const util::Point &c, double s)
Canonical parameter vector for examples, mesh generation tests, and demos.

References createGeomObject(), and exampleGeomParams().

Referenced by anonymous_namespace{testMeshGen.cpp}::builtinMeshCheckForGeometry().

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

◆ mapSimilarity()

util::Point geom::mapSimilarity ( const util::Point &  x,
const util::Point &  pivotDefault,
const util::Point &  t,
double  scale,
double  angle,
const util::Point &  axis,
const util::Point *  rotationPoint 
)
inline

Rigid similarity then displacement: \(\mathbf y = \mathbf p + s\,\mathbf R(\mathbf x-\mathbf p) + \mathbf t\). Pivot \(\mathbf p\) is rotationPoint if non-null, else pivotDefault (typically old center).

Definition at line 55 of file geomObjects.h.

57 {
58 const util::Point &p = (rotationPoint != nullptr) ? *rotationPoint : pivotDefault;
59 return p + util::rotate(x - p, angle, axis) * scale + t;
60 }
util::Point rotate(const util::Point &p, const double &theta, const util::Point &axis)
Returns the vector after rotating by desired angle.

References util::rotate().

Referenced by geom::Plane::transform(), geom::Line::transform(), geom::Triangle::transform(), geom::Square::transform(), geom::Rectangle::transform(), geom::Hexagon::transform(), geom::Drum2D::transform(), geom::Cube::transform(), geom::Cuboid::transform(), geom::Circle::transform(), geom::Ellipse::transform(), geom::Sphere::transform(), geom::Ellipsoid::transform(), geom::Cylinder::transform(), and geom::OpenCuboidChannel3D::transform().

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

◆ pointDistanceLine()

double geom::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 519 of file geomUtilFunctions.cpp.

520 {
521
522 // line vector
523 auto v = line.second - line.first;
524
525 // vector from 1st point of line to p
526 auto w = p - line.first;
527
528 // project w onto v and add 1st point to get projected point's location
529 auto w_on_line = line.first + (w * v) * v / v.lengthSq();
530
531 return (p - w_on_line).length();
532}

References util::Point::lengthSq().

Here is the call graph for this function:

◆ pointDistancePlane()

double geom::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 557 of file geomUtilFunctions.cpp.

558 {
559
560 // if plane is given by unit normal n and a point a which is contained in it
561 // then the distance of point p from plane is
562 // |(p - a) dot n| / |n|
563
564 auto pa = p - plane.second;
565 return std::abs(pa * plane.first) / plane.first.length();
566}
double length() const
Computes the Euclidean length of the vector.
Definition point.h:124

References util::Point::length().

Here is the call graph for this function:

◆ pointDistanceSegment()

double geom::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 534 of file geomUtilFunctions.cpp.

535 {
536
537 // line vector
538 auto v = line.second - line.first;
539
540 // vector from 1st point of line to p
541 auto w = p - line.first;
542
543 // determine if w is on left side or right side of line
544 double w_dot_v = w * v;
545 if (w_dot_v < 1.0E-12)
546 return (p - line.first).length();
547
548 if (w_dot_v > v.lengthSq() - 1.0E-12)
549 return (p - line.second).length();
550
551 // project w onto v and add 1st point to get projected point's location
552 auto w_on_line = line.first + w_dot_v * v / v.lengthSq();
553
554 return (p - w_on_line).length();
555}

References util::Point::length().

Here is the call graph for this function:

◆ readGeometry()

void geom::readGeometry ( const json &  j,
geom::GeomData &  geomData 
)

Definition at line 1400 of file geomObjectsUtil.cpp.

1400 {
1401
1402 if (j.find("Type") == j.end()) {
1403 throw std::invalid_argument(
1405 << "Error: Geometry type not found in json file.\n");
1406 }
1407 geomData.d_geomName = j.at("Type");
1408
1409 if (geomData.d_geomName == "complex") {
1410 if ((j.find("Vec_type") == j.end()) or (j.find("Vec_flag") == j.end())) {
1411 throw std::invalid_argument(
1413 << "Error: Geometry type and/or flag not found in json file.\n");
1414 }
1415 geomData.d_geomComplexInfo.first = j.at("Vec_type").get<std::vector<std::string>>();
1416 geomData.d_geomComplexInfo.second = j.at("Vec_flag").get<std::vector<std::string>>();
1417 }
1418
1419 if (j.find("Parameters") == j.end()) {
1420 throw std::invalid_argument(
1422 << "Error: Geometry parameters not found in json file.\n");
1423 }
1424
1425 for (auto a: j.at("Parameters"))
1426 geomData.d_geomParams.push_back(a);
1427 }

References geom::GeomData::d_geomComplexInfo, geom::GeomData::d_geomName, and geom::GeomData::d_geomParams.

Referenced by inp::BCBaseDeck::readFromJson(), and inp::ParticleDeck::readParticleGeomFromJson().

Here is the caller graph for this function:

◆ toPointBox()

std::pair< util::Point, util::Point > geom::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 651 of file geomUtilFunctions.cpp.

653 {
654 auto q1 = util::Point(p1[0], p1[1], p1[2]);
655 auto q2 = util::Point(p2[0], p2[1], p2[2]);
656 return {q1, q2};
657}

◆ triangleArea()

double geom::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 659 of file geomUtilFunctions.cpp.

660 {
661 return 0.5 * ((x2.d_x - x1.d_x) * (x3.d_y - x1.d_y) -
662 (x3.d_x - x1.d_x) * (x2.d_y - x1.d_y));
663}

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

Referenced by geom::Triangle::isInside(), geom::Triangle::isNearBoundary(), test::testUtilMethods(), and geom::Triangle::volume().

Here is the caller graph for this function:

◆ writeGeometry()

void geom::writeGeometry ( json &  j,
const geom::GeomData &  geomData 
)

Definition at line 1389 of file geomObjectsUtil.cpp.

1389 {
1390 j["Type"] = geomData.d_geomName;
1391
1392 if (geomData.d_geomName == "complex") {
1393 j["Vec_type"] = geomData.d_geomComplexInfo.first;
1394 j["Vec_flag"] = geomData.d_geomComplexInfo.second;
1395 }
1396
1397 j["Parameters"] = geomData.d_geomParams;
1398 }

References geom::GeomData::d_geomComplexInfo, geom::GeomData::d_geomName, and geom::GeomData::d_geomParams.

Referenced by anonymous_namespace{main.cpp}::buildInputJson(), inp::BCBaseDeck::getExampleJson(), and inp::ParticleDeck::getParticleGeomExampleJson().

Here is the caller graph for this function:

Variable Documentation

◆ acceptable_geometries

const std::vector<std::string> geom::acceptable_geometries
Initial value:
= {"circle",
"ellipse",
"square",
"rectangle",
"hexagon",
"triangle",
"drum2d",
"sphere",
"ellipsoid",
"cube",
"cuboid",
"cylinder",
"circle_minus_circle",
"ellipse_minus_ellipse",
"sphere_minus_sphere",
"rectangle_minus_rectangle",
"cuboid_minus_cuboid",
"open_rect_channel_2d",
"open_cuboid_channel_3d",
"complex"}

List of acceptable geometries for particles in PeriDEM.

Definition at line 127 of file geomObjectsUtil.h.

127 {"circle",
128 "ellipse",
129 "square",
130 "rectangle",
131 "hexagon",
132 "triangle",
133 "drum2d",
134 "sphere",
135 "ellipsoid",
136 "cube",
137 "cuboid",
138 "cylinder",
139 "circle_minus_circle",
140 "ellipse_minus_ellipse",
141 "sphere_minus_sphere",
142 "rectangle_minus_rectangle",
143 "cuboid_minus_cuboid",
144 "open_rect_channel_2d",
145 "open_cuboid_channel_3d",
146 "complex"};

Referenced by getAcceptableGeometries().

◆ geom_type_to_dim

const std::map<std::string, size_t> geom::geom_type_to_dim
Initial value:
= {
{"circle", 2},
{"ellipse", 2},
{"square", 2},
{"rectangle", 2},
{"hexagon", 2},
{"triangle", 2},
{"drum2d", 2},
{"sphere", 3},
{"ellipsoid", 3},
{"cube", 3},
{"cuboid", 3},
{"cylinder", 3},
{"open_rect_channel_2d", 2},
{"open_cuboid_channel_3d", 3},
{"plane", 3},
{"line", 1}
}

Geometry type to dimension map.

Definition at line 27 of file geomObjects.h.

27 {
28 {"circle", 2},
29 {"ellipse", 2},
30 {"square", 2},
31 {"rectangle", 2},
32 {"hexagon", 2},
33 {"triangle", 2},
34 {"drum2d", 2},
35 {"sphere", 3},
36 {"ellipsoid", 3},
37 {"cube", 3},
38 {"cuboid", 3},
39 {"cylinder", 3},
40 {"open_rect_channel_2d", 2},
41 {"open_cuboid_channel_3d", 3},
42 {"plane", 3},
43 {"line", 1}
44 };

Referenced by getGeomTypeToDim().