OGS 6.1.0-1721-g6382411ad
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 
20 namespace MeshLib
21 {
22 template <typename T>
23 class PropertyVector;
24 } // MeshLib
25 
26 namespace ProcessLib
27 {
28 
31 template <typename T, MeshLib::MeshItemType MeshItemType>
32 struct GroupBasedParameter final
33  : public Parameter<T>
34 {
42  GroupBasedParameter(std::string const& name_,
43  MeshLib::PropertyVector<int> const& property,
44  std::vector<std::vector<double>>
45  vec_values)
46  : Parameter<T>(name_),
47  _property_index(property),
48  _vec_values(std::move(vec_values))
49  {
50  }
51 
52  bool isTimeDependent() const override { return false; }
53 
54  int getNumberOfComponents() const override
55  {
56  return _vec_values.empty()
57  ? 0
58  : static_cast<int>(_vec_values.front().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.get()];
67  auto const& values = _vec_values[index];
68  if (values.empty())
69  OGS_FATAL("No data found for the group index %d", index);
70  return values;
71  }
72 
73 private:
74  template <MeshLib::MeshItemType ITEM_TYPE> struct type {};
75 
76  static boost::optional<std::size_t>
78  {
79  return pos.getElementID();
80  }
81 
82  static boost::optional<std::size_t>
84  {
85  return pos.getNodeID();
86  }
87 
89  std::vector<std::vector<T>> const _vec_values;
90 };
91 
92 std::unique_ptr<ParameterBase> createGroupBasedParameter(
93  std::string const& name,
94  BaseLib::ConfigTree const& config,
95  MeshLib::Mesh const& mesh);
96 
97 } // ProcessLib
std::vector< T > operator()(double const, SpatialPosition const &pos) const override
Returns the parameter value at the given time and position.
std::unique_ptr< ParameterBase > createGroupBasedParameter(std::string const &name, BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh)
int getNumberOfComponents() const override
static boost::optional< std::size_t > getMeshItemID(SpatialPosition const &pos, type< MeshLib::MeshItemType::Node >)
boost::optional< std::size_t > getNodeID() const
GroupBasedParameter(std::string const &name_, MeshLib::PropertyVector< int > const &property, std::vector< std::vector< double >> vec_values)
bool isTimeDependent() const override
boost::optional< std::size_t > getElementID() const
MeshLib::PropertyVector< int > const & _property_index
std::vector< std::vector< T > > const _vec_values
Interface for heuristic search length strategy.
Definition: ProjectData.h:28
#define OGS_FATAL(fmt,...)
Definition: Error.h:71
static boost::optional< std::size_t > getMeshItemID(SpatialPosition const &pos, type< MeshLib::MeshItemType::Cell >)