PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
geomObjectsUitl.cpp
Go to the documentation of this file.
1
2// Copyright (c) 2021 Prashant K. Jha
3//
4// Distributed under the Boost Software License, Version 1.0. (See accompanying
5// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6// ////////////////////////////////////////////////////////////////////////////////
7
8#include "geomObjectsUtil.h"
9#include "function.h"
10#include "geom.h"
11#include "methods.h"
12#include <vector>
13#include <set>
14
15namespace {
16 std::string printErrMsg(const std::string &geom_type,
17 const std::vector<double> &params,
18 const std::vector<size_t> &num_params_needed) {
19
20 std::ostringstream oss;
21
22 oss << "Error: Number of parameters needed to create geometry = "
23 << geom_type << " are "
24 << util::io::printStr(num_params_needed, 0)
25 << ". But the number of parameters provided are "
26 << params.size()
27 << " and the parameters are "
28 << util::io::printStr(params, 0)
29 << ". Exiting.\n";
30
31 return oss.str();
32 }
33};
34
35namespace util {
36 std::vector<size_t> util::geometry::getNumParamsRequired(std::string geom_type) {
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 }
75
76 bool
77 util::geometry::isNumberOfParamForGeometryValid(size_t n, std::string geom_type) {
78
80 }
81
83 std::string geom_type,
84 std::vector<std::string> vec_type) {
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 }
100
101 bool
102 util::geometry::checkParamForGeometry(size_t n, std::string geom_type) {
103
105 }
106
108 std::string geom_type,
109 std::vector<std::string> vec_type) {
110
111 return !util::geometry::checkParamForComplexGeometry(n, geom_type, vec_type);
112 }
113
114
115
116 void util::geometry::createGeomObjectOld(const std::string &type,
117 const std::vector<double> &params,
118 const std::vector<std::string> &vec_type,
119 const std::vector<std::string> &vec_flag,
120 std::shared_ptr<util::geometry::GeomObject> &obj,
121 const size_t &dim,
122 bool perform_check) {
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 }
515
516 void util::geometry::createGeomObject(const std::string &geom_type,
517 const std::vector<double> &params,
518 const std::vector<std::string> &vec_type,
519 const std::vector<std::string> &vec_flag,
520 std::shared_ptr<util::geometry::GeomObject> &obj,
521 const size_t &dim,
522 bool perform_check) {
523
524 std::vector<size_t> num_params_needed;
525
526 if (geom_type == "line") {
527
528 num_params_needed = {1, 4, 6};
529
530 for (auto n: num_params_needed) {
531 if (params.size() == n) {
532 if (n == 1) {
533 obj = std::make_shared<util::geometry::Line>(params[0]);
534 return;
535 } else if (n == 4) {
536 obj = std::make_shared<util::geometry::Line>(params[0],
538 params[1],
539 params[2],
540 params[3]));
541
542 return;
543 } else if (n == 6) {
544 obj = std::make_shared<util::geometry::Line>(
545 util::Point(params[0], params[1], params[2]),
546 util::Point(params[3], params[4], params[5]));
547
548 return;
549 }
550 } // if params.size() == n
551 } // loop over n
552 } // Line
553 else if (geom_type == "triangle") {
554
555 num_params_needed = {1, 4, 7};
556
557 for (auto n: num_params_needed) {
558 if (params.size() == n) {
559 if (n == 1) {
560 obj = std::make_shared<util::geometry::Triangle>(params[0]);
561 return;
562 } else if (n == 4) {
563 obj = std::make_shared<util::geometry::Triangle>(
564 params[0],
565 util::Point(params[1], params[2], params[3]));
566
567 return;
568 } else if (n == 7) {
569 obj = std::make_shared<util::geometry::Triangle>(
570 params[0],
571 util::Point(params[1],params[2],params[3]),
572 util::Point(params[4],params[5],params[6]));
573
574 return;
575 }
576 } // if params.size() == n
577 } // loop over n
578 } // Triangle
579 else if (geom_type == "square") {
580
581 num_params_needed = {1, 4, 6};
582
583 for (auto n: num_params_needed) {
584 if (params.size() == n) {
585 if (n == 1) {
586 obj = std::make_shared<util::geometry::Square>(params[0]);
587 return;
588 } else if (n == 4) {
589 obj = std::make_shared<util::geometry::Square>(params[0],
591 params[1],
592 params[2],
593 params[3]));
594 return;
595 } else if (n == 6) {
596 obj = std::make_shared<util::geometry::Square>(
597 util::Point(params[0], params[1], params[2]),
598 util::Point(params[3], params[4], params[5]));
599 return;
600 }
601 } // if params.size() == n
602 } // loop over n
603 } // Square
604 else if (geom_type == "rectangle") {
605
606 num_params_needed = {2, 5, 6};
607
608 for (auto n: num_params_needed) {
609 if (params.size() == n) {
610 if (n == 2) {
611 obj = std::make_shared<util::geometry::Rectangle>(params[0],
612 params[1]);
613 return;
614 } else if (n == 5) {
615 obj = std::make_shared<util::geometry::Rectangle>(
616 params[0], params[1],
617 util::Point(params[2], params[3], params[4]));
618 return;
619 } else if (n == 6) {
620 obj = std::make_shared<util::geometry::Rectangle>(
621 util::Point(params[0], params[1], params[2]),
622 util::Point(params[3], params[4], params[5]));
623 return;
624 }
625 } // if params.size() == n
626 } // loop over n
627 } // Rectangle
628 else if (geom_type == "hexagon") {
629
630 num_params_needed = {1, 4, 7};
631
632 for (auto n: num_params_needed) {
633 if (params.size() == n) {
634 if (n == 1) {
635 obj = std::make_shared<util::geometry::Hexagon>(params[0]);
636 return;
637 } else if (n == 4) {
638 obj = std::make_shared<util::geometry::Hexagon>(
639 params[0], util::Point(params[2], params[3], params[4]));
640 return;
641 } else if (n == 7) {
642 obj = std::make_shared<util::geometry::Hexagon>(
643 params[0],
644 util::Point(params[1], params[2], params[3]),
645 util::Point(params[4], params[5], params[6]));
646 return;
647 }
648 } // if params.size() == n
649 } // loop over n
650 } // Hexagon
651 else if (geom_type == "drum2d") {
652
653 num_params_needed = {2, 5, 8};
654
655 for (auto n: num_params_needed) {
656 if (params.size() == n) {
657 if (n == 2) {
658 obj = std::make_shared<util::geometry::Drum2D>(
659 params[0], params[1]);
660 return;
661 } else if (n == 5) {
662 obj = std::make_shared<util::geometry::Drum2D>(
663 params[0], params[1],
664 util::Point(params[2], params[3], params[4]));
665 return;
666 } else if (n == 8) {
667 obj = std::make_shared<util::geometry::Drum2D>(
668 params[0], params[1],
669 util::Point(params[2], params[3], params[4]),
670 util::Point(params[5], params[6], params[7]));
671 return;
672 }
673 } // if params.size() == n
674 } // loop over n
675 } // Drum2D
676 else if (geom_type == "cube") {
677
678 num_params_needed = {1, 4, 6};
679
680 for (auto n: num_params_needed) {
681 if (params.size() == n) {
682 if (n == 1) {
683 obj = std::make_shared<util::geometry::Cube>(params[0]);
684 return;
685 } else if (n == 4) {
686 obj = std::make_shared<util::geometry::Cube>(
687 params[0],
688 util::Point(params[1], params[2], params[3]));
689 return;
690 } else if (n == 6) {
691 obj = std::make_shared<util::geometry::Cube>(
692 util::Point(params[0], params[1], params[2]),
693 util::Point(params[3], params[4], params[5]));
694 return;
695 }
696 } // if params.size() == n
697 } // loop over n
698 } // Cube
699 else if (geom_type == "cuboid") {
700
701 num_params_needed = {3, 6};
702
703 for (auto n: num_params_needed) {
704 if (params.size() == n) {
705 if (n == 3) {
706 obj = std::make_shared<util::geometry::Cuboid>(
707 params[0], params[1], params[2]);
708 return;
709 } else if (n == 6) {
710 obj = std::make_shared<util::geometry::Cuboid>(
711 util::Point(params[0], params[1], params[2]),
712 util::Point(params[3], params[4], params[5]));
713 return;
714 }
715 } // if params.size() == n
716 } // loop over n
717 } // Cuboid
718 else if (geom_type == "circle") {
719
720 num_params_needed = {1, 4};
721
722 for (auto n: num_params_needed) {
723 if (params.size() == n) {
724 if (n == 1) {
725 obj = std::make_shared<util::geometry::Circle>(params[0]);
726 return;
727 } else if (n == 4) {
728 obj = std::make_shared<util::geometry::Circle>(
729 params[0],
730 util::Point(params[1], params[2], params[3]));
731 return;
732 }
733 } // if params.size() == n
734 } // loop over n
735 } // Circle
736 else if (geom_type == "ellipse") {
737
738 num_params_needed = {2, 5, 6};
739
740 for (auto n: num_params_needed) {
741 if (params.size() == n) {
742 if (n == 2) {
743 obj = std::make_shared<util::geometry::Ellipse>(params[0], params[1]);
744 return;
745 } else if (n == 5) {
746 obj = std::make_shared<util::geometry::Ellipse>(params[0], params[1],
747 util::Point(params[2], params[3], params[4]));
748 return;
749 } else if (n == 6) {
750 obj = std::make_shared<util::geometry::Ellipse>(params[0], params[1],
751 util::Point(params[2], params[3], params[4]),
752 params[5]);
753 return;
754 }
755 } // if params.size() == n
756 } // loop over n
757 } // Ellipse
758 else if (geom_type == "sphere") {
759
760 num_params_needed = {1, 4};
761
762 for (auto n: num_params_needed) {
763 if (params.size() == n) {
764 if (n == 1) {
765 obj = std::make_shared<util::geometry::Sphere>(params[0]);
766 return;
767 } else if (n == 4) {
768 obj = std::make_shared<util::geometry::Sphere>(
769 params[0],
770 util::Point(params[1], params[2], params[3]));
771 return;
772 }
773 } // if params.size() == n
774 } // loop over n
775 } // Sphere
776 else if (geom_type == "cylinder") {
777
778 num_params_needed = {7, 8};
779
780 for (auto n: num_params_needed) {
781 if (params.size() == n) {
782 if (n == 7) {
783 obj = std::make_shared<util::geometry::Cylinder>(
784 params[0],
785 util::Point(params[1], params[2], params[3]),
786 util::Point(params[4], params[5], params[6]));
787 return;
788 } else if (n == 8) {
789 obj = std::make_shared<util::geometry::Cylinder>(
790 params[0], params[1],
791 util::Point(params[2], params[3], params[4]),
792 util::Point(params[5], params[6], params[7]));
793 return;
794 }
795 } // if params.size() == n
796 } // loop over n
797 } // Cylinder
798 else if (geom_type == "angled_rectangle") {
799
800 num_params_needed = {6};
801
802 for (auto n: num_params_needed) {
803 if (params.size() == n) {
804 if (n == 6) {
805 obj = std::make_shared<util::geometry::Rectangle>(
806 util::Point(params[0], params[1], params[2]),
807 util::Point(params[3], params[4], params[5]));
808
809 return;
810 }
811 } // if params.size() == n
812 } // loop over n
813 } // angled_rectangle
814 else if (geom_type == "angled_cuboid") {
815
816 num_params_needed = {6};
817
818 for (auto n: num_params_needed) {
819 if (params.size() == n) {
820 if (n == 6) {
821 obj = std::make_shared<util::geometry::Cuboid>(
822 util::Point(params[0], params[1], params[2]),
823 util::Point(params[3], params[4], params[5]));
824
825 return;
826 }
827 } // if params.size() == n
828 } // loop over n
829 } // angled_cuboid
830 else if (geom_type == "rectangle_minus_rectangle") {
831
832 num_params_needed = {12};
833
834 for (auto n: num_params_needed) {
835 if (params.size() == n) {
836 if (n == 12) {
837
838 auto rin = new util::geometry::Rectangle(
839 util::Point(params[0], params[1], params[2]),
840 util::Point(params[3], params[4], params[5]));
841 auto rout = new util::geometry::Rectangle(
842 util::Point(params[6], params[7], params[8]),
843 util::Point(params[9], params[10], params[11]));
844
845 obj = std::make_shared<util::geometry::AnnulusGeomObject>
846 (rin, rout, 2);
847
848 return;
849 }
850 } // if params.size() == n
851 } // loop over n
852 } // rectangle_minus_rectangle
853 else if (geom_type == "cuboid_minus_cuboid") {
854
855 num_params_needed = {12};
856
857 for (auto n: num_params_needed) {
858 if (params.size() == n) {
859 if (n == 12) {
860
861 auto rin = new util::geometry::Cuboid(
862 util::Point(params[0], params[1], params[2]),
863 util::Point(params[3], params[4], params[5]));
864 auto rout = new util::geometry::Cuboid(
865 util::Point(params[6], params[7], params[8]),
866 util::Point(params[9], params[10], params[11]));
867
868 obj = std::make_shared<util::geometry::AnnulusGeomObject>
869 (rin, rout, 3);
870
871 return;
872 }
873 } // if params.size() == n
874 } // loop over n
875 } // rectangle_minus_rectangle
876 else if (geom_type == "complex") {
877
878 /*
879 std::cout << "vec_type = " << util::io::printStr(vec_type, 0)
880 << ", vec_flag = " << util::io::printStr(vec_flag, 0)
881 << "\n";
882 */
883
884 num_params_needed = {0};
885 std::vector<size_t> params_level(vec_type.size());
886 for (size_t i = 0; i < vec_type.size(); i++) {
887
888 // only consider the biggest parameter set from the list
889 auto nps = getNumParamsRequired(vec_type[i]);
890 if (nps.size() > 0)
891 params_level[i] = nps[nps.size() - 1];
892 else {
893 std::cerr << "Error: Geometry type = " << vec_type[i]
894 << " has zero number of parameters required. \n";
895 exit(EXIT_FAILURE);
896 }
897
898 //std::cout << "Geom type = " << vec_type[i]
899 // << ", params required = " << params_level[i] << "\n";
900
901 num_params_needed[0] += params_level[i];
902 }
903
904 std::vector<std::shared_ptr<util::geometry::GeomObject>> objs(vec_type.size());
905 std::vector<std::string> obj_flags(vec_type.size());
906
907 if (params.size() == num_params_needed[0]) {
908
909 // loop over objects and create
910 size_t param_start = 0;
911 for (size_t i = 0; i < vec_type.size(); i++) {
912
913 auto geom_type_temp = vec_type[i];
914 auto geom_flag_temp = vec_flag[i];
915
916 std::vector<std::string> vec_type_temp;
917 std::vector<std::string> vec_flag_temp;
918
919 // find what range of parameters we need to provide
920 std::vector<double> params_temp;
921 for (size_t j=0; j<params_level[i]; j++)
922 params_temp.push_back(params[j + param_start]);
923
924 // call this function recursively
925 obj_flags[i] = vec_flag[i];
927 geom_type_temp, params_temp, vec_type_temp, vec_flag_temp,
928 objs[i], dim, perform_check);
929
930 param_start += params_level[i];
931 } // loop over objects
932
933 // now create a composite object
934 obj = std::make_shared<util::geometry::ComplexGeomObject>(objs, obj_flags, dim);
935
936 return;
937 } // if params.size() == n
938 } // complex
939 else {
940 std::cerr << "Error: Invalid geometry type: " << geom_type << std::endl;
941 exit(1);
942 }
943
944
945 std::cerr << printErrMsg(geom_type, params, num_params_needed);
946 exit(1);
947 }
948
950 const size_t &dim,
951 bool perform_check) {
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 }
958
960 z.d_geomName = d_geomName;
961 z.d_geomParams = d_geomParams;
962 z.d_geomComplexInfo = d_geomComplexInfo;
963
964 if (d_geom_p->d_name == "null") {
965 z.d_geom_p =
966 std::make_shared<util::geometry::NullGeomObject>(
967 d_geom_p->d_description);
968 } else if (d_geom_p->d_name.empty()) {
969 z.d_geom_p =
970 std::make_shared<util::geometry::GeomObject>(
971 d_geom_p->d_name, d_geom_p->d_description);
972 } else {
974 }
975 }
976
978 std::vector<double> &params,
979 std::pair<std::vector<std::string>, std::vector<std::string>> &complexInfo,
980 std::shared_ptr<util::geometry::GeomObject> &geom,
981 size_t dim) {
982 name = d_geomName;
983 params = d_geomParams;
984 complexInfo = d_geomComplexInfo;
985
986 if (d_geom_p->d_name == "null") {
987 geom =
988 std::make_shared<util::geometry::NullGeomObject>(
989 d_geom_p->d_description);
990 } else if (d_geom_p->d_name.empty()) {
991 geom =
992 std::make_shared<util::geometry::GeomObject>(
993 d_geom_p->d_name, d_geom_p->d_description);
994 } else {
996 params,
997 complexInfo.first,
998 complexInfo.second,
999 geom, dim);
1000 }
1001 }
1002
1003}// Utility functions
Defines Rectangle.
std::string printErrMsg(const std::string &geom_type, const std::vector< double > &params, const std::vector< size_t > &num_params_needed)
std::string printErrMsg(const std::string &geom_type, const std::vector< double > &params, const std::vector< size_t > &num_params_needed)
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.
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.
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 printStr(const T &msg, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:54
bool isInList(const T &i, const std::vector< T > &list)
Find if data is in the list.
Definition methods.h:265
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
Collection of methods useful in simulation.
A structure to represent 3d vectors.
Definition point.h:30
Input data for geometrical objects.
void copyGeometry(GeomData &z, size_t dim)
Copies the geometry details.
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.