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