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