OGS
CreateConstant.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#include "Constant.h"
6
8{
9std::unique_ptr<Constant> createConstant(BaseLib::ConfigTree const& config)
10{
12 config.checkConfigParameter("type", "Constant");
13
14 // Second access for storage.
16 auto property_name = config.peekConfigParameter<std::string>("name");
17
18 DBUG("Create Constant property {:s}.", property_name);
19 auto const value_data =
21 config.getConfigParameterOptional<std::vector<double>>("value");
22
23 auto const values_data =
25 config.getConfigParameterOptional<std::vector<double>>("values");
26
27 if ((value_data) && (values_data))
28 {
30 "Both the value and the values tags were given.\n\
31 Please give only one of them.");
32 }
33
34 std::vector<double> values;
35
36 if (value_data)
37 {
38 values = *value_data;
39 }
40 else if (values_data)
41 {
42 values = *values_data;
43 }
44
45 if (values.empty())
46 {
47 OGS_FATAL("No value(s) was(were) provided.");
48 }
49
50 DBUG("Using following values for the constant parameter:");
51 for (double const v : values)
52 {
53 (void)v; // unused value if building w/o DBUG output.
54 DBUG("\t{:g}", v);
55 }
56
57 return std::make_unique<Constant>(std::move(property_name),
58 fromVector(values));
59}
60} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:19
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
T peekConfigParameter(std::string const &param) const
std::optional< T > getConfigParameterOptional(std::string const &param) const
void checkConfigParameter(std::string const &param, std::string_view const value) const
PropertyDataType fromVector(std::vector< double > const &values)
std::unique_ptr< Constant > createConstant(BaseLib::ConfigTree const &config)