https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CSG::CSGPlane Class Reference

CSGPlane creates an internal representation of a Constructive Solid Geometry (CSG) plane, represented in the form aX + bY + cZ = d. More...

#include <CSGPlane.h>

Inheritance diagram for CSG::CSGPlane:
[legend]

Public Types

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

Public Member Functions

 CSGPlane (const std::string &name, const Point &p1, const Point &p2, const Point &p3)
 Construct a new CSGPlane surface from three non co-linear points.
 
 CSGPlane (const std::string &name, const Real a, const Real b, const Real c, const Real d)
 Construct a new CSGPlane surface from coefficients (a, b, c, d) for the equation of a plane: aX + bY + cZ = d.
 
virtual ~CSGPlane ()=default
 Destructor.
 
virtual std::unordered_map< std::string, Real > getCoeffs () const override
 get coefficients (a, b, c, d) of the Plane aX + bY + cZ = d
 
virtual Real evaluateSurfaceEquationAtPoint (const Point &p) const override
 given a point, determine its evaluation based on the equation of the plane
 
const std::string getSurfaceType () const
 Get the Surface Type.
 
CSGSurface::Halfspace getHalfspaceFromPoint (const Point &p) const
 given a point, determine if it is in the positive or negative half-space for the surface
 
const std::string & getName () const
 Get the name of surface.
 
virtual bool isEngUnit () const
 Whether this surface is an engineering unit.
 
bool operator== (const CSGSurface &other) const
 Operator overload for checking if two CSGSurface objects are equal.
 
bool operator!= (const CSGSurface &other) const
 Operator overload for checking if two CSGSurface objects are not equal.
 
const std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > & getTransformations () const
 Get the list of transformations.
 
std::vector< std::pair< std::string, std::tuple< Real, Real, Real > > > getTransformationsAsStrings () const
 Get the transformations of this object with string representations for types.
 

Static Public Member Functions

static bool isValidTransformationValue (TransformationType type, const std::tuple< Real, Real, Real > &values)
 Check if the transformation value is valid for the given type.
 
static std::string getTransformationTypeString (TransformationType type)
 Get the string representation of the transformation type.
 

Protected Member Functions

virtual std::unique_ptr< CSGSurfaceclone () const override
 create clone of CSGPlane object
 
void coeffsFromPoints (const Point &p1, const Point &p2, const Point &p3)
 
void normalizePlaneCoefficients ()
 Normalize plane coefficients so that a^2 + b^2 + c^2 = 1.
 
void setName (const std::string &name)
 
void addTransformation (TransformationType type, const std::tuple< Real, Real, Real > &values)
 Add a transformation to the list of transformations.
 
Point applyReverseTransformsToPoint (Point p) const
 update the value of point p by applying the inverse of the list of transformations to the point
 
 FRIEND_TEST (CSGSurfaceTest, testSetName)
 Friends for unit testing.
 
 FRIEND_TEST (CSGSurfaceTest, testSurfaceEquality)
 
 FRIEND_TEST (CSGSurfaceTest, testHalfspaceWithTransform)
 Friends for unit testing.
 
 FRIEND_TEST (CSGSurfaceTest, testHalfspaceWithNullTransform)
 
 FRIEND_TEST (CSGEngUnitTest, testEngUnitEqual)
 

Protected Attributes

Real _a
 Value of a in equation of plane.
 
Real _b
 Value of b in equation of plane.
 
Real _c
 Value of c in equation of plane.
 
Real _d
 Value of d in equation of plane.
 
std::string _name
 Name of surface.
 
std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > _transformations
 List of transformations applied to this object.
 

Detailed Description

CSGPlane creates an internal representation of a Constructive Solid Geometry (CSG) plane, represented in the form aX + bY + cZ = d.

Definition at line 23 of file CSGPlane.h.

Member Enumeration Documentation

◆ Halfspace

enum class 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.

Constructor & Destructor Documentation

◆ CSGPlane() [1/2]

CSG::CSGPlane::CSGPlane ( const std::string &  name,
const Point &  p1,
const Point &  p2,
const Point &  p3 
)

Construct a new CSGPlane surface from three non co-linear points.

Parameters
nameunique name of plane
p1point 1
p2point 2
p3point 3

Definition at line 15 of file CSGPlane.C.

16 : CSGSurface(name)
17{
18 coeffsFromPoints(p1, p2, p3);
20}
void coeffsFromPoints(const Point &p1, const Point &p2, const Point &p3)
Definition CSGPlane.C:36
void normalizePlaneCoefficients()
Normalize plane coefficients so that a^2 + b^2 + c^2 = 1.
Definition CSGPlane.C:55
CSGSurface(const std::string &name)
Default constructor.
Definition CSGSurface.C:17

◆ CSGPlane() [2/2]

CSG::CSGPlane::CSGPlane ( const std::string &  name,
const Real  a,
const Real  b,
const Real  c,
const Real  d 
)

Construct a new CSGPlane surface from coefficients (a, b, c, d) for the equation of a plane: aX + bY + cZ = d.

Parameters
nameunique name of plane
acoefficient a
bcoefficient b
ccoefficient c
dcoefficient d

Definition at line 22 of file CSGPlane.C.

23 : CSGSurface(name), _a(a), _b(b), _c(c), _d(d)
24{
26}
Real _b
Value of b in equation of plane.
Definition CSGPlane.h:90
Real _a
Value of a in equation of plane.
Definition CSGPlane.h:87
Real _d
Value of d in equation of plane.
Definition CSGPlane.h:96
Real _c
Value of c in equation of plane.
Definition CSGPlane.h:93

◆ ~CSGPlane()

virtual CSG::CSGPlane::~CSGPlane ( )
virtualdefault

Destructor.

Member Function Documentation

◆ addTransformation()

void CSG::CSGTransformationHelper::addTransformation ( TransformationType  type,
const std::tuple< Real, Real, Real > &  values 
)
protectedinherited

Add a transformation to the list of transformations.

Parameters
typeThe type of transformation
valuesThe values for the transformation

Definition at line 16 of file CSGTransformationHelper.C.

18{
20 mooseError("Invalid transformation values provided for transformation type " +
22 _transformations.emplace_back(type, values);
23}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
std::array< Real, 2 > values
Definition MortarUtils.C:52
static std::string getTransformationTypeString(TransformationType type)
Get the string representation of the transformation type.
static bool isValidTransformationValue(TransformationType type, const std::tuple< Real, Real, Real > &values)
Check if the transformation value is valid for the given type.
std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > _transformations
List of transformations applied to this object.

Referenced by CSG::CSGBase::addTransformation(), CSG::CSGBase::expandEngUnit(), CSG::CSGBase::expandEngUnit(), and CSG::CSGBase::expandEngUnit().

◆ applyReverseTransformsToPoint()

Point CSG::CSGTransformationHelper::applyReverseTransformsToPoint ( Point  p) const
protectedinherited

update the value of point p by applying the inverse of the list of transformations to the point

Parameters
ppoint to transform
Returns
transformed point

Definition at line 74 of file CSGTransformationHelper.C.

75{
76 // iterate list of transformations in reverse and apply the inverse operation
77 for (auto it = _transformations.rbegin(); it != _transformations.rend(); ++it)
78 {
79 auto trans_type = it->first;
80 auto val = it->second;
81
82 if (trans_type == TransformationType::TRANSLATION)
83 {
84 Point offset(std::get<0>(val), std::get<1>(val), std::get<2>(val));
85 p -= offset;
86 }
87 else if (trans_type == TransformationType::SCALE)
88 {
89 Point scale(std::get<0>(val), std::get<1>(val), std::get<2>(val));
90 for (int i = 0; i < 3; ++i)
91 p(i) /= scale(i);
92 }
93 else if (trans_type == TransformationType::ROTATION)
94 {
95 // get the transpose of the original rotation matrix and apply to point p
96 const auto rot_matrix = RealTensorValue::intrinsic_rotation_matrix(
97 std::get<0>(val), std::get<1>(val), std::get<2>(val));
98 const auto rot_transpose = rot_matrix.transpose();
99 p = rot_transpose * p;
100 }
101 else
102 mooseError("Transformation type is not recognized.");
103 }
104 return p;
105}
Real scale
Definition MortarUtils.C:62

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

◆ clone()

virtual std::unique_ptr< CSGSurface > CSG::CSGPlane::clone ( ) const
inlineoverrideprotectedvirtual

create clone of CSGPlane object

Returns
std::unordered_map<CSGSurface> unique_ptr to cloned plane

Implements CSG::CSGSurface.

Definition at line 75 of file CSGPlane.h.

76 {
77 return std::make_unique<CSGPlane>(_name, _a, _b, _c, _d);
78 }
std::string _name
Name of surface.
Definition CSGSurface.h:122

◆ coeffsFromPoints()

void CSG::CSGPlane::coeffsFromPoints ( const Point &  p1,
const Point &  p2,
const Point &  p3 
)
protected

Definition at line 36 of file CSGPlane.C.

37{
38 // Use three points on plane to solve for the plane equation in form aX + bY +cZ = d,
39 // where we are solving for a, b, c, and d.
40 RealVectorValue v1 = p2 - p1;
41 RealVectorValue v2 = p3 - p1;
42 RealVectorValue cross = v2.cross(v1);
43
44 // Check that provided points aren't collinear
45 if (MooseUtils::absoluteFuzzyEqual(cross.norm(), 0))
46 mooseError("Provided points to define a CSGPlane are collinear");
47
48 _a = cross(0);
49 _b = cross(1);
50 _c = cross(2);
51 _d = cross * (RealVectorValue)p1;
52}
TypeVector< typename CompareTypes< T, T2 >::supertype > cross(const TypeVector< T2 > &v) const
VectorValue< Real > RealVectorValue
Definition SubProblem.h:34

Referenced by CSGPlane().

◆ evaluateSurfaceEquationAtPoint()

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

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

Parameters
ppoint
Returns
evaluation of point based on surface equation

Implements CSG::CSGSurface.

Definition at line 65 of file CSGPlane.C.

66{
67 // Compute dot product of <a, b, c> and p to determine if p lies
68 // in the positive or negative halfspace of the plane
69 const Real dot_prod = _a * p(0) + _b * p(1) + _c * p(2);
70
71 return dot_prod - _d;
72}
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ FRIEND_TEST() [1/5]

CSG::CSGTransformationHelper::FRIEND_TEST ( CSGEngUnitTest  ,
testEngUnitEqual   
)
protectedinherited

◆ FRIEND_TEST() [2/5]

CSG::CSGTransformationHelper::FRIEND_TEST ( CSGSurfaceTest  ,
testHalfspaceWithNullTransform   
)
protectedinherited

◆ FRIEND_TEST() [3/5]

CSG::CSGTransformationHelper::FRIEND_TEST ( CSGSurfaceTest  ,
testHalfspaceWithTransform   
)
protectedinherited

Friends for unit testing.

◆ FRIEND_TEST() [4/5]

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

Friends for unit testing.

◆ FRIEND_TEST() [5/5]

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

◆ getCoeffs()

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

get coefficients (a, b, c, d) of the Plane aX + bY + cZ = d

Returns
std::unordered_map<std::string, Real> map of coefficients (a, b, c, and d) and their values

Implements CSG::CSGSurface.

Definition at line 29 of file CSGPlane.C.

30{
31 std::unordered_map<std::string, Real> coeffs = {{"a", _a}, {"b", _b}, {"c", _c}, {"d", _d}};
32 return coeffs;
33}

◆ 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 23 of file CSGSurface.C.

24{
25 // if transformations are present on the surface, apply them in reverse to the point and pass that
26 // new point to the evaluation to ensure transformations are considered.
27
28 // Create a local transformed copy - the original p in the calling scope is NOT modified
29 const Point p_trans = getTransformations().size() ? applyReverseTransformsToPoint(p) : p;
30
31 auto eval = evaluateSurfaceEquationAtPoint(p_trans);
32 if (MooseUtils::absoluteFuzzyGreaterThan(eval, 0))
34 else if (MooseUtils::absoluteFuzzyLessThan(eval, 0))
36 else
37 mooseError("Point ",
38 p,
39 " used to determine halfspace evaluation lies on the surface ",
40 _name,
41 ", leading to an ambiguously defined halfspace.");
42}
virtual Real evaluateSurfaceEquationAtPoint(const Point &p) const =0
given a point, determine its evaluation based on the surface equation.
const std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > & getTransformations() const
Get the list of transformations.
Point applyReverseTransformsToPoint(Point p) const
update the value of point p by applying the inverse of the list of transformations to the point

◆ getName()

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

◆ getSurfaceType()

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

Get the Surface Type.

Returns
type of surface

Definition at line 53 of file CSGSurface.h.

54 {
55 return MooseUtils::prettyCppType(libMesh::demangle(typeid(*this).name()));
56 }
std::string prettyCppType(const std::string &cpp_type)
std::string demangle(const char *name)

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

◆ getTransformations()

const std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > & CSG::CSGTransformationHelper::getTransformations ( ) const
inlineinherited

◆ getTransformationsAsStrings()

std::vector< std::pair< std::string, std::tuple< Real, Real, Real > > > CSG::CSGTransformationHelper::getTransformationsAsStrings ( ) const
inherited

Get the transformations of this object with string representations for types.

Returns
Vector of transformation pairs with string representations for types

Definition at line 65 of file CSGTransformationHelper.C.

66{
67 std::vector<std::pair<std::string, std::tuple<Real, Real, Real>>> result;
68 for (const auto & transform_pair : _transformations)
69 result.emplace_back(getTransformationTypeString(transform_pair.first), transform_pair.second);
70 return result;
71}

Referenced by CSG::CSGCellEngUnit::getTransformationsAsStrings(), CSG::CSGSurfaceEngUnit::getTransformationsAsStrings(), and CSG::CSGUniverseEngUnit::getTransformationsAsStrings().

◆ getTransformationTypeString()

std::string CSG::CSGTransformationHelper::getTransformationTypeString ( TransformationType  type)
staticinherited

Get the string representation of the transformation type.

Parameters
typeThe transformation type
Returns
String name of the transformation type

Definition at line 56 of file CSGTransformationHelper.C.

57{
58 // Set the enum to the value and convert it to string
60 enum_copy = static_cast<int>(type);
61 return std::string(enum_copy);
62}
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
static const MooseEnum transformation_type_enum
MooseEnum for transformation types, matching the TransformationType enum values.

Referenced by CSG::CSGTransformationHelper::addTransformation(), and CSG::CSGTransformationHelper::getTransformationsAsStrings().

◆ isEngUnit()

virtual bool CSG::CSGSurface::isEngUnit ( ) const
inlinevirtualinherited

Whether this surface is an engineering unit.

Returns false for a plain CSGSurface; overridden to return true by the engineering unit types. Used to avoid a dynamic_cast on the common plain-surface comparison path (see operator==).

Returns
true if this object is a CSGEngUnit, otherwise false

Reimplemented in CSG::CSGSurfaceEngUnit.

Definition at line 101 of file CSGSurface.h.

101{ return false; }

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

◆ isValidTransformationValue()

bool CSG::CSGTransformationHelper::isValidTransformationValue ( TransformationType  type,
const std::tuple< Real, Real, Real > &  values 
)
staticinherited

Check if the transformation value is valid for the given type.

Parameters
typeThe type of transformation
valuesThe values for the transformation
Returns
True if the values are valid for the type

Definition at line 26 of file CSGTransformationHelper.C.

28{
29 // Additional validation specific to each transformation type could be added here
30 switch (type)
31 {
33 // All translation values are inherently valid
34 return true;
35
37 // Rotation uses euler notation; values are angles in degrees (phi, theta, psi)
38 // For consistency with TransformGenerator, there are no restrictions on the angles
39 // phi: rotation around Z-axis
40 // theta: rotation around new X-axis
41 // psi: rotation around new Z-axis
42 return true;
43
45 // Scaling factors should be non-zero
46 if (std::get<0>(values) == 0.0 || std::get<1>(values) == 0.0 || std::get<2>(values) == 0.0)
47 return false;
48 return true;
49
50 default:
51 mooseError("Unknown transformation type");
52 }
53}

Referenced by CSG::CSGTransformationHelper::addTransformation().

◆ normalizePlaneCoefficients()

void CSG::CSGPlane::normalizePlaneCoefficients ( )
protected

Normalize plane coefficients so that a^2 + b^2 + c^2 = 1.

Definition at line 55 of file CSGPlane.C.

56{
57 const auto k = 1. / std::sqrt(_a * _a + _b * _b + _c * _c);
58 _a *= k;
59 _b *= k;
60 _c *= k;
61 _d *= k;
62}

Referenced by CSGPlane(), and CSGPlane().

◆ operator!=()

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

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

Definition at line 65 of file CSGSurface.C.

66{
67 return !(*this == other);
68}

◆ operator==()

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

Operator overload for checking if two CSGSurface objects are equal.

Definition at line 45 of file CSGSurface.C.

46{
47 // If both objects are engineering units, delegate to CSGEngUnit::operator== to avoid
48 // calling getCoeffs(), which is not supported on engineering unit types. The isEngUnit()
49 // check keeps the common plain-surface path free of any dynamic_cast; the casts below
50 // only run once we know the objects are engineering units.
51 if (isEngUnit())
52 {
53 if (other.isEngUnit())
54 return *dynamic_cast<const CSGEngUnit *>(this) == *dynamic_cast<const CSGEngUnit *>(&other);
55 return false; // an engineering unit cannot equal a plain surface
56 }
57
58 return (this->getName() == other.getName()) &&
59 (this->getSurfaceType() == other.getSurfaceType()) &&
60 (this->getCoeffs() == other.getCoeffs()) &&
61 (this->getTransformations() == other.getTransformations());
62}
const std::string getSurfaceType() const
Get the Surface Type.
Definition CSGSurface.h:53
virtual bool isEngUnit() const
Whether this surface is an engineering unit.
Definition CSGSurface.h:101
const std::string & getName() const
Get the name of surface.
Definition CSGSurface.h:90
virtual std::unordered_map< std::string, Real > getCoeffs() const =0
Get the coefficients that define the surface.

◆ setName()

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

Definition at line 119 of file CSGSurface.h.

119{ _name = name; }
std::string name(const ElemQuality q)

Member Data Documentation

◆ _a

Real CSG::CSGPlane::_a
protected

Value of a in equation of plane.

Definition at line 87 of file CSGPlane.h.

Referenced by clone(), coeffsFromPoints(), evaluateSurfaceEquationAtPoint(), getCoeffs(), and normalizePlaneCoefficients().

◆ _b

Real CSG::CSGPlane::_b
protected

Value of b in equation of plane.

Definition at line 90 of file CSGPlane.h.

Referenced by clone(), coeffsFromPoints(), evaluateSurfaceEquationAtPoint(), getCoeffs(), and normalizePlaneCoefficients().

◆ _c

Real CSG::CSGPlane::_c
protected

Value of c in equation of plane.

Definition at line 93 of file CSGPlane.h.

Referenced by clone(), coeffsFromPoints(), evaluateSurfaceEquationAtPoint(), getCoeffs(), and normalizePlaneCoefficients().

◆ _d

Real CSG::CSGPlane::_d
protected

Value of d in equation of plane.

Definition at line 96 of file CSGPlane.h.

Referenced by clone(), coeffsFromPoints(), evaluateSurfaceEquationAtPoint(), getCoeffs(), and normalizePlaneCoefficients().

◆ _name

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

◆ _transformations

std::vector<std::pair<TransformationType, std::tuple<Real, Real, Real> > > CSG::CSGTransformationHelper::_transformations
protectedinherited

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