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