KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
flux_limiter.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Miguel Maso Sotomayor
11 //
12 
13 #ifndef KRATOS_FLUX_LIMITER_H_INCLUDED
14 #define KRATOS_FLUX_LIMITER_H_INCLUDED
15 
16 
17 // System includes
18 #include <string>
19 #include <iostream>
20 
21 
22 // External includes
23 
24 
25 // Project includes
26 #include "includes/node.h"
29 
30 
31 namespace Kratos
32 {
35 
38 
42 
46 
50 
54 
59 template<class TLocalVectorType>
61 {
62 public:
65 
67 
69  double max;
70  double min;
71  AllowableIncrements(double NewMax, double NewMin) {max = NewMax; min = NewMin;}
72  };
73 
74  typedef Node NodeType;
75 
77 
81 
86  AddFluxLimiters(this->GetDefaultParameters());
87  }
88 
92  FluxLimiter(Parameters ThisParameters) {
93  ThisParameters.ValidateAndAssignDefaults(this->GetDefaultParameters());
94  AddFluxLimiters(ThisParameters);
95  }
96 
100  FluxLimiter(FluxLimiter const& rOther) {
101  mUnlimitedFlux = rOther.mUnlimitedFlux;
102  mAllowableIncrements = rOther.mAllowableIncrements;
103  }
104 
108  virtual ~FluxLimiter() {}
109 
113 
114 
118 
119  IndexType size() {return mUnlimitedFlux.size();}
120 
121  double ComputeUnlimitedFlux(const TLocalVectorType& rContributions, const NodeType& rNode, IndexType iNode, IndexType iVar) {
122  return mUnlimitedFlux[iVar](rContributions, rNode, iNode);
123  }
124 
126  return mAllowableIncrements[iVar](rNode);
127  }
128 
132 
133 
137 
138 
142 
144  virtual std::string Info() const
145  {
146  std::stringstream buffer;
147  buffer << "FluxLimiter" ;
148  return buffer.str();
149  }
150 
152  virtual void PrintInfo(std::ostream& rOStream) const {rOStream << "FluxLimiter";}
153 
155  virtual void PrintData(std::ostream& rOStream) const {}
156 
158 
159 private:
162 
163  std::vector<std::function<double(const TLocalVectorType&, const NodeType&, IndexType)>> mUnlimitedFlux;
164 
165  std::vector<std::function<AllowableIncrements(const NodeType&)>> mAllowableIncrements;
166 
170 
171 
175 
176  void AddFluxLimiters(Parameters ThisParameters) {
177  for (auto var_name : ThisParameters["limiting_variables"].GetStringArray()) {
178  if (KratosComponents<Variable<double>>::Has(var_name)) {
179  const auto& r_var = KratosComponents<Variable<double>>::Get(var_name);
180  this->SetDoubleLimiter(r_var);
181  }
182  else if (KratosComponents<Variable<array_1d<double,3>>>::Has(var_name)) {
183  const auto& r_var = KratosComponents<Variable<array_1d<double,3>>>::Get(var_name);
184  this->SetArrayLimiter(r_var);
185  }
186  }
187  }
188 
189  virtual void SetDoubleLimiter(const Variable<double>& rVariable)
190  {
191  if (rVariable == HEIGHT) {
192  mUnlimitedFlux.push_back(HeightUnlimitedFlux);
193  mAllowableIncrements.push_back(HeightAllowableIncrements);
194  } else if (rVariable == FREE_SURFACE_ELEVATION) {
195  mUnlimitedFlux.push_back(FreeSurfaceUnlimitedFlux);
196  mAllowableIncrements.push_back(FreeSurfaceAllowableIncrements);
197  } else {
198  KRATOS_ERROR << "FluxLimiter: The limiter for the variable " << rVariable << " is undefined." << std::endl;
199  }
200  }
201 
202  virtual void SetArrayLimiter(const Variable<array_1d<double,3>>& rVariable)
203  {
204  if (rVariable == MOMENTUM) {
205  mUnlimitedFlux.push_back(FlowRateUnlimitedFlux);
206  mAllowableIncrements.push_back(FlowRateAllowableIncrements);
207  } else if (rVariable == VELOCITY) {
208  mUnlimitedFlux.push_back(VelocityUnlimitedFlux);
209  mAllowableIncrements.push_back(VelocityAllowableIncrements);
210  } else {
211  KRATOS_ERROR << "FluxLimiter: The limiter for the variable " << rVariable << " is undefined." << std::endl;
212  }
213  }
214 
215  static double HeightUnlimitedFlux(const TLocalVectorType& rContributions, const NodeType& rNode, IndexType iNode)
216  {
217  return rContributions(3*iNode + 2);
218  }
219 
220  static double FreeSurfaceUnlimitedFlux(const TLocalVectorType& rContributions, const NodeType& rNode, IndexType iNode)
221  {
222  return rContributions(3*iNode + 2);
223  }
224 
225  static double FlowRateUnlimitedFlux(const TLocalVectorType& rContributions, const NodeType& rNode, IndexType iNode)
226  {
227  array_1d<double,3> flux;
228  flux[0] = rContributions(3*iNode);
229  flux[1] = rContributions(3*iNode + 1);
230  flux[2] = 0.0;
231  const array_1d<double,3>& v = rNode.FastGetSolutionStepValue(VELOCITY);
232  return inner_prod(flux, v); // projection onto velocity
233  }
234 
235  static double VelocityUnlimitedFlux(const TLocalVectorType& rContributions, const NodeType& rNode, IndexType iNode)
236  {
237  array_1d<double,3> flux_q, flux_v;
238  flux_q[0] = rContributions(3*iNode);
239  flux_q[1] = rContributions(3*iNode + 1);
240  flux_q[2] = 0.0;
241  double flux_h = rContributions(3*iNode + 2);
242  const double h = rNode.FastGetSolutionStepValue(HEIGHT);
243  const array_1d<double,3>& v = rNode.FastGetSolutionStepValue(VELOCITY);
244  const double next_h = h + flux_h;
245  flux_v = flux_q / next_h - v * flux_h / next_h;
246  return inner_prod(flux_v, v); // projection onto velocity
247  }
248 
249  static AllowableIncrements HeightAllowableIncrements(const NodeType& rNode)
250  {
251  // Getting the maximum increments for the height variable
252  AllowableIncrements increments(0.0, 0.0);
253  const auto& neigh_nodes = rNode.GetValue(NEIGHBOUR_NODES);
254  const double h_i = rNode.FastGetSolutionStepValue(HEIGHT);
255  for (IndexType j = 0; j < neigh_nodes.size(); ++j) {
256  double delta_ij = neigh_nodes[j].FastGetSolutionStepValue(HEIGHT) - h_i;
257  increments.max = std::max(increments.max, delta_ij);
258  increments.min = std::min(increments.min, delta_ij);
259  }
260  return increments;
261  }
262 
263  static AllowableIncrements FreeSurfaceAllowableIncrements(const NodeType& rNode)
264  {
265  // Getting the maximum increments for the free surface variable
266  AllowableIncrements increments(0.0, 0.0);
267  const auto& neigh_nodes = rNode.GetValue(NEIGHBOUR_NODES);
268  const double h_i = rNode.FastGetSolutionStepValue(FREE_SURFACE_ELEVATION);
269  for (IndexType j = 0; j < neigh_nodes.size(); ++j) {
270  double delta_ij = neigh_nodes[j].FastGetSolutionStepValue(FREE_SURFACE_ELEVATION) - h_i;
271  increments.max = std::max(increments.max, delta_ij);
272  increments.min = std::min(increments.min, delta_ij);
273  }
274  return increments;
275  }
276 
277  static AllowableIncrements FlowRateAllowableIncrements(const NodeType& rNode)
278  {
279  // Getting the maximum increments for the flow rate variable
280  // The increments are projected to convert it to a scalar
281  AllowableIncrements increments(0.0, 0.0);
282  const auto& neigh_nodes = rNode.GetValue(NEIGHBOUR_NODES);
283  const array_1d<double,3>& q_i = rNode.FastGetSolutionStepValue(MOMENTUM);
284  const array_1d<double,3>& v_i = rNode.FastGetSolutionStepValue(VELOCITY);
285  for (IndexType j = 0; j < neigh_nodes.size(); ++j) {
286  const array_1d<double,3>& delta_ij = neigh_nodes[j].FastGetSolutionStepValue(MOMENTUM) - q_i;
287  double proj_ij = inner_prod(v_i, delta_ij);
288  increments.max = std::max(increments.max, proj_ij);
289  increments.min = std::min(increments.min, proj_ij);
290  }
291  return increments;
292  }
293 
294  static AllowableIncrements VelocityAllowableIncrements(const NodeType& rNode)
295  {
296  // Getting the maximum increments for the velocity variable
297  // The increments are projected to convert it to a scalar
298  AllowableIncrements increments(0.0, 0.0);
299  const auto& neigh_nodes = rNode.GetValue(NEIGHBOUR_NODES);
300  const array_1d<double,3>& v_i = rNode.FastGetSolutionStepValue(VELOCITY);
301  for (IndexType j = 0; j < neigh_nodes.size(); ++j) {
302  const array_1d<double,3>& delta_ij = neigh_nodes[j].FastGetSolutionStepValue(VELOCITY) - v_i;
303  double proj_ij = inner_prod(v_i, delta_ij);
304  increments.max = std::max(increments.max, proj_ij);
305  increments.min = std::min(increments.min, proj_ij);
306  }
307  return increments;
308  }
309 
314  virtual Parameters GetDefaultParameters() const
315  {
316  Parameters default_parameters = Parameters(R"({
317  "limiting_variables" : ["HEIGHT"]
318  })");
319  return default_parameters;
320  }
321 
325 
326 
330 
331 
335 
337  FluxLimiter& operator=(FluxLimiter const& rOther){}
338 
340 
341 }; // Class FluxLimiter
342 
346 
348 
350 
351 } // namespace Kratos.
352 
353 #endif // KRATOS_FLUX_LIMITER_H_INCLUDED defined
This is a helper class to separate the physics from the flux corrected scheme.
Definition: flux_limiter.h:61
GlobalPointersVector< Node > GlobalPointersVectorType
Definition: flux_limiter.h:76
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: flux_limiter.h:155
FluxLimiter(Parameters ThisParameters)
Constructor with parameters.
Definition: flux_limiter.h:92
virtual ~FluxLimiter()
Destructor.
Definition: flux_limiter.h:108
double ComputeUnlimitedFlux(const TLocalVectorType &rContributions, const NodeType &rNode, IndexType iNode, IndexType iVar)
Definition: flux_limiter.h:121
IndexType size()
Definition: flux_limiter.h:119
virtual std::string Info() const
Turn back information as a string.
Definition: flux_limiter.h:144
Node NodeType
Definition: flux_limiter.h:74
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: flux_limiter.h:152
AllowableIncrements ComputeAllowableIncrements(const NodeType &rNode, IndexType iVar)
Definition: flux_limiter.h:125
FluxLimiter(FluxLimiter const &rOther)
Copy constructor.
Definition: flux_limiter.h:100
FluxLimiter()
Default constructor.
Definition: flux_limiter.h:85
KRATOS_CLASS_POINTER_DEFINITION(FluxLimiter)
This class is a vector which stores global pointers.
Definition: global_pointers_vector.h:61
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
This class defines the node.
Definition: node.h:65
TVariableType::Type & FastGetSolutionStepValue(const TVariableType &rThisVariable)
Definition: node.h:435
TVariableType::Type & GetValue(const TVariableType &rThisVariable)
Definition: node.h:466
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
void ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
#define KRATOS_ERROR
Definition: exception.h:161
static double max(double a, double b)
Definition: GeometryFunctions.h:79
static double min(double a, double b)
Definition: GeometryFunctions.h:71
bool Has(const std::string &ModelerName)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:24
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
TABLE_NUMBER_ANGULAR_VELOCITY TABLE_NUMBER_MOMENT I33 BEAM_INERTIA_ROT_UNIT_LENGHT_Y KRATOS_DEFINE_APPLICATION_VARIABLE(DEM_APPLICATION, double, BEAM_INERTIA_ROT_UNIT_LENGHT_Z) typedef std double
Definition: DEM_application_variables.h:182
v
Definition: generate_convection_diffusion_explicit_element.py:114
h
Definition: generate_droplet_dynamics.py:91
int j
Definition: quadrature.py:648
Definition: flux_limiter.h:68
double min
Definition: flux_limiter.h:70
AllowableIncrements(double NewMax, double NewMin)
Definition: flux_limiter.h:71
double max
Definition: flux_limiter.h:69