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

CSGYCylinder creates an internal representation of a Constructive Solid Geometry (CSG) y-axis aligned cylinder, represented in the following form (x - x0)^2 + (z - z0)^2 = r^2. More...

#include <CSGYCylinder.h>

Inheritance diagram for CSG::CSGYCylinder:
[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

 CSGYCylinder (const std::string &name, const Real x0, const Real z0, const Real r)
 Construct a cylinder surface aligned with the y axis. More...
 
virtual ~CSGYCylinder ()=default
 Destructor. More...
 
virtual std::unordered_map< std::string, RealgetCoeffs () const override
 Get the coefficients (x0, z0, and r) that define the cylindrical surface with the equation: (x - x0)^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 cylinder 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...
 
const std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > & getTransformations () const
 Get the list of transformations. More...
 
std::vector< std::pair< std::string, std::tuple< Real, Real, Real > > > getTransformationsAsStrings () const
 Get the transformations of this object with string representations for types. More...
 

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. More...
 
static std::string getTransformationTypeString (TransformationType type)
 Get the string representation of the transformation type. More...
 

Protected Member Functions

virtual std::unique_ptr< CSGSurfaceclone () const override
 create clone of CSGYCylinder object More...
 
void checkRadius () const
 
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. More...
 
Point applyReverseTransformsToPoint (Point p) const
 update the value of point p by applying the inverse of the list of transformations to the point More...
 
 FRIEND_TEST (CSGSurfaceTest, testSetName)
 Friends for unit testing. More...
 
 FRIEND_TEST (CSGSurfaceTest, testSurfaceEquality)
 
 FRIEND_TEST (CSGSurfaceTest, testHalfspaceWithTransform)
 Friends for unit testing. More...
 
 FRIEND_TEST (CSGSurfaceTest, testHalfspaceWithNullTransform)
 

Protected Attributes

Real _x0
 Value of x0 in equation of an y-axis aligned cylinder. More...
 
Real _z0
 Value of z0 in equation of an y-axis aligned cylinder. More...
 
Real _r
 Value of r in equation of an y-axis aligned cylinder. 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...
 
std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > _transformations
 List of transformations applied to this object. More...
 

Detailed Description

CSGYCylinder creates an internal representation of a Constructive Solid Geometry (CSG) y-axis aligned cylinder, represented in the following form (x - x0)^2 + (z - z0)^2 = r^2.

Definition at line 23 of file CSGYCylinder.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

◆ CSGYCylinder()

CSG::CSGYCylinder::CSGYCylinder ( const std::string &  name,
const Real  x0,
const Real  z0,
const Real  r 
)

Construct a cylinder surface aligned with the y axis.

Parameters
nameunique name of surface
x0x coordinate of center
z0z coordinate of center
rradius

Definition at line 15 of file CSGYCylinder.C.

16  : CSGSurface(name, MooseUtils::prettyCppType<CSGYCylinder>()), _x0(x0), _z0(z0), _r(r)
17 {
18  checkRadius();
19 }
void checkRadius() const
Definition: CSGYCylinder.C:39
Real _z0
Value of z0 in equation of an y-axis aligned cylinder.
Definition: CSGYCylinder.h:75
Real _r
Value of r in equation of an y-axis aligned cylinder.
Definition: CSGYCylinder.h:78
CSGSurface(const std::string &name)
Default constructor.
Real _x0
Value of x0 in equation of an y-axis aligned cylinder.
Definition: CSGYCylinder.h:72

◆ ~CSGYCylinder()

virtual CSG::CSGYCylinder::~CSGYCylinder ( )
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 {
19  if (!isValidTransformationValue(type, values))
20  mooseError("Invalid transformation values provided for transformation type " +
22  _transformations.emplace_back(type, values);
23 }
static bool isValidTransformationValue(TransformationType type, const std::tuple< Real, Real, Real > &values)
Check if the transformation value is valid for the given type.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
static std::string getTransformationTypeString(TransformationType type)
Get the string representation of the transformation type.
std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > _transformations
List of transformations applied to this object.

◆ 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.

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

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 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
void scale(MeshBase &mesh, const Real xs, const Real ys=0., const Real zs=0.)
std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > _transformations
List of transformations applied to this object.
static TensorValue< Real > intrinsic_rotation_matrix(Real phi, Real theta, Real psi)

◆ checkRadius()

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

Definition at line 39 of file CSGYCylinder.C.

Referenced by CSGYCylinder().

40 {
41  if (_r <= 0.0)
42  mooseError("Radius of y-cylinder must be positive.");
43 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
Real _r
Value of r in equation of an y-axis aligned cylinder.
Definition: CSGYCylinder.h:78

◆ clone()

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

create clone of CSGYCylinder object

Returns
std::unordered_map<CSGSurface> unique_ptr to cloned y-cylinder

Implements CSG::CSGSurface.

Definition at line 63 of file CSGYCylinder.h.

64  {
65  return std::make_unique<CSGYCylinder>(_name, _x0, _z0, _r);
66  }
Real _z0
Value of z0 in equation of an y-axis aligned cylinder.
Definition: CSGYCylinder.h:75
Real _r
Value of r in equation of an y-axis aligned cylinder.
Definition: CSGYCylinder.h:78
std::string _name
Name of surface.
Definition: CSGSurface.h:116
Real _x0
Value of x0 in equation of an y-axis aligned cylinder.
Definition: CSGYCylinder.h:72

◆ evaluateSurfaceEquationAtPoint()

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

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

Parameters
ppoint
Returns
evaluation of point based on surface equation

Implements CSG::CSGSurface.

Definition at line 29 of file CSGYCylinder.C.

30 {
31  // Compute distance from the cylinder center to determine if inside (< r^2)
32  // or outside (> r^2) the cylinder
33  const Real dist_sq = Utility::pow<2>((p(0) - _x0)) + Utility::pow<2>((p(2) - _z0));
34 
35  return dist_sq - Utility::pow<2>(_r);
36 }
Real _z0
Value of z0 in equation of an y-axis aligned cylinder.
Definition: CSGYCylinder.h:75
Real _r
Value of r in equation of an y-axis aligned cylinder.
Definition: CSGYCylinder.h:78
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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
Real _x0
Value of x0 in equation of an y-axis aligned cylinder.
Definition: CSGYCylinder.h:72

◆ FRIEND_TEST() [1/4]

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

Friends for unit testing.

◆ FRIEND_TEST() [2/4]

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

◆ FRIEND_TEST() [3/4]

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

Friends for unit testing.

◆ FRIEND_TEST() [4/4]

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

◆ getCoeffs()

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

Get the coefficients (x0, z0, and r) that define the cylindrical surface with the equation: (x - x0)^2 + (z - z0)^2 = r^2.

Returns
map of coefficients to their value

Implements CSG::CSGSurface.

Definition at line 22 of file CSGYCylinder.C.

23 {
24  std::unordered_map<std::string, Real> coeffs = {{"x0", _x0}, {"z0", _z0}, {"r", _r}};
25  return coeffs;
26 }
Real _z0
Value of z0 in equation of an y-axis aligned cylinder.
Definition: CSGYCylinder.h:75
Real _r
Value of r in equation of an y-axis aligned cylinder.
Definition: CSGYCylinder.h:78
Real _x0
Value of x0 in equation of an y-axis aligned cylinder.
Definition: CSGYCylinder.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 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))
33  return Halfspace::POSITIVE;
34  else if (MooseUtils::absoluteFuzzyLessThan(eval, 0))
35  return Halfspace::NEGATIVE;
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 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
virtual Real evaluateSurfaceEquationAtPoint(const Point &p) const =0
given a point, determine its evaluation based on the surface equation.
Point applyReverseTransformsToPoint(Point p) const
update the value of point p by applying the inverse of the list of transformations to the point ...
std::string _name
Name of surface.
Definition: CSGSurface.h:116
const std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > & getTransformations() const
Get the list of transformations.

◆ 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::CSGBase::addTransformation(), CSG::CSGBase::checkSurfaceInBase(), CSG::CSGBase::deleteSurface(), CSG::CSGSurface::operator==(), and CSG::CSGSurfaceList::renameSurface().

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

◆ 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:120

◆ getTransformations()

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

Get the list of transformations.

Returns
The list of transformations

Definition at line 47 of file CSGTransformationHelper.h.

Referenced by CSG::CSGSurface::getHalfspaceFromPoint(), CSG::CSGUniverse::operator==(), CSG::CSGSurface::operator==(), CSG::CSGCell::operator==(), and CSG::CSGLattice::operator==().

48  {
49  return _transformations;
50  }
std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > _transformations
List of transformations applied to this object.

◆ 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 }
static std::string getTransformationTypeString(TransformationType type)
Get the string representation of the transformation type.
std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > _transformations
List of transformations applied to this object.

◆ 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.

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

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:54
static const MooseEnum transformation_type_enum
MooseEnum for transformation types, matching the TransformationType enum values.

◆ 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.

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

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 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311

◆ operator!=()

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

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

Definition at line 54 of file CSGSurface.C.

55 {
56  return !(*this == other);
57 }

◆ 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  return (this->getName() == other.getName()) &&
48  (this->getSurfaceType() == other.getSurfaceType()) &&
49  (this->getCoeffs() == other.getCoeffs()) &&
50  (this->getTransformations() == other.getTransformations());
51 }
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
const std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > & getTransformations() const
Get the list of transformations.

◆ setName()

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

Definition at line 113 of file CSGSurface.h.

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

Member Data Documentation

◆ _name

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

◆ _r

Real CSG::CSGYCylinder::_r
protected

Value of r in equation of an y-axis aligned cylinder.

Definition at line 78 of file CSGYCylinder.h.

Referenced by checkRadius(), clone(), 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 120 of file CSGSurface.h.

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

◆ _transformations

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

◆ _x0

Real CSG::CSGYCylinder::_x0
protected

Value of x0 in equation of an y-axis aligned cylinder.

Definition at line 72 of file CSGYCylinder.h.

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

◆ _z0

Real CSG::CSGYCylinder::_z0
protected

Value of z0 in equation of an y-axis aligned cylinder.

Definition at line 75 of file CSGYCylinder.h.

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


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