PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
geomObjects.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 "geomObjects.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
35//
36// Line
37//
38namespace util {
40 return d_L;
41 }
42
44 return d_x;
45 }
46
47 std::pair<util::Point, util::Point> util::geometry::Line::box() const {
48
49 return box(0.);
50 }
51
52 std::pair<util::Point, util::Point> util::geometry::Line::box(const
53 double &tol) const {
54
55 return {d_vertices[0] - tol, d_vertices[1] + tol};
56 }
57
59
60 return d_r;
61 }
62
64
65 return d_r;
66 }
67
69
70 auto da = (d_vertices[1] - d_vertices[0]) / d_L;
71 auto db = x - d_vertices[0];
72 double dot = db * da;
73
74 if (util::isLess(dot, 0.) or util::isGreater(dot, d_L))
75 return false;
76
77
78 auto dx = db - dot * da;
79
80 return util::isLess(dx.length(), 1.0E-10);
81 }
82
84
85 return !isInside(x);
86 }
87
89 const double &tol) const {
90
91 auto da = (d_vertices[1] - d_vertices[0]) / d_L;
92 auto db = x - d_vertices[0];
93 double dot = db * da;
94
95 if (util::isLess(dot, 0.) or util::isGreater(dot, d_L))
96 return false;
97
98 auto dx = db - dot * da;
99
100 return util::isLess(dx.length(), tol);
101 }
102
104 const double &tol, const bool
105 &within) const {
106
107 // check if particle is inside the object
108 if (!isNear(x, within ? 0. : tol))
109 return false;
110
111 auto da = (d_vertices[1] - d_vertices[0]) / d_L;
112 auto db = x - d_vertices[0];
113 double dot = db * da;
114
115 if (util::isLess(dot, 0.) or util::isGreater(dot, tol)
116 or util::isGreater(dot, d_L) or util::isLess(dot, d_L - tol))
117 return false;
118
119 auto dx = db - dot * da;
120
121 return util::isLess(dx.length(), tol);
122 }
123
125
126 return isNearBoundary(x, 1.0E-8, false);
127 }
128
130 const std::pair<util::Point, util::Point> &box) const {
131
132 return false;
133 }
134
136 const std::pair<util::Point, util::Point> &box) const {
137
138 return true;
139 }
140
142 const std::pair<util::Point, util::Point> &box,
143 const double &tol) const {
144
145 return true;
146 }
147
149 const std::pair<util::Point, util::Point> &box) const {
150
151 return false;
152 }
153
154 std::string util::geometry::Line::printStr(int nt, int lvl) const {
155
156 auto tabS = util::io::getTabS(nt);
157
158 std::ostringstream oss;
159
160 oss << tabS << "------- Line --------" << std::endl << std::endl;
161 oss << tabS << "Name = " << d_name << std::endl;
162 oss << tabS << "Length = " << d_L << std::endl;
163 oss << tabS << "Point 1 = " << d_vertices[0].printStr(0, lvl) << std::endl;
164 oss << tabS << "Point 2 = " << d_vertices[1].printStr(0, lvl) << std::endl;
165 oss << std::endl;
166
167 if (lvl > 0)
168 oss << tabS << "Bounding box: "
169 << util::io::printBoxStr(box(0.), nt + 1);
170
171 if (lvl == 0)
172 oss << std::endl;
173
174 return oss.str();
175 }
176} //Line
177
178//
179// Triangle
180//
181namespace util {
183 return d_r * d_r * (1. + std::sin(M_PI / 3));
184 }
185
187 return d_x;
188 }
189
190 std::pair<util::Point, util::Point> util::geometry::Triangle::box() const {
191
192 return box(0.);
193 }
194
195 std::pair<util::Point, util::Point> util::geometry::Triangle::box(const
196 double &tol) const {
197
198 // find lower and upper coordinates
199 auto p1 = util::Point(d_x.d_x - d_r, d_x.d_y - d_r, d_x.d_z);
200 auto p2 = util::Point(d_x.d_x + d_r, d_x.d_y + d_r, d_x.d_z);
201
202 return {p1 - tol, p2 + tol};
203 }
204
206
207 return d_r * std::sin(M_PI / 3);
208 }
209
211
212 return d_r;
213 }
214
216
217 if ((x - d_x).length() > d_r)
218 return false;
219
220 if ((x - d_x).length() < this->inscribedRadius())
221 return true;
222
223 double a = this->volume();
224 double a1 =
225 std::abs(util::triangleArea(x, d_vertices[1], d_vertices[2]));
226 double a2 =
227 std::abs(util::triangleArea(d_vertices[0], x, d_vertices[2]));
228 double a3 =
229 std::abs(util::triangleArea(d_vertices[0], d_vertices[1], x));
230
231 return (a1 + a2 + a3 < a);
232 }
233
235 return !isInside(x);
236 }
237
239 const double &tol) const {
240
241 // get a bigger box containing this object
242 auto bbox = box(tol);
243
244 return util::isPointInsideBox(x, 2, bbox);
245 }
246
248 const double &tol, const bool
249 &within) const {
250
251 // check if particle is inside the object
252 if (!isNear(x, within ? 0. : tol))
253 return false;
254
255 double a = this->volume();
256 double l = 0.5 * std::sqrt(a);
257
258 double a1 =
259 std::abs(util::triangleArea(x, d_vertices[1], d_vertices[2]));
260 if (a1 < tol * l)
261 return true;
262
263 double a2 =
264 std::abs(util::triangleArea(d_vertices[0], x, d_vertices[2]));
265 if (a2 < tol * l)
266 return true;
267
268 double a3 =
269 std::abs(util::triangleArea(d_vertices[0], d_vertices[1], x));
270 if (a3 < tol * l)
271 return true;
272
273 return false;
274 }
275
277
278 return isNearBoundary(x, 1.0E-8, false);
279 }
280
282 const std::pair<util::Point, util::Point> &box) const {
283
284 for (auto p: util::getCornerPoints(2, box))
285 if (!this->isInside(p))
286 return false;
287
288 return true;
289 }
290
292 const std::pair<util::Point, util::Point> &box) const {
293
294 bool intersect = false;
295 for (auto p: util::getCornerPoints(2, box))
296 if (!intersect)
297 intersect = this->isInside(p);
298
299 return !intersect;
300 }
301
303 const std::pair<util::Point, util::Point> &box,
304 const double &tol) const {
305
306 return util::areBoxesNear(this->box(), box, tol, 2);
307 }
308
310 const std::pair<util::Point, util::Point> &box) const {
311
312 // need to check all four corner points
313 for (auto p: util::getCornerPoints(2, box))
314 if (this->isInside(p))
315 return true;
316
317 return false;
318 }
319
320 std::string util::geometry::Triangle::printStr(int nt, int lvl) const {
321
322 auto tabS = util::io::getTabS(nt);
323
324 std::ostringstream oss;
325
326 oss << tabS << "------- Triangle --------" << std::endl << std::endl;
327 oss << tabS << "Name = " << d_name << std::endl;
328 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
329 oss << tabS << "Radius = " << d_r << std::endl;
330 oss << tabS << "Vertices = " << util::io::printStr(d_vertices)
331 << std::endl;
332 oss << std::endl;
333
334 if (lvl == 0)
335 oss << std::endl;
336
337 return oss.str();
338 }
339}// Triangle
340
341//
342// Square
343//
344namespace util {
346 return std::pow(d_L, 2);
347 }
348
350 return d_x;
351 }
352
353 std::pair<util::Point, util::Point> util::geometry::Square::box() const {
354
355 return box(0.);
356 }
357 std::pair<util::Point, util::Point> util::geometry::Square::box(const
358 double &tol) const {
359
360 return {util::Point(d_vertices[0].d_x - tol, d_vertices[0].d_y - tol,
361 0.),
362 util::Point(d_vertices[2].d_x + tol, d_vertices[2].d_y + tol,
363 0.)};
364 }
365
367
368 return 0.5*d_L;
369 }
370
372
373 return d_r;
374 }
375
377 return util::isPointInsideRectangle(x, d_vertices[0], d_vertices[2]);
378 }
379
381 return !isInside(x);
382 }
383
385 const double &tol) const {
386
387 // get a bigger box containing this object
388 auto bbox = box(tol);
389
390 return util::isPointInsideBox(x, 2, bbox);
391 }
392
394 const double &tol, const bool
395 &within) const {
396
397 // check if particle is inside the object
398 if (!isNear(x, within ? 0. : tol))
399 return false;
400
401 bool near_x_edge = util::isLess(std::abs(x.d_x - d_vertices[0].d_x), tol) or
402 util::isLess(std::abs(x.d_x - d_vertices[2].d_x), tol);
403
404 bool near_y_edge = util::isLess(std::abs(x.d_y - d_vertices[0].d_y), tol) or
405 util::isLess(std::abs(x.d_y - d_vertices[2].d_y), tol);
406
407 return near_x_edge || near_y_edge;
408 }
409
411
412 return isNearBoundary(x, 1.0E-8, false);
413 }
414
416 const std::pair<util::Point, util::Point> &box) const {
417
418 for (auto p : util::getCornerPoints(2, box))
419 if(!this->isInside(p))
420 return false;
421
422 return true;
423 }
424
426 const std::pair<util::Point, util::Point> &box) const {
427
428 bool intersect = false;
429 for (auto p : util::getCornerPoints(2, box))
430 if (!intersect)
431 intersect = this->isInside(p);
432
433 return !intersect;
434 }
435
437 const std::pair<util::Point, util::Point> &box, const double &tol) const {
438
439 return util::areBoxesNear(this->box(), box, tol, 2);
440 }
441
443 const std::pair<util::Point, util::Point> &box) const {
444
445 // need to check all four corner points
446 for (auto p : util::getCornerPoints(2, box))
447 if (this->isInside(p))
448 return true;
449
450 return false;
451 }
452
453 std::string util::geometry::Square::printStr(int nt, int lvl) const {
454
455 auto tabS = util::io::getTabS(nt);
456
457 std::ostringstream oss;
458
459 oss << tabS << "------- Rectangle --------" << std::endl << std::endl;
460 oss << tabS << "Name = " << d_name << std::endl;
461 oss << tabS << "Length = " << d_L << std::endl;
462 oss << tabS << "Bounding radius = " << d_r << std::endl;
463 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
464 oss << tabS << "Vertices = " << util::io::printStr(d_vertices, 0) << std::endl;
465 oss << std::endl;
466
467 if (lvl > 0)
468 oss << tabS << "Bounding box: " << util::io::printBoxStr(box(0.), nt + 1);
469
470 if (lvl == 0)
471 oss << std::endl;
472
473 return oss.str();
474 }
475}// Square
476
477//
478// Rectangle
479//
480namespace util {
482 return d_Lx * d_Ly;
483 }
484
486 return d_x;
487 }
488
489 std::pair<util::Point, util::Point> util::geometry::Rectangle::box() const {
490
491 return box(0.);
492 }
493
494 std::pair<util::Point, util::Point> util::geometry::Rectangle::box(const
495 double &tol) const {
496
497 return {util::Point(d_vertices[0].d_x - tol, d_vertices[0].d_y - tol,
498 0.),
499 util::Point(d_vertices[2].d_x + tol, d_vertices[2].d_y + tol,
500 0.)};
501 }
502
504
505 return util::isLess(d_Lx, d_Ly) ? d_Lx : d_Ly;
506 }
507
509
510 return d_r;
511 }
512
514 return util::isPointInsideRectangle(x, d_vertices[0], d_vertices[2]);
515 }
516
518 return !isInside(x);
519 }
520
522 const double &tol) const {
523
524 // get a bigger box containing this object
525 auto bbox = box(tol);
526
527 return util::isPointInsideBox(x, 2, bbox);
528 }
529
531 const double &tol, const bool
532 &within) const {
533
534 // check if particle is inside the object
535 if (!isNear(x, within ? 0. : tol))
536 return false;
537
538 bool near_x_edge = util::isLess(std::abs(x.d_x - d_vertices[0].d_x), tol) or
539 util::isLess(std::abs(x.d_x - d_vertices[2].d_x), tol);
540
541 bool near_y_edge = util::isLess(std::abs(x.d_y - d_vertices[0].d_y), tol) or
542 util::isLess(std::abs(x.d_y - d_vertices[2].d_y), tol);
543
544 return near_x_edge || near_y_edge;
545 }
546
548
549 return isNearBoundary(x, 1.0E-8, false);
550 }
551
553 const std::pair<util::Point, util::Point> &box) const {
554
555 for (auto p: util::getCornerPoints(2, box))
556 if (!this->isInside(p))
557 return false;
558
559 return true;
560 }
561
563 const std::pair<util::Point, util::Point> &box) const {
564
565 bool intersect = false;
566 for (auto p: util::getCornerPoints(2, box))
567 if (!intersect)
568 intersect = this->isInside(p);
569
570 return !intersect;
571 }
572
574 const std::pair<util::Point, util::Point> &box,
575 const double &tol) const {
576
577 return util::areBoxesNear(this->box(), box, tol, 2);
578 }
579
581 const std::pair<util::Point, util::Point> &box) const {
582
583 // need to check all four corner points
584 for (auto p: util::getCornerPoints(2, box))
585 if (this->isInside(p))
586 return true;
587
588 return false;
589 }
590
591 std::string util::geometry::Rectangle::printStr(int nt, int lvl) const {
592
593 auto tabS = util::io::getTabS(nt);
594
595 std::ostringstream oss;
596
597 oss << tabS << "------- Rectangle --------" << std::endl << std::endl;
598 oss << tabS << "Name = " << d_name << std::endl;
599 oss << tabS << "Lengths (Lx, Ly) = (" << d_Lx << ", " << d_Ly << ")" << std::endl;
600 oss << tabS << "Bounding circle radius = " << d_r << std::endl;
601 oss << tabS << "Vertices = " << util::io::printStr(d_vertices, 0) << std::endl;
602 oss << std::endl;
603
604 if (lvl > 0)
605 oss << tabS << "Bounding box: "
606 << util::io::printBoxStr(box(0.), nt + 1);
607
608 if (lvl == 0)
609 oss << std::endl;
610
611 return oss.str();
612 }
613}// Rectangle
614
615//
616// Hexagon
617//
618namespace util {
620 // https://en.wikipedia.org/wiki/Hexagon
621 double r_small = this->inscribedRadius();
622 return 2. * std::sqrt(3.) * r_small * r_small;
623 }
624
626 return d_x;
627 }
628
629 std::pair<util::Point, util::Point> util::geometry::Hexagon::box() const {
630
631 return box(0.);
632 }
633
634 std::pair<util::Point, util::Point> util::geometry::Hexagon::box(const
635 double &tol) const {
636
637 auto p1 = d_x - util::Point(d_r + tol, d_r + tol, d_x[2] + tol);
638 auto p2 = d_x + util::Point(d_r + tol, d_r + tol, d_x[2] + tol);
639 return {p1, p2};
640 }
641
643
644 return d_r * 0.5 * std::sqrt(3.);
645 }
646
648
649 return d_r;
650 }
651
653
654 if ((x - d_x).length() > d_r)
655 return false;
656
657 if ((x - d_x).length() < inscribedRadius())
658 return true;
659
660 return false;
661 }
662
664 return !isInside(x);
665 }
666
668 const double &tol) const {
669
670 // get a bigger box containing this object
671 auto bbox = box(tol);
672
673 return util::isPointInsideBox(x, 2, bbox);
674 }
675
677 const double &tol, const bool
678 &within) const {
679
680 if ((x - d_x).length() > d_r + tol)
681 return false;
682
683 if ((x - d_x).length() < inscribedRadius() - tol)
684 return false;
685
686 return true;
687 }
688
690
691 return isNearBoundary(x, 1.0E-8, false);
692 }
693
695 const std::pair<util::Point, util::Point> &box) const {
696
697 for (auto p: util::getCornerPoints(2, box))
698 if (!this->isInside(p))
699 return false;
700
701 return true;
702 }
703
705 const std::pair<util::Point, util::Point> &box) const {
706
707 bool intersect = false;
708 for (auto p: util::getCornerPoints(2, box))
709 if (!intersect)
710 intersect = this->isInside(p);
711
712 return !intersect;
713 }
714
716 const std::pair<util::Point, util::Point> &box,
717 const double &tol) const {
718
719 return util::areBoxesNear(this->box(), box, tol, 2);
720 }
721
723 const std::pair<util::Point, util::Point> &box) const {
724
725 // need to check all four corner points
726 for (auto p: util::getCornerPoints(2, box))
727 if (this->isInside(p))
728 return true;
729
730 return false;
731 }
732
733 std::string util::geometry::Hexagon::printStr(int nt, int lvl) const {
734
735 auto tabS = util::io::getTabS(nt);
736
737 std::ostringstream oss;
738
739 oss << tabS << "------- Hexagon --------" << std::endl << std::endl;
740 oss << tabS << "Name = " << d_name << std::endl;
741 oss << tabS << "Radius = " << d_r << std::endl;
742 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
743 oss << tabS << "Axis = " << d_a.printStr(0, lvl) << std::endl;
744 oss << tabS << "Vertices = " << util::io::printStr(d_vertices, lvl) <<
745 std::endl;
746 oss << std::endl;
747
748 if (lvl == 0)
749 oss << std::endl;
750
751 return oss.str();
752 }
753}// Hexagon
754
755//
756// Drum2D
757//
758namespace util {
760
761 return (2. * d_r * d_r - d_r * (d_r - 2. * d_w)) * std::sin(M_PI / 3.);
762 }
763
765 return d_x;
766 }
767
768 std::pair<util::Point, util::Point> util::geometry::Drum2D::box() const {
769
770 return box(0.);
771 }
772
773 std::pair<util::Point, util::Point> util::geometry::Drum2D::box(const
774 double &tol) const {
775
776 auto p1 = d_x - util::Point(d_r + tol, d_r + tol, d_x[2] + tol);
777 auto p2 = d_x + util::Point(d_r + tol, d_r + tol, d_x[2] + tol);
778 return {p1, p2};
779 }
780
782
783 return d_w;
784 }
785
787
788 return d_r;
789 }
790
792
793 if ((x - d_x).length() > d_r)
794 return false;
795
796 if ((x - d_x).length() < inscribedRadius())
797 return true;
798
799 // rotate axis to get orthogonal axis
800 auto ortho_axis = util::rotate(d_a, M_PI * 0.5, util::Point(0., 0., 1.));
801
802 //
803 // + v2
804 // /
805 // / x
806 // /
807 // /
808 // o----+v1
809 //
810 auto ox = x - d_x;
811 double angle_ox_ov1 = std::acos(std::abs(d_a.dot(ox)) / ox.length());
812 double max_length = d_w + angle_ox_ov1 * (d_r - d_w) / (M_PI / 3.);
813
814 return ox.length() <= max_length;
815 }
816
818 return !isInside(x);
819 }
820
822 const double &tol) const {
823
824 // get a bigger box containing this object
825 auto bbox = box(tol);
826
827 return util::isPointInsideBox(x, 2, bbox);
828 }
829
831 const double &tol, const bool
832 &within) const {
833
834 if ((x - d_x).length() > d_r + tol)
835 return false;
836
837 if ((x - d_x).length() < this->inscribedRadius() - tol)
838 return false;
839
840 return true;
841 }
842
844
845 return isNearBoundary(x, 1.0E-8, false);
846 }
847
849 const std::pair<util::Point, util::Point> &box) const {
850
851 for (auto p: util::getCornerPoints(2, box))
852 if (!this->isInside(p))
853 return false;
854
855 return true;
856 }
857
859 const std::pair<util::Point, util::Point> &box) const {
860
861 bool intersect = false;
862 for (auto p: util::getCornerPoints(2, box))
863 if (!intersect)
864 intersect = this->isInside(p);
865
866 return !intersect;
867 }
868
870 const std::pair<util::Point, util::Point> &box,
871 const double &tol) const {
872
873 return util::areBoxesNear(this->box(), box, tol, 2);
874 }
875
877 const std::pair<util::Point, util::Point> &box) const {
878
879 // need to check all four corner points
880 for (auto p: util::getCornerPoints(2, box))
881 if (this->isInside(p))
882 return true;
883
884 return false;
885 }
886
887 std::string util::geometry::Drum2D::printStr(int nt, int lvl) const {
888
889 auto tabS = util::io::getTabS(nt);
890
891 std::ostringstream oss;
892
893 oss << tabS << "------- Drum2D --------" << std::endl << std::endl;
894 oss << tabS << "Name = " << d_name << std::endl;
895 oss << tabS << "Radius = " << d_r << std::endl;
896 oss << tabS << "Neck half-width = " << d_w << std::endl;
897 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
898 oss << tabS << "Axis = " << d_a.printStr(0, lvl) << std::endl;
899 oss << tabS << "Vertices = " << util::io::printStr(d_vertices, lvl) <<
900 std::endl;
901 oss << std::endl;
902
903 if (lvl == 0)
904 oss << std::endl;
905
906 return oss.str();
907 }
908}// Drum2D
909
910//
911// Cube
912//
913namespace util {
915 return std::pow(d_L, 3);
916 }
917
919 return d_x;
920 }
921
922 std::pair<util::Point, util::Point> util::geometry::Cube::box() const {
923
924 return box(0.);
925 }
926
927 std::pair<util::Point, util::Point> util::geometry::Cube::box(const
928 double &tol) const {
929 return {util::Point(d_vertices[0].d_x - tol, d_vertices[0].d_y - tol,
930 d_vertices[0].d_z - tol),
931 util::Point(d_vertices[6].d_x + tol, d_vertices[6].d_y + tol,
932 d_vertices[6].d_z + tol)};
933 }
934
936
937 return d_L;
938 }
939
941
942 return d_r;
943 }
944
946 return util::isPointInsideCuboid(x, d_vertices[0], d_vertices[6]);
947 }
948
950 return !isInside(x);
951 }
952
954 const double &tol) const {
955
956 // get a bigger box containing this object
957 auto bbox = box(tol);
958
959 return util::isPointInsideBox(x, 3, bbox);
960 }
961
963 const double &tol, const bool
964 &within) const {
965
966 // check if particle is within the tolerance distance
967 if (!isNear(x, within ? 0. : tol))
968 return false;
969
970 bool near_x_edge = util::isLess(std::abs(x.d_x - d_vertices[0].d_x), tol) or
971 util::isLess(std::abs(x.d_x - d_vertices[6].d_x), tol);
972
973 bool near_y_edge = util::isLess(std::abs(x.d_y - d_vertices[0].d_y), tol) or
974 util::isLess(std::abs(x.d_y - d_vertices[6].d_y), tol);
975
976 bool near_z_edge = util::isLess(std::abs(x.d_z - d_vertices[0].d_z), tol) or
977 util::isLess(std::abs(x.d_z - d_vertices[6].d_z), tol);
978
979 return near_x_edge || near_y_edge || near_z_edge;
980 }
981
983
984 return isNearBoundary(x, 1.0E-8, false);
985 }
986
988 const std::pair<util::Point, util::Point> &box) const {
989
990 for (auto p: util::getCornerPoints(3, box))
991 if (!this->isInside(p))
992 return false;
993
994 return true;
995 }
996
998 const std::pair<util::Point, util::Point> &box) const {
999
1000 bool intersect = false;
1001 for (auto p: util::getCornerPoints(3, box))
1002 if (!intersect)
1003 intersect = this->isInside(p);
1004
1005 return !intersect;
1006 }
1007
1009 const std::pair<util::Point, util::Point> &bbox, const double &tol)
1010 const {
1011
1012 return util::areBoxesNear(box(), bbox, tol, 3);
1013 }
1014
1016 const std::pair<util::Point, util::Point> &box) const {
1017
1018 // need to check all four corner points
1019 for (auto p: util::getCornerPoints(3, box))
1020 if (this->isInside(p))
1021 return true;
1022
1023 return false;
1024 }
1025
1026 std::string util::geometry::Cube::printStr(int nt, int lvl) const {
1027
1028 auto tabS = util::io::getTabS(nt);
1029
1030 std::ostringstream oss;
1031
1032 oss << tabS << "------- Cube --------" << std::endl << std::endl;
1033 oss << tabS << "Name = " << d_name << std::endl;
1034 oss << tabS << "Length = " << d_L << std::endl;
1035 oss << tabS << "Bounding sphere radius = " << d_r << std::endl;
1036 oss << tabS << "Center = " << d_x.printStr(0, 0) << std::endl;
1037 oss << tabS << "Vertices = " << util::io::printStr(d_vertices, 0) << std::endl;
1038 oss << std::endl;
1039
1040 if (lvl > 0)
1041 oss << tabS << "Bounding box: "
1042 << util::io::printBoxStr(box(0.), nt + 1);
1043
1044 if (lvl == 0)
1045 oss << std::endl;
1046
1047 return oss.str();
1048 }
1049}// Cube
1050
1051//
1052// Cuboid
1053//
1054namespace util {
1056 return d_Lx * d_Ly * d_Lz;
1057 }
1058
1060 return d_x;
1061 }
1062
1063 std::pair<util::Point, util::Point> util::geometry::Cuboid::box() const {
1064
1065 return box(0.);
1066 }
1067
1068 std::pair<util::Point, util::Point> util::geometry::Cuboid::box(const
1069 double &tol) const {
1070 return {util::Point(d_vertices[0].d_x - tol, d_vertices[0].d_y - tol,
1071 d_vertices[0].d_z - tol),
1072 util::Point(d_vertices[6].d_x + tol, d_vertices[6].d_y + tol,
1073 d_vertices[6].d_z + tol)};
1074 }
1075
1077
1078 auto l = util::isLess(d_Lx, d_Ly) ? d_Lx : d_Ly;
1079 return util::isLess(l, d_Lz) ? l : d_Lz;
1080 }
1081
1083
1084 return d_r;
1085 }
1086
1088 return util::isPointInsideCuboid(x, d_vertices[0], d_vertices[6]);
1089 }
1090
1092 return !isInside(x);
1093 }
1094
1096 const double &tol) const {
1097
1098 // get a bigger box containing this object
1099 auto bbox = box(tol);
1100
1101 return util::isPointInsideBox(x, 3, bbox);
1102 }
1103
1105 const double &tol, const bool
1106 &within) const {
1107
1108 // check if particle is within the tolerance distance
1109 if (!isNear(x, within ? 0. : tol))
1110 return false;
1111
1112 bool near_x_edge = util::isLess(std::abs(x.d_x - d_vertices[0].d_x), tol) or
1113 util::isLess(std::abs(x.d_x - d_vertices[6].d_x), tol);
1114
1115 bool near_y_edge = util::isLess(std::abs(x.d_y - d_vertices[0].d_y), tol) or
1116 util::isLess(std::abs(x.d_y - d_vertices[6].d_y), tol);
1117
1118 bool near_z_edge = util::isLess(std::abs(x.d_z - d_vertices[0].d_z), tol) or
1119 util::isLess(std::abs(x.d_z - d_vertices[6].d_z), tol);
1120
1121 return near_x_edge || near_y_edge || near_z_edge;
1122 }
1123
1125
1126 return isNearBoundary(x, 1.0E-8, false);
1127 }
1128
1130 const std::pair<util::Point, util::Point> &box) const {
1131
1132 for (auto p: util::getCornerPoints(3, box))
1133 if (!this->isInside(p))
1134 return false;
1135
1136 return true;
1137 }
1138
1140 const std::pair<util::Point, util::Point> &box) const {
1141
1142 bool intersect = false;
1143 for (auto p: util::getCornerPoints(3, box))
1144 if (!intersect)
1145 intersect = this->isInside(p);
1146
1147 return !intersect;
1148 }
1149
1151 const std::pair<util::Point, util::Point> &bbox, const double &tol)
1152 const {
1153
1154 return util::areBoxesNear(box(), bbox, tol, 3);
1155 }
1156
1158 const std::pair<util::Point, util::Point> &box) const {
1159
1160 // need to check all four corner points
1161 for (auto p: util::getCornerPoints(3, box))
1162 if (this->isInside(p))
1163 return true;
1164
1165 return false;
1166 }
1167
1168 std::string util::geometry::Cuboid::printStr(int nt, int lvl) const {
1169
1170 auto tabS = util::io::getTabS(nt);
1171
1172 std::ostringstream oss;
1173
1174 oss << tabS << "------- Cuboid --------" << std::endl << std::endl;
1175 oss << tabS << "Name = " << d_name << std::endl;
1176 oss << tabS << "Lengths (Lx, Ly, Lz) = "
1177 << util::io::printStr(std::vector<double>{d_Lx, d_Ly, d_Lz}, 0)
1178 << std::endl;
1179 oss << tabS << "Bounding sphere radius = " << d_r << std::endl;
1180 oss << tabS << "Center = " << d_x.printStr(0, 0) << std::endl;
1181 oss << tabS << "Vertices = " << util::io::printStr(d_vertices, 0) << std::endl;
1182 oss << std::endl;
1183
1184 if (lvl > 0)
1185 oss << tabS << "Bounding box: "
1186 << util::io::printBoxStr(box(0.), nt + 1);
1187
1188 if (lvl == 0)
1189 oss << std::endl;
1190
1191 return oss.str();
1192 }
1193}// Cuboid
1194
1195//
1196// Circle
1197//
1198namespace util {
1200 return M_PI * d_r * d_r;
1201 }
1202
1204 return d_x;
1205 }
1206
1207 std::pair<util::Point, util::Point> util::geometry::Circle::box() const {
1208
1209 return box(0.);
1210 }
1211
1212 std::pair<util::Point, util::Point> util::geometry::Circle::box(const
1213 double &tol) const {
1214 double r = d_r + tol;
1215 return {
1216 util::Point(d_x.d_x - r, d_x.d_y - r, 0.),
1217 util::Point(d_x.d_x + r, d_x.d_y + r, 0.)
1218 };
1219 }
1220
1222
1223 return d_r;
1224 }
1225
1227
1228 return d_r;
1229 }
1230
1232
1233 return util::isLess(d_x.dist(x), d_r + 1.0E-12);
1234 }
1235
1237 return !isInside(x);
1238 }
1239
1241 const double &tol) const {
1242
1243 // translate to origin
1244 auto x0 = x - d_x;
1245
1246 return util::isLess(x0.length(), d_r + tol);
1247 }
1248
1250 const double &tol, const bool
1251 &within) const {
1252
1253 // check if particle is within the tolerance distance
1254 if (!isNear(x, within ? 0. : tol))
1255 return false;
1256
1257 // check if it is close enough to circumference
1258 auto x0 = x - d_x;
1259
1260 return util::isLess(x0.length(), d_r + tol) ||
1261 util::isLess(x0.length(), d_r - tol);
1262 }
1263
1265
1266 return isNearBoundary(x, 1.0E-8, false);
1267 }
1268
1270 const std::pair<util::Point, util::Point> &box) const {
1271
1272 for (auto p: util::getCornerPoints(2, box))
1273 if (!this->isInside(p))
1274 return false;
1275
1276 return true;
1277 }
1278
1280 const std::pair<util::Point, util::Point> &box) const {
1281
1282 bool intersect = false;
1283 for (auto p: util::getCornerPoints(2, box))
1284 if (!intersect)
1285 intersect = this->isInside(p);
1286
1287 return !intersect;
1288 }
1289
1291 const std::pair<util::Point, util::Point> &box,
1292 const double &tol) const {
1293
1294 if (this->isInside(box))
1295 return true;
1296
1297 // get corner points of box
1298 auto cp = getCornerPoints(2, box);
1299
1300 for (auto p: cp) {
1301
1302 // check the distance of corner point with the center
1303 auto dx = p - d_x;
1304 if (util::isLess(dx.length(), d_r + tol))
1305 return true;
1306 }
1307
1308 // check center to center distance
1309 auto dxc = util::getCenter(2, box) - d_x;
1310
1311 // check wrt inscribed circle
1312 auto r = util::inscribedRadiusInBox(2, box);
1313 if (util::isLess(dxc.length(), d_r + r + tol))
1314 return true;
1315
1316 // check wrt circumscribed circle
1318 return util::isLess(dxc.length(), d_r + r + tol);
1319 }
1320
1322 const std::pair<util::Point, util::Point> &box) const {
1323
1324 // need to check all four corner points
1325 for (auto p: util::getCornerPoints(2, box))
1326 if (this->isInside(p))
1327 return true;
1328
1329 return false;
1330 }
1331
1332 std::string util::geometry::Circle::printStr(int nt, int lvl) const {
1333
1334 auto tabS = util::io::getTabS(nt);
1335
1336 std::ostringstream oss;
1337
1338 oss << tabS << "------- Circle --------" << std::endl << std::endl;
1339 oss << tabS << "Name = " << d_name << std::endl;
1340 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
1341 oss << tabS << "Radius = " << d_r << std::endl;
1342
1343 if (lvl > 0)
1344 oss << tabS << "Bounding box: "
1345 << util::io::printBoxStr(box(0.), nt + 1);
1346
1347 if (lvl == 0)
1348 oss << std::endl;
1349
1350 return oss.str();
1351 }
1352}// Circle
1353
1354//
1355// Cylinder
1356//
1357namespace util {
1359 return M_PI * d_r * d_r * d_l;
1360 }
1361
1363 return d_x;
1364 }
1365
1366 std::pair<util::Point, util::Point> util::geometry::Cylinder::box() const {
1367
1368 return box(0.);
1369 }
1370
1371 std::pair<util::Point, util::Point>
1372 util::geometry::Cylinder::box(const double &tol) const {
1373
1374 if (d_xa.length() < 1.0E-10)
1375 return {util::Point(), util::Point()};
1376
1377 auto xb = d_xBegin - tol * d_xa;
1378 auto xt = d_xBegin + (d_l + tol) * d_xa;
1379
1380 double r = d_r + tol;
1381
1382 return {xb - r, xt + r};
1383 }
1384
1386
1387 auto box = this->box();
1388
1389 return 0.5 * (box.second - box.first).length();
1390 }
1391
1393
1394 return 0.5 * std::sqrt(d_l * d_l + 4. * d_r * d_r);
1395 }
1396
1398
1399 auto dx = x - d_xBegin;
1400
1401 if (dx.length() < 1.0E-10)
1402 return true;
1403
1404 double dx_dot_xa = dx * d_xa;
1405 if (util::isLess(dx_dot_xa, 0.) or
1406 util::isGreater(dx_dot_xa, d_l))
1407 return false;
1408 else {
1409
1410 // project dx onto cross-section plane of cylinder
1411 auto dx_project = dx - dx_dot_xa * d_xa;
1412
1413 return !util::isGreater(dx_project.length(), d_r + 1.0E-12);
1414 }
1415 }
1416
1418 return !isInside(x);
1419 }
1420
1422 &tol) const {
1423
1424 auto dx = x - d_xBegin;
1425
1426 if (dx.length() < tol)
1427 return true;
1428
1429 double dx_dot_xa = dx * d_xa;
1430 if (util::isLess(dx_dot_xa, -tol) or
1431 util::isGreater(dx_dot_xa, d_l + tol))
1432 return false;
1433 else {
1434
1435 // project dx onto cross-section plane of cylinder
1436 auto dx_project = dx - dx_dot_xa * d_xa;
1437
1438 return !util::isGreater(dx_project.length(), d_r + tol);
1439 }
1440 }
1441
1443 const double &tol, const bool
1444 &within) const {
1445
1446 auto dx = x - d_xBegin;
1447
1448 if (dx.length() < tol)
1449 return true;
1450
1451 double dx_dot_xa = dx * d_xa;
1452 if (util::isLess(dx_dot_xa, -tol) or
1453 util::isGreater(dx_dot_xa, tol) or
1454 util::isGreater(dx_dot_xa, d_l + tol) or
1455 util::isLess(dx_dot_xa, d_l - tol))
1456 return false;
1457 else {
1458
1459 // project dx onto cross-section plane of cylinder
1460 auto dx_project = dx - dx_dot_xa * d_xa;
1461
1462 return !(util::isLess(dx_project.length(), d_r - tol) or
1463 util::isGreater(dx_project.length(), d_r + tol));
1464 }
1465 }
1466
1468
1469 return isNearBoundary(x, 1.0E-8, false);
1470 }
1471
1473 const std::pair<util::Point, util::Point> &box) const {
1474
1475 for (auto p: util::getCornerPoints(3, box))
1476 if (!this->isInside(p))
1477 return false;
1478
1479 return true;
1480 }
1481
1483 const std::pair<util::Point, util::Point> &box) const {
1484
1485 bool intersect = false;
1486 for (auto p: util::getCornerPoints(3, box))
1487 if (!intersect)
1488 intersect = this->isInside(p);
1489
1490 return !intersect;
1491 }
1492
1494 const std::pair<util::Point, util::Point> &box,
1495 const double &tol) const {
1496
1497 return util::areBoxesNear(this->box(), box, tol, 3);
1498 }
1499
1501 const std::pair<util::Point, util::Point> &box) const {
1502
1503 // need to check all four corner points
1504 for (auto p: util::getCornerPoints(3, box))
1505 if (this->isInside(p))
1506 return true;
1507
1508 return false;
1509 }
1510
1511
1512 std::string util::geometry::Cylinder::printStr(int nt, int lvl) const {
1513
1514 auto tabS = util::io::getTabS(nt);
1515
1516 std::ostringstream oss;
1517
1518 oss << tabS << "------- Cylinder --------" << std::endl << std::endl;
1519 oss << tabS << "Name = " << d_name << std::endl;
1520 oss << tabS << "Center = " << d_xBegin.printStr(0, lvl) << std::endl;
1521 oss << tabS << "Axis = " << d_xa.printStr(0, lvl) << std::endl;
1522 oss << tabS << "Radius = " << d_r << std::endl;
1523 oss << tabS << "Center = " << d_x.printStr(0, 0) << std::endl;
1524
1525 if (lvl > 0)
1526 oss << tabS << "Bounding box: "
1527 << util::io::printBoxStr(box(0.), nt + 1);
1528
1529 if (lvl == 0)
1530 oss << std::endl;
1531
1532 return oss.str();
1533 }
1534
1535}// Cylinder
1536
1537//
1538// Sphere
1539//
1540namespace util {
1542 return 4. * M_PI * d_r * d_r * d_r / 3.;
1543 }
1544
1546 return d_x;
1547 }
1548
1549 std::pair<util::Point, util::Point> util::geometry::Sphere::box() const {
1550
1551 return box(0.);
1552 }
1553
1554 std::pair<util::Point, util::Point> util::geometry::Sphere::box(const
1555 double &tol) const {
1556 double r = d_r + tol;
1557
1558 return {
1559 util::Point(d_x.d_x - r, d_x.d_y - r, d_x.d_z - r),
1560 util::Point(d_x.d_x + r, d_x.d_y + r, d_x.d_z + r)
1561 };
1562 }
1563
1565
1566 return d_r;
1567 }
1568
1570
1571 return d_r;
1572 }
1573
1575
1576 return util::isLess(d_x.dist(x), d_r + 1.0E-12);
1577 }
1578
1580 return !isInside(x);
1581 }
1582
1584 const double &tol) const {
1585
1586 // translate to origin
1587 auto x0 = x - d_x;
1588
1589 return util::isLess(x0.length(), d_r + tol);
1590 }
1591
1593 const double &tol, const bool
1594 &within) const {
1595
1596 // check if particle is within the tolerance distance
1597 if (!isNear(x, within ? 0. : tol))
1598 return false;
1599
1600 // check if it is close enough to circumference
1601 auto x0 = x - d_x;
1602
1603 return util::isLess(x0.length(), d_r + tol) ||
1604 util::isLess(x0.length(), d_r - tol);
1605 }
1606
1608
1609 return isNearBoundary(x, 1.0E-8, false);
1610 }
1611
1613 const std::pair<util::Point, util::Point> &box) const {
1614
1615 for (auto p: util::getCornerPoints(3, box))
1616 if (!this->isInside(p))
1617 return false;
1618
1619 return true;
1620 }
1621
1623 const std::pair<util::Point, util::Point> &box) const {
1624
1625 bool intersect = false;
1626 for (auto p: util::getCornerPoints(3, box))
1627 if (!intersect)
1628 intersect = this->isInside(p);
1629
1630 return !intersect;
1631 }
1632
1634 const std::pair<util::Point, util::Point> &box,
1635 const double &tol) const {
1636
1637 if (this->isInside(box))
1638 return true;
1639
1640 // get corner points of box
1641 auto cp = getCornerPoints(3, box);
1642
1643 for (auto p: cp) {
1644
1645 // check the distance of corner point with the center
1646 auto dx = p - d_x;
1647 if (util::isLess(dx.length(), d_r + tol))
1648 return true;
1649 }
1650
1651 // check center to center distance
1652 auto dxc = util::getCenter(3, box) - d_x;
1653
1654 // check wrt inscribed circle
1655 auto r = util::inscribedRadiusInBox(3, box);
1656 if (util::isLess(dxc.length(), d_r + r + tol))
1657 return true;
1658
1659 // check wrt circumscribed circle
1661 return util::isLess(dxc.length(), d_r + r + tol);
1662 }
1663
1665 const std::pair<util::Point, util::Point> &box) const {
1666
1667 // need to check all four corner points
1668 for (auto p: util::getCornerPoints(3, box))
1669 if (this->isInside(p))
1670 return true;
1671
1672 return false;
1673 }
1674
1675 std::string util::geometry::Sphere::printStr(int nt, int lvl) const {
1676
1677 auto tabS = util::io::getTabS(nt);
1678
1679 std::ostringstream oss;
1680
1681 oss << tabS << "------- Sphere --------" << std::endl << std::endl;
1682 oss << tabS << "Name = " << d_name << std::endl;
1683 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
1684 oss << tabS << "Radius = " << d_r << std::endl;
1685
1686 if (lvl > 0)
1687 oss << tabS << "Bounding box: "
1688 << util::io::printBoxStr(box(0.), nt + 1);
1689
1690 if (lvl == 0)
1691 oss << std::endl;
1692
1693 return oss.str();
1694 }
1695
1696}// Sphere
1697
1698//
1699// AnnulusGeomObject
1700//
1701namespace util {
1703 return d_outObj_p->volume() - d_inObj_p->volume();
1704 }
1705
1707
1708 // we use the formula for centroid of composite objects
1709 // x = sum_i sign(i) V_i x_i / sum_i sign(i) V_i
1710 // where sign(i) = +1 if object is filling
1711 // sign(i) = -1 if object is empty
1712 auto vol = volume();
1713 if (util::isGreater(vol, 0.))
1714 return (1./vol) * (d_outObj_p->volume() * d_outObj_p->center()
1715 - d_inObj_p->volume() * d_inObj_p->center());
1716 else
1717 return d_outObj_p->center();
1718 }
1719
1720 std::pair<util::Point, util::Point> util::geometry::AnnulusGeomObject::box
1721 () const {
1722 return d_outObj_p->box();
1723 }
1724
1725 std::pair<util::Point, util::Point> util::geometry::AnnulusGeomObject::box
1726 (const double &tol) const {
1727 return d_outObj_p->box(tol);
1728 }
1729
1731
1732 return d_outObj_p->inscribedRadius();
1733 }
1734
1736
1737 return d_outObj_p->boundingRadius();
1738 }
1739
1740 bool
1742
1743 // should be outside inner object and inside outer object
1744 return !d_inObj_p->isInside(x) && d_outObj_p->isInside(x);
1745 }
1746
1747 bool
1749 return !isInside(x);
1750 }
1751
1753 const double &tol) const {
1754
1755 return d_outObj_p->isNear(x, tol) || d_inObj_p->isNear(x, tol);
1756 }
1757
1759 const double &tol,
1760 const bool
1761 &within) const {
1762
1763 return d_outObj_p->isNearBoundary(x, tol, within) ||
1764 d_inObj_p->isNearBoundary(x, tol, within);
1765 }
1766
1768 const util::Point &x) const {
1769
1770 return isNearBoundary(x, 1.0E-8, false);
1771 }
1772
1774 const std::pair<util::Point, util::Point> &box) const {
1775
1776 for (auto p: util::getCornerPoints(d_dim, box))
1777 if (!this->isInside(p))
1778 return false;
1779
1780 return true;
1781 }
1782
1784 const std::pair<util::Point, util::Point> &box) const {
1785
1786 bool intersect = false;
1787 for (auto p: util::getCornerPoints(d_dim, box))
1788 intersect = this->isInside(p);
1789
1790 return !intersect;
1791 }
1792
1794 const std::pair<util::Point, util::Point> &box,
1795 const double &tol) const {
1796
1797 return d_outObj_p->isNear(box, tol) || d_inObj_p->isNear(box, tol);
1798 }
1799
1801 const std::pair<util::Point, util::Point> &box) const {
1802
1803 // need to check all four corner points
1804 for (auto p: util::getCornerPoints(d_dim, box))
1805 if (this->isInside(p))
1806 return true;
1807
1808 return false;
1809 }
1810
1811 std::string
1813
1814 auto tabS = util::io::getTabS(nt);
1815
1816 std::ostringstream oss;
1817
1818 oss << tabS << "------- AnnulusGeomObject --------" << std::endl
1819 << std::endl;
1820 oss << tabS << "Name = " << d_name << std::endl;
1821 oss << tabS << "Center = " << center().printStr() << std::endl;
1822 oss << tabS << "Inner object info:" << std::endl;
1823 oss << d_inObj_p->printStr(nt + 1, lvl);
1824 oss << tabS << "Outer object info:" << std::endl;
1825 oss << d_outObj_p->printStr(nt + 1, lvl);
1826
1827 if (lvl > 0)
1828 oss << tabS << "Bounding box: "
1829 << util::io::printBoxStr(box(0.), nt + 1);
1830
1831 if (lvl == 0)
1832 oss << std::endl;
1833
1834 return oss.str();
1835 }
1836
1837}// AnnulusGeomObject
1838
1839//
1840// ComplexGeomObject
1841//
1842namespace util {
1844
1845 double volume = 0.;
1846 for (size_t i = 0; i < d_objFlag.size(); i++)
1847 volume += d_obj[i]->volume() * d_objFlagInt[i];
1848
1849 return volume;
1850 }
1851
1853
1854 // use formula for centroid of composite objects
1855 auto vol = volume();
1856 if (util::isGreater(vol, 0.)) {
1857 auto center = util::Point();
1858 for (size_t i = 0; i < d_objFlag.size(); i++)
1859 center += d_obj[i]->volume() * d_objFlagInt[i] * d_obj[i]->center();
1860 return (1./vol) * center;
1861 }
1862 else {
1863
1864 // find biggest object that has positive d_objFlagInt
1865 // (that is it is a filling and not void object)
1866 std::vector<double> vol_vec(d_obj.size());
1867 for (size_t i = 0; i < d_obj.size(); i++)
1868 vol_vec[i] = d_obj[i]->volume() * d_objFlagInt[i];
1869
1870 auto max_vol_obj = util::methods::maxIndex(vol_vec);
1871 return d_obj[max_vol_obj]->center();
1872 }
1873 }
1874
1875 std::pair<util::Point, util::Point> util::geometry::ComplexGeomObject::box
1876 () const {
1877
1878 return box(0.);
1879 }
1880
1881 std::pair<util::Point, util::Point> util::geometry::ComplexGeomObject::box
1882 (const double &tol) const {
1883
1884 auto p1 = d_obj[0]->box(tol).first;
1885 auto p2 = d_obj[0]->box(tol).second;
1886
1887 for (size_t i = 1; i < d_objFlag.size(); i++) {
1888
1889 auto q1 = d_obj[i]->box(tol).first;
1890 auto q2 = d_obj[i]->box(tol).second;
1891
1892 for (size_t i = 0; i < 3; i++) {
1893 if (q1[i] < p1[i])
1894 p1[i] = q1[i];
1895 if (q2[i] > p2[i])
1896 p2[i] = q2[i];
1897 }
1898 }
1899
1900 return std::make_pair(p1, p2);
1901 }
1902
1904
1905 auto box = this->box();
1906 return 0.5 * (box.first - box.second).length();
1907 }
1908
1910
1911 auto box = this->box();
1912 return 0.5 * (box.first - box.second).length();
1913 }
1914
1915 bool
1917
1918 // point inside means x should be inside in the object with plus flag and
1919 // outside in the object with minus flag
1920 bool point_inside = d_obj[0]->isInside(x);
1921 for (size_t i = 1; i < d_objFlag.size(); i++) {
1922
1923 const auto &obj_i = d_obj[i];
1924 if (d_objFlagInt[i] < 0)
1925 point_inside = point_inside and !obj_i->isInside(x);
1926 else
1927 point_inside = point_inside or obj_i->isInside(x);
1928 }
1929
1930 return point_inside;
1931 }
1932
1933 bool
1935 return !isInside(x);
1936 }
1937
1939 const double &tol) const {
1940
1941 bool is_near = d_obj[0]->isNear(x, tol);
1942 for (size_t i = 1; i < d_objFlag.size(); i++) {
1943
1944 const auto &obj_i = d_obj[i];
1945 is_near = is_near or obj_i->isNear(x, tol);
1946 }
1947
1948 return is_near;
1949 }
1950
1952 const double &tol,
1953 const bool
1954 &within) const {
1955
1956 bool is_near = d_obj[0]->isNearBoundary(x, tol, within);
1957 for (size_t i = 1; i < d_objFlag.size(); i++) {
1958
1959 const auto &obj_i = d_obj[i];
1960 is_near = is_near or obj_i->isNearBoundary(x, tol, within);
1961 }
1962
1963 return is_near;
1964 }
1965
1967 const util::Point &x) const {
1968
1969 return isNearBoundary(x, 1.0E-8, false);
1970 }
1971
1973 const std::pair<util::Point, util::Point> &box) const {
1974
1975 for (auto p: util::getCornerPoints(d_dim, box))
1976 if (!this->isInside(p))
1977 return false;
1978
1979 return true;
1980 }
1981
1983 const std::pair<util::Point, util::Point> &box) const {
1984
1985 bool intersect = false;
1986 for (auto p: util::getCornerPoints(d_dim, box))
1987 intersect = this->isInside(p);
1988
1989 return !intersect;
1990 }
1991
1993 const std::pair<util::Point, util::Point> &box,
1994 const double &tol) const {
1995
1996 bool is_near = d_obj[0]->isNear(box, tol);
1997 for (size_t i = 1; i < d_objFlag.size(); i++) {
1998
1999 const auto &obj_i = d_obj[i];
2000 is_near = is_near or obj_i->isNear(box, tol);
2001 }
2002
2003 return is_near;
2004 }
2005
2007 const std::pair<util::Point, util::Point> &box) const {
2008
2009 // need to check all four corner points
2010 for (auto p: util::getCornerPoints(d_dim, box))
2011 if (this->isInside(p))
2012 return true;
2013
2014 return false;
2015 }
2016
2017 std::string
2019
2020 auto tabS = util::io::getTabS(nt);
2021
2022 std::ostringstream oss;
2023
2024 oss << tabS << "------- ComplexGeomObject --------" << std::endl
2025 << std::endl;
2026 oss << tabS << "Name = " << d_name << std::endl;
2027 oss << tabS << "Center = " << center().printStr() << std::endl;
2028 oss << tabS << "Object info:" << std::endl;
2029 auto ocount = 0;
2030 for (const auto &p: d_obj) {
2031 oss << tabS << "Object id: " << ocount << std::endl;
2032 oss << tabS << "Object flag: " << d_objFlag[ocount] << std::endl;
2033 oss << tabS << "Object int flag: " << d_objFlagInt[ocount] << std::endl;
2034 oss << p->printStr(nt + 1, lvl);
2035 ocount++;
2036 }
2037
2038 if (lvl > 0)
2039 oss << tabS << "Bounding box: "
2040 << util::io::printBoxStr(box(0.), nt + 1);
2041
2042 if (lvl == 0)
2043 oss << std::endl;
2044
2045 return oss.str();
2046 }
2047
2048}// ComplexGeomObject
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
util::Point center() const override
Computes the center of object.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
util::Point center() const override
Computes the center of object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
util::Point center() const override
Computes the center of object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
util::Point center() const override
Computes the center of object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
util::Point center() const override
Computes the center of object.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
util::Point center() const override
Computes the center of object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
util::Point center() const override
Computes the center of object.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
util::Point center() const override
Computes the center of object.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
util::Point center() const override
Computes the center of object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
util::Point center() const override
Computes the center of object.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
util::Point center() const override
Computes the center of object.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
util::Point center() const override
Computes the center of object.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
util::Point center() const override
Computes the center of object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
std::string printErrMsg(const std::string &geom_type, const std::vector< double > &params, const std::vector< size_t > &num_params_needed)
std::string printBoxStr(const std::pair< util::Point, util::Point > &box, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:168
std::string getTabS(int nt)
Returns tab spaces of given size.
Definition io.h:40
std::string printStr(const T &msg, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:54
size_t maxIndex(const std::vector< T > &data)
Returns the index corresponding to maximum from list of data.
Definition methods.h:38
Collection of methods useful in simulation.
bool isPointInsideBox(util::Point x, size_t dim, const std::pair< util::Point, util::Point > &box)
Returns true if point is inside box.
Definition geom.cpp:159
bool areBoxesNear(const std::pair< util::Point, util::Point > &b1, const std::pair< util::Point, util::Point > &b2, const double &tol, size_t dim)
Checks if given two boxes are within given distance from each other.
Definition geom.cpp:109
bool isGreater(const double &a, const double &b)
Returns true if a > b.
Definition function.cpp:15
bool isPointInsideCuboid(util::Point x, util::Point x_lbb, util::Point x_rtf)
Checks if point is inside a cuboid.
Definition geom.cpp:286
std::vector< util::Point > getCornerPoints(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns all corner points in the box.
Definition geom.cpp:14
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:20
util::Point getCenter(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns center point.
Definition geom.cpp:91
std::vector< double > dot(const std::vector< std::vector< double > > &m, const std::vector< double > &v)
Computes the dot product between matrix and vector.
Definition matrix.cpp:38
double inscribedRadiusInBox(size_t dim, const std::pair< util::Point, util::Point > &box)
Computes the radius of biggest circle/sphere completely within the object.
Definition geom.cpp:183
double triangleArea(const util::Point &x1, const util::Point &x2, const util::Point &x3)
Compute area of triangle.
Definition geom.cpp:642
bool isPointInsideRectangle(util::Point x, double x_min, double x_max, double y_min, double y_max)
Checks if point is inside a rectangle.
Definition geom.cpp:231
double circumscribedRadiusInBox(size_t dim, const std::pair< util::Point, util::Point > &box)
Computes the radius of smallest circle/sphere which can have the box inside.
Definition geom.cpp:208
util::Point rotate(const util::Point &p, const double &theta, const util::Point &axis)
Returns the vector after rotating by desired angle.
A structure to represent 3d vectors.
Definition point.h:30
double d_y
the y coordinate
Definition point.h:36
double d_z
the z coordinate
Definition point.h:39
double d_x
the x coordinate
Definition point.h:33