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
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(
......
......@@ -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());
}
......
......@@ -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(
......
......@@ -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);
......
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