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 == "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 }
73
74 bool
75 util::geometry::isNumberOfParamForGeometryValid(size_t n, std::string geom_type) {
76
78 }
79
81 std::string geom_type,
82 std::vector<std::string> vec_type) {
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 }
98
99 bool
100 util::geometry::checkParamForGeometry(size_t n, std::string geom_type) {
101
103 }
104
106 std::string geom_type,
107 std::vector<std::string> vec_type) {
108
109 return !util::geometry::checkParamForComplexGeometry(n, geom_type, vec_type);
110 }
111
112
113
114 void util::geometry::createGeomObjectOld(const std::string &type,
115 const std::vector<double> &params,
116 const std::vector<std::string> &vec_type,
117 const std::vector<std::string> &vec_flag,
118 std::shared_ptr<util::geometry::GeomObject> &obj,
119 const size_t &dim,
120 bool perform_check) {
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 }
488
489 void util::geometry::createGeomObject(const std::string &geom_type,
490 const std::vector<double> &params,
491 const std::vector<std::string> &vec_type,
492 const std::vector<std::string> &vec_flag,
493 std::shared_ptr<util::geometry::GeomObject> &obj,
494 const size_t &dim,
495 bool perform_check) {
496
497 std::vector<size_t> num_params_needed;
498
499 if (geom_type == "line") {
500
501 num_params_needed = {1, 4, 6};
502
503 for (auto n: num_params_needed) {
504 if (params.size() == n) {
505 if (n == 1) {
506 obj = std::make_shared<util::geometry::Line>(params[0]);
507 return;
508 } else if (n == 4) {
509 obj = std::make_shared<util::geometry::Line>(params[0],
511 params[1],
512 params[2],
513 params[3]));
514
515 return;
516 } else if (n == 6) {
517 obj = std::make_shared<util::geometry::Line>(
518 util::Point(params[0], params[1], params[2]),
519 util::Point(params[3], params[4], params[5]));
520
521 return;
522 }
523 } // if params.size() == n
524 } // loop over n
525 } // Line
526 else if (geom_type == "triangle") {
527
528 num_params_needed = {1, 4, 7};
529
530 for (auto n: num_params_needed) {
531 if (params.size() == n) {
532 if (n == 1) {
533 obj = std::make_shared<util::geometry::Triangle>(params[0]);
534 return;
535 } else if (n == 4) {
536 obj = std::make_shared<util::geometry::Triangle>(
537 params[0],
538 util::Point(params[1], params[2], params[3]));
539
540 return;
541 } else if (n == 7) {
542 obj = std::make_shared<util::geometry::Triangle>(
543 params[0],
544 util::Point(params[1],params[2],params[3]),
545 util::Point(params[4],params[5],params[6]));
546
547 return;
548 }
549 } // if params.size() == n
550 } // loop over n
551 } // Triangle
552 else if (geom_type == "square") {
553
554 num_params_needed = {1, 4, 6};
555
556 for (auto n: num_params_needed) {
557 if (params.size() == n) {
558 if (n == 1) {
559 obj = std::make_shared<util::geometry::Square>(params[0]);
560 return;
561 } else if (n == 4) {
562 obj = std::make_shared<util::geometry::Square>(params[0],
564 params[1],
565 params[2],
566 params[3]));
567 return;
568 } else if (n == 6) {
569 obj = std::make_shared<util::geometry::Square>(
570 util::Point(params[0], params[1], params[2]),
571 util::Point(params[3], params[4], params[5]));
572 return;
573 }
574 } // if params.size() == n
575 } // loop over n
576 } // Square
577 else if (geom_type == "rectangle") {
578
579 num_params_needed = {2, 5, 6};
580
581 for (auto n: num_params_needed) {
582 if (params.size() == n) {
583 if (n == 2) {
584 obj = std::make_shared<util::geometry::Rectangle>(params[0],
585 params[1]);
586 return;
587 } else if (n == 5) {
588 obj = std::make_shared<util::geometry::Rectangle>(
589 params[0], params[1],
590 util::Point(params[2], params[3], params[4]));
591 return;
592 } else if (n == 6) {
593 obj = std::make_shared<util::geometry::Rectangle>(
594 util::Point(params[0], params[1], params[2]),
595 util::Point(params[3], params[4], params[5]));
596 return;
597 }
598 } // if params.size() == n
599 } // loop over n
600 } // Rectangle
601 else if (geom_type == "hexagon") {
602
603 num_params_needed = {1, 4, 7};
604
605 for (auto n: num_params_needed) {
606 if (params.size() == n) {
607 if (n == 1) {
608 obj = std::make_shared<util::geometry::Hexagon>(params[0]);
609 return;
610 } else if (n == 4) {
611 obj = std::make_shared<util::geometry::Hexagon>(
612 params[0], util::Point(params[2], params[3], params[4]));
613 return;
614 } else if (n == 7) {
615 obj = std::make_shared<util::geometry::Hexagon>(
616 params[0],
617 util::Point(params[1], params[2], params[3]),
618 util::Point(params[4], params[5], params[6]));
619 return;
620 }
621 } // if params.size() == n
622 } // loop over n
623 } // Hexagon
624 else if (geom_type == "drum2d") {
625
626 num_params_needed = {2, 5, 8};
627
628 for (auto n: num_params_needed) {
629 if (params.size() == n) {
630 if (n == 2) {
631 obj = std::make_shared<util::geometry::Drum2D>(
632 params[0], params[1]);
633 return;
634 } else if (n == 5) {
635 obj = std::make_shared<util::geometry::Drum2D>(
636 params[0], params[1],
637 util::Point(params[2], params[3], params[4]));
638 return;
639 } else if (n == 8) {
640 obj = std::make_shared<util::geometry::Drum2D>(
641 params[0], params[1],
642 util::Point(params[2], params[3], params[4]),
643 util::Point(params[5], params[6], params[7]));
644 return;
645 }
646 } // if params.size() == n
647 } // loop over n
648 } // Drum2D
649 else if (geom_type == "cube") {
650
651 num_params_needed = {1, 4, 6};
652
653 for (auto n: num_params_needed) {
654 if (params.size() == n) {
655 if (n == 1) {
656 obj = std::make_shared<util::geometry::Cube>(params[0]);
657 return;
658 } else if (n == 4) {
659 obj = std::make_shared<util::geometry::Cube>(
660 params[0],
661 util::Point(params[1], params[2], params[3]));
662 return;
663 } else if (n == 6) {
664 obj = std::make_shared<util::geometry::Cube>(
665 util::Point(params[0], params[1], params[2]),
666 util::Point(params[3], params[4], params[5]));
667 return;
668 }
669 } // if params.size() == n
670 } // loop over n
671 } // Cube
672 else if (geom_type == "cuboid") {
673
674 num_params_needed = {3, 6};
675
676 for (auto n: num_params_needed) {
677 if (params.size() == n) {
678 if (n == 3) {
679 obj = std::make_shared<util::geometry::Cuboid>(
680 params[0], params[1], params[2]);
681 return;
682 } else if (n == 6) {
683 obj = std::make_shared<util::geometry::Cuboid>(
684 util::Point(params[0], params[1], params[2]),
685 util::Point(params[3], params[4], params[5]));
686 return;
687 }
688 } // if params.size() == n
689 } // loop over n
690 } // Cuboid
691 else if (geom_type == "circle") {
692
693 num_params_needed = {1, 4};
694
695 for (auto n: num_params_needed) {
696 if (params.size() == n) {
697 if (n == 1) {
698 obj = std::make_shared<util::geometry::Circle>(params[0]);
699 return;
700 } else if (n == 4) {
701 obj = std::make_shared<util::geometry::Circle>(
702 params[0],
703 util::Point(params[1], params[2], params[3]));
704 return;
705 }
706 } // if params.size() == n
707 } // loop over n
708 } // Circle
709 else if (geom_type == "sphere") {
710
711 num_params_needed = {1, 4};
712
713 for (auto n: num_params_needed) {
714 if (params.size() == n) {
715 if (n == 1) {
716 obj = std::make_shared<util::geometry::Sphere>(params[0]);
717 return;
718 } else if (n == 4) {
719 obj = std::make_shared<util::geometry::Sphere>(
720 params[0],
721 util::Point(params[1], params[2], params[3]));
722 return;
723 }
724 } // if params.size() == n
725 } // loop over n
726 } // Sphere
727 else if (geom_type == "cylinder") {
728
729 num_params_needed = {7, 8};
730
731 for (auto n: num_params_needed) {
732 if (params.size() == n) {
733 if (n == 7) {
734 obj = std::make_shared<util::geometry::Cylinder>(
735 params[0],
736 util::Point(params[1], params[2], params[3]),
737 util::Point(params[4], params[5], params[6]));
738 return;
739 } else if (n == 8) {
740 obj = std::make_shared<util::geometry::Cylinder>(
741 params[0], params[1],
742 util::Point(params[2], params[3], params[4]),
743 util::Point(params[5], params[6], params[7]));
744 return;
745 }
746 } // if params.size() == n
747 } // loop over n
748 } // Cylinder
749 else if (geom_type == "angled_rectangle") {
750
751 num_params_needed = {6};
752
753 for (auto n: num_params_needed) {
754 if (params.size() == n) {
755 if (n == 6) {
756 obj = std::make_shared<util::geometry::Rectangle>(
757 util::Point(params[0], params[1], params[2]),
758 util::Point(params[3], params[4], params[5]));
759
760 return;
761 }
762 } // if params.size() == n
763 } // loop over n
764 } // angled_rectangle
765 else if (geom_type == "angled_cuboid") {
766
767 num_params_needed = {6};
768
769 for (auto n: num_params_needed) {
770 if (params.size() == n) {
771 if (n == 6) {
772 obj = std::make_shared<util::geometry::Cuboid>(
773 util::Point(params[0], params[1], params[2]),
774 util::Point(params[3], params[4], params[5]));
775
776 return;
777 }
778 } // if params.size() == n
779 } // loop over n
780 } // angled_cuboid
781 else if (geom_type == "rectangle_minus_rectangle") {
782
783 num_params_needed = {12};
784
785 for (auto n: num_params_needed) {
786 if (params.size() == n) {
787 if (n == 12) {
788
789 auto rin = new util::geometry::Rectangle(
790 util::Point(params[0], params[1], params[2]),
791 util::Point(params[3], params[4], params[5]));
792 auto rout = new util::geometry::Rectangle(
793 util::Point(params[6], params[7], params[8]),
794 util::Point(params[9], params[10], params[11]));
795
796 obj = std::make_shared<util::geometry::AnnulusGeomObject>
797 (rin, rout, 2);
798
799 return;
800 }
801 } // if params.size() == n
802 } // loop over n
803 } // rectangle_minus_rectangle
804 else if (geom_type == "cuboid_minus_cuboid") {
805
806 num_params_needed = {12};
807
808 for (auto n: num_params_needed) {
809 if (params.size() == n) {
810 if (n == 12) {
811
812 auto rin = new util::geometry::Cuboid(
813 util::Point(params[0], params[1], params[2]),
814 util::Point(params[3], params[4], params[5]));
815 auto rout = new util::geometry::Cuboid(
816 util::Point(params[6], params[7], params[8]),
817 util::Point(params[9], params[10], params[11]));
818
819 obj = std::make_shared<util::geometry::AnnulusGeomObject>
820 (rin, rout, 3);
821
822 return;
823 }
824 } // if params.size() == n
825 } // loop over n
826 } // rectangle_minus_rectangle
827 else if (geom_type == "complex") {
828
829 /*
830 std::cout << "vec_type = " << util::io::printStr(vec_type, 0)
831 << ", vec_flag = " << util::io::printStr(vec_flag, 0)
832 << "\n";
833 */
834
835 num_params_needed = {0};
836 std::vector<size_t> params_level(vec_type.size());
837 for (size_t i = 0; i < vec_type.size(); i++) {
838
839 // only consider the biggest parameter set from the list
840 auto nps = getNumParamsRequired(vec_type[i]);
841 if (nps.size() > 0)
842 params_level[i] = nps[nps.size() - 1];
843 else {
844 std::cerr << "Error: Geometry type = " << vec_type[i]
845 << " has zero number of parameters required. \n";
846 exit(EXIT_FAILURE);
847 }
848
849 //std::cout << "Geom type = " << vec_type[i]
850 // << ", params required = " << params_level[i] << "\n";
851
852 num_params_needed[0] += params_level[i];
853 }
854
855 std::vector<std::shared_ptr<util::geometry::GeomObject>> objs(vec_type.size());
856 std::vector<std::string> obj_flags(vec_type.size());
857
858 if (params.size() == num_params_needed[0]) {
859
860 // loop over objects and create
861 size_t param_start = 0;
862 for (size_t i = 0; i < vec_type.size(); i++) {
863
864 auto geom_type_temp = vec_type[i];
865 auto geom_flag_temp = vec_flag[i];
866
867 std::vector<std::string> vec_type_temp;
868 std::vector<std::string> vec_flag_temp;
869
870 // find what range of parameters we need to provide
871 std::vector<double> params_temp;
872 for (size_t j=0; j<params_level[i]; j++)
873 params_temp.push_back(params[j + param_start]);
874
875 // call this function recursively
876 obj_flags[i] = vec_flag[i];
878 geom_type_temp, params_temp, vec_type_temp, vec_flag_temp,
879 objs[i], dim, perform_check);
880
881 param_start += params_level[i];
882 } // loop over objects
883
884 // now create a composite object
885 obj = std::make_shared<util::geometry::ComplexGeomObject>(objs, obj_flags, dim);
886
887 return;
888 } // if params.size() == n
889 } // complex
890 else {
891 std::cerr << "Error: Invalid geometry type: " << geom_type << std::endl;
892 exit(1);
893 }
894
895
896 std::cerr << printErrMsg(geom_type, params, num_params_needed);
897 exit(1);
898 }
899
901 const size_t &dim,
902 bool perform_check) {
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 }
909
911 z.d_geomName = d_geomName;
912 z.d_geomParams = d_geomParams;
913 z.d_geomComplexInfo = d_geomComplexInfo;
914
915 if (d_geom_p->d_name == "null") {
916 z.d_geom_p =
917 std::make_shared<util::geometry::NullGeomObject>(
918 d_geom_p->d_description);
919 } else if (d_geom_p->d_name.empty()) {
920 z.d_geom_p =
921 std::make_shared<util::geometry::GeomObject>(
922 d_geom_p->d_name, d_geom_p->d_description);
923 } else {
925 }
926 }
927
929 std::vector<double> &params,
930 std::pair<std::vector<std::string>, std::vector<std::string>> &complexInfo,
931 std::shared_ptr<util::geometry::GeomObject> &geom,
932 size_t dim) {
933 name = d_geomName;
934 params = d_geomParams;
935 complexInfo = d_geomComplexInfo;
936
937 if (d_geom_p->d_name == "null") {
938 geom =
939 std::make_shared<util::geometry::NullGeomObject>(
940 d_geom_p->d_description);
941 } else if (d_geom_p->d_name.empty()) {
942 geom =
943 std::make_shared<util::geometry::GeomObject>(
944 d_geom_p->d_name, d_geom_p->d_description);
945 } else {
947 params,
948 complexInfo.first,
949 complexInfo.second,
950 geom, dim);
951 }
952 }
953
954}// 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.