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...
 
class  Ellipse
 Defines ellipse. 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 107 of file geomObjectsUitl.cpp.

109 {
110
111 return !util::geometry::checkParamForComplexGeometry(n, geom_type, vec_type);
112 }
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 102 of file geomObjectsUitl.cpp.

102 {
103
105 }
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 949 of file geomObjectsUitl.cpp.

951 {
952
953 createGeomObject(geomData.d_geomName, geomData.d_geomParams,
954 geomData.d_geomComplexInfo.first,
955 geomData.d_geomComplexInfo.second,
956 geomData.d_geom_p, dim, perform_check);
957 }
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 116 of file geomObjectsUitl.cpp.

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

141 {
143};
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 == "ellipse")
57 return {2, 5};
58 else if (geom_type == "sphere")
59 return {1, 4};
60 else if (geom_type == "cylinder")
61 return {7, 8};
62 else if (geom_type == "angled_rectangle")
63 return {6};
64 else if (geom_type == "angled_cuboid")
65 return {6};
66 else if (geom_type == "rectangle_minus_rectangle")
67 return {12};
68 else if (geom_type == "cuboid_minus_cuboid")
69 return {12};
70 else {
71 std::cerr << "Error: Invalid geometry type: " << geom_type << std::endl;
72 exit(1);
73 }
74 }

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 82 of file geomObjectsUitl.cpp.

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

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 77 of file geomObjectsUitl.cpp.

77 {
78
80 }
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",
"ellipse"}

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",
138 "ellipse"};

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