OGS
RasterParameter.h
Go to the documentation of this file.
1
11#pragma once
12
13#include "GeoLib/Raster.h"
14#include "Parameter.h"
15
16namespace ParameterLib
17{
18struct RasterParameter final : public Parameter<double>
19{
20 explicit RasterParameter(std::string const& name_,
21 GeoLib::NamedRaster const& named_raster)
22 : Parameter<double>(name_), _named_raster(named_raster)
23 {
24 }
25
26 bool isTimeDependent() const override { return false; }
27
28 int getNumberOfGlobalComponents() const override { return 1; }
29
30 std::vector<double> operator()(double const /*t*/,
31 SpatialPosition const& pos) const override
32 {
33 auto const& coordinates = pos.getCoordinates();
34 if (!coordinates)
35 {
36 OGS_FATAL("RasterParameter::operator(): couldn't get coordinates.");
37 }
38 auto const value = _named_raster.raster->getValueAtPoint(*coordinates);
39 return {value};
40 }
41
42 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>
44 double const t) const override
45 {
46 auto const n_nodes = element.getNumberOfNodes();
47 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> result(
49
50 SpatialPosition position;
51 auto const nodes = element.getNodes();
52 for (unsigned i = 0; i < n_nodes; ++i)
53 {
54 position.setCoordinates(*(nodes[i]));
55 auto const& values = this->operator()(t, position);
56 result.row(i) =
57 Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, 1> const>(
58 values.data(), values.size());
59 }
60
61 return result;
62 }
63
64private:
66};
67
68std::unique_ptr<ParameterBase> createRasterParameter(
69 std::string const& name, BaseLib::ConfigTree const& config,
70 std::vector<GeoLib::NamedRaster> const& named_rasters);
71
72} // namespace ParameterLib
#define OGS_FATAL(...)
Definition Error.h:26
Definition of the GeoLib::Raster class.
virtual unsigned getNumberOfNodes() const =0
virtual Node *const * getNodes() const =0
Get array of element nodes.
std::optional< MathLib::Point3d > const & getCoordinates() const
void setCoordinates(MathLib::Point3d const &coordinates)
std::unique_ptr< ParameterBase > createRasterParameter(std::string const &name, BaseLib::ConfigTree const &config, std::vector< GeoLib::NamedRaster > const &named_rasters)
std::unique_ptr< GeoLib::Raster > raster
Definition Raster.h:157
std::vector< double > operator()(double const, SpatialPosition const &pos) const override
Returns the parameter value at the given time and position.
int getNumberOfGlobalComponents() const override
bool isTimeDependent() const override
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > getNodalValuesOnElement(MeshLib::Element const &element, double const t) const override
Returns a matrix of values for all nodes of the given element.
GeoLib::NamedRaster const & _named_raster
RasterParameter(std::string const &name_, GeoLib::NamedRaster const &named_raster)