OGS
CreateComponent.cpp
Go to the documentation of this file.
1
12#include "CreateComponent.h"
13
14#include <boost/algorithm/string/predicate.hpp>
15
16#include "BaseLib/ConfigTree.h"
18#include "CreateProperty.h"
21
22namespace
23{
24std::unique_ptr<MaterialPropertyLib::Component> createComponent(
25 int const geometry_dimension,
26 BaseLib::ConfigTree const& config,
27 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
28 ParameterLib::CoordinateSystem const* const local_coordinate_system,
29 std::map<std::string,
30 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
31 curves)
32{
33 using namespace MaterialPropertyLib;
34 // Parsing the component name
36 auto const& component_name = config.getConfigParameter<std::string>("name");
37
38 // Check whether a name is given or not
39 if (component_name.empty())
40 {
41 OGS_FATAL("Component name is a mandatory field and cannot be empty.");
42 }
43
44 // Parsing component properties. If a component name is given and this
45 // component is predefined in the class implementation, properties
46 // become optional. The default values of properties will be overwritten
47 // if specified.
48 std::unique_ptr<PropertyArray> properties = createProperties(
49 geometry_dimension,
51 config.getConfigSubtreeOptional("properties"), parameters,
52 local_coordinate_system, curves);
53
54 // If a name is given, it must conform with one of the derived component
55 // names in the following list:
56 if (boost::iequals(component_name, "water"))
57 {
58 return std::make_unique<Water>(std::move(properties));
59 }
60
61 if (!properties)
62 {
63 // No component properties are provided. If the component is not
64 // specified, this results in a fatal error, since an unspecified
65 // component has no properties.
66 OGS_FATAL("No Properties defined for unspecified component");
67 }
68
69 return std::make_unique<Component>(component_name, std::move(properties));
70}
71} // namespace
72
73namespace MaterialPropertyLib
74{
75std::vector<std::unique_ptr<Component>> createComponents(
76 int const geometry_dimension,
77 std::optional<BaseLib::ConfigTree> const& config,
78 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
79 ParameterLib::CoordinateSystem const* const local_coordinate_system,
80 std::map<std::string,
81 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
82 curves)
83{
84 if (!config)
85 {
86 return {};
87 }
88
89 std::vector<std::unique_ptr<Component>> components;
90 for (
91 auto const& component_config :
93 config->getConfigSubtreeList("component"))
94 {
95 auto component =
96 createComponent(geometry_dimension, component_config, parameters,
97 local_coordinate_system, curves);
98
99 if (std::find_if(components.begin(),
100 components.end(),
101 [component_name = component->name](auto const& c) {
102 return c->name == component_name;
103 }) != components.end())
104 {
105 OGS_FATAL(
106 "Found duplicates with the same component name tag '{:s}'.",
107 component->name);
108 }
109
110 components.push_back(std::move(component));
111 }
112
113 return components;
114}
115} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition: Error.h:26
Definition of the PiecewiseLinearInterpolation class.
std::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
Definition: ConfigTree.cpp:159
T getConfigParameter(std::string const &param) const
std::unique_ptr< PropertyArray > createProperties(int const geometry_dimension, std::optional< BaseLib::ConfigTree > const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, ParameterLib::CoordinateSystem const *const local_coordinate_system, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)
std::vector< std::unique_ptr< Component > > createComponents(int const geometry_dimension, std::optional< BaseLib::ConfigTree > const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, ParameterLib::CoordinateSystem const *const local_coordinate_system, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)
std::unique_ptr< MaterialPropertyLib::Component > createComponent(int const geometry_dimension, BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, ParameterLib::CoordinateSystem const *const local_coordinate_system, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)