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 <stdexcept>
16#include <utility>
17#include <memory>
18#include <map>
19
20#include "geomObjects.h"
21#include "geomObjectsUtil.h"
22
23namespace geom {
24
29 public:
32
35
37 size_t d_dim;
38
39 public:
44 : GeomObject("annulus_object", ""),
45 d_outObj_p(nullptr),
46 d_inObj_p(nullptr),
47 d_dim(0) {
48 };
49
57 AnnulusGeomObject(GeomObject *in, GeomObject *out, std::string description = "")
58 : GeomObject("annulus_object", description),
59 d_outObj_p(out),
60 d_inObj_p(in),
61 d_dim(0) {
62 d_dim = getGeomTypeToDim(d_outObj_p->d_name); // assume all types have same dim
63 };
64
71 : GeomObject(other.d_name, other.d_description),
72 d_outObj_p(nullptr),
73 d_inObj_p(nullptr),
74 d_dim(other.d_dim) {
75 // Copy tags from base class
76 d_tags = other.d_tags;
77
78 // Deep copy inner and outer objects using utility function
81 }
82
87 delete d_inObj_p;
88 delete d_outObj_p;
89 }
90
97 if (this != &other) {
98 // Clean up existing objects
99 delete d_inObj_p;
100 delete d_outObj_p;
101 d_inObj_p = nullptr;
102 d_outObj_p = nullptr;
103
104 // Copy base class members
105 d_tags = other.d_tags;
106 d_dim = other.d_dim;
107
108 // Deep copy inner and outer objects using utility function
111 }
112 return *this;
113 }
114
120 void transform(const util::Point &translation, const double &scale,
121 const double &angle, const util::Point &axis,
122 const util::Point *rotationPoint) override {
123 const util::Point *pivot = rotationPoint;
124 util::Point pivotStore;
125 if (pivot == nullptr) {
126 if (d_inObj_p && d_outObj_p) {
127 pivotStore = center();
128 pivot = &pivotStore;
129 } else if (d_inObj_p) {
130 pivotStore = d_inObj_p->center();
131 pivot = &pivotStore;
132 } else if (d_outObj_p) {
133 pivotStore = d_outObj_p->center();
134 pivot = &pivotStore;
135 }
136 }
137 if (d_inObj_p) d_inObj_p->transform(translation, scale, angle, axis, pivot);
138 if (d_outObj_p) d_outObj_p->transform(translation, scale, angle, axis, pivot);
139 }
140
144 double volume() const override;
145
149 util::Point center() const override;
150
154 std::pair<util::Point, util::Point> box() const override;
155
159 std::pair<util::Point, util::Point>
160 box(const double &tol) const override;
161
165 double inscribedRadius() const override;
166
170 double boundingRadius() const override;
171
180 bool isInside(const util::Point &x) const override;
181
185 bool isOutside(const util::Point &x) const override;
186
190 bool isNear(const util::Point &x, const double &tol) const override;
191
196 bool isNearBoundary(const util::Point &x, const double &tol,
197 const bool &within) const override;
198
202 bool doesIntersect(const util::Point &x) const override;
203
215 bool
216 isInside(
217 const std::pair<util::Point, util::Point> &box) const override;
218
223 bool
224 isOutside(
225 const std::pair<util::Point, util::Point> &box) const override;
226
231 bool isNear(const std::pair<util::Point, util::Point> &box,
232 const double &tol) const override;
233
238 bool doesIntersect(
239 const std::pair<util::Point, util::Point> &box) const override;
240
246 std::string printStr(int nt, int lvl) const override;
247
251 void print(int nt, int lvl) const override {
252 std::cout << printStr(nt, lvl);
253 };
254
258 void print() const override { print(0, 0); };
259 };
260
265
266 public:
268 std::vector<std::shared_ptr<GeomObject> > d_obj;
269
278 std::vector<std::string> d_objFlag;
279
283 std::vector<int> d_objFlagInt;
284
286 size_t d_dim;
287
288 public:
292 ComplexGeomObject() : GeomObject("complex", ""), d_dim(0) {
293 };
294
303 std::vector<std::shared_ptr<GeomObject> > &obj,
304 std::vector<std::string> obj_flag, std::string description = "")
305 : GeomObject("complex", description),
306 d_obj(obj),
307 d_objFlag(obj_flag),
308 d_dim(0) {
309
310 d_dim = getGeomTypeToDim(d_obj[0]->d_name); // assume all types have same dim
311
312 for (const auto &s: d_objFlag)
313 if (s == "plus")
314 d_objFlagInt.push_back(1);
315 else if (s == "minus")
316 d_objFlagInt.push_back(-1);
317 else {
318 throw std::invalid_argument(
320 << "Error: Check object flag " + s +
321 " passed to create ComplexGeomObject\n");
322 }
323 };
324
330 : GeomObject(other.d_name, other.d_description),
331 d_objFlag(other.d_objFlag),
333 d_dim(other.d_dim) {
334 d_tags = other.d_tags;
335
336 // Deep copy each geometric object
337 d_obj.reserve(other.d_obj.size());
338 for (const auto& obj : other.d_obj) {
339 if (obj) {
340 // Create a raw pointer copy first
341 GeomObject* raw_copy = createGeomDeepCopy(obj.get());
342 // Convert to shared_ptr and store
343 d_obj.push_back(std::shared_ptr<GeomObject>(raw_copy));
344 } else {
345 d_obj.push_back(nullptr);
346 }
347 }
348 }
349
356 if (this != &other) {
357 // Copy base class members
358 d_tags = other.d_tags;
359
360 // Copy flags and dimension
361 d_objFlag = other.d_objFlag;
363 d_dim = other.d_dim;
364
365 // Deep copy each geometric object
366 d_obj.clear();
367 d_obj.reserve(other.d_obj.size());
368 for (const auto& obj : other.d_obj) {
369 if (obj) {
370 // Create a raw pointer copy first
371 GeomObject* raw_copy = createGeomDeepCopy(obj.get());
372 // Convert to shared_ptr and store
373 d_obj.push_back(std::shared_ptr<GeomObject>(raw_copy));
374 } else {
375 d_obj.push_back(nullptr);
376 }
377 }
378 }
379 return *this;
380 }
381
385 void transform(const util::Point &translation, const double &scale,
386 const double &angle, const util::Point &axis,
387 const util::Point *rotationPoint) override {
388 const util::Point *pivot = rotationPoint;
389 util::Point pivotStore;
390 if (pivot == nullptr) {
391 pivotStore = center();
392 pivot = &pivotStore;
393 }
394 for (auto &obj : d_obj) {
395 if (obj) obj->transform(translation, scale, angle, axis, pivot);
396 }
397 }
398
402 double volume() const override;
403
407 util::Point center() const override;
408
412 std::pair<util::Point, util::Point> box() const override;
413
417 std::pair<util::Point, util::Point>
418 box(const double &tol) const override;
419
423 double inscribedRadius() const override;
424
428 double boundingRadius() const override;
429
438 bool isInside(const util::Point &x) const override;
439
443 bool isOutside(const util::Point &x) const override;
444
448 bool isNear(const util::Point &x, const double &tol) const override;
449
454 bool isNearBoundary(const util::Point &x, const double &tol,
455 const bool &within) const override;
456
460 bool doesIntersect(const util::Point &x) const override;
461
473 bool
474 isInside(
475 const std::pair<util::Point, util::Point> &box) const override;
476
481 bool
482 isOutside(
483 const std::pair<util::Point, util::Point> &box) const override;
484
489 bool isNear(const std::pair<util::Point, util::Point> &box,
490 const double &tol) const override;
491
496 bool doesIntersect(
497 const std::pair<util::Point, util::Point> &box) const override;
498
504 std::string printStr(int nt, int lvl) const override;
505
509 void print(int nt, int lvl) const override {
510 std::cout << printStr(nt, lvl);
511 };
512
516 void print() const override { print(0, 0); };
517 };
518
519 } // namespace geom
520
521#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.
Collects a message with stream syntax for use in an exception.
Definition io.h:52
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