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