OGS
CreateSecondaryVariables.cpp
Go to the documentation of this file.
1
12
13#include "BaseLib/ConfigTree.h"
14#include "SecondaryVariable.h"
15
16namespace ProcessLib
17{
19 SecondaryVariableCollection& secondary_variables)
20{
21 auto sec_vars_config =
23 config.getConfigSubtreeOptional("secondary_variables");
24 if (!sec_vars_config)
25 {
26 return;
27 }
28
29 for (
30 auto sec_var_config :
32 sec_vars_config->getConfigSubtreeList("secondary_variable"))
33 {
34 auto const type =
36 sec_var_config.getConfigAttributeOptional<std::string>("type");
37 if (type)
38 {
39 WARN(
40 "Secondary variable type specification is deprecated and is "
41 "ignored. All secondary variable types are 'static'.");
42 }
43
44 auto const [internal_name, output_name] =
45 [&sec_var_config]() -> std::pair<std::string, std::string>
46 {
48 auto const name =
49 sec_var_config.getConfigAttributeOptional<std::string>("name");
50 if (name)
51 {
52 return {*name, *name};
53 }
54 else
55 {
56 auto const internal_name =
58 sec_var_config.getConfigAttribute<std::string>(
59 "internal_name");
60 auto const output_name =
62 sec_var_config.getConfigAttribute<std::string>(
63 "output_name");
64 return {internal_name, output_name};
65 }
66 }();
67
68 secondary_variables.addNameMapping(internal_name, output_name);
69 }
70}
71
72} // namespace ProcessLib
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:42
std::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
Handles configuration of several secondary variables from the project file.
void addNameMapping(std::string const &internal_name, std::string const &external_name)
Register a variable with the given internal and external names.
void createSecondaryVariables(BaseLib::ConfigTree const &config, SecondaryVariableCollection &secondary_variables)