PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
util::geometry Namespace Reference

Provides geometrical methods such as point inside rectangle. More...

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...
 
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  Rectangle
 Defines Rectangle. More...
 
class  Sphere
 Defines sphere. More...
 
class  Square
 Defines Square. More...
 
class  Triangle
 Defines Triangle. More...
 

Functions

const std::vector< std::string > & getAcceptableGeometries ()
 Returns list of acceptable geometries for PeriDEM simulation.
 
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.
 
bool isNumberOfParamForGeometryValid (size_t n, std::string geom_type)
 Ascertain if number of parameters are correct for the given geometry.
 
bool checkParamForComplexGeometry (size_t n, std::string geom_type, std::vector< std::string > vec_type)
 Check parameter data for validity.
 
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.
 
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.
 
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)
 
void createGeomObject (GeomData &geomData, const size_t &dim, bool perform_check=true)
 

Variables

const std::vector< std::string > acceptable_geometries
 List of acceptable geometries for particles in PeriDEM.
 

Detailed Description

Provides geometrical methods such as point inside rectangle.

Function Documentation

◆ checkParamForComplexGeometry()

bool util::geometry::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 105 of file geomObjectsUitl.cpp.

107 {
108
109 return !util::geometry::checkParamForComplexGeometry(n, geom_type, vec_type);
110 }
bool checkParamForComplexGeometry(size_t n, std::string geom_type, std::vector< std::string > vec_type)
Check parameter data for validity.

References checkParamForComplexGeometry().

Referenced by checkParamForComplexGeometry().

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

◆ checkParamForGeometry()

bool util::geometry::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 100 of file geomObjectsUitl.cpp.

100 {
101
103 }
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:

◆ createGeomObject() [1/2]

void util::geometry::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 
)

◆ createGeomObject() [2/2]

void util::geometry::createGeomObject ( GeomData geomData,
const size_t &  dim,
bool  perform_check = true 
)

Definition at line 900 of file geomObjectsUitl.cpp.

902 {
903
904 createGeomObject(geomData.d_geomName, geomData.d_geomParams,
905 geomData.d_geomComplexInfo.first,
906 geomData.d_geomComplexInfo.second,
907 geomData.d_geom_p, dim, perform_check);
908 }
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::shared_ptr< util::geometry::GeomObject > d_geom_p
Zone geometry.
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.
std::vector< double > d_geomParams
Zone parameters.

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

Here is the call graph for this function:

◆ createGeomObjectOld()

void util::geometry::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.

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
dimDimension
perform_checkPerform check for sufficient parameters

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

Definition at line 114 of file geomObjectsUitl.cpp.

120 {
121
122 // for any of the objects below, issue error if number of parameters not
123 // sufficient regardless of perform_check value
124 std::vector<std::string> no_default_obj = {"cylinder", "complex",
125 "rectangle_minus_rectangle",
126 "cuboid_minus_cuboid"};
127
128 bool check_passed; // true means check passed
129 if (type != "complex")
130 check_passed = isNumberOfParamForGeometryValid(params.size(), type);
131 else
132 check_passed = isNumberOfParamForComplexGeometryValid(params.size(), type,
133 vec_type);
134
135 std::ostringstream oss;
136 if (!check_passed) {
137 oss << "Error: Data maybe invalid. Can not create geometrical object: "
138 << type << " with params: " << util::io::printStr(params)
139 << ", vec type: " << util::io::printStr(vec_type)
140 << ", vec flag: " << util::io::printStr(vec_flag) << std::endl;
141 }
142
143 // issue error
144 if (!check_passed) {
145 if (perform_check || util::methods::isTagInList(type, no_default_obj)) {
146 std::cerr << oss.str();
147 exit(1);
148 }
149 }
150
151 // create object
152 if (type == "circle") {
153
154 if (check_passed) {
155 // if check is passed
156 obj = std::make_shared<util::geometry::Circle>(
157 params[0], util::Point(params[1], params[2], params[3]));
158 } else {
159 // if check is failed check if we can use other constructor
160 if (params.size() < 1) {
161 // if params are not adequate
162 std::cerr << "Error: need at least " << 1
163 << " parameters for creating circle. "
164 "Number of params provided = "
165 << params.size()
166 << ", params = "
167 << util::io::printStr(params) << " \n";
168 exit(EXIT_FAILURE);
169 }
170
171 // reached here it means we have adequate parameters
172 obj = std::make_shared<util::geometry::Circle>(params[0],
173 util::Point());
174 } // if else check_failed
175 } // if circle
176 else if (type == "rectangle") {
177
178 if (check_passed) {
179 // if check is passed
180 obj = std::make_shared<util::geometry::Rectangle>(
181 params[0], params[1],
182 util::Point(params[2], params[3], params[4]));
183 } else {
184 // if check is failed check if we can use other constructor
185 if (params.size() != 6 or params.size() != 5) {
186 // if params are not adequate
187 std::cerr << "Error: need either 5 or 6"
188 << " parameters for creating Rectangle. "
189 "Number of params provided = "
190 << params.size()
191 << ", params = "
192 << util::io::printStr(params) << " \n";
193 exit(EXIT_FAILURE);
194 }
195
196 // reached here it means we have adequate parameters
197 if (params.size() == 6)
198 obj = std::make_shared<util::geometry::Rectangle>(
199 util::Point(params[0], params[1], params[2]),
200 util::Point(params[3], params[4], params[5]));
201 else if (params.size() == 5)
202 obj = std::make_shared<util::geometry::Rectangle>(
203 params[0], params[1],
204 util::Point(params[2], params[3], params[4]));
205 } // if else check_failed
206 } // if rectangle
207 else if (type == "square") {
208
209 if (check_passed) {
210 // if check is passed
211 obj = std::make_shared<util::geometry::Square>(
212 params[0],
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) {
217 // if params are not adequate
218 std::cerr << "Error: need " << 6
219 << " parameters for creating Square. "
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 obj = std::make_shared<util::geometry::Square>(
229 util::Point(params[0], params[1], params[2]),
230 util::Point(params[3], params[4], params[5]));
231 } // if else check_failed
232 } // if square
233 else if (type == "triangle") {
234
235 if (check_passed) {
236 // if check is passed
237 obj = std::make_shared<util::geometry::Triangle>(
238 params[0], util::Point(params[1], params[2], params[3]),
239 util::Point(params[4], params[5], params[6]));
240 } else {
241 // if check is failed check if we can use other constructor
242 if (params.size() != 4) {
243 // if params are not adequate
244 std::cerr << "Error: need at least " << 4
245 << " parameters for creating triangle. "
246 "Number of params provided = "
247 << params.size()
248 << ", params = "
249 << util::io::printStr(params) << " \n";
250 exit(1);
251 }
252
253 // reached here it means we have adequate parameters
254 obj = std::make_shared<util::geometry::Triangle>(
255 params[0], util::Point(params[1], params[2], params[3]));
256 }// if else check_failed
257 }// if triangle
258 else if (type == "hexagon") {
259
260 if (check_passed) {
261 // if check is passed
262 obj = std::make_shared<util::geometry::Hexagon>(
263 params[0], util::Point(params[1], params[2], params[3]),
264 util::Point(params[4], params[5], params[6]));
265 } else {
266 // if check is failed check if we can use other constructor
267 if (params.size() != 4) {
268 // if params are not adequate
269 std::cerr << "Error: need at least " << 4
270 << " parameters for creating hexagon. "
271 "Number of params provided = "
272 << params.size()
273 << ", params = "
274 << util::io::printStr(params) << " \n";
275 exit(1);
276 }
277
278 // reached here it means we have adequate parameters
279 obj = std::make_shared<util::geometry::Hexagon>(
280 params[0], util::Point(params[1], params[2], params[3]));
281 }// if else check_failed
282 }// if hexagon
283 else if (type == "drum2d") {
284
285 if (check_passed) {
286 // if check is passed
287 obj = std::make_shared<util::geometry::Drum2D>(
288 params[0], params[1],
289 util::Point(params[2], params[3], params[4]),
290 util::Point(params[5], params[6], params[7]));
291 } else {
292 // if check is failed check if we can use other constructor
293 if (params.size() < 5) {
294 // if params are not adequate
295 std::cerr << "Error: need at least " << 5
296 << " parameters for creating drum2d. "
297 "Number of params provided = "
298 << params.size()
299 << ", params = "
300 << util::io::printStr(params) << " \n";
301 exit(1);
302 }
303
304 // reached here it means we have adequate parameters
305 obj = std::make_shared<util::geometry::Drum2D>(
306 params[0], params[1],
307 util::Point(params[2], params[3], params[4]));
308 }// if else check_failed
309 }// if drum2d
310 else if (type == "sphere") {
311
312 if (check_passed) {
313 // if check is passed
314 obj = std::make_shared<util::geometry::Sphere>(
315 params[0], util::Point(params[1], params[2], params[3]));
316 } else {
317 // if check is failed check if we can use other constructor
318 if (params.size() < 1) {
319 // if params are not adequate
320 std::cerr << "Error: need at least " << 1
321 << " parameters for creating sphere. "
322 "Number of params provided = "
323 << params.size()
324 << ", params = "
325 << util::io::printStr(params) << " \n";
326 exit(1);
327 }
328
329 // reached here it means we have adequate parameters
330 obj = std::make_shared<util::geometry::Sphere>(params[0],
331 util::Point());
332 }// if else check_failed
333 }// if sphere
334 else if (type == "cuboid") {
335
336 if (check_passed) {
337 // if check is passed
338 obj = std::make_shared<util::geometry::Cuboid>(
339 params[0], params[1], params[2],
340 util::Point(params[3], params[4], params[5]));
341 } else {
342 std::cerr << "Error: need at least " << 6
343 << " parameters for creating cuboid. "
344 "Number of params provided = "
345 << params.size()
346 << ", params = "
347 << util::io::printStr(params) << " \n";
348 exit(1);
349 }// if else check_failed
350 }// if cuboid
351 else if (type == "cube") {
352
353 if (check_passed) {
354 // if check is passed
355 obj = std::make_shared<util::geometry::Cube>(
356 params[0],
357 util::Point(params[2], params[3], params[4]));
358 } else {
359 // if check is failed check if we can use other constructor
360 if (params.size() < 6) {
361 // if params are not adequate
362 std::cerr << "Error: need " << 6
363 << " parameters for creating Cube. "
364 "Number of params provided = "
365 << params.size()
366 << ", params = "
367 << util::io::printStr(params) << " \n";
368 exit(EXIT_FAILURE);
369 }
370
371 // reached here it means we have adequate parameters
372 obj = std::make_shared<util::geometry::Cube>(
373 util::Point(params[0], params[1], params[2]),
374 util::Point(params[3], params[4], params[5]));
375 } // if else check_failed
376 } // if cube
377 else if (type == "cylinder") {
378
379 if (check_passed) {
380 // if check is passed
381 obj = std::make_shared<util::geometry::Cylinder>(
382 params[0], util::Point(params[1], params[2], params[3]),
383 util::Point(params[4], params[5], params[6]));
384 } else {
385 std::cerr << "Error: need at least " << 7
386 << " parameters for creating Cylinder. "
387 "Number of params provided = "
388 << params.size()
389 << ", params = "
390 << util::io::printStr(params) << " \n";
391 exit(1);
392 }// if else check_failed
393 }// if cylinder
394 else if (type == "rectangle_minus_rectangle") {
395
396 if (check_passed) {
397 // if check is passed
398 auto rin = new util::geometry::Rectangle(
399 util::Point(params[0], params[1],
400 params[2]),
401 util::Point(params[3], params[4], params[5]));
402 auto rout = new util::geometry::Rectangle(
403 util::Point(params[6], params[7],
404 params[8]),
405 util::Point(params[9], params[10],
406 params[11]));
407
408 obj = std::make_shared<util::geometry::AnnulusGeomObject>
409 (rin, rout, 2);
410 } else {
411 std::cerr << "Error: need at least " << 12
412 << " parameters for creating rectangle_minus_rectangle. "
413 "Number of params provided = "
414 << params.size()
415 << ", params = "
416 << util::io::printStr(params) << " \n";
417 exit(1);
418 }// if else check_failed
419 }// if rectangle_minus_rectangle
420 else if (type == "cuboid_minus_cuboid") {
421
422 if (check_passed) {
423 // if check is passed
424 auto rin = new util::geometry::Cuboid(
425 util::Point(params[0], params[1],
426 params[2]),
427 util::Point(params[3], params[4],
428 params[5]));
429 auto rout = new util::geometry::Cuboid(
430 util::Point(params[6], params[7],
431 params[8]),
432 util::Point(params[9], params[10],
433 params[11]));
434
435 obj = std::make_shared<util::geometry::AnnulusGeomObject>
436 (rin, rout, 3);
437 } else {
438 std::cerr << "Error: need at least " << 12
439 << " parameters for creating cuboid_minus_cuboid. "
440 "Number of params provided = "
441 << params.size()
442 << ", params = "
443 << util::io::printStr(params) << " \n";
444 exit(1);
445 }// if else check_failed
446 }// if cuboid_minus_cuboid
447 else if (type == "complex") {
448
449 if (check_passed) {
450 // if check is passed
451 std::vector<std::shared_ptr<util::geometry::GeomObject>> vec_obj(
452 vec_type.size());
453
454 size_t param_start = 0;
455 for (size_t i = 0; i < vec_type.size(); i++) {
456 auto geom_type = vec_type[i];
457 auto geom_flag = vec_flag[i];
458 auto num_params = getNumParamsRequired(geom_type)[0];
459
460 // get slice of full param vector
461 auto p1 = params.begin() + param_start;
462 auto p2 = params.begin() + param_start + num_params;
463 auto geom_param = std::vector<double>(p1, p2);
464
465 // create geom object
466 createGeomObject(geom_type, geom_param, std::vector<std::string>(),
467 std::vector<std::string>(), vec_obj[i], dim);
468
469 param_start += num_params;
470 }
471
472 // create complex geom object
474 obj = std::make_shared<util::geometry::ComplexGeomObject>(vec_obj,
475 vec_flag,
476 dim);
477 //obj->print();
478 } else {
479 std::cerr << "Error: Not enough parameters for creating complex. "
480 "Number of params provided = "
481 << params.size()
482 << ", params = "
483 << util::io::printStr(params) << " \n";
484 exit(1);
485 }// if else check_failed
486 }// if complex
487 }
Defines Rectangle.
std::vector< size_t > getNumParamsRequired(std::string geom_type)
Get num params required for creation of object.
std::string printStr(const T &msg, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:54
bool isTagInList(const std::string &tag, const std::vector< std::string > &tags)
Returns true if tag is found in the list of tags.
Definition methods.h:279
A structure to represent 3d vectors.
Definition point.h:30

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

Here is the call graph for this function:

◆ getAcceptableGeometries()

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

Returns list of acceptable geometries for PeriDEM simulation.

Definition at line 140 of file geomObjectsUtil.h.

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

References acceptable_geometries.

◆ getNumParamsRequired()

std::vector< size_t > util::geometry::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 36 of file geomObjectsUitl.cpp.

36 {
37
38 if (geom_type == "line")
39 return {1, 4, 6};
40 else if (geom_type == "triangle")
41 return {1, 4, 7};
42 else if (geom_type == "square")
43 return {1, 4, 6};
44 else if (geom_type == "rectangle")
45 return {2, 5, 6};
46 else if (geom_type == "hexagon")
47 return {1, 4, 7};
48 else if (geom_type == "drum2d")
49 return {2, 5, 8};
50 else if (geom_type == "cube")
51 return {1, 4, 6};
52 else if (geom_type == "cuboid")
53 return {3, 6};
54 else if (geom_type == "circle")
55 return {1, 4};
56 else if (geom_type == "sphere")
57 return {1, 4};
58 else if (geom_type == "cylinder")
59 return {7, 8};
60 else if (geom_type == "angled_rectangle")
61 return {6};
62 else if (geom_type == "angled_cuboid")
63 return {6};
64 else if (geom_type == "rectangle_minus_rectangle")
65 return {12};
66 else if (geom_type == "cuboid_minus_cuboid")
67 return {12};
68 else {
69 std::cerr << "Error: Invalid geometry type: " << geom_type << std::endl;
70 exit(1);
71 }
72 }

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

Here is the caller graph for this function:

◆ isNumberOfParamForComplexGeometryValid()

bool util::geometry::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 80 of file geomObjectsUitl.cpp.

82 {
83
84 int num_params = 0;
85 for (const auto &s: vec_type) {
86 // only consider the biggest parameter set from the list
87 auto nps = getNumParamsRequired(s);
88 if (nps.size() > 0)
89 num_params += nps[nps.size() - 1];
90 else {
91 std::cerr << "Error: Geometry type = " << s
92 << " has zero number of parameters required. \n";
93 exit(EXIT_FAILURE);
94 }
95 }
96 return n == num_params;
97 }

References getNumParamsRequired().

Referenced by createGeomObjectOld().

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

◆ isNumberOfParamForGeometryValid()

bool util::geometry::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 75 of file geomObjectsUitl.cpp.

75 {
76
78 }
bool isInList(const T &i, const std::vector< T > &list)
Find if data is in the list.
Definition methods.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:

Variable Documentation

◆ acceptable_geometries

const std::vector<std::string> util::geometry::acceptable_geometries
Initial value:
= {"circle",
"square",
"rectangle",
"hexagon",
"triangle",
"drum2d",
"sphere",
"cube",
"cuboid"}

List of acceptable geometries for particles in PeriDEM.

Definition at line 129 of file geomObjectsUtil.h.

129 {"circle",
130 "square",
131 "rectangle",
132 "hexagon",
133 "triangle",
134 "drum2d",
135 "sphere",
136 "cube",
137 "cuboid"};

Referenced by model::DEMModel::createGeometryAtSite(), and getAcceptableGeometries().