OGS
CurveScaledParameter.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <map>
7#include <utility>
9#include "Parameter.h"
10#include "Utils.h"
11
12namespace ParameterLib
13{
14template <typename T>
15struct CurveScaledParameter final : public Parameter<T>
16{
17 CurveScaledParameter(std::string const& name_,
19 std::string referenced_parameter_name)
20 : Parameter<T>(name_),
21 _curve(curve),
22 _referenced_parameter_name(std::move(referenced_parameter_name))
23 {
24 }
25
26 bool isTimeDependent() const override { return true; }
28 std::vector<std::unique_ptr<ParameterBase>> const& parameters) override
29 {
33 }
34
35 int getNumberOfGlobalComponents() const override
36 {
37 return _parameter->getNumberOfGlobalComponents();
38 }
39
40 std::vector<T> operator()(double const t,
41 SpatialPosition const& pos) const override
42 {
43 // No local coordinate transformation here, which might happen twice
44 // otherwise.
45 assert(!this->_coordinate_system ||
46 "Coordinate system not expected to be set for curve scaled "
47 "parameters.");
48
49 auto const& tup = (*_parameter)(t, pos);
50 auto const scaling = _curve.getValue(t);
51
52 auto const num_comp = _parameter->getNumberOfGlobalComponents();
53 std::vector<T> cache(num_comp);
54 for (int c = 0; c < num_comp; ++c)
55 {
56 cache[c] = scaling * tup[c];
57 }
58 return cache;
59 }
60
61private:
63 Parameter<T> const* _parameter = nullptr;
64 std::string const _referenced_parameter_name;
65};
66
67std::unique_ptr<ParameterBase> createCurveScaledParameter(
68 std::string const& name,
69 BaseLib::ConfigTree const& config,
70 std::map<std::string,
71 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
72 curves);
73
74} // namespace ParameterLib
OGS_NO_DANGLING Parameter< ParameterDataType > & findParameter(std::string const &parameter_name, std::vector< std::unique_ptr< ParameterBase > > const &parameters, int const num_components, MeshLib::Mesh const *const mesh=nullptr)
std::unique_ptr< ParameterBase > createCurveScaledParameter(std::string const &name, BaseLib::ConfigTree const &config, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)
int getNumberOfGlobalComponents() const override
CurveScaledParameter(std::string const &name_, MathLib::PiecewiseLinearInterpolation const &curve, std::string referenced_parameter_name)
void initialize(std::vector< std::unique_ptr< ParameterBase > > const &parameters) override
std::vector< T > operator()(double const t, SpatialPosition const &pos) const override
Returns the parameter value at the given time and position.
MathLib::PiecewiseLinearInterpolation const & _curve
std::optional< CoordinateSystem > _coordinate_system