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