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. Basically, 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< GeomObjectmakeExampleGeomObject (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)
 
GeomObjectcreateGeomDeepCopy (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::PointgetCornerPoints (size_t dim, const std::pair< util::Point, util::Point > &box)
 Returns all corner points in the box.
 
std::vector< std::pair< util::Point, util::Point > > getEdges (size_t dim, const std::pair< util::Point, util::Point > &box)
 Returns all corner points in the box.
 
util::Point getCenter (size_t dim, const std::pair< util::Point, util::Point > &box)
 Returns center point.
 
double inscribedRadiusInBox (size_t dim, const std::pair< util::Point, util::Point > &box)
 Computes the radius of biggest circle/sphere completely within the object.
 
double circumscribedRadiusInBox (size_t dim, const std::pair< util::Point, util::Point > &box)
 Computes the radius of smallest circle/sphere which can have the box inside.
 
util::Point getPointOnLine (const util::Point &p1, const util::Point &p2, const double &s)
 Returns point in line formed by points p1 and p2.
 
double computeMeshSize (const std::vector< util::Point > &nodes)
 Computes minimum distance between any two nodes.
 
double computeMeshSize (const std::vector< util::Point > &nodes, size_t start, size_t end)
 Computes minimum distance between any two nodes.
 
std::pair< util::Point, util::PointcomputeBBox (const std::vector< util::Point > &nodes)
 Computes bounding box for vector nodes.
 
double computeInscribedRadius (const std::pair< util::Point, util::Point > &box)
 Computes maximum radius of circle/sphere within a given box.
 
std::pair< util::Point, util::PointtoPointBox (const std::vector< double > &p1, const std::vector< double > &p2)
 Create box from two coordinate data.
 
double triangleArea (const util::Point &x1, const util::Point &x2, const util::Point &x3)
 Compute area of triangle.
 
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 various objects
bool areBoxesNear (const std::pair< util::Point, util::Point > &b1, const std::pair< util::Point, util::Point > &b2, const double &tol, size_t dim)
 Checks if given two boxes are within given distance from each other.
 
bool doLinesIntersect (const std::pair< util::Point, util::Point > &line_1, const std::pair< util::Point, util::Point > &line_2)
 Do lines intersect.
 
double distanceBetweenLines (const std::pair< util::Point, util::Point > &line_1, const std::pair< util::Point, util::Point > &line_2)
 Compute distance between lines.
 
double distanceBetweenSegments (const std::pair< util::Point, util::Point > &line_1, const std::pair< util::Point, util::Point > &line_2)
 Compute distance between lines.
 
double distanceBetweenPlanes (const std::pair< util::Point, util::Point > &plane_1, const std::pair< util::Point, util::Point > &plane_2)
 Compute distance between planes.
 
double pointDistanceLine (const util::Point &p, const std::pair< util::Point, util::Point > &line)
 Compute distance between point and line.
 
double pointDistanceSegment (const util::Point &p, const std::pair< util::Point, util::Point > &line)
 Compute distance between point and line.
 
double pointDistancePlane (const util::Point &p, const std::pair< util::Point, util::Point > &plane)
 Compute distance between point and plane.
 
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 120 of file geomUtilFunctions.cpp.

124 {
125
126 auto cp1 = getCornerPoints(dim, b1);
127 auto cp2 = getCornerPoints(dim, b2);
128
129 for (auto p : cp1) {
130
131 // check 1: If any of the corner points of box 1 are inside box 2
132 if (isPointInsideBox(p, dim, b2))
133 return true;
134
135 // check 2: If any pair of corner points of box 1 and box 2 are at
136 // distance smaller than the tolerance
137 for (auto pp : cp2) {
138 auto dx = pp - p;
139 if (util::isLess(dx.length(), tol))
140 return true;
141 }
142 }
143
144 // check 3: Check if distance between centers of box 1 and box 2 are below
145 // sum of tolerance, radius of circle inscribed in box 1, and radius of
146 // circle inscribed in box 2
147 auto dxc = getCenter(dim, b2) - getCenter(dim, b1);
148 auto dist = tol + inscribedRadiusInBox(dim, b1) + inscribedRadiusInBox(dim,
149 b2);
150
151 if (util::isLess(dxc.length(), dist))
152 return true;
153
154 // check 4: Check if distance between centers of box 1 and box 2 are below
155 // sum of tolerance, radius of circle inscribed in box 1, and radius of
156 // circle circumscribed in box 2
157 dist = tol + inscribedRadiusInBox(dim, b1) + circumscribedRadiusInBox(dim,
158 b2);
159 if (util::isLess(dxc.length(), dist))
160 return true;
161
162 dist = tol + circumscribedRadiusInBox(dim, b1) + inscribedRadiusInBox(dim,
163 b2);
164 if (util::isLess(dxc.length(), dist))
165 return true;
166
167 return false;
168}
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:20

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 132 of file geomObjectsUtil.cpp.

134 {
135
136 return !isNumberOfParamForComplexGeometryValid(n, geom_type, vec_type);
137 }
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 127 of file geomObjectsUtil.cpp.

127 {
128
129 return !isNumberOfParamForGeometryValid(n, geom_type);
130 }
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 219 of file geomUtilFunctions.cpp.

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

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 617 of file geomUtilFunctions.cpp.

617 {
618
619 auto p1 = util::Point();
620 auto p2 = util::Point();
621 for (const auto& x : nodes) {
622 if (util::isLess(x.d_x, p1.d_x))
623 p1.d_x = x.d_x;
624 if (util::isLess(x.d_y, p1.d_y))
625 p1.d_y = x.d_y;
626 if (util::isLess(x.d_z, p1.d_z))
627 p1.d_z = x.d_z;
628 if (util::isLess(p2.d_x, x.d_x))
629 p2.d_x = x.d_x;
630 if (util::isLess(p2.d_y, x.d_y))
631 p2.d_y = x.d_y;
632 if (util::isLess(p2.d_z, x.d_z))
633 p2.d_z = x.d_z;
634 }
635
636 return {p1, p2};
637}
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 639 of file geomUtilFunctions.cpp.

640 {
641
642 return 0.5 * (box.first - box.second).length();
643}

◆ 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 562 of file geomUtilFunctions.cpp.

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

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 589 of file geomUtilFunctions.cpp.

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

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

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

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 1400 of file geomObjectsUtil.cpp.

1400 {
1401 if (!obj)
1402 return nullptr;
1403
1404 const std::string &type = obj->d_name;
1405 if (type == "null")
1406 return new NullGeomObject(*dynamic_cast<const NullGeomObject *>(obj));
1407 if (type == "plane")
1408 return new Plane(*dynamic_cast<const Plane *>(obj));
1409 if (type == "line")
1410 return new Line(*dynamic_cast<const Line *>(obj));
1411 if (type == "triangle")
1412 return new Triangle(*dynamic_cast<const Triangle *>(obj));
1413 if (type == "square")
1414 return new Square(*dynamic_cast<const Square *>(obj));
1415 if (type == "rectangle")
1416 return new Rectangle(*dynamic_cast<const Rectangle *>(obj));
1417 if (type == "hexagon")
1418 return new Hexagon(*dynamic_cast<const Hexagon *>(obj));
1419 if (type == "drum2d")
1420 return new Drum2D(*dynamic_cast<const Drum2D *>(obj));
1421 if (type == "cube")
1422 return new Cube(*dynamic_cast<const Cube *>(obj));
1423 if (type == "cuboid")
1424 return new Cuboid(*dynamic_cast<const Cuboid *>(obj));
1425 if (type == "circle")
1426 return new Circle(*dynamic_cast<const Circle *>(obj));
1427 if (type == "sphere")
1428 return new Sphere(*dynamic_cast<const Sphere *>(obj));
1429 if (type == "cylinder")
1430 return new Cylinder(*dynamic_cast<const Cylinder *>(obj));
1431 if (type == "ellipse")
1432 return new Ellipse(*dynamic_cast<const Ellipse *>(obj));
1433 if (type == "ellipsoid")
1434 return new Ellipsoid(*dynamic_cast<const Ellipsoid *>(obj));
1435 if (type == "annulus_object")
1436 return new AnnulusGeomObject(*dynamic_cast<const AnnulusGeomObject *>(obj));
1437 if (type == "open_rect_channel_2d")
1438 return new OpenRectChannel2D(*dynamic_cast<const OpenRectChannel2D *>(obj));
1439 if (type == "open_cuboid_channel_3d")
1440 return new OpenCuboidChannel3D(*dynamic_cast<const OpenCuboidChannel3D *>(obj));
1441 if (type == "complex")
1442 return new ComplexGeomObject(*dynamic_cast<const ComplexGeomObject *>(obj));
1443
1444 std::cerr << "Error: Unsupported object type '" << type << "' in createGeomDeepCopy\n";
1445 exit(1);
1446 }
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.

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 665 of file geomObjectsUtil.cpp.

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

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 1232 of file geomObjectsUtil.cpp.

1233 {
1234
1235 createGeomObject(geomData.d_geomName, geomData.d_geomParams,
1236 geomData.d_geomComplexInfo.first,
1237 geomData.d_geomComplexInfo.second,
1238 geomData.d_geom_p, perform_check);
1239 }
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 141 of file geomObjectsUtil.cpp.

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

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

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 398 of file geomUtilFunctions.cpp.

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

◆ 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 501 of file geomUtilFunctions.cpp.

503 {
504
505 // check if planes are parallel
506 if (util::angle(plane_1.first, plane_2.first) < 1.0E-8)
507 return 0.;
508
509 return std::abs(plane_1.first * (plane_1.second - plane_2.second)) /
510 plane_1.first.length();
511}
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 423 of file geomUtilFunctions.cpp.

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

◆ 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 367 of file geomUtilFunctions.cpp.

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

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 683 of file geomUtilFunctions.cpp.

683 {
684
685 if (std::abs(e.d_theta) < 1.0e-15) {
686 R[0] = R[4] = R[8] = 1.;
687 R[1] = R[2] = R[3] = R[5] = R[6] = R[7] = 0.;
688 return;
689 }
690
691 const double kx = e.d_axis.d_x;
692 const double ky = e.d_axis.d_y;
693 const double kz = e.d_axis.d_z;
694 const double c = std::cos(e.d_theta);
695 const double s = std::sin(e.d_theta);
696 const double t = 1.0 - c;
697
698 R[0] = t * kx * kx + c;
699 R[1] = t * kx * ky - kz * s;
700 R[2] = t * kx * kz + ky * s;
701 R[3] = t * kx * ky + kz * s;
702 R[4] = t * ky * ky + c;
703 R[5] = t * ky * kz - kx * s;
704 R[6] = t * kx * kz - ky * s;
705 R[7] = t * ky * kz + kx * s;
706 R[8] = t * kz * kz + c;
707}
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 1241 of file geomObjectsUtil.cpp.

1242 {
1243 if (geom_type == "circle")
1244 return {s, c.d_x, c.d_y, c.d_z};
1245 if (geom_type == "plane")
1246 return {0., 1., 0., c.d_x, c.d_y, c.d_z};
1247 if (geom_type == "square")
1248 return {c.d_x - s, c.d_y - s, c.d_z, c.d_x + s, c.d_y + s, c.d_z};
1249 if (geom_type == "rectangle")
1250 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};
1251 if (geom_type == "triangle")
1252 return {s, c.d_x, c.d_y, c.d_z, 1.0, 0.0, 0.0};
1253 if (geom_type == "hexagon")
1254 return {s, c.d_x, c.d_y, c.d_z, 1.0, 0.0, 0.0};
1255 if (geom_type == "drum2d") {
1256 const double r = 1.2 * s;
1257 const double w = 0.35 * s;
1258 return {r, w, c.d_x, c.d_y, c.d_z, 1.0, 0.0, 0.0};
1259 }
1260 if (geom_type == "sphere")
1261 return {s, c.d_x, c.d_y, c.d_z};
1262 if (geom_type == "cube")
1263 return {2.0 * s, c.d_x, c.d_y, c.d_z};
1264 if (geom_type == "cuboid")
1265 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,
1266 c.d_z + 0.6 * s};
1267 if (geom_type == "cylinder")
1268 return {0.5 * s, c.d_x, c.d_y - s, c.d_z, 0., 2. * s, 0.};
1269 if (geom_type == "ellipse")
1270 return {1.2 * s, 0.85 * s, 0.25, c.d_x, c.d_y, c.d_z};
1271 if (geom_type == "ellipsoid")
1272 return {2. * s, 1. * s, 1.5 * s, c.d_x, c.d_y, c.d_z};
1273 if (geom_type == "circle_minus_circle")
1274 return {c.d_x, c.d_y, c.d_z, s, 0.35 * s};
1275 if (geom_type == "ellipse_minus_ellipse")
1276 return {1.2 * s, 0.85 * s, 0.7 * s, 0.5 * s, 0.25, c.d_x, c.d_y, c.d_z};
1277 if (geom_type == "sphere_minus_sphere")
1278 return {c.d_x, c.d_y, c.d_z, s, 0.35 * s};
1279 if (geom_type == "rectangle_minus_rectangle") {
1280 const double ri = 0.35 * s;
1281 const double lo_ix = c.d_x - ri, lo_iy = c.d_y - ri, lo_iz = c.d_z;
1282 const double hi_ix = c.d_x + ri, hi_iy = c.d_y + ri, hi_iz = c.d_z;
1283 const double lo_ox = c.d_x - s, lo_oy = c.d_y - s, lo_oz = c.d_z;
1284 const double hi_ox = c.d_x + s, hi_oy = c.d_y + s, hi_oz = c.d_z;
1285 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};
1286 }
1287 if (geom_type == "cuboid_minus_cuboid") {
1288 const double sx = s, sy = 0.75 * s, sz = 0.6 * s;
1289 const double f = 0.35;
1290 const double lo_ix = c.d_x - f * sx, lo_iy = c.d_y - f * sy, lo_iz = c.d_z - f * sz;
1291 const double hi_ix = c.d_x + f * sx, hi_iy = c.d_y + f * sy, hi_iz = c.d_z + f * sz;
1292 const double lo_ox = c.d_x - sx, lo_oy = c.d_y - sy, lo_oz = c.d_z - sz;
1293 const double hi_ox = c.d_x + sx, hi_oy = c.d_y + sy, hi_oz = c.d_z + sz;
1294 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};
1295 }
1296 if (geom_type == "open_rect_channel_2d") {
1297 const double wall_t = 0.35 * s;
1298 return {c.d_x - s, c.d_y - s, c.d_x + s, c.d_y + s, wall_t, c.d_z};
1299 }
1300 if (geom_type == "open_cuboid_channel_3d") {
1301 const double wall_t = 0.35 * s;
1302 const double open_face = 4.; // +z (matches 2D “open up”)
1303 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};
1304 }
1305 throw std::runtime_error("exampleGeomParams: unknown geometry \"" + geom_type + "\"");
1306 }

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 102 of file geomUtilFunctions.cpp.

103 {
104
105 if (dim == 1)
106 return {0.5 * box.second.d_x + 0.5 * box.first.d_x, 0., 0.};
107 else if (dim == 2)
108 return {0.5 * box.second.d_x + 0.5 * box.first.d_x,
109 0.5 * box.second.d_y + 0.5 * box.first.d_y, 0.};
110 else if (dim == 3)
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,
113 0.5 * box.second.d_z + 0.5 * box.first.d_z};
114 else {
115 std::cerr << "Error: Check dimension = " << dim << ".\n";
116 exit(1);
117 }
118}

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

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

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 54 of file geomUtilFunctions.cpp.

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

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 361 of file geomUtilFunctions.cpp.

363 {
364 return (1. - s) * p1 + s * p2;
365}

◆ 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 194 of file geomUtilFunctions.cpp.

195 {
196
197 double r = 0.5 * std::abs(box.second.d_x - box.first.d_x);
198 if (dim == 1)
199 return r;
200 else if (dim == 2) {
201 if (util::isGreater(r, 0.5 * std::abs(box.second.d_y - box.first.d_y)))
202 return 0.5 * std::abs(box.second.d_y - box.first.d_y);
203 else
204 return r;
205 } else if (dim == 3) {
206 if (util::isGreater(r, 0.5 * std::abs(box.second.d_y - box.first.d_y)))
207 r = 0.5 * std::abs(box.second.d_y - box.first.d_y);
208
209 if (util::isGreater(r, 0.5 * std::abs(box.second.d_z - box.first.d_z)))
210 return 0.5 * std::abs(box.second.d_z - box.first.d_z);
211 else
212 return r;
213 } else {
214 std::cerr << "inscribedRadiusInBox(): Function implemented for dim = 1,2,3 only.\n";
215 exit(EXIT_FAILURE);
216 }
217}

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

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

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 102 of file geomObjectsUtil.cpp.

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

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 260 of file geomUtilFunctions.cpp.

262 {
263 // we assume that the rectangle has passed the test
264
265 //
266 // (x2,y2)
267 // o
268 //
269 //
270 //
271 //
272 //
273 // o
274 // (x1,y1)
275
276 // get divisors
278 util::Point(x2 - x1, y2 - y1, 0.0), theta);
279
280 // double lam1 = (x2-x1) * std::cos(theta) + (y2-y1) * std::sin(theta);
281 // double lam2 = -(x2-x1) * std::sin(theta) + (y2-y1) * std::cos(theta);
282
283 // get mapped coordinate of x
285 util::Point(x[0] - x1, x[1] - y1, 0.0), theta);
286
287 // double xmap = (x[0]-x1) * std::cos(theta) + (x[1]-y1) * std::sin(theta);
288 // double ymap = -(x[0]-x1) * std::sin(theta) + (x[1]-y1) * std::cos(theta);
289
290 // check if mapped coordinate are out of range [0, lam1] and [0, lam2]
291 return !(util::isLess(xmap[0], -1.0E-12) or
292 util::isLess(xmap[1], -1.0E-12) or
293 util::isGreater(xmap[0], lam[0] + 1.0E-12) or
294 util::isGreater(xmap[1], lam[1] + 1.0E-12));
295}
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 170 of file geomUtilFunctions.cpp.

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

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 297 of file geomUtilFunctions.cpp.

298 {
299 return !(util::isLess(x.d_x, x_lbb.d_x - 1.0E-12) or
300 util::isLess(x.d_y, x_lbb.d_y - 1.0E-12) or
301 util::isLess(x.d_z, x_lbb.d_z - 1.0E-12) or
302 util::isGreater(x.d_x, x_rtf.d_x + 1.0E-12) or
303 util::isGreater(x.d_y, x_rtf.d_y + 1.0E-12) or
304 util::isGreater(x.d_z, x_rtf.d_z + 1.0E-12));
305}

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 307 of file geomUtilFunctions.cpp.

308 {
309
310 double p_dot_a = p * axis;
311 if (p_dot_a > length or p_dot_a < 0.)
312 return false;
313 else {
314
315 auto p_parallel = p - p_dot_a * axis;
316
317 return p_parallel.lengthSq() < radius * radius;
318 }
319}
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 321 of file geomUtilFunctions.cpp.

322 {
323
324 auto p_new = p - x1;
325 auto a = x2 - x1;
326 double p_dot_a = p_new * a;
327
328 // note here we should 1 if a is not normalized
329 if (p_dot_a > 1. or p_dot_a < 0.)
330 return false;
331 else {
332
333 auto p_parallel = p_new - p_dot_a * a;
334
335 return p_parallel.lengthSq() < radius * radius;
336 }
337}

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 339 of file geomUtilFunctions.cpp.

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

◆ 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 350 of file geomUtilFunctions.cpp.

351 {
352
353 d = 0.;
354 auto x = p - center;
355 for (unsigned int i=0; i<dim; i++)
356 d += x[i] * x[i] / (radius_vec[i] * radius_vec[i]);
357
358 return d < 1.;
359}

◆ 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 242 of file geomUtilFunctions.cpp.

244 {
245
246 return !(util::isLess(x.d_x, x_min - 1.0E-12) or
247 util::isLess(x.d_y, y_min - 1.0E-12) or
248 util::isGreater(x.d_x, x_max + 1.0E-12) or
249 util::isGreater(x.d_y, y_max + 1.0E-12));
250}

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 252 of file geomUtilFunctions.cpp.

253 {
254 return !(util::isLess(x.d_x, x_lb.d_x - 1.0E-12) or
255 util::isLess(x.d_y, x_lb.d_y - 1.0E-12) or
256 util::isGreater(x.d_x, x_rt.d_x + 1.0E-12) or
257 util::isGreater(x.d_y, x_rt.d_y + 1.0E-12));
258}

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 1308 of file geomObjectsUtil.cpp.

1309 {
1310 std::shared_ptr<GeomObject> obj;
1311 createGeomObject(geom_type, exampleGeomParams(geom_type, c, s), {}, {}, obj, false);
1312 return obj;
1313 }
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 513 of file geomUtilFunctions.cpp.

514 {
515
516 // line vector
517 auto v = line.second - line.first;
518
519 // vector from 1st point of line to p
520 auto w = p - line.first;
521
522 // project w onto v and add 1st point to get projected point's location
523 auto w_on_line = line.first + (w * v) * v / v.lengthSq();
524
525 return (p - w_on_line).length();
526}

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 551 of file geomUtilFunctions.cpp.

552 {
553
554 // if plane is given by unit normal n and a point a which is contained in it
555 // then the distance of point p from plane is
556 // |(p - a) dot n| / |n|
557
558 auto pa = p - plane.second;
559 return std::abs(pa * plane.first) / plane.first.length();
560}
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 528 of file geomUtilFunctions.cpp.

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

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 1374 of file geomObjectsUtil.cpp.

1374 {
1375
1376 if (j.find("Type") == j.end()) {
1377 std::cerr << "Error: Geometry type not found in json file.\n";
1378 exit(1);
1379 }
1380 geomData.d_geomName = j.at("Type");
1381
1382 if (geomData.d_geomName == "complex") {
1383 if ((j.find("Vec_type") == j.end()) or (j.find("Vec_flag") == j.end())) {
1384 std::cerr << "Error: Geometry type and/or flag not found in json file.\n";
1385 exit(1);
1386 }
1387 geomData.d_geomComplexInfo.first = j.at("Vec_type").get<std::vector<std::string>>();
1388 geomData.d_geomComplexInfo.second = j.at("Vec_flag").get<std::vector<std::string>>();
1389 }
1390
1391 if (j.find("Parameters") == j.end()) {
1392 std::cerr << "Error: Geometry parameters not found in json file.\n";
1393 exit(1);
1394 }
1395
1396 for (auto a: j.at("Parameters"))
1397 geomData.d_geomParams.push_back(a);
1398 }

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

647 {
648 auto q1 = util::Point(p1[0], p1[1], p1[2]);
649 auto q2 = util::Point(p2[0], p2[1], p2[2]);
650 return {q1, q2};
651}

◆ 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 653 of file geomUtilFunctions.cpp.

654 {
655 return 0.5 * ((x2.d_x - x1.d_x) * (x3.d_y - x1.d_y) -
656 (x3.d_x - x1.d_x) * (x2.d_y - x1.d_y));
657}

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 1363 of file geomObjectsUtil.cpp.

1363 {
1364 j["Type"] = geomData.d_geomName;
1365
1366 if (geomData.d_geomName == "complex") {
1367 j["Vec_type"] = geomData.d_geomComplexInfo.first;
1368 j["Vec_flag"] = geomData.d_geomComplexInfo.second;
1369 }
1370
1371 j["Parameters"] = geomData.d_geomParams;
1372 }

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