From ce69acaed1d62a1a1e3e5eb619832b7e12ff5336 Mon Sep 17 00:00:00 2001 From: Christoph Lehmann <christoph.lehmann@ufz.de> Date: Tue, 16 Aug 2016 15:35:35 +0200 Subject: [PATCH] [PL] added getNumComp(), added docu, added check --- ProcessLib/ConstantParameter.h | 6 +++++- ProcessLib/MeshElementParameter.cpp | 7 ++++++- ProcessLib/MeshElementParameter.h | 14 +++++++++++--- ProcessLib/Parameter.h | 15 ++++++++++++++- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/ProcessLib/ConstantParameter.h b/ProcessLib/ConstantParameter.h index 4cb66a19d88..54e79a2317f 100644 --- a/ProcessLib/ConstantParameter.h +++ b/ProcessLib/ConstantParameter.h @@ -18,6 +18,10 @@ namespace ProcessLib template <typename T> struct ConstantParameter final : public Parameter<T> { ConstantParameter(T const& value) : _value{{value}} {} + + // TODO allow for different sizes + unsigned getNumberOfComponents() const { return 1; } + std::vector<T> const& getTuple( double const /*t*/, SpatialPosition const& /*pos*/) const override { @@ -25,7 +29,7 @@ struct ConstantParameter final : public Parameter<T> { } private: - std::vector<T> _value; + std::vector<T> const _value; }; std::unique_ptr<ParameterBase> createConstantParameter( diff --git a/ProcessLib/MeshElementParameter.cpp b/ProcessLib/MeshElementParameter.cpp index f05dab9a44f..b019c8fed58 100644 --- a/ProcessLib/MeshElementParameter.cpp +++ b/ProcessLib/MeshElementParameter.cpp @@ -32,7 +32,12 @@ std::unique_ptr<ParameterBase> createMeshElementParameter( auto const& property = mesh.getProperties().template getPropertyVector<double>(field_name); if (!property) { - OGS_FATAL("The required property %s is not of the requested type.", + OGS_FATAL("The mesh property `%s' is not of the requested type.", + field_name.c_str()); + } + + if (property->getMeshItemType() != MeshLib::MeshItemType::Cell) { + OGS_FATAL("The mesh property `%s' is not an element property.", field_name.c_str()); } diff --git a/ProcessLib/MeshElementParameter.h b/ProcessLib/MeshElementParameter.h index bb4f8d6ded3..298065a64c7 100644 --- a/ProcessLib/MeshElementParameter.h +++ b/ProcessLib/MeshElementParameter.h @@ -25,22 +25,30 @@ template <typename T> struct MeshElementParameter final : public Parameter<T> { MeshElementParameter(MeshLib::PropertyVector<T> const& property) : _property(property) + , _cache(_property.getNumberOfComponents()) { } + unsigned getNumberOfComponents() const override + { + return _property.getNumberOfComponents(); + } + std::vector<T> const& getTuple(double const /*t*/, SpatialPosition const& pos) const override { auto const e = pos.getElementID(); assert(e); - _cache.front() = _property[*e]; + auto const num_comp = _property.getNumberOfComponents(); + for (std::size_t c=0; c<num_comp; ++c) { + _cache[c] = _property.getComponent(*e, c); + } return _cache; } private: MeshLib::PropertyVector<T> const& _property; - // TODO multi-component - mutable std::vector<double> _cache = std::vector<double>(1); + mutable std::vector<double> _cache; }; std::unique_ptr<ParameterBase> createMeshElementParameter( diff --git a/ProcessLib/Parameter.h b/ProcessLib/Parameter.h index 7a464b58763..aec56e55794 100644 --- a/ProcessLib/Parameter.h +++ b/ProcessLib/Parameter.h @@ -36,16 +36,29 @@ struct ParameterBase std::string name; }; +/*! A Parameter is a function \f$ (t, x) \mapsto f(t, x) \in T^n \f$. + * + * Where \f$ t \f$ is the time and \f$ x \f$ is the SpatialPosition. + * \f$ n \f$ is the number of components of \f$f\f$'s results, i.e., 1 for a + * scalar parameter and >1 for a vectorial or tensorial parameter. + */ template <typename T> struct Parameter : public ParameterBase { virtual ~Parameter() = default; - // TODO number of components + //! Returns the number of components this Parameter has at every position and + //! point in time. + virtual unsigned getNumberOfComponents() const = 0; + + //! Returns the parameter value at the given time and position. virtual std::vector<T> const& getTuple( double const t, SpatialPosition const& pos) const = 0; }; +//! Constructs a new ParameterBase from the given configuration. +//! +//! The \c meshes vector is used to set up parameters from mesh input data. std::unique_ptr<ParameterBase> createParameter( BaseLib::ConfigTree const& config, const std::vector<MeshLib::Mesh*>& meshes); -- GitLab