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_strategy.h
Go to the documentation of this file.
1 //
2 // Project Name: KratosPFEMFluidDynamicsApplication $
3 // Last modified by: $Author: AFranci $
4 // Date: $Date: January 2016 $
5 // Revision: $Revision: 0.0 $
6 //
7 //
8 
9 #ifndef KRATOS_TWO_STEP_V_P_STRATEGY_H
10 #define KRATOS_TWO_STEP_V_P_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 
36 #include "v_p_strategy.h"
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 TwoStepVPStrategy : public VPStrategy<TSparseSpace, TDenseSpace, TLinearSolver>
71  {
72  public:
76 
78 
79  typedef typename BaseType::TDataType TDataType;
80 
82 
84 
86 
88 
90 
92 
94 
98 
100  typename TLinearSolver::Pointer pVelocityLinearSolver,
101  typename TLinearSolver::Pointer pPressureLinearSolver,
102  bool ReformDofSet = true,
103  double VelTol = 0.0001,
104  double PresTol = 0.0001,
105  int MaxPressureIterations = 1, // Only for predictor-corrector
106  unsigned int TimeOrder = 2,
107  unsigned int DomainSize = 2) : BaseType(rModelPart, pVelocityLinearSolver, pPressureLinearSolver, ReformDofSet, DomainSize),
108  mVelocityTolerance(VelTol),
109  mPressureTolerance(PresTol),
110  mMaxPressureIter(MaxPressureIterations),
111  mDomainSize(DomainSize),
112  mTimeOrder(TimeOrder),
113  mReformDofSet(ReformDofSet)
114  {
115  KRATOS_TRY;
116 
118 
119  // Check that input parameters are reasonable and sufficient.
120  this->Check();
121 
122  bool CalculateNormDxFlag = true;
123 
124  bool ReformDofAtEachIteration = false; // DofSet modifiaction is managed by the fractional step strategy, auxiliary strategies should not modify the DofSet directly.
125 
126  // Additional Typedefs
127  typedef typename BuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver>::Pointer BuilderSolverTypePointer;
129 
130  // initializing fractional velocity solution step
131  typedef Scheme<TSparseSpace, TDenseSpace> SchemeType;
132  typename SchemeType::Pointer pScheme;
133 
134  typename SchemeType::Pointer Temp = typename SchemeType::Pointer(new ResidualBasedIncrementalUpdateStaticScheme<TSparseSpace, TDenseSpace>());
135  pScheme.swap(Temp);
136 
137  // CONSTRUCTION OF VELOCITY
138  // BuilderSolverTypePointer vel_build = BuilderSolverTypePointer(new ResidualBasedEliminationBuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver>(pVelocityLinearSolver));
139  BuilderSolverTypePointer vel_build = BuilderSolverTypePointer(new ResidualBasedBlockBuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver>(pVelocityLinearSolver));
140 
141  this->mpMomentumStrategy = typename BaseType::Pointer(new GaussSeidelLinearStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(rModelPart, pScheme, pVelocityLinearSolver, vel_build, ReformDofAtEachIteration, CalculateNormDxFlag));
142 
143  vel_build->SetCalculateReactionsFlag(false);
144 
145  /* BuilderSolverTypePointer pressure_build = BuilderSolverTypePointer(new ResidualBasedEliminationBuilderAndSolverComponentwise<TSparseSpace, TDenseSpace, TLinearSolver, Variable<double> >(pPressureLinearSolver, PRESSURE)); */
146  BuilderSolverTypePointer pressure_build = BuilderSolverTypePointer(new ResidualBasedBlockBuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver>(pPressureLinearSolver));
147 
148  this->mpPressureStrategy = typename BaseType::Pointer(new GaussSeidelLinearStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(rModelPart, pScheme, pPressureLinearSolver, pressure_build, ReformDofAtEachIteration, CalculateNormDxFlag));
149 
150  pressure_build->SetCalculateReactionsFlag(false);
151 
152  KRATOS_CATCH("");
153  }
154 
156  virtual ~TwoStepVPStrategy() {}
157 
158  int Check() override
159  {
160  KRATOS_TRY;
161 
162  // Check elements and conditions in the model part
163  int ierr = BaseType::Check();
164  if (ierr != 0)
165  return ierr;
166 
167  if (DELTA_TIME.Key() == 0)
168  KRATOS_THROW_ERROR(std::runtime_error, "DELTA_TIME Key is 0. Check that the application was correctly registered.", "");
169 
170  ModelPart &rModelPart = BaseType::GetModelPart();
171 
172  const auto &r_current_process_info = rModelPart.GetProcessInfo();
173  for (const auto &r_element : rModelPart.Elements())
174  {
175  ierr = r_element.Check(r_current_process_info);
176  if (ierr != 0)
177  {
178  break;
179  }
180  }
181 
182  return ierr;
183 
184  KRATOS_CATCH("");
185  }
186 
187  void SetTimeCoefficients(ProcessInfo &rCurrentProcessInfo)
188  {
189  KRATOS_TRY;
190 
191  if (mTimeOrder == 2)
192  {
193  // calculate the BDF coefficients
194  double Dt = rCurrentProcessInfo[DELTA_TIME];
195  double OldDt = rCurrentProcessInfo.GetPreviousTimeStepInfo(1)[DELTA_TIME];
196 
197  double Rho = OldDt / Dt;
198  double TimeCoeff = 1.0 / (Dt * Rho * Rho + Dt * Rho);
199 
200  Vector &BDFcoeffs = rCurrentProcessInfo[BDF_COEFFICIENTS];
201  BDFcoeffs.resize(3, false);
202 
203  BDFcoeffs[0] = TimeCoeff * (Rho * Rho + 2.0 * Rho); // coefficient for step n+1 (3/2Dt if Dt is constant)
204  BDFcoeffs[1] = -TimeCoeff * (Rho * Rho + 2.0 * Rho + 1.0); // coefficient for step n (-4/2Dt if Dt is constant)
205  BDFcoeffs[2] = TimeCoeff; // coefficient for step n-1 (1/2Dt if Dt is constant)
206  }
207  else if (mTimeOrder == 1)
208  {
209  double Dt = rCurrentProcessInfo[DELTA_TIME];
210  double TimeCoeff = 1.0 / Dt;
211 
212  Vector &BDFcoeffs = rCurrentProcessInfo[BDF_COEFFICIENTS];
213  BDFcoeffs.resize(2, false);
214 
215  BDFcoeffs[0] = TimeCoeff; // coefficient for step n+1 (1/Dt)
216  BDFcoeffs[1] = -TimeCoeff; // coefficient for step n (-1/Dt)
217  }
218 
219  KRATOS_CATCH("");
220  }
221 
222  bool SolveSolutionStep() override
223  {
224  ModelPart &rModelPart = BaseType::GetModelPart();
225  ProcessInfo &rCurrentProcessInfo = rModelPart.GetProcessInfo();
226  double currentTime = rCurrentProcessInfo[TIME];
227  double timeInterval = rCurrentProcessInfo[DELTA_TIME];
228  bool timeIntervalChanged = rCurrentProcessInfo[TIME_INTERVAL_CHANGED];
229  unsigned int stepsWithChangedDt = rCurrentProcessInfo[STEPS_WITH_CHANGED_DT];
230  bool converged = false;
231 
232  unsigned int maxNonLinearIterations = mMaxPressureIter;
233 
234  KRATOS_INFO("\nSolution with two_step_vp_strategy at t=") << currentTime << "s" << std::endl;
235 
236  if ((timeIntervalChanged == true && currentTime > 10 * timeInterval) || stepsWithChangedDt > 0)
237  {
238  maxNonLinearIterations *= 2;
239  }
240  if (currentTime < 10 * timeInterval)
241  {
242  if (BaseType::GetEchoLevel() > 1)
243  std::cout << "within the first 10 time steps, I consider the given iteration number x3" << std::endl;
244  maxNonLinearIterations *= 3;
245  }
246  if (currentTime < 20 * timeInterval && currentTime >= 10 * timeInterval)
247  {
248  if (BaseType::GetEchoLevel() > 1)
249  std::cout << "within the second 10 time steps, I consider the given iteration number x2" << std::endl;
250  maxNonLinearIterations *= 2;
251  }
252  bool momentumConverged = true;
253  bool continuityConverged = false;
254  bool fixedTimeStep = false;
255 
256  double pressureNorm = 0;
257  double velocityNorm = 0;
258 
260 
261  for (unsigned int it = 0; it < maxNonLinearIterations; ++it)
262  {
263  momentumConverged = this->SolveMomentumIteration(it, maxNonLinearIterations, fixedTimeStep, velocityNorm);
264 
265  this->UpdateTopology(rModelPart, BaseType::GetEchoLevel());
266 
267  if (fixedTimeStep == false)
268  {
269  continuityConverged = this->SolveContinuityIteration(it, maxNonLinearIterations, pressureNorm);
270  }
271  if (it == maxNonLinearIterations - 1 || ((continuityConverged && momentumConverged) && it > 2))
272  {
273 
274  // double tensilStressSign = 1.0;
275  // ComputeErrorL2Norm(tensilStressSign);
276  this->UpdateStressStrain();
277  }
278 
279  if ((continuityConverged && momentumConverged) && it > 2)
280  {
281  rCurrentProcessInfo.SetValue(BAD_VELOCITY_CONVERGENCE, false);
282  rCurrentProcessInfo.SetValue(BAD_PRESSURE_CONVERGENCE, false);
283  converged = true;
284 
285  KRATOS_INFO("TwoStepVPStrategy") << "V-P strategy converged in " << it + 1 << " iterations." << std::endl;
286 
287  break;
288  }
289  if (fixedTimeStep == true)
290  {
291  break;
292  }
293  }
294 
295  if (!continuityConverged && !momentumConverged && BaseType::GetEchoLevel() > 0 && rModelPart.GetCommunicator().MyPID() == 0)
296  std::cout << "Convergence tolerance not reached." << std::endl;
297 
298  if (mReformDofSet)
299  this->Clear();
300 
301  return converged;
302  }
303 
304  void FinalizeSolutionStep() override
305  {
306  }
307 
308  void InitializeSolutionStep() override
309  {
310  }
311 
312  void UpdateStressStrain() override
313  {
314  ModelPart &rModelPart = BaseType::GetModelPart();
315  const ProcessInfo &rCurrentProcessInfo = rModelPart.GetProcessInfo();
316 
317 #pragma omp parallel
318  {
319  ModelPart::ElementIterator ElemBegin;
321  OpenMPUtils::PartitionedIterators(rModelPart.Elements(), ElemBegin, ElemEnd);
322  for (ModelPart::ElementIterator itElem = ElemBegin; itElem != ElemEnd; ++itElem)
323  {
324  itElem->InitializeNonLinearIteration(rCurrentProcessInfo);
325  }
326  }
327 
329  }
330 
331  void Clear() override
332  {
333  mpMomentumStrategy->Clear();
334  mpPressureStrategy->Clear();
335  }
336 
340 
341  void SetEchoLevel(int Level) override
342  {
343  BaseType::SetEchoLevel(Level);
344  int StrategyLevel = Level > 0 ? Level - 1 : 0;
345  mpMomentumStrategy->SetEchoLevel(StrategyLevel);
346  mpPressureStrategy->SetEchoLevel(StrategyLevel);
347  }
348 
352 
356 
358  std::string Info() const override
359  {
360  std::stringstream buffer;
361  buffer << "TwoStepVPStrategy";
362  return buffer.str();
363  }
364 
366  void PrintInfo(std::ostream &rOStream) const override
367  {
368  rOStream << "TwoStepVPStrategy";
369  }
370 
372  void PrintData(std::ostream &rOStream) const override
373  {
374  }
375 
379 
381 
382  protected:
385 
389 
393 
397 
401 
403 
407  bool SolveMomentumIteration(unsigned int it, unsigned int maxIt, bool &fixedTimeStep, double &velocityNorm) override
408  {
409 
410  ModelPart &rModelPart = BaseType::GetModelPart();
411  int Rank = rModelPart.GetCommunicator().MyPID();
412  bool ConvergedMomentum = false;
413  double NormDv = 0;
414  fixedTimeStep = false;
415  // build momentum system and solve for fractional step velocity increment
416  rModelPart.GetProcessInfo().SetValue(FRACTIONAL_STEP, 1);
417 
418  if (it == 0)
419  {
420  mpMomentumStrategy->InitializeSolutionStep();
421  }
422 
423  NormDv = mpMomentumStrategy->Solve();
424 
425  if (BaseType::GetEchoLevel() > 1 && Rank == 0)
426  std::cout << "-------------- s o l v e d ! ------------------" << std::endl;
427 
428  if (it == 0)
429  {
430  velocityNorm = this->ComputeVelocityNorm();
431  }
432 
433  double DvErrorNorm = NormDv / velocityNorm;
434  unsigned int iterationForCheck = 2;
435  // Check convergence
436  if (it == maxIt - 1)
437  {
438  KRATOS_INFO("Iteration") << it << " Final Velocity error: " << DvErrorNorm << std::endl;
439  ConvergedMomentum = this->FixTimeStepMomentum(DvErrorNorm, fixedTimeStep);
440  }
441  else if (it > iterationForCheck)
442  {
443  KRATOS_INFO("Iteration") << it << " Velocity error: " << DvErrorNorm << std::endl;
444  ConvergedMomentum = this->CheckMomentumConvergence(DvErrorNorm, fixedTimeStep);
445  }
446  else
447  {
448  KRATOS_INFO("Iteration") << it << " Velocity error: " << DvErrorNorm << std::endl;
449  }
450 
451  if (!ConvergedMomentum && BaseType::GetEchoLevel() > 0 && Rank == 0)
452  std::cout << "Momentum equations did not reach the convergence tolerance." << std::endl;
453 
454  return ConvergedMomentum;
455  }
456 
457  bool SolveContinuityIteration(unsigned int it, unsigned int maxIt, double &NormP) override
458  {
459  ModelPart &rModelPart = BaseType::GetModelPart();
460  int Rank = rModelPart.GetCommunicator().MyPID();
461  bool ConvergedContinuity = false;
462  bool fixedTimeStep = false;
463  double NormDp = 0;
464 
465  // 2. Pressure solution
466  rModelPart.GetProcessInfo().SetValue(FRACTIONAL_STEP, 5);
467 
468  if (it == 0)
469  {
470  mpPressureStrategy->InitializeSolutionStep();
471  }
472  NormDp = mpPressureStrategy->Solve();
473 
474  if (BaseType::GetEchoLevel() > 0 && Rank == 0)
475  std::cout << "The norm of pressure is: " << NormDp << std::endl;
476 
477  if (it == 0)
478  {
479  NormP = this->ComputePressureNorm();
480  }
481 
482  double DpErrorNorm = NormDp / (NormP);
483 
484  // Check convergence
485  if (it == (maxIt - 1))
486  {
487  KRATOS_INFO("Iteration") << it << " Final Pressure error: " << DpErrorNorm << std::endl;
488  ConvergedContinuity = this->FixTimeStepContinuity(DpErrorNorm, fixedTimeStep);
489  }
490  else
491  {
492  KRATOS_INFO("Iteration") << it << " Pressure error: " << DpErrorNorm << std::endl;
493  ConvergedContinuity = this->CheckContinuityConvergence(DpErrorNorm, fixedTimeStep);
494  }
495 
496  if (!ConvergedContinuity && BaseType::GetEchoLevel() > 0 && Rank == 0)
497  std::cout << "Continuity equation did not reach the convergence tolerance." << std::endl;
498 
499  return ConvergedContinuity;
500  }
501 
502  bool CheckVelocityConvergence(const double NormDv, double &errorNormDv) override
503  {
504  ModelPart &rModelPart = BaseType::GetModelPart();
505  const int n_nodes = rModelPart.NumberOfNodes();
506 
507  double NormV = 0.00;
508  errorNormDv = 0;
509 
510 #pragma omp parallel for reduction(+ \
511  : NormV)
512  for (int i_node = 0; i_node < n_nodes; ++i_node)
513  {
514  const auto it_node = rModelPart.NodesBegin() + i_node;
515  const auto &r_vel = it_node->FastGetSolutionStepValue(VELOCITY);
516  for (unsigned int d = 0; d < 3; ++d)
517  {
518  NormV += r_vel[d] * r_vel[d];
519  }
520  }
521  NormV = BaseType::GetModelPart().GetCommunicator().GetDataCommunicator().SumAll(NormV);
522  NormV = sqrt(NormV);
523 
524  const double zero_tol = 1.0e-12;
525  errorNormDv = (NormV < zero_tol) ? NormDv : NormDv / NormV;
526 
527  if (BaseType::GetEchoLevel() > 0 && rModelPart.GetCommunicator().MyPID() == 0)
528  {
529  std::cout << "The norm of velocity increment is: " << NormDv << std::endl;
530  std::cout << "The norm of velocity is: " << NormV << std::endl;
531  std::cout << "Velocity error: " << errorNormDv << "mVelocityTolerance: " << mVelocityTolerance << std::endl;
532  }
533 
534  if (errorNormDv < mVelocityTolerance)
535  {
536  return true;
537  }
538  else
539  {
540  return false;
541  }
542  }
543 
544  bool CheckPressureConvergence(const double NormDp, double &errorNormDp, double &NormP) override
545  {
546  ModelPart &rModelPart = BaseType::GetModelPart();
547  const int n_nodes = rModelPart.NumberOfNodes();
548 
549  NormP = 0.00;
550  errorNormDp = 0;
551  double tmp_NormP = 0.0;
552 
553 #pragma omp parallel for reduction(+ : tmp_NormP)
554  for (int i_node = 0; i_node < n_nodes; ++i_node)
555  {
556  const auto it_node = rModelPart.NodesBegin() + i_node;
557  const double Pr = it_node->FastGetSolutionStepValue(PRESSURE);
558  tmp_NormP += Pr * Pr;
559  }
560  NormP = tmp_NormP;
561  NormP = BaseType::GetModelPart().GetCommunicator().GetDataCommunicator().SumAll(NormP);
562  NormP = sqrt(NormP);
563 
564  const double zero_tol = 1.0e-12;
565  errorNormDp = (NormP < zero_tol) ? NormDp : NormDp / NormP;
566 
567  if (BaseType::GetEchoLevel() > 0 && rModelPart.GetCommunicator().MyPID() == 0)
568  {
569  std::cout << " The norm of pressure increment is: " << NormDp << std::endl;
570  std::cout << " The norm of pressure is: " << NormP << std::endl;
571  std::cout << " Pressure error: " << errorNormDp << std::endl;
572  }
573 
574  if (errorNormDp < mPressureTolerance)
575  {
576  return true;
577  }
578  else
579  return false;
580  }
581 
582  bool FixTimeStepMomentum(const double DvErrorNorm, bool &fixedTimeStep) override
583  {
584  ModelPart &rModelPart = BaseType::GetModelPart();
585  ProcessInfo &rCurrentProcessInfo = rModelPart.GetProcessInfo();
586  double currentTime = rCurrentProcessInfo[TIME];
587  double timeInterval = rCurrentProcessInfo[DELTA_TIME];
588  double minTolerance = 0.005;
589  bool converged = false;
590 
591  if (currentTime < 10 * timeInterval)
592  {
593  minTolerance = 10;
594  }
595 
596  if ((DvErrorNorm > minTolerance || (DvErrorNorm < 0 && DvErrorNorm > 0) || (DvErrorNorm != DvErrorNorm)) &&
597  DvErrorNorm != 0 &&
598  (DvErrorNorm != 1 || currentTime > timeInterval))
599  {
600  rCurrentProcessInfo.SetValue(BAD_VELOCITY_CONVERGENCE, true);
601  std::cout << "NOT GOOD CONVERGENCE!!! I'll reduce the next time interval" << DvErrorNorm << std::endl;
602  minTolerance = 0.05;
603  if (DvErrorNorm > minTolerance)
604  {
605  std::cout << "BAD CONVERGENCE!!! I GO AHEAD WITH THE PREVIOUS VELOCITY AND PRESSURE FIELDS" << DvErrorNorm << std::endl;
606  fixedTimeStep = true;
607 #pragma omp parallel
608  {
609  ModelPart::NodeIterator NodeBegin;
610  ModelPart::NodeIterator NodeEnd;
611  OpenMPUtils::PartitionedIterators(rModelPart.Nodes(), NodeBegin, NodeEnd);
612  for (ModelPart::NodeIterator itNode = NodeBegin; itNode != NodeEnd; ++itNode)
613  {
614  itNode->FastGetSolutionStepValue(VELOCITY, 0) = itNode->FastGetSolutionStepValue(VELOCITY, 1);
615  itNode->FastGetSolutionStepValue(PRESSURE, 0) = itNode->FastGetSolutionStepValue(PRESSURE, 1);
616  itNode->FastGetSolutionStepValue(ACCELERATION, 0) = itNode->FastGetSolutionStepValue(ACCELERATION, 1);
617  }
618  }
619  }
620  }
621  else
622  {
623  rCurrentProcessInfo.SetValue(BAD_VELOCITY_CONVERGENCE, false);
624  if (DvErrorNorm < mVelocityTolerance)
625  {
626  converged = true;
627  }
628  }
629  return converged;
630  }
631 
632  bool CheckMomentumConvergence(const double DvErrorNorm, bool &fixedTimeStep) override
633  {
634  ModelPart &rModelPart = BaseType::GetModelPart();
635  ProcessInfo &rCurrentProcessInfo = rModelPart.GetProcessInfo();
636  double currentTime = rCurrentProcessInfo[TIME];
637  double timeInterval = rCurrentProcessInfo[DELTA_TIME];
638  double minTolerance = 0.99999;
639  bool converged = false;
640 
641  if ((DvErrorNorm > minTolerance || (DvErrorNorm < 0 && DvErrorNorm > 0) || (DvErrorNorm != DvErrorNorm)) &&
642  DvErrorNorm != 0 &&
643  (DvErrorNorm != 1 || currentTime > timeInterval))
644  {
645  rCurrentProcessInfo.SetValue(BAD_VELOCITY_CONVERGENCE, true);
646  std::cout << " BAD CONVERGENCE DETECTED DURING THE ITERATIVE LOOP!!! error: " << DvErrorNorm << " higher than 0.9999" << std::endl;
647  std::cout << " I GO AHEAD WITH THE PREVIOUS VELOCITY AND PRESSURE FIELDS" << std::endl;
648  fixedTimeStep = true;
649 #pragma omp parallel
650  {
651  ModelPart::NodeIterator NodeBegin;
652  ModelPart::NodeIterator NodeEnd;
653  OpenMPUtils::PartitionedIterators(rModelPart.Nodes(), NodeBegin, NodeEnd);
654  for (ModelPart::NodeIterator itNode = NodeBegin; itNode != NodeEnd; ++itNode)
655  {
656  itNode->FastGetSolutionStepValue(VELOCITY, 0) = itNode->FastGetSolutionStepValue(VELOCITY, 1);
657  itNode->FastGetSolutionStepValue(PRESSURE, 0) = itNode->FastGetSolutionStepValue(PRESSURE, 1);
658  itNode->FastGetSolutionStepValue(ACCELERATION, 0) = itNode->FastGetSolutionStepValue(ACCELERATION, 1);
659  }
660  }
661  }
662  else
663  {
664  rCurrentProcessInfo.SetValue(BAD_VELOCITY_CONVERGENCE, false);
665  if (DvErrorNorm < mVelocityTolerance)
666  {
667  converged = true;
668  }
669  }
670  return converged;
671  }
672 
673  bool FixTimeStepContinuity(const double DvErrorNorm, bool &fixedTimeStep) override
674  {
675  ModelPart &rModelPart = BaseType::GetModelPart();
676  ProcessInfo &rCurrentProcessInfo = rModelPart.GetProcessInfo();
677  double currentTime = rCurrentProcessInfo[TIME];
678  double timeInterval = rCurrentProcessInfo[DELTA_TIME];
679  double minTolerance = 0.01;
680  bool converged = false;
681  if (currentTime < 10 * timeInterval)
682  {
683  minTolerance = 10;
684  }
685 
686  if ((DvErrorNorm > minTolerance || (DvErrorNorm < 0 && DvErrorNorm > 0) || (DvErrorNorm != DvErrorNorm)) &&
687  DvErrorNorm != 0 &&
688  (DvErrorNorm != 1 || currentTime > timeInterval))
689  {
690  fixedTimeStep = true;
691  // rCurrentProcessInfo.SetValue(BAD_PRESSURE_CONVERGENCE, true);
692  if (DvErrorNorm > 0.9999)
693  {
694  rCurrentProcessInfo.SetValue(BAD_VELOCITY_CONVERGENCE, true);
695  std::cout << " BAD PRESSURE CONVERGENCE DETECTED DURING THE ITERATIVE LOOP!!! error: " << DvErrorNorm << " higher than 0.1" << std::endl;
696  std::cout << " I GO AHEAD WITH THE PREVIOUS VELOCITY AND PRESSURE FIELDS" << std::endl;
697  fixedTimeStep = true;
698 #pragma omp parallel
699  {
700  ModelPart::NodeIterator NodeBegin;
701  ModelPart::NodeIterator NodeEnd;
702  OpenMPUtils::PartitionedIterators(rModelPart.Nodes(), NodeBegin, NodeEnd);
703  for (ModelPart::NodeIterator itNode = NodeBegin; itNode != NodeEnd; ++itNode)
704  {
705  itNode->FastGetSolutionStepValue(VELOCITY, 0) = itNode->FastGetSolutionStepValue(VELOCITY, 1);
706  itNode->FastGetSolutionStepValue(PRESSURE, 0) = itNode->FastGetSolutionStepValue(PRESSURE, 1);
707  itNode->FastGetSolutionStepValue(ACCELERATION, 0) = itNode->FastGetSolutionStepValue(ACCELERATION, 1);
708  }
709  }
710  }
711  }
712  else if (DvErrorNorm < mPressureTolerance)
713  {
714  converged = true;
715  fixedTimeStep = false;
716  }
717  rCurrentProcessInfo.SetValue(BAD_PRESSURE_CONVERGENCE, false);
718  return converged;
719  }
720 
721  bool CheckContinuityConvergence(const double DvErrorNorm, bool &fixedTimeStep) override
722  {
723  ModelPart &rModelPart = BaseType::GetModelPart();
724  ProcessInfo &rCurrentProcessInfo = rModelPart.GetProcessInfo();
725  bool converged = false;
726 
727  if (DvErrorNorm < mPressureTolerance)
728  {
729  converged = true;
730  fixedTimeStep = false;
731  }
732  rCurrentProcessInfo.SetValue(BAD_PRESSURE_CONVERGENCE, false);
733  return converged;
734  }
735 
739 
743 
747 
749 
752 
756 
758 
760 
761  unsigned int mMaxPressureIter;
762 
763  unsigned int mDomainSize;
764 
765  unsigned int mTimeOrder;
766 
768 
769  // Fractional step index.
770  /* 1 : Momentum step (calculate fractional step velocity)
771  * 2-3 : Unused (reserved for componentwise calculation of frac step velocity)
772  * 4 : Pressure step
773  * 5 : Computation of projections
774  * 6 : End of step velocity
775  */
776  // unsigned int mStepId;
777 
780 
783 
787 
791 
795 
799 
803 
806 
809 
811 
812  };
813 
817 
819 
821 
822 } // namespace Kratos.
823 
824 #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 const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
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
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Communicator & GetCommunicator()
Definition: model_part.h:1821
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
MeshType::ElementIterator ElementIterator
Definition: model_part.h:174
SizeType NumberOfNodes(IndexType ThisIndex=0) const
Definition: model_part.h:341
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
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
ProcessInfo & GetPreviousTimeStepInfo(IndexType StepsBefore=1)
Definition: process_info.h:187
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 CheckPressureConvergence(const double NormDp, double &errorNormDp, double &NormP) override
Definition: two_step_v_p_strategy.h:544
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 UpdateStressStrain() override
Definition: two_step_v_p_strategy.h:312
void FinalizeSolutionStep() override
Performs all the required operations that should be done (for each step) after solving the solution s...
Definition: two_step_v_p_strategy.h:304
void SetTimeCoefficients(ProcessInfo &rCurrentProcessInfo)
Definition: two_step_v_p_strategy.h:187
TwoStepVPSolverSettings< TSparseSpace, TDenseSpace, TLinearSolver > SolverSettingsType
Definition: two_step_v_p_strategy.h:93
unsigned int mDomainSize
Definition: two_step_v_p_strategy.h:763
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: two_step_v_p_strategy.h:89
virtual ~TwoStepVPStrategy()
Destructor.
Definition: two_step_v_p_strategy.h:156
bool CheckVelocityConvergence(const double NormDv, double &errorNormDv) override
Definition: two_step_v_p_strategy.h:502
void Clear() override
Clears the internal storage.
Definition: two_step_v_p_strategy.h:331
double mVelocityTolerance
Definition: two_step_v_p_strategy.h:757
void InitializeSolutionStep() override
Performs all the required operations that should be done (for each step) before solving the solution ...
Definition: two_step_v_p_strategy.h:308
bool CheckMomentumConvergence(const double DvErrorNorm, bool &fixedTimeStep) override
Definition: two_step_v_p_strategy.h:632
bool mReformDofSet
Definition: two_step_v_p_strategy.h:767
unsigned int mTimeOrder
Definition: two_step_v_p_strategy.h:765
unsigned int mMaxPressureIter
Definition: two_step_v_p_strategy.h:761
TwoStepVPStrategy(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_strategy.h:99
StrategyPointerType mpMomentumStrategy
Scheme for the solution of the momentum equation.
Definition: two_step_v_p_strategy.h:779
BaseType::DofsArrayType DofsArrayType
Definition: two_step_v_p_strategy.h:81
void SetEchoLevel(int Level) override
This sets the level of echo for the solving strategy.
Definition: two_step_v_p_strategy.h:341
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: two_step_v_p_strategy.h:366
bool SolveSolutionStep() override
Solves the current step. This function returns true if a solution has been found, false otherwise.
Definition: two_step_v_p_strategy.h:222
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: two_step_v_p_strategy.h:87
StrategyPointerType mpPressureStrategy
Scheme for the solution of the mass equation.
Definition: two_step_v_p_strategy.h:782
BaseType::TSystemVectorType TSystemVectorType
Definition: two_step_v_p_strategy.h:85
bool FixTimeStepContinuity(const double DvErrorNorm, bool &fixedTimeStep) override
Definition: two_step_v_p_strategy.h:673
KRATOS_CLASS_POINTER_DEFINITION(TwoStepVPStrategy)
double mPressureTolerance
Definition: two_step_v_p_strategy.h:759
bool FixTimeStepMomentum(const double DvErrorNorm, bool &fixedTimeStep) override
Definition: two_step_v_p_strategy.h:582
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver >::Pointer StrategyPointerType
Definition: two_step_v_p_strategy.h:91
BaseType::TSystemMatrixType TSystemMatrixType
Definition: two_step_v_p_strategy.h:83
TwoStepVPStrategy(TwoStepVPStrategy const &rOther)
Copy constructor.
Definition: two_step_v_p_strategy.h:808
std::string Info() const override
Turn back information as a string.
Definition: two_step_v_p_strategy.h:358
TwoStepVPStrategy & operator=(TwoStepVPStrategy const &rOther)
Assignment operator.
Definition: two_step_v_p_strategy.h:805
BaseType::TDataType TDataType
Definition: two_step_v_p_strategy.h:79
VPStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: two_step_v_p_strategy.h:77
bool CheckContinuityConvergence(const double DvErrorNorm, bool &fixedTimeStep) override
Definition: two_step_v_p_strategy.h:721
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: two_step_v_p_strategy.h:372
Definition: v_p_strategy.h:59
virtual void SetEchoLevel(int Level) override
This sets the level of echo for the solving strategy.
Definition: v_p_strategy.h:436
virtual void CalculateTemporalVariables()
Definition: v_p_strategy.h:274
double ComputeVelocityNorm()
Definition: v_p_strategy.h:765
void UpdateTopology(ModelPart &rModelPart, unsigned int echoLevel)
Definition: v_p_strategy.h:107
double ComputePressureNorm()
Definition: v_p_strategy.h:793
void SetBlockedAndIsolatedFlags()
Definition: v_p_strategy.h:116
virtual int Check() override
Function to perform expensive checks.
Definition: v_p_strategy.h:93
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#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
Dt
Definition: face_heat.py:78
int n_nodes
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:15
int d
Definition: ode_solve.py:397
ReformDofAtEachIteration
Definition: test_pureconvectionsolver_benchmarking.py:131