https://mooseframework.inl.gov
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 
22 namespace CSG
23 {
24 
29 typedef std::variant<std::reference_wrapper<const CSGUniverse>, std::string> OuterVariant;
30 
35 {
36 public:
45  CSGLattice(const std::string & name,
46  const std::string & lattice_type,
47  const std::optional<OuterVariant> & outer = std::nullopt);
48 
52  virtual ~CSGLattice() = default;
53 
54  // Pure virtual clone method that derived classes must implement
55  virtual std::unique_ptr<CSGLattice> clone() const = 0;
56 
62  const std::string & getName() const { return _name; }
63 
69  const std::string & getType() const { return _lattice_type; }
70 
76  const std::string getOuterType() const { return _outer_type; }
77 
83  const CSGUniverse & getOuterUniverse() const;
84 
90  const std::string & getOuterMaterial() const;
91 
97  std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> getUniverses() const
98  {
99  return _universe_map;
100  }
101 
107  const std::vector<std::vector<std::string>> getUniverseNameMap() const;
108 
116  bool hasUniverse(const std::string & name) const;
117 
123  virtual std::unordered_map<std::string, AttributeVariant>
124  getAttributes() const = 0; // pure virtual function
125 
132  virtual bool isValidIndex(const std::pair<int, int> index) const = 0; // Pure virtual function
133 
140  const CSGUniverse & getUniverseAtIndex(const std::pair<int, int> index);
141 
148  const std::vector<std::pair<unsigned int, unsigned int>>
149  getUniverseIndices(const std::string & univ_name) const;
150 
158  virtual bool
159  isValidUniverseMap(std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes)
160  const = 0; // pure virtual function
161 
165  void resetOuter();
166 
172  const std::vector<std::reference_wrapper<const CSGUniverse>> getUniqueUniverses() const;
173 
175  bool operator==(const CSGLattice & other) const;
176 
178  bool operator!=(const CSGLattice & other) const;
179 
180 protected:
181  // set the name of the lattices - intentionally not public because
182  // name needs to be managed at the CSGLatticeList level
183  void setName(const std::string & name) { _name = name; }
184 
187  virtual void
188  setUniverses(std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes) = 0;
189 
197  void setUniverseAtIndex(const CSGUniverse & universe, const std::pair<int, int> index);
198 
200  virtual bool compareAttributes(const CSGLattice & other) const = 0; // pure virtual
201 
208  void updateOuter(const std::string & outer_name);
209 
216  void updateOuter(const CSGUniverse & outer_universe);
217 
219  std::string _name;
220 
222  const std::string _lattice_type;
223 
225  std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> _universe_map;
226 
228  mutable std::string _outer_type;
229 
231  mutable std::string _outer_material;
232 
235 
236  // CSGLatticeList needs to be friend to access setName()
237  friend class CSGLatticeList;
238  // CSGBase needed for access updateAttributes()
239  friend class CSGBase;
240 
241 #ifdef MOOSE_UNIT_TEST
242  FRIEND_TEST(CSGLatticeTest, testSetName);
245  FRIEND_TEST(CSGLatticeTest, testUpdateOuter);
246  FRIEND_TEST(CSGBaseTest, testAddLattice);
247  FRIEND_TEST(CSGLatticeTest, testCartLatticeEquality);
249 #endif
250 };
251 }
std::string name(const ElemQuality q)
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 _outer_material
name of the outer material
Definition: CSGLattice.h:231
std::string _outer_type
An enum for type of outer fill for lattice.
Definition: CSGLattice.h:228
virtual ~CSGLattice()=default
Destructor.
std::string _name
Name of lattice.
Definition: CSGLattice.h:219
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:76
bool operator!=(const CSGLattice &other) const
Operator overload for checking if two CSGLattice objects are not equal.
Definition: CSGLattice.C:189
CSGLattice(const std::string &name, const std::string &lattice_type, const std::optional< OuterVariant > &outer=std::nullopt)
Construct a new CSGLattice of specific type.
Definition: CSGLattice.C:16
virtual bool isValidIndex(const std::pair< int, int > index) const =0
Checks if the given index location is a valid index for the lattice.
const CSGUniverse & getOuterUniverse() const
Get the outer universe if outer type is UNIVERSE.
Definition: CSGLattice.C:111
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:30
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...
CSGUniverse creates an internal representation of a Constructive Solid Geometry (CSG) universe...
Definition: CSGUniverse.h:27
const std::string & getType() const
Get the lattice type.
Definition: CSGLattice.h:69
const std::string & getName() const
Get the name of lattice.
Definition: CSGLattice.h:62
CSGLatticeList creates a container for CSGLattice objects to pass to CSGBase.
const std::vector< std::reference_wrapper< const CSGUniverse > > getUniqueUniverses() const
Get the list of unique universe objects in the lattice.
Definition: CSGLattice.C:93
CSGLattice is the abstract class for defining lattices.
Definition: CSGLattice.h:34
void resetOuter()
reset the outer fill around the lattice elements to be VOID
Definition: CSGLattice.C:145
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:225
const std::string & getOuterMaterial() const
Get the outer material name if outer fype is CSG_MATERIAL.
Definition: CSGLattice.C:120
virtual std::unordered_map< std::string, AttributeVariant > getAttributes() const =0
Get attributes that define the lattice (excluding the universe map).
const CSGUniverse & getUniverseAtIndex(const std::pair< int, int > index)
Get the universe located at the given index.
Definition: CSGLattice.C:66
void updateOuter(const std::string &outer_name)
Update the outer of the lattice to be the provided material name.
Definition: CSGLattice.C:137
const std::vector< std::vector< std::string > > getUniverseNameMap() const
Get the arrangement of CSGUniverses in the lattice as their names.
Definition: CSGLattice.C:52
FRIEND_TEST(CSGLatticeTest, testSetName)
Friends for unit testing.
const CSGUniverse * _outer_universe
outer object if fill is CSGUniverse
Definition: CSGLattice.h:234
virtual bool compareAttributes(const CSGLattice &other) const =0
helper function to compare the attributes of the lattice type
std::vector< std::vector< std::reference_wrapper< const CSGUniverse > > > getUniverses() const
Get the arrangement of CSGUniverses in the lattice.
Definition: CSGLattice.h:97
bool hasUniverse(const std::string &name) const
whether or not the universe of the specified name exists in the lattice
Definition: CSGLattice.C:42
const std::string _lattice_type
Type of lattice.
Definition: CSGLattice.h:222
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::string getOuterType() const
Get the type of outer that fills the space around the lattice elements.
Definition: CSGLattice.h:76
void setName(const std::string &name)
Definition: CSGLattice.h:183
Class for managing transformations in CSG objects.
CSGBase creates an internal representation of a Constructive Solid Geometry (CSG) model...
Definition: CSGBase.h:51
virtual std::unique_ptr< CSGLattice > clone() const =0
bool operator==(const CSGLattice &other) const
Operator overload for checking if two CSGLattice objects are equal.
Definition: CSGLattice.C:153