https://mooseframework.inl.gov
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CSG::CSGSphere Class Reference

CSGSphere creates an internal representation of a Constructive Solid Geometry (CSG) sphere, represented in the form (x - x0)^2 + (y - y0)^2 + (z - z0)^2 = r^2. More...

#include <CSGSphere.h>

Inheritance diagram for CSG::CSGSphere:
[legend]

Public Types

enum  Halfspace { Halfspace::POSITIVE, Halfspace::NEGATIVE }
 Enum for the sign of the half-space being represented by a point and surface. More...
 

Public Member Functions

 CSGSphere (const std::string &name, const Point &center, const Real r)
 Construct a new CSGSphere surface. More...
 
 CSGSphere (const std::string &name, const Real r)
 Construct a new CSGSphere surface. More...
 
virtual ~CSGSphere ()=default
 Destructor. More...
 
virtual std::unordered_map< std::string, RealgetCoeffs () const override
 Get the coefficients (x0, y0, z0, r) for the equation of a sphere (x - x0)^2 + (y - y0)^2 + (z - z0)^2 = r^2. More...
 
virtual Real evaluateSurfaceEquationAtPoint (const Point &p) const override
 given a point, determine its evaluation based on the equation of the sphere More...
 
const std::string & getSurfaceType () const
 Get the Surface Type. More...
 
CSGSurface::Halfspace getHalfspaceFromPoint (const Point &p) const
 given a point, determine if it is in the positive or negative half-space for the surface More...
 
const std::string & getName () const
 Get the name of surface. More...
 
bool operator== (const CSGSurface &other) const
 Operator overload for checking if two CSGSurface objects are equal. More...
 
bool operator!= (const CSGSurface &other) const
 Operator overload for checking if two CSGSurface objects are not equal. More...
 

Protected Member Functions

void checkRadius () const
 
void setName (const std::string &name)
 
 FRIEND_TEST (CSGSurfaceTest, testSetName)
 Friends for unit testing. More...
 

Protected Attributes

Real _x0
 Value of x0 in equation of sphere. More...
 
Real _y0
 Value of y0 in equation of sphere. More...
 
Real _z0
 Value of z0 in equation of sphere. More...
 
Real _r
 Value of r in equation of sphere. More...
 
std::string _name
 Name of surface. More...
 
const std::string _surface_type
 Type of surface that is being represented string is taken directly from the surface class name. More...
 

Detailed Description

CSGSphere creates an internal representation of a Constructive Solid Geometry (CSG) sphere, represented in the form (x - x0)^2 + (y - y0)^2 + (z - z0)^2 = r^2.

Definition at line 23 of file CSGSphere.h.

Member Enumeration Documentation

◆ Halfspace

enum CSG::CSGSurface::Halfspace
stronginherited

Enum for the sign of the half-space being represented by a point and surface.

Enumerator
POSITIVE 
NEGATIVE 

Definition at line 30 of file CSGSurface.h.

31  {
32  POSITIVE,
33  NEGATIVE
34  };

Constructor & Destructor Documentation

◆ CSGSphere() [1/2]

CSG::CSGSphere::CSGSphere ( const std::string &  name,
const Point &  center,
const Real  r 
)

Construct a new CSGSphere surface.

Parameters
nameunique name for the sphere surface
centercenter point of sphere
rradius of sphere

Definition at line 15 of file CSGSphere.C.

16  : CSGSurface(name, MooseUtils::prettyCppType<CSGSphere>()),
17  _x0(center(0)),
18  _y0(center(1)),
19  _z0(center(2)),
20  _r(r)
21 {
22  checkRadius();
23 }
void checkRadius() const
Definition: CSGSphere.C:50
Real _r
Value of r in equation of sphere.
Definition: CSGSphere.h:78
Real _z0
Value of z0 in equation of sphere.
Definition: CSGSphere.h:75
Real _x0
Value of x0 in equation of sphere.
Definition: CSGSphere.h:69
CSGSurface(const std::string &name)
Default constructor.
Real _y0
Value of y0 in equation of sphere.
Definition: CSGSphere.h:72

◆ CSGSphere() [2/2]

CSG::CSGSphere::CSGSphere ( const std::string &  name,
const Real  r 
)

Construct a new CSGSphere surface.

Parameters
nameunique name for the sphere surface
rradius of sphere

Definition at line 25 of file CSGSphere.C.

26  : CSGSurface(name, MooseUtils::prettyCppType<CSGSphere>()), _x0(0.0), _y0(0.0), _z0(0.0), _r(r)
27 {
28  checkRadius();
29 }
void checkRadius() const
Definition: CSGSphere.C:50
Real _r
Value of r in equation of sphere.
Definition: CSGSphere.h:78
Real _z0
Value of z0 in equation of sphere.
Definition: CSGSphere.h:75
Real _x0
Value of x0 in equation of sphere.
Definition: CSGSphere.h:69
CSGSurface(const std::string &name)
Default constructor.
Real _y0
Value of y0 in equation of sphere.
Definition: CSGSphere.h:72

◆ ~CSGSphere()

virtual CSG::CSGSphere::~CSGSphere ( )
virtualdefault

Destructor.

Member Function Documentation

◆ checkRadius()

void CSG::CSGSphere::checkRadius ( ) const
protected

Definition at line 50 of file CSGSphere.C.

Referenced by CSGSphere().

51 {
52  if (_r <= 0.0)
53  mooseError("Radius of sphere must be positive.");
54 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
Real _r
Value of r in equation of sphere.
Definition: CSGSphere.h:78

◆ evaluateSurfaceEquationAtPoint()

Real CSG::CSGSphere::evaluateSurfaceEquationAtPoint ( const Point &  p) const
overridevirtual

given a point, determine its evaluation based on the equation of the sphere

Parameters
ppoint
Returns
evaluation of point based on surface equation

Implements CSG::CSGSurface.

Definition at line 39 of file CSGSphere.C.

40 {
41  // Compute distance from the sphere center to determine if inside (< r^2)
42  // or outside (> r^2) the sphere
43  const Real dist_sq =
44  Utility::pow<2>((p(0) - _x0)) + Utility::pow<2>((p(1) - _y0)) + Utility::pow<2>((p(2) - _z0));
45 
46  return dist_sq - Utility::pow<2>(_r);
47 }
Real _r
Value of r in equation of sphere.
Definition: CSGSphere.h:78
Real _z0
Value of z0 in equation of sphere.
Definition: CSGSphere.h:75
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real _x0
Value of x0 in equation of sphere.
Definition: CSGSphere.h:69
Real _y0
Value of y0 in equation of sphere.
Definition: CSGSphere.h:72
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template pow< 2 >(tan(_arg))+1.0) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(sqrt

◆ FRIEND_TEST()

CSG::CSGSurface::FRIEND_TEST ( CSGSurfaceTest  ,
testSetName   
)
protectedinherited

Friends for unit testing.

◆ getCoeffs()

std::unordered_map< std::string, Real > CSG::CSGSphere::getCoeffs ( ) const
overridevirtual

Get the coefficients (x0, y0, z0, r) for the equation of a sphere (x - x0)^2 + (y - y0)^2 + (z - z0)^2 = r^2.

Returns
map of coefficients (x0, y0, z0, and r) and their values

Implements CSG::CSGSurface.

Definition at line 32 of file CSGSphere.C.

33 {
34  std::unordered_map<std::string, Real> coeffs = {{"x0", _x0}, {"y0", _y0}, {"z0", _z0}, {"r", _r}};
35  return coeffs;
36 }
Real _r
Value of r in equation of sphere.
Definition: CSGSphere.h:78
Real _z0
Value of z0 in equation of sphere.
Definition: CSGSphere.h:75
Real _x0
Value of x0 in equation of sphere.
Definition: CSGSphere.h:69
Real _y0
Value of y0 in equation of sphere.
Definition: CSGSphere.h:72

◆ getHalfspaceFromPoint()

CSGSurface::Halfspace CSG::CSGSurface::getHalfspaceFromPoint ( const Point &  p) const
inherited

given a point, determine if it is in the positive or negative half-space for the surface

Parameters
ppoint
Returns
sign of the half-space

Definition at line 21 of file CSGSurface.C.

22 {
23  auto eval = evaluateSurfaceEquationAtPoint(p);
25  return Halfspace::POSITIVE;
26  else if (MooseUtils::absoluteFuzzyLessThan(eval, 0))
27  return Halfspace::NEGATIVE;
28  else
29  mooseError("Point ",
30  p,
31  " used to determine halfspace evaluation lies on the surface ",
32  _name,
33  ", leading to an ambiguously defined halfspace.");
34 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
virtual Real evaluateSurfaceEquationAtPoint(const Point &p) const =0
given a point, determine its evaluation based on the surface equation.
bool absoluteFuzzyLessThan(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is less than another variable within an absolute tolerance...
Definition: MooseUtils.h:477
std::string _name
Name of surface.
Definition: CSGSurface.h:109
bool absoluteFuzzyGreaterThan(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than another variable within an absolute tolerance...
Definition: MooseUtils.h:430

◆ getName()

const std::string& CSG::CSGSurface::getName ( ) const
inlineinherited

Get the name of surface.

Returns
std::string name of surface

Definition at line 95 of file CSGSurface.h.

Referenced by CSG::CSGSurfaceList::addSurface(), CSG::CSGRegion::CSGRegion(), CSG::CSGSurface::operator==(), and CSG::CSGSurfaceList::renameSurface().

95 { return _name; }
std::string _name
Name of surface.
Definition: CSGSurface.h:109

◆ getSurfaceType()

const std::string& CSG::CSGSurface::getSurfaceType ( ) const
inlineinherited

Get the Surface Type.

Returns
type of surface

Definition at line 61 of file CSGSurface.h.

Referenced by CSG::CSGSurface::operator==().

61 { return _surface_type; }
const std::string _surface_type
Type of surface that is being represented string is taken directly from the surface class name...
Definition: CSGSurface.h:113

◆ operator!=()

bool CSG::CSGSurface::operator!= ( const CSGSurface other) const
inherited

Operator overload for checking if two CSGSurface objects are not equal.

Definition at line 45 of file CSGSurface.C.

46 {
47  return !(*this == other);
48 }

◆ operator==()

bool CSG::CSGSurface::operator== ( const CSGSurface other) const
inherited

Operator overload for checking if two CSGSurface objects are equal.

Definition at line 37 of file CSGSurface.C.

38 {
39  return (this->getName() == other.getName()) &&
40  (this->getSurfaceType() == other.getSurfaceType()) &&
41  (this->getCoeffs() == other.getCoeffs());
42 }
const std::string & getName() const
Get the name of surface.
Definition: CSGSurface.h:95
virtual std::unordered_map< std::string, Real > getCoeffs() const =0
Get the coefficients that define the surface.
const std::string & getSurfaceType() const
Get the Surface Type.
Definition: CSGSurface.h:61

◆ setName()

void CSG::CSGSurface::setName ( const std::string &  name)
inlineprotectedinherited

Definition at line 106 of file CSGSurface.h.

106 { _name = name; }
std::string name(const ElemQuality q)
std::string _name
Name of surface.
Definition: CSGSurface.h:109

Member Data Documentation

◆ _name

std::string CSG::CSGSurface::_name
protectedinherited

Name of surface.

Definition at line 109 of file CSGSurface.h.

Referenced by CSG::CSGSurface::getHalfspaceFromPoint(), CSG::CSGSurface::getName(), and CSG::CSGSurface::setName().

◆ _r

Real CSG::CSGSphere::_r
protected

Value of r in equation of sphere.

Definition at line 78 of file CSGSphere.h.

Referenced by checkRadius(), evaluateSurfaceEquationAtPoint(), and getCoeffs().

◆ _surface_type

const std::string CSG::CSGSurface::_surface_type
protectedinherited

Type of surface that is being represented string is taken directly from the surface class name.

Definition at line 113 of file CSGSurface.h.

Referenced by CSG::CSGSurface::getSurfaceType().

◆ _x0

Real CSG::CSGSphere::_x0
protected

Value of x0 in equation of sphere.

Definition at line 69 of file CSGSphere.h.

Referenced by evaluateSurfaceEquationAtPoint(), and getCoeffs().

◆ _y0

Real CSG::CSGSphere::_y0
protected

Value of y0 in equation of sphere.

Definition at line 72 of file CSGSphere.h.

Referenced by evaluateSurfaceEquationAtPoint(), and getCoeffs().

◆ _z0

Real CSG::CSGSphere::_z0
protected

Value of z0 in equation of sphere.

Definition at line 75 of file CSGSphere.h.

Referenced by evaluateSurfaceEquationAtPoint(), and getCoeffs().


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