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