PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
geom::ComplexGeomObject Class Reference

Defines complex geometrical object. More...

#include <complexGeomObjects.h>

Inheritance diagram for geom::ComplexGeomObject:
Collaboration diagram for geom::ComplexGeomObject:

Public Member Functions

 ComplexGeomObject ()
 Constructor.
 
 ComplexGeomObject (std::vector< std::shared_ptr< GeomObject > > &obj, std::vector< std::string > obj_flag, std::string description="")
 Constructor.
 
 ComplexGeomObject (const ComplexGeomObject &other)
 Copy constructor.
 
ComplexGeomObject & operator= (const ComplexGeomObject &other)
 Assignment operator.
 
void transform (const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
 
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.
 
std::pair< util::Point, util::Point > box () const override
 Computes the bounding box of object.
 
std::pair< util::Point, util::Point > box (const double &tol) const override
 Computes the bounding box of object.
 
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.
 
std::string printStr (int nt, int lvl) const override
 Returns the string containing printable information about the object.
 
void print (int nt, int lvl) const override
 Prints the information about the object.
 
void print () const override
 Prints the information about the object.
 
Interaction with point
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.
 
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
 
bool doesIntersect (const util::Point &x) const override
 Checks if point lies exactly on the boundary.
 
Interaction with box
bool isInside (const std::pair< util::Point, util::Point > &box) const override
 Checks if box is completely inside.
 
bool isOutside (const std::pair< util::Point, util::Point > &box) const override
 Checks if box is outside of the object.
 
bool isNear (const std::pair< util::Point, util::Point > &box, const double &tol) const override
 Checks if box is within given distance of this object.
 
bool doesIntersect (const std::pair< util::Point, util::Point > &box) const override
 Checks if box intersects this object.
 
- Public Member Functions inherited from geom::GeomObject
 GeomObject (std::string name="", std::string description="")
 Constructor.
 
virtual bool wallContactQuery (const util::Point &x, WallContactHit &hit) const
 Closest-point / signed-gap query for analytical wall contact. Default: unsupported (returns false, clears hit).
 

Data Fields

std::vector< std::shared_ptr< GeomObject > > d_obj
 Object.
 
std::vector< std::string > d_objFlag
 Object flag.
 
std::vector< int > d_objFlagInt
 Object integer flags. Here, +1 means object is filling and -1 means object is void.
 
size_t d_dim
 Dimension objects live in.
 
- Data Fields inherited from geom::GeomObject
const std::string d_name
 name of object
 
const std::string d_description
 Further description of object.
 
std::vector< std::string > d_tags
 Tags/attributes about the object.
 

Detailed Description

Defines complex geometrical object.

Definition at line 264 of file complexGeomObjects.h.

Constructor & Destructor Documentation

◆ ComplexGeomObject() [1/3]

geom::ComplexGeomObject::ComplexGeomObject ( )
inline

Constructor.

Definition at line 292 of file complexGeomObjects.h.

292 : GeomObject("complex", ""), d_dim(0) {
293 };
size_t d_dim
Dimension objects live in.
GeomObject(std::string name="", std::string description="")
Constructor.

◆ ComplexGeomObject() [2/3]

geom::ComplexGeomObject::ComplexGeomObject ( std::vector< std::shared_ptr< GeomObject > > &  obj,
std::vector< std::string >  obj_flag,
std::string  description = "" 
)
inline

Constructor.

Parameters
objVector of geometrical objects
obj_flagSpecifies which objects are filling and which are void
descriptionDescription of object (e.g., further classification or any tag)

Definition at line 302 of file complexGeomObjects.h.

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 };
std::vector< int > d_objFlagInt
Object integer flags. Here, +1 means object is filling and -1 means object is void.
std::vector< std::string > d_objFlag
Object flag.
std::vector< std::shared_ptr< GeomObject > > d_obj
Object.
const std::string d_name
name of object
Collects a message with stream syntax for use in an exception.
Definition io.h:52
size_t getGeomTypeToDim(std::string type)
Returns list of acceptable geometries for PeriDEM simulation.
Definition geomObjects.h:47

References d_dim, geom::GeomObject::d_name, d_obj, d_objFlag, d_objFlagInt, and geom::getGeomTypeToDim().

Here is the call graph for this function:

◆ ComplexGeomObject() [3/3]

geom::ComplexGeomObject::ComplexGeomObject ( const ComplexGeomObject &  other)
inline

Copy constructor.

Parameters
otherObject to copy from

Definition at line 329 of file complexGeomObjects.h.

330 : GeomObject(other.d_name, other.d_description),
331 d_objFlag(other.d_objFlag),
332 d_objFlagInt(other.d_objFlagInt),
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 }
std::vector< std::string > d_tags
Tags/attributes about the object.
GeomObject * createGeomDeepCopy(GeomObject *obj)
Creates a deep copy of a geometric object.

References geom::createGeomDeepCopy(), d_obj, and geom::GeomObject::d_tags.

Here is the call graph for this function:

Member Function Documentation

◆ boundingRadius()

double geom::ComplexGeomObject::boundingRadius ( ) const
overridevirtual

Computes the radius of smallest circle/sphere such that object can be fit into it.

Returns
Radius Radius of bounding circle/sphere

Reimplemented from geom::GeomObject.

Definition at line 251 of file complexGeomObjects.cpp.

251 {
252
253 auto box = this->box();
254 return 0.5 * (box.first - box.second).length();
255 }
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.

References box().

Here is the call graph for this function:

◆ box() [1/2]

std::pair< util::Point, util::Point > geom::ComplexGeomObject::box ( ) const
overridevirtual

Computes the bounding box of object.

Returns
Pair Left-bottom-back and right-top-front corner points of box

Reimplemented from geom::GeomObject.

Definition at line 217 of file complexGeomObjects.cpp.

218 {
219
220 return box(0.);
221 }

References box().

Referenced by boundingRadius(), box(), doesIntersect(), inscribedRadius(), isInside(), isNear(), isOutside(), and printStr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ box() [2/2]

std::pair< util::Point, util::Point > geom::ComplexGeomObject::box ( const double &  tol) const
overridevirtual

Computes the bounding box of object.

Parameters
tolTolerance/padding used in creating bounding box
Returns
Pair Left-bottom-back and right-top-front corner points of box

Reimplemented from geom::GeomObject.

Definition at line 223 of file complexGeomObjects.cpp.

224 {
225
226 auto p1 = d_obj[0]->box(tol).first;
227 auto p2 = d_obj[0]->box(tol).second;
228
229 for (size_t i = 1; i < d_objFlag.size(); i++) {
230
231 auto q1 = d_obj[i]->box(tol).first;
232 auto q2 = d_obj[i]->box(tol).second;
233
234 for (size_t i = 0; i < 3; i++) {
235 if (q1[i] < p1[i])
236 p1[i] = q1[i];
237 if (q2[i] > p2[i])
238 p2[i] = q2[i];
239 }
240 }
241
242 return std::make_pair(p1, p2);
243 }

References d_obj, and d_objFlag.

◆ center()

util::Point geom::ComplexGeomObject::center ( ) const
overridevirtual

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from geom::GeomObject.

Definition at line 194 of file complexGeomObjects.cpp.

194 {
195
196 // use formula for centroid of composite objects
197 auto vol = volume();
198 if (util::isGreater(vol, 0.)) {
199 auto center = util::Point();
200 for (size_t i = 0; i < d_objFlag.size(); i++)
201 center += d_obj[i]->volume() * d_objFlagInt[i] * d_obj[i]->center();
202 return (1./vol) * center;
203 }
204 else {
205
206 // find biggest object that has positive d_objFlagInt
207 // (that is it is a filling and not void object)
208 std::vector<double> vol_vec(d_obj.size());
209 for (size_t i = 0; i < d_obj.size(); i++)
210 vol_vec[i] = d_obj[i]->volume() * d_objFlagInt[i];
211
212 auto max_vol_obj = util::methods::maxIndex(vol_vec);
213 return d_obj[max_vol_obj]->center();
214 }
215 }
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.
size_t maxIndex(const std::vector< T > &data)
Returns the index corresponding to maximum from list of data.
Definition vecMethods.h:40
bool isGreater(const double &a, const double &b)
Returns true if a > b.
Definition function.cpp:17
A structure to represent 3d vectors.
Definition point.h:30

References center(), d_obj, d_objFlag, d_objFlagInt, util::isGreater(), util::methods::maxIndex(), and volume().

Referenced by center(), printStr(), and transform().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doesIntersect() [1/2]

bool geom::ComplexGeomObject::doesIntersect ( const std::pair< util::Point, util::Point > &  box) const
overridevirtual

Checks if box intersects this object.

Parameters
boxBox
Returns
True True if intersects

Reimplemented from geom::GeomObject.

Definition at line 348 of file complexGeomObjects.cpp.

349 {
350
351 // need to check all four corner points
352 for (auto p: geom::getCornerPoints(d_dim, box))
353 if (this->isInside(p))
354 return true;
355
356 return false;
357 }
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
std::vector< util::Point > getCornerPoints(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns all corner points in the box.

References box(), d_dim, geom::getCornerPoints(), and isInside().

Here is the call graph for this function:

◆ doesIntersect() [2/2]

bool geom::ComplexGeomObject::doesIntersect ( const util::Point &  x) const
overridevirtual

Checks if point lies exactly on the boundary.

Parameters
xPoint
Returns
True True if it lies on the boundary

Reimplemented from geom::GeomObject.

Definition at line 308 of file complexGeomObjects.cpp.

309 {
310
311 return isNearBoundary(x, 1.0E-8, false);
312 }
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons

References isNearBoundary().

Here is the call graph for this function:

◆ inscribedRadius()

double geom::ComplexGeomObject::inscribedRadius ( ) const
overridevirtual

Computes the radius of biggest circle/sphere completely within the object.

Returns
Radius Radius of inscribed circle/sphere

Reimplemented from geom::GeomObject.

Definition at line 245 of file complexGeomObjects.cpp.

245 {
246
247 auto box = this->box();
248 return 0.5 * (box.first - box.second).length();
249 }

References box().

Here is the call graph for this function:

◆ isInside() [1/2]

bool geom::ComplexGeomObject::isInside ( const std::pair< util::Point, util::Point > &  box) const
overridevirtual

Checks if box is completely inside.

Parameters
boxBox
Returns
True True if box lies inside

Reimplemented from geom::GeomObject.

Definition at line 314 of file complexGeomObjects.cpp.

315 {
316
317 for (auto p: geom::getCornerPoints(d_dim, box))
318 if (!this->isInside(p))
319 return false;
320
321 return true;
322 }

References box(), d_dim, geom::getCornerPoints(), and isInside().

Here is the call graph for this function:

◆ isInside() [2/2]

bool geom::ComplexGeomObject::isInside ( const util::Point &  x) const
overridevirtual

Checks if point is inside this object.

Parameters
xPoint
Returns
True If point lies inside

Reimplemented from geom::GeomObject.

Definition at line 258 of file complexGeomObjects.cpp.

258 {
259
260 // point inside means x should be inside in the object with plus flag and
261 // outside in the object with minus flag
262 bool point_inside = d_obj[0]->isInside(x);
263 for (size_t i = 1; i < d_objFlag.size(); i++) {
264
265 const auto &obj_i = d_obj[i];
266 if (d_objFlagInt[i] < 0)
267 point_inside = point_inside and !obj_i->isInside(x);
268 else
269 point_inside = point_inside or obj_i->isInside(x);
270 }
271
272 return point_inside;
273 }

References d_obj, d_objFlag, and d_objFlagInt.

Referenced by doesIntersect(), isInside(), isOutside(), and isOutside().

Here is the caller graph for this function:

◆ isNear() [1/2]

bool geom::ComplexGeomObject::isNear ( const std::pair< util::Point, util::Point > &  box,
const double &  tol 
) const
overridevirtual

Checks if box is within given distance of this object.

Parameters
boxBox
tolTolerance used in checking the nearness
Returns
True True if box is inside within the tol distance

Reimplemented from geom::GeomObject.

Definition at line 334 of file complexGeomObjects.cpp.

336 {
337
338 bool is_near = d_obj[0]->isNear(box, tol);
339 for (size_t i = 1; i < d_objFlag.size(); i++) {
340
341 const auto &obj_i = d_obj[i];
342 is_near = is_near or obj_i->isNear(box, tol);
343 }
344
345 return is_near;
346 }

References box(), d_obj, and d_objFlag.

Here is the call graph for this function:

◆ isNear() [2/2]

bool geom::ComplexGeomObject::isNear ( const util::Point &  x,
const double &  tol 
) const
overridevirtual

Checks if point is within given distance of this object.

Parameters
xPoint
tolTolerance used in checking the nearness
Returns
True True if within the tol distance

Reimplemented from geom::GeomObject.

Definition at line 280 of file complexGeomObjects.cpp.

281 {
282
283 bool is_near = d_obj[0]->isNear(x, tol);
284 for (size_t i = 1; i < d_objFlag.size(); i++) {
285
286 const auto &obj_i = d_obj[i];
287 is_near = is_near or obj_i->isNear(x, tol);
288 }
289
290 return is_near;
291 }

References d_obj, and d_objFlag.

◆ isNearBoundary()

bool geom::ComplexGeomObject::isNearBoundary ( const util::Point &  x,
const double &  tol,
const bool &  within 
) const
overridevirtual

cons

cons

Reimplemented from geom::GeomObject.

Definition at line 293 of file complexGeomObjects.cpp.

296 {
297
298 bool is_near = d_obj[0]->isNearBoundary(x, tol, within);
299 for (size_t i = 1; i < d_objFlag.size(); i++) {
300
301 const auto &obj_i = d_obj[i];
302 is_near = is_near or obj_i->isNearBoundary(x, tol, within);
303 }
304
305 return is_near;
306 }

References d_obj, and d_objFlag.

Referenced by doesIntersect().

Here is the caller graph for this function:

◆ isOutside() [1/2]

bool geom::ComplexGeomObject::isOutside ( const std::pair< util::Point, util::Point > &  box) const
overridevirtual

Checks if box is outside of the object.

Parameters
boxBox
Returns
True True if box lies outside

Reimplemented from geom::GeomObject.

Definition at line 324 of file complexGeomObjects.cpp.

325 {
326
327 bool intersect = false;
328 for (auto p: geom::getCornerPoints(d_dim, box))
329 intersect = this->isInside(p);
330
331 return !intersect;
332 }

References box(), d_dim, geom::getCornerPoints(), and isInside().

Here is the call graph for this function:

◆ isOutside() [2/2]

bool geom::ComplexGeomObject::isOutside ( const util::Point &  x) const
overridevirtual

Checks if point is outside of this object.

Parameters
xPoint
Returns
True If point lies outside

Reimplemented from geom::GeomObject.

Definition at line 276 of file complexGeomObjects.cpp.

276 {
277 return !isInside(x);
278 }

References isInside().

Here is the call graph for this function:

◆ operator=()

ComplexGeomObject & geom::ComplexGeomObject::operator= ( const ComplexGeomObject &  other)
inline

Assignment operator.

Parameters
otherObject to copy from
Returns
Reference to this object

Definition at line 355 of file complexGeomObjects.h.

355 {
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;
362 d_objFlagInt = other.d_objFlagInt;
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 }

References geom::createGeomDeepCopy(), d_dim, d_obj, d_objFlag, d_objFlagInt, and geom::GeomObject::d_tags.

Here is the call graph for this function:

◆ print() [1/2]

void geom::ComplexGeomObject::print ( ) const
inlineoverridevirtual

Prints the information about the object.

Reimplemented from geom::GeomObject.

Definition at line 516 of file complexGeomObjects.h.

516{ print(0, 0); };
void print() const override
Prints the information about the object.

References print().

Referenced by print().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print() [2/2]

void geom::ComplexGeomObject::print ( int  nt,
int  lvl 
) const
inlineoverridevirtual

Prints the information about the object.

Parameters
ntNumber of tabs to append before printing
lvlInformation level (higher means more information)

Reimplemented from geom::GeomObject.

Definition at line 509 of file complexGeomObjects.h.

509 {
510 std::cout << printStr(nt, lvl);
511 };
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.

References printStr().

Here is the call graph for this function:

◆ printStr()

std::string geom::ComplexGeomObject::printStr ( int  nt,
int  lvl 
) const
overridevirtual

Returns the string containing printable information about the object.

Parameters
ntNumber of tabs to append before printing
lvlInformation level (higher means more information)
Returns
string String containing printable information about the object

Reimplemented from geom::GeomObject.

Definition at line 360 of file complexGeomObjects.cpp.

360 {
361
362 auto tabS = util::io::getTabS(nt);
363
364 std::ostringstream oss;
365
366 oss << tabS << "------- ComplexGeomObject --------" << std::endl
367 << std::endl;
368 oss << tabS << "Name = " << d_name << std::endl;
369 oss << tabS << "Center = " << center().printStr() << std::endl;
370 oss << tabS << "Object info:" << std::endl;
371 auto ocount = 0;
372 for (const auto &p: d_obj) {
373 oss << tabS << "Object id: " << ocount << std::endl;
374 oss << tabS << "Object flag: " << d_objFlag[ocount] << std::endl;
375 oss << tabS << "Object int flag: " << d_objFlagInt[ocount] << std::endl;
376 oss << p->printStr(nt + 1, lvl);
377 ocount++;
378 }
379
380 if (lvl > 0)
381 oss << tabS << "Bounding box: "
382 << util::io::printBoxStr(box(0.), nt + 1);
383
384 if (lvl == 0)
385 oss << std::endl;
386
387 return oss.str();
388 }
std::string printBoxStr(const std::pair< util::Point, util::Point > &box, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:231
std::string getTabS(int nt)
Returns tab spaces of a given size.
Definition io.h:82
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition point.h:94

References box(), center(), geom::GeomObject::d_name, d_obj, d_objFlag, d_objFlagInt, util::io::getTabS(), util::io::printBoxStr(), and util::Point::printStr().

Referenced by print().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ transform()

void geom::ComplexGeomObject::transform ( const util::Point &  translation,
const double &  scale,
const double &  angle,
const util::Point &  axis,
const util::Point *  rotationPoint 
)
inlineoverridevirtual

If rotationPoint is null, pivot is center() (signed-volume centroid of the composite).

Reimplemented from geom::GeomObject.

Definition at line 385 of file complexGeomObjects.h.

387 {
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 }

References center(), and d_obj.

Here is the call graph for this function:

◆ volume()

double geom::ComplexGeomObject::volume ( ) const
overridevirtual

Computes the volume (area in 2d, length in 1d) of object.

Returns
Volume Volume of object

Reimplemented from geom::GeomObject.

Definition at line 185 of file complexGeomObjects.cpp.

185 {
186
187 double volume = 0.;
188 for (size_t i = 0; i < d_objFlag.size(); i++)
189 volume += d_obj[i]->volume() * d_objFlagInt[i];
190
191 return volume;
192 }

References d_obj, d_objFlag, d_objFlagInt, and volume().

Referenced by center(), and volume().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ d_dim

size_t geom::ComplexGeomObject::d_dim

Dimension objects live in.

Definition at line 286 of file complexGeomObjects.h.

Referenced by ComplexGeomObject(), doesIntersect(), isInside(), isOutside(), and operator=().

◆ d_obj

◆ d_objFlag

std::vector<std::string> geom::ComplexGeomObject::d_objFlag

Object flag.

Ordering of objects is important. To describe a rectangle with circular hole, we will have d_obj = {rectangle, circle} and have flag = {plus, minus}. This means final object is rectangle - circle

Definition at line 278 of file complexGeomObjects.h.

Referenced by box(), center(), ComplexGeomObject(), isInside(), isNear(), isNear(), isNearBoundary(), operator=(), printStr(), and volume().

◆ d_objFlagInt

std::vector<int> geom::ComplexGeomObject::d_objFlagInt

Object integer flags. Here, +1 means object is filling and -1 means object is void.

Definition at line 283 of file complexGeomObjects.h.

Referenced by mesh_gen::anonymous_namespace{builtinGmshGeometry.cpp}::buildComplexRectangles2DOcc(), center(), ComplexGeomObject(), isInside(), operator=(), printStr(), and volume().


The documentation for this class was generated from the following files: