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.
estimate_dt_utilities.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: Jordi Cotela
11 // Ruben Zorrilla
12 //
13 //
14 
15 #ifndef KRATOS_ESTIMATE_DT_UTILITIES_H
16 #define KRATOS_ESTIMATE_DT_UTILITIES_H
17 
18 // System includes
19 
20 
21 // External includes
22 
23 
24 // Project includes
25 #include "includes/define.h"
26 #include "includes/model_part.h"
28 #include "includes/serializer.h"
29 
30 // Application includes
31 
32 
33 namespace Kratos
34 {
35 
38 
41 
43 class KRATOS_API(FLUID_DYNAMICS_APPLICATION) EstimateDtUtility
44 {
45 public:
46 
49 
52 
54  typedef std::function<double(const Geometry<Node>&)> ElementSizeFunctionType;
55 
56  // Function type for the CFL calculator function
57  typedef std::function<double(const Element &, const ElementSizeFunctionType &, const double)> CFLCalculatorType;
58 
62 
64 
72  const double CFL,
73  const double DtMin,
74  const double DtMax)
75  : mrModelPart(ModelPart)
76  {
77  mCFL = CFL;
78  mDtMin = DtMin;
79  mDtMax = DtMax;
80  mViscousFourier = 0.0;
81  mThermalFourier = 0.0;
82  mConsiderArtificialDiffusion = false;
83  mConsiderCompressibilityInCFL = false;
84 
85  SetDtEstimationMagnitudesFlag();
86  }
87 
89 
100  const double CFL,
101  const double ViscousFourier,
102  const double ThermalFourier,
103  const bool ConsiderArtificialDiffusion,
104  const bool NodalDensityFormulation,
105  const double DtMin,
106  const double DtMax,
107  const bool ConsiderCompressibilityInCFL = false)
108  : mrModelPart(ModelPart)
109  {
110  mCFL = CFL;
111  mDtMin = DtMin;
112  mDtMax = DtMax;
113  mViscousFourier = ViscousFourier;
114  mThermalFourier = ThermalFourier;
115  mConsiderArtificialDiffusion = ConsiderArtificialDiffusion;
116  mNodalDensityFormulation = NodalDensityFormulation;
117  mConsiderCompressibilityInCFL = ConsiderCompressibilityInCFL;
118 
119  SetDtEstimationMagnitudesFlag();
120  }
121 
123 
129  Parameters& rParameters)
130  : mrModelPart(ModelPart)
131  {
132  Parameters defaultParameters(R"({
133  "automatic_time_step" : true,
134  "CFL_number" : 1.0,
135  "Viscous_Fourier_number" : 0.0,
136  "Thermal_Fourier_number" : 0.0,
137  "consider_artificial_diffusion" : false,
138  "nodal_density_formulation" : false,
139  "minimum_delta_time" : 1e-4,
140  "maximum_delta_time" : 0.1,
141  "consider_compressibility_in_CFL" : false
142  })");
143 
144  rParameters.ValidateAndAssignDefaults(defaultParameters);
145 
146  mCFL = rParameters["CFL_number"].GetDouble();
147  mViscousFourier = rParameters["Viscous_Fourier_number"].GetDouble();
148  mThermalFourier = rParameters["Thermal_Fourier_number"].GetDouble();
149  mConsiderArtificialDiffusion = rParameters["consider_artificial_diffusion"].GetBool();
150  mNodalDensityFormulation = rParameters["nodal_density_formulation"].GetBool();
151  mDtMin = rParameters["minimum_delta_time"].GetDouble();
152  mDtMax = rParameters["maximum_delta_time"].GetDouble();
153  mConsiderCompressibilityInCFL = rParameters["consider_compressibility_in_CFL"].GetBool();
154 
155  SetDtEstimationMagnitudesFlag();
156  }
157 
160  {}
161 
165 
171  void SetCFL(const double CFL);
172 
178  void SetViscousFourier(const double ViscousFourier);
179 
185  void SetThermalFourier(const double ThermalFourier);
186 
192  void SetDtMin(const double DtMin);
193 
199  void SetDtMax(const double DtMax);
200 
207  double EstimateDt() const;
208 
210 
211 private:
212 
215 
217  KRATOS_DEFINE_LOCAL_FLAG(CFL_ESTIMATION);
218  KRATOS_DEFINE_LOCAL_FLAG(VISCOUS_FOURIER_ESTIMATION);
219  KRATOS_DEFINE_LOCAL_FLAG(THERMAL_FOURIER_ESTIMATION);
220 
224 
225  double mCFL; // User-defined CFL number
226  double mViscousFourier; // User-defined viscous Fourier number
227  double mThermalFourier; // User-defined thermal Fourier number
228  bool mConsiderArtificialDiffusion; // Speficies if the artificial diffusion values are considered in the Peclet numbers
229  bool mNodalDensityFormulation; // Specifies if the density is nodally stored (only required for the Peclet number)
230  double mDtMax; // User-defined maximum time increment allowed
231  double mDtMin; // User-defined minimum time increment allowed
232  bool mConsiderCompressibilityInCFL;// User-defined formulation. CFL number depends on this parameter.
233  Flags mDtEstimationMagnitudesFlags; // Flags indicating the reference magnitudes used in the Dt estimation
234  ModelPart &mrModelPart; // The problem's model part
235 
239 
240 
244 
245  void SetDtEstimationMagnitudesFlag();
246 
247  template<const bool ConsiderCFL, const bool ConsiderViscousFourier, const bool ConsiderThermalFourier>
248  double InternalEstimateDt() const;
249 
261  template <class... CharacteristicNumbersPairsType>
262  double CalculateNewDeltaTime(
263  const double CurrentDeltaTime,
264  const CharacteristicNumbersPairsType&... rCharacteristicNumbersPairs) const
265  {
266  KRATOS_TRY
267 
268  // Calculate the corresponding new time increments from the provided pairs
269  const double zero_tol = std::min(0.1 * mDtMin, 1e-10);
270  double new_dt_list[sizeof...(CharacteristicNumbersPairsType)] = {(
271  (std::get<0>(rCharacteristicNumbersPairs) > zero_tol) ? CurrentDeltaTime * std::get<1>(rCharacteristicNumbersPairs) / std::get<0>(rCharacteristicNumbersPairs) : mDtMin
272  )...};
273 
274  // Get the minimum one among all the obtained ones and check the user-defined bounds
275  double new_dt = *(std::min_element(new_dt_list, new_dt_list + sizeof...(CharacteristicNumbersPairsType)));
276  LimitNewDeltaTime(new_dt);
277 
278  // Perform MPI sync if needed
279  new_dt = mrModelPart.GetCommunicator().GetDataCommunicator().MinAll(new_dt);
280 
281  return new_dt;
282 
283  KRATOS_CATCH("");
284  }
285 
292  void LimitNewDeltaTime(double& rNewDeltaTime) const;
293 
294 
301  const CFLCalculatorType GetCFLCalculatorUtility() const;
302 
304 };
305 
307 
309 
310 } // namespace Kratos.
311 
312 
313 #endif /* KRATOS_ESTIMATE_DT_UTILITIES_H */
Base class for all Elements.
Definition: element.h:60
Estimate the time step in a fluid problem to obtain a given Courant number.
Definition: estimate_dt_utilities.h:44
std::function< double(const Geometry< Node > &)> ElementSizeFunctionType
Function type for the element size calculator function.
Definition: estimate_dt_utilities.h:54
EstimateDtUtility(ModelPart &ModelPart, const double CFL, const double DtMin, const double DtMax)
Constructor for CFD-based time step estimation.
Definition: estimate_dt_utilities.h:70
KRATOS_CLASS_POINTER_DEFINITION(EstimateDtUtility)
Pointer definition of EstimateDtUtility.
std::function< double(const Element &, const ElementSizeFunctionType &, const double)> CFLCalculatorType
Definition: estimate_dt_utilities.h:57
EstimateDtUtility(ModelPart &ModelPart, const double CFL, const double ViscousFourier, const double ThermalFourier, const bool ConsiderArtificialDiffusion, const bool NodalDensityFormulation, const double DtMin, const double DtMax, const bool ConsiderCompressibilityInCFL=false)
Complete constructor.
Definition: estimate_dt_utilities.h:98
~EstimateDtUtility()
Destructor.
Definition: estimate_dt_utilities.h:159
EstimateDtUtility(ModelPart &ModelPart, Parameters &rParameters)
Constructor with Kratos parameters.
Definition: estimate_dt_utilities.h:127
Definition: flags.h:58
Geometry base class.
Definition: geometry.h:71
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
double GetDouble() const
This method returns the double contained in the current Parameter.
Definition: kratos_parameters.cpp:657
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
bool GetBool() const
This method returns the boolean contained in the current Parameter.
Definition: kratos_parameters.cpp:675
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_DEFINE_LOCAL_FLAG(name)
Definition: define.h:673
#define KRATOS_TRY
Definition: define.h:109
static double min(double a, double b)
Definition: GeometryFunctions.h:71
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
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
CFL
Definition: isotropic_damage_automatic_differentiation.py:156
e
Definition: run_cpp_mpi_tests.py:31