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.
compressible_navier_stokes_explicit_solving_strategy_bfecc.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: Eduard Gómez
11 //
12 //
13 
14 #if !defined(KRATOS_COMPRESSIBLE_NAVIER_STOKES_EXPLICIT_SOLVING_STRATEGY_BFECC)
15 #define KRATOS_COMPRESSIBLE_NAVIER_STOKES_EXPLICIT_SOLVING_STRATEGY_BFECC
16 
17 /* System includes */
18 #if __cplusplus >= 201703L
19 #include <optional>
20 #endif
21 
22 /* External includes */
23 
24 /* Project includes */
25 #include "includes/define.h"
26 #include "includes/model_part.h"
27 #include "factories/factory.h"
29 
30 /* Appication includes */
33 
34 namespace Kratos
35 {
36 
40 
44 
48 
49 template <class TSparseSpace, class TDenseSpace>
51 : public CompressibleNavierStokesExplicitSolvingStrategy<ExplicitSolvingStrategyBFECC<TSparseSpace, TDenseSpace>>
52 {
53 public:
56 
57  // The base solving strategy class definition
59 
60  // The base class definition
62 
65 
66  // The explicit builder and solver definition
68 
70  typedef typename BaseType::DofType DofType;
71 
75 
76  // Replace with proper std::optional when upgrading to c++17
77 #if __cplusplus >= 201703L
78  // using std::optional;
79 #else
83  template<typename T>
84  struct optional {
85  optional() noexcept : mHasValue(false) { }
86  optional(const T& V) noexcept : mHasValue(true), mValue(V) { }
87 
88  void reset() noexcept { mHasValue = false; }
89 
90  T& operator*() noexcept { return mValue; }
91  T operator*() const noexcept { return mValue; }
92 
93  bool has_value() const noexcept { return mHasValue;}
94  private:
95  bool mHasValue;
96  T mValue;
97  };
98 #endif
99 
102 
106 
111  : BaseType()
112  {
113  }
114 
121  ModelPart &rModelPart,
122  Parameters ThisParameters)
123  : BaseType(rModelPart)
124  {
125  // Validate and assign defaults
126  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
127  this->AssignSettings(ThisParameters);
128  }
129 
137  ModelPart &rModelPart,
138  typename ExplicitBuilderType::Pointer pExplicitBuilder,
139  bool MoveMeshFlag = false,
140  int RebuildLevel = 0)
141  : BaseType(rModelPart, pExplicitBuilder, MoveMeshFlag, RebuildLevel)
142  {
143  }
144 
151  ModelPart &rModelPart,
152  bool MoveMeshFlag = false,
153  int RebuildLevel = 0)
154  : BaseType(rModelPart, MoveMeshFlag, RebuildLevel)
155  {
156  }
157 
163  typename SolvingStrategyType::Pointer Create(
164  ModelPart& rModelPart,
165  Parameters ThisParameters
166  ) const override
167  {
168  return Kratos::make_shared<ClassType>(rModelPart, ThisParameters);
169  }
170 
174 
178 
183  static std::string Name()
184  {
185  std::stringstream s;
186  s << "compressible_navier_stokes_explicit_solving_strategy_bfecc";
187  return s.str();
188  }
189 
193 
194 
198 
204  {
205  KRATOS_TRY
206 
207  Parameters default_parameters {};
208  default_parameters.AddString("explicit_solving_strategy", Name());
209 
210  // Getting base class default parameters
211  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
212  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
213  return default_parameters;
214 
215  KRATOS_CATCH("")
216  }
217 
218 
222 
224  std::string Info() const override
225  {
226  std::stringstream ss;
227  ss << "CompressibleNavierStokesExplicitSolvingStrategyBFECC";
228  return ss.str();
229  }
230 
232 
233 protected:
236 
240 
244 
245 
249 
255  {
257  StashDiffusiveConstants();
258  this->InitializeEverySubstep();
259  };
260 
266  {
268  this->InitializeEverySubstep();
269  };
270 
276  {
278  PopDiffusiveConstants();
279  this->InitializeEverySubstep();
280  };
281 
287  {
289  this->FinalizeEverySubstep();
290  };
291 
297  {
299  this->FinalizeEverySubstep();
300  };
301 
307  {
309  PopDiffusiveConstants();
310  this->FinalizeEverySubstep();
311  };
312 
316 
317 
321 
322 
326 
327 
329 private:
332 
333 
337 
338 #if __cplusplus >= 201703L
339  struct Stash {
340  std::optional<double> conductivity = {};
341  std::optional<double> dynamic_viscosity = {};
342  } mDiffusionStash;
343 #else
344  struct Stash {
345  optional<double> conductivity = {};
346  optional<double> dynamic_viscosity = {};
347  } mDiffusionStash;
348 #endif
349 
353 
354 
358 
359  void StashDiffusiveConstants()
360  {
361  KRATOS_TRY
362 
364 
365  KRATOS_ERROR_IF(model_part.NumberOfElements() == 0) << "Model part is devoid of elements!"; // This error must be removed when MPI is implemented
366 
367  auto& properties = model_part.ElementsBegin()->GetProperties();
368 
369  if(properties.Has(CONDUCTIVITY))
370  {
371  auto& r_conductivity = properties.GetValue(CONDUCTIVITY);
372  mDiffusionStash.conductivity = r_conductivity;
373  r_conductivity = 0;
374  }
375 
376  if(properties.Has(DYNAMIC_VISCOSITY))
377  {
378  auto& r_dynamic_viscosity = properties.GetValue(DYNAMIC_VISCOSITY);
379  mDiffusionStash.dynamic_viscosity = r_dynamic_viscosity;
380  r_dynamic_viscosity = 0;
381  }
382 
383  KRATOS_CATCH("")
384  }
385 
386  void PopDiffusiveConstants()
387  {
388  KRATOS_TRY
389 
391 
392  KRATOS_ERROR_IF(model_part.NumberOfElements() == 0) << "Model part is devoid of elements!"; // This error must be removed when MPI is implemented
393 
394  auto& properties = model_part.ElementsBegin()->GetProperties();
395 
396  if(mDiffusionStash.conductivity.has_value())
397  {
398  properties.SetValue(CONDUCTIVITY, *mDiffusionStash.conductivity);
399  }
400 
401  if(mDiffusionStash.dynamic_viscosity.has_value())
402  {
403  properties.SetValue(DYNAMIC_VISCOSITY, *mDiffusionStash.dynamic_viscosity);
404  }
405 
406  mDiffusionStash.conductivity.reset();
407  mDiffusionStash.dynamic_viscosity.reset();
408 
409  KRATOS_CATCH("")
410  }
411 
415 
416 
420 
421 
425 
426 
428 };
429 
431 
434 
436 
437 } /* namespace Kratos.*/
438 
439 #endif /* KRATOS_COMPRESSIBLE_NAVIER_STOKES_EXPLICIT_SOLVING_STRATEGY_BFECC defined */
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:52
CompressibleNavierStokesExplicitSolvingStrategy< ExplicitSolvingStrategyBFECC< TSparseSpace, TDenseSpace > > BaseType
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:61
std::string Info() const override
Turn back information as a string.
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:224
CompressibleNavierStokesExplicitSolvingStrategyBFECC(ModelPart &rModelPart, Parameters ThisParameters)
Default constructor. (with parameters)
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:120
SolvingStrategy< TSparseSpace, TDenseSpace > SolvingStrategyType
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:58
void FinalizeBFECCForwardSubstep() override
Initialize the BFECC forward substep This method is intended to implement all the operations required...
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:286
void InitializeBFECCForwardSubstep() override
Initialize the BFECC forward substep This method is intended to implement all the operations required...
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:254
void InitializeBFECCBackwardSubstep() override
Initialize the BFECC backward substep This method is intended to implement all the operations require...
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:265
SolvingStrategyType::Pointer Create(ModelPart &rModelPart, Parameters ThisParameters) const override
Create method.
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:163
void InitializeBFECCFinalSubstep() override
Initialize the BFECC final substep This method is intended to implement all the operations required b...
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:275
CompressibleNavierStokesExplicitSolvingStrategyBFECC(ModelPart &rModelPart, bool MoveMeshFlag=false, int RebuildLevel=0)
Default constructor.
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:150
CompressibleNavierStokesExplicitSolvingStrategyBFECC()
Default constructor. (empty)
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:110
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:203
BaseType::DofType DofType
The DOF type.
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:70
void FinalizeBFECCBackwardSubstep() override
Finalize the BFECC backward substep This method is intended to implement all the operations required ...
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:296
CompressibleNavierStokesExplicitSolvingStrategyBFECC(ModelPart &rModelPart, typename ExplicitBuilderType::Pointer pExplicitBuilder, bool MoveMeshFlag=false, int RebuildLevel=0)
Default constructor.
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:136
KRATOS_CLASS_POINTER_DEFINITION(CompressibleNavierStokesExplicitSolvingStrategyBFECC)
BaseType::ExplicitBuilderType ExplicitBuilderType
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:67
void FinalizeBFECCFinalSubstep() override
Finalize the BFECC final substep This method is intended to implement all the operations required bef...
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:306
TDenseSpace::VectorType LocalSystemVectorType
The local vector definition.
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:73
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:183
TDenseSpace::MatrixType LocalSystemMatrixType
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:74
CompressibleNavierStokesExplicitSolvingStrategyBFECC(const CompressibleNavierStokesExplicitSolvingStrategyBFECC &Other)=delete
CompressibleNavierStokesExplicitSolvingStrategyBFECC< TSparseSpace, TDenseSpace > ClassType
The definition of the current class.
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:64
Explicit solving strategy base class.
Definition: compressible_navier_stokes_explicit_solving_strategy.h:63
BaseType::ExplicitBuilderType ExplicitBuilderType
The explicit builder and solver definition.
Definition: compressible_navier_stokes_explicit_solving_strategy.h:73
virtual void FinalizeEverySubstep()
Definition: compressible_navier_stokes_explicit_solving_strategy.h:480
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: compressible_navier_stokes_explicit_solving_strategy.h:193
virtual void InitializeEverySubstep()
Definition: compressible_navier_stokes_explicit_solving_strategy.h:468
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: compressible_navier_stokes_explicit_solving_strategy.h:169
virtual void InitializeBFECCFinalSubstep()
Initialize the BFECC final substep This method is intended to implement all the operations required b...
Definition: explicit_solving_strategy_bfecc.h:408
virtual void FinalizeBFECCBackwardSubstep()
Finalize the BFECC backward substep This method is intended to implement all the operations required ...
Definition: explicit_solving_strategy_bfecc.h:402
virtual void InitializeBFECCBackwardSubstep()
Initialize the BFECC backward substep This method is intended to implement all the operations require...
Definition: explicit_solving_strategy_bfecc.h:396
virtual void FinalizeBFECCFinalSubstep()
Finalize the BFECC final substep This method is intended to implement all the operations required aft...
Definition: explicit_solving_strategy_bfecc.h:414
virtual void FinalizeBFECCForwardSubstep()
Finalize the BFECC initial forward substep This method is intended to implement all the operations re...
Definition: explicit_solving_strategy_bfecc.h:390
virtual void InitializeBFECCForwardSubstep()
Initialize the BFECC initial forward substep This method is intended to implement all the operations ...
Definition: explicit_solving_strategy_bfecc.h:384
BaseType::DofType DofType
The DOF type.
Definition: explicit_solving_strategy_bfecc.h:113
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
void AddString(const std::string &rEntry, const std::string &rValue)
This method adds a new string Parameter.
Definition: kratos_parameters.cpp:909
Solving strategy base class This is the base class from which we will derive all the strategies (impl...
Definition: solving_strategy.h:64
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solving_strategy.h:350
virtual Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const
This method validate and assign default parameters.
Definition: solving_strategy.h:507
bool MoveMeshFlag()
This function returns the flag that says if the mesh is moved.
Definition: solving_strategy.h:290
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
Vector VectorType
Definition: geometrical_transformation_utilities.h:56
Matrix MatrixType
Definition: geometrical_transformation_utilities.h:55
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
float conductivity
Definition: face_heat.py:55
model_part
Definition: face_heat.py:14
V
Definition: generate_droplet_dynamics.py:256
tuple const
Definition: ode_solve.py:403
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:84
optional(const T &V) noexcept
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:86
bool has_value() const noexcept
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:93
optional() noexcept
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:85
T & operator*() noexcept
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:90
void reset() noexcept
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:88
T operator*() const noexcept
Definition: compressible_navier_stokes_explicit_solving_strategy_bfecc.h:91