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