PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
geomObjectsUtil.h
Go to the documentation of this file.
1/*
2* -------------------------------------------
3* Copyright (c) 2021 - 2024 Prashant K. Jha
4* -------------------------------------------
5* PeriDEM https://github.com/prashjha/PeriDEM
6*
7* Distributed under the Boost Software License, Version 1.0. (See accompanying
8* file LICENSE)
9*/
10
11#pragma once
12
13#include "geomObjects.h"
14
15namespace util {
16
18namespace geometry {
19
21struct GeomData {
22
24std::string d_geomName;
25
27std::vector<double> d_geomParams;
28
30std::shared_ptr<util::geometry::GeomObject> d_geom_p;
31
33std::pair<std::vector<std::string>, std::vector<std::string>> d_geomComplexInfo;
34
38GeomData() : d_geom_p(nullptr) {};
39
50
55void createNullGeomObject(std::string description = "") {
56 d_geomName = "null";
57 d_geomParams.resize(0);
58 d_geom_p = std::make_shared<util::geometry::NullGeomObject>(
59 description);
60};
61
68void copyGeometry(GeomData &z, size_t dim);
69
79void copyGeometry(std::string &name,
80 std::vector<double> &params,
81 std::pair<std::vector<std::string>, std::vector<std::string>> &complexInfo,
82 std::shared_ptr<util::geometry::GeomObject> &geom,
83 size_t dim);
84
92std::string printStr(int nt = 0, int lvl = 0) const {
93
94 auto tabS = util::io::getTabS(nt);
95 std::ostringstream oss;
96 oss << tabS << "------- GeomData --------" << std::endl
97 << std::endl;
98 oss << tabS << "Type = " << d_geomName << std::endl;
99 oss << tabS << "Parameters = ["
100 << util::io::printStr<double>(d_geomParams, 0)
101 << "]" << std::endl;
102 if (!d_geomComplexInfo.first.empty()) {
103 oss << tabS << "Vec type for complex geometry = ["
105 << "]" << std::endl;
106
107 oss << tabS << "Vec flag for complex geometry = ["
109 << "]" << std::endl;
110 }
111 if (d_geom_p != nullptr)
112 oss << d_geom_p->printStr(nt + 1, lvl);
113
114 return oss.str();
115}
116
123void print(int nt = 0, int lvl = 0) const {
124 std::cout << printStr(nt, lvl);
125}
126}; // struct GeomData
127
129const std::vector<std::string> acceptable_geometries = {"circle",
130 "square",
131 "rectangle",
132 "hexagon",
133 "triangle",
134 "drum2d",
135 "sphere",
136 "cube",
137 "cuboid"};
138
140inline const std::vector<std::string> &getAcceptableGeometries() {
142};
143
148
149util::Point d_xc; // centroid of box
150std::pair<util::Point, util::Point> d_box; // two corner points
151double d_r; // radius of circle inscribing box
152std::vector<size_t> d_nodes; // id of nodes in this box
153
156 d_r(0.) {}
157
158bool isNear(const BoxPartition &box, const double &tol) const {
159 auto dx = d_xc - box.d_xc;
160 return dx.length() < d_r + box.d_r + tol;
161}
162
163bool isNear(const util::Point &x, const double &tol) const {
164
165 if (util::isLess(x.d_x, d_box.first.d_x - tol) or
166 util::isLess(x.d_y, d_box.first.d_y - tol) or
167 util::isLess(x.d_z, d_box.first.d_z - tol) or
168 util::isGreater(x.d_x, d_box.second.d_x + tol) or
169 util::isGreater(x.d_y, d_box.second.d_y + tol) or
170 util::isGreater(x.d_z, d_box.second.d_z + tol))
171 return false;
172
173 return true;
174}
175
176void addNode(const size_t &i) {
177 for (const auto &j: d_nodes)
178 if (j == i)
179 return;
180
181 d_nodes.push_back(i);
182}
183};
184
191std::vector<size_t> getNumParamsRequired(std::string geom_type);
192
200bool checkParamForGeometry(size_t n, std::string geom_type);
201
209bool isNumberOfParamForGeometryValid(size_t n, std::string geom_type);
210
219bool checkParamForComplexGeometry(size_t n, std::string geom_type,
220 std::vector<std::string> vec_type);
221
230bool
231isNumberOfParamForComplexGeometryValid(size_t n, std::string geom_type,
232 std::vector<std::string> vec_type);
233
245void createGeomObjectOld(const std::string &type,
246 const std::vector<double> &params,
247 const std::vector<std::string> &vec_type,
248 const std::vector<std::string> &vec_flag,
249 std::shared_ptr<util::geometry::GeomObject> &obj,
250 const size_t &dim,
251 bool perform_check = true);
252
253void createGeomObject(const std::string &geom_type,
254 const std::vector<double> &params,
255 const std::vector<std::string> &vec_type,
256 const std::vector<std::string> &vec_flag,
257 std::shared_ptr<util::geometry::GeomObject> &obj,
258 const size_t &dim,
259 bool perform_check = true);
260
261
262void createGeomObject(GeomData &geomData,
263 const size_t &dim,
264 bool perform_check = true);
265
266} // namespace geometry
267
268} // namespace util
269
Collection of methods and data related to geometry.
Definition fracture.h:20
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 isNumberOfParamForGeometryValid(size_t n, std::string geom_type)
Ascertain if number of parameters are correct for the given geometry.
std::vector< size_t > getNumParamsRequired(std::string geom_type)
Get num params required for creation of object.
bool checkParamForGeometry(size_t n, std::string geom_type)
Check parameter data for validity.
const std::vector< std::string > acceptable_geometries
List of acceptable geometries for particles in PeriDEM.
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< util::geometry::GeomObject > &obj, const size_t &dim, bool perform_check=true)
Create geometrical object from the given data.
const std::vector< std::string > & getAcceptableGeometries()
Returns list of acceptable geometries for PeriDEM simulation.
bool checkParamForComplexGeometry(size_t n, std::string geom_type, std::vector< std::string > vec_type)
Check parameter data for validity.
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< util::geometry::GeomObject > &obj, const size_t &dim, bool perform_check=true)
std::string getTabS(int nt)
Returns tab spaces of given size.
Definition io.h:40
std::string printStr(const T &msg, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:54
Collection of methods useful in simulation.
bool isGreater(const double &a, const double &b)
Returns true if a > b.
Definition function.cpp:15
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:20
A structure to represent 3d vectors.
Definition point.h:30
double d_y
the y coordinate
Definition point.h:36
double d_z
the z coordinate
Definition point.h:39
double length() const
Computes the Euclidean length of the vector.
Definition point.h:118
double d_x
the x coordinate
Definition point.h:33
Defines simple rectangle domain.
bool isNear(const util::Point &x, const double &tol) const
std::vector< size_t > d_nodes
std::pair< util::Point, util::Point > d_box
bool isNear(const BoxPartition &box, const double &tol) const
void addNode(const size_t &i)
Input data for geometrical objects.
void copyGeometry(GeomData &z, size_t dim)
Copies the geometry details.
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
std::shared_ptr< util::geometry::GeomObject > d_geom_p
Zone geometry.
GeomData(const GeomData &z)
Constructor.
std::pair< std::vector< std::string >, std::vector< std::string > > d_geomComplexInfo
Zone geometry info if it is a complex type.
std::string d_geomName
Zone type.
void createNullGeomObject(std::string description="")
Creates NullGeomObject.
std::vector< double > d_geomParams
Zone parameters.
void print(int nt=0, int lvl=0) const
Prints the information about the object.