OGS
CreateFunction.cpp
Go to the documentation of this file.
1 
10 #include "BaseLib/ConfigTree.h"
11 #include "Function.h"
12 
13 namespace MaterialPropertyLib
14 {
15 std::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;
48  for (auto const& p : dvalue_config.getConfigSubtreeList("expression"))
49  {
50  expressions.emplace_back(p.getValue<std::string>());
51  }
52  dvalue_expressions.emplace_back(std::move(variable_name),
53  std::move(expressions));
54  }
55 
56  return std::make_unique<MaterialPropertyLib::Function>(
57  std::move(property_name), value_expressions, dvalue_expressions);
58 }
59 } // namespace MaterialPropertyLib
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27
T peekConfigParameter(std::string const &param) const
void checkConfigParameter(std::string const &param, T const &value) const
T getConfigParameter(std::string const &param) const
Range< SubtreeIterator > getConfigSubtreeList(std::string const &root) const
Definition: ConfigTree.cpp:169
ConfigTree getConfigSubtree(std::string const &root) const
Definition: ConfigTree.cpp:146
std::unique_ptr< Function > createFunction(BaseLib::ConfigTree const &config)