https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
12namespace 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, 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)
30 : CSGLattice(name, outer), _pitch(pitch), _nrow(0), _ncol(0)
31{
32 if (_pitch < 0)
33 mooseError("Lattice " + getName() + " must have pitch greater than 0.");
34}
35
36void
38{
39 if (pitch < 0)
40 mooseError("Lattice " + getName() + " must have pitch greater than 0.");
41 _pitch = pitch;
42}
43
44std::unordered_map<std::string, AttributeVariant>
46{
47 return {{"nrow", static_cast<unsigned int>(_nrow)},
48 {"ncol", static_cast<unsigned int>(_ncol)},
49 {"pitch", _pitch}};
50}
51
52bool
54 std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes) const
55{
56 // need at least one row
57 if (universes.size() < 1)
58 return false;
59
60 // check that each row is same size
61 auto row_size = universes[0].size();
62 for (auto univ_list : universes)
63 {
64 if (univ_list.size() != row_size)
65 return false;
66 }
67 return true;
68}
69
70void
72 std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes)
73{
74 // check for valid map arrangment
75 if (!isValidUniverseMap(universes))
76 mooseError("Cannot set lattice " + getName() +
77 " with universes. Does not have valid dimensions for lattice type " + getType());
78 // set attributes based on universe map
79 _nrow = universes.size();
80 _ncol = universes[0].size();
81 _universe_map = universes;
82}
83
84bool
85CSGCartesianLattice::isValidIndex(const std::pair<int, int> index) const
86{
87 auto row = index.first; // must be (0 <= row < _nrow); rows
88 auto col = index.second; // must be (0 <= col < _ncol); cols
89 return ((0 <= row && row < (int)_nrow) && (0 <= col && col < (int)_ncol));
90}
91
92bool
94{
95 if (other.getType() != this->getType())
96 return false;
97
98 auto this_dims = this->getAttributes();
99 auto other_dims = other.getAttributes();
100 if (std::get<unsigned int>(this_dims["nrow"]) != std::get<unsigned int>(other_dims["nrow"]))
101 return false;
102 if (std::get<unsigned int>(this_dims["ncol"]) != std::get<unsigned int>(other_dims["ncol"]))
103 return false;
104 if (std::get<Real>(this_dims["pitch"]) != std::get<Real>(other_dims["pitch"]))
105 return false;
106 return true;
107}
108
109} // namespace CSG
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
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.
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.
virtual void setUniverses(std::vector< std::vector< std::reference_wrapper< const CSGUniverse > > > universes) override
set the universes that define the lattice layout
virtual bool compareAttributes(const CSGLattice &other) const override
compare the attributes returned in getAttributes of this lattice to another lattice
unsigned int _ncol
number of elements in the second direction (columns)
virtual std::unordered_map< std::string, AttributeVariant > getAttributes() const override
Get attributes that define the lattice (excluding the universe map).
void setPitch(Real pitch)
set the pitch of the lattice
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.
unsigned int _nrow
number of elements in the first dimension (rows)
CSGLattice is the abstract class for defining lattices.
Definition CSGLattice.h:35
const std::string & getName() const
Get the name of lattice.
Definition CSGLattice.h:60
virtual std::unordered_map< std::string, AttributeVariant > getAttributes() const =0
Get attributes that define the lattice (excluding the universe map).
const std::string getType() const
Get the lattice type.
Definition CSGLattice.h:67
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