OGS 6.2.1-76-gbb689931b
SecondaryVariable.h
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include "BaseLib/Algorithm.h"
15 
16 namespace NumLib
17 {
18 class LocalToGlobalIndexMap;
19 }
20 
21 namespace ProcessLib
22 {
26 {
37  using Function = std::function<GlobalVector const&(
38  const double t,
39  GlobalVector const& x,
40  NumLib::LocalToGlobalIndexMap const& dof_table,
41  std::unique_ptr<GlobalVector>& result_cache)>;
42 
43  template <typename F1, typename F2>
44  SecondaryVariableFunctions(const unsigned num_components_, F1&& eval_field_,
45  F2&& eval_residuals_)
46  : num_components(num_components_),
47  eval_field(std::forward<F1>(eval_field_)),
48  eval_residuals(std::forward<F2>(eval_residuals_))
49  {
50  // Used to detect nasty implicit conversions.
51  static_assert(
52  std::is_same<GlobalVector const&,
53  typename std::result_of<F1(
54  double const, GlobalVector const&,
56  std::unique_ptr<GlobalVector>&)>::type>::value,
57  "The function eval_field_ does not return a const reference"
58  " to a GlobalVector");
59 
60  static_assert(
61  std::is_same<GlobalVector const&,
62  typename std::result_of<F2(
63  double const, GlobalVector const&,
65  std::unique_ptr<GlobalVector>&)>::type>::value,
66  "The function eval_residuals_ does not return a const reference"
67  " to a GlobalVector");
68  }
69 
70  template <typename F1>
71  SecondaryVariableFunctions(const unsigned num_components_, F1&& eval_field_,
72  std::nullptr_t)
73  : num_components(num_components_),
74  eval_field(std::forward<F1>(eval_field_))
75  {
76  // Used to detect nasty implicit conversions.
77  static_assert(
78  std::is_same<GlobalVector const&,
79  typename std::result_of<F1(
80  double const, GlobalVector const&,
82  std::unique_ptr<GlobalVector>&)>::type>::value,
83  "The function eval_field_ does not return a const reference"
84  " to a GlobalVector");
85  }
86 
87  const unsigned num_components;
88 
90  Function const eval_field;
91 
96  Function const eval_residuals;
97 };
98 
100 struct SecondaryVariable final
101 {
102  std::string const name;
103 
106 };
107 
110 {
111 public:
113  void addNameMapping(std::string const& internal_name,
114  std::string const& external_name);
115 
127  void addSecondaryVariable(std::string const& internal_name,
129 
131  SecondaryVariable const& get(std::string const& external_name) const;
132 
133  std::map<std::string, std::string>::const_iterator begin() const;
134  std::map<std::string, std::string>::const_iterator end() const;
135 
136 private:
139  std::map<std::string, std::string> _map_external_to_internal;
140 
144  std::map<std::string, SecondaryVariable> _configured_secondary_variables;
145 };
146 
158 template <typename LocalAssemblerCollection>
160  const unsigned num_components,
161  NumLib::Extrapolator& extrapolator,
162  LocalAssemblerCollection const& local_assemblers,
164  LocalAssemblerCollection>::IntegrationPointValuesMethod
165  integration_point_values_method)
166 {
167  auto const eval_field = [num_components, &extrapolator, &local_assemblers,
168  integration_point_values_method](
169  const double t,
170  GlobalVector const& x,
171  NumLib::LocalToGlobalIndexMap const& dof_table,
172  std::unique_ptr<GlobalVector> & /*result_cache*/
173  ) -> GlobalVector const& {
174  auto const extrapolatables = NumLib::makeExtrapolatable(
175  local_assemblers, integration_point_values_method);
176  extrapolator.extrapolate(num_components, extrapolatables, t, x,
177  dof_table);
178  return extrapolator.getNodalValues();
179  };
180 
181  auto const eval_residuals =
182  [num_components, &extrapolator, &local_assemblers,
183  integration_point_values_method](
184  const double t,
185  GlobalVector const& x,
186  NumLib::LocalToGlobalIndexMap const& dof_table,
187  std::unique_ptr<GlobalVector> & /*result_cache*/
188  ) -> GlobalVector const& {
189  auto const extrapolatables = NumLib::makeExtrapolatable(
190  local_assemblers, integration_point_values_method);
191  extrapolator.calculateResiduals(num_components, extrapolatables, t, x,
192  dof_table);
193  return extrapolator.getElementResiduals();
194  };
195  return {num_components, eval_field, eval_residuals};
196 }
197 
198 } // namespace ProcessLib
const unsigned num_components
Number of components of the variable.
SecondaryVariableFunctions(const unsigned num_components_, F1 &&eval_field_, std::nullptr_t)
ExtrapolatableLocalAssemblerCollection< LocalAssemblerCollection > makeExtrapolatable(LocalAssemblerCollection const &local_assemblers, IntegrationPointValuesMethod integration_point_values_method)
SecondaryVariableFunctions fcts
Functions used for computing the secondary variable.
SecondaryVariableFunctions makeExtrapolator(const unsigned num_components, NumLib::Extrapolator &extrapolator, LocalAssemblerCollection const &local_assemblers, typename NumLib::ExtrapolatableLocalAssemblerCollection< LocalAssemblerCollection >::IntegrationPointValuesMethod integration_point_values_method)
Function const eval_field
Computes the value of the field at every node of the underlying mesh.
std::map< std::string, std::string > _map_external_to_internal
Stores information about a specific secondary variable.
SecondaryVariableFunctions(const unsigned num_components_, F1 &&eval_field_, F2 &&eval_residuals_)
std::string const name
Name of the variable; used, e.g., for output.
std::function< GlobalVector const &(const double t, GlobalVector const &x, NumLib::LocalToGlobalIndexMap const &dof_table, std::unique_ptr< GlobalVector > &result_cache)> Function
Handles configuration of several secondary variables from the project file.
std::map< std::string, SecondaryVariable > _configured_secondary_variables