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