OGS
CreateSecondaryVariables.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
5
7#include "SecondaryVariable.h"
8
9namespace ProcessLib
10{
12 SecondaryVariableCollection& secondary_variables)
13{
14 auto sec_vars_config =
16 config.getConfigSubtreeOptional("secondary_variables");
17 if (!sec_vars_config)
18 {
19 return;
20 }
21
22 for (
23 auto sec_var_config :
25 sec_vars_config->getConfigSubtreeList("secondary_variable"))
26 {
27 auto const type =
29 sec_var_config.getConfigAttributeOptional<std::string>("type");
30 if (type)
31 {
32 WARN(
33 "Secondary variable type specification is deprecated and is "
34 "ignored. All secondary variable types are 'static'.");
35 }
36
37 auto const [internal_name, output_name] =
38 [&sec_var_config]() -> std::pair<std::string, std::string>
39 {
40 auto const name =
42 sec_var_config.getConfigAttributeOptional<std::string>("name");
43 if (name)
44 {
45 return {*name, *name};
46 }
47
48 auto const internal_name =
50 sec_var_config.getConfigAttribute<std::string>("internal_name");
51 auto const output_name =
53 sec_var_config.getConfigAttribute<std::string>("output_name");
54 return {internal_name, output_name};
55
56 }();
57
58 secondary_variables.addNameMapping(internal_name, output_name);
59 }
60}
61
62} // namespace ProcessLib
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34
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)