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)
template<int Dim>
static void checkTransformationIsSON (Eigen::Matrix< double, Dim, Dim, Eigen::ColMajor, Dim, Dim > const &t)
template<typename Derived>
static void checkNormalization (Eigen::MatrixBase< Derived > const &vec, std::string_view const parmeter_name)
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)
Parameter< double > & getNamedOrCreateInlineParameter (BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< ParameterBase > > &parameters, std::string const &property_name, std::string const &tag_name, std::string const &inline_suffix)
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>
OGS_NO_DANGLING 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>
OGS_NO_DANGLING 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()

Function Documentation

◆ checkNormalization()

template<typename Derived>
void ParameterLib::checkNormalization ( Eigen::MatrixBase< Derived > const & vec,
std::string_view const parmeter_name )
static

Definition at line 48 of file ParameterLib/CoordinateSystem.cpp.

50{
51 if (std::abs(vec.squaredNorm() - 1.0) > tolerance)
52 {
54 "The direction vector given by parameter {:s} for the "
55 "local_coordinate_system is not normalized to unit length. Vector "
56 "norm is {:g} and |v|^2-1 = {:g}.",
57 parmeter_name, vec.norm(), vec.squaredNorm() - 1.0);
58 }
59}
#define OGS_FATAL(...)
Definition Error.h:19
static double const tolerance

References OGS_FATAL, and tolerance.

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

◆ checkThirdBaseExistanceFor2D()

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

Definition at line 54 of file CreateCoordinateSystem.cpp.

55{
56 auto const base2_config =
58 config.getConfigSubtreeOptional("basis_vector_2");
59 if (base2_config)
60 {
62 "The tag \"basis_vector_2\" is not needed for a 2D local "
63 "coordinate system.");
64 }
65}

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

Referenced by createCoordinateSystem(), and createCoordinateSystemWithImplicitBase().

◆ checkTransformationIsSON()

template<int Dim>
void ParameterLib::checkTransformationIsSON ( Eigen::Matrix< double, Dim, Dim, Eigen::ColMajor, Dim, Dim > const & t)
static

Definition at line 21 of file ParameterLib/CoordinateSystem.cpp.

23{
24 if (std::abs(t.determinant() - 1) > tolerance)
25 {
27 "The determinant of the coordinate system transformation matrix is "
28 "'{:g}', which is not sufficiently close to unity with the "
29 "tolerance of '{:g}'. Please adjust the accuracy of the local "
30 "system bases",
31 t.determinant(), tolerance);
32 }
33 if (((t * t.transpose() - Eigen::Matrix<double, Dim, Dim>::Identity())
34 .array() > 2 * tolerance)
35 .any())
36 {
38 "The transformation is not orthogonal because the difference "
39 "A*A^T - I is:\n{}\nand at least one component deviates from zero "
40 "by more then '{:g}'.",
41 (t * t.transpose() - Eigen::Matrix<double, Dim, Dim>::Identity())
42 .eval(),
43 2 * tolerance);
44 }
45}

References OGS_FATAL, and tolerance.

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

◆ confirmThirdBaseExplicit()

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

Definition at line 67 of file CreateCoordinateSystem.cpp.

68{
69 auto const implicit_base2 =
71 config.getConfigAttribute<bool>("implicit", false);
72 if (implicit_base2)
73 {
74 OGS_FATAL("basis_vector_2 must be explicit.");
75 }
76}

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

14{
16 config.checkConfigParameter("type", "Constant");
17
18 auto const value_data =
20 config.getConfigParameterOptional<std::vector<double>>("value");
21
22 auto const values_data =
24 config.getConfigParameterOptional<std::vector<double>>("values");
25
26 if ((value_data) && (values_data))
27 {
29 "Both value and values tags were given.\n\
30 Please give only one of them.");
31 }
32
33 std::vector<double> values;
34
35 if (value_data)
36 {
37 values = *value_data;
38 }
39 else if (values_data)
40 {
41 values = *values_data;
42 }
43
44 if (values.empty())
45 {
46 OGS_FATAL("No value(s) was(were) provided.");
47 }
48
49 DBUG("Using following values for the constant parameter:");
50 for (double const v : values)
51 {
52 (void)v; // unused value if building w/o DBUG output.
53 DBUG("\t{:g}", v);
54 }
55
56 return std::make_unique<ConstantParameter<double>>(name, std::move(values));
57}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22

References BaseLib::ConfigTree::checkConfigParameter(), DBUG(), 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 134 of file CreateCoordinateSystem.cpp.

137{
138 if (!config)
139 {
140 return {};
141 }
142
143 //
144 // Fetch the first basis vector; its length defines the dimension.
145 //
147 auto const& config_base0 = config->getConfigSubtree("basis_vector_0");
148 auto const implicit_base0 =
150 config_base0.getConfigAttribute<bool>("implicit", false);
151
152 // base0 and base1 can be implicit. If base0 is implicit, check whether
153 // base1 is implicit.
154 // If base1 is explicit, create a 2D system if its components is 2 or quit
155 // if its components is not equal to 2.
156 // Otherwise, read base2, create a 3D system if its components is 3 or quit
157 // if its components is not equal to 3.
158 if (implicit_base0)
159 {
160 return createCoordinateSystemWithImplicitBase(*config, parameters);
161 }
162
163 auto const base0_name = config_base0.getValue<std::string>();
164 auto const& basis_vector_0 = ParameterLib::findParameter<double>(
165 base0_name, parameters, 0 /* any dimension */);
166 int const dimension = basis_vector_0.getNumberOfGlobalComponents();
167 // check dimension
168 if (dimension != 2 && dimension != 3)
169 {
170 OGS_FATAL(
171 "Basis vector parameter '{:s}' must have two or three components, "
172 "but it has {:d}.",
173 base0_name, dimension);
174 }
175
176 // Fetch the second basis vector.
178 auto const& config_base1 = config->getConfigSubtree("basis_vector_1");
179 auto const implicit_base1 =
181 config_base1.getConfigAttribute<bool>("implicit", false);
182 if (implicit_base1)
183 {
184 OGS_FATAL(
185 "Since basis_vector_0 is explicitly defined, basis_vector_1"
186 " must be explicit as well.");
187 }
188 auto const base1_name = config_base1.getValue<std::string>();
189 auto const& basis_vector_1 =
190 ParameterLib::findParameter<double>(base1_name, parameters, dimension);
191
192 if (dimension == 2)
193 {
195 return ParameterLib::CoordinateSystem{basis_vector_0, basis_vector_1};
196 }
197
198 // Parse the third basis vector, e2, for the three dimensional system.
200 auto const& config_base2 = config->getConfigSubtree("basis_vector_2");
201 confirmThirdBaseExplicit(config_base2);
202
203 int const expected_component_number = 3;
204 auto const basis_vector_2 = parseBase1OrBase2(
205 config_base2, parameters, expected_component_number, "basis_vector_2");
206
207 return ParameterLib::CoordinateSystem{basis_vector_0, basis_vector_1,
208 *basis_vector_2};
209}
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)
OGS_NO_DANGLING 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)
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)

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

◆ 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 79 of file CreateCoordinateSystem.cpp.

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

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

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

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 10 of file FunctionParameter.cpp.

15{
17 config.checkConfigParameter("type", "Function");
18
19 std::vector<std::string> vec_expressions;
20
22 for (auto const& p : config.getConfigSubtreeList("expression"))
23 {
24 std::string const expression_str = p.getValue<std::string>();
25 vec_expressions.emplace_back(expression_str);
26 }
27
28 return std::make_unique<FunctionParameter<double>>(name, vec_expressions,
29 curves);
30}

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 12 of file GroupBasedParameter.cpp.

15{
17 config.checkConfigParameter("type", "Group");
18
19 // get a property vector of group IDs
20 std::string const group_id_property_name =
22 config.getConfigParameter<std::string>("group_id_property");
23 DBUG("Using group_id_property {:s}", group_id_property_name);
24
25 auto const& group_id_property =
26 mesh.getProperties().getPropertyVector<int>(group_id_property_name);
27
28 // parse mapping data
29 using Values = std::vector<double>;
30 std::map<int, Values> vec_index_values;
32 for (auto p : config.getConfigSubtreeList("index_values"))
33 {
35 auto const index = p.getConfigParameter<int>("index");
36 {
38 auto const value = p.getConfigParameterOptional<double>("value");
39
40 if (value)
41 {
42 Values values(1, *value);
43 vec_index_values.emplace(index, values);
44 continue;
45 }
46 }
47
48 // Value tag not available; continue with required values tag.
50 Values const values = p.getConfigParameter<Values>("values");
51
52 if (values.empty())
53 {
54 OGS_FATAL("No value available for constant parameter.");
55 }
56
57 vec_index_values.emplace(index, values);
58 }
59
60 // check the input
61 for (auto p : vec_index_values)
62 {
63#ifndef USE_PETSC // In case of partitioned meshes not all of the material ids
64 // might be available in the particular partition, therefore
65 // the check is omitted.
66 if (std::find(group_id_property->begin(), group_id_property->end(),
67 p.first) == group_id_property->end())
68 {
70 "Specified property index {:d} does not exist in the property "
71 "vector {:s}",
72 p.first, group_id_property_name);
73 }
74#endif
75
76 auto const n_values = vec_index_values.begin()->second.size();
77 if (p.second.size() != n_values)
78 {
80 "The length of some values ({:d}) is different from the first "
81 "one ({:d}). The length should be same for all index_values.",
82 p.second.size(), n_values);
83 }
84 }
85
86 if (group_id_property->getMeshItemType() == MeshLib::MeshItemType::Node)
87 {
88 return std::make_unique<
90 name, mesh, *group_id_property, vec_index_values);
91 }
92 if (group_id_property->getMeshItemType() == MeshLib::MeshItemType::Cell)
93 {
94 return std::make_unique<
96 name, mesh, *group_id_property, vec_index_values);
97 }
98
99 OGS_FATAL("Mesh item type of the specified property is not supported.");
100}

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

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

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

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

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 20 of file ParameterLib/Parameter.cpp.

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

Definition at line 15 of file RandomFieldMeshElementParameter.cpp.

18{
20 config.checkConfigParameter("type", "RandomFieldMeshElement");
21 auto const field_name =
23 config.getConfigParameter<std::string>("field_name");
24 auto const range =
26 config.getConfigParameter<std::vector<double>>("range");
27 if (range.size() != 2)
28 {
30 "The range needs to have two components, but {:d} were given.",
31 range.size());
32 }
33 auto const seed =
35 config.getConfigParameter<int>("seed");
36 DBUG("Generating field {:s} with range {:g} to {:g} and seed {:d}.",
37 field_name, range[0], range[1], seed);
38
39 std::vector<double> values(mesh.getElements().size());
40
41 std::mt19937 generator(seed);
42 std::uniform_real_distribution<> distr(range[0], range[1]);
43 auto gen = [&distr, &generator]() { return distr(generator); };
44 generate(begin(values), end(values), gen);
45
47 mesh, field_name, MeshLib::MeshItemType::Cell, 1, {values});
48
49 auto const& property =
50 mesh.getProperties().getPropertyVector<double>(field_name);
51
52 if (property->getMeshItemType() != MeshLib::MeshItemType::Cell)
53 {
54 OGS_FATAL("The mesh property `{:s}' is not an element property.",
55 field_name);
56 }
57
58 return std::make_unique<RandomFieldMeshElementParameter<double>>(name, mesh,
59 *property);
60}
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:100
Properties & getProperties()
Definition Mesh.h:125
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::span< 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 12 of file RasterParameter.cpp.

15{
17 config.checkConfigParameter("type", "Raster");
18
19 auto const& named_raster = BaseLib::getIfOrError(
20 named_rasters,
21 [&name](auto const& named_raster)
22 { return name == named_raster.raster_name; },
23 "Could not find raster '" + name);
24
25 DBUG("Using the raster '{}' for the raster parameter.", name);
26
27 return std::make_unique<RasterParameter>(name, named_raster);
28}
OGS_NO_DANGLING Container::value_type const & getIfOrError(Container const &container, Predicate &&predicate, std::string const &error_message)
Definition Algorithm.h:156

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__TimeDependentHeterogeneous__time_series
Input File Parameter
prj__parameters__parameter__TimeDependentHeterogeneous__time_series__pair
Input File Parameter
prj__parameters__parameter__TimeDependentHeterogeneous__time_series__pair__time
Input File Parameter
prj__parameters__parameter__TimeDependentHeterogeneous__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(),
139 p0,
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(), 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 159 of file ParameterLib/Utils.h.

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

References findParameter(), and BaseLib::ConfigTree::getConfigParameterOptional().

Referenced by ProcessLib::ComponentTransport::createComponentTransportProcess(), ProcessLib::LargeDeformation::createLargeDeformationProcess(), ProcessLib::SmallDeformation::createSmallDeformationProcess(), and ProcessLib::ThermoMechanics::createThermoMechanicsProcess().

◆ findParameter() [1/2]

template<typename ParameterDataType>
OGS_NO_DANGLING 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 128 of file ParameterLib/Utils.h.

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

References findParameter(), BaseLib::ConfigTree::getConfigParameter(), and OGS_NO_DANGLING.

◆ findParameter() [2/2]

template<typename ParameterDataType>
OGS_NO_DANGLING 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 95 of file ParameterLib/Utils.h.

100{
102 parameter_name, parameters, num_components, mesh);
103
104 if (!parameter)
105 {
106 OGS_FATAL(
107 "Could not find parameter `{:s}' in the provided parameters list.",
108 parameter_name);
109 }
110 return *parameter;
111}
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)

References findParameterOptional(), OGS_FATAL, and OGS_NO_DANGLING.

Referenced by ProcessLib::createAnchorTerm(), ProcessLib::ProcessVariable::createBoundaryConditionsForDeactivatedSubDomains(), MaterialLib::Fracture::CohesiveZoneModeI::createCohesiveZoneModeI(), ProcessLib::ComponentTransport::createComponentTransportProcess(), ProcessLib::createConstraintDirichletBoundaryCondition(), createCoordinateSystem(), MaterialLib::Fracture::createCoulomb(), MaterialLib::Solids::Creep::createCreepBGRa(), MaterialPropertyLib::createCubicLawPermeability(), MaterialLib::Solids::Ehlers::createDamageProperties(), ProcessLib::createDeactivatedSubdomain(), ProcessLib::createDirichletBoundaryCondition(), ProcessLib::createDirichletBoundaryConditionWithinTimeInterval(), MaterialPropertyLib::createDupuitPermeability(), MaterialLib::Solids::Ehlers::createEhlers(), MaterialPropertyLib::createEmbeddedFracturePermeability(), MaterialPropertyLib::createGasPressureDependentPermeability(), ProcessLib::createHCNonAdvectiveFreeComponentFlowBoundaryCondition(), ProcessLib::HMPhaseField::createHMPhaseFieldProcess(), ProcessLib::HT::createHTProcess(), ProcessLib::LIE::HydroMechanics::createHydroMechanicsProcess(), ProcessLib::createInitialStress(), MaterialPropertyLib::createKozenyCarmanModel(), MaterialLib::Fracture::createLinearElasticIsotropic(), MaterialLib::Solids::createLinearElasticIsotropic(), MaterialLib::Solids::createLinearElasticIsotropicSoftening(), MaterialLib::Solids::createLinearElasticOrthotropic(), MaterialLib::Solids::createLinearElasticTransverseIsotropic(), ProcessLib::LiquidFlow::createLiquidFlowProcess(), MaterialLib::Solids::Lubby2::createLubby2(), ProcessLib::createNeumannBoundaryCondition(), ProcessLib::createNodalSourceTerm(), ProcessLib::NormalTractionBoundaryCondition::createNormalTractionBoundaryCondition(), MaterialPropertyLib::createOrthotropicEmbeddedFracturePermeability(), MaterialPropertyLib::createParameterProperty(), MaterialPropertyLib::createPermeabilityMohrCoulombFailureIndexModel(), ProcessLib::PhaseField::createPhaseFieldProcess(), MaterialPropertyLib::createPorosityFromMassBalance(), ProcessLib::createPrimaryVariableConstraintDirichletBoundaryCondition(), ProcessLib::createReleaseNodalForce(), ProcessLib::WellboreSimulator::createReservoirProperties(), ProcessLib::createRobinBoundaryCondition(), ProcessLib::LIE::SmallDeformation::createSmallDeformationProcess(), ProcessLib::createSolutionDependentDirichletBoundaryCondition(), MaterialPropertyLib::createStrainDependentPermeability(), MaterialPropertyLib::createTemperatureDependentDiffusion(), ProcessLib::TH2M::createTH2MProcess(), ProcessLib::createTimeDecayDirichletBoundaryCondition(), MaterialPropertyLib::createTransportPorosityFromMassBalance(), ProcessLib::TwoPhaseFlowWithPP::createTwoPhaseFlowWithPPProcess(), ProcessLib::createVariableDependentNeumannBoundaryCondition(), MaterialPropertyLib::createVermaPruessModel(), ProcessLib::createVolumetricSourceTerm(), ProcessLib::WellboreSimulator::createWellboreGeometry(), ProcessLib::WellboreSimulator::createWellboreSimulatorProcess(), findOptionalTagParameter(), findParameter(), getNamedOrCreateInlineParameter(), ParameterLib::CurveScaledParameter< T >::initialize(), ParameterLib::TimeDependentHeterogeneousParameter::initialize(), parseBase1OrBase2(), anonymous_namespace{CreateMFrontGeneric.cpp}::readMaterialProperties(), and anonymous_namespace{CreateMFrontGeneric.cpp}::readStateVariablesInitialValueProperties().

◆ 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 8 of file ParameterLib/Utils.cpp.

11{
12 // Find corresponding parameter by name.
13 auto const it =
14 std::find_if(parameters.cbegin(), parameters.cend(),
15 [&parameter_name](std::unique_ptr<ParameterBase> const& p)
16 { return p->name == parameter_name; });
17
18 if (it == parameters.end())
19 {
20 return nullptr;
21 }
22
23 DBUG("Found parameter `{:s}'.", (*it)->name);
24 return it->get();
25}

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 36 of file ParameterLib/Utils.h.

40{
41 // Find corresponding parameter by name.
42 ParameterBase* parameter_ptr =
43 findParameterByName(parameter_name, parameters);
44 if (parameter_ptr == nullptr)
45 {
46 return nullptr;
47 }
48
49 // Check the type correctness of the found parameter.
50 auto* const parameter =
51 dynamic_cast<Parameter<ParameterDataType>*>(parameter_ptr);
52 if (!parameter)
53 {
54 OGS_FATAL("The read parameter `{:s}' is of incompatible type.",
55 parameter_name);
56 }
57
58 if (num_components != 0 &&
59 parameter->getNumberOfGlobalComponents() != num_components)
60 {
62 "The read parameter `{:s}' has the wrong number of components "
63 "({:d} instead of {:d}).",
64 parameter_name, parameter->getNumberOfGlobalComponents(),
65 num_components);
66 }
67
68 // Test the parameter's mesh only if there is a "test"-mesh provided.
69 if (mesh != nullptr)
70 {
71 if (auto const error = isDefinedOnSameMesh(*parameter, *mesh))
72 {
74 "The found parameter is not suitable for the use on the "
75 "required mesh.\n{:s}",
76 error->c_str());
77 }
78 }
79
80 return parameter;
81}
std::optional< std::string > isDefinedOnSameMesh(ParameterBase const &parameter, MeshLib::Mesh const &mesh)
ParameterBase * findParameterByName(std::string const &parameter_name, std::vector< std::unique_ptr< ParameterBase > > const &parameters)

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

Referenced by findParameter().

◆ getNamedOrCreateInlineParameter()

Parameter< double > & ParameterLib::getNamedOrCreateInlineParameter ( BaseLib::ConfigTree const & config,
std::vector< std::unique_ptr< ParameterBase > > & parameters,
std::string const & property_name,
std::string const & tag_name,
std::string const & inline_suffix )

Returns a Parameter<double>& based on the value of the given config tag.

If the config entry <tag_name> is a double, creates a ConstantParameter with that value, adds it to parameters, and returns it.

If the entry is a string, interprets it as the name of an existing parameter and returns a reference to that parameter.

Parameters
configThe configuration tree to read from.
parametersThe parameter storage vector (will be modified if an inline constant is created).
property_nameName of the property (used for auto-generated parameter names in the inline case).
tag_nameXML/ConfigTree tag name to read.
inline_suffixSuffix for auto-generated parameter names.
Input File Parameter
special OGS input file parameter

Definition at line 117 of file ParameterLib/Parameter.cpp.

123{
125 std::string const raw = config.getConfigParameter<std::string>(tag_name);
126
127 // try to parse number(s) (if empty - no inline-values)
128 std::size_t bad_idx = 0;
129 if (auto values = BaseLib::tryParseVector<double>(raw, &bad_idx); values)
130 {
131 if (values->empty())
132 {
133 OGS_FATAL(
134 "Empty inline value list in <{:s}> for property '{:s}'. "
135 "Provide at least one numeric value (e.g., \"1.23 4.56\") or "
136 "specify the name of an existing parameter. "
137 "Raw input was: \"{:s}\".",
138 tag_name, property_name, raw);
139 }
140
141 // collect all existing parameter names for checks against uniqueness
142 std::vector<std::string> existing_names;
143 existing_names.reserve(parameters.size());
144 std::transform(parameters.begin(), parameters.end(),
145 std::back_inserter(existing_names),
146 [](auto const& p) { return p->name; });
147
148 // assign inline values as constant parameter
149 std::string pname = BaseLib::getUniqueName(
150 existing_names, property_name + "_" + inline_suffix);
151 using P = ConstantParameter<double>;
152 parameters.push_back(std::make_unique<P>(pname, std::move(*values)));
153 return static_cast<Parameter<double>&>(*parameters.back());
154 }
155
156 // No inline values -> 'raw' is just a parameter name, now find that
157 // parameter.
158 return findParameter<double>(raw, parameters, 0, nullptr);
159}
std::optional< std::vector< T > > tryParseVector(std::string const &raw, std::size_t *bad_token_idx)
Definition StringTools.h:85
std::string getUniqueName(std::vector< std::string > const &existing_names, std::string const &input_name)
Append '-' and a number such that the name is unique.

References findParameter(), BaseLib::ConfigTree::getConfigParameter(), BaseLib::getUniqueName(), OGS_FATAL, and BaseLib::tryParseVector().

Referenced by MaterialPropertyLib::createSaturationWeightedThermalConductivity().

◆ getTransformationFromSingleBase2D()

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

Definition at line 125 of file ParameterLib/CoordinateSystem.cpp.

127{
128 auto const& normal = unit_direction(0 /* time independent */, pos);
129 checkNormalization(Eigen::Map<Eigen::Vector2d const>(normal.data()),
130 unit_direction.name);
131
132 Eigen::Matrix<double, 2, 2> t;
133 // base 0: ( normal[1], -normal[0])^T
134 // base 1: ( normal[0], normal[1])^T
135 t << normal[1], normal[0], -normal[0], normal[1];
136
138 return t;
139}
static void checkNormalization(Eigen::MatrixBase< Derived > const &vec, std::string_view const parmeter_name)
static void checkTransformationIsSON(Eigen::Matrix< double, Dim, Dim, Eigen::ColMajor, Dim, Dim > const &t)

◆ getTransformationFromSingleBase3D()

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

Definition at line 167 of file ParameterLib/CoordinateSystem.cpp.

169{
170 auto const& normal = unit_direction(0 /* time independent */, pos);
171
172 Eigen::Matrix<double, 3, 3> t;
173 auto e2 = t.col(2);
174 e2 = Eigen::Map<Eigen::Vector3d const>(normal.data());
175 checkNormalization(e2, unit_direction.name);
176
177 // Find the id of the first non-zero component of e2:
178 int id;
179 e2.cwiseAbs().maxCoeff(&id);
180
181 // Get other two component ids:
182 const auto id_a = (id + 1) % 3;
183 const auto id_b = (id + 2) % 3;
184
185 // Compute basis vector e1 orthogonal to e2
186 auto e1 = t.col(1);
187 e1 = Eigen::Vector3d::Zero();
188
189 if (std::abs(e2[id_a]) < tolerance)
190 {
191 e1[id_a] = 1.0;
192 }
193 else if (std::abs(e2[id_b]) < tolerance)
194 {
195 e1[id_b] = 1.0;
196 }
197 else
198 {
199 e1[id_a] = 1.0;
200 e1[id_b] = -e2[id_a] / e2[id_b];
201 }
202
203 e1.normalize();
204
205 // |e0| = |e1 x e2| = |e1||e2|sin(theta) with theta the angle between e1 and
206 // e2. Since |e1| = |e2| = 1.0, and theta = pi/2, we have |e0|=1. Therefore
207 // e0 is normalized by nature.
208 t.col(0) = e1.cross(e2);
209
211
212 return t;
213}

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 92 of file ParameterLib/Parameter.cpp.

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

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 20 of file CreateCoordinateSystem.cpp.

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

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

Referenced by createCoordinateSystem(), and createCoordinateSystemWithImplicitBase().

Variable Documentation

◆ tolerance

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