OGS 6.1.0-1699-ge946d4c5f
ConstantParameter.cpp
Go to the documentation of this file.
1 
10 #include "ConstantParameter.h"
11 #include <logog/include/logog.hpp>
12 #include "BaseLib/ConfigTree.h"
13 #include "BaseLib/Error.h"
14 
15 namespace ProcessLib
16 {
17 std::unique_ptr<ParameterBase> createConstantParameter(
18  std::string const& name, BaseLib::ConfigTree const& config)
19 {
21  config.checkConfigParameter("type", "Constant");
22 
23  // Optional case for single-component variables where the value can be used.
24  // If the 'value' tag is found, use it and return. Otherwise continue with
25  // then required tag 'values'.
26  {
28  auto const value =
29  config.getConfigParameterOptional<std::vector<double>>("value");
30 
31  if (value)
32  {
33  if (value->size() != 1)
34  {
35  OGS_FATAL(
36  "Expected to read exactly one value, but %d were given.",
37  value->size());
38  }
39  DBUG("Using value %g for constant parameter.", (*value)[0]);
40  return std::make_unique<ConstantParameter<double>>(name,
41  (*value)[0]);
42  }
43  }
44 
45  // Value tag not available; continue with required values tag.
46  std::vector<double> const values =
48  config.getConfigParameter<std::vector<double>>("values");
49 
50  if (values.empty())
51  OGS_FATAL("No value available for constant parameter.");
52 
53  DBUG("Using following values for the constant parameter:");
54  for (double const v : values)
55  {
56  (void)v; // unused value if building w/o DBUG output.
57  DBUG("\t%g", v);
58  }
59 
60  return std::make_unique<ConstantParameter<double>>(name, values);
61 }
62 
63 } // ProcessLib
std::unique_ptr< ParameterBase > createConstantParameter(std::string const &name, BaseLib::ConfigTree const &config)
T getConfigParameter(std::string const &param) const
void checkConfigParameter(std::string const &param, T const &value) const
boost::optional< T > getConfigParameterOptional(std::string const &param) const
#define OGS_FATAL(fmt,...)
Definition: Error.h:71