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.
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 #if !defined(KRATOS_RESIDUALBASED_NEWTON_RAPHSON_STRATEGY)
14 #define KRATOS_RESIDUALBASED_NEWTON_RAPHSON_STRATEGY
15 
16 // System includes
17 #include <iostream>
18 
19 // External includes
20 
21 // Project includes
22 #include "includes/define.h"
26 
27 //default builder and solver
29 
30 namespace Kratos
31 {
32 
35 
39 
41 
44 
48 
52 
60 template <class TSparseSpace,
61  class TDenseSpace, // = DenseSpace<double>,
62  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
63  >
65  : public ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>
66 {
67  public:
71 
72  // Counted pointer of ClassName
74 
76 
78 
80 
82 
83  typedef typename BaseType::TDataType TDataType;
84 
85  typedef TSparseSpace SparseSpaceType;
86 
88 
90 
92 
94 
96 
98 
100 
102 
106 
111  {
112  }
113 
121  {
122  }
123 
129  explicit ResidualBasedNewtonRaphsonStrategy(ModelPart& rModelPart, Parameters ThisParameters)
130  : BaseType(rModelPart),
133  {
134  // Validate and assign defaults
135  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
136  this->AssignSettings(ThisParameters);
137 
138  // Getting builder and solver
139  auto p_builder_and_solver = GetBuilderAndSolver();
140  if (p_builder_and_solver != nullptr) {
141  // Tells to the builder and solver if the reactions have to be Calculated or not
142  p_builder_and_solver->SetCalculateReactionsFlag(mCalculateReactionsFlag);
143 
144  // Tells to the Builder And Solver if the system matrix and vectors need to
145  // be reshaped at each step or not
146  p_builder_and_solver->SetReshapeMatrixFlag(mReformDofSetAtEachStep);
147  } else {
148  KRATOS_WARNING("ResidualBasedNewtonRaphsonStrategy") << "BuilderAndSolver is not initialized. Please assign one before settings flags" << std::endl;
149  }
150 
154  }
155 
168  ModelPart& rModelPart,
169  typename TSchemeType::Pointer pScheme,
170  typename TLinearSolver::Pointer pNewLinearSolver,
171  typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
172  int MaxIterations = 30,
173  bool CalculateReactions = false,
174  bool ReformDofSetAtEachStep = false,
175  bool MoveMeshFlag = false)
176  : BaseType(rModelPart, MoveMeshFlag),
177  mpScheme(pScheme),
178  mpConvergenceCriteria(pNewConvergenceCriteria),
179  mReformDofSetAtEachStep(ReformDofSetAtEachStep),
180  mCalculateReactionsFlag(CalculateReactions),
181  mMaxIterationNumber(MaxIterations),
184  {
185  KRATOS_TRY;
186 
187  // Setting up the default builder and solver
188  mpBuilderAndSolver = typename TBuilderAndSolverType::Pointer(
190 
191  // Tells to the builder and solver if the reactions have to be Calculated or not
192  mpBuilderAndSolver->SetCalculateReactionsFlag(mCalculateReactionsFlag);
193 
194  // Tells to the Builder And Solver if the system matrix and vectors need to
195  // be reshaped at each step or not
196  mpBuilderAndSolver->SetReshapeMatrixFlag(mReformDofSetAtEachStep);
197 
198  // Set EchoLevel to the default value (only time is displayed)
199  SetEchoLevel(1);
200 
201  // By default the matrices are rebuilt at each iteration
202  this->SetRebuildLevel(2);
203 
207 
208  KRATOS_CATCH("");
209  }
210 
223  ModelPart& rModelPart,
224  typename TSchemeType::Pointer pScheme,
225  typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
226  typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver,
227  int MaxIterations = 30,
228  bool CalculateReactions = false,
229  bool ReformDofSetAtEachStep = false,
230  bool MoveMeshFlag = false)
231  : BaseType(rModelPart, MoveMeshFlag),
232  mpScheme(pScheme),
233  mpBuilderAndSolver(pNewBuilderAndSolver),
234  mpConvergenceCriteria(pNewConvergenceCriteria),
235  mReformDofSetAtEachStep(ReformDofSetAtEachStep),
236  mCalculateReactionsFlag(CalculateReactions),
237  mMaxIterationNumber(MaxIterations),
240  {
241  KRATOS_TRY
242 
243  // Getting builder and solver
244  auto p_builder_and_solver = GetBuilderAndSolver();
245 
246  // Tells to the builder and solver if the reactions have to be Calculated or not
247  p_builder_and_solver->SetCalculateReactionsFlag(mCalculateReactionsFlag);
248 
249  // Tells to the Builder And Solver if the system matrix and vectors need to
250  //be reshaped at each step or not
251  p_builder_and_solver->SetReshapeMatrixFlag(mReformDofSetAtEachStep);
252 
253  // Set EchoLevel to the default value (only time is displayed)
254  SetEchoLevel(1);
255 
256  // By default the matrices are rebuilt at each iteration
257  this->SetRebuildLevel(2);
258 
262 
263  KRATOS_CATCH("")
264  }
265 
278  KRATOS_DEPRECATED_MESSAGE("Constructor deprecated, please use the constructor without linear solver")
280  ModelPart& rModelPart,
281  typename TSchemeType::Pointer pScheme,
282  typename TLinearSolver::Pointer pNewLinearSolver,
283  typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
284  typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver,
285  int MaxIterations = 30,
286  bool CalculateReactions = false,
287  bool ReformDofSetAtEachStep = false,
288  bool MoveMeshFlag = false)
289  : ResidualBasedNewtonRaphsonStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(rModelPart, pScheme, pNewConvergenceCriteria, pNewBuilderAndSolver, MaxIterations, CalculateReactions, ReformDofSetAtEachStep, MoveMeshFlag)
290  {
291  KRATOS_TRY
292 
293  KRATOS_WARNING("ResidualBasedNewtonRaphsonStrategy") << "This constructor is deprecated, please use the constructor without linear solver" << std::endl;
294 
295  // Getting builder and solver
296  auto p_builder_and_solver = GetBuilderAndSolver();
297 
298  // We check if the linear solver considered for the builder and solver is consistent
299  auto p_linear_solver = p_builder_and_solver->GetLinearSystemSolver();
300  KRATOS_ERROR_IF(p_linear_solver != pNewLinearSolver) << "Inconsistent linear solver in strategy and builder and solver. Considering the linear solver assigned to builder and solver :\n" << p_linear_solver->Info() << "\n instead of:\n" << pNewLinearSolver->Info() << std::endl;
301 
302  KRATOS_CATCH("")
303  }
304 
314  ModelPart& rModelPart,
315  typename TSchemeType::Pointer pScheme,
316  typename TLinearSolver::Pointer pNewLinearSolver,
317  typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
318  Parameters Settings)
319  : BaseType(rModelPart),
320  mpScheme(pScheme),
321  mpConvergenceCriteria(pNewConvergenceCriteria),
324  {
325  KRATOS_TRY;
326 
327  // Setting up the default builder and solver
328  mpBuilderAndSolver = typename TBuilderAndSolverType::Pointer(
330 
331  // Tells to the builder and solver if the reactions have to be Calculated or not
332  mpBuilderAndSolver->SetCalculateReactionsFlag(mCalculateReactionsFlag);
333 
334  // Tells to the Builder And Solver if the system matrix and vectors need to
335  // be reshaped at each step or not
336  mpBuilderAndSolver->SetReshapeMatrixFlag(mReformDofSetAtEachStep);
337 
338  // Set EchoLevel to the default value (only time is displayed)
339  SetEchoLevel(1);
340 
341  // By default the matrices are rebuilt at each iteration
342  this->SetRebuildLevel(2);
343 
347 
348  KRATOS_CATCH("");
349  }
350 
361  ModelPart& rModelPart,
362  typename TSchemeType::Pointer pScheme,
363  typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
364  typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver,
365  Parameters Settings)
366  : BaseType(rModelPart),
367  mpScheme(pScheme),
368  mpBuilderAndSolver(pNewBuilderAndSolver),
369  mpConvergenceCriteria(pNewConvergenceCriteria),
372  {
373  KRATOS_TRY
374  // Validate and assign defaults
375  Settings = this->ValidateAndAssignParameters(Settings, this->GetDefaultParameters());
376  this->AssignSettings(Settings);
377  // Getting builder and solver
378  auto p_builder_and_solver = GetBuilderAndSolver();
379 
380  // Tells to the builder and solver if the reactions have to be Calculated or not
381  p_builder_and_solver->SetCalculateReactionsFlag(mCalculateReactionsFlag);
382 
383  // Tells to the Builder And Solver if the system matrix and vectors need to
384  //be reshaped at each step or not
385  p_builder_and_solver->SetReshapeMatrixFlag(mReformDofSetAtEachStep);
386 
387  // Set EchoLevel to the default value (only time is displayed)
388  SetEchoLevel(1);
389 
390  // By default the matrices are rebuilt at each iteration
391  this->SetRebuildLevel(2);
392 
396 
397  KRATOS_CATCH("")
398  }
399 
409  KRATOS_DEPRECATED_MESSAGE("Constructor deprecated, please use the constructor without linear solver")
411  ModelPart& rModelPart,
412  typename TSchemeType::Pointer pScheme,
413  typename TLinearSolver::Pointer pNewLinearSolver,
414  typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
415  typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver,
416  Parameters Settings)
417  : ResidualBasedNewtonRaphsonStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(rModelPart, pScheme, pNewConvergenceCriteria, pNewBuilderAndSolver, Settings)
418  {
419  KRATOS_TRY
420 
421  KRATOS_WARNING("ResidualBasedNewtonRaphsonStrategy") << "This constructor is deprecated, please use the constructor without linear solver" << std::endl;
422 
423  // Getting builder and solver
424  auto p_builder_and_solver = GetBuilderAndSolver();
425 
426  // We check if the linear solver considered for the builder and solver is consistent
427  auto p_linear_solver = p_builder_and_solver->GetLinearSystemSolver();
428  KRATOS_ERROR_IF(p_linear_solver != pNewLinearSolver) << "Inconsistent linear solver in strategy and builder and solver. Considering the linear solver assigned to builder and solver :\n" << p_linear_solver->Info() << "\n instead of:\n" << pNewLinearSolver->Info() << std::endl;
429 
430  KRATOS_CATCH("")
431  }
432 
438  {
439  // If the linear solver has not been deallocated, clean it before
440  // deallocating mpA. This prevents a memory error with the the ML
441  // solver (which holds a reference to it).
442  // NOTE: The linear solver is hold by the B&S
443  auto p_builder_and_solver = this->GetBuilderAndSolver();
444  if (p_builder_and_solver != nullptr) {
445  p_builder_and_solver->Clear();
446  }
447 
448  // Deallocating system vectors to avoid errors in MPI. Clear calls
449  // TrilinosSpace::Clear for the vectors, which preserves the Map of
450  // current vectors, performing MPI calls in the process. Due to the
451  // way Python garbage collection works, this may happen after
452  // MPI_Finalize has already been called and is an error. Resetting
453  // the pointers here prevents Clear from operating with the
454  // (now deallocated) vectors.
455  mpA.reset();
456  mpDx.reset();
457  mpb.reset();
458 
459  Clear();
460  }
461 
466  void SetScheme(typename TSchemeType::Pointer pScheme)
467  {
468  mpScheme = pScheme;
469  };
470 
475  typename TSchemeType::Pointer GetScheme()
476  {
477  return mpScheme;
478  };
479 
484  void SetBuilderAndSolver(typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver)
485  {
486  mpBuilderAndSolver = pNewBuilderAndSolver;
487  };
488 
493  typename TBuilderAndSolverType::Pointer GetBuilderAndSolver()
494  {
495  return mpBuilderAndSolver;
496  };
497 
502  void SetInitializePerformedFlag(bool InitializePerformedFlag = true)
503  {
504  mInitializeWasPerformed = InitializePerformedFlag;
505  }
506 
512  {
514  }
515 
520  void SetCalculateReactionsFlag(bool CalculateReactionsFlag)
521  {
522  mCalculateReactionsFlag = CalculateReactionsFlag;
523  }
524 
530  {
532  }
533 
538  void SetUseOldStiffnessInFirstIterationFlag(bool UseOldStiffnessInFirstIterationFlag)
539  {
540  mUseOldStiffnessInFirstIteration = UseOldStiffnessInFirstIterationFlag;
541  }
542 
548  {
550  }
551 
557  {
559  GetBuilderAndSolver()->SetReshapeMatrixFlag(mReformDofSetAtEachStep);
560  }
561 
567  {
569  }
570 
575  void SetMaxIterationNumber(unsigned int MaxIterationNumber)
576  {
577  mMaxIterationNumber = MaxIterationNumber;
578  }
579 
584  unsigned int GetMaxIterationNumber()
585  {
586  return mMaxIterationNumber;
587  }
588 
599  void SetEchoLevel(int Level) override
600  {
601  BaseType::mEchoLevel = Level;
602  GetBuilderAndSolver()->SetEchoLevel(Level);
603  }
604 
605  //*********************************************************************************
613  typename SolvingStrategyType::Pointer Create(
614  ModelPart& rModelPart,
615  Parameters ThisParameters
616  ) const override
617  {
618  return Kratos::make_shared<ClassType>(rModelPart, ThisParameters);
619  }
620 
625  void Predict() override
626  {
627  KRATOS_TRY
629  //OPERATIONS THAT SHOULD BE DONE ONCE - internal check to avoid repetitions
630  //if the operations needed were already performed this does nothing
631  if (mInitializeWasPerformed == false)
632  Initialize();
633 
634  TSystemMatrixType& rA = *mpA;
635  TSystemVectorType& rDx = *mpDx;
636  TSystemVectorType& rb = *mpb;
637 
638  DofsArrayType& r_dof_set = GetBuilderAndSolver()->GetDofSet();
639 
640  GetScheme()->Predict(BaseType::GetModelPart(), r_dof_set, rA, rDx, rb);
641 
642  // Applying constraints if needed
643  auto& r_constraints_array = BaseType::GetModelPart().MasterSlaveConstraints();
644  const int local_number_of_constraints = r_constraints_array.size();
645  const int global_number_of_constraints = r_comm.SumAll(local_number_of_constraints);
646  if(global_number_of_constraints != 0) {
647  const auto& r_process_info = BaseType::GetModelPart().GetProcessInfo();
648 
649  block_for_each(r_constraints_array, [&r_process_info](MasterSlaveConstraint& rConstraint){
650  rConstraint.ResetSlaveDofs(r_process_info);
651  });
652  block_for_each(r_constraints_array, [&r_process_info](MasterSlaveConstraint& rConstraint){
653  rConstraint.Apply(r_process_info);
654  });
655 
656  // The following is needed since we need to eventually compute time derivatives after applying
657  // Master slave relations
658  TSparseSpace::SetToZero(rDx);
659  this->GetScheme()->Update(BaseType::GetModelPart(), r_dof_set, rA, rDx, rb);
660  }
661 
662  // Move the mesh if needed
663  if (this->MoveMeshFlag() == true)
665 
666  KRATOS_CATCH("")
667  }
668 
672  void Initialize() override
673  {
674  KRATOS_TRY;
675 
676  if (mInitializeWasPerformed == false)
677  {
678  //pointers needed in the solution
679  typename TSchemeType::Pointer p_scheme = GetScheme();
680  typename TConvergenceCriteriaType::Pointer p_convergence_criteria = mpConvergenceCriteria;
681 
682  //Initialize The Scheme - OPERATIONS TO BE DONE ONCE
683  if (p_scheme->SchemeIsInitialized() == false)
684  p_scheme->Initialize(BaseType::GetModelPart());
685 
686  //Initialize The Elements - OPERATIONS TO BE DONE ONCE
687  if (p_scheme->ElementsAreInitialized() == false)
688  p_scheme->InitializeElements(BaseType::GetModelPart());
689 
690  //Initialize The Conditions - OPERATIONS TO BE DONE ONCE
691  if (p_scheme->ConditionsAreInitialized() == false)
692  p_scheme->InitializeConditions(BaseType::GetModelPart());
693 
694  //initialisation of the convergence criteria
695  if (p_convergence_criteria->IsInitialized() == false)
696  p_convergence_criteria->Initialize(BaseType::GetModelPart());
697 
699  }
700 
701  KRATOS_CATCH("");
702  }
703 
707  void Clear() override
708  {
709  KRATOS_TRY;
710 
711  // Setting to zero the internal flag to ensure that the dof sets are recalculated. Also clear the linear solver stored in the B&S
712  auto p_builder_and_solver = GetBuilderAndSolver();
713  if (p_builder_and_solver != nullptr) {
714  p_builder_and_solver->SetDofSetIsInitializedFlag(false);
715  p_builder_and_solver->Clear();
716  }
717 
718  // Clearing the system of equations
719  if (mpA != nullptr)
721  if (mpDx != nullptr)
723  if (mpb != nullptr)
725 
726  // Clearing scheme
727  auto p_scheme = GetScheme();
728  if (p_scheme != nullptr) {
729  GetScheme()->Clear();
730  }
731 
732  mInitializeWasPerformed = false;
733 
734  KRATOS_CATCH("");
735  }
736 
740  bool IsConverged() override
741  {
742  KRATOS_TRY;
743 
744  TSystemMatrixType& rA = *mpA;
745  TSystemVectorType& rDx = *mpDx;
746  TSystemVectorType& rb = *mpb;
747 
748  if (mpConvergenceCriteria->GetActualizeRHSflag() == true)
749  {
750  TSparseSpace::SetToZero(rb);
752  }
753 
754  return mpConvergenceCriteria->PostCriteria(BaseType::GetModelPart(), GetBuilderAndSolver()->GetDofSet(), rA, rDx, rb);
755 
756  KRATOS_CATCH("");
757  }
758 
766  void CalculateOutputData() override
767  {
768  TSystemMatrixType& rA = *mpA;
769  TSystemVectorType& rDx = *mpDx;
770  TSystemVectorType& rb = *mpb;
771 
772  GetScheme()->CalculateOutputData(BaseType::GetModelPart(),
773  GetBuilderAndSolver()->GetDofSet(),
774  rA, rDx, rb);
775  }
776 
781  void InitializeSolutionStep() override
782  {
783  KRATOS_TRY;
784 
785  // Pointers needed in the solution
786  typename TSchemeType::Pointer p_scheme = GetScheme();
787  typename TBuilderAndSolverType::Pointer p_builder_and_solver = GetBuilderAndSolver();
788  ModelPart& r_model_part = BaseType::GetModelPart();
789 
790  // Set up the system, operation performed just once unless it is required
791  // to reform the dof set at each iteration
792  BuiltinTimer system_construction_time;
793  if (!p_builder_and_solver->GetDofSetIsInitializedFlag() || mReformDofSetAtEachStep)
794  {
795  // Setting up the list of the DOFs to be solved
796  BuiltinTimer setup_dofs_time;
797  p_builder_and_solver->SetUpDofSet(p_scheme, r_model_part);
798  KRATOS_INFO_IF("ResidualBasedNewtonRaphsonStrategy", BaseType::GetEchoLevel() > 0) << "Setup Dofs Time: "
799  << setup_dofs_time << std::endl;
800 
801  // Shaping correctly the system
802  BuiltinTimer setup_system_time;
803  p_builder_and_solver->SetUpSystem(r_model_part);
804  KRATOS_INFO_IF("ResidualBasedNewtonRaphsonStrategy", BaseType::GetEchoLevel() > 0) << "Setup System Time: "
805  << setup_system_time << std::endl;
806 
807  // Setting up the Vectors involved to the correct size
808  BuiltinTimer system_matrix_resize_time;
809  p_builder_and_solver->ResizeAndInitializeVectors(p_scheme, mpA, mpDx, mpb,
810  r_model_part);
811  KRATOS_INFO_IF("ResidualBasedNewtonRaphsonStrategy", BaseType::GetEchoLevel() > 0) << "System Matrix Resize Time: "
812  << system_matrix_resize_time << std::endl;
813  }
814 
815  KRATOS_INFO_IF("ResidualBasedNewtonRaphsonStrategy", BaseType::GetEchoLevel() > 0) << "System Construction Time: "
816  << system_construction_time << std::endl;
817 
818  TSystemMatrixType& rA = *mpA;
819  TSystemVectorType& rDx = *mpDx;
820  TSystemVectorType& rb = *mpb;
821 
822  // Initial operations ... things that are constant over the Solution Step
823  p_builder_and_solver->InitializeSolutionStep(r_model_part, rA, rDx, rb);
824 
825  // Initial operations ... things that are constant over the Solution Step
826  p_scheme->InitializeSolutionStep(r_model_part, rA, rDx, rb);
827 
828  // Initialisation of the convergence criteria
829  if (mpConvergenceCriteria->GetActualizeRHSflag())
830  {
831  TSparseSpace::SetToZero(rb);
832  p_builder_and_solver->BuildRHS(p_scheme, r_model_part, rb);
833  }
834 
835  mpConvergenceCriteria->InitializeSolutionStep(r_model_part, p_builder_and_solver->GetDofSet(), rA, rDx, rb);
836 
837  if (mpConvergenceCriteria->GetActualizeRHSflag()) {
838  TSparseSpace::SetToZero(rb);
839  }
840 
841  KRATOS_CATCH("");
842  }
843 
848  void FinalizeSolutionStep() override
849  {
850  KRATOS_TRY;
851 
852  ModelPart& r_model_part = BaseType::GetModelPart();
853 
854  typename TSchemeType::Pointer p_scheme = GetScheme();
855  typename TBuilderAndSolverType::Pointer p_builder_and_solver = GetBuilderAndSolver();
856 
857  TSystemMatrixType& rA = *mpA;
858  TSystemVectorType& rDx = *mpDx;
859  TSystemVectorType& rb = *mpb;
860 
861  //Finalisation of the solution step,
862  //operations to be done after achieving convergence, for example the
863  //Final Residual Vector (mb) has to be saved in there
864  //to avoid error accumulation
865 
866  p_scheme->FinalizeSolutionStep(r_model_part, rA, rDx, rb);
867  p_builder_and_solver->FinalizeSolutionStep(r_model_part, rA, rDx, rb);
868  mpConvergenceCriteria->FinalizeSolutionStep(r_model_part, p_builder_and_solver->GetDofSet(), rA, rDx, rb);
869 
870  //Cleaning memory after the solution
871  p_scheme->Clean();
872 
873  if (mReformDofSetAtEachStep == true) //deallocate the systemvectors
874  {
875  this->Clear();
876  }
877 
878  KRATOS_CATCH("");
879  }
880 
884  bool SolveSolutionStep() override
885  {
886  // Pointers needed in the solution
887  ModelPart& r_model_part = BaseType::GetModelPart();
888  typename TSchemeType::Pointer p_scheme = GetScheme();
889  typename TBuilderAndSolverType::Pointer p_builder_and_solver = GetBuilderAndSolver();
890  auto& r_dof_set = p_builder_and_solver->GetDofSet();
891 
892  TSystemMatrixType& rA = *mpA;
893  TSystemVectorType& rDx = *mpDx;
894  TSystemVectorType& rb = *mpb;
895 
896  //initializing the parameters of the Newton-Raphson cycle
897  unsigned int iteration_number = 1;
898  r_model_part.GetProcessInfo()[NL_ITERATION_NUMBER] = iteration_number;
899  bool residual_is_updated = false;
900  p_scheme->InitializeNonLinIteration(r_model_part, rA, rDx, rb);
901  mpConvergenceCriteria->InitializeNonLinearIteration(r_model_part, r_dof_set, rA, rDx, rb);
902  bool is_converged = mpConvergenceCriteria->PreCriteria(r_model_part, r_dof_set, rA, rDx, rb);
903 
904  // Function to perform the building and the solving phase.
906  TSparseSpace::SetToZero(rA);
907  TSparseSpace::SetToZero(rDx);
908  TSparseSpace::SetToZero(rb);
909 
911  p_builder_and_solver->BuildAndSolveLinearizedOnPreviousIteration(p_scheme, r_model_part, rA, rDx, rb,BaseType::MoveMeshFlag());
912  } else {
913  p_builder_and_solver->BuildAndSolve(p_scheme, r_model_part, rA, rDx, rb);
914  }
915  } else {
916  TSparseSpace::SetToZero(rDx); // Dx = 0.00;
917  TSparseSpace::SetToZero(rb);
918 
919  p_builder_and_solver->BuildRHSAndSolve(p_scheme, r_model_part, rA, rDx, rb);
920  }
921 
922  // Debugging info
923  EchoInfo(iteration_number);
924 
925  // Updating the results stored in the database
926  UpdateDatabase(rA, rDx, rb, BaseType::MoveMeshFlag());
927 
928  p_scheme->FinalizeNonLinIteration(r_model_part, rA, rDx, rb);
929  mpConvergenceCriteria->FinalizeNonLinearIteration(r_model_part, r_dof_set, rA, rDx, rb);
930 
931  if (is_converged) {
932  if (mpConvergenceCriteria->GetActualizeRHSflag()) {
933  TSparseSpace::SetToZero(rb);
934 
935  p_builder_and_solver->BuildRHS(p_scheme, r_model_part, rb);
936  }
937 
938  is_converged = mpConvergenceCriteria->PostCriteria(r_model_part, r_dof_set, rA, rDx, rb);
939  }
940 
941  //Iteration Cycle... performed only for NonLinearProblems
942  while (is_converged == false &&
943  iteration_number++ < mMaxIterationNumber)
944  {
945  //setting the number of iteration
946  r_model_part.GetProcessInfo()[NL_ITERATION_NUMBER] = iteration_number;
947 
948  p_scheme->InitializeNonLinIteration(r_model_part, rA, rDx, rb);
949  mpConvergenceCriteria->InitializeNonLinearIteration(r_model_part, r_dof_set, rA, rDx, rb);
950 
951  is_converged = mpConvergenceCriteria->PreCriteria(r_model_part, r_dof_set, rA, rDx, rb);
952 
953  //call the linear system solver to find the correction mDx for the
954  //it is not called if there is no system to solve
955  if (SparseSpaceType::Size(rDx) != 0)
956  {
958  {
960  {
961  //A = 0.00;
962  TSparseSpace::SetToZero(rA);
963  TSparseSpace::SetToZero(rDx);
964  TSparseSpace::SetToZero(rb);
965 
966  p_builder_and_solver->BuildAndSolve(p_scheme, r_model_part, rA, rDx, rb);
967  }
968  else
969  {
970  TSparseSpace::SetToZero(rDx);
971  TSparseSpace::SetToZero(rb);
972 
973  p_builder_and_solver->BuildRHSAndSolve(p_scheme, r_model_part, rA, rDx, rb);
974  }
975  }
976  else
977  {
978  TSparseSpace::SetToZero(rDx);
979  TSparseSpace::SetToZero(rb);
980 
981  p_builder_and_solver->BuildRHSAndSolve(p_scheme, r_model_part, rA, rDx, rb);
982  }
983  }
984  else
985  {
986  KRATOS_WARNING("NO DOFS") << "ATTENTION: no free DOFs!! " << std::endl;
987  }
988 
989  // Debugging info
990  EchoInfo(iteration_number);
991 
992  // Updating the results stored in the database
993  UpdateDatabase(rA, rDx, rb, BaseType::MoveMeshFlag());
994 
995  p_scheme->FinalizeNonLinIteration(r_model_part, rA, rDx, rb);
996  mpConvergenceCriteria->FinalizeNonLinearIteration(r_model_part, r_dof_set, rA, rDx, rb);
997 
998  residual_is_updated = false;
999 
1000  if (is_converged == true)
1001  {
1002  if (mpConvergenceCriteria->GetActualizeRHSflag() == true)
1003  {
1004  TSparseSpace::SetToZero(rb);
1005 
1006  p_builder_and_solver->BuildRHS(p_scheme, r_model_part, rb);
1007  residual_is_updated = true;
1008  }
1009 
1010  is_converged = mpConvergenceCriteria->PostCriteria(r_model_part, r_dof_set, rA, rDx, rb);
1011  }
1012  }
1013 
1014  //plots a warning if the maximum number of iterations is exceeded
1015  if (iteration_number >= mMaxIterationNumber) {
1017  } else {
1018  KRATOS_INFO_IF("ResidualBasedNewtonRaphsonStrategy", this->GetEchoLevel() > 0)
1019  << "Convergence achieved after " << iteration_number << " / "
1020  << mMaxIterationNumber << " iterations" << std::endl;
1021  }
1022 
1023  //recalculate residual if needed
1024  //(note that some convergence criteria need it to be recalculated)
1025  if (residual_is_updated == false)
1026  {
1027  // NOTE:
1028  // The following part will be commented because it is time consuming
1029  // and there is no obvious reason to be here. If someone need this
1030  // part please notify the community via mailing list before uncommenting it.
1031  // Pooyan.
1032 
1033  // TSparseSpace::SetToZero(mb);
1034  // p_builder_and_solver->BuildRHS(p_scheme, r_model_part, mb);
1035  }
1036 
1037  //calculate reactions if required
1038  if (mCalculateReactionsFlag == true)
1039  p_builder_and_solver->CalculateReactions(p_scheme, r_model_part, rA, rDx, rb);
1040 
1041  return is_converged;
1042  }
1043 
1048  int Check() override
1049  {
1050  KRATOS_TRY
1051 
1052  BaseType::Check();
1053 
1055 
1056  GetScheme()->Check(BaseType::GetModelPart());
1057 
1059 
1060  return 0;
1061 
1062  KRATOS_CATCH("")
1063  }
1064 
1070  {
1071  Parameters default_parameters = Parameters(R"(
1072  {
1073  "name" : "newton_raphson_strategy",
1074  "use_old_stiffness_in_first_iteration": false,
1075  "max_iteration" : 10,
1076  "reform_dofs_at_each_step" : false,
1077  "compute_reactions" : false,
1078  "builder_and_solver_settings" : {},
1079  "convergence_criteria_settings" : {},
1080  "linear_solver_settings" : {},
1081  "scheme_settings" : {}
1082  })");
1083 
1084  // Getting base class default parameters
1085  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
1086  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
1087  return default_parameters;
1088  }
1089 
1094  static std::string Name()
1095  {
1096  return "newton_raphson_strategy";
1097  }
1098 
1101 
1103 
1107 
1111 
1117  {
1118  TSystemMatrixType &mA = *mpA;
1119 
1120  return mA;
1121  }
1122 
1128  {
1129  TSystemVectorType& mb = *mpb;
1130 
1131  return mb;
1132  }
1133 
1139  {
1140  TSystemVectorType& mDx = *mpDx;
1141 
1142  return mDx;
1143  }
1144 
1150  {
1152  }
1153 
1159  {
1161  }
1162 
1166 
1170 
1172  std::string Info() const override
1173  {
1174  return "ResidualBasedNewtonRaphsonStrategy";
1175  }
1176 
1178  void PrintInfo(std::ostream& rOStream) const override
1179  {
1180  rOStream << Info();
1181  }
1182 
1184  void PrintData(std::ostream& rOStream) const override
1185  {
1186  rOStream << Info();
1187  }
1188 
1192 
1194 
1195  private:
1198 
1202 
1206 
1210 
1214 
1218 
1222 
1224  protected:
1227 
1231 
1232  typename TSchemeType::Pointer mpScheme = nullptr;
1233  typename TBuilderAndSolverType::Pointer mpBuilderAndSolver = nullptr;
1234  typename TConvergenceCriteriaType::Pointer mpConvergenceCriteria = nullptr;
1235 
1239 
1248 
1254 
1260 
1261  unsigned int mMaxIterationNumber;
1262 
1264 
1265  bool mKeepSystemConstantDuringIterations; // Flag to allow keeping system matrix constant during iterations
1266 
1270 
1278  virtual void UpdateDatabase(
1279  TSystemMatrixType& rA,
1280  TSystemVectorType& rDx,
1281  TSystemVectorType& rb,
1282  const bool MoveMesh)
1283  {
1284  typename TSchemeType::Pointer p_scheme = GetScheme();
1285  typename TBuilderAndSolverType::Pointer p_builder_and_solver = GetBuilderAndSolver();
1286 
1287  p_scheme->Update(BaseType::GetModelPart(), p_builder_and_solver->GetDofSet(), rA, rDx, rb);
1288 
1289  // Move the mesh if needed
1290  if (MoveMesh == true)
1292  }
1293 
1298  virtual void EchoInfo(const unsigned int IterationNumber)
1299  {
1300  TSystemMatrixType& rA = *mpA;
1301  TSystemVectorType& rDx = *mpDx;
1302  TSystemVectorType& rb = *mpb;
1303 
1304  if (this->GetEchoLevel() == 2) //if it is needed to print the debug info
1305  {
1306  KRATOS_INFO("Dx") << "Solution obtained = " << rDx << std::endl;
1307  KRATOS_INFO("RHS") << "RHS = " << rb << std::endl;
1308  }
1309  else if (this->GetEchoLevel() == 3) //if it is needed to print the debug info
1310  {
1311  KRATOS_INFO("LHS") << "SystemMatrix = " << rA << std::endl;
1312  KRATOS_INFO("Dx") << "Solution obtained = " << rDx << std::endl;
1313  KRATOS_INFO("RHS") << "RHS = " << rb << std::endl;
1314  }
1315  else if (this->GetEchoLevel() == 4) //print to matrix market file
1316  {
1317  std::stringstream matrix_market_name;
1318  matrix_market_name << "A_" << BaseType::GetModelPart().GetProcessInfo()[TIME] << "_" << IterationNumber << ".mm";
1319  TSparseSpace::WriteMatrixMarketMatrix((char *)(matrix_market_name.str()).c_str(), rA, false);
1320 
1321  std::stringstream matrix_market_vectname;
1322  matrix_market_vectname << "b_" << BaseType::GetModelPart().GetProcessInfo()[TIME] << "_" << IterationNumber << ".mm.rhs";
1323  TSparseSpace::WriteMatrixMarketVector((char *)(matrix_market_vectname.str()).c_str(), rb);
1324 
1325  std::stringstream matrix_market_dxname;
1326  matrix_market_dxname << "dx_" << BaseType::GetModelPart().GetProcessInfo()[TIME] << "_" << IterationNumber << ".mm.rhs";
1327  TSparseSpace::WriteMatrixMarketVector((char *)(matrix_market_dxname.str()).c_str(), rDx);
1328 
1329  std::stringstream dof_data_name;
1330  unsigned int rank=BaseType::GetModelPart().GetCommunicator().MyPID();
1331  dof_data_name << "dofdata_" << BaseType::GetModelPart().GetProcessInfo()[TIME]
1332  << "_" << IterationNumber << "_rank_"<< rank << ".csv";
1333  WriteDofInfo(dof_data_name.str(), rDx);
1334  }
1335  }
1336 
1340  virtual void MaxIterationsExceeded()
1341  {
1342  KRATOS_INFO_IF("ResidualBasedNewtonRaphsonStrategy", this->GetEchoLevel() > 0)
1343  << "ATTENTION: max iterations ( " << mMaxIterationNumber
1344  << " ) exceeded!" << std::endl;
1345  }
1346 
1351  void AssignSettings(const Parameters ThisParameters) override
1352  {
1353  BaseType::AssignSettings(ThisParameters);
1354  mMaxIterationNumber = ThisParameters["max_iteration"].GetInt();
1355  mReformDofSetAtEachStep = ThisParameters["reform_dofs_at_each_step"].GetBool();
1356  mCalculateReactionsFlag = ThisParameters["compute_reactions"].GetBool();
1357  mUseOldStiffnessInFirstIteration = ThisParameters["use_old_stiffness_in_first_iteration"].GetBool();
1358 
1359  // Saving the convergence criteria to be used
1360  if (ThisParameters["convergence_criteria_settings"].Has("name")) {
1361  KRATOS_ERROR << "IMPLEMENTATION PENDING IN CONSTRUCTOR WITH PARAMETERS" << std::endl;
1362  }
1363 
1364  // Saving the scheme
1365  if (ThisParameters["scheme_settings"].Has("name")) {
1366  KRATOS_ERROR << "IMPLEMENTATION PENDING IN CONSTRUCTOR WITH PARAMETERS" << std::endl;
1367  }
1368 
1369  // Setting up the default builder and solver
1370  if (ThisParameters["builder_and_solver_settings"].Has("name")) {
1371  KRATOS_ERROR << "IMPLEMENTATION PENDING IN CONSTRUCTOR WITH PARAMETERS" << std::endl;
1372  }
1373  }
1374 
1375  void WriteDofInfo(std::string FileName, const TSystemVectorType& rDX)
1376  {
1377  std::ofstream out(FileName);
1378 
1379  out.precision(15);
1380  out << "EquationId,NodeId,VariableName,IsFixed,Value,coordx,coordy,coordz" << std::endl;
1381  for(const auto& rdof : GetBuilderAndSolver()->GetDofSet()) {
1382  const auto& coords = BaseType::GetModelPart().Nodes()[rdof.Id()].Coordinates();
1383  out << rdof.EquationId() << "," << rdof.Id() << "," << rdof.GetVariable().Name() << "," << rdof.IsFixed() << ","
1384  << rdof.GetSolutionStepValue() << "," << "," << coords[0] << "," << coords[1] << "," << coords[2]<< "\n";
1385  }
1386  out.close();
1387  }
1388 
1392 
1396 
1400 
1404 
1410 
1412 
1413 }; /* Class ResidualBasedNewtonRaphsonStrategy */
1414 
1416 
1419 
1421 
1422 } /* namespace Kratos. */
1423 
1424 #endif /* KRATOS_RESIDUALBASED_NEWTON_RAPHSON_STRATEGY defined */
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
Definition: builtin_timer.h:26
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
virtual int MyPID() const
Definition: communicator.cpp:91
This is the base class to define the different convergence criterion considered.
Definition: convergence_criteria.h:58
Serial (do-nothing) version of a wrapper class for MPI communication.
Definition: data_communicator.h:318
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
Scheme< TSparseSpace, TDenseSpace > TSchemeType
Definition: implicit_solving_strategy.h:82
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
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > TBuilderAndSolverType
Definition: implicit_solving_strategy.h:84
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: implicit_solving_strategy.h:74
BaseType::TSystemMatrixType TSystemMatrixType
Definition: implicit_solving_strategy.h:70
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: implicit_solving_strategy.h:169
A class that implements the interface for different master-slave constraints to be applied on a syste...
Definition: master_slave_constraint.h:76
virtual void ResetSlaveDofs(const ProcessInfo &rCurrentProcessInfo)
This method resets the values of the slave dofs.
Definition: master_slave_constraint.h:373
virtual void Apply(const ProcessInfo &rCurrentProcessInfo)
This method directly applies the master/slave relationship.
Definition: master_slave_constraint.h:382
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MasterSlaveConstraintContainerType & MasterSlaveConstraints(IndexType ThisIndex=0)
Definition: model_part.h:654
Communicator & GetCommunicator()
Definition: model_part.h:1821
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
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 builder and solving operations.
Definition: residualbased_block_builder_and_solver.h:82
This is the base Newton Raphson strategy.
Definition: residualbased_newton_raphson_strategy.h:66
ResidualBasedNewtonRaphsonStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TLinearSolver::Pointer pNewLinearSolver, typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria, Parameters Settings)
Definition: residualbased_newton_raphson_strategy.h:313
ResidualBasedNewtonRaphsonStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria, typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver, Parameters Settings)
Constructor specifying the builder and solver and using Parameters.
Definition: residualbased_newton_raphson_strategy.h:360
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residualbased_newton_raphson_strategy.h:97
void SetMaxIterationNumber(unsigned int MaxIterationNumber)
This method sets the flag mMaxIterationNumber.
Definition: residualbased_newton_raphson_strategy.h:575
bool mUseOldStiffnessInFirstIteration
Flag telling if a full update of the database will be performed at the first iteration.
Definition: residualbased_newton_raphson_strategy.h:1259
TSystemVectorType & GetSystemVector() override
This method returns the RHS vector.
Definition: residualbased_newton_raphson_strategy.h:1127
ResidualBasedNewtonRaphsonStrategy(ModelPart &rModelPart)
Default constructor. (with parameters)
Definition: residualbased_newton_raphson_strategy.h:119
void SetKeepSystemConstantDuringIterations(bool Value)
Set method for the flag mKeepSystemConstantDuringIterations.
Definition: residualbased_newton_raphson_strategy.h:1149
TSparseSpace SparseSpaceType
Definition: residualbased_newton_raphson_strategy.h:85
std::string Info() const override
Turn back information as a string.
Definition: residualbased_newton_raphson_strategy.h:1172
TBuilderAndSolverType::Pointer GetBuilderAndSolver()
Get method for the builder and solver.
Definition: residualbased_newton_raphson_strategy.h:493
virtual void UpdateDatabase(TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb, const bool MoveMesh)
Here the database is updated.
Definition: residualbased_newton_raphson_strategy.h:1278
int Check() override
Function to perform expensive checks.
Definition: residualbased_newton_raphson_strategy.h:1048
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: residualbased_newton_raphson_strategy.h:1178
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedNewtonRaphsonStrategy)
TSystemMatrixType & GetSystemMatrix() override
This method returns the LHS matrix.
Definition: residualbased_newton_raphson_strategy.h:1116
ResidualBasedNewtonRaphsonStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria, typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver, int MaxIterations=30, bool CalculateReactions=false, bool ReformDofSetAtEachStep=false, bool MoveMeshFlag=false)
Constructor specifying the builder and solver.
Definition: residualbased_newton_raphson_strategy.h:222
ResidualBasedNewtonRaphsonStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TLinearSolver::Pointer pNewLinearSolver, typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria, int MaxIterations=30, bool CalculateReactions=false, bool ReformDofSetAtEachStep=false, bool MoveMeshFlag=false)
Definition: residualbased_newton_raphson_strategy.h:167
BaseType::TDataType TDataType
Definition: residualbased_newton_raphson_strategy.h:83
ConvergenceCriteria< TSparseSpace, TDenseSpace > TConvergenceCriteriaType
Definition: residualbased_newton_raphson_strategy.h:70
bool mKeepSystemConstantDuringIterations
Flag to set as initialized the strategy.
Definition: residualbased_newton_raphson_strategy.h:1265
unsigned int mMaxIterationNumber
Definition: residualbased_newton_raphson_strategy.h:1261
TSchemeType::Pointer GetScheme()
Get method for the time scheme.
Definition: residualbased_newton_raphson_strategy.h:475
BaseType::TSystemVectorType TSystemVectorType
Definition: residualbased_newton_raphson_strategy.h:93
TSystemVectorPointerType mpb
The increment in the solution.
Definition: residualbased_newton_raphson_strategy.h:1237
bool GetInitializePerformedFlag()
This method gets the flag mInitializeWasPerformed.
Definition: residualbased_newton_raphson_strategy.h:511
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: residualbased_newton_raphson_strategy.h:77
bool GetReformDofSetAtEachStepFlag()
This method returns the flag mReformDofSetAtEachStep.
Definition: residualbased_newton_raphson_strategy.h:566
unsigned int GetMaxIterationNumber()
This method gets the flag mMaxIterationNumber.
Definition: residualbased_newton_raphson_strategy.h:584
bool GetCalculateReactionsFlag()
This method returns the flag mCalculateReactionsFlag.
Definition: residualbased_newton_raphson_strategy.h:529
SolvingStrategy< TSparseSpace, TDenseSpace > SolvingStrategyType
Definition: residualbased_newton_raphson_strategy.h:75
ResidualBasedNewtonRaphsonStrategy(ModelPart &rModelPart, Parameters ThisParameters)
Default constructor. (with parameters)
Definition: residualbased_newton_raphson_strategy.h:129
TSystemMatrixPointerType mpA
The RHS vector of the system of equations.
Definition: residualbased_newton_raphson_strategy.h:1238
virtual void MaxIterationsExceeded()
This method prints information after reach the max number of iterations.
Definition: residualbased_newton_raphson_strategy.h:1340
bool mCalculateReactionsFlag
Flag telling if it is needed or not to compute the reactions.
Definition: residualbased_newton_raphson_strategy.h:1253
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: residualbased_newton_raphson_strategy.h:1069
TSystemVectorPointerType mpDx
The pointer to the convergence criteria employed.
Definition: residualbased_newton_raphson_strategy.h:1236
TBuilderAndSolverType::Pointer mpBuilderAndSolver
The pointer to the time scheme employed.
Definition: residualbased_newton_raphson_strategy.h:1233
bool SolveSolutionStep() override
Solves the current step. This function returns true if a solution has been found, false otherwise.
Definition: residualbased_newton_raphson_strategy.h:884
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: residualbased_newton_raphson_strategy.h:1094
void SetUseOldStiffnessInFirstIterationFlag(bool UseOldStiffnessInFirstIterationFlag)
This method sets the flag mFullUpdateFlag.
Definition: residualbased_newton_raphson_strategy.h:538
BaseType::TSchemeType TSchemeType
Definition: residualbased_newton_raphson_strategy.h:87
TSystemVectorType & GetSolutionVector() override
This method returns the solution vector.
Definition: residualbased_newton_raphson_strategy.h:1138
void Initialize() override
Initialization of member variables and prior operations.
Definition: residualbased_newton_raphson_strategy.h:672
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: residualbased_newton_raphson_strategy.h:1184
TSchemeType::Pointer mpScheme
Definition: residualbased_newton_raphson_strategy.h:1232
ResidualBasedNewtonRaphsonStrategy()
Default constructor.
Definition: residualbased_newton_raphson_strategy.h:110
void Predict() override
Operation to predict the solution ... if it is not called a trivial predictor is used in which the va...
Definition: residualbased_newton_raphson_strategy.h:625
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: residualbased_newton_raphson_strategy.h:1351
void InitializeSolutionStep() override
Performs all the required operations that should be done (for each step) before solving the solution ...
Definition: residualbased_newton_raphson_strategy.h:781
ResidualBasedNewtonRaphsonStrategy< TSparseSpace, TDenseSpace, TLinearSolver > ClassType
Definition: residualbased_newton_raphson_strategy.h:79
void SetReformDofSetAtEachStepFlag(bool Flag)
This method sets the flag mReformDofSetAtEachStep.
Definition: residualbased_newton_raphson_strategy.h:556
BaseType::TBuilderAndSolverType TBuilderAndSolverType
Definition: residualbased_newton_raphson_strategy.h:81
void SetEchoLevel(int Level) override
It sets the level of echo for the solving strategy.
Definition: residualbased_newton_raphson_strategy.h:599
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_newton_raphson_strategy.h:91
bool GetKeepSystemConstantDuringIterations()
Get method for the flag mKeepSystemConstantDuringIterations.
Definition: residualbased_newton_raphson_strategy.h:1158
bool IsConverged() override
This should be considered as a "post solution" convergence check which is useful for coupled analysis...
Definition: residualbased_newton_raphson_strategy.h:740
ResidualBasedNewtonRaphsonStrategy(const ResidualBasedNewtonRaphsonStrategy &Other)
Definition: residualbased_newton_raphson_strategy.h:1409
void SetCalculateReactionsFlag(bool CalculateReactionsFlag)
This method sets the flag mCalculateReactionsFlag.
Definition: residualbased_newton_raphson_strategy.h:520
void Clear() override
Clears the internal storage.
Definition: residualbased_newton_raphson_strategy.h:707
virtual void EchoInfo(const unsigned int IterationNumber)
This method returns the components of the system of equations depending of the echo level.
Definition: residualbased_newton_raphson_strategy.h:1298
void WriteDofInfo(std::string FileName, const TSystemVectorType &rDX)
Definition: residualbased_newton_raphson_strategy.h:1375
TConvergenceCriteriaType::Pointer mpConvergenceCriteria
The pointer to the builder and solver employed.
Definition: residualbased_newton_raphson_strategy.h:1234
bool mInitializeWasPerformed
The maximum number of iterations, 30 by default.
Definition: residualbased_newton_raphson_strategy.h:1263
void SetScheme(typename TSchemeType::Pointer pScheme)
Set method for the time scheme.
Definition: residualbased_newton_raphson_strategy.h:466
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: residualbased_newton_raphson_strategy.h:101
void FinalizeSolutionStep() override
Performs all the required operations that should be done (for each step) after solving the solution s...
Definition: residualbased_newton_raphson_strategy.h:848
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residualbased_newton_raphson_strategy.h:95
~ResidualBasedNewtonRaphsonStrategy() override
Destructor.
Definition: residualbased_newton_raphson_strategy.h:437
bool mReformDofSetAtEachStep
The LHS matrix of the system of equations.
Definition: residualbased_newton_raphson_strategy.h:1247
void CalculateOutputData() override
This operations should be called before printing the results when non trivial results (e....
Definition: residualbased_newton_raphson_strategy.h:766
void SetBuilderAndSolver(typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver)
Set method for the builder and solver.
Definition: residualbased_newton_raphson_strategy.h:484
bool GetUseOldStiffnessInFirstIterationFlag()
This method returns the flag mFullUpdateFlag.
Definition: residualbased_newton_raphson_strategy.h:547
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: residualbased_newton_raphson_strategy.h:99
BaseType::DofsArrayType DofsArrayType
Definition: residualbased_newton_raphson_strategy.h:89
void SetInitializePerformedFlag(bool InitializePerformedFlag=true)
This method sets the flag mInitializeWasPerformed.
Definition: residualbased_newton_raphson_strategy.h:502
SolvingStrategyType::Pointer Create(ModelPart &rModelPart, Parameters ThisParameters) const override
Create method.
Definition: residualbased_newton_raphson_strategy.h:613
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
TSparseSpace::VectorPointerType TSystemVectorPointerType
Definition: solving_strategy.h:77
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
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
TSparseSpace::MatrixType TSystemMatrixType
Definition: solving_strategy.h:71
virtual int Check()
Function to perform expensive checks.
Definition: solving_strategy.h:377
TSparseSpace::MatrixPointerType TSystemMatrixPointerType
Definition: solving_strategy.h:75
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
TSparseSpace::VectorType TSystemVectorType
Definition: solving_strategy.h:73
virtual void MoveMesh()
This function is designed to move the mesh.
Definition: solving_strategy.h:330
TDenseSpace::VectorType LocalSystemVectorType
Definition: solving_strategy.h:81
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_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_INFO(label)
Definition: logger.h:250
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
#define KRATOS_WARNING(label)
Definition: logger.h:265
string FileName
Export to vtk.
Definition: GenerateWind.py:175
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
void block_for_each(TIterator itBegin, TIterator itEnd, TFunction &&rFunction)
Execute a functor on all items of a range in parallel.
Definition: parallel_utilities.h:299
bool WriteMatrixMarketVector(const char *FileName, VectorType &V)
Definition: matrix_market_interface.h:539
bool WriteMatrixMarketMatrix(const char *FileName, CompressedMatrixType &M, bool Symmetric)
Definition: matrix_market_interface.h:308
namespace KRATOS_DEPRECATED_MESSAGE("Please use std::filesystem directly") filesystem
Definition: kratos_filesystem.h:33
out
Definition: isotropic_damage_automatic_differentiation.py:200
double precision function mb(a)
Definition: TensorModule.f:849