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