PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
complexGeomObjects.h
Go to the documentation of this file.
1/*
2* -------------------------------------------
3* Copyright (c) 2021 - 2026 Prashant K. Jha
4* -------------------------------------------
5* PeriDEM https://github.com/prashjha/PeriDEM
6*
7* Distributed under the Boost Software License, Version 1.0. (See accompanying
8* file LICENSE)
9*/
10
11#ifndef GEOM_COMPLEXGEOMOBJECTS_H
12#define GEOM_COMPLEXGEOMOBJECTS_H
13
14#include <iostream>
15#include <utility>
16#include <memory>
17#include <map>
18
19#include "geomObjects.h"
20#include "geomObjectsUtil.h"
21
22namespace geom {
23
28 public:
31
34
36 size_t d_dim;
37
38 public:
43 : GeomObject("annulus_object", ""),
44 d_outObj_p(nullptr),
45 d_inObj_p(nullptr),
46 d_dim(0) {
47 };
48
56 AnnulusGeomObject(GeomObject *in, GeomObject *out, std::string description = "")
57 : GeomObject("annulus_object", description),
58 d_outObj_p(out),
59 d_inObj_p(in),
60 d_dim(0) {
61 d_dim = getGeomTypeToDim(d_outObj_p->d_name); // assume all types have same dim
62 };
63
70 : GeomObject(other.d_name, other.d_description),
71 d_outObj_p(nullptr),
72 d_inObj_p(nullptr),
73 d_dim(other.d_dim) {
74 // Copy tags from base class
75 d_tags = other.d_tags;
76
77 // Deep copy inner and outer objects using utility function
80 }
81
86 delete d_inObj_p;
87 delete d_outObj_p;
88 }
89
96 if (this != &other) {
97 // Clean up existing objects
98 delete d_inObj_p;
99 delete d_outObj_p;
100 d_inObj_p = nullptr;
101 d_outObj_p = nullptr;
102
103 // Copy base class members
104 d_tags = other.d_tags;
105 d_dim = other.d_dim;
106
107 // Deep copy inner and outer objects using utility function
110 }
111 return *this;
112 }
113
119 void transform(const util::Point &translation, const double &scale,
120 const double &angle, const util::Point &axis,
121 const util::Point *rotationPoint) override {
122 const util::Point *pivot = rotationPoint;
123 util::Point pivotStore;
124 if (pivot == nullptr) {
125 if (d_inObj_p && d_outObj_p) {
126 pivotStore = center();
127 pivot = &pivotStore;
128 } else if (d_inObj_p) {
129 pivotStore = d_inObj_p->center();
130 pivot = &pivotStore;
131 } else if (d_outObj_p) {
132 pivotStore = d_outObj_p->center();
133 pivot = &pivotStore;
134 }
135 }
136 if (d_inObj_p) d_inObj_p->transform(translation, scale, angle, axis, pivot);
137 if (d_outObj_p) d_outObj_p->transform(translation, scale, angle, axis, pivot);
138 }
139
143 double volume() const override;
144
148 util::Point center() const override;
149
153 std::pair<util::Point, util::Point> box() const override;
154
158 std::pair<util::Point, util::Point>
159 box(const double &tol) const override;
160
164 double inscribedRadius() const override;
165
169 double boundingRadius() const override;
170
179 bool isInside(const util::Point &x) const override;
180
184 bool isOutside(const util::Point &x) const override;
185
189 bool isNear(const util::Point &x, const double &tol) const override;
190
195 bool isNearBoundary(const util::Point &x, const double &tol,
196 const bool &within) const override;
197
201 bool doesIntersect(const util::Point &x) const override;
202
214 bool
215 isInside(
216 const std::pair<util::Point, util::Point> &box) const override;
217
222 bool
223 isOutside(
224 const std::pair<util::Point, util::Point> &box) const override;
225
230 bool isNear(const std::pair<util::Point, util::Point> &box,
231 const double &tol) const override;
232
237 bool doesIntersect(
238 const std::pair<util::Point, util::Point> &box) const override;
239
245 std::string printStr(int nt, int lvl) const override;
246
250 void print(int nt, int lvl) const override {
251 std::cout << printStr(nt, lvl);
252 };
253
257 void print() const override { print(0, 0); };
258 };
259
264
265 public:
267 std::vector<std::shared_ptr<GeomObject> > d_obj;
268
277 std::vector<std::string> d_objFlag;
278
282 std::vector<int> d_objFlagInt;
283
285 size_t d_dim;
286
287 public:
291 ComplexGeomObject() : GeomObject("complex", ""), d_dim(0) {
292 };
293
302 std::vector<std::shared_ptr<GeomObject> > &obj,
303 std::vector<std::string> obj_flag, std::string description = "")
304 : GeomObject("complex", description),
305 d_obj(obj),
306 d_objFlag(obj_flag),
307 d_dim(0) {
308
309 d_dim = getGeomTypeToDim(d_obj[0]->d_name); // assume all types have same dim
310
311 for (const auto &s: d_objFlag)
312 if (s == "plus")
313 d_objFlagInt.push_back(1);
314 else if (s == "minus")
315 d_objFlagInt.push_back(-1);
316 else {
317 std::cerr
318 << "Error: Check object flag " + s +
319 " passed to create ComplexGeomObject\n";
320 exit(1);
321 }
322 };
323
329 : GeomObject(other.d_name, other.d_description),
330 d_objFlag(other.d_objFlag),
332 d_dim(other.d_dim) {
333 d_tags = other.d_tags;
334
335 // Deep copy each geometric object
336 d_obj.reserve(other.d_obj.size());
337 for (const auto& obj : other.d_obj) {
338 if (obj) {
339 // Create a raw pointer copy first
340 GeomObject* raw_copy = createGeomDeepCopy(obj.get());
341 // Convert to shared_ptr and store
342 d_obj.push_back(std::shared_ptr<GeomObject>(raw_copy));
343 } else {
344 d_obj.push_back(nullptr);
345 }
346 }
347 }
348
355 if (this != &other) {
356 // Copy base class members
357 d_tags = other.d_tags;
358
359 // Copy flags and dimension
360 d_objFlag = other.d_objFlag;
362 d_dim = other.d_dim;
363
364 // Deep copy each geometric object
365 d_obj.clear();
366 d_obj.reserve(other.d_obj.size());
367 for (const auto& obj : other.d_obj) {
368 if (obj) {
369 // Create a raw pointer copy first
370 GeomObject* raw_copy = createGeomDeepCopy(obj.get());
371 // Convert to shared_ptr and store
372 d_obj.push_back(std::shared_ptr<GeomObject>(raw_copy));
373 } else {
374 d_obj.push_back(nullptr);
375 }
376 }
377 }
378 return *this;
379 }
380
384 void transform(const util::Point &translation, const double &scale,
385 const double &angle, const util::Point &axis,
386 const util::Point *rotationPoint) override {
387 const util::Point *pivot = rotationPoint;
388 util::Point pivotStore;
389 if (pivot == nullptr) {
390 pivotStore = center();
391 pivot = &pivotStore;
392 }
393 for (auto &obj : d_obj) {
394 if (obj) obj->transform(translation, scale, angle, axis, pivot);
395 }
396 }
397
401 double volume() const override;
402
406 util::Point center() const override;
407
411 std::pair<util::Point, util::Point> box() const override;
412
416 std::pair<util::Point, util::Point>
417 box(const double &tol) const override;
418
422 double inscribedRadius() const override;
423
427 double boundingRadius() const override;
428
437 bool isInside(const util::Point &x) const override;
438
442 bool isOutside(const util::Point &x) const override;
443
447 bool isNear(const util::Point &x, const double &tol) const override;
448
453 bool isNearBoundary(const util::Point &x, const double &tol,
454 const bool &within) const override;
455
459 bool doesIntersect(const util::Point &x) const override;
460
472 bool
473 isInside(
474 const std::pair<util::Point, util::Point> &box) const override;
475
480 bool
481 isOutside(
482 const std::pair<util::Point, util::Point> &box) const override;
483
488 bool isNear(const std::pair<util::Point, util::Point> &box,
489 const double &tol) const override;
490
495 bool doesIntersect(
496 const std::pair<util::Point, util::Point> &box) const override;
497
503 std::string printStr(int nt, int lvl) const override;
504
508 void print(int nt, int lvl) const override {
509 std::cout << printStr(nt, lvl);
510 };
511
515 void print() const override { print(0, 0); };
516 };
517
518 } // namespace geom
519
520#endif // GEOM_COMPLEXGEOMOBJECTS_H
Defines annulus rectangle.
void print() const override
Prints the information about the object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
AnnulusGeomObject(GeomObject *in, GeomObject *out, std::string description="")
Constructor.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
AnnulusGeomObject & operator=(const AnnulusGeomObject &other)
Assignment operator.
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.
AnnulusGeomObject(const AnnulusGeomObject &other)
Copy constructor.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
GeomObject * d_outObj_p
Outer 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.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
size_t d_dim
Dimension objects live in.
void print(int nt, int lvl) const override
Prints the information about the 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.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
GeomObject * d_inObj_p
Inner object.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
Defines complex geometrical object.
void print() const override
Prints the 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 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 boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
ComplexGeomObject(const ComplexGeomObject &other)
Copy constructor.
std::vector< int > d_objFlagInt
Object integer flags. Here, +1 means object is filling and -1 means object is void.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
size_t d_dim
Dimension objects live in.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
ComplexGeomObject & operator=(const ComplexGeomObject &other)
Assignment operator.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
void print(int nt, int lvl) const override
Prints the information about the object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
util::Point center() const override
Computes the center of object.
std::vector< std::string > d_objFlag
Object flag.
std::vector< std::shared_ptr< GeomObject > > d_obj
Object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
ComplexGeomObject(std::vector< std::shared_ptr< GeomObject > > &obj, std::vector< std::string > obj_flag, std::string description="")
Constructor.
Defines abstract geometrical domain.
virtual void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint=nullptr)
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
std::vector< std::string > d_tags
Tags/attributes about the object.
virtual util::Point center() const
Computes the center of object.
const std::string d_name
name of object
const std::string d_description
Further description of object.
GeomObject * createGeomDeepCopy(GeomObject *obj)
Creates a deep copy of a geometric object.
size_t getGeomTypeToDim(std::string type)
Returns list of acceptable geometries for PeriDEM simulation.
Definition geomObjects.h:47
A structure to represent 3d vectors.
Definition point.h:30