OGS 6.1.0-1699-ge946d4c5f
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 ProcessLib
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 {
30 
32  auto const name = config.getConfigParameter<std::string>("name");
34  auto const type = config.peekConfigParameter<std::string>("type");
35 
36  // Create parameter based on the provided type.
37  if (type == "Constant")
38  {
39  INFO("ConstantParameter: %s", name.c_str());
40  auto param = createConstantParameter(name, config);
41  return param;
42  }
43  if (type == "CurveScaled")
44  {
45  INFO("CurveScaledParameter: %s", name.c_str());
46  auto param = createCurveScaledParameter(name, config, curves);
47  return param;
48  }
49  if (type == "Function")
50  {
51  INFO("FunctionParameter: %s", name.c_str());
52  auto param = createFunctionParameter(name, config, *meshes.front());
53  return param;
54  }
55  if (type == "Group")
56  {
57  INFO("GroupBasedParameter: %s", name.c_str());
58  auto param = createGroupBasedParameter(name, config, *meshes.front());
59  return param;
60  }
61  if (type == "MeshElement")
62  {
63  INFO("MeshElementParameter: %s", name.c_str());
64  auto param = createMeshElementParameter(name, config, *meshes.front());
65  return param;
66  }
67  if (type == "MeshNode")
68  {
69  INFO("MeshNodeParameter: %s", name.c_str());
70  auto param = createMeshNodeParameter(name, config, *meshes.front());
71  return param;
72  }
73 
74  OGS_FATAL("Cannot construct a parameter of given type '%s'.", type.c_str());
75 }
76 
77 } // ProcessLib
std::unique_ptr< ParameterBase > createConstantParameter(std::string const &name, BaseLib::ConfigTree const &config)
std::unique_ptr< ParameterBase > createGroupBasedParameter(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)
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
T getConfigParameter(std::string const &param) const
T peekConfigParameter(std::string const &param) const
std::unique_ptr< ParameterBase > createMeshElementParameter(std::string const &name, BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh)
#define OGS_FATAL(fmt,...)
Definition: Error.h:71
std::unique_ptr< ParameterBase > createFunctionParameter(std::string const &name, BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh)