https://mooseframework.inl.gov
CSGCartesianLattice.C
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 #include "CSGCartesianLattice.h"
11 
12 namespace CSG
13 {
14 
16  const std::string & name,
17  const Real pitch,
18  std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes,
19  const std::optional<OuterVariant> & outer)
20  : CSGLattice(name, MooseUtils::prettyCppType<CSGCartesianLattice>(), outer), _pitch(pitch)
21 {
22  setUniverses(universes); // this will set _nrow and _ncol
23  if (_pitch < 0)
24  mooseError("Lattice " + getName() + " must have pitch greater than 0.");
25 }
26 
28  const Real pitch,
29  const std::optional<OuterVariant> & outer)
31  _pitch(pitch),
32  _nrow(0),
33  _ncol(0)
34 {
35  if (_pitch < 0)
36  mooseError("Lattice " + getName() + " must have pitch greater than 0.");
37 }
38 
39 void
41 {
42  if (pitch < 0)
43  mooseError("Lattice " + getName() + " must have pitch greater than 0.");
44  _pitch = pitch;
45 }
46 
47 std::unordered_map<std::string, AttributeVariant>
49 {
50  return {{"nrow", static_cast<unsigned int>(_nrow)},
51  {"ncol", static_cast<unsigned int>(_ncol)},
52  {"pitch", _pitch}};
53 }
54 
55 bool
57  std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes) const
58 {
59  // need at least one row
60  if (universes.size() < 1)
61  return false;
62 
63  // check that each row is same size
64  auto row_size = universes[0].size();
65  for (auto univ_list : universes)
66  {
67  if (univ_list.size() != row_size)
68  return false;
69  }
70  return true;
71 }
72 
73 void
75  std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes)
76 {
77  // check for valid map arrangment
78  if (!isValidUniverseMap(universes))
79  mooseError("Cannot set lattice " + getName() +
80  " with universes. Does not have valid dimensions for lattice type " + getType());
81  // set attributes based on universe map
82  _nrow = universes.size();
83  _ncol = universes[0].size();
84  _universe_map = universes;
85 }
86 
87 bool
88 CSGCartesianLattice::isValidIndex(const std::pair<int, int> index) const
89 {
90  auto row = index.first; // must be (0 <= row < _nrow); rows
91  auto col = index.second; // must be (0 <= col < _ncol); cols
92  return ((0 <= row && row < (int)_nrow) && (0 <= col && col < (int)_ncol));
93 }
94 
95 bool
97 {
98  if (other.getType() != this->getType())
99  return false;
100 
101  auto this_dims = this->getAttributes();
102  auto other_dims = other.getAttributes();
103  if (std::get<unsigned int>(this_dims["nrow"]) != std::get<unsigned int>(other_dims["nrow"]))
104  return false;
105  if (std::get<unsigned int>(this_dims["ncol"]) != std::get<unsigned int>(other_dims["ncol"]))
106  return false;
107  if (std::get<Real>(this_dims["pitch"]) != std::get<Real>(other_dims["pitch"]))
108  return false;
109  return true;
110 }
111 
112 } // namespace CSG
std::string name(const ElemQuality q)
void setPitch(Real pitch)
set the pitch of the lattice
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
const std::string & getType() const
Get the lattice type.
Definition: CSGLattice.h:69
unsigned int _ncol
number of elements in the second direction (columns)
const std::string & getName() const
Get the name of lattice.
Definition: CSGLattice.h:62
virtual std::unordered_map< std::string, AttributeVariant > getAttributes() const override
Get attributes that define the lattice (excluding the universe map).
CSGLattice is the abstract class for defining lattices.
Definition: CSGLattice.h:34
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
virtual bool isValidUniverseMap(std::vector< std::vector< std::reference_wrapper< const CSGUniverse >>> universes) const override
check that any provided list of list of CSGUniverses are the correct dimensions.
virtual bool compareAttributes(const CSGLattice &other) const override
compare the attributes returned in getAttributes of this lattice to another lattice ...
virtual void setUniverses(std::vector< std::vector< std::reference_wrapper< const CSGUniverse >>> universes) override
set the universes that define the lattice layout
virtual std::unordered_map< std::string, AttributeVariant > getAttributes() const =0
Get attributes that define the lattice (excluding the universe map).
CSGCartesianLattice(const std::string &name, const Real pitch, std::vector< std::vector< std::reference_wrapper< const CSGUniverse >>> universes, const std::optional< OuterVariant > &outer=std::nullopt)
Construct a new CSGCartesianLattice object from the map of universes provided.
unsigned int _nrow
number of elements in the first dimension (rows)
CSGCartesianLattice is the class for constructing regular Cartesian lattices of CSGUniverses.
virtual bool isValidIndex(const std::pair< int, int > index) const override
Checks if the given index location (row, column) is a valid index for the lattice.
std::string prettyCppType(const std::string &cpp_type)
Definition: MooseUtils.C:1140