OGS
CreateFunction.cpp
Go to the documentation of this file.
1
10#include "BaseLib/ConfigTree.h"
11#include "Function.h"
12
13namespace MaterialPropertyLib
14{
15std::unique_ptr<Function> createFunction(BaseLib::ConfigTree const& config)
16{
18 config.checkConfigParameter("type", "Function");
19
20 // Second access for storage.
22 auto property_name = config.peekConfigParameter<std::string>("name");
23
24 DBUG("Create Function property {:s}.", property_name);
25
26 std::vector<std::string> value_expressions;
28 auto const& value_config = config.getConfigSubtree("value");
29
31 for (auto const& p : value_config.getConfigSubtreeList("expression"))
32 {
33 value_expressions.emplace_back(p.getValue<std::string>());
34 }
35
36 // For each derivative a name of the variable and the list of expressions.
37 std::vector<std::pair<std::string, std::vector<std::string>>>
38 dvalue_expressions;
40 for (auto const& dvalue_config : config.getConfigSubtreeList("dvalue"))
41 {
42 auto variable_name =
44 dvalue_config.getConfigParameter<std::string>("variable_name");
45
46 std::vector<std::string> expressions;
47 auto const& expression_configs =
49 dvalue_config.getConfigSubtreeList("expression");
50
51 expressions.reserve(expression_configs.size());
52 std::transform(std::begin(expression_configs),
53 std::end(expression_configs),
54 std::back_inserter(expressions),
55 [](BaseLib::ConfigTree const& p)
56 { return p.getValue<std::string>(); });
57
58 dvalue_expressions.emplace_back(std::move(variable_name),
59 std::move(expressions));
60 }
61
62 return std::make_unique<MaterialPropertyLib::Function>(
63 std::move(property_name), value_expressions, dvalue_expressions);
64}
65} // namespace MaterialPropertyLib
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
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)