9 #ifndef KRATOS_TWO_STEP_V_P_STRATEGY_H
10 #define KRATOS_TWO_STEP_V_P_STRATEGY_H
28 #include "custom_utilities/solver_settings.h"
67 template <
class TSparseSpace,
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,
106 unsigned int TimeOrder = 2,
107 unsigned int DomainSize = 2) :
BaseType(rModelPart, pVelocityLinearSolver, pPressureLinearSolver, ReformDofSet, DomainSize),
122 bool CalculateNormDxFlag =
true;
132 typename SchemeType::Pointer pScheme;
143 vel_build->SetCalculateReactionsFlag(
false);
150 pressure_build->SetCalculateReactionsFlag(
false);
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.",
"");
173 for (
const auto &r_element : rModelPart.
Elements())
175 ierr = r_element.Check(r_current_process_info);
194 double Dt = rCurrentProcessInfo[DELTA_TIME];
197 double Rho = OldDt /
Dt;
198 double TimeCoeff = 1.0 / (
Dt * Rho * Rho +
Dt * Rho);
200 Vector &BDFcoeffs = rCurrentProcessInfo[BDF_COEFFICIENTS];
201 BDFcoeffs.
resize(3,
false);
203 BDFcoeffs[0] = TimeCoeff * (Rho * Rho + 2.0 * Rho);
204 BDFcoeffs[1] = -TimeCoeff * (Rho * Rho + 2.0 * Rho + 1.0);
205 BDFcoeffs[2] = TimeCoeff;
209 double Dt = rCurrentProcessInfo[DELTA_TIME];
210 double TimeCoeff = 1.0 /
Dt;
212 Vector &BDFcoeffs = rCurrentProcessInfo[BDF_COEFFICIENTS];
213 BDFcoeffs.
resize(2,
false);
215 BDFcoeffs[0] = TimeCoeff;
216 BDFcoeffs[1] = -TimeCoeff;
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;
234 KRATOS_INFO(
"\nSolution with two_step_vp_strategy at t=") << currentTime <<
"s" << std::endl;
236 if ((timeIntervalChanged ==
true && currentTime > 10 * timeInterval) || stepsWithChangedDt > 0)
238 maxNonLinearIterations *= 2;
240 if (currentTime < 10 * timeInterval)
243 std::cout <<
"within the first 10 time steps, I consider the given iteration number x3" << std::endl;
244 maxNonLinearIterations *= 3;
246 if (currentTime < 20 * timeInterval && currentTime >= 10 * timeInterval)
249 std::cout <<
"within the second 10 time steps, I consider the given iteration number x2" << std::endl;
250 maxNonLinearIterations *= 2;
252 bool momentumConverged =
true;
253 bool continuityConverged =
false;
254 bool fixedTimeStep =
false;
256 double pressureNorm = 0;
257 double velocityNorm = 0;
261 for (
unsigned int it = 0; it < maxNonLinearIterations; ++it)
263 momentumConverged = this->
SolveMomentumIteration(it, maxNonLinearIterations, fixedTimeStep, velocityNorm);
267 if (fixedTimeStep ==
false)
271 if (it == maxNonLinearIterations - 1 || ((continuityConverged && momentumConverged) && it > 2))
279 if ((continuityConverged && momentumConverged) && it > 2)
281 rCurrentProcessInfo.
SetValue(BAD_VELOCITY_CONVERGENCE,
false);
282 rCurrentProcessInfo.
SetValue(BAD_PRESSURE_CONVERGENCE,
false);
285 KRATOS_INFO(
"TwoStepVPStrategy") <<
"V-P strategy converged in " << it + 1 <<
" iterations." << std::endl;
289 if (fixedTimeStep ==
true)
296 std::cout <<
"Convergence tolerance not reached." << std::endl;
324 itElem->InitializeNonLinearIteration(rCurrentProcessInfo);
344 int StrategyLevel = Level > 0 ? Level - 1 : 0;
358 std::string
Info()
const override
360 std::stringstream buffer;
361 buffer <<
"TwoStepVPStrategy";
368 rOStream <<
"TwoStepVPStrategy";
412 bool ConvergedMomentum =
false;
414 fixedTimeStep =
false;
426 std::cout <<
"-------------- s o l v e d ! ------------------" << std::endl;
433 double DvErrorNorm = NormDv / velocityNorm;
434 unsigned int iterationForCheck = 2;
438 KRATOS_INFO(
"Iteration") << it <<
" Final Velocity error: " << DvErrorNorm << std::endl;
441 else if (it > iterationForCheck)
443 KRATOS_INFO(
"Iteration") << it <<
" Velocity error: " << DvErrorNorm << std::endl;
448 KRATOS_INFO(
"Iteration") << it <<
" Velocity error: " << DvErrorNorm << std::endl;
452 std::cout <<
"Momentum equations did not reach the convergence tolerance." << std::endl;
454 return ConvergedMomentum;
461 bool ConvergedContinuity =
false;
462 bool fixedTimeStep =
false;
475 std::cout <<
"The norm of pressure is: " << NormDp << std::endl;
482 double DpErrorNorm = NormDp / (NormP);
485 if (it == (maxIt - 1))
487 KRATOS_INFO(
"Iteration") << it <<
" Final Pressure error: " << DpErrorNorm << std::endl;
492 KRATOS_INFO(
"Iteration") << it <<
" Pressure error: " << DpErrorNorm << std::endl;
497 std::cout <<
"Continuity equation did not reach the convergence tolerance." << std::endl;
499 return ConvergedContinuity;
510 #pragma omp parallel for reduction(+ \
512 for (
int i_node = 0; i_node <
n_nodes; ++i_node)
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)
518 NormV += r_vel[
d] * r_vel[
d];
524 const double zero_tol = 1.0e-12;
525 errorNormDv = (NormV < zero_tol) ? NormDv : NormDv / NormV;
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;
551 double tmp_NormP = 0.0;
553 #pragma omp parallel for reduction(+ : tmp_NormP)
554 for (
int i_node = 0; i_node <
n_nodes; ++i_node)
556 const auto it_node = rModelPart.
NodesBegin() + i_node;
557 const double Pr = it_node->FastGetSolutionStepValue(PRESSURE);
558 tmp_NormP += Pr * Pr;
564 const double zero_tol = 1.0e-12;
565 errorNormDp = (NormP < zero_tol) ? NormDp : NormDp / NormP;
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;
586 double currentTime = rCurrentProcessInfo[TIME];
587 double timeInterval = rCurrentProcessInfo[DELTA_TIME];
588 double minTolerance = 0.005;
589 bool converged =
false;
591 if (currentTime < 10 * timeInterval)
596 if ((DvErrorNorm > minTolerance || (DvErrorNorm < 0 && DvErrorNorm > 0) || (DvErrorNorm != DvErrorNorm)) &&
598 (DvErrorNorm != 1 || currentTime > timeInterval))
600 rCurrentProcessInfo.
SetValue(BAD_VELOCITY_CONVERGENCE,
true);
601 std::cout <<
"NOT GOOD CONVERGENCE!!! I'll reduce the next time interval" << DvErrorNorm << std::endl;
603 if (DvErrorNorm > minTolerance)
605 std::cout <<
"BAD CONVERGENCE!!! I GO AHEAD WITH THE PREVIOUS VELOCITY AND PRESSURE FIELDS" << DvErrorNorm << std::endl;
606 fixedTimeStep =
true;
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);
623 rCurrentProcessInfo.
SetValue(BAD_VELOCITY_CONVERGENCE,
false);
636 double currentTime = rCurrentProcessInfo[TIME];
637 double timeInterval = rCurrentProcessInfo[DELTA_TIME];
638 double minTolerance = 0.99999;
639 bool converged =
false;
641 if ((DvErrorNorm > minTolerance || (DvErrorNorm < 0 && DvErrorNorm > 0) || (DvErrorNorm != DvErrorNorm)) &&
643 (DvErrorNorm != 1 || currentTime > timeInterval))
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;
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);
664 rCurrentProcessInfo.
SetValue(BAD_VELOCITY_CONVERGENCE,
false);
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)
686 if ((DvErrorNorm > minTolerance || (DvErrorNorm < 0 && DvErrorNorm > 0) || (DvErrorNorm != DvErrorNorm)) &&
688 (DvErrorNorm != 1 || currentTime > timeInterval))
690 fixedTimeStep =
true;
692 if (DvErrorNorm > 0.9999)
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;
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);
715 fixedTimeStep =
false;
717 rCurrentProcessInfo.
SetValue(BAD_PRESSURE_CONVERGENCE,
false);
725 bool converged =
false;
730 fixedTimeStep =
false;
732 rCurrentProcessInfo.
SetValue(BAD_PRESSURE_CONVERGENCE,
false);
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