diff --git a/ProcessLib/Parameter/CurveScaledParameter.h b/ProcessLib/Parameter/CurveScaledParameter.h index 3e4babb03045cd949e84faf603e6b08d1fe71a72..bce7cfbedd3c7dfe38c8bf955d25e74e93e1d3ac 100644 --- a/ProcessLib/Parameter/CurveScaledParameter.h +++ b/ProcessLib/Parameter/CurveScaledParameter.h @@ -35,6 +35,7 @@ struct CurveScaledParameter final : public Parameter<T> { { _parameter = &findParameter<T>(_referenced_parameter_name, parameters, 0); + ParameterBase::_mesh = _parameter->mesh(); } int getNumberOfComponents() const override diff --git a/ProcessLib/Parameter/FunctionParameter.h b/ProcessLib/Parameter/FunctionParameter.h index 82b84338d58f7148e239bf91dc610e3d99968928..f32a3cddc236343f82ad888904d9365f217c414a 100644 --- a/ProcessLib/Parameter/FunctionParameter.h +++ b/ProcessLib/Parameter/FunctionParameter.h @@ -39,15 +39,15 @@ struct FunctionParameter final : public Parameter<T> /** * Constructing from a vector of expressions * - * @param name_ the parameter's name - * @param mesh_ a mesh object - * @param vec_expression_str_ a vector of mathematical expressions + * @param name the parameter's name + * @param mesh the parameter's domain of definition. + * @param vec_expression_str a vector of mathematical expressions * The vector size specifies the number of components of the parameter. */ - FunctionParameter(std::string const& name_, - MeshLib::Mesh const& mesh_, - std::vector<std::string> const& vec_expression_str_) - : Parameter<T>(name_), _mesh(mesh_), _vec_expression_str(vec_expression_str_) + FunctionParameter(std::string const& name, + MeshLib::Mesh const& mesh, + std::vector<std::string> const& vec_expression_str) + : Parameter<T>(name, &mesh), _vec_expression_str(vec_expression_str) { _symbol_table.add_constants(); _symbol_table.create_variable("x"); @@ -90,7 +90,8 @@ struct FunctionParameter final : public Parameter<T> } else if (pos.getNodeID()) { - auto const& node = *_mesh.getNode(pos.getNodeID().get()); + auto const& node = + *ParameterBase::_mesh->getNode(pos.getNodeID().get()); x = node[0]; y = node[1]; z = node[2]; @@ -105,7 +106,6 @@ struct FunctionParameter final : public Parameter<T> } private: - MeshLib::Mesh const& _mesh; std::vector<std::string> const _vec_expression_str; symbol_table_t _symbol_table; std::vector<expression_t> _vec_expression; diff --git a/ProcessLib/Parameter/GroupBasedParameter.cpp b/ProcessLib/Parameter/GroupBasedParameter.cpp index f6b256b233530dc06c5439f4af8291fb023d10fe..e939846c857bb92794305146a3be0f224026f23f 100644 --- a/ProcessLib/Parameter/GroupBasedParameter.cpp +++ b/ProcessLib/Parameter/GroupBasedParameter.cpp @@ -99,13 +99,13 @@ std::unique_ptr<ParameterBase> createGroupBasedParameter( { return std::make_unique< GroupBasedParameter<double, MeshLib::MeshItemType::Node>>( - name, *group_id_property, vec_values); + name, mesh, *group_id_property, vec_values); } if (group_id_property->getMeshItemType() == MeshLib::MeshItemType::Cell) { return std::make_unique< GroupBasedParameter<double, MeshLib::MeshItemType::Cell>>( - name, *group_id_property, vec_values); + name, mesh, *group_id_property, vec_values); } OGS_FATAL("Mesh item type of the specified property is not supported."); diff --git a/ProcessLib/Parameter/GroupBasedParameter.h b/ProcessLib/Parameter/GroupBasedParameter.h index 67b7ecfcf6fead611e5dfd18bb42f3cfeaba7ece..1a1d217c909c3ce5bf96246eb944179ab87c6540 100644 --- a/ProcessLib/Parameter/GroupBasedParameter.h +++ b/ProcessLib/Parameter/GroupBasedParameter.h @@ -36,14 +36,16 @@ struct GroupBasedParameter final * Constructing from a property vector of index and corresponding values * * @param name_ the parameter's name + * @param mesh the parameter's domain of definition. * @param property a property vector of index for mesh items * @param vec_values a vector of values for each index */ GroupBasedParameter(std::string const& name_, + MeshLib::Mesh const& mesh, MeshLib::PropertyVector<int> const& property, std::vector<std::vector<double>> vec_values) - : Parameter<T>(name_), + : Parameter<T>(name_, &mesh), _property_index(property), _vec_values(std::move(vec_values)) { diff --git a/ProcessLib/Parameter/MeshElementParameter.cpp b/ProcessLib/Parameter/MeshElementParameter.cpp index aaa20760daabe2547be608b521c9b409c9edf835..8c707397d762ec99737dbcc916871b4eabe2e35f 100644 --- a/ProcessLib/Parameter/MeshElementParameter.cpp +++ b/ProcessLib/Parameter/MeshElementParameter.cpp @@ -32,7 +32,8 @@ std::unique_ptr<ParameterBase> createMeshElementParameter( field_name.c_str()); } - return std::make_unique<MeshElementParameter<double>>(name, *property); + return std::make_unique<MeshElementParameter<double>>(name, mesh, + *property); } } // namespace ProcessLib diff --git a/ProcessLib/Parameter/MeshElementParameter.h b/ProcessLib/Parameter/MeshElementParameter.h index 1146105622d4fe12c8977ae5970bb94ef338d097..1999f6f014b7eb563df6a2f80bebe72c69975f91 100644 --- a/ProcessLib/Parameter/MeshElementParameter.h +++ b/ProcessLib/Parameter/MeshElementParameter.h @@ -23,9 +23,9 @@ namespace ProcessLib template <typename T> struct MeshElementParameter final : public Parameter<T> { MeshElementParameter(std::string const& name_, + MeshLib::Mesh const& mesh, MeshLib::PropertyVector<T> const& property) - : Parameter<T>(name_), - _property(property) + : Parameter<T>(name_, &mesh), _property(property) { } diff --git a/ProcessLib/Parameter/Parameter.h b/ProcessLib/Parameter/Parameter.h index e350d341550b7d21ea9d4e68572b2e864549374f..51c71a82d2f3e888713827ca952b80aa39ea912a 100644 --- a/ProcessLib/Parameter/Parameter.h +++ b/ProcessLib/Parameter/Parameter.h @@ -44,7 +44,12 @@ namespace ProcessLib /// Its property name helps addressing the right parameter. struct ParameterBase { - ParameterBase(std::string name_) : name(std::move(name_)) {} + explicit ParameterBase(std::string name_, + MeshLib::Mesh const* mesh = nullptr) + : name(std::move(name_)), _mesh(mesh) + { + } + virtual ~ParameterBase() = default; virtual bool isTimeDependent() const = 0; @@ -57,7 +62,14 @@ struct ParameterBase { } + MeshLib::Mesh const* mesh() const { return _mesh; } + std::string const name; + +protected: + /// A mesh on which the parameter is defined. Some parameters might be + /// mesh-independent. + MeshLib::Mesh const* _mesh; }; /*! A Parameter is a function \f$ (t, x) \mapsto f(t, x) \in T^n \f$. @@ -69,7 +81,8 @@ struct ParameterBase template <typename T> struct Parameter : public ParameterBase { - Parameter(std::string const& name_) : ParameterBase(name_) {} + using ParameterBase::ParameterBase; + ~Parameter() override = default; //! Returns the number of components this Parameter has at every position and