OGS
ConstantParameter.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 "Parameter.h"
7
8namespace ParameterLib
9{
11template <typename T>
12struct ConstantParameter final : public Parameter<T>
13{
15 explicit ConstantParameter(std::string const& name_, T const& value)
16 : Parameter<T>(name_), _values({value})
17 {
18 }
19
22 explicit ConstantParameter(std::string const& name_, std::vector<T> values)
23 : Parameter<T>(name_), _values(std::move(values))
24 {
25 assert(!_values.empty());
26 }
27
28 bool isTimeDependent() const override { return false; }
29
30 int getNumberOfGlobalComponents() const override
31 {
32 return static_cast<int>(_values.size());
33 }
34
35 std::vector<T> operator()(double const /*t*/,
36 SpatialPosition const& pos) const override
37 {
38 if (!this->_coordinate_system)
39 {
40 return _values;
41 }
42
43 return this->rotateWithCoordinateSystem(_values, pos);
44 }
45
46 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> getNodalValuesOnElement(
47 MeshLib::Element const& element, double const /*t*/) const override
48 {
49 auto const n_nodes = element.getNumberOfNodes();
50 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> result(
52
53 // Column vector of values, copied for each node.
54 auto const row_values =
55 Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, 1> const>(
56 _values.data(), _values.size());
57 for (unsigned i = 0; i < n_nodes; ++i)
58 {
59 result.row(i) = row_values;
60 }
61 return result;
62 }
63
64private:
65 std::vector<T> const _values;
66};
67
68std::unique_ptr<ParameterBase> createConstantParameter(
69 std::string const& name, BaseLib::ConfigTree const& config);
70
71} // namespace ParameterLib
virtual unsigned getNumberOfNodes() const =0
std::unique_ptr< ParameterBase > createConstantParameter(std::string const &name, BaseLib::ConfigTree const &config)
ConstantParameter(std::string const &name_, std::vector< T > values)
bool isTimeDependent() const override
int getNumberOfGlobalComponents() const override
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > getNodalValuesOnElement(MeshLib::Element const &element, double const) const override
Returns a matrix of values for all nodes of the given element.
std::vector< T > operator()(double const, SpatialPosition const &pos) const override
Returns the parameter value at the given time and position.
ConstantParameter(std::string const &name_, T const &value)
Construction with single value.
std::vector< double > rotateWithCoordinateSystem(std::vector< double > const &values, SpatialPosition const &pos) const
std::optional< CoordinateSystem > _coordinate_system