PeriDEM 0.3.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 - 2026 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#include "util/io.h"
15#include "util/point.h"
16#include <nlohmann_json/json.hpp>
17using json = nlohmann::ordered_json;
18
19namespace geom {
20
22struct GeomData {
23
25std::string d_geomName;
26
28std::vector<double> d_geomParams;
29
31std::shared_ptr<geom::GeomObject> d_geom_p;
32
34std::pair<std::vector<std::string>, std::vector<std::string>> d_geomComplexInfo;
35
39GeomData() : d_geom_p(nullptr) {};
40
51
56void createNullGeomObject(std::string description = "") {
57 d_geomName = "null";
58 d_geomParams.resize(0);
59 d_geom_p = std::make_shared<geom::NullGeomObject>(
60 description);
61};
62
68void copyGeometry(GeomData &z);
69
78void copyGeometry(std::string &name,
79 std::vector<double> &params,
80 std::pair<std::vector<std::string>, std::vector<std::string>> &complexInfo,
81 std::shared_ptr<geom::GeomObject> &geom);
82
90std::string printStr(int nt = 0, int lvl = 0) const {
91
92 auto tabS = util::io::getTabS(nt);
93 std::ostringstream oss;
94 oss << tabS << "------- GeomData --------" << std::endl
95 << std::endl;
96 oss << tabS << "Type = " << d_geomName << std::endl;
97 oss << tabS << "Parameters = ["
98 << util::io::printStr<double>(d_geomParams, 0)
99 << "]" << std::endl;
100 if (!d_geomComplexInfo.first.empty()) {
101 oss << tabS << "Vec type for complex geometry = ["
103 << "]" << std::endl;
104
105 oss << tabS << "Vec flag for complex geometry = ["
107 << "]" << std::endl;
108 }
109 if (d_geom_p != nullptr)
110 oss << d_geom_p->printStr(nt + 1, lvl);
111
112 return oss.str();
113}
114
121void print(int nt = 0, int lvl = 0) const {
122 std::cout << printStr(nt, lvl);
123}
124}; // struct GeomData
125
127const std::vector<std::string> acceptable_geometries = {"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"};
147
148
149
151inline const std::vector<std::string> &getAcceptableGeometries() {
153};
154
155
162std::vector<size_t> getNumParamsRequired(std::string geom_type);
163
171bool checkParamForGeometry(size_t n, std::string geom_type);
172
180bool isNumberOfParamForGeometryValid(size_t n, std::string geom_type);
181
190bool checkParamForComplexGeometry(size_t n, std::string geom_type,
191 std::vector<std::string> vec_type);
192
201bool
202isNumberOfParamForComplexGeometryValid(size_t n, std::string geom_type,
203 std::vector<std::string> vec_type);
204
217void createGeomObjectOld(const std::string &type,
218 const std::vector<double> &params,
219 const std::vector<std::string> &vec_type,
220 const std::vector<std::string> &vec_flag,
221 std::shared_ptr<geom::GeomObject> &obj,
222 bool perform_check = true);
223
224void createGeomObject(const std::string &geom_type,
225 const std::vector<double> &params,
226 const std::vector<std::string> &vec_type,
227 const std::vector<std::string> &vec_flag,
228 std::shared_ptr<geom::GeomObject> &obj,
229 bool perform_check = true);
230
237std::vector<double> exampleGeomParams(const std::string &geom_type,
238 const util::Point &c = util::Point(0., 0., 0.),
239 double s = 0.001);
240
245std::shared_ptr<GeomObject> makeExampleGeomObject(const std::string &geom_type,
246 const util::Point &c = util::Point(0., 0., 0.),
247 double s = 0.001);
248
249void createGeomObject(GeomData &geomData,
250 bool perform_check = true);
251
252
253void readGeometry(const json &j, geom::GeomData &geomData);
254
255void writeGeometry(json &j, const geom::GeomData &geomData);
256
262GeomObject* createGeomDeepCopy(GeomObject* obj);
263
264} // namespace geom
nlohmann::ordered_json json
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)
GeomObject * createGeomDeepCopy(GeomObject *obj)
Creates a deep copy of a geometric object.
void readGeometry(const json &j, geom::GeomData &geomData)
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.
std::shared_ptr< GeomObject > makeExampleGeomObject(const std::string &geom_type, const util::Point &c, double s)
One-liner: createGeomObject(exampleGeomParams(...)). Prefer this over per-class static factories so a...
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)
Create geometrical object from the given data.
bool checkParamForComplexGeometry(size_t n, std::string geom_type, std::vector< std::string > vec_type)
Check parameter data for validity.
const std::vector< std::string > & getAcceptableGeometries()
Returns list of acceptable geometries for PeriDEM simulation.
void writeGeometry(json &j, const geom::GeomData &geomData)
bool checkParamForGeometry(size_t n, std::string geom_type)
Check parameter data for validity.
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.
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.
const std::vector< std::string > acceptable_geometries
List of acceptable geometries for particles in PeriDEM.
std::string getTabS(int nt)
Returns tab spaces of a given size.
Definition io.h:82
std::string printStr(const T &msg, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:96
Input data for geometrical objects.
std::shared_ptr< geom::GeomObject > d_geom_p
Zone geometry.
void createNullGeomObject(std::string description="")
Creates NullGeomObject.
void print(int nt=0, int lvl=0) const
Prints the information about the object.
GeomData()
Constructor.
void copyGeometry(GeomData &z)
Copies the geometry details.
std::vector< double > d_geomParams
Zone parameters.
std::string d_geomName
Zone type.
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
std::pair< std::vector< std::string >, std::vector< std::string > > d_geomComplexInfo
Zone geometry info if it is a complex type.
GeomData(const GeomData &z)
Constructor.
A structure to represent 3d vectors.
Definition point.h:30