OGS
GroupBasedParameter.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <utility>
14
15#include "BaseLib/Error.h"
17
18#include "Parameter.h"
19
20namespace MeshLib
21{
22template <typename T>
23class PropertyVector;
24} // namespace MeshLib
25
26namespace ParameterLib
27{
30template <typename T, MeshLib::MeshItemType MeshItemType>
31struct GroupBasedParameter final : public Parameter<T>
32{
41 GroupBasedParameter(std::string const& name_,
42 MeshLib::Mesh const& mesh,
43 MeshLib::PropertyVector<int> const& property,
44 std::map<int, std::vector<double>>
45 vec_values)
46 : Parameter<T>(name_, &mesh),
47 _property_index(property),
48 _vec_values(std::move(vec_values))
49 {
50 }
51
52 bool isTimeDependent() const override { return false; }
53
54 int getNumberOfGlobalComponents() const override
55 {
56 return _vec_values.empty()
57 ? 0
58 : static_cast<int>(_vec_values.begin()->second.size());
59 }
60
61 std::vector<T> operator()(double const /*t*/,
62 SpatialPosition const& pos) const override
63 {
64 auto const item_id = getMeshItemID(pos, type<MeshItemType>());
65 assert(item_id);
66 int const index = _property_index[item_id.value()];
67 auto const v = _vec_values.find(index);
68 if (v == _vec_values.end())
69 {
70 OGS_FATAL("No data found for the group index {:d}", index);
71 }
72 auto const& values = v->second;
73
74 if (!this->_coordinate_system)
75 {
76 return values;
77 }
78
79 return this->rotateWithCoordinateSystem(values, pos);
80 }
81
82private:
83 template <MeshLib::MeshItemType ITEM_TYPE>
84 struct type
85 {
86 };
87
88 static std::optional<std::size_t> getMeshItemID(
89 SpatialPosition const& pos,
91 {
92 return pos.getElementID();
93 }
94
95 static std::optional<std::size_t> getMeshItemID(
96 SpatialPosition const& pos,
98 {
99 return pos.getNodeID();
100 }
101
103 std::map<int, std::vector<T>> const _vec_values;
104};
105
106std::unique_ptr<ParameterBase> createGroupBasedParameter(
107 std::string const& name,
108 BaseLib::ConfigTree const& config,
109 MeshLib::Mesh const& mesh);
110
111} // namespace ParameterLib
#define OGS_FATAL(...)
Definition Error.h:26
std::optional< std::size_t > getNodeID() const
std::optional< std::size_t > getElementID() const
std::unique_ptr< ParameterBase > createGroupBasedParameter(std::string const &name, BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh)
std::map< int, std::vector< T > > const _vec_values
GroupBasedParameter(std::string const &name_, MeshLib::Mesh const &mesh, MeshLib::PropertyVector< int > const &property, std::map< int, std::vector< double > > vec_values)
static std::optional< std::size_t > getMeshItemID(SpatialPosition const &pos, type< MeshLib::MeshItemType::Node >)
MeshLib::PropertyVector< int > const & _property_index
static std::optional< std::size_t > getMeshItemID(SpatialPosition const &pos, type< MeshLib::MeshItemType::Cell >)
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