OGS
RandomFieldMeshElementParameter.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include "Parameter.h"
14 
15 namespace MeshLib
16 {
17 template <typename T>
18 class PropertyVector;
19 } // namespace MeshLib
20 
21 namespace ParameterLib
22 {
24 template <typename T>
26 {
27  RandomFieldMeshElementParameter(std::string const& name_,
29  MeshLib::PropertyVector<T> const& property)
30  : Parameter<T>(name_, &mesh), _property(property)
31  {
32  }
33 
34  bool isTimeDependent() const override { return false; }
35 
36  int getNumberOfGlobalComponents() const override
37  {
39  }
40 
41  std::vector<T> operator()(double const /*t*/,
42  SpatialPosition const& pos) const override
43  {
44  auto const e = pos.getElementID();
45  if (!e)
46  {
47  OGS_FATAL(
48  "Trying to access a RandomFieldMeshElementParameter but "
49  "the element id is not specified.");
50  }
51  auto const num_comp = _property.getNumberOfGlobalComponents();
52  std::vector<T> cache(num_comp);
53  for (int c = 0; c < num_comp; ++c)
54  {
55  cache[c] = _property.getComponent(*e, c);
56  }
57 
58  if (!this->_coordinate_system)
59  {
60  return cache;
61  }
62 
63  return this->rotateWithCoordinateSystem(cache, pos);
64  }
65 
66  Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> getNodalValuesOnElement(
67  MeshLib::Element const& element, double const t) const override
68  {
69  auto const n_nodes = element.getNumberOfNodes();
70  Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> result(
71  n_nodes, getNumberOfGlobalComponents());
72 
73  // Column vector of values, copied for each node.
74  SpatialPosition x_position;
75  x_position.setElementID(element.getID());
76  auto const& values = this->operator()(t, x_position);
77  auto const row_values =
78  Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, 1> const>(
79  values.data(), values.size());
80  for (unsigned i = 0; i < n_nodes; ++i)
81  {
82  result.row(i) = row_values;
83  }
84  return result;
85  }
86 
87 private:
89 };
90 
91 std::unique_ptr<ParameterBase> createRandomFieldMeshElementParameter(
92  std::string const& name, BaseLib::ConfigTree const& config,
93  MeshLib::Mesh& mesh);
94 
95 } // namespace ParameterLib
#define OGS_FATAL(...)
Definition: Error.h:26
virtual unsigned getNumberOfNodes() const =0
virtual std::size_t getID() const final
Returns the ID of the element.
Definition: Element.h:82
int getNumberOfGlobalComponents() const
PROP_VAL_TYPE & getComponent(std::size_t tuple_index, int component)
Returns the value for the given component stored in the given tuple.
std::optional< std::size_t > getElementID() const
void setElementID(std::size_t element_id)
std::unique_ptr< ParameterBase > createRandomFieldMeshElementParameter(std::string const &name, BaseLib::ConfigTree const &config, MeshLib::Mesh &mesh)
std::optional< CoordinateSystem > _coordinate_system
Definition: Parameter.h:125
MeshLib::Mesh const * mesh() const
Definition: Parameter.h:70
std::vector< double > rotateWithCoordinateSystem(std::vector< double > const &values, SpatialPosition const &pos) const
Definition: Parameter.h:75
A parameter represented by a mesh property vector.
Eigen::Matrix< T, 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.
std::vector< T > operator()(double const, SpatialPosition const &pos) const override
Returns the parameter value at the given time and position.
RandomFieldMeshElementParameter(std::string const &name_, MeshLib::Mesh &mesh, MeshLib::PropertyVector< T > const &property)