OGS
Phase.cpp
Go to the documentation of this file.
1 
13 #include "Phase.h"
14 
15 #include "BaseLib/Algorithm.h"
16 #include "Component.h"
17 #include "Properties/Properties.h"
18 
19 namespace MaterialPropertyLib
20 {
21 Phase::Phase(std::string&& phase_name,
22  std::vector<std::unique_ptr<Component>>&& components,
23  std::unique_ptr<PropertyArray>&& properties)
24  : name(std::move(phase_name)), components_(std::move(components))
25 {
26  if (properties)
27  {
28  overwriteExistingProperties(properties_, *properties, this);
29  }
30 }
31 
32 Component const& Phase::component(const std::size_t& index) const
33 {
34  return *components_[index];
35 }
36 
37 bool Phase::hasComponent(std::size_t const& index) const
38 {
39  return components_[index] != nullptr;
40 }
41 
42 Component const& Phase::component(std::string const& name) const
43 {
45  components_.begin(), components_.end(),
46  [&name](std::unique_ptr<Component> const& component)
47  { return component->name == name; },
48  "Could not find component name '" + name + "'.");
49 }
50 
51 Property const& Phase::property(PropertyType const& p) const
52 {
53  Property const* const property = properties_[p].get();
54  if (property == nullptr)
55  {
56  OGS_FATAL("Trying to access undefined property '{:s}' of {:s}",
58  }
59  return *properties_[p];
60 }
61 
62 Property const& Phase::operator[](PropertyType const& p) const
63 {
64  return property(p);
65 }
66 
67 bool Phase::hasProperty(PropertyType const& p) const
68 {
69  return properties_[p] != nullptr;
70 }
71 
72 std::size_t Phase::numberOfComponents() const
73 {
74  return components_.size();
75 }
76 
77 std::string Phase::description() const
78 {
79  return "phase '" + name + "'";
80 }
81 } // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition: Error.h:26
This class defines components (substances).
Definition: Component.h:25
Property const & property(PropertyType const &p) const
Definition: Phase.cpp:51
PropertyArray properties_
Definition: Phase.h:71
std::string const name
Definition: Phase.h:61
std::string description() const
Short description of the phase with its name.
Definition: Phase.cpp:77
std::size_t numberOfComponents() const
A get-function for retrieving the number of components in this phase.
Definition: Phase.cpp:72
std::vector< std::unique_ptr< Component > > const components_
Definition: Phase.h:64
Property const & operator[](PropertyType const &p) const
Definition: Phase.cpp:62
bool hasProperty(PropertyType const &p) const
Definition: Phase.cpp:67
Phase(std::string &&phase_name, std::vector< std::unique_ptr< Component >> &&components, std::unique_ptr< PropertyArray > &&properties)
The Phase constructor is called with the optional phase name.
Definition: Phase.cpp:21
bool hasComponent(std::size_t const &index) const
Definition: Phase.cpp:37
Component const & component(std::size_t const &index) const
Definition: Phase.cpp:32
std::iterator_traits< InputIt >::reference findElementOrError(InputIt begin, InputIt end, Predicate predicate, std::string const &error="")
Definition: Algorithm.h:69
void overwriteExistingProperties(PropertyArray &properties, PropertyArray &new_properties, std::variant< Medium *, Phase *, Component * > scale_pointer)
Definition: Property.h:311
static const std::array< std::string, PropertyType::number_of_properties > property_enum_to_string
Definition: PropertyType.h:111