Skip to content
Snippets Groups Projects
Commit ce69acae authored by Christoph Lehmann's avatar Christoph Lehmann
Browse files

[PL] added getNumComp(), added docu, added check

parent 0dcaba1d
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,10 @@ namespace ProcessLib ...@@ -18,6 +18,10 @@ namespace ProcessLib
template <typename T> template <typename T>
struct ConstantParameter final : public Parameter<T> { struct ConstantParameter final : public Parameter<T> {
ConstantParameter(T const& value) : _value{{value}} {} ConstantParameter(T const& value) : _value{{value}} {}
// TODO allow for different sizes
unsigned getNumberOfComponents() const { return 1; }
std::vector<T> const& getTuple( std::vector<T> const& getTuple(
double const /*t*/, SpatialPosition const& /*pos*/) const override double const /*t*/, SpatialPosition const& /*pos*/) const override
{ {
...@@ -25,7 +29,7 @@ struct ConstantParameter final : public Parameter<T> { ...@@ -25,7 +29,7 @@ struct ConstantParameter final : public Parameter<T> {
} }
private: private:
std::vector<T> _value; std::vector<T> const _value;
}; };
std::unique_ptr<ParameterBase> createConstantParameter( std::unique_ptr<ParameterBase> createConstantParameter(
......
...@@ -32,7 +32,12 @@ std::unique_ptr<ParameterBase> createMeshElementParameter( ...@@ -32,7 +32,12 @@ std::unique_ptr<ParameterBase> createMeshElementParameter(
auto const& property = auto const& property =
mesh.getProperties().template getPropertyVector<double>(field_name); mesh.getProperties().template getPropertyVector<double>(field_name);
if (!property) { 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()); field_name.c_str());
} }
......
...@@ -25,22 +25,30 @@ template <typename T> ...@@ -25,22 +25,30 @@ template <typename T>
struct MeshElementParameter final : public Parameter<T> { struct MeshElementParameter final : public Parameter<T> {
MeshElementParameter(MeshLib::PropertyVector<T> const& property) MeshElementParameter(MeshLib::PropertyVector<T> const& property)
: _property(property) : _property(property)
, _cache(_property.getNumberOfComponents())
{ {
} }
unsigned getNumberOfComponents() const override
{
return _property.getNumberOfComponents();
}
std::vector<T> const& getTuple(double const /*t*/, std::vector<T> const& getTuple(double const /*t*/,
SpatialPosition const& pos) const override SpatialPosition const& pos) const override
{ {
auto const e = pos.getElementID(); auto const e = pos.getElementID();
assert(e); 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; return _cache;
} }
private: private:
MeshLib::PropertyVector<T> const& _property; MeshLib::PropertyVector<T> const& _property;
// TODO multi-component mutable std::vector<double> _cache;
mutable std::vector<double> _cache = std::vector<double>(1);
}; };
std::unique_ptr<ParameterBase> createMeshElementParameter( std::unique_ptr<ParameterBase> createMeshElementParameter(
......
...@@ -36,16 +36,29 @@ struct ParameterBase ...@@ -36,16 +36,29 @@ struct ParameterBase
std::string name; 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> template <typename T>
struct Parameter : public ParameterBase struct Parameter : public ParameterBase
{ {
virtual ~Parameter() = default; 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( virtual std::vector<T> const& getTuple(
double const t, SpatialPosition const& pos) const = 0; 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( std::unique_ptr<ParameterBase> createParameter(
BaseLib::ConfigTree const& config, BaseLib::ConfigTree const& config,
const std::vector<MeshLib::Mesh*>& meshes); const std::vector<MeshLib::Mesh*>& meshes);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment