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