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  ConstantParameter
 Single, constant value parameter. More...
 
struct  CoordinateSystem
 A local coordinate system used for tensor transformations. More...
 
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
 
struct  RandomFieldMeshElementParameter
 A parameter represented by a mesh property vector. More...
 
struct  RasterParameter
 
class  SpatialPosition
 
class  TimeDependentHeterogeneousParameter
 

Functions

std::unique_ptr< ParameterBasecreateConstantParameter (std::string const &name, BaseLib::ConfigTree const &config)
 
Eigen::Matrix< double, 2, 2 > getTransformationFromSingleBase2D (Parameter< double > const &unit_direction, SpatialPosition const &pos)
 
Eigen::Matrix< double, 3, 3 > getTransformationFromSingleBase3D (Parameter< double > const &unit_direction, SpatialPosition const &pos)
 
Parameter< double > const * parseBase1OrBase2 (BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, int const expected_component_number, std::string_view const base_tag_name)
 
void checkThirdBaseExistanceFor2D (BaseLib::ConfigTree const &config)
 
void confirmThirdBaseExplicit (BaseLib::ConfigTree const &config)
 
std::optional< ParameterLib::CoordinateSystemcreateCoordinateSystemWithImplicitBase (BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters)
 
std::optional< ParameterLib::CoordinateSystemcreateCoordinateSystem (std::optional< BaseLib::ConfigTree > const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters)
 
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::vector< GeoLib::NamedRaster > const &named_rasters, 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< ParameterBasecreateRasterParameter (std::string const &name, BaseLib::ConfigTree const &config, std::vector< GeoLib::NamedRaster > const &named_rasters)
 
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 = std::numeric_limits<double>::epsilon()
 
static constexpr char error_info []
 
static constexpr char normalization_error_info []
 

Function Documentation

◆ checkThirdBaseExistanceFor2D()

void ParameterLib::checkThirdBaseExistanceFor2D ( BaseLib::ConfigTree const & config)
Input File Parameter
prj__local_coordinate_system__basis_vector_2

Definition at line 62 of file CreateCoordinateSystem.cpp.

63{
64 auto const base2_config =
66 config.getConfigSubtreeOptional("basis_vector_2");
67 if (base2_config)
68 {
70 "The tag \"basis_vector_2\" is not needed for a 2D local "
71 "coordinate system.");
72 }
73}
#define OGS_FATAL(...)
Definition Error.h:26

References BaseLib::ConfigTree::getConfigSubtreeOptional(), and OGS_FATAL.

Referenced by createCoordinateSystem(), and createCoordinateSystemWithImplicitBase().

◆ confirmThirdBaseExplicit()

void ParameterLib::confirmThirdBaseExplicit ( BaseLib::ConfigTree const & config)
Input File Parameter
prj__local_coordinate_system__basis_vector_2__implicit

Definition at line 75 of file CreateCoordinateSystem.cpp.

76{
77 auto const implicit_base2 =
79 config.getConfigAttribute<bool>("implicit", false);
80 if (implicit_base2)
81 {
82 OGS_FATAL("basis_vector_2 must be explicit.");
83 }
84}

References BaseLib::ConfigTree::getConfigAttribute(), and OGS_FATAL.

Referenced by createCoordinateSystem(), and createCoordinateSystemWithImplicitBase().

◆ 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 {
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}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30

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

Referenced by createParameter().

◆ createCoordinateSystem()

std::optional< ParameterLib::CoordinateSystem > ParameterLib::createCoordinateSystem ( std::optional< BaseLib::ConfigTree > const & config,
std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const & parameters )
Input File Parameter
prj__local_coordinate_system__basis_vector_0
Input File Parameter
prj__local_coordinate_system__basis_vector_0__implicit
Input File Parameter
prj__local_coordinate_system__basis_vector_1
Input File Parameter
prj__local_coordinate_system__basis_vector_1__implicit
Input File Parameter
prj__local_coordinate_system__basis_vector_2

Definition at line 142 of file CreateCoordinateSystem.cpp.

145{
146 if (!config)
147 {
148 return {};
149 }
150
151 //
152 // Fetch the first basis vector; its length defines the dimension.
153 //
155 auto const& config_base0 = config->getConfigSubtree("basis_vector_0");
156 auto const implicit_base0 =
158 config_base0.getConfigAttribute<bool>("implicit", false);
159
160 // base0 and base1 can be implicit. If base0 is implicit, check whether
161 // base1 is implicit.
162 // If base1 is explicit, create a 2D system if its components is 2 or quit
163 // if its components is not equal to 2.
164 // Otherwise, read base2, create a 3D system if its components is 3 or quit
165 // if its components is not equal to 3.
166 if (implicit_base0)
167 {
168 return createCoordinateSystemWithImplicitBase(*config, parameters);
169 }
170
171 auto const base0_name = config_base0.getValue<std::string>();
172 auto const& basis_vector_0 = ParameterLib::findParameter<double>(
173 base0_name, parameters, 0 /* any dimension */);
174 int const dimension = basis_vector_0.getNumberOfGlobalComponents();
175 // check dimension
176 if (dimension != 2 && dimension != 3)
177 {
178 OGS_FATAL(
179 "Basis vector parameter '{:s}' must have two or three components, "
180 "but it has {:d}.",
181 base0_name, dimension);
182 }
183
184 // Fetch the second basis vector.
186 auto const& config_base1 = config->getConfigSubtree("basis_vector_1");
187 auto const implicit_base1 =
189 config_base1.getConfigAttribute<bool>("implicit", false);
190 if (implicit_base1)
191 {
192 OGS_FATAL(
193 "Since basis_vector_0 is explicitly defined, basis_vector_1"
194 " must be explicit as well.");
195 }
196 auto const base1_name = config_base1.getValue<std::string>();
197 auto const& basis_vector_1 =
198 ParameterLib::findParameter<double>(base1_name, parameters, dimension);
199
200 if (dimension == 2)
201 {
203 return ParameterLib::CoordinateSystem{basis_vector_0, basis_vector_1};
204 }
205
206 // Parse the third basis vector, e2, for the three dimensional system.
208 auto const& config_base2 = config->getConfigSubtree("basis_vector_2");
209 confirmThirdBaseExplicit(config_base2);
210
211 int const expected_component_number = 3;
212 auto const basis_vector_2 = parseBase1OrBase2(
213 config_base2, parameters, expected_component_number, "basis_vector_2");
214
215 return ParameterLib::CoordinateSystem{basis_vector_0, basis_vector_1,
216 *basis_vector_2};
217}
constexpr int dimension()
Displacement dimension of a vectorized tensor.
Parameter< double > const * parseBase1OrBase2(BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, int const expected_component_number, std::string_view const base_tag_name)
std::optional< ParameterLib::CoordinateSystem > createCoordinateSystemWithImplicitBase(BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters)
void checkThirdBaseExistanceFor2D(BaseLib::ConfigTree const &config)
void confirmThirdBaseExplicit(BaseLib::ConfigTree const &config)
A local coordinate system used for tensor transformations.

References checkThirdBaseExistanceFor2D(), confirmThirdBaseExplicit(), createCoordinateSystemWithImplicitBase(), OGS_FATAL, and parseBase1OrBase2().

Referenced by ProjectData::ProjectData().

◆ createCoordinateSystemWithImplicitBase()

std::optional< ParameterLib::CoordinateSystem > ParameterLib::createCoordinateSystemWithImplicitBase ( BaseLib::ConfigTree const & config,
std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const & parameters )
Input File Parameter
prj__local_coordinate_system__basis_vector_1
Input File Parameter
prj__local_coordinate_system__basis_vector_1__implicit
Input File Parameter
prj__local_coordinate_system__basis_vector_2

Definition at line 87 of file CreateCoordinateSystem.cpp.

90{
92 auto const& config_base1 = config.getConfigSubtree("basis_vector_1");
93
94 // Parse the second vectors.
95 auto const implicit_base1 =
97 config_base1.getConfigAttribute<bool>("implicit", false);
98
99 if (!implicit_base1)
100 {
101 // For 2D problem.
102 // Only the following case is accepted:
103 // <basis_vector_0 implicit = false/>
104 // <basis_vector_1> [two-component parameter] </basis_vector_1>.
105 int const expected_component_number = 2;
106 auto const basis_vector_1 =
107 parseBase1OrBase2(config_base1, parameters,
108 expected_component_number, "basis_vector_1");
109
111
112 return ParameterLib::CoordinateSystem(*basis_vector_1);
113 }
114
115 // For 3D problem.
116 // Only the following case is accepted:
117 // <basis_vector_0 implicit = false/>
118 // <basis_vector_1 implicit = false>.
119 // <basis_vector_2> [three-component parameter] </basis_vector_2>.
120
121 // Parse the third basis vector, e2, for the three dimensional system.
122 auto const config_base2 =
124 config.getConfigSubtreeOptional("basis_vector_2");
125 if (!config_base2)
126 {
127 OGS_FATAL(
128 "Both \"basis_vector_0\" and \"basis_vector_1\" are implicit but "
129 "\"basis_vector_2\" does not exist. If 2D coordinate system is "
130 "considered, please change \"basis_vector_1\" to explicit. If 3D "
131 "coordinate system is considered, please add \"basis_vector_2\".");
132 }
133
134 confirmThirdBaseExplicit(*config_base2);
135
136 int const expected_component_number = 3;
137 auto const basis_vector_2 = parseBase1OrBase2(
138 *config_base2, parameters, expected_component_number, "basis_vector_2");
139 return ParameterLib::CoordinateSystem(*basis_vector_2);
140}

References checkThirdBaseExistanceFor2D(), confirmThirdBaseExplicit(), BaseLib::ConfigTree::getConfigAttribute(), BaseLib::ConfigTree::getConfigSubtree(), BaseLib::ConfigTree::getConfigSubtreeOptional(), OGS_FATAL, and parseBase1OrBase2().

Referenced by createCoordinateSystem().

◆ 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(), 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}

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

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 {
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 {
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(), 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(), 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(), 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::vector< GeoLib::NamedRaster > const & named_rasters,
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. The named_rasters vector is used to set up parameters from raster 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 27 of file Parameter.cpp.

34{
36 auto const name = config.getConfigParameter<std::string>("name");
38 auto const type = config.peekConfigParameter<std::string>("type");
39
40 // Either the mesh name is given, or the first mesh's name will be
41 // taken.
42 auto const mesh_name =
44 config.getConfigParameter<std::string>("mesh", meshes[0]->getName());
45
46 auto const& mesh = MeshLib::findMeshByName(meshes, mesh_name);
47
48 // Create parameter based on the provided type.
49 if (type == "Constant")
50 {
51 INFO("ConstantParameter: {:s}", name);
52 return createConstantParameter(name, config);
53 }
54 if (type == "CurveScaled")
55 {
56 INFO("CurveScaledParameter: {:s}", name);
57 return createCurveScaledParameter(name, config, curves);
58 }
59 if (type == "Function")
60 {
61 INFO("FunctionParameter: {:s}", name);
62 return createFunctionParameter(name, config, curves);
63 }
64 if (type == "Group")
65 {
66 INFO("GroupBasedParameter: {:s}", name);
67 return createGroupBasedParameter(name, config, mesh);
68 }
69 if (type == "MeshElement")
70 {
71 INFO("MeshElementParameter: {:s}", name);
72 return createMeshElementParameter(name, config, mesh);
73 }
74 if (type == "MeshNode")
75 {
76 INFO("MeshNodeParameter: {:s}", name);
77 return createMeshNodeParameter(name, config, mesh);
78 }
79 if (type == "RandomFieldMeshElement")
80 {
81 auto& mesh_var = MeshLib::findMeshByName(meshes, mesh_name);
82 INFO("RandomFieldMeshElement: {:s}", name);
83 return createRandomFieldMeshElementParameter(name, config, mesh_var);
84 }
85 if (type == "Raster")
86 {
87 INFO("RasterParameter: {:s}", name);
88 return createRasterParameter(name, config, named_rasters);
89 }
90 if (type == "TimeDependentHeterogeneousParameter")
91 {
92 INFO("TimeDependentHeterogeneousParameter: {:s}", name);
94 }
95
96 OGS_FATAL("Cannot construct a parameter of given type '{:s}'.", type);
97}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
Mesh & findMeshByName(std::vector< std::unique_ptr< Mesh > > const &meshes, std::string_view const name)
Definition Mesh.cpp:363
std::unique_ptr< ParameterBase > createRasterParameter(std::string const &name, BaseLib::ConfigTree const &config, std::vector< GeoLib::NamedRaster > const &named_rasters)
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)
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 > createFunctionParameter(std::string const &name, BaseLib::ConfigTree const &config, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)
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(), createRasterParameter(), createTimeDependentHeterogeneousParameter(), MeshLib::findMeshByName(), BaseLib::ConfigTree::getConfigParameter(), INFO(), 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 22 of file RandomFieldMeshElementParameter.cpp.

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

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

Referenced by createParameter().

◆ createRasterParameter()

std::unique_ptr< ParameterBase > ParameterLib::createRasterParameter ( std::string const & name,
BaseLib::ConfigTree const & config,
std::vector< GeoLib::NamedRaster > const & named_rasters )
Input File Parameter
prj__parameters__parameter__type

Definition at line 19 of file RasterParameter.cpp.

22{
24 config.checkConfigParameter("type", "Raster");
25
26 auto const& named_raster = BaseLib::getIfOrError(
27 named_rasters,
28 [&name](auto const& named_raster)
29 { return name == named_raster.raster_name; },
30 "Could not find raster '" + name);
31
32 DBUG("Using the raster '{}' for the raster parameter.", name);
33
34 return std::make_unique<RasterParameter>(name, named_raster);
35}
Container::value_type const & getIfOrError(Container const &container, Predicate &&predicate, std::string const &error_message)
Definition Algorithm.h:158

References BaseLib::ConfigTree::checkConfigParameter(), DBUG(), and BaseLib::getIfOrError().

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 113 of file TimeDependentHeterogeneousParameter.cpp.

115{
117 config.checkConfigParameter("type", "TimeDependentHeterogeneousParameter");
118 auto const time_series_config =
120 config.getConfigSubtree("time_series");
121
122 std::vector<TimeDependentHeterogeneousParameter::PairTimeParameterName>
123 time_series;
125 for (auto const p : time_series_config.getConfigSubtreeList("pair"))
126 {
128 auto time = p.getConfigParameter<double>("time");
129 auto parameter_name =
131 p.getConfigParameter<std::string>("parameter_name");
132 time_series.emplace_back(time, parameter_name);
133 }
134
135 if (time_series.empty())
136 {
137 OGS_FATAL(
138 "Time dependent heterogeneous parameter '{:s}' doesn't contain "
139 "necessary time series data.",
140 name);
141 }
142
143 if (!std::is_sorted(
144 time_series.begin(), time_series.end(),
145 [](TimeDependentHeterogeneousParameter::PairTimeParameterName const&
146 p0,
147 TimeDependentHeterogeneousParameter::PairTimeParameterName const&
148 p1) { return p0.first < p1.first; }))
149 {
150 OGS_FATAL(
151 "The points in time in the time series '{:s}' aren't in ascending "
152 "order.",
153 name);
154 }
155
156 return std::make_unique<TimeDependentHeterogeneousParameter>(
157 name, std::move(time_series));
158}

References BaseLib::ConfigTree::checkConfigParameter(), BaseLib::ConfigTree::getConfigSubtree(), 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 162 of file Utils.h.

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

References BaseLib::ConfigTree::getConfigParameterOptional().

Referenced by ProcessLib::ComponentTransport::createComponentTransportProcess(), ProcessLib::LargeDeformation::createLargeDeformationProcess(), and 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 133 of file Utils.h.

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

References BaseLib::ConfigTree::getConfigParameter().

◆ 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 101 of file Utils.h.

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

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 {
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 {
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 return parameter;
87}
std::optional< std::string > isDefinedOnSameMesh(ParameterBase const &parameter, MeshLib::Mesh const &mesh)
Definition Parameter.cpp:99
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.

◆ getTransformationFromSingleBase2D()

Eigen::Matrix< double, 2, 2 > ParameterLib::getTransformationFromSingleBase2D ( Parameter< double > const & unit_direction,
SpatialPosition const & pos )

Definition at line 100 of file CoordinateSystem.cpp.

102{
103 Eigen::Matrix<double, 2, 2> t;
104#ifndef NDEBUG
105 if (std::abs(Eigen::Map<Eigen::Vector2d>(
106 unit_direction(0 /* time independent */, pos).data())
107 .norm() -
108 1) > tolerance)
109 {
110 OGS_FATAL(normalization_error_info, unit_direction.name);
111 }
112#endif // NDEBUG
113
114 auto normal = unit_direction(0 /* time independent */, pos);
115 // base 0: ( normal[1], -normal[0])^T
116 // base 1: ( normal[0], normal[1])^T
117 t << normal[1], normal[0], -normal[0], normal[1];
118
119#ifndef NDEBUG
120 if (std::abs(t.determinant() - 1) > tolerance)
121 {
122 OGS_FATAL(error_info, t.determinant(), tolerance);
123 }
124#endif // NDEBUG
125 return t;
126}
std::string const name
Definition Parameter.h:73

◆ getTransformationFromSingleBase3D()

Eigen::Matrix< double, 3, 3 > ParameterLib::getTransformationFromSingleBase3D ( Parameter< double > const & unit_direction,
SpatialPosition const & pos )

Definition at line 159 of file CoordinateSystem.cpp.

161{
162 auto e2 = unit_direction(0 /* time independent */, pos);
163#ifndef NDEBUG
164 if (std::abs(Eigen::Map<Eigen::Vector3d>(e2.data()).norm() - 1.0) >
165 tolerance)
166 {
167 OGS_FATAL(normalization_error_info, unit_direction.name);
168 }
169#endif
170
171 // Find the id of the first non-zero component of e2:
172 auto const it = std::max_element(e2.begin(), e2.end(),
173 [](const double a, const double b)
174 { return std::abs(a) < std::abs(b); });
175 const auto id = std::distance(e2.begin(), it);
176 // Get other two component ids:
177 const auto id_a = (id + 1) % 3;
178 const auto id_b = (id + 2) % 3;
179
180 // Compute basis vector e1 orthogonal to e2
181 using Vector3 = Eigen::Vector3d;
182 Vector3 e1(0.0, 0.0, 0.0);
183
184 if (std::abs(e2[id_a]) < tolerance)
185 {
186 e1[id_a] = 1.0;
187 }
188 else if (std::abs(e2[id_b]) < tolerance)
189 {
190 e1[id_b] = 1.0;
191 }
192 else
193 {
194 e1[id_a] = 1.0;
195 e1[id_b] = -e2[id_a] / e2[id_b];
196 }
197
198 e1.normalize();
199
200 auto eigen_mapped_e2 = Eigen::Map<Vector3>(e2.data());
201
202 auto e0 = e1.cross(eigen_mapped_e2);
203 // |e0| = |e1 x e2| = |e1||e2|sin(theta) with theta the angle between e1 and
204 // e2. Since |e1| = |e2| = 1.0, and theta = pi/2, we have |e0|=1. Therefore
205 // e0 is normalized by nature.
206
207 Eigen::Matrix<double, 3, 3> t;
208 t.col(0) = e0;
209 t.col(1) = e1;
210 t.col(2) = eigen_mapped_e2;
211
212#ifndef NDEBUG
213
214 if (std::abs(t.determinant() - 1) > tolerance)
215 {
216 OGS_FATAL(error_info, t.determinant(), tolerance);
217 }
218
219#endif // NDEBUG
220
221 return t;
222}

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

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

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

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

Referenced by findParameterOptional().

◆ parseBase1OrBase2()

Parameter< double > const * ParameterLib::parseBase1OrBase2 ( BaseLib::ConfigTree const & config,
std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const & parameters,
int const expected_component_number,
std::string_view const base_tag_name )

Definition at line 28 of file CreateCoordinateSystem.cpp.

33{
34 auto const base_parameter_name = config.getValue<std::string>();
35 auto const& basis_vector = ParameterLib::findParameter<double>(
36 base_parameter_name, parameters, 0 /* any dimension */);
37
38 int const component_number = basis_vector.getNumberOfGlobalComponents();
39 if (base_tag_name == "basis_vector_1" && component_number != 2)
40 {
42 "The case of implicit \"basis_vector_0\" and "
43 "explicit \"basis_vector_1\" is for a 2D coordinate system. The "
44 "parameter for \"basis_vector_1\", {:s}, must have "
45 "two components but it has {:d}. In addition, \"basis_vector_2\" "
46 "should not exist in this case.",
47 base_parameter_name, component_number);
48 }
49
50 if (component_number != expected_component_number)
51 {
53 "The read parameter `{:s}' for tag {:s} has the wrong number of "
54 "components ({:d} instead of {:d}).",
55 base_parameter_name, base_tag_name, component_number,
56 expected_component_number);
57 }
58
59 return &basis_vector;
60}

References BaseLib::ConfigTree::getValue(), and OGS_FATAL.

Referenced by createCoordinateSystem(), and createCoordinateSystemWithImplicitBase().

Variable Documentation

◆ error_info

constexpr char ParameterLib::error_info[]
staticconstexpr
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 26 of file CoordinateSystem.cpp.

Referenced by ParameterLib::CoordinateSystem::transformation(), and ParameterLib::CoordinateSystem::transformation_3d().

◆ normalization_error_info

constexpr char ParameterLib::normalization_error_info[]
staticconstexpr
Initial value:
=
"The direction vector given by parameter {:s} for local_coordinate_system "
"is not normalized to unit length"

Definition at line 31 of file CoordinateSystem.cpp.

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

◆ tolerance

double const ParameterLib::tolerance = std::numeric_limits<double>::epsilon()
static