https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CSGEngUnitList.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 "CSGEngUnitList.h"
11
12namespace CSG
13{
14
16
19{
20 const auto & name = unit.getName();
21 if (hasEngUnit(name))
22 mooseError("An engineering unit with name '", name, "' already exists in geometry.");
23 _eng_units.push_back(&unit);
24 return unit;
25}
26
28CSGEngUnitList::getEngUnit(const std::string & name) const
29{
30 for (auto * ptr : _eng_units)
31 if (ptr->getName() == name)
32 return *ptr;
33 mooseError("Engineering unit with name '", name, "' does not exist in this CSGBase.");
34}
35
36void
38{
39 auto it = std::find(_eng_units.begin(), _eng_units.end(), &unit);
40 if (it != _eng_units.end())
41 _eng_units.erase(it);
42}
43
44std::vector<std::reference_wrapper<const CSGEngUnit>>
46{
47 std::vector<std::reference_wrapper<const CSGEngUnit>> result;
48 for (const auto * ptr : _eng_units)
49 result.push_back(*ptr);
50 return result;
51}
52
53std::vector<std::reference_wrapper<const CSGSurfaceEngUnit>>
55{
56 std::vector<std::reference_wrapper<const CSGSurfaceEngUnit>> result;
57 for (const auto * ptr : _eng_units)
58 if (const auto * surf = dynamic_cast<const CSGSurfaceEngUnit *>(ptr))
59 result.push_back(*surf);
60 return result;
61}
62
63std::vector<std::reference_wrapper<const CSGCellEngUnit>>
65{
66 std::vector<std::reference_wrapper<const CSGCellEngUnit>> result;
67 for (const auto * ptr : _eng_units)
68 if (const auto * cell = dynamic_cast<const CSGCellEngUnit *>(ptr))
69 result.push_back(*cell);
70 return result;
71}
72
73std::vector<std::reference_wrapper<const CSGUniverseEngUnit>>
75{
76 std::vector<std::reference_wrapper<const CSGUniverseEngUnit>> result;
77 for (const auto * ptr : _eng_units)
78 if (const auto * univ = dynamic_cast<const CSGUniverseEngUnit *>(ptr))
79 result.push_back(*univ);
80 return result;
81}
82
83bool
85{
86 const auto all_units = this->getAllEngUnits();
87 const auto other_units = other.getAllEngUnits();
88
89 if (all_units.size() != other_units.size())
90 return false;
91
92 for (const auto & unit : all_units)
93 {
94 const std::string & unit_name = unit.get().getName();
95 const auto & other_unit = other.getEngUnit(unit_name);
96 if (unit.get() != other_unit)
97 return false;
98 }
99 return true;
100}
101
102bool
104{
105 return !(*this == other);
106}
107
108} // namespace CSG
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
CSGCellEngUnit is an abstract base class for "engineering units" that are cell-like.
CSGEngUnitList is a non-owning index of CSGEngUnit objects stored in the type lists (CSGSurfaceList,...
std::vector< CSGEngUnit * > _eng_units
Non-owning index: raw pointers into the type lists.
CSGEngUnit & addEngUnit(CSGEngUnit &unit)
Register an engineering unit in this index.
std::vector< std::reference_wrapper< const CSGSurfaceEngUnit > > getAllSurfaceEngUnits() const
Get all surface-like engineering units.
CSGEngUnitList()
Default constructor.
void removeEngUnit(const CSGEngUnit &unit)
Remove an engineering unit from this index by address.
CSGEngUnit & getEngUnit(const std::string &name) const
Get an engineering unit by name.
std::vector< std::reference_wrapper< const CSGUniverseEngUnit > > getAllUniverseEngUnits() const
Get all universe-like engineering units.
bool operator==(const CSGEngUnitList &other) const
Operator overload for checking if two CSGEngUnitList objects are equal.
std::vector< std::reference_wrapper< const CSGEngUnit > > getAllEngUnits() const
Get all engineering units of all types in the list.
std::vector< std::reference_wrapper< const CSGCellEngUnit > > getAllCellEngUnits() const
Get all cell-like engineering units.
bool hasEngUnit(const std::string &name) const
Return whether an engineering unit with the given name exists in this list.
bool operator!=(const CSGEngUnitList &other) const
Operator overload for checking if two CSGEngUnitList objects are not equal.
CSGEngUnit is the abstract base class for all "engineering unit" types in the CSG system.
Definition CSGEngUnit.h:33
virtual const std::string & getName() const =0
Get the unique instance name of this engineering unit.
CSGSurfaceEngUnit is an abstract base class for "engineering units" that can be used as surfaces in c...
CSGUniverseEngUnit is an abstract base class for "engineering units" that are universe-like.