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.
two_step_v_p_thermal_strategy.h
Go to the documentation of this file.
1 //
2 // Project Name: KratosPFEMFluidDynamicsApplication $
3 // Last modified by: $Author: AFranci $
4 // Date: $Date: January 2023 $
5 // Revision: $Revision: 0.0 $
6 //
7 //
8 
9 #ifndef KRATOS_TWO_STEP_V_P_THERMAL_STRATEGY_H
10 #define KRATOS_TWO_STEP_V_P_THERMAL_STRATEGY_H
11 
12 #include "includes/define.h"
13 #include "includes/model_part.h"
15 #include "includes/cfd_variables.h"
16 #include "utilities/openmp_utils.h"
17 #include "processes/process.h"
22 
27 
28 #include "custom_utilities/solver_settings.h"
29 
31 
33 
35 
37 
38 #include <stdio.h>
39 #include <cmath>
40 
41 namespace Kratos
42 {
43 
46 
49 
53 
55 
58 
62 
66 
67  template <class TSparseSpace,
68  class TDenseSpace,
69  class TLinearSolver>
70  class TwoStepVPThermalStrategy : public TwoStepVPStrategy<TSparseSpace, TDenseSpace, TLinearSolver>
71  {
72  public:
76 
78 
79  typedef typename BaseType::TDataType TDataType;
80 
82 
84 
86 
88 
90 
92 
94 
106 
108  typename TLinearSolver::Pointer pVelocityLinearSolver,
109  typename TLinearSolver::Pointer pPressureLinearSolver,
110  bool ReformDofSet = true,
111  double VelTol = 0.0001,
112  double PresTol = 0.0001,
113  int MaxPressureIterations = 1, // Only for predictor-corrector
114  unsigned int TimeOrder = 2,
115  unsigned int DomainSize = 2) : BaseType(rModelPart,
116  pVelocityLinearSolver,
117  pPressureLinearSolver,
118  ReformDofSet,
119  VelTol,
120  PresTol,
121  MaxPressureIterations,
122  TimeOrder,
123  DomainSize)
124  {
125  KRATOS_TRY;
126 
128 
129  // Check that input parameters are reasonable and sufficient.
130  this->Check();
131 
132  bool CalculateNormDxFlag = true;
133 
134  bool ReformDofAtEachIteration = false; // DofSet modifiaction is managed by the fractional step strategy, auxiliary strategies should not modify the DofSet directly.
135 
136  // Additional Typedefs
137  typedef typename BuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver>::Pointer BuilderSolverTypePointer;
139 
140  // initializing fractional velocity solution step
141  typedef Scheme<TSparseSpace, TDenseSpace> SchemeType;
142  typename SchemeType::Pointer pScheme;
143 
144  typename SchemeType::Pointer Temp = typename SchemeType::Pointer(new ResidualBasedIncrementalUpdateStaticScheme<TSparseSpace, TDenseSpace>());
145  pScheme.swap(Temp);
146 
147  // CONSTRUCTION OF VELOCITY
148  BuilderSolverTypePointer vel_build = BuilderSolverTypePointer(new ResidualBasedBlockBuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver>(pVelocityLinearSolver));
149 
150  this->mpMomentumStrategy = typename BaseType::Pointer(new GaussSeidelLinearStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(rModelPart, pScheme, pVelocityLinearSolver, vel_build, ReformDofAtEachIteration, CalculateNormDxFlag));
151 
152  vel_build->SetCalculateReactionsFlag(false);
153 
154  BuilderSolverTypePointer pressure_build = BuilderSolverTypePointer(new ResidualBasedBlockBuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver>(pPressureLinearSolver));
155 
156  this->mpPressureStrategy = typename BaseType::Pointer(new GaussSeidelLinearStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(rModelPart, pScheme, pPressureLinearSolver, pressure_build, ReformDofAtEachIteration, CalculateNormDxFlag));
157 
158  pressure_build->SetCalculateReactionsFlag(false);
159 
160  KRATOS_CATCH("");
161  }
162 
165 
169 
173 
175  std::string Info() const override
176  {
177  std::stringstream buffer;
178  buffer << "TwoStepVPThermalStrategy";
179  return buffer.str();
180  }
181 
183  void PrintInfo(std::ostream &rOStream) const override
184  {
185  rOStream << "TwoStepVPThermalStrategy";
186  }
187 
189  void PrintData(std::ostream &rOStream) const override
190  {
191  }
192 
196 
198 
199  protected:
202 
206 
210 
214 
218 
220 
224  bool SolveSolutionStep() override
225  {
226  ModelPart &rModelPart = BaseType::GetModelPart();
227  ProcessInfo &rCurrentProcessInfo = rModelPart.GetProcessInfo();
228  double currentTime = rCurrentProcessInfo[TIME];
229  double timeInterval = rCurrentProcessInfo[DELTA_TIME];
230  bool timeIntervalChanged = rCurrentProcessInfo[TIME_INTERVAL_CHANGED];
231  unsigned int stepsWithChangedDt = rCurrentProcessInfo[STEPS_WITH_CHANGED_DT];
232  bool converged = false;
233 
234  unsigned int maxNonLinearIterations = mMaxPressureIter;
235 
236  KRATOS_INFO("\nSolution with two_step_vp_thermal_strategy at t=") << currentTime << "s" << std::endl;
237 
238  if ((timeIntervalChanged == true && currentTime > 10 * timeInterval) || stepsWithChangedDt > 0)
239  {
240  maxNonLinearIterations *= 2;
241  }
242  if (currentTime < 10 * timeInterval)
243  {
244  if (BaseType::GetEchoLevel() > 1)
245  std::cout << "within the first 10 time steps, I consider the given iteration number x3" << std::endl;
246  maxNonLinearIterations *= 3;
247  }
248  if (currentTime < 20 * timeInterval && currentTime >= 10 * timeInterval)
249  {
250  if (BaseType::GetEchoLevel() > 1)
251  std::cout << "within the second 10 time steps, I consider the given iteration number x2" << std::endl;
252  maxNonLinearIterations *= 2;
253  }
254  bool momentumConverged = true;
255  bool continuityConverged = false;
256  bool fixedTimeStep = false;
257 
258  double pressureNorm = 0;
259  double velocityNorm = 0;
260 
262 
263  for (unsigned int it = 0; it < maxNonLinearIterations; ++it)
264  {
265  momentumConverged = this->SolveMomentumIteration(it, maxNonLinearIterations, fixedTimeStep, velocityNorm);
266 
267  this->UpdateTopology(rModelPart, BaseType::GetEchoLevel());
268 
269  if (fixedTimeStep == false)
270  {
271  continuityConverged = this->SolveContinuityIteration(it, maxNonLinearIterations, pressureNorm);
272  }
273  if (it == maxNonLinearIterations - 1 || ((continuityConverged && momentumConverged) && it > 2))
274  {
276  }
277 
278  if ((continuityConverged && momentumConverged) && it > 2)
279  {
280  rCurrentProcessInfo.SetValue(BAD_VELOCITY_CONVERGENCE, false);
281  rCurrentProcessInfo.SetValue(BAD_PRESSURE_CONVERGENCE, false);
282  converged = true;
283 
284  KRATOS_INFO("TwoStepVPThermalStrategy") << "V-P thermal strategy converged in " << it + 1 << " iterations." << std::endl;
285 
286  break;
287  }
288  if (fixedTimeStep == true)
289  {
290  break;
291  }
292  }
293 
294  if (!continuityConverged && !momentumConverged && BaseType::GetEchoLevel() > 0 && rModelPart.GetCommunicator().MyPID() == 0)
295  std::cout << "Convergence tolerance not reached." << std::endl;
296 
297  if (mReformDofSet)
298  this->Clear();
299 
300  return converged;
301  }
302 
304  {
305  ModelPart &rModelPart = BaseType::GetModelPart();
306  const ProcessInfo &rCurrentProcessInfo = rModelPart.GetProcessInfo();
307 
308 #pragma omp parallel
309  {
310  ModelPart::ElementIterator ElemBegin;
312  OpenMPUtils::PartitionedIterators(rModelPart.Elements(), ElemBegin, ElemEnd);
313  for (ModelPart::ElementIterator itElem = ElemBegin; itElem != ElemEnd; ++itElem)
314  {
315  itElem->InitializeNonLinearIteration(rCurrentProcessInfo);
316  }
317  }
318 
320 
321  Parameters extrapolation_parameters(R"(
322  {
323  "list_of_variables": ["MECHANICAL_DISSIPATION"]
324  })");
325  auto extrapolation_process = IntegrationValuesExtrapolationToNodesProcess(rModelPart, extrapolation_parameters);
326  extrapolation_process.Execute();
327 
328  const auto &this_var = KratosComponents<Variable<double>>::Get("MECHANICAL_DISSIPATION");
329  for (auto &node : rModelPart.Nodes())
330  {
331  node.FastGetSolutionStepValue(HEAT_FLUX) = node.GetValue(this_var);
332  }
333 
334  }
335 
336  void SetEchoLevel(int Level) override
337  {
338  BaseType::SetEchoLevel(Level);
339  int StrategyLevel = Level > 0 ? Level - 1 : 0;
340  mpMomentumStrategy->SetEchoLevel(StrategyLevel);
341  mpPressureStrategy->SetEchoLevel(StrategyLevel);
342  }
343 
347 
351 
355 
357 
360 
364 
365  // Fractional step index.
366  /* 1 : Momentum step (calculate fractional step velocity)
367  * 2-3 : Unused (reserved for componentwise calculation of frac step velocity)
368  * 4 : Pressure step
369  * 5 : Computation of projections
370  * 6 : End of step velocity
371  */
372  // unsigned int mStepId;
373 
376 
379 
383 
387 
391 
395 
399 
402 
405 
407 
408  };
409 
413 
415 
417 
418 } // namespace Kratos.
419 
420 #endif // KRATOS_TWO_STEP_V_P_STRATEGY_H
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
virtual int MyPID() const
Definition: communicator.cpp:91
void SetValue(const Variable< TDataType > &rThisVariable, TDataType const &rValue)
Sets the value for a given variable.
Definition: data_value_container.h:320
Short class definition.
Definition: gauss_seidel_linear_strategy.h:83
Implicit solving strategy base class This is the base class from which we will derive all the implici...
Definition: implicit_solving_strategy.h:61
This process extrapolates vales from the integration points to the nodes.
Definition: integration_values_extrapolation_to_nodes_process.h:59
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Communicator & GetCommunicator()
Definition: model_part.h:1821
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
MeshType::ElementIterator ElementIterator
Definition: model_part.h:174
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
static void PartitionedIterators(TVector &rVector, typename TVector::iterator &rBegin, typename TVector::iterator &rEnd)
Generate a partition for an std::vector-like array, providing iterators to the begin and end position...
Definition: openmp_utils.h:179
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
Current class provides an implementation for standard builder and solving operations.
Definition: residualbased_block_builder_and_solver.h:82
This class provides the implementation of a static scheme.
Definition: residualbased_incrementalupdate_static_scheme.h:57
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
TDenseSpace::MatrixType LocalSystemMatrixType
Definition: solving_strategy.h:79
TSparseSpace::DataType TDataType
Definition: solving_strategy.h:69
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solving_strategy.h:350
int GetEchoLevel()
This returns the level of echo for the solving strategy.
Definition: solving_strategy.h:271
TSparseSpace::MatrixType TSystemMatrixType
Definition: solving_strategy.h:71
TSparseSpace::VectorType TSystemVectorType
Definition: solving_strategy.h:73
TDenseSpace::VectorType LocalSystemVectorType
Definition: solving_strategy.h:81
Helper class to define solution strategies for TwoStepVPStrategy.
Definition: solver_settings.h:57
Definition: two_step_v_p_strategy.h:71
bool SolveContinuityIteration(unsigned int it, unsigned int maxIt, double &NormP) override
Definition: two_step_v_p_strategy.h:457
int Check() override
Function to perform expensive checks.
Definition: two_step_v_p_strategy.h:158
bool SolveMomentumIteration(unsigned int it, unsigned int maxIt, bool &fixedTimeStep, double &velocityNorm) override
Calculate the coefficients for time iteration.
Definition: two_step_v_p_strategy.h:407
void Clear() override
Clears the internal storage.
Definition: two_step_v_p_strategy.h:331
bool mReformDofSet
Definition: two_step_v_p_strategy.h:767
unsigned int mMaxPressureIter
Definition: two_step_v_p_strategy.h:761
void SetEchoLevel(int Level) override
This sets the level of echo for the solving strategy.
Definition: two_step_v_p_strategy.h:341
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver >::Pointer StrategyPointerType
Definition: two_step_v_p_strategy.h:91
Definition: two_step_v_p_thermal_strategy.h:71
BaseType::TSystemMatrixType TSystemMatrixType
Definition: two_step_v_p_thermal_strategy.h:83
void SetEchoLevel(int Level) override
This sets the level of echo for the solving strategy.
Definition: two_step_v_p_thermal_strategy.h:336
BaseType::TDataType TDataType
Definition: two_step_v_p_thermal_strategy.h:79
BaseType::TSystemVectorType TSystemVectorType
Definition: two_step_v_p_thermal_strategy.h:85
bool SolveSolutionStep() override
Calculate the coefficients for time iteration.
Definition: two_step_v_p_thermal_strategy.h:224
StrategyPointerType mpPressureStrategy
Scheme for the solution of the mass equation.
Definition: two_step_v_p_thermal_strategy.h:378
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver >::Pointer StrategyPointerType
Definition: two_step_v_p_thermal_strategy.h:91
TwoStepVPThermalStrategy(TwoStepVPThermalStrategy const &rOther)
Copy constructor.
Definition: two_step_v_p_thermal_strategy.h:404
KRATOS_CLASS_POINTER_DEFINITION(TwoStepVPThermalStrategy)
virtual ~TwoStepVPThermalStrategy()
Destructor.
Definition: two_step_v_p_thermal_strategy.h:164
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: two_step_v_p_thermal_strategy.h:89
TwoStepVPThermalStrategy & operator=(TwoStepVPThermalStrategy const &rOther)
Assignment operator.
Definition: two_step_v_p_thermal_strategy.h:401
TwoStepVPSolverSettings< TSparseSpace, TDenseSpace, TLinearSolver > SolverSettingsType
Definition: two_step_v_p_thermal_strategy.h:93
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: two_step_v_p_thermal_strategy.h:189
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: two_step_v_p_thermal_strategy.h:87
BaseType::DofsArrayType DofsArrayType
Definition: two_step_v_p_thermal_strategy.h:81
std::string Info() const override
Turn back information as a string.
Definition: two_step_v_p_thermal_strategy.h:175
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: two_step_v_p_thermal_strategy.h:183
void UpdateThermalStressStrain()
Definition: two_step_v_p_thermal_strategy.h:303
TwoStepVPThermalStrategy(ModelPart &rModelPart, typename TLinearSolver::Pointer pVelocityLinearSolver, typename TLinearSolver::Pointer pPressureLinearSolver, bool ReformDofSet=true, double VelTol=0.0001, double PresTol=0.0001, int MaxPressureIterations=1, unsigned int TimeOrder=2, unsigned int DomainSize=2)
Definition: two_step_v_p_thermal_strategy.h:107
StrategyPointerType mpMomentumStrategy
Scheme for the solution of the momentum equation.
Definition: two_step_v_p_thermal_strategy.h:375
TwoStepVPStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: two_step_v_p_thermal_strategy.h:77
Definition: v_p_strategy.h:59
virtual void CalculateTemporalVariables()
Definition: v_p_strategy.h:274
void UpdateTopology(ModelPart &rModelPart, unsigned int echoLevel)
Definition: v_p_strategy.h:107
void SetBlockedAndIsolatedFlags()
Definition: v_p_strategy.h:116
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_INFO(label)
Definition: logger.h:250
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
Temp
Definition: PecletTest.py:105
ReformDofAtEachIteration
Definition: test_pureconvectionsolver_benchmarking.py:131
Definition: mesh_converter.cpp:38