OGS
CreateFunction.cpp
Go to the documentation of this file.
1
10#include <vector>
11
12#include "BaseLib/ConfigTree.h"
13#include "Function.h"
15
16namespace MaterialPropertyLib
17{
18std::unique_ptr<Function> createFunction(
19 BaseLib::ConfigTree const& config,
20 std::map<std::string,
21 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
22 curves)
23{
25 config.checkConfigParameter("type", "Function");
26
27 // Second access for storage.
29 auto property_name = config.peekConfigParameter<std::string>("name");
30
31 DBUG("Create Function property {:s}.", property_name);
32
33 std::vector<std::string> value_expressions;
35 auto const& value_config = config.getConfigSubtree("value");
36
38 for (auto const& p : value_config.getConfigSubtreeList("expression"))
39 {
40 value_expressions.emplace_back(p.getValue<std::string>());
41 }
42
43 // For each derivative a name of the variable and the list of expressions.
44 std::vector<std::pair<std::string, std::vector<std::string>>>
45 dvalue_expressions;
47 for (auto const& dvalue_config : config.getConfigSubtreeList("dvalue"))
48 {
49 auto variable_name =
51 dvalue_config.getConfigParameter<std::string>("variable_name");
52
53 std::vector<std::string> expressions;
54 auto const& expression_configs =
56 dvalue_config.getConfigSubtreeList("expression");
57
58 expressions.reserve(expression_configs.size());
59 std::transform(std::begin(expression_configs),
60 std::end(expression_configs),
61 std::back_inserter(expressions),
62 [](BaseLib::ConfigTree const& p)
63 { return p.getValue<std::string>(); });
64
65 dvalue_expressions.emplace_back(std::move(variable_name),
66 std::move(expressions));
67 }
68
69 return std::make_unique<MaterialPropertyLib::Function>(
70 std::move(property_name),
71 value_expressions,
72 dvalue_expressions,
73 curves);
74}
75} // namespace MaterialPropertyLib
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
Definition of the PiecewiseLinearInterpolation class.
T peekConfigParameter(std::string const &param) const
Range< SubtreeIterator > getConfigSubtreeList(std::string const &root) const
ConfigTree getConfigSubtree(std::string const &root) const
void checkConfigParameter(std::string const &param, std::string_view const value) const
std::unique_ptr< Function > createFunction(BaseLib::ConfigTree const &config, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)