OGS 6.2.0-97-g4a610c866
Parameter.cpp
Go to the documentation of this file.
1 
10 #include "Parameter.h"
11 #include "BaseLib/ConfigTree.h"
12 #include "BaseLib/Error.h"
13 
14 #include "ConstantParameter.h"
15 #include "CurveScaledParameter.h"
16 #include "FunctionParameter.h"
17 #include "GroupBasedParameter.h"
18 #include "MeshElementParameter.h"
19 #include "MeshNodeParameter.h"
20 
21 namespace ParameterLib
22 {
23 std::unique_ptr<ParameterBase> createParameter(
24  BaseLib::ConfigTree const& config,
25  std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes,
26  std::map<std::string,
27  std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
28  curves)
29 {
31  auto const name = config.getConfigParameter<std::string>("name");
33  auto const type = config.peekConfigParameter<std::string>("type");
34 
35  // Either the mesh name is given, or the first mesh's name will be
36  // taken.
37  auto const mesh_name =
39  config.getConfigParameter<std::string>("mesh", meshes[0]->getName());
40 
41  auto const& mesh = *BaseLib::findElementOrError(
42  begin(meshes), end(meshes),
43  [&mesh_name](auto const& m) { return m->getName() == mesh_name; },
44  "Expected to find a mesh named " + mesh_name + ".");
45 
46  // Create parameter based on the provided type.
47  if (type == "Constant")
48  {
49  INFO("ConstantParameter: %s", name.c_str());
50  auto param = createConstantParameter(name, config);
51  return param;
52  }
53  if (type == "CurveScaled")
54  {
55  INFO("CurveScaledParameter: %s", name.c_str());
56  auto param = createCurveScaledParameter(name, config, curves);
57  return param;
58  }
59  if (type == "Function")
60  {
61  INFO("FunctionParameter: %s", name.c_str());
62  auto param = createFunctionParameter(name, config, mesh);
63  return param;
64  }
65  if (type == "Group")
66  {
67  INFO("GroupBasedParameter: %s", name.c_str());
68  auto param = createGroupBasedParameter(name, config, mesh);
69  return param;
70  }
71  if (type == "MeshElement")
72  {
73  INFO("MeshElementParameter: %s", name.c_str());
74  auto param = createMeshElementParameter(name, config, mesh);
75  return param;
76  }
77  if (type == "MeshNode")
78  {
79  INFO("MeshNodeParameter: %s", name.c_str());
80  auto param = createMeshNodeParameter(name, config, mesh);
81  return param;
82  }
83 
84  OGS_FATAL("Cannot construct a parameter of given type '%s'.", type.c_str());
85 }
86 
87 } // namespace ParameterLib
std::unique_ptr< ParameterBase > createCurveScaledParameter(std::string const &name, BaseLib::ConfigTree const &config, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation >> const &curves)
std::unique_ptr< ParameterBase > createParameter(BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< MeshLib::Mesh >> const &meshes, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation >> const &curves)
Definition: Parameter.cpp:23
std::unique_ptr< ParameterBase > createFunctionParameter(std::string const &name, BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh)
std::unique_ptr< ParameterBase > createConstantParameter(std::string const &name, BaseLib::ConfigTree const &config)
T getConfigParameter(std::string const &param) const
T peekConfigParameter(std::string const &param) const
std::unique_ptr< ParameterBase > createGroupBasedParameter(std::string const &name, BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh)
#define OGS_FATAL(fmt,...)
Definition: Error.h:63
std::iterator_traits< InputIt >::reference findElementOrError(InputIt begin, InputIt end, Predicate predicate, std::string const &error="")
Definition: Algorithm.h:67
std::unique_ptr< ParameterBase > createMeshElementParameter(std::string const &name, BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh)
std::unique_ptr< ParameterBase > createMeshNodeParameter(std::string const &name, BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh)