OGS
GroupBasedParameter.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <utility>
14 
15 #include "BaseLib/Error.h"
16 #include "MeshLib/PropertyVector.h"
17 
18 #include "Parameter.h"
19 
20 namespace MeshLib
21 {
22 template <typename T>
23 class PropertyVector;
24 } // namespace MeshLib
25 
26 namespace ParameterLib
27 {
30 template <typename T, MeshLib::MeshItemType MeshItemType>
31 struct 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 
82 private:
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 
106 std::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 > getElementID() const
std::optional< std::size_t > getNodeID() 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
MeshLib::PropertyVector< int > const & _property_index
static std::optional< std::size_t > getMeshItemID(SpatialPosition const &pos, type< MeshLib::MeshItemType::Node >)
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.
GroupBasedParameter(std::string const &name_, MeshLib::Mesh const &mesh, MeshLib::PropertyVector< int > const &property, std::map< int, std::vector< double >> vec_values)
int getNumberOfGlobalComponents() const override
std::optional< CoordinateSystem > _coordinate_system
Definition: Parameter.h:125
MeshLib::Mesh const * mesh() const
Definition: Parameter.h:70
std::vector< double > rotateWithCoordinateSystem(std::vector< double > const &values, SpatialPosition const &pos) const
Definition: Parameter.h:75