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