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