https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CSGLattice.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://www.mooseframework.org
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include "CSGUniverse.h"
14#include "JsonIO.h"
15#include <variant>
16#include <optional>
17
18#ifdef MOOSE_UNIT_TEST
19#include "gtest/gtest.h"
20#endif
21
22namespace CSG
23{
24
29typedef std::variant<std::reference_wrapper<const CSGUniverse>, std::string> OuterVariant;
30
35{
36public:
45 CSGLattice(const std::string & name, const std::optional<OuterVariant> & outer = std::nullopt);
46
50 virtual ~CSGLattice() = default;
51
52 // Pure virtual clone method that derived classes must implement
53 virtual std::unique_ptr<CSGLattice> clone() const = 0;
54
60 const std::string & getName() const { return _name; }
61
67 const std::string getType() const
68 {
69 return MooseUtils::prettyCppType(libMesh::demangle(typeid(*this).name()));
70 }
71
77 const std::string getOuterType() const { return _outer_type; }
78
84 const CSGUniverse & getOuterUniverse() const;
85
91 const std::string & getOuterMaterial() const;
92
98 std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> getUniverses() const
99 {
100 return _universe_map;
101 }
102
108 const std::vector<std::vector<std::string>> getUniverseNameMap() const;
109
117 bool hasUniverse(const std::string & name) const;
118
124 virtual std::unordered_map<std::string, AttributeVariant>
125 getAttributes() const = 0; // pure virtual function
126
133 virtual bool isValidIndex(const std::pair<int, int> index) const = 0; // Pure virtual function
134
141 const CSGUniverse & getUniverseAtIndex(const std::pair<int, int> index);
142
149 const std::vector<std::pair<unsigned int, unsigned int>>
150 getUniverseIndices(const std::string & univ_name) const;
151
159 virtual bool
160 isValidUniverseMap(std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes)
161 const = 0; // pure virtual function
162
166 void resetOuter();
167
173 const std::vector<std::reference_wrapper<const CSGUniverse>> getUniqueUniverses() const;
174
176 bool operator==(const CSGLattice & other) const;
177
179 bool operator!=(const CSGLattice & other) const;
180
181protected:
182 // set the name of the lattices - intentionally not public because
183 // name needs to be managed at the CSGLatticeList level
184 void setName(const std::string & name) { _name = name; }
185
188 virtual void
189 setUniverses(std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes) = 0;
190
198 void setUniverseAtIndex(const CSGUniverse & universe, const std::pair<int, int> index);
199
201 virtual bool compareAttributes(const CSGLattice & other) const = 0; // pure virtual
202
209 void updateOuter(const std::string & outer_name);
210
217 void updateOuter(const CSGUniverse & outer_universe);
218
220 std::string _name;
221
223 std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> _universe_map;
224
226 mutable std::string _outer_type;
227
229 mutable std::string _outer_material;
230
233
234 // CSGLatticeList needs to be friend to access setName()
235 friend class CSGLatticeList;
236 // CSGBase needed for access updateAttributes()
237 friend class CSGBase;
238
239#ifdef MOOSE_UNIT_TEST
242 FRIEND_TEST(CSGLatticeTest, testSetName);
243 FRIEND_TEST(CSGLatticeTest, testUpdateOuter);
244 FRIEND_TEST(CSGBaseTest, testAddLattice);
245 FRIEND_TEST(CSGLatticeTest, testCartLatticeEquality);
247#endif
248};
249}
CSGBase creates an internal representation of a Constructive Solid Geometry (CSG) model.
Definition CSGBase.h:54
CSGLatticeList creates a container for CSGLattice objects to pass to CSGBase.
CSGLattice is the abstract class for defining lattices.
Definition CSGLattice.h:35
std::vector< std::vector< std::reference_wrapper< const CSGUniverse > > > getUniverses() const
Get the arrangement of CSGUniverses in the lattice.
Definition CSGLattice.h:98
FRIEND_TEST(CSGLatticeTest, testSetName)
Friends for unit testing.
virtual std::unique_ptr< CSGLattice > clone() const =0
FRIEND_TEST(CSGLatticeTest, testCartLatticeEquality)
void updateOuter(const std::string &outer_name)
Update the outer of the lattice to be the provided material name.
Definition CSGLattice.C:135
virtual bool isValidUniverseMap(std::vector< std::vector< std::reference_wrapper< const CSGUniverse > > > universes) const =0
check that any provided list of list of CSGUniverses are the correct dimensions for the type of latti...
const std::string & getName() const
Get the name of lattice.
Definition CSGLattice.h:60
const std::vector< std::vector< std::string > > getUniverseNameMap() const
Get the arrangement of CSGUniverses in the lattice as their names.
Definition CSGLattice.C:50
const std::string getOuterType() const
Get the type of outer that fills the space around the lattice elements.
Definition CSGLattice.h:77
const std::string & getOuterMaterial() const
Get the outer material name if outer fype is CSG_MATERIAL.
Definition CSGLattice.C:118
std::string _outer_material
name of the outer material
Definition CSGLattice.h:229
FRIEND_TEST(CSGBaseTest, testAddLattice)
bool operator!=(const CSGLattice &other) const
Operator overload for checking if two CSGLattice objects are not equal.
Definition CSGLattice.C:187
bool operator==(const CSGLattice &other) const
Operator overload for checking if two CSGLattice objects are equal.
Definition CSGLattice.C:151
const CSGUniverse * _outer_universe
outer object if fill is CSGUniverse
Definition CSGLattice.h:232
void setName(const std::string &name)
Definition CSGLattice.h:184
virtual void setUniverses(std::vector< std::vector< std::reference_wrapper< const CSGUniverse > > > universes)=0
assign the vectors of universes as the lattice elements
const std::vector< std::reference_wrapper< const CSGUniverse > > getUniqueUniverses() const
Get the list of unique universe objects in the lattice.
Definition CSGLattice.C:91
virtual std::unordered_map< std::string, AttributeVariant > getAttributes() const =0
Get attributes that define the lattice (excluding the universe map).
const CSGUniverse & getOuterUniverse() const
Get the outer universe if outer type is UNIVERSE.
Definition CSGLattice.C:109
virtual bool compareAttributes(const CSGLattice &other) const =0
helper function to compare the attributes of the lattice type
void resetOuter()
reset the outer fill around the lattice elements to be VOID
Definition CSGLattice.C:143
const std::vector< std::pair< unsigned int, unsigned int > > getUniverseIndices(const std::string &univ_name) const
get all locations in lattice where universe of the specified name exists
Definition CSGLattice.C:74
virtual ~CSGLattice()=default
Destructor.
bool hasUniverse(const std::string &name) const
whether or not the universe of the specified name exists in the lattice
Definition CSGLattice.C:40
const std::string getType() const
Get the lattice type.
Definition CSGLattice.h:67
const CSGUniverse & getUniverseAtIndex(const std::pair< int, int > index)
Get the universe located at the given index.
Definition CSGLattice.C:64
FRIEND_TEST(CSGLatticeTest, testUpdateOuter)
std::string _name
Name of lattice.
Definition CSGLattice.h:220
void setUniverseAtIndex(const CSGUniverse &universe, const std::pair< int, int > index)
replace the element at specified index in the lattice with the provided CSGUniverse.
Definition CSGLattice.C:28
virtual bool isValidIndex(const std::pair< int, int > index) const =0
Checks if the given index location is a valid index for the lattice.
std::vector< std::vector< std::reference_wrapper< const CSGUniverse > > > _universe_map
Universes in the arrangement of how they appear in the lattice; dimensions depends on lattice type.
Definition CSGLattice.h:223
std::string _outer_type
An enum for type of outer fill for lattice.
Definition CSGLattice.h:226
Class for managing transformations in CSG objects.
CSGUniverse creates an internal representation of a Constructive Solid Geometry (CSG) universe,...
Definition CSGUniverse.h:28
std::variant< std::reference_wrapper< const CSGUniverse >, std::string > OuterVariant
Type definition for a variant that can hold either a CSGUniverse reference or a string for use as the...
Definition CSGLattice.h:29
std::string prettyCppType(const std::string &cpp_type)
std::string demangle(const char *name)