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.
adaptive_residualbased_newton_raphson_strategy.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: Riccardo Rossi
11 //
12 
13 
14 
15 #if !defined(KRATOS_ADAPTIVE_RESIDUALBASED_NEWTON_RAPHSON_STRATEGY )
16 #define KRATOS_ADAPTIVE_RESIDUALBASED_NEWTON_RAPHSON_STRATEGY
17 
18 
19 /* System includes */
20 
21 
22 /* External includes */
23 
24 
25 /* Project includes */
26 #include "includes/define.h"
27 #include "includes/model_part.h"
31 
32 //default builder and solver
34 
35 namespace Kratos
36 {
37 
64 
85 template<class TSparseSpace,
86  class TDenseSpace, // = DenseSpace<double>,
87  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
88  >
90  : public ImplicitSolvingStrategy<TSparseSpace,TDenseSpace,TLinearSolver>
91 {
92 public:
96 
99 
101 
103 
105 
107 
108  typedef typename BaseType::TDataType TDataType;
109 
110  typedef TSparseSpace SparseSpaceType;
111 
113 
114  //typedef typename BaseType::DofSetType DofSetType;
115 
117 
119 
121 
123 
125 
128 
138  {
139  }
140 
147  : BaseType(rModelPart)
148  {
149  // Validate and assign defaults
150  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
151  this->AssignSettings(ThisParameters);
152 
153  // Getting builder and solver
154  auto p_builder_and_solver = this->GetBuilderAndSolver();
155  if (p_builder_and_solver != nullptr) {
156  // Tells to the builder and solver if the reactions have to be Calculated or not
157  p_builder_and_solver->SetCalculateReactionsFlag(this->GetCalculateReactionsFlag());
158 
159  // Tells to the Builder And Solver if the system matrix and vectors need to
160  // be reshaped at each step or not
161  p_builder_and_solver->SetReshapeMatrixFlag(this->GetReformDofSetAtEachStepFlag());
162  } else {
163  KRATOS_WARNING("AdaptiveResidualBasedNewtonRaphsonStrategy") << "BuilderAndSolver is not initialized. Please assign one before settings flags" << std::endl;
164  }
165 
169  }
170 
174  ModelPart& rModelPart,
175  typename TSchemeType::Pointer pScheme,
176  typename TLinearSolver::Pointer pNewLinearSolver,
177  typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
178  int MaxIterations = 30,
179  int MinIterations = 4,
180  bool CalculateReactions = false,
181  bool ReformDofSetAtEachStep = false,
182  bool MoveMeshFlag = false,
183  double ReductionFactor = 0.5,
184  double IncreaseFactor = 1.3,
185  int NumberOfCycles = 5
186  ) : BaseType(rModelPart, MoveMeshFlag)
187  {
188  KRATOS_TRY
189  //set flags to default values
190  SetMaxIterationNumber(MaxIterations);
191 
192  mMinIterationNumber = MinIterations;
193 
194  mReductionFactor = ReductionFactor;
195 
196  mIncreaseFactor = IncreaseFactor;
197 
198  mNumberOfCycles = NumberOfCycles;
199 
200  mCalculateReactionsFlag = CalculateReactions;
201 
202 
203  mReformDofSetAtEachStep = ReformDofSetAtEachStep;
204 
205  //saving the convergence criteria to be used
206  mpConvergenceCriteria = pNewConvergenceCriteria;
207 
208  //saving the scheme
209  mpScheme = pScheme;
210 
211  //saving the linear solver
212  mpLinearSolver = pNewLinearSolver;
213 
214  //setting up the default builder and solver
215  mpBuilderAndSolver = typename TBuilderAndSolverType::Pointer
216  (
218  );
219 
220  //set flags to start the calculations correctly
222  mInitializeWasPerformed = false;
223 
224  //tells to the builder and solver if the reactions have to be Calculated or not
225  GetBuilderAndSolver()->SetCalculateReactionsFlag(mCalculateReactionsFlag);
226 
227  //tells to the Builder And Solver if the system matrix and vectors need to
228  //be reshaped at each step or not
229  GetBuilderAndSolver()->SetReshapeMatrixFlag(mReformDofSetAtEachStep);
230 
231  //set EchoLevel to the default value (only time is displayed)
232  SetEchoLevel(1);
233 
234  //by default the matrices are rebuilt at each iteration
235  this->SetRebuildLevel(2);
236 
237  KRATOS_WATCH("AdaptiveResidualBasedNewtonRaphsonStrategy is chosen");
238 
239  KRATOS_CATCH("")
240  }
241 
258  ModelPart& rModelPart,
259  typename TSchemeType::Pointer pScheme,
260  typename TLinearSolver::Pointer pNewLinearSolver,
261  typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
262  typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver,
263  int MaxIterations = 30,
264  int MinIterations = 4,
265  bool CalculateReactions = false,
266  bool ReformDofSetAtEachStep = false,
267  bool MoveMeshFlag = false,
268  double ReductionFactor = 0.5,
269  double IncreaseFactor = 1.3,
270  int NumberOfCycles = 5
271  ) : BaseType(rModelPart, MoveMeshFlag)
272  {
273  KRATOS_TRY
274  //set flags to default values
275  SetMaxIterationNumber(MaxIterations);
276  mCalculateReactionsFlag = CalculateReactions;
277 
278  mMinIterationNumber = MinIterations;
279 
280  mReductionFactor = ReductionFactor;
281 
282  mIncreaseFactor = IncreaseFactor;
283 
284  mNumberOfCycles = NumberOfCycles;
285 
286 
287  mReformDofSetAtEachStep = ReformDofSetAtEachStep;
288 
289  //saving the convergence criteria to be used
290  mpConvergenceCriteria = pNewConvergenceCriteria;
291 
292  //saving the scheme
293  mpScheme = pScheme;
294 
295  //saving the linear solver
296  mpLinearSolver = pNewLinearSolver;
297 
298  //setting up the default builder and solver
299  mpBuilderAndSolver = pNewBuilderAndSolver;
300 
301  //set flags to start the calculations correctly
303  mInitializeWasPerformed = false;
304 
305  //tells to the builder and solver if the reactions have to be Calculated or not
306  GetBuilderAndSolver()->SetCalculateReactionsFlag(mCalculateReactionsFlag);
307 
308  //tells to the Builder And Solver if the system matrix and vectors need to
309  //be reshaped at each step or not
310  GetBuilderAndSolver()->SetReshapeMatrixFlag(mReformDofSetAtEachStep);
311 
312  //set EchoLevel to the default value (only time is displayed)
313  SetEchoLevel(1);
314 
315  //by default the matrices are rebuilt at each iteration
316  this->SetRebuildLevel(2);
317 
318  KRATOS_CATCH("")
319  }
320 
324 
328  //Set and Get Scheme ... containing Builder, Update and other
329  void SetScheme(typename TSchemeType::Pointer pScheme )
330  {
331  mpScheme = pScheme;
332  };
333  typename TSchemeType::Pointer GetScheme()
334  {
335  return mpScheme;
336  };
337 
338  //Set and Get the BuilderAndSolver
339  void SetBuilderAndSolver(typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver )
340  {
341  mpBuilderAndSolver = pNewBuilderAndSolver;
342  };
343  typename TBuilderAndSolverType::Pointer GetBuilderAndSolver()
344  {
345  return mpBuilderAndSolver;
346  };
347 
348  void SetCalculateReactionsFlag(bool CalculateReactionsFlag)
349  {
350  mCalculateReactionsFlag = CalculateReactionsFlag;
351  }
353  {
355  }
356 
358  {
360  GetBuilderAndSolver()->SetReshapeMatrixFlag(mReformDofSetAtEachStep);
361  }
363  {
365  }
366 
367  void SetMaxIterationNumber( int MaxIterationNumber)
368  {
369  mMaxIterationNumber = MaxIterationNumber;
370  }
371  unsigned int GetMaxIterationNumber()
372  {
373  return mMaxIterationNumber;
374  }
375 
376  //level of echo for the solving strategy
377  // 0 -> mute... no echo at all
378  // 1 -> printing time and basic information
379  // 2 -> printing linear solver data
380  // 3 -> Print of debug information:
381  // Echo of stiffness matrix, Dx, b...
382  void SetEchoLevel(int Level) override
383  {
384  BaseType::mEchoLevel = Level;
385  GetBuilderAndSolver()->SetEchoLevel(Level);
386  }
387 
388  //*********************************************************************************
396  typename SolvingStrategyType::Pointer Create(
397  ModelPart& rModelPart,
398  Parameters ThisParameters
399  ) const override
400  {
401  return Kratos::make_shared<ClassType>(rModelPart, ThisParameters);
402  }
403 
408  void Predict() override
409  {
410  KRATOS_TRY
411  //OPERATIONS THAT SHOULD BE DONE ONCE - internal check to avoid repetitions
412  //if the operations needed were already performed this does nothing
413  if(mInitializeWasPerformed == false)
414  Initialize();
415 
416  //initialize solution step
417  if (mSolutionStepIsInitialized == false)
419 
420  DofsArrayType& rDofSet = GetBuilderAndSolver()->GetDofSet();
421 
422  TSystemMatrixType& mA = *mpA;
423  TSystemVectorType& mDx = *mpDx;
425 
426 
427  GetScheme()->Predict(BaseType::GetModelPart(),rDofSet,mA,mDx,mb);
428 
429  //move the mesh if needed
430  if(this->MoveMeshFlag() == true) BaseType::MoveMesh();
431 
432  KRATOS_CATCH("")
433  }
434 
435  //*********************************************************************************
439  //**********************************************************************
440  bool CyclicSolve()
441  {
442  KRATOS_TRY
443 
444 
445  //pointers needed in the solution
446  typename TSchemeType::Pointer pScheme = GetScheme();
447  typename TBuilderAndSolverType::Pointer pBuilderAndSolver = GetBuilderAndSolver();
448 
449  //int solstep = pCurrentProcessInfo.GetCurrentSolutionStep();
450  DofsArrayType& rDofSet = pBuilderAndSolver->GetDofSet();
451 
452  //OPERATIONS THAT SHOULD BE DONE ONCE - internal check to avoid repetitions
453  //if the operations needed were already performed this does nothing
454  if(mInitializeWasPerformed == false)
455  Initialize();
456 
457  //set up the system, operation performed just once unless it is required
458  //to reform the dof set at each iteration
459  if (pBuilderAndSolver->GetDofSetIsInitializedFlag() == false ||
460  mReformDofSetAtEachStep == true )
461  {
462  //setting up the list of the DOFs to be solved
463  pBuilderAndSolver->SetUpDofSet(pScheme,BaseType::GetModelPart());
464 
465  //shaping correctly the system
466  pBuilderAndSolver->SetUpSystem(BaseType::GetModelPart());
467  }
468 
469  //prints information about the current time
470  if (this->GetEchoLevel()!=0)
471  {
472  std::cout << " " << std::endl;
473  std::cout << "CurrentTime = " << BaseType::GetModelPart().GetProcessInfo()[TIME] << std::endl;
474  }
475 
476  //updates the database with a prediction of the solution
477  Predict();
478 
479  //initialize solution step
480  if (mSolutionStepIsInitialized == false)
482 
483  TSystemMatrixType& mA = *mpA;
484  TSystemVectorType& mDx = *mpDx;
486 
487 
488 
489  //initializing the parameters of the Newton-Raphson cicle
490  int iteration_number=1;
491  BaseType::GetModelPart().GetProcessInfo()[NL_ITERATION_NUMBER] = iteration_number;
492 // BaseType::GetModelPart().GetProcessInfo().SetNonLinearIterationNumber(iteration_number);
493  bool is_converged = false;
494 // bool ResidualIsUpdated = false;
495  pScheme->InitializeNonLinIteration(BaseType::GetModelPart(),mA,mDx,mb);
496  is_converged = mpConvergenceCriteria->PreCriteria(BaseType::GetModelPart(),rDofSet,mA,mDx,mb);
497 
498  //function to perform the building and the solving phase.
500  {
501  TSparseSpace::SetToZero(mA);
502  TSparseSpace::SetToZero(mDx);
503  TSparseSpace::SetToZero(mb);
504 
505  pBuilderAndSolver->BuildAndSolve(pScheme,BaseType::GetModelPart(),mA,mDx,mb);
506  }
507  else
508  {
509  TSparseSpace::SetToZero(mDx); //mDx=0.00;
510  TSparseSpace::SetToZero(mb);
511 
512  pBuilderAndSolver->BuildRHSAndSolve(pScheme,BaseType::GetModelPart(),mA,mDx,mb);
513  }
514 
515  if (this->GetEchoLevel()==3) //if it is needed to print the debug info
516  {
517 // std::cout << "After first system solution" << std::endl;
518  std::cout << "SystemMatrix = " << mA << std::endl;
519  std::cout << "solution obtained = " << mDx << std::endl;
520  std::cout << "RHS = " << mb << std::endl;
521  }
522  if (this->GetEchoLevel()==4) //print to matrix market file
523  {
524  std::stringstream matrix_market_name;
525  matrix_market_name << "A_"<< BaseType::GetModelPart().GetProcessInfo()[TIME] << "_" << iteration_number << ".mm";
526  WriteMatrixMarketMatrix((char*)(matrix_market_name.str()).c_str() , mA, false);
527  }
528 
529  //update results
530  pScheme->Update(BaseType::GetModelPart(),rDofSet,mA,mDx,mb);
531 
532  //move the mesh if needed
534 
535  pScheme->FinalizeNonLinIteration(BaseType::GetModelPart(),mA,mDx,mb);
536 
537  if (is_converged==true)
538  {
539  //initialisation of the convergence criteria
540  mpConvergenceCriteria->InitializeSolutionStep(BaseType::GetModelPart(),rDofSet,mA,mDx,mb);
541 
542  if (mpConvergenceCriteria->GetActualizeRHSflag() == true)
543  {
544  TSparseSpace::SetToZero(mb);
545 
546  pBuilderAndSolver->BuildRHS(pScheme,BaseType::GetModelPart(),mb);
547  }
548 
549  is_converged = mpConvergenceCriteria->PostCriteria(BaseType::GetModelPart(),rDofSet,mA,mDx,mb);
550  }
551 
552 
553  //Iteration Cicle... performed only for NonLinearProblems
554  while( is_converged == false &&
555  iteration_number++<mMaxIterationNumber)
556  {
557  //setting the number of iteration
558  BaseType::GetModelPart().GetProcessInfo()[NL_ITERATION_NUMBER] = iteration_number;
559 
560  pScheme->InitializeNonLinIteration(BaseType::GetModelPart(),mA,mDx,mb);
561 
562  is_converged = mpConvergenceCriteria->PreCriteria(BaseType::GetModelPart(),rDofSet,mA,mDx,mb);
563 
564  //call the linear system solver to find the correction mDx for the
565  //it is not called if there is no system to solve
566  if (SparseSpaceType::Size(mDx)!=0)
567  {
569  {
570  //mA = 0.00;
571  TSparseSpace::SetToZero(mA);
572  TSparseSpace::SetToZero(mDx);
573  TSparseSpace::SetToZero(mb);
574 
575  pBuilderAndSolver->BuildAndSolve(pScheme,BaseType::GetModelPart(),mA,mDx,mb);
576  }
577  else
578  {
579  TSparseSpace::SetToZero(mDx);
580  TSparseSpace::SetToZero(mb);
581 
582  pBuilderAndSolver->BuildRHSAndSolve(pScheme,BaseType::GetModelPart(),mA,mDx,mb);
583  }
584  }
585  else
586  {
587  std::cout << "ATTENTION: no free DOFs!! " << std::endl;
588  }
589 
590 
591  //Updating the results stored in the database
592  pScheme->Update(BaseType::GetModelPart(),rDofSet,mA,mDx,mb);
593 
594  //move the mesh if needed
596 
597  pScheme->FinalizeNonLinIteration(BaseType::GetModelPart(),mA,mDx,mb);
598 
599 // ResidualIsUpdated = false;
600 
601  if (is_converged==true)
602  {
603 
604  if (mpConvergenceCriteria->GetActualizeRHSflag() == true)
605  {
606  TSparseSpace::SetToZero(mb);
607 
608  pBuilderAndSolver->BuildRHS(pScheme,BaseType::GetModelPart(),mb);
609 // ResidualIsUpdated = true;
610  //std::cout << "mb is calculated" << std::endl;
611  }
612 
613  is_converged = mpConvergenceCriteria->PostCriteria(BaseType::GetModelPart(),rDofSet,mA,mDx,mb);
614  }
615  }
616 
617  return is_converged;
618 
619  KRATOS_CATCH("")
620 
621  }
622  //**********************************************************************
623  double Solve() override
624  {
625  KRATOS_TRY
626  bool is_converged = false;
627  int number_of_cycles = 0;
628 
629  while(is_converged == false && number_of_cycles++ < mNumberOfCycles )
630  {
631  KRATOS_WATCH("****************** inside cyclic_lopp*******************");
636 
637  // mSolutionStepIsInitialized = false;
638  //Iteration Cicle... performed only for NonLinearProblems
639  is_converged = CyclicSolve();
640 
641  double iteration_number = BaseType::GetModelPart().GetProcessInfo()[NL_ITERATION_NUMBER];
642 
643  if(is_converged == false)
644  {
646  double CurrentTime = model_part.GetProcessInfo()[TIME];
647  KRATOS_WATCH("old delta_time");
648  KRATOS_WATCH(model_part.GetProcessInfo()[DELTA_TIME]);
649  double delta_time = model_part.GetProcessInfo()[DELTA_TIME];
650  double new_time = CurrentTime - delta_time * mReductionFactor;
651 
652 
653  ReductionStrategy(model_part, new_time);
654 
655 
656  //plots a warning if the maximum number of iterations is exceeded
657  MaxIterationsExceeded(number_of_cycles);
658 
659  KRATOS_WATCH("CurrentTime");
660  KRATOS_WATCH(CurrentTime);
661 
662  KRATOS_WATCH("new_time");
663  KRATOS_WATCH(new_time);
664 
665  KRATOS_WATCH("new delta_time");
666  KRATOS_WATCH(model_part.GetProcessInfo()[DELTA_TIME]);
667  }
668 
669  if(iteration_number <= mMinIterationNumber)
670  {
672  double DeltaTime = model_part.GetProcessInfo()[DELTA_TIME];
673  double New_Dt = DeltaTime * mIncreaseFactor;
674  model_part.GetProcessInfo()[DELTA_TIME] = New_Dt;
675  //ModelPart.GetProcessInfo().SetCurrentTime(NewTime);
676  PrintIncreaseOfDeltaTime(DeltaTime, New_Dt);
677  }
678  }//end of cyclic loop
679 
680  BaseType::GetModelPart().GetProcessInfo()[SCALE] = number_of_cycles;
681  TSystemMatrixType& mA = *mpA;
682  TSystemVectorType& mDx = *mpDx;
684 
685 
686 
687  //recalculate residual if needed
688  // (note that some convergence criteria need it to be recalculated)
689  if (mpConvergenceCriteria->GetActualizeRHSflag() == false)
690  {
691  TSparseSpace::SetToZero(mb);
692 
694 
695  //std::cout << "mb is calculated" << std::endl;
696  }
697 
698  //calculate reactions if required
699  if (mCalculateReactionsFlag ==true)
700  {
701  mpBuilderAndSolver->CalculateReactions(mpScheme,BaseType::GetModelPart(),mA,mDx,mb);
702  }
703  //Finalisation of the solution step,
704  //operations to be done after achieving convergence, for example the
705  //Final Residual Vector (mb) has to be saved in there
706  //to avoid error accumulation
707  mpScheme->FinalizeSolutionStep(BaseType::GetModelPart(),mA,mDx,mb);
708  mpBuilderAndSolver->FinalizeSolutionStep(BaseType::GetModelPart(),mA,mDx,mb);
709 
710  //Cleaning memory after the solution
711  mpScheme->Clean();
712 
713  //reset flags for next step
715 
716  if (mReformDofSetAtEachStep == true) //deallocate the systemvectors
717  {
721 
722  this->Clear();
723  }
724 
725  return 0.00;
726 
727  KRATOS_CATCH("")
728 
729  }
730 
735  //**********************************************************************
736  bool IsConverged() override
737  {
738  KRATOS_TRY
739 
740  TSystemMatrixType& mA = *mpA;
741  TSystemVectorType& mDx = *mpDx;
743 
744 
745  if (mpConvergenceCriteria->GetActualizeRHSflag() == true)
746  {
748  }
749 
750  DofsArrayType& rDofSet = GetBuilderAndSolver()->GetDofSet();
751 
752  return mpConvergenceCriteria->PostCriteria(BaseType::GetModelPart(),rDofSet,mA,mDx,mb);
753  KRATOS_CATCH("")
754 
755  }
756 
757  //*********************************************************************************
764  void CalculateOutputData() override
765  {
766  TSystemMatrixType& mA = *mpA;
767  TSystemVectorType& mDx = *mpDx;
769 
770  DofsArrayType& rDofSet = GetBuilderAndSolver()->GetDofSet();
771  GetScheme()->CalculateOutputData(BaseType::GetModelPart(),rDofSet,mA,mDx,mb);
772  }
773 
774  //**********************************************************************
775  //**********************************************************************
776  void Clear() override
777  {
778  KRATOS_TRY
779  std::cout << "Newton Raphson strategy Clear function used" << std::endl;
780 
781  TSystemMatrixType& mA = *mpA;
782  TSystemVectorType& mDx = *mpDx;
784 
786  SparseSpaceType::Resize(mA,0,0);
787 
790 
793 
794 
795  //setting to zero the internal flag to ensure that the dof sets are recalculated
796  GetBuilderAndSolver()->SetDofSetIsInitializedFlag(false);
797  GetBuilderAndSolver()->Clear();
798 
799 
800  KRATOS_CATCH("");
801  }
802 
808  {
809  Parameters default_parameters = Parameters(R"(
810  {
811  "name" : "adaptative_newton_raphson_strategy",
812  "min_iteration" : 4,
813  "reduction_factor" : 0.5,
814  "increase_factor" : 1.3,
815  "number_of_cycles" : 5,
816  "max_iteration" : 10,
817  "reform_dofs_at_each_step" : false,
818  "compute_reactions" : false,
819  "builder_and_solver_settings" : {},
820  "convergence_criteria_settings" : {},
821  "linear_solver_settings" : {},
822  "scheme_settings" : {}
823  })");
824 
825  // Getting base class default parameters
826  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
827  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
828  return default_parameters;
829  }
830 
835  static std::string Name()
836  {
837  return "adaptative_newton_raphson_strategy";
838  }
839 
855  {
856  TSystemMatrixType& mA = *mpA;
857 
858  return mA;
859  }
860 
868 
870  std::string Info() const override
871  {
872  return "AdaptiveResidualBasedNewtonRaphsonStrategy";
873  }
874 
876  void PrintInfo(std::ostream& rOStream) const override
877  {
878  rOStream << Info();
879  }
880 
882  void PrintData(std::ostream& rOStream) const override
883  {
884  rOStream << Info();
885  }
886 
894 private:
933 protected:
942  typename TSchemeType::Pointer mpScheme;
943 
944  typename TLinearSolver::Pointer mpLinearSolver;
945 
946  typename TBuilderAndSolverType::Pointer mpBuilderAndSolver;
947 
948  typename TConvergenceCriteriaType::Pointer mpConvergenceCriteria;
949 
950  /* TSystemVectorType mDx;
951  TSystemVectorType mb;
952  TSystemMatrixType mA;*/
956 
966 
973 
975 
980 
983 
985 
989  //**********************************************************************
990  //**********************************************************************
991  void Initialize() override
992  {
993  KRATOS_TRY
994 
995  //pointers needed in the solution
996  typename TSchemeType::Pointer pScheme = GetScheme();
997  typename TConvergenceCriteriaType::Pointer pConvergenceCriteria = mpConvergenceCriteria;
998 
999  //Initialize The Scheme - OPERATIONS TO BE DONE ONCE
1000  if (pScheme->SchemeIsInitialized() == false)
1001  pScheme->Initialize(BaseType::GetModelPart());
1002 
1003  //Initialize The Elements - OPERATIONS TO BE DONE ONCE
1004  if (pScheme->ElementsAreInitialized() == false)
1005  pScheme->InitializeElements(BaseType::GetModelPart());
1006 
1007  //initialisation of the convergence criteria
1008  if (mpConvergenceCriteria->IsInitialized() == false)
1010 
1011 
1012  mInitializeWasPerformed = true;
1013 
1014  KRATOS_CATCH("")
1015  }
1016 
1017 
1018  //**********************************************************************
1019  //**********************************************************************
1020  void InitializeSolutionStep() override
1021  {
1022  KRATOS_TRY
1023 
1024  typename TBuilderAndSolverType::Pointer pBuilderAndSolver = GetBuilderAndSolver();
1025  typename TSchemeType::Pointer pScheme = GetScheme();
1026 
1027 
1028 
1029  //setting up the Vectors involved to the correct size
1030  pBuilderAndSolver->ResizeAndInitializeVectors(pScheme, mpA,mpDx,mpb,BaseType::GetModelPart());
1031 
1032  TSystemMatrixType& mA = *mpA;
1033  TSystemVectorType& mDx = *mpDx;
1034  TSystemVectorType& mb = *mpb;
1035 
1036 
1037  //initial operations ... things that are constant over the Solution Step
1038  pBuilderAndSolver->InitializeSolutionStep(BaseType::GetModelPart(),mA,mDx,mb);
1039 
1040  //initial operations ... things that are constant over the Solution Step
1041  pScheme->InitializeSolutionStep(BaseType::GetModelPart(),mA,mDx,mb);
1042 
1044 
1045  KRATOS_CATCH("")
1046  }
1047 
1048 
1049  //**********************************************************************
1050  //**********************************************************************
1051  void MaxIterationsExceeded(int cycle_number)
1052  {
1053  std::cout << "***************************************************" << std::endl;
1054  std::cout << "******* ATTENTION: max iterations exceeded ********" << std::endl;
1055  std::cout << "***************************************************" << std::endl;
1056 
1057  std::cout << "*****************REDUCTION CYCLE********************" << std::endl;
1058  std::cout << cycle_number << std::endl;
1059  std::cout << "***************************************************" << std::endl;
1060  }
1061 
1062 
1063  void PrintIncreaseOfDeltaTime(double old_dt , double new_dt)
1064  {
1065  std::cout << "***************************************************" << std::endl;
1066  std::cout << "******* ATTENTION: INcreasing dt ********" << std::endl;
1067  std::cout << "***************************************************" << std::endl;
1068 
1069  std::cout << "*****************OLD DT********************" << std::endl;
1070  std::cout << old_dt << std::endl;
1071  std::cout << "*****************NEW DT********************" << std::endl;
1072  std::cout << new_dt << std::endl;
1073  }
1074 
1075  //**********************************************************************
1076  //**********************************************************************
1077  void ReductionStrategy(ModelPart& model_part, double NewTime)
1078  {
1079  model_part.ReduceTimeStep(model_part, NewTime);
1080 
1081  for(ModelPart::NodeIterator i = model_part.NodesBegin() ;
1082  i != model_part.NodesEnd() ; ++i)
1083  {
1084  (i)->X() = (i)->X0() + i->GetSolutionStepValue(DISPLACEMENT_X , 1);
1085  (i)->Y() = (i)->Y0() + i->GetSolutionStepValue(DISPLACEMENT_Y , 1);
1086  (i)->Z() = (i)->Z0() + i->GetSolutionStepValue(DISPLACEMENT_Z , 1);
1087  }
1088 
1089  }
1090 
1095  void AssignSettings(const Parameters ThisParameters) override
1096  {
1097  BaseType::AssignSettings(ThisParameters);
1098  mMinIterationNumber = ThisParameters["min_iteration"].GetInt();
1099  mReductionFactor = ThisParameters["reduction_factor"].GetDouble();
1100  mIncreaseFactor = ThisParameters["increase_factor"].GetDouble();
1101  mNumberOfCycles = ThisParameters["number_of_cycles"].GetInt();
1102  mMaxIterationNumber = ThisParameters["max_iteration"].GetInt();
1103  mReformDofSetAtEachStep = ThisParameters["reform_dofs_at_each_step"].GetBool();
1104  mCalculateReactionsFlag = ThisParameters["compute_reactions"].GetBool();
1105 
1106  // Saving the convergence criteria to be used
1107  if (ThisParameters["convergence_criteria_settings"].Has("name")) {
1108  KRATOS_ERROR << "IMPLEMENTATION PENDING IN CONSTRUCTOR WITH PARAMETERS" << std::endl;
1109  }
1110 
1111  // Saving the scheme
1112  if (ThisParameters["scheme_settings"].Has("name")) {
1113  KRATOS_ERROR << "IMPLEMENTATION PENDING IN CONSTRUCTOR WITH PARAMETERS" << std::endl;
1114  }
1115 
1116  // Setting up the default builder and solver
1117  if (ThisParameters["builder_and_solver_settings"].Has("name")) {
1118  KRATOS_ERROR << "IMPLEMENTATION PENDING IN CONSTRUCTOR WITH PARAMETERS" << std::endl;
1119  }
1120  }
1121 
1144 
1145 
1148 }; /* Class ResidualBasedNewtonRaphsonStrategy */
1149 
1158 } /* namespace Kratos.*/
1159 
1160 #endif /* KRATOS_RESIDUALBASED_NEWTON_RAPHSON_STRATEGY defined */
1161 
Short class definition.
Definition: adaptive_residualbased_newton_raphson_strategy.h:91
void MaxIterationsExceeded(int cycle_number)
Definition: adaptive_residualbased_newton_raphson_strategy.h:1051
AdaptiveResidualBasedNewtonRaphsonStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TLinearSolver::Pointer pNewLinearSolver, typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria, int MaxIterations=30, int MinIterations=4, bool CalculateReactions=false, bool ReformDofSetAtEachStep=false, bool MoveMeshFlag=false, double ReductionFactor=0.5, double IncreaseFactor=1.3, int NumberOfCycles=5)
Definition: adaptive_residualbased_newton_raphson_strategy.h:173
TSystemVectorPointerType mpDx
Definition: adaptive_residualbased_newton_raphson_strategy.h:953
TBuilderAndSolverType::Pointer GetBuilderAndSolver()
Definition: adaptive_residualbased_newton_raphson_strategy.h:343
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: adaptive_residualbased_newton_raphson_strategy.h:122
void SetMaxIterationNumber(int MaxIterationNumber)
Definition: adaptive_residualbased_newton_raphson_strategy.h:367
~AdaptiveResidualBasedNewtonRaphsonStrategy() override
Definition: adaptive_residualbased_newton_raphson_strategy.h:323
void SetScheme(typename TSchemeType::Pointer pScheme)
Definition: adaptive_residualbased_newton_raphson_strategy.h:329
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: adaptive_residualbased_newton_raphson_strategy.h:127
std::string Info() const override
Turn back information as a string.
Definition: adaptive_residualbased_newton_raphson_strategy.h:870
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: adaptive_residualbased_newton_raphson_strategy.h:882
void CalculateOutputData() override
Definition: adaptive_residualbased_newton_raphson_strategy.h:764
bool mCalculateReactionsFlag
Definition: adaptive_residualbased_newton_raphson_strategy.h:972
AdaptiveResidualBasedNewtonRaphsonStrategy(ModelPart &rModelPart, Parameters ThisParameters)
Default constructor. (with parameters)
Definition: adaptive_residualbased_newton_raphson_strategy.h:146
double mReductionFactor
Definition: adaptive_residualbased_newton_raphson_strategy.h:981
BaseType::TSchemeType TSchemeType
Definition: adaptive_residualbased_newton_raphson_strategy.h:112
void SetCalculateReactionsFlag(bool CalculateReactionsFlag)
Definition: adaptive_residualbased_newton_raphson_strategy.h:348
TSystemMatrixType & GetSystemMatrix() override
This method returns the LHS matrix.
Definition: adaptive_residualbased_newton_raphson_strategy.h:854
TConvergenceCriteriaType::Pointer mpConvergenceCriteria
Definition: adaptive_residualbased_newton_raphson_strategy.h:948
void SetBuilderAndSolver(typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver)
Definition: adaptive_residualbased_newton_raphson_strategy.h:339
AdaptiveResidualBasedNewtonRaphsonStrategy()
Default constructor.
Definition: adaptive_residualbased_newton_raphson_strategy.h:137
TSchemeType::Pointer GetScheme()
Definition: adaptive_residualbased_newton_raphson_strategy.h:333
int mMaxIterationNumber
default = 30
Definition: adaptive_residualbased_newton_raphson_strategy.h:977
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: adaptive_residualbased_newton_raphson_strategy.h:1095
SolvingStrategyType::Pointer Create(ModelPart &rModelPart, Parameters ThisParameters) const override
Create method.
Definition: adaptive_residualbased_newton_raphson_strategy.h:396
double Solve() override
The problem of interest is solved.
Definition: adaptive_residualbased_newton_raphson_strategy.h:623
BaseType::TBuilderAndSolverType TBuilderAndSolverType
Definition: adaptive_residualbased_newton_raphson_strategy.h:106
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: adaptive_residualbased_newton_raphson_strategy.h:124
TSystemVectorPointerType mpb
Definition: adaptive_residualbased_newton_raphson_strategy.h:954
bool IsConverged() override
Definition: adaptive_residualbased_newton_raphson_strategy.h:736
unsigned int GetMaxIterationNumber()
Definition: adaptive_residualbased_newton_raphson_strategy.h:371
double mIncreaseFactor
Definition: adaptive_residualbased_newton_raphson_strategy.h:982
int mMinIterationNumber
Definition: adaptive_residualbased_newton_raphson_strategy.h:978
void SetEchoLevel(int Level) override
This sets the level of echo for the solving strategy.
Definition: adaptive_residualbased_newton_raphson_strategy.h:382
AdaptiveResidualBasedNewtonRaphsonStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TLinearSolver::Pointer pNewLinearSolver, typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria, typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver, int MaxIterations=30, int MinIterations=4, bool CalculateReactions=false, bool ReformDofSetAtEachStep=false, bool MoveMeshFlag=false, double ReductionFactor=0.5, double IncreaseFactor=1.3, int NumberOfCycles=5)
Definition: adaptive_residualbased_newton_raphson_strategy.h:257
TBuilderAndSolverType::Pointer mpBuilderAndSolver
Definition: adaptive_residualbased_newton_raphson_strategy.h:946
TSystemMatrixPointerType mpA
Definition: adaptive_residualbased_newton_raphson_strategy.h:955
TSchemeType::Pointer mpScheme
Definition: adaptive_residualbased_newton_raphson_strategy.h:942
void Predict() override
Definition: adaptive_residualbased_newton_raphson_strategy.h:408
void Clear() override
Clears the internal storage.
Definition: adaptive_residualbased_newton_raphson_strategy.h:776
void SetReformDofSetAtEachStepFlag(bool flag)
Definition: adaptive_residualbased_newton_raphson_strategy.h:357
BaseType::TSystemMatrixType TSystemMatrixType
Definition: adaptive_residualbased_newton_raphson_strategy.h:118
KRATOS_CLASS_POINTER_DEFINITION(AdaptiveResidualBasedNewtonRaphsonStrategy)
AdaptiveResidualBasedNewtonRaphsonStrategy(const AdaptiveResidualBasedNewtonRaphsonStrategy &Other)
bool mReformDofSetAtEachStep
Definition: adaptive_residualbased_newton_raphson_strategy.h:965
bool mInitializeWasPerformed
Definition: adaptive_residualbased_newton_raphson_strategy.h:979
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: adaptive_residualbased_newton_raphson_strategy.h:876
BaseType::DofsArrayType DofsArrayType
Definition: adaptive_residualbased_newton_raphson_strategy.h:116
int mNumberOfCycles
Definition: adaptive_residualbased_newton_raphson_strategy.h:984
TSparseSpace SparseSpaceType
Definition: adaptive_residualbased_newton_raphson_strategy.h:110
BaseType::TDataType TDataType
Definition: adaptive_residualbased_newton_raphson_strategy.h:108
BaseType::TSystemVectorType TSystemVectorType
Definition: adaptive_residualbased_newton_raphson_strategy.h:120
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: adaptive_residualbased_newton_raphson_strategy.h:807
bool GetCalculateReactionsFlag()
Definition: adaptive_residualbased_newton_raphson_strategy.h:352
TLinearSolver::Pointer mpLinearSolver
Definition: adaptive_residualbased_newton_raphson_strategy.h:944
void ReductionStrategy(ModelPart &model_part, double NewTime)
Definition: adaptive_residualbased_newton_raphson_strategy.h:1077
bool mSolutionStepIsInitialized
Definition: adaptive_residualbased_newton_raphson_strategy.h:974
void InitializeSolutionStep() override
Performs all the required operations that should be done (for each step) before solving the solution ...
Definition: adaptive_residualbased_newton_raphson_strategy.h:1020
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: adaptive_residualbased_newton_raphson_strategy.h:126
AdaptiveResidualBasedNewtonRaphsonStrategy< TSparseSpace, TDenseSpace, TLinearSolver > ClassType
Definition: adaptive_residualbased_newton_raphson_strategy.h:104
bool CyclicSolve()
Definition: adaptive_residualbased_newton_raphson_strategy.h:440
ConvergenceCriteria< TSparseSpace, TDenseSpace > TConvergenceCriteriaType
Definition: adaptive_residualbased_newton_raphson_strategy.h:95
bool GetReformDofSetAtEachStepFlag()
Definition: adaptive_residualbased_newton_raphson_strategy.h:362
SolvingStrategy< TSparseSpace, TDenseSpace > SolvingStrategyType
Definition: adaptive_residualbased_newton_raphson_strategy.h:100
void PrintIncreaseOfDeltaTime(double old_dt, double new_dt)
Definition: adaptive_residualbased_newton_raphson_strategy.h:1063
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: adaptive_residualbased_newton_raphson_strategy.h:835
void Initialize() override
Initialization of member variables and prior operations.
Definition: adaptive_residualbased_newton_raphson_strategy.h:991
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: adaptive_residualbased_newton_raphson_strategy.h:102
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
This is the base class to define the different convergence criterion considered.
Definition: convergence_criteria.h:58
Implicit solving strategy base class This is the base class from which we will derive all the implici...
Definition: implicit_solving_strategy.h:61
BaseType::TSystemVectorType TSystemVectorType
Definition: implicit_solving_strategy.h:72
void SetRebuildLevel(int Level) override
This sets the build level.
Definition: implicit_solving_strategy.h:207
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: implicit_solving_strategy.h:283
int mRebuildLevel
Definition: implicit_solving_strategy.h:263
bool mStiffnessMatrixIsBuilt
The current rebuild level.
Definition: implicit_solving_strategy.h:264
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: implicit_solving_strategy.h:76
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: implicit_solving_strategy.h:74
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: implicit_solving_strategy.h:80
BaseType::TSystemMatrixType TSystemMatrixType
Definition: implicit_solving_strategy.h:70
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: implicit_solving_strategy.h:78
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: implicit_solving_strategy.h:169
BaseType::TDataType TDataType
Definition: implicit_solving_strategy.h:68
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
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
int GetInt() const
This method returns the integer contained in the current Parameter.
Definition: kratos_parameters.cpp:666
void RecursivelyAddMissingParameters(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing contain at least all parameters...
Definition: kratos_parameters.cpp:1457
bool GetBool() const
This method returns the boolean contained in the current Parameter.
Definition: kratos_parameters.cpp:675
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
Current class provides an implementation for standard elimination builder and solving operations.
Definition: residualbased_elimination_builder_and_solver.h:76
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
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
int GetEchoLevel()
This returns the level of echo for the solving strategy.
Definition: solving_strategy.h:271
bool MoveMeshFlag()
This function returns the flag that says if the mesh is moved.
Definition: solving_strategy.h:290
int mEchoLevel
Definition: solving_strategy.h:485
virtual void MoveMesh()
This function is designed to move the mesh.
Definition: solving_strategy.h:330
static void Resize(MatrixType &rA, SizeType m, SizeType n)
Definition: ublas_space.h:558
static void Clear(MatrixPointerType &pA)
Definition: ublas_space.h:578
static IndexType Size(VectorType const &rV)
return size of vector rV
Definition: ublas_space.h:190
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_WATCH(variable)
Definition: define.h:806
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_WARNING(label)
Definition: logger.h:265
bool Has(const std::string &ModelerName)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:24
TSpaceType::VectorPointerType CreateEmptyVectorPointer(TSpaceType &dummy)
Definition: add_strategies_to_python.cpp:187
TSpaceType::MatrixPointerType CreateEmptyMatrixPointer(TSpaceType &dummy)
Definition: add_strategies_to_python.cpp:181
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
bool WriteMatrixMarketMatrix(const char *FileName, CompressedMatrixType &M, bool Symmetric)
Definition: matrix_market_interface.h:308
model_part
Definition: face_heat.py:14
delta_time
Definition: generate_frictional_mortar_condition.py:130
integer i
Definition: TensorModule.f:17
double precision function mb(a)
Definition: TensorModule.f:849