OGS
ParameterLib Namespace Reference

Classes

struct  ConstantParameter
 Single, constant value parameter. More...
struct  CoordinateSystem
 A local coordinate system used for tensor transformations. More...
struct  CurveScaledParameter
struct  CurveWrapper
class  FunctionEvaluation
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
struct  SymbolTableCache
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)
bool isBuiltinSymbol (std::string_view const name)
bool hasSpatialVariables (std::vector< std::string > const &variables)
exprtk::symbol_table< double > createBaseSymbolTable (bool spatial_position_is_required)
void registerCurveWrappers (exprtk::symbol_table< double > &symbol_table, std::vector< std::string > const &curve_names, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves, std::map< std::string, CurveWrapper > &curve_wrappers)
template std::vector< exprtk::expression< double > > compileExpressions< double > (exprtk::symbol_table< double > &, std::vector< std::string > const &)
std::vector< std::string > collectVariables (std::vector< std::string > const &expression_strings)
std::vector< std::string > collectUsedCurveNames (std::vector< std::string > const &expression_symbol_names, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)
 Returns the subset of expression_symbol_names that are keys in curves.
template<typename T>
std::vector< exprtk::expression< T > > compileExpressions (exprtk::symbol_table< T > &symbol_table, std::vector< std::string > const &string_expressions)
static FunctionEvaluation::SymbolTable createSymbolTable (std::vector< std::string > const &variables, bool const spatial_position_is_required, std::vector< std::string > const &used_curve_names, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves, std::map< std::string, CurveWrapper > &curve_wrappers)
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 (std::string const &parameter_or_value, std::vector< std::unique_ptr< ParameterBase > > &parameters, std::string const &property_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::ostream & operator<< (std::ostream &os, SpatialPosition const &pos)
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:10
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().

◆ collectUsedCurveNames()

std::vector< std::string > ParameterLib::collectUsedCurveNames ( std::vector< std::string > const & expression_symbol_names,
std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const & curves )

Returns the subset of expression_symbol_names that are keys in curves.

Definition at line 153 of file ExprtkUtils.cpp.

158{
159 std::vector<std::string> used;
160 for (auto const& v : expression_symbol_names)
161 {
162 if (curves.contains(v))
163 {
164 used.push_back(v);
165 }
166 }
167 return used;
168}

Referenced by ParameterLib::FunctionEvaluation::FunctionEvaluation(), and MaterialPropertyLib::Function::Implementation< D >::Implementation().

◆ collectVariables()

std::vector< std::string > ParameterLib::collectVariables ( std::vector< std::string > const & expression_strings)

Collects and deduplicates all variable/function identifiers appearing in the given expression strings by calling exprtk::collect_variables on each.

Definition at line 126 of file ExprtkUtils.cpp.

128{
129 std::vector<std::string> expression_symbol_names;
130 for (auto const& expr : expression_strings)
131 {
132 if (!exprtk::collect_variables(expr, expression_symbol_names))
133 {
134 OGS_FATAL("Collecting variables from expression '{}' didn't work.",
135 expr);
136 }
137 }
138 BaseLib::makeVectorUnique(expression_symbol_names);
139
140 // exprtk::collect_variables reports the named constants added by
141 // add_constants() (pi, epsilon, inf) as variables. Drop them so that
142 // downstream code does not try to (re)create them as variables and clash
143 // with the constants. A base symbol table is used so the set of constants
144 // is queried from exprtk itself rather than hard-coded.
145 auto const constants = createBaseSymbolTable(false);
146 std::erase_if(expression_symbol_names,
147 [&constants](std::string const& name)
148 { return constants.is_constant_node(name); });
149
150 return expression_symbol_names;
151}
void makeVectorUnique(std::vector< T > &v)
Definition Algorithm.h:198
exprtk::symbol_table< double > createBaseSymbolTable(bool spatial_position_is_required)

References createBaseSymbolTable(), BaseLib::makeVectorUnique(), and OGS_FATAL.

Referenced by MaterialPropertyLib::Function::Function(), and ParameterLib::FunctionEvaluation::FunctionEvaluation().

◆ compileExpressions()

template<typename T>
std::vector< exprtk::expression< T > > ParameterLib::compileExpressions ( exprtk::symbol_table< T > & symbol_table,
std::vector< std::string > const & string_expressions )

Compiles expression strings into exprtk expressions using the given symbol table. Assignment (:=, +=, ...) to user-defined local vars is allowed, but assignment to a symbol that is already registered in symbol_table (the built-in t/x/y/z, MPL variables, curves or constants) is rejected: such a write would corrupt the shared per-thread evaluation scratch. This is enforced by enabling exprtk's dependent-entity collector and checking, after each compile, whether any assignment target resolves to a registered symbol (local var assignments are not reported by the collector).

Definition at line 74 of file ExprtkUtils.h.

77{
78 using settings_t = typename exprtk::parser<T>::settings_store;
79 exprtk::parser<T> parser(settings_t::default_compile_all_opts +
80 settings_t::e_collect_assings);
81
82 std::vector<exprtk::expression<T>> expressions(string_expressions.size());
83 for (unsigned i = 0; i < string_expressions.size(); ++i)
84 {
85 expressions[i].register_symbol_table(symbol_table);
86 if (!parser.compile(string_expressions[i], expressions[i]))
87 {
88 OGS_FATAL("Error: {:s}\tExpression: {:s}\n", parser.error(),
89 string_expressions[i]);
90 }
91
92 std::vector<
93 typename exprtk::parser<T>::dependent_entity_collector::symbol_t>
94 assignments;
95 parser.dec().assignment_symbols(assignments);
96 if (!assignments.empty())
97 {
98 std::string names;
99 for (auto const& [name, type] : assignments)
100 {
101 if (!names.empty())
102 {
103 names += ", ";
104 }
105 names += name;
106 }
107 OGS_FATAL(
108 "Expression '{:s}' assigns to the already-defined symbol(s) "
109 "'{:s}'. Assignment to the built-in variables (t, x, y, z), to "
110 "MPL variables, curves or constants is not allowed because it "
111 "would corrupt the shared evaluation state. Assignment to "
112 "user-defined local 'var's is permitted.",
113 string_expressions[i], names);
114 }
115 }
116 return expressions;
117}
constexpr ranges::views::view_closure names
For an element of a range view return its name.
Definition Mesh.h:227

References OGS_FATAL.

Referenced by ParameterLib::FunctionEvaluation::PerThreadData::PerThreadData(), and MaterialPropertyLib::PerThreadData::compileExpressions().

◆ compileExpressions< double >()

template std::vector< exprtk::expression< double > > ParameterLib::compileExpressions< double > ( exprtk::symbol_table< double > & ,
std::vector< std::string > const &  )

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

◆ createBaseSymbolTable()

exprtk::symbol_table< double > ParameterLib::createBaseSymbolTable ( bool spatial_position_is_required)

Creates a symbol table with time variable ("t") and optionally spatial variables ("x", "y", "z"). Does not add any other variables or curves.

Definition at line 51 of file ExprtkUtils.cpp.

53{
54 exprtk::symbol_table<double> symbol_table;
55 symbol_table.add_constants();
56 symbol_table.create_variable("t");
57 if (spatial_position_is_required)
58 {
59 symbol_table.create_variable("x");
60 symbol_table.create_variable("y");
61 symbol_table.create_variable("z");
62 }
63 return symbol_table;
64}

Referenced by collectVariables(), MaterialPropertyLib::createSymbolTable(), and createSymbolTable().

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

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

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:101
Properties & getProperties()
Definition Mesh.h:127
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:157

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

Referenced by createParameter().

◆ createSymbolTable()

FunctionEvaluation::SymbolTable ParameterLib::createSymbolTable ( std::vector< std::string > const & variables,
bool const spatial_position_is_required,
std::vector< std::string > const & used_curve_names,
std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const & curves,
std::map< std::string, CurveWrapper > & curve_wrappers )
static

Definition at line 41 of file FunctionEvaluation.cpp.

49{
50 auto symbol_table = createBaseSymbolTable(spatial_position_is_required);
51
52 // Create additional (non-standard) variables.
53 for (auto const& v : variables)
54 {
55 if (!isBuiltinSymbol(v))
56 {
57 symbol_table.create_variable(v);
58 }
59 }
60
61 registerCurveWrappers(symbol_table, used_curve_names, curves,
62 curve_wrappers);
63
64 return symbol_table;
65}
bool isBuiltinSymbol(std::string_view const name)
void registerCurveWrappers(exprtk::symbol_table< double > &symbol_table, std::vector< std::string > const &curve_names, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves, std::map< std::string, CurveWrapper > &curve_wrappers)

References createBaseSymbolTable(), isBuiltinSymbol(), and registerCurveWrappers().

Referenced by ParameterLib::FunctionEvaluation::PerThreadData::PerThreadData().

◆ 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 auto const type = config.getConfigParameter<std::string>("type");
111 if (type != "TimeDependentHeterogeneous" &&
112 type != "TimeDependentHeterogeneousParameter")
113 {
114 OGS_FATAL(
115 "Expected the parameter type 'TimeDependentHeterogeneous' (or its "
116 "deprecated spelling 'TimeDependentHeterogeneousParameter'), but "
117 "got '{:s}'.",
118 type);
119 }
120 auto const time_series_config =
122 config.getConfigSubtree("time_series");
123
124 std::vector<TimeDependentHeterogeneousParameter::PairTimeParameterName>
125 time_series;
127 for (auto const p : time_series_config.getConfigSubtreeList("pair"))
128 {
130 auto time = p.getConfigParameter<double>("time");
131 auto parameter_name =
133 p.getConfigParameter<std::string>("parameter_name");
134 time_series.emplace_back(time, parameter_name);
135 }
136
137 if (time_series.empty())
138 {
139 OGS_FATAL(
140 "Time dependent heterogeneous parameter '{:s}' doesn't contain "
141 "necessary time series data.",
142 name);
143 }
144
145 if (!std::is_sorted(
146 time_series.begin(), time_series.end(),
148 & p0,
150 & p1) { return p0.first < p1.first; }))
151 {
152 OGS_FATAL(
153 "The points in time in the time series '{:s}' aren't in ascending "
154 "order.",
155 name);
156 }
157
158 return std::make_unique<TimeDependentHeterogeneousParameter>(
159 name, std::move(time_series));
160}

References BaseLib::ConfigTree::getConfigParameter(), 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::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(), parseOverwriteMeshData(), 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()

OGS_NO_DANGLING Parameter< double > & ParameterLib::getNamedOrCreateInlineParameter ( std::string const & parameter_or_value,
std::vector< std::unique_ptr< ParameterBase > > & parameters,
std::string const & property_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
parameter_or_valueThe raw string to create parameter or value 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).
inline_suffixSuffix for auto-generated parameter names.

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

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

Referenced by ProcessLib::HeatTransportBHE::BHE::createBoreholeGeometry(), ProcessLib::HeatTransportBHE::BHE::createCoolingVariant(), ProcessLib::HeatTransportBHE::BHE::createFlowAndTemperatureControl(), ProcessLib::HeatTransportBHE::BHE::createPipe(), ProcessLib::HeatTransportBHE::BHE::createPowerWithCOPStruct(), and 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().

◆ hasSpatialVariables()

bool ParameterLib::hasSpatialVariables ( std::vector< std::string > const & variables)

Returns true if variables contains any of the spatial variable names "x", "y", or "z".

Definition at line 45 of file ExprtkUtils.cpp.

46{
47 return std::ranges::any_of(variables, [](std::string const& v)
48 { return v == "x" || v == "y" || v == "z"; });
49}

Referenced by ParameterLib::FunctionEvaluation::FunctionEvaluation(), and MaterialPropertyLib::Function::Implementation< D >::Implementation().

◆ isBuiltinSymbol()

bool ParameterLib::isBuiltinSymbol ( std::string_view name)

Returns true if name is one of the built-in symbol names registered by createBaseSymbolTable ("t", "x", "y", "z").

Definition at line 40 of file ExprtkUtils.cpp.

41{
42 return name == "t" || name == "x" || name == "y" || name == "z";
43}

Referenced by MaterialPropertyLib::Function::Function(), MaterialPropertyLib::createSymbolTable(), and createSymbolTable().

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

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

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

Referenced by findParameterOptional().

◆ operator<<()

std::ostream & ParameterLib::operator<< ( std::ostream & os,
SpatialPosition const & pos )

Prints the node id, element id and coordinates carried by pos, using "not set" for any of the three that is not specified.

Definition at line 12 of file SpatialPosition.cpp.

13{
14 auto const default_precision = os.precision();
15 os << "{ node: ";
16 if (auto const node_id = pos.getNodeID())
17 {
18 os << *node_id;
19 }
20 else
21 {
22 os << "not set";
23 }
24
25 os << ", element: ";
26 if (auto const element_id = pos.getElementID())
27 {
28 os << *element_id;
29 }
30 else
31 {
32 os << "not set";
33 }
34
35 os << ", coordinates: ";
36 if (auto const coordinates = pos.getCoordinates())
37 {
38 os << std::setprecision(std::numeric_limits<double>::digits10 + 1)
39 << "(" << *coordinates << ")"
40 << std::setprecision(default_precision);
41 }
42 else
43 {
44 os << "not set";
45 }
46 os << " }";
47 return os;
48}

References ParameterLib::SpatialPosition::getCoordinates(), ParameterLib::SpatialPosition::getElementID(), and ParameterLib::SpatialPosition::getNodeID().

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

◆ registerCurveWrappers()

void ParameterLib::registerCurveWrappers ( exprtk::symbol_table< double > & symbol_table,
std::vector< std::string > const & curve_names,
std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const & curves,
std::map< std::string, CurveWrapper > & curve_wrappers )

Registers CurveWrapper objects in the symbol table for the given curve names.

Parameters
symbol_tableThe symbol table to register curves into.
curve_namesNames of curves to register.
curvesMap of all available curves.
curve_wrappersIs filled with CurveWrapper objects and must outlive the returned symbol table.

Definition at line 66 of file ExprtkUtils.cpp.

73{
74 for (auto const& name : curve_names)
75 {
76 if (exprtk::details::is_reserved_symbol(name))
77 {
79 "Curve name '{:s}' collides with an exprtk reserved symbol "
80 "(built-in function or keyword). Such a curve cannot be "
81 "registered: the built-in would silently be used instead. "
82 "Please rename the curve.",
83 name);
84 }
85 curve_wrappers.emplace(name, CurveWrapper(*curves.at(name)));
86 }
87 for (auto& [name, wrapper] : curve_wrappers)
88 {
89 if (!symbol_table.add_function(name, wrapper))
90 {
92 "Failed to register curve '{:s}' as an exprtk function. The "
93 "name is likely already in use (reserved symbol or duplicate).",
94 name);
95 }
96 }
97}

References OGS_FATAL.

Referenced by MaterialPropertyLib::createSymbolTable(), and createSymbolTable().

Variable Documentation

◆ tolerance

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