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

CSGUniverse creates an internal representation of a Constructive Solid Geometry (CSG) universe, which represents a collection of cells that can be defined repeatedly within a separate container of cells. More...

#include <CSGUniverse.h>

Inheritance diagram for CSG::CSGUniverse:
[legend]

Public Member Functions

 CSGUniverse (const std::string &name, bool is_root=false)
 Construct a new CSGUniverse object.
 
 CSGUniverse (const std::string &name, std::vector< CSGCell * > &cells, bool is_root=false)
 Construct a new CSGUniverse object from list of cells.
 
virtual ~CSGUniverse ()=default
 Destructor.
 
const CSGCellgetCell (const std::string &name)
 Get the CSGCell object by name.
 
bool hasCell (const std::string &name) const
 check if cell of provided name is present in universe
 
const std::vector< std::reference_wrapper< const CSGCell > > & getAllCells () const
 Get list of the all cells in the universe.
 
const std::string & getName () const
 Get the name of the universe.
 
bool isRoot () const
 return true if the universe is the root universe
 
virtual bool isEngUnit () const
 Whether this universe is an engineering unit.
 
bool operator== (const CSGUniverse &other) const
 Operator overload for checking if two CSGUniverse objects are equal.
 
bool operator!= (const CSGUniverse &other) const
 Operator overload for checking if two CSGUniverse 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

void addCell (const CSGCell &cell)
 add cell to universe
 
void removeCell (const std::string &name)
 remove a cell of the specified name from the universe
 
void removeAllCells ()
 remove all cells from the universe
 
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 (CSGUniverseTest, testGetCell)
 Friends for unit testing.
 
 FRIEND_TEST (CSGUniverseTest, testAddCell)
 
 FRIEND_TEST (CSGUniverseTest, testRemoveCell)
 
 FRIEND_TEST (CSGUniverseTest, testRemoveAllCells)
 
 FRIEND_TEST (CSGUniverseTest, testSetName)
 
 FRIEND_TEST (CSGUniverseTest, testUniverseEquality)
 
 FRIEND_TEST (CSGSurfaceTest, testHalfspaceWithTransform)
 Friends for unit testing.
 
 FRIEND_TEST (CSGSurfaceTest, testHalfspaceWithNullTransform)
 
 FRIEND_TEST (CSGEngUnitTest, testEngUnitEqual)
 

Protected Attributes

std::string _name
 Name of universe.
 
std::vector< std::reference_wrapper< const CSGCell > > _cells
 list of references to cells in universe
 
bool _is_root
 whether or not this universe is the root universe
 
std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > _transformations
 List of transformations applied to this object.
 

Friends

class CSGUniverseList
 
class CSGBase
 

Detailed Description

CSGUniverse creates an internal representation of a Constructive Solid Geometry (CSG) universe, which represents a collection of cells that can be defined repeatedly within a separate container of cells.

Definition at line 27 of file CSGUniverse.h.

Constructor & Destructor Documentation

◆ CSGUniverse() [1/2]

CSG::CSGUniverse::CSGUniverse ( const std::string &  name,
bool  is_root = false 
)

Construct a new CSGUniverse object.

Parameters
nameunique name of universe
is_roottrue to set universe as the root universe (default false)

Definition at line 18 of file CSGUniverse.C.

18: _name(name), _is_root(is_root) {}
bool _is_root
whether or not this universe is the root universe
std::string _name
Name of universe.

◆ CSGUniverse() [2/2]

CSG::CSGUniverse::CSGUniverse ( const std::string &  name,
std::vector< CSGCell * > &  cells,
bool  is_root = false 
)

Construct a new CSGUniverse object from list of cells.

Parameters
nameunique name of universe
cellslist of cells to add to universe
is_roottrue to set universe as the root universe (default false)

Definition at line 20 of file CSGUniverse.C.

21 : _name(name), _is_root(is_root)
22{
24 for (auto cell : cells)
25 addCell(*cell);
26}
void addCell(const CSGCell &cell)
add cell to universe
Definition CSGUniverse.C:29
void checkValidCSGName(const std::string &name)
Check name of CSG component for disallowed characters and symbols.
Definition CSGUtils.C:36

◆ ~CSGUniverse()

virtual CSG::CSGUniverse::~CSGUniverse ( )
virtualdefault

Destructor.

Member Function Documentation

◆ addCell()

void CSG::CSGUniverse::addCell ( const CSGCell cell)
protected

add cell to universe

Parameters
referenceto cell to add

Definition at line 29 of file CSGUniverse.C.

30{
31 auto cell_name = cell.getName();
32 if (!hasCell(cell_name))
33 _cells.push_back(cell);
34 else
35 mooseWarning("Universe " + getName() + " already contains a cell by name " + cell_name + ". " +
36 "Skipping cell insertion for cell with duplicate name.");
37}
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition MooseError.h:345
const std::string & getName() const
Get the name of the universe.
Definition CSGUniverse.h:80
std::vector< std::reference_wrapper< const CSGCell > > _cells
list of references to cells in universe
bool hasCell(const std::string &name) const
check if cell of provided name is present in universe
Definition CSGUniverse.C:51

Referenced by CSG::CSGBase::addCellToUniverse(), and CSGUniverse().

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

◆ FRIEND_TEST() [1/9]

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

◆ FRIEND_TEST() [2/9]

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

◆ FRIEND_TEST() [3/9]

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

Friends for unit testing.

◆ FRIEND_TEST() [4/9]

CSG::CSGUniverse::FRIEND_TEST ( CSGUniverseTest  ,
testAddCell   
)
protected

◆ FRIEND_TEST() [5/9]

CSG::CSGUniverse::FRIEND_TEST ( CSGUniverseTest  ,
testGetCell   
)
protected

Friends for unit testing.

◆ FRIEND_TEST() [6/9]

CSG::CSGUniverse::FRIEND_TEST ( CSGUniverseTest  ,
testRemoveAllCells   
)
protected

◆ FRIEND_TEST() [7/9]

CSG::CSGUniverse::FRIEND_TEST ( CSGUniverseTest  ,
testRemoveCell   
)
protected

◆ FRIEND_TEST() [8/9]

CSG::CSGUniverse::FRIEND_TEST ( CSGUniverseTest  ,
testSetName   
)
protected

◆ FRIEND_TEST() [9/9]

CSG::CSGUniverse::FRIEND_TEST ( CSGUniverseTest  ,
testUniverseEquality   
)
protected

◆ getAllCells()

const std::vector< std::reference_wrapper< const CSGCell > > & CSG::CSGUniverse::getAllCells ( ) const
inline

Get list of the all cells in the universe.

Returns
list of pointers to cells in universe

Definition at line 73 of file CSGUniverse.h.

73{ return _cells; }

Referenced by CSG::CSGBase::addUniverseToList(), CSG::CSGBase::CSGBase(), CSG::CSGBase::getLinkedUniverses(), operator==(), and CSG::CSGBase::replaceCellRefs().

◆ getCell()

const CSGCell & CSG::CSGUniverse::getCell ( const std::string &  name)

Get the CSGCell object by name.

Parameters
namename of cell
Returns
reference to the cell of the specified name in this universe

Definition at line 40 of file CSGUniverse.C.

41{
42 if (!hasCell(name))
43 mooseError("Cell with name " + name + " does not exist in universe " + _name + ".");
44 for (const CSGCell & cell : _cells)
45 if (cell.getName() == name)
46 return cell;
47 mooseError("Should not reach here.");
48}
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
std::string name(const ElemQuality q)

◆ getName()

const std::string & CSG::CSGUniverse::getName ( ) const
inline

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

◆ hasCell()

bool CSG::CSGUniverse::hasCell ( const std::string &  name) const

check if cell of provided name is present in universe

Parameters
namename of cell
Returns
true if cell of name is in universe, otherwise false

Definition at line 51 of file CSGUniverse.C.

52{
53 for (const CSGCell & cell : _cells)
54 if (cell.getName() == name)
55 return true;
56 return false;
57}

Referenced by addCell(), getCell(), and removeCell().

◆ isEngUnit()

virtual bool CSG::CSGUniverse::isEngUnit ( ) const
inlinevirtual

Whether this universe is an engineering unit.

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

Returns
true if this object is a CSGEngUnit, otherwise false

Reimplemented in CSG::CSGUniverseEngUnit.

Definition at line 98 of file CSGUniverse.h.

98{ return false; }

Referenced by operator==().

◆ isRoot()

bool CSG::CSGUniverse::isRoot ( ) const
inline

return true if the universe is the root universe

Returns
true / false

Definition at line 87 of file CSGUniverse.h.

87{ return _is_root; }

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

◆ operator!=()

bool CSG::CSGUniverse::operator!= ( const CSGUniverse other) const

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

Definition at line 104 of file CSGUniverse.C.

105{
106 return !(*this == other);
107}

◆ operator==()

bool CSG::CSGUniverse::operator== ( const CSGUniverse other) const

Operator overload for checking if two CSGUniverse objects are equal.

Definition at line 74 of file CSGUniverse.C.

75{
76 // If both objects are engineering units, delegate to CSGEngUnit::operator==. The
77 // isEngUnit() check keeps the common plain-universe path free of any dynamic_cast;
78 // the casts below only run once we know the objects are engineering units.
79 if (isEngUnit())
80 {
81 if (other.isEngUnit())
82 return *dynamic_cast<const CSGEngUnit *>(this) == *dynamic_cast<const CSGEngUnit *>(&other);
83 return false; // an engineering unit cannot equal a plain universe
84 }
85
86 if ((this->getName() != other.getName()) ||
87 (this->getTransformations() != other.getTransformations()))
88 return false;
89 const auto & all_cells = getAllCells();
90 const auto & other_cells = other.getAllCells();
91 const bool num_cells_eq = all_cells.size() == other_cells.size();
92 if (num_cells_eq)
93 {
94 for (unsigned int i = 0; i < all_cells.size(); ++i)
95 if (all_cells[i].get() != other_cells[i].get())
96 return false;
97 return true;
98 }
99 else
100 return false;
101}
const std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > & getTransformations() const
Get the list of transformations.
virtual bool isEngUnit() const
Whether this universe is an engineering unit.
Definition CSGUniverse.h:98
const std::vector< std::reference_wrapper< const CSGCell > > & getAllCells() const
Get list of the all cells in the universe.
Definition CSGUniverse.h:73
const Elem & get(const ElemType type_in)

◆ removeAllCells()

void CSG::CSGUniverse::removeAllCells ( )
inlineprotected

remove all cells from the universe

Definition at line 124 of file CSGUniverse.h.

124{ _cells.clear(); }

◆ removeCell()

void CSG::CSGUniverse::removeCell ( const std::string &  name)
protected

remove a cell of the specified name from the universe

Parameters
namename of cell to remove

Definition at line 60 of file CSGUniverse.C.

61{
62 if (!hasCell(name))
63 mooseError("Cannot remove cell. Cell with name " + name + " does not exist in universe " +
64 _name + ".");
65 for (auto it = _cells.begin(); it != _cells.end(); ++it)
66 if (it->get().getName() == name)
67 {
68 _cells.erase(it);
69 break;
70 }
71}

Referenced by CSG::CSGBase::removeCellFromUniverse().

◆ setName()

void CSG::CSGUniverse::setName ( const std::string &  name)
inlineprotected

Definition at line 128 of file CSGUniverse.h.

128{ _name = name; }

Friends And Related Symbol Documentation

◆ CSGBase

friend class CSGBase
friend

Definition at line 143 of file CSGUniverse.h.

◆ CSGUniverseList

friend class CSGUniverseList
friend

Definition at line 140 of file CSGUniverse.h.

Member Data Documentation

◆ _cells

std::vector<std::reference_wrapper<const CSGCell> > CSG::CSGUniverse::_cells
protected

list of references to cells in universe

Definition at line 134 of file CSGUniverse.h.

Referenced by addCell(), getAllCells(), getCell(), hasCell(), removeAllCells(), and removeCell().

◆ _is_root

bool CSG::CSGUniverse::_is_root
protected

whether or not this universe is the root universe

Definition at line 137 of file CSGUniverse.h.

Referenced by isRoot().

◆ _name

std::string CSG::CSGUniverse::_name
protected

Name of universe.

Definition at line 131 of file CSGUniverse.h.

Referenced by getCell(), getName(), removeCell(), and setName().

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