https://mooseframework.inl.gov
CSGLatticeList.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 "CSGLatticeList.h"
11 
12 namespace CSG
13 {
14 
16 
17 CSGLattice &
18 CSGLatticeList::getLattice(const std::string & name) const
19 {
20  auto lat = _lattices.find(name);
21  if (lat == _lattices.end())
22  mooseError("No lattice by name " + name + " exists in the geometry.");
23  else
24  return *(lat->second);
25 }
26 
27 std::vector<std::reference_wrapper<const CSGLattice>>
29 {
30  std::vector<std::reference_wrapper<const CSGLattice>> lattices;
31  for (auto it = _lattices.begin(); it != _lattices.end(); ++it)
32  lattices.push_back(*(it->second.get()));
33  return lattices;
34 }
35 
36 CSGLattice &
37 CSGLatticeList::addLattice(std::unique_ptr<CSGLattice> lattice, const bool ignore_identical_lattice)
38 {
39  auto lattice_name = lattice->getName();
40  if (ignore_identical_lattice)
41  // Check that lattice already defined in _lattice and if so, confirm it matches with input lat
42  if (auto it = _lattices.find(lattice_name); it != _lattices.end())
43  {
44  if (*lattice == *it->second)
45  return *it->second;
46  else
47  mooseError("Lattice with name ",
48  lattice_name,
49  " has the same name as an existing lattice in CSGBase instance but cannot be "
50  "discarded as it is not an identical lattice.");
51  }
52 
53  // Otherwise, add the lattice to the lattice list. At this point, we don't expect the lattice
54  // to already be defined in the lattice list
55  auto [it, inserted] = _lattices.emplace(lattice_name, std::move(lattice));
56  if (!inserted)
57  mooseError("Lattice with name " + lattice_name + " already exists in geometry.");
58  return *it->second;
59 }
60 
61 void
62 CSGLatticeList::renameLattice(const CSGLattice & lattice, const std::string & name)
63 {
64  // check that this lattice passed in is actually in the same lattice that is in the lattice list
65  auto prev_name = lattice.getName();
66  auto it = _lattices.find(prev_name);
67  if (it == _lattices.end() || it->second.get() != &lattice)
68  mooseError("Lattice " + prev_name + " cannot be renamed to " + name +
69  " as it does not exist in this CSGBase instance.");
70 
71  auto existing_lat = std::move(it->second);
72  existing_lat->setName(name);
73  _lattices.erase(prev_name);
74  addLattice(std::move(existing_lat));
75 }
76 
77 bool
79 {
80  const auto all_lats = this->getAllLattices();
81  const auto other_lats = other.getAllLattices();
82 
83  // Check that same number of lattices are defined in both lists
84  if (all_lats.size() != other_lats.size())
85  return false;
86 
87  // Iterate through each CSGLattices in list and check equality of each cell
88  // with other list
89  for (const auto & lat : all_lats)
90  {
91  const auto & lat_name = lat.get().getName();
92  if (!other.hasLattice(lat_name))
93  return false;
94  const auto & other_lat = other.getLattice(lat_name);
95  if (lat.get() != other_lat)
96  return false;
97  }
98  return true;
99 }
100 
101 bool
103 {
104  return !(*this == other);
105 }
106 
107 } // namespace CSG
std::string name(const ElemQuality q)
CSGLattice & addLattice(std::unique_ptr< CSGLattice > lattice, const bool ignore_identical_lattice=false)
add an existing lattice to list.
bool operator!=(const CSGLatticeList &other) const
Operator overload for checking if two CSGLatticeList objects are not equal.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
std::vector< std::reference_wrapper< const CSGLattice > > getAllLattices() const
Get all the lattices in CSGBase instance.
const std::string & getName() const
Get the name of lattice.
Definition: CSGLattice.h:62
void renameLattice(const CSGLattice &lattice, const std::string &name)
rename the specified lattice
CSGLatticeList creates a container for CSGLattice objects to pass to CSGBase.
std::unordered_map< std::string, std::unique_ptr< CSGLattice > > _lattices
Mapping of lattice names to pointers of stored lattice objects.
CSGLattice is the abstract class for defining lattices.
Definition: CSGLattice.h:34
CSGLatticeList()
Default constructor.
bool hasLattice(const std::string &name) const
return whether lattice with given name exists in lattice list
bool operator==(const CSGLatticeList &other) const
Operator overload for checking if two CSGLatticeList objects are equal.
CSGLattice & getLattice(const std::string &name) const
Get a Lattice from the list by its name.