WRApplication
External kratos "application" for multiscale time integration.
basic_pipes.hpp
Go to the documentation of this file.
1 
3 #pragma once
4 
5 // --- Core Includes ---
6 #include "containers/variable.h"
7 #include "includes/process_info.h"
8 #include "containers/model.h"
9 #include "includes/model_part.h"
10 #include "includes/kratos_parameters.h"
11 #include "utilities/interval_utility.h"
12 
13 // --- WRApplication Includes ---
14 #include "wrapp/pipes/inc/pipe.hpp"
16 
17 // --- STL Includes ---
18 #include <optional>
19 #include <functional> // std::reference_wrapper
20 #include <cmath> // std::fmod
21 
22 
23 namespace Kratos::Pipes {
24 
25 
30 
31 
34 class ModelPartFromModel : public Traits<const Model&, const ModelPart&>
35 {
36 public:
37  ModelPartFromModel() = default;
38 
39  ModelPartFromModel(const std::string& rModelPartName);
40 
41  ModelPartFromModel(std::string&& rModelPartName) noexcept;
42 
43  ModelPartFromModel(const Parameters& rParameters);
44 
45  ModelPartFromModel(ModelPartFromModel&& rOther) noexcept = default;
46 
47  ModelPartFromModel(const ModelPartFromModel& rOther) = default;
48 
49  const ModelPart& operator()(const Model& rModel) const
50  {return rModel.GetModelPart(mModelPartName);}
51 
52  static Parameters GetDefaultParameters();
53 
54 private:
55  std::string mModelPartName;
56 }; // class ModelPartFromModel
57 
58 
61 struct ProcessInfoFromModelPart : public Traits<const ModelPart&, const ProcessInfo&>
62 {
63  ProcessInfoFromModelPart() noexcept = default;
64 
65  ProcessInfoFromModelPart(const Parameters& rParameters) noexcept {}
66 
67  ProcessInfoFromModelPart(ProcessInfoFromModelPart&& rOther) noexcept = default;
68 
70 
71  const ProcessInfo& operator()(const ModelPart& rModelPart) const
72  {return rModelPart.GetProcessInfo();}
73 
74  static Parameters GetDefaultParameters();
75 }; // struct ProcessInfoFromModelPart
76 
77 
81 template <class TVariable>
82 class VariableFromProcessInfo : public Traits<const ProcessInfo&, typename TVariable::Type>
83 {
84 public:
86 
87  VariableFromProcessInfo(const TVariable& rVariable)
88  : mVariable({rVariable})
89  {}
90 
91  VariableFromProcessInfo(const Parameters& rParameters);
92 
93  VariableFromProcessInfo(VariableFromProcessInfo&& rOther) noexcept = default;
94 
96 
97  typename TVariable::Type operator()(const ProcessInfo& rProcessInfo) const
98  {
99  KRATOS_ERROR_IF_NOT(bool(mVariable)) << "uninitialized variable in VariableFromProcessInfo";
100  return rProcessInfo[mVariable.value().get()];
101  }
102 
103  static Parameters GetDefaultParameters();
104 
105 private:
106  std::optional<std::reference_wrapper<const TVariable>> mVariable;
107 }; // class VariableFromProcessInfo
108 
109 
112 struct TimeFromProcessInfo : public VariableFromProcessInfo<decltype(TIME)>
113 {
115 
116  TimeFromProcessInfo(const Parameters& rParameters);
117 
119 
120  TimeFromProcessInfo(const TimeFromProcessInfo& rOther) = default;
121 }; // struct TimeFromProcessInfo
122 
123 
126 struct StepFromProcessInfo : public VariableFromProcessInfo<decltype(STEP)>
127 {
129 
130  StepFromProcessInfo(const Parameters& rParameters);
131 
133 
134  StepFromProcessInfo(const StepFromProcessInfo& rOther) = default;
135 }; // struct TimeFromProcessInfo
136 
137 
140 template <class TValue, class TOperator>
141 class Comparison : public Traits<TValue,bool>
142 {
143 public:
145 
146  Comparison(const Parameters& rParameters);
147 
148  bool operator()(TValue lhs) const noexcept;
149 
150  static Parameters GetDefaultParameters();
151 
152 private:
153  TValue mRHS;
154 }; // class Comparison
155 
156 
159 template <class TValue>
160 class IntervalPredicate : public Traits<TValue,bool>
161 {
162 public:
163  IntervalPredicate() = default;
164 
165  IntervalPredicate(TValue begin, TValue end);
166 
167  IntervalPredicate(const Parameters& rParameters);
168 
169  IntervalPredicate(IntervalPredicate&& rOther) noexcept = default;
170 
171  IntervalPredicate(const IntervalPredicate& rOther) = default;
172 
173  bool operator()(TValue Value) const
174  {return mInterval.IsInInterval(Value);}
175 
176  static Parameters GetDefaultParameters();
177 
178 private:
180 }; // class IntervalPredicate
181 
182 
185 template <class TValue>
186 class Modulo : public Traits<TValue,TValue>
187 {
188 public:
189  Modulo() noexcept;
190 
191  Modulo(TValue modulo) noexcept;
192 
193  Modulo(const Parameters& rParameters);
194 
195  Modulo(Modulo&& rOther) noexcept = default;
196 
197  Modulo(const Modulo& rOther) = default;
198 
199  TValue operator()(TValue Value) const
200  {
201  if constexpr (std::is_integral_v<TValue>) {
202  return Value % mModulo;
203  } else {
204  return std::fmod(Value, mModulo);
205  }
206  }
207 
208  static Parameters GetDefaultParameters();
209 
210 private:
211  TValue mModulo;
212 }; // class Modulo
213 
214 
217 template <class TValue>
218 class Add : public Traits<TValue,TValue>
219 {
220 public:
221  Add() noexcept;
222 
223  Add(TValue rhs) noexcept;
224 
225  Add(const Parameters& rParameters);
226 
227  TValue operator()(TValue input) const noexcept
228  {
229  return input + mValue;
230  }
231 
232  static Parameters GetDefaultParameters();
233 
234 private:
235  TValue mValue;
236 }; // class Add
237 
238 
242 template <class TInput>
243 class ConstPredicate : public Traits<TInput,bool>
244 {
245 public:
246  ConstPredicate() noexcept;
247 
248  ConstPredicate(bool value) noexcept;
249 
250  ConstPredicate(const Parameters& rParameters);
251 
252  ConstPredicate(ConstPredicate&& rOther) noexcept = default;
253 
254  ConstPredicate(const ConstPredicate& rOther) noexcept = default;
255 
256  bool operator()(TInput) const noexcept
257  {return mValue;}
258 
259  static Parameters GetDefaultParameters();
260 
261 private:
262  bool mValue;
263 }; // class ConstPredicate
264 
265 
268 
269 
270 } // namespace Kratos::Pipes
271 
272 
273 // Template definitions
274 #include "wrapp/pipes/impl/basic_pipes_impl.hpp"
Add a constant value to the input.
Definition: basic_pipes.hpp:219
static Parameters GetDefaultParameters()
Perform a comparison operation on the input as the left hand side.
Definition: basic_pipes.hpp:142
static Parameters GetDefaultParameters()
Comparison(const Parameters &rParameters)
bool operator()(TValue lhs) const noexcept
Return a bool regardless of the input.
Definition: basic_pipes.hpp:244
static Parameters GetDefaultParameters()
Pipe wrapper for Detail::IntervalUtility.
Definition: basic_pipes.hpp:161
IntervalPredicate(TValue begin, TValue end)
bool operator()(TValue Value) const
Definition: basic_pipes.hpp:173
IntervalPredicate(const Parameters &rParameters)
IntervalPredicate(IntervalPredicate &&rOther) noexcept=default
static Parameters GetDefaultParameters()
IntervalPredicate(const IntervalPredicate &rOther)=default
Get a ModelPart from a Model by name.
Definition: basic_pipes.hpp:35
ModelPartFromModel(ModelPartFromModel &&rOther) noexcept=default
ModelPartFromModel(const ModelPartFromModel &rOther)=default
ModelPartFromModel(const Parameters &rParameters)
ModelPartFromModel(std::string &&rModelPartName) noexcept
static Parameters GetDefaultParameters()
ModelPartFromModel(const std::string &rModelPartName)
const ModelPart & operator()(const Model &rModel) const
Definition: basic_pipes.hpp:49
Compute the mod of the input.
Definition: basic_pipes.hpp:187
static Parameters GetDefaultParameters()
Get a variable from ProcessInfo.
Definition: basic_pipes.hpp:83
TVariable::Type operator()(const ProcessInfo &rProcessInfo) const
Definition: basic_pipes.hpp:97
VariableFromProcessInfo(const VariableFromProcessInfo &rOther)=default
VariableFromProcessInfo(const TVariable &rVariable)
Definition: basic_pipes.hpp:87
static Parameters GetDefaultParameters()
VariableFromProcessInfo(VariableFromProcessInfo &&rOther) noexcept=default
VariableFromProcessInfo(const Parameters &rParameters)
Utility class for membership tests on a 1D interval.
Definition: IntervalUtility.hpp:26
Unix-inspired pipes in C++.
Definition: basic_pipes.hpp:23
Get the ProcessInfo of a ModelPart.
Definition: basic_pipes.hpp:62
const ProcessInfo & operator()(const ModelPart &rModelPart) const
Definition: basic_pipes.hpp:71
ProcessInfoFromModelPart(const ProcessInfoFromModelPart &rOther)=default
ProcessInfoFromModelPart(ProcessInfoFromModelPart &&rOther) noexcept=default
Get STEP from a ProcessInfo.
Definition: basic_pipes.hpp:127
StepFromProcessInfo(const Parameters &rParameters)
StepFromProcessInfo(StepFromProcessInfo &&rOther)=default
StepFromProcessInfo(const StepFromProcessInfo &rOther)=default
Get TIME from a ProcessInfo.
Definition: basic_pipes.hpp:113
TimeFromProcessInfo(const TimeFromProcessInfo &rOther)=default
TimeFromProcessInfo(const Parameters &rParameters)
TimeFromProcessInfo(TimeFromProcessInfo &&rOther)=default
Metaclass containing type information every pipe must inherit from.
Definition: pipe.hpp:72