OGS 6.2.1-499-g3b941532c.dirty.20191012113459
ParameterLib Namespace Reference

Detailed Description

The TimeDependentHeterogeneousParameter class implements a parameter that varies in time and space, i.e., it is a function $ (t, x) \mapsto f(t, x) \in T^n $.

Classes

struct  ConstantParameter
 Single, constant value parameter. More...
 
struct  CoordinateSystem
 
struct  CurveScaledParameter
 
struct  FunctionParameter
 
struct  GroupBasedParameter
 
struct  MeshElementParameter
 A parameter represented by a mesh property vector. More...
 
struct  MeshNodeParameter
 A parameter represented by a mesh property vector. More...
 
struct  Parameter
 
struct  ParameterBase
 
class  SpatialPosition
 
class  TimeDependentHeterogeneousParameter
 

Functions

std::unique_ptr< ParameterBasecreateConstantParameter (std::string const &name, BaseLib::ConfigTree const &config)
 
std::unique_ptr< ParameterBasecreateCurveScaledParameter (std::string const &name, BaseLib::ConfigTree const &config, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation >> const &curves)
 
std::unique_ptr< ParameterBasecreateFunctionParameter (std::string const &name, BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh)
 
std::unique_ptr< ParameterBasecreateGroupBasedParameter (std::string const &name, BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh)
 
std::unique_ptr< ParameterBasecreateMeshElementParameter (std::string const &name, BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh)
 
std::unique_ptr< ParameterBasecreateMeshNodeParameter (std::string const &name, BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh)
 
std::unique_ptr< ParameterBasecreateParameter (BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< MeshLib::Mesh >> const &meshes, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation >> const &curves)
 
boost::optional< std::string > isDefinedOnSameMesh (ParameterBase const &parameter, MeshLib::Mesh const &mesh)
 
std::unique_ptr< ParameterBasecreateTimeDependentHeterogeneousParameter (std::string const &name, BaseLib::ConfigTree const &config)
 
ParameterBasefindParameterByName (std::string const &parameter_name, std::vector< std::unique_ptr< ParameterBase >> const &parameters)
 
template<typename ParameterDataType >
Parameter< ParameterDataType > * findParameterOptional (std::string const &parameter_name, std::vector< std::unique_ptr< ParameterBase >> const &parameters, int const num_components, MeshLib::Mesh const *const mesh=nullptr)
 
template<typename ParameterDataType >
Parameter< ParameterDataType > & findParameter (std::string const &parameter_name, std::vector< std::unique_ptr< ParameterBase >> const &parameters, int const num_components, MeshLib::Mesh const *const mesh=nullptr)
 
template<typename ParameterDataType >
Parameter< ParameterDataType > & findParameter (BaseLib::ConfigTree const &process_config, std::string const &tag, std::vector< std::unique_ptr< ParameterBase >> const &parameters, int const num_components, MeshLib::Mesh const *const mesh=nullptr)
 
template<typename ParameterDataType >
Parameter< ParameterDataType > * findOptionalTagParameter (BaseLib::ConfigTree const &process_config, std::string const &tag, std::vector< std::unique_ptr< ParameterBase >> const &parameters, int const num_components, MeshLib::Mesh const *const mesh=nullptr)
 

Function Documentation

◆ createConstantParameter()

std::unique_ptr< ParameterBase > ParameterLib::createConstantParameter ( std::string const &  name,
BaseLib::ConfigTree const &  config 
)
Input File Parameter:
prj__parameters__parameter__type
Input File Parameter:
prj__parameters__parameter__Constant__value
Input File Parameter:
prj__parameters__parameter__Constant__values

Definition at line 17 of file ConstantParameter.cpp.

References BaseLib::ConfigTree::checkConfigParameter(), BaseLib::ConfigTree::getConfigParameter(), BaseLib::ConfigTree::getConfigParameterOptional(), MaterialPropertyLib::name, and OGS_FATAL.

Referenced by createParameter().

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  {
27  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  {
52  OGS_FATAL("No value available for constant parameter.");
53  }
54 
55  DBUG("Using following values for the constant parameter:");
56  for (double const v : values)
57  {
58  (void)v; // unused value if building w/o DBUG output.
59  DBUG("\t%g", v);
60  }
61 
62  return std::make_unique<ConstantParameter<double>>(name, values);
63 }
#define OGS_FATAL(fmt,...)
Definition: Error.h:64

◆ createCurveScaledParameter()

std::unique_ptr< ParameterBase > ParameterLib::createCurveScaledParameter ( std::string const &  name,
BaseLib::ConfigTree const &  config,
std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation >> const &  curves 
)
Input File Parameter:
prj__parameters__parameter__type
Input File Parameter:
prj__parameters__parameter__CurveScaled__curve
Input File Parameter:
prj__parameters__parameter__CurveScaled__parameter

Definition at line 16 of file CurveScaledParameter.cpp.

References BaseLib::ConfigTree::checkConfigParameter(), BaseLib::ConfigTree::getConfigParameter(), MaterialPropertyLib::name, and OGS_FATAL.

Referenced by createParameter().

22 {
24  config.checkConfigParameter("type", "CurveScaled");
25 
27  auto curve_name = config.getConfigParameter<std::string>("curve");
28  DBUG("Using curve %s", curve_name.c_str());
29 
30  auto const curve_it = curves.find(curve_name);
31  if (curve_it == curves.end())
32  {
33  OGS_FATAL("Curve `%s' does not exists.", curve_name.c_str());
34  }
35 
36  auto referenced_parameter_name =
38  config.getConfigParameter<std::string>("parameter");
39  DBUG("Using parameter %s", referenced_parameter_name.c_str());
40 
41  // TODO other data types than only double
42  return std::make_unique<CurveScaledParameter<double>>(
43  name, *curve_it->second, referenced_parameter_name);
44 }
#define OGS_FATAL(fmt,...)
Definition: Error.h:64

◆ createFunctionParameter()

std::unique_ptr< ParameterBase > ParameterLib::createFunctionParameter ( std::string const &  name,
BaseLib::ConfigTree const &  config,
MeshLib::Mesh const &  mesh 
)
Input File Parameter:
prj__parameters__parameter__type
Input File Parameter:
prj__parameters__parameter__Function__expression

Definition at line 18 of file FunctionParameter.cpp.

References BaseLib::ConfigTree::checkConfigParameter(), BaseLib::ConfigTree::getConfigSubtreeList(), and MaterialPropertyLib::name.

Referenced by createParameter().

21 {
23  config.checkConfigParameter("type", "Function");
24 
25  std::vector<std::string> vec_expressions;
26 
28  for (auto const& p : config.getConfigSubtreeList("expression"))
29  {
30  std::string const expression_str = p.getValue<std::string>();
31  vec_expressions.emplace_back(expression_str);
32  }
33 
34  return std::make_unique<FunctionParameter<double>>(name, mesh,
35  vec_expressions);
36 }
static const double p

◆ createGroupBasedParameter()

std::unique_ptr< ParameterBase > ParameterLib::createGroupBasedParameter ( std::string const &  name,
BaseLib::ConfigTree const &  config,
MeshLib::Mesh const &  mesh 
)
Input File Parameter:
prj__parameters__parameter__type
Input File Parameter:
prj__parameters__parameter__Group__group_id_property
Input File Parameter:
prj__parameters__parameter__Group__index_values
Input File Parameter:
prj__parameters__parameter__Group__index_values__index
Input File Parameter:
prj__parameters__parameter__Group__index_values__value
Input File Parameter:
prj__parameters__parameter__Group__index_values__values

Definition at line 19 of file GroupBasedParameter.cpp.

References MeshLib::Cell, BaseLib::ConfigTree::checkConfigParameter(), BaseLib::ConfigTree::getConfigParameter(), BaseLib::ConfigTree::getConfigSubtreeList(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), MaterialPropertyLib::name, MeshLib::Node, and OGS_FATAL.

Referenced by createParameter().

22 {
24  config.checkConfigParameter("type", "Group");
25 
26  // get a property vector of group IDs
27  std::string const group_id_property_name =
29  config.getConfigParameter<std::string>("group_id_property");
30  DBUG("Using group_id_property %s", group_id_property_name.c_str());
31 
32  auto const& group_id_property =
33  mesh.getProperties().getPropertyVector<int>(group_id_property_name);
34 
35  // parse mapping data
36  using Values = std::vector<double>;
37  using Index_Values = std::pair<int, Values>;
38  std::vector<Index_Values> vec_index_values;
40  for (auto p : config.getConfigSubtreeList("index_values"))
41  {
43  auto const index = p.getConfigParameter<int>("index");
44  {
46  auto const value = p.getConfigParameterOptional<double>("value");
47 
48  if (value)
49  {
50  Values values(1, *value);
51  vec_index_values.emplace_back(index, values);
52  continue;
53  }
54  }
55 
56  // Value tag not available; continue with required values tag.
58  Values const values = p.getConfigParameter<Values>("values");
59 
60  if (values.empty())
61  {
62  OGS_FATAL("No value available for constant parameter.");
63  }
64 
65  vec_index_values.emplace_back(index, values);
66  }
67 
68  // check the input
69  unsigned n_values = vec_index_values.front().second.size();
70  for (auto p : vec_index_values)
71  {
72  auto itr = std::find(group_id_property->begin(),
73  group_id_property->end(), p.first);
74  if (itr == group_id_property->end())
75  {
76  OGS_FATAL(
77  "Specified property index %d does not exist in the property "
78  "vector %s",
79  p.first, group_id_property_name.c_str());
80  }
81 
82  if (p.second.size() != n_values)
83  {
84  OGS_FATAL(
85  "The length of some values (%d) is different from the first "
86  "one (%d). "
87  "The length should be same for all index_values.",
88  p.second.size(), n_values);
89  }
90  }
91 
92  // create a mapping table
93  const int max_index =
94  *std::max_element(group_id_property->begin(), group_id_property->end());
95  std::vector<Values> vec_values(max_index + 1);
96  for (auto p : vec_index_values)
97  {
98  vec_values[p.first] = p.second;
99  }
100 
101  if (group_id_property->getMeshItemType() == MeshLib::MeshItemType::Node)
102  {
103  return std::make_unique<
104  GroupBasedParameter<double, MeshLib::MeshItemType::Node>>(
105  name, mesh, *group_id_property, vec_values);
106  }
107  if (group_id_property->getMeshItemType() == MeshLib::MeshItemType::Cell)
108  {
109  return std::make_unique<
110  GroupBasedParameter<double, MeshLib::MeshItemType::Cell>>(
111  name, mesh, *group_id_property, vec_values);
112  }
113 
114  OGS_FATAL("Mesh item type of the specified property is not supported.");
115 }
static const double p
#define OGS_FATAL(fmt,...)
Definition: Error.h:64

◆ createMeshElementParameter()

std::unique_ptr< ParameterBase > ParameterLib::createMeshElementParameter ( std::string const &  name,
BaseLib::ConfigTree const &  config,
MeshLib::Mesh const &  mesh 
)
Input File Parameter:
prj__parameters__parameter__type
Input File Parameter:
prj__parameters__parameter__MeshElement__field_name

Definition at line 17 of file MeshElementParameter.cpp.

References MeshLib::Cell, BaseLib::ConfigTree::checkConfigParameter(), BaseLib::ConfigTree::getConfigParameter(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), MaterialPropertyLib::name, and OGS_FATAL.

Referenced by createParameter().

20 {
22  config.checkConfigParameter("type", "MeshElement");
23  auto const field_name =
25  config.getConfigParameter<std::string>("field_name");
26  DBUG("Using field_name %s", field_name.c_str());
27 
28  // TODO other data types than only double
29  auto const& property =
30  mesh.getProperties().getPropertyVector<double>(field_name);
31 
32  if (property->getMeshItemType() != MeshLib::MeshItemType::Cell)
33  {
34  OGS_FATAL("The mesh property `%s' is not an element property.",
35  field_name.c_str());
36  }
37 
38  return std::make_unique<MeshElementParameter<double>>(name, mesh,
39  *property);
40 }
#define OGS_FATAL(fmt,...)
Definition: Error.h:64

◆ createMeshNodeParameter()

std::unique_ptr< ParameterBase > ParameterLib::createMeshNodeParameter ( std::string const &  name,
BaseLib::ConfigTree const &  config,
MeshLib::Mesh const &  mesh 
)
Input File Parameter:
prj__parameters__parameter__type
Input File Parameter:
prj__parameters__parameter__MeshNode__field_name

Definition at line 17 of file MeshNodeParameter.cpp.

References BaseLib::ConfigTree::checkConfigParameter(), BaseLib::ConfigTree::getConfigParameter(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), MaterialPropertyLib::name, MeshLib::Node, and OGS_FATAL.

Referenced by createParameter().

20 {
22  config.checkConfigParameter("type", "MeshNode");
23  auto const field_name =
25  config.getConfigParameter<std::string>("field_name");
26  DBUG("Using field_name %s", field_name.c_str());
27 
28  // TODO other data types than only double
29  auto const& property =
30  mesh.getProperties().getPropertyVector<double>(field_name);
31 
32  if (property->getMeshItemType() != MeshLib::MeshItemType::Node)
33  {
34  OGS_FATAL("The mesh property `%s' is not a nodal property.",
35  field_name.c_str());
36  }
37 
38  return std::make_unique<MeshNodeParameter<double>>(name, mesh, *property);
39 }
#define OGS_FATAL(fmt,...)
Definition: Error.h:64

◆ createParameter()

std::unique_ptr< ParameterBase > ParameterLib::createParameter ( BaseLib::ConfigTree const &  config,
const std::vector< std::unique_ptr< MeshLib::Mesh >> &  meshes,
std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation >> const &  curves 
)

Constructs a new ParameterBase from the given configuration.

The meshes vector is used to set up parameters from mesh input data.

Input File Parameter:
prj__parameters__parameter__name
Input File Parameter:
prj__parameters__parameter__type
Input File Parameter:
prj__parameters__parameter__mesh

Definition at line 25 of file Parameter.cpp.

References createConstantParameter(), createCurveScaledParameter(), createFunctionParameter(), createGroupBasedParameter(), createMeshElementParameter(), createMeshNodeParameter(), createTimeDependentHeterogeneousParameter(), BaseLib::findElementOrError(), BaseLib::ConfigTree::getConfigParameter(), MaterialPropertyLib::name, OGS_FATAL, and BaseLib::ConfigTree::peekConfigParameter().

Referenced by ParameterLib::Parameter< double >::getNodalValuesOnElement(), and ProjectData::parseParameters().

31 {
33  auto const name = config.getConfigParameter<std::string>("name");
35  auto const type = config.peekConfigParameter<std::string>("type");
36 
37  // Either the mesh name is given, or the first mesh's name will be
38  // taken.
39  auto const mesh_name =
41  config.getConfigParameter<std::string>("mesh", meshes[0]->getName());
42 
43  auto const& mesh = *BaseLib::findElementOrError(
44  begin(meshes), end(meshes),
45  [&mesh_name](auto const& m) { return m->getName() == mesh_name; },
46  "Expected to find a mesh named " + mesh_name + ".");
47 
48  // Create parameter based on the provided type.
49  if (type == "Constant")
50  {
51  INFO("ConstantParameter: %s", name.c_str());
52  return createConstantParameter(name, config);
53  }
54  if (type == "CurveScaled")
55  {
56  INFO("CurveScaledParameter: %s", name.c_str());
57  return createCurveScaledParameter(name, config, curves);
58  }
59  if (type == "Function")
60  {
61  INFO("FunctionParameter: %s", name.c_str());
62  return createFunctionParameter(name, config, mesh);
63  }
64  if (type == "Group")
65  {
66  INFO("GroupBasedParameter: %s", name.c_str());
67  return createGroupBasedParameter(name, config, mesh);
68  }
69  if (type == "MeshElement")
70  {
71  INFO("MeshElementParameter: %s", name.c_str());
72  return createMeshElementParameter(name, config, mesh);
73  }
74  if (type == "MeshNode")
75  {
76  INFO("MeshNodeParameter: %s", name.c_str());
77  return createMeshNodeParameter(name, config, mesh);
78  }
79  if (type == "TimeDependentHeterogeneousParameter")
80  {
81  INFO("TimeDependentHeterogeneousParameter: %s", name.c_str());
83  }
84 
85  OGS_FATAL("Cannot construct a parameter of given type '%s'.", type.c_str());
86 }
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 > 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)
std::unique_ptr< ParameterBase > createTimeDependentHeterogeneousParameter(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)
#define OGS_FATAL(fmt,...)
Definition: Error.h:64
std::iterator_traits< InputIt >::reference findElementOrError(InputIt begin, InputIt end, Predicate predicate, std::string const &error="")
Definition: Algorithm.h:66
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)

◆ createTimeDependentHeterogeneousParameter()

std::unique_ptr< ParameterBase > ParameterLib::createTimeDependentHeterogeneousParameter ( std::string const &  name,
BaseLib::ConfigTree const &  config 
)
Input File Parameter:
prj__parameters__parameter__type
Input File Parameter:
prj__parameters__parameter__TimeDependentHeterogeneousParameter__time_series
Input File Parameter:
prj__parameters__parameter__TimeDependentHeterogeneousParameter__time_series__pair
Input File Parameter:
prj__parameters__parameter__TimeDependentHeterogeneousParameter__time_series__pair__time
Input File Parameter:
prj__parameters__parameter__TimeDependentHeterogeneousParameter__time_series__pair__parameter_name

Definition at line 106 of file TimeDependentHeterogeneousParameter.cpp.

References BaseLib::ConfigTree::checkConfigParameter(), BaseLib::ConfigTree::getConfigSubtree(), ParameterLib::ParameterBase::name, and OGS_FATAL.

Referenced by createParameter().

108 {
110  config.checkConfigParameter("type", "TimeDependentHeterogeneousParameter");
111  auto const time_series_config =
113  config.getConfigSubtree("time_series");
114 
115  std::vector<TimeDependentHeterogeneousParameter::PairTimeParameterName>
116  time_series;
118  for (auto const p : time_series_config.getConfigSubtreeList("pair"))
119  {
121  auto time = p.getConfigParameter<double>("time");
122  auto parameter_name =
124  p.getConfigParameter<std::string>("parameter_name");
125  time_series.emplace_back(time, parameter_name);
126  }
127 
128  if (time_series.empty())
129  {
130  OGS_FATAL(
131  "Time dependent heterogeneous parameter '%s' doesn't contain "
132  "necessary time series data.",
133  name.c_str());
134  }
135 
136  if (!std::is_sorted(
137  time_series.begin(), time_series.end(),
138  [](TimeDependentHeterogeneousParameter::PairTimeParameterName const&
139  p0,
140  TimeDependentHeterogeneousParameter::PairTimeParameterName const&
141  p1) { return p0.first < p1.first; }))
142  {
143  OGS_FATAL(
144  "The points in time in the time series '%s' aren't in ascending "
145  "order.",
146  name.c_str());
147  }
148 
149  return std::make_unique<TimeDependentHeterogeneousParameter>(
150  name, std::move(time_series));
151 }
static const double p
#define OGS_FATAL(fmt,...)
Definition: Error.h:64

◆ findOptionalTagParameter()

template<typename ParameterDataType >
Parameter<ParameterDataType>* ParameterLib::findOptionalTagParameter ( BaseLib::ConfigTree const &  process_config,
std::string const &  tag,
std::vector< std::unique_ptr< ParameterBase >> const &  parameters,
int const  num_components,
MeshLib::Mesh const *const  mesh = nullptr 
)

Find a parameter of specific type for a name given in the process configuration under the optional tag. If the tag is not present, a nullptr will be returned. The parameter must have the specified number of components. In the process config a parameter is referenced by a name. For example it will be looking for a parameter named "K" in the list of parameters when the tag is "hydraulic_conductivity":

<process>
...
<hydraulic_conductivity>K</hydraulic_conductivity>
</process>

and return a pointer to that parameter. Additionally it checks for the type of the found parameter.

Input File Parameter:
special OGS input file parameter

Definition at line 163 of file Utils.h.

References BaseLib::ConfigTree::getConfigParameterOptional(), and MaterialPropertyLib::name.

167 {
168  // Find parameter name in process config.
169  auto const name =
171  process_config.getConfigParameterOptional<std::string>(tag);
172 
173  if (!name)
174  {
175  return nullptr;
176  }
177  return &findParameter<ParameterDataType>(*name, parameters, num_components,
178  mesh);
179 }

◆ findParameter() [1/2]

template<typename ParameterDataType >
Parameter<ParameterDataType>& ParameterLib::findParameter ( std::string const &  parameter_name,
std::vector< std::unique_ptr< ParameterBase >> const &  parameters,
int const  num_components,
MeshLib::Mesh const *const  mesh = nullptr 
)

Find a parameter of specific type for a given name.

Template Parameters
ParameterDataTypethe data type of the parameter
Parameters
parameter_namename of the requested parameter
parameterslist of parameters in which it will be searched
num_componentsthe number of components of the parameters or zero if any number is acceptable
meshan optional mesh pointer used for test whether the parameter is defined on the given mesh. No test is performed if the pointer is a nullptr.
See also
The documentation of the other findParameter() function.

Definition at line 102 of file Utils.h.

References OGS_FATAL.

Referenced by ProcessLib::LIE::HydroMechanics::createHydroMechanicsProcess(), MaterialLib::PorousMedium::createPermeabilityModel(), ProcessLib::RichardsComponentTransport::createRichardsComponentTransportProcess(), ProcessLib::ThermoMechanicalPhaseField::createThermoMechanicalPhaseFieldProcess(), and ProcessLib::ThermoMechanics::createThermoMechanicsProcess().

106 {
107  auto* parameter = findParameterOptional<ParameterDataType>(
108  parameter_name, parameters, num_components, mesh);
109 
110  if (!parameter)
111  {
112  OGS_FATAL(
113  "Could not find parameter `%s' in the provided parameters list.",
114  parameter_name.c_str());
115  }
116  return *parameter;
117 }
#define OGS_FATAL(fmt,...)
Definition: Error.h:64

◆ findParameter() [2/2]

template<typename ParameterDataType >
Parameter<ParameterDataType>& ParameterLib::findParameter ( BaseLib::ConfigTree const &  process_config,
std::string const &  tag,
std::vector< std::unique_ptr< ParameterBase >> const &  parameters,
int const  num_components,
MeshLib::Mesh const *const  mesh = nullptr 
)

Find a parameter of specific type for a name given in the process configuration under the tag. The parameter must have the specified number of components. In the process config a parameter is referenced by a name. For example it will be looking for a parameter named "K" in the list of parameters when the tag is "hydraulic_conductivity":

<process>
...
<hydraulic_conductivity>K</hydraulic_conductivity>
</process>

and return a reference to that parameter. Additionally it checks for the type of the found parameter.

Input File Parameter:
special OGS input file parameter

Definition at line 134 of file Utils.h.

References BaseLib::ConfigTree::getConfigParameter(), and MaterialPropertyLib::name.

138 {
139  // Find parameter name in process config.
141  auto const name = process_config.getConfigParameter<std::string>(tag);
142 
143  return findParameter<ParameterDataType>(name, parameters, num_components,
144  mesh);
145 }

◆ findParameterByName()

ParameterBase * ParameterLib::findParameterByName ( std::string const &  parameter_name,
std::vector< std::unique_ptr< ParameterBase >> const &  parameters 
)

Find an optional parameter of specific type for a given name.

Template Parameters
ParameterDataTypethe data type of the parameter
Parameters
parameter_namename of the requested parameter
parameterslist of parameters in which it will be searched

Definition at line 15 of file Utils.cpp.

Referenced by findParameterOptional().

18 {
19  // Find corresponding parameter by name.
20  auto const it = std::find_if(
21  parameters.cbegin(), parameters.cend(),
22  [&parameter_name](std::unique_ptr<ParameterBase> const& p) {
23  return p->name == parameter_name;
24  });
25 
26  if (it == parameters.end())
27  {
28  return nullptr;
29  }
30 
31  DBUG("Found parameter `%s'.", (*it)->name.c_str());
32  return it->get();
33 }
static const double p

◆ findParameterOptional()

template<typename ParameterDataType >
Parameter<ParameterDataType>* ParameterLib::findParameterOptional ( std::string const &  parameter_name,
std::vector< std::unique_ptr< ParameterBase >> const &  parameters,
int const  num_components,
MeshLib::Mesh const *const  mesh = nullptr 
)

Find an optional parameter of specific type for a given name.

Template Parameters
ParameterDataTypethe data type of the parameter
Parameters
parameter_namename of the requested parameter
parameterslist of parameters in which it will be searched
num_componentsthe number of components of the parameters or zero if any number is acceptable
meshan optional mesh pointer used for test whether the parameter is defined on the given mesh. No test is performed if the pointer is a nullptr.
See also
The documentation of the other findParameter() function.

Definition at line 42 of file Utils.h.

References findParameterByName(), isDefinedOnSameMesh(), and OGS_FATAL.

46 {
47  // Find corresponding parameter by name.
48  ParameterBase* parameter_ptr =
49  findParameterByName(parameter_name, parameters);
50  if (parameter_ptr == nullptr)
51  {
52  return nullptr;
53  }
54 
55  // Check the type correctness of the found parameter.
56  auto* const parameter =
57  dynamic_cast<Parameter<ParameterDataType>*>(parameter_ptr);
58  if (!parameter)
59  {
60  OGS_FATAL("The read parameter `%s' is of incompatible type.",
61  parameter_name.c_str());
62  }
63 
64  if (num_components != 0 &&
65  parameter->getNumberOfComponents() != num_components)
66  {
67  OGS_FATAL(
68  "The read parameter `%s' has the wrong number of components (%lu "
69  "instead of %u).",
70  parameter_name.c_str(), parameter->getNumberOfComponents(),
71  num_components);
72  }
73 
74  // Test the parameter's mesh only if there is a "test"-mesh provided.
75  if (mesh != nullptr)
76  {
77  if (auto const error = isDefinedOnSameMesh(*parameter, *mesh))
78  {
79  OGS_FATAL(
80  "The found parameter is not suitable for the use on the "
81  "required mesh.\n%s",
82  error->c_str());
83  }
84  }
85 
86 
87  return parameter;
88 }
ParameterBase * findParameterByName(std::string const &parameter_name, std::vector< std::unique_ptr< ParameterBase >> const &parameters)
Definition: Utils.cpp:15
boost::optional< std::string > isDefinedOnSameMesh(ParameterBase const &parameter, MeshLib::Mesh const &mesh)
Definition: Parameter.cpp:88
#define OGS_FATAL(fmt,...)
Definition: Error.h:64

◆ isDefinedOnSameMesh()

boost::optional< std::string > ParameterLib::isDefinedOnSameMesh ( ParameterBase const &  parameter,
MeshLib::Mesh const &  mesh 
)

Checks whether the parameter can be used on the given mesh. The parameter's domain of definition can be arbitrary (like for constant parameters), or the parameter is defined on a mesh. In the latter case that mesh must be equal to the given mesh.

Returns
nothing if the parameter can be used on the given mesh, or an error string otherwise.

Definition at line 88 of file Parameter.cpp.

References MeshLib::Mesh::getName(), and ParameterLib::ParameterBase::mesh().

Referenced by findParameterOptional(), and ParameterLib::Parameter< double >::getNodalValuesOnElement().

90 {
91  // Arbitrary domain of definition.
92  if (parameter.mesh() == nullptr)
93  {
94  return {};
95  }
96 
97  // Equal meshes.
98  if (*parameter.mesh() == mesh)
99  {
100  return {};
101  }
102 
103  return "The parameter's domain of definition mesh '" +
104  parameter.mesh()->getName() + "' differs from the used mesh '" +
105  mesh.getName() +
106  "'. The same mesh (the same name) has to be referenced in the "
107  "project file. Possible reasons are:\n - the parameter used for the "
108  "initial condition is not defined on the bulk mesh,\n - the "
109  "parameter's domain of definition mesh differs from the boundary "
110  "condition or source term domain of definition mesh.";
111 }