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