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