OGS
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  Parameter
 
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  ParameterBase
 
struct  RandomFieldMeshElementParameter
 A parameter represented by a mesh property vector. More...
 
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, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation >> const &curves)
 
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)
 
std::optional< std::string > isDefinedOnSameMesh (ParameterBase const &parameter, MeshLib::Mesh const &mesh)
 
std::unique_ptr< ParameterBasecreateRandomFieldMeshElementParameter (std::string const &name, BaseLib::ConfigTree const &config, MeshLib::Mesh &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)
 

Variables

static double const tolerance = 1.e-15
 
static const char *const error_info
 

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 19 of file ConstantParameter.cpp.

21 {
23  config.checkConfigParameter("type", "Constant");
24 
25  // Optional case for single-component variables where the value can be used.
26  // If the 'value' tag is found, use it and return. Otherwise continue with
27  // then required tag 'values'.
28  {
29  auto const value =
31  config.getConfigParameterOptional<std::vector<double>>("value");
32 
33  if (value)
34  {
35  if (value->size() != 1)
36  {
37  OGS_FATAL(
38  "Expected to read exactly one value, but {:d} were given.",
39  value->size());
40  }
41  DBUG("Using value {:g} for constant parameter.", (*value)[0]);
42  return std::make_unique<ConstantParameter<double>>(name,
43  (*value)[0]);
44  }
45  }
46 
47  // Value tag not available; continue with required values tag.
48  std::vector<double> const values =
50  config.getConfigParameter<std::vector<double>>("values");
51 
52  if (values.empty())
53  {
54  OGS_FATAL("No value available for constant parameter.");
55  }
56 
57  DBUG("Using following values for the constant parameter:");
58  for (double const v : values)
59  {
60  (void)v; // unused value if building w/o DBUG output.
61  DBUG("\t{:g}", v);
62  }
63 
64  return std::make_unique<ConstantParameter<double>>(name, values);
65 }
#define OGS_FATAL(...)
Definition: Error.h:26
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27

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

Referenced by createParameter().

◆ 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 17 of file CurveScaledParameter.cpp.

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

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

Referenced by createParameter().

◆ createFunctionParameter()

std::unique_ptr< ParameterBase > ParameterLib::createFunctionParameter ( 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__Function__expression

Definition at line 17 of file FunctionParameter.cpp.

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

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

Referenced by createParameter().

◆ 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.

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);
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  std::map<int, Values> vec_index_values;
39  for (auto p : config.getConfigSubtreeList("index_values"))
40  {
42  auto const index = p.getConfigParameter<int>("index");
43  {
45  auto const value = p.getConfigParameterOptional<double>("value");
46 
47  if (value)
48  {
49  Values values(1, *value);
50  vec_index_values.emplace(index, values);
51  continue;
52  }
53  }
54 
55  // Value tag not available; continue with required values tag.
57  Values const values = p.getConfigParameter<Values>("values");
58 
59  if (values.empty())
60  {
61  OGS_FATAL("No value available for constant parameter.");
62  }
63 
64  vec_index_values.emplace(index, values);
65  }
66 
67  // check the input
68  for (auto p : vec_index_values)
69  {
70 #ifndef USE_PETSC // In case of partitioned meshes not all of the material ids
71  // might be available in the particular partition, therefore
72  // the check is omitted.
73  if (std::find(group_id_property->begin(), group_id_property->end(),
74  p.first) == 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);
80  }
81 #endif
82 
83  auto const n_values = vec_index_values.begin()->second.size();
84  if (p.second.size() != n_values)
85  {
86  OGS_FATAL(
87  "The length of some values ({:d}) is different from the first "
88  "one ({:d}). The length should be same for all index_values.",
89  p.second.size(), n_values);
90  }
91  }
92 
93  if (group_id_property->getMeshItemType() == MeshLib::MeshItemType::Node)
94  {
95  return std::make_unique<
96  GroupBasedParameter<double, MeshLib::MeshItemType::Node>>(
97  name, mesh, *group_id_property, vec_index_values);
98  }
99  if (group_id_property->getMeshItemType() == MeshLib::MeshItemType::Cell)
100  {
101  return std::make_unique<
102  GroupBasedParameter<double, MeshLib::MeshItemType::Cell>>(
103  name, mesh, *group_id_property, vec_index_values);
104  }
105 
106  OGS_FATAL("Mesh item type of the specified property is not supported.");
107 }

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

Referenced by createParameter().

◆ 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 18 of file MeshElementParameter.cpp.

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

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

Referenced by createParameter().

◆ 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 18 of file MeshNodeParameter.cpp.

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

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

Referenced by createParameter().

◆ 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 26 of file Parameter.cpp.

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

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

Referenced by ProjectData::parseParameters().

◆ createRandomFieldMeshElementParameter()

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

Definition at line 21 of file RandomFieldMeshElementParameter.cpp.

24 {
26  config.checkConfigParameter("type", "RandomFieldMeshElement");
27  auto const field_name =
29  config.getConfigParameter<std::string>("field_name");
30  auto const range =
32  config.getConfigParameter<std::vector<double>>("range");
33  if (range.size() != 2)
34  {
35  OGS_FATAL(
36  "The range needs to have two components, but {:d} were given.",
37  range.size());
38  }
39  auto const seed =
41  config.getConfigParameter<int>("seed");
42  DBUG("Generating field {:s} with range {:g} to {:g} and seed {:d}.",
43  field_name, range[0], range[1], seed);
44 
45  std::vector<double> values(mesh.getElements().size());
46 
47  std::mt19937 generator(seed);
48  std::uniform_real_distribution<> distr(range[0], range[1]);
49  auto gen = [&distr, &generator]() { return distr(generator); };
50  generate(begin(values), end(values), gen);
51 
53  values);
54 
55  auto const& property =
56  mesh.getProperties().getPropertyVector<double>(field_name);
57 
58  if (property->getMeshItemType() != MeshLib::MeshItemType::Cell)
59  {
60  OGS_FATAL("The mesh property `{:s}' is not an element property.",
61  field_name);
62  }
63 
64  return std::make_unique<RandomFieldMeshElementParameter<double>>(name, mesh,
65  *property);
66 }
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:98
Properties & getProperties()
Definition: Mesh.h:123
PropertyVector< T > const * getPropertyVector(std::string const &name) const
void addPropertyToMesh(Mesh &mesh, std::string const &name, MeshItemType item_type, std::size_t number_of_components, std::vector< T > const &values)
Definition: Mesh.h:193

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

Referenced by createParameter().

◆ 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.

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);
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);
147  }
148 
149  return std::make_unique<TimeDependentHeterogeneousParameter>(
150  name, std::move(time_series));
151 }

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

Referenced by createParameter().

◆ 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.

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 }

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

Referenced by ProcessLib::SmallDeformation::createSmallDeformationProcess().

◆ findParameter() [1/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.

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 }

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

◆ findParameter() [2/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.

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);
115  }
116  return *parameter;
117 }

References OGS_FATAL.

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

◆ 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.

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

References DBUG().

Referenced by findParameterOptional().

◆ 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.

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);
62  }
63 
64  if (num_components != 0 &&
65  parameter->getNumberOfGlobalComponents() != num_components)
66  {
67  OGS_FATAL(
68  "The read parameter `{:s}' has the wrong number of components "
69  "({:d} instead of {:d}).",
70  parameter_name, parameter->getNumberOfGlobalComponents(),
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 }
std::optional< std::string > isDefinedOnSameMesh(ParameterBase const &parameter, MeshLib::Mesh const &mesh)
Definition: Parameter.cpp:98
ParameterBase * findParameterByName(std::string const &parameter_name, std::vector< std::unique_ptr< ParameterBase >> const &parameters)
Definition: Utils.cpp:15

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

◆ isDefinedOnSameMesh()

std::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 98 of file Parameter.cpp.

100 {
101  // Arbitrary domain of definition.
102  if (parameter.mesh() == nullptr)
103  {
104  return {};
105  }
106 
107  // Equal meshes.
108  if (*parameter.mesh() == mesh)
109  {
110  return {};
111  }
112 
113  return "The parameter's domain of definition mesh '" +
114  parameter.mesh()->getName() + "' differs from the used mesh '" +
115  mesh.getName() +
116  "'. The same mesh (the same name) has to be referenced in the "
117  "project file. Possible reasons are:\n - the parameter used for the "
118  "initial condition is not defined on the bulk mesh,\n - the "
119  "parameter's domain of definition mesh differs from the boundary "
120  "condition or source term domain of definition mesh.";
121 }

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

Referenced by findParameterOptional().

Variable Documentation

◆ error_info

const char* const ParameterLib::error_info
static
Initial value:
=
"The determinant of the coordinate system transformation matrix is '{:g}', "
"which is not sufficiently close to unity with the tolerance of '{:g}'. "
"Please adjust the accuracy of the local system bases"

Definition at line 20 of file CoordinateSystem.cpp.

Referenced by ParameterLib::CoordinateSystem::transformation_3d().

◆ tolerance