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_linear_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 #if !defined(KRATOS_RESIDUALBASED_LINEAR_STRATEGY )
15 #define KRATOS_RESIDUALBASED_LINEAR_STRATEGY
16 
17 // System includes
18 
19 // External includes
20 
21 // Project includes
22 #include "includes/define.h"
25 
26 //default builder and solver
29 
30 namespace Kratos
31 {
34 
38 
42 
46 
50 
58 template<class TSparseSpace,
59  class TDenseSpace, //= DenseSpace<double>,
60  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
61  >
63  : public ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>
64 {
65 public:
68 
71 
73 
75 
77 
78  typedef typename BaseType::TDataType TDataType;
79 
80  typedef TSparseSpace SparseSpaceType;
81 
83 
85 
87 
89 
91 
93 
95 
97 
99 
100 
104 
109  {
110  }
111 
117  explicit ResidualBasedLinearStrategy(ModelPart& rModelPart, Parameters ThisParameters)
118  : BaseType(rModelPart)
119  {
120  // Validate and assign defaults
121  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
122  this->AssignSettings(ThisParameters);
123 
124  // Set flags to start the calculations correctly
125  mSolutionStepIsInitialized = false;
126  mInitializeWasPerformed = false;
127 
128  // Tells to the builder and solver if the reactions have to be Calculated or not
129  GetBuilderAndSolver()->SetCalculateReactionsFlag(mCalculateReactionsFlag);
130 
131  // Tells to the Builder And Solver if the system matrix and vectors need to
132  // be reshaped at each step or not
133  GetBuilderAndSolver()->SetReshapeMatrixFlag(mReformDofSetAtEachStep);
134  }
135 
147  ModelPart& rModelPart,
148  typename TSchemeType::Pointer pScheme,
149  typename TLinearSolver::Pointer pNewLinearSolver,
150  bool CalculateReactionFlag = false,
151  bool ReformDofSetAtEachStep = false,
152  bool CalculateNormDxFlag = false,
153  bool MoveMeshFlag = false
154  ) : BaseType(rModelPart, MoveMeshFlag),
155  mpScheme(pScheme),
156  mReformDofSetAtEachStep(ReformDofSetAtEachStep),
157  mCalculateNormDxFlag(CalculateNormDxFlag),
158  mCalculateReactionsFlag(CalculateReactionFlag)
159  {
160  KRATOS_TRY
161 
162  // Setting up the default builder and solver
163  mpBuilderAndSolver = typename TBuilderAndSolverType::Pointer
164  (
166  );
167 
168  // Set flag to start the calculations correctly
169  mSolutionStepIsInitialized = false;
170  mInitializeWasPerformed = false;
171 
172  // Tells to the builder and solver if the reactions have to be Calculated or not
173  GetBuilderAndSolver()->SetCalculateReactionsFlag(mCalculateReactionsFlag);
174 
175  // Tells to the Builder And Solver if the system matrix and vectors need to
176  //be reshaped at each step or not
177  GetBuilderAndSolver()->SetReshapeMatrixFlag(mReformDofSetAtEachStep);
178 
179  // Set EchoLevel to the default value (only time is displayed)
180  this->SetEchoLevel(1);
181 
182  // By default the matrices are rebuilt at each solution step
184 
185  KRATOS_CATCH("")
186  }
187 
200  ModelPart& rModelPart,
201  typename TSchemeType::Pointer pScheme,
202  typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver,
203  bool CalculateReactionFlag = false,
204  bool ReformDofSetAtEachStep = false,
205  bool CalculateNormDxFlag = false,
206  bool MoveMeshFlag = false
207  ) : BaseType(rModelPart, MoveMeshFlag),
208  mpScheme(pScheme),
209  mpBuilderAndSolver(pNewBuilderAndSolver),
210  mReformDofSetAtEachStep(ReformDofSetAtEachStep),
211  mCalculateNormDxFlag(CalculateNormDxFlag),
212  mCalculateReactionsFlag(CalculateReactionFlag)
213  {
214  KRATOS_TRY
215 
216  // Set flag to start the calculations correctly
217  mSolutionStepIsInitialized = false;
218  mInitializeWasPerformed = false;
219 
220  // Tells to the builder and solver if the reactions have to be Calculated or not
221  GetBuilderAndSolver()->SetCalculateReactionsFlag(mCalculateReactionsFlag);
222 
223  // Tells to the Builder And Solver if the system matrix and vectors need to
224  //be reshaped at each step or not
225  GetBuilderAndSolver()->SetReshapeMatrixFlag(mReformDofSetAtEachStep);
226 
227  //set EchoLevel to the default value (only time is displayed)
228  this->SetEchoLevel(1);
229 
230  // By default the matrices are rebuilt at each solution step
232 
233  KRATOS_CATCH("")
234  }
235 
241  {
242  // If the linear solver has not been deallocated, clean it before
243  // deallocating mpA. This prevents a memory error with the the ML
244  // solver (which holds a reference to it).
245  // NOTE: The linear solver is hold by the B&S
246  auto p_builder_and_solver = this->GetBuilderAndSolver();
247  if (p_builder_and_solver != nullptr) {
248  p_builder_and_solver->Clear();
249  }
250 
251  // Deallocating system vectors to avoid errors in MPI. Clear calls
252  // TrilinosSpace::Clear for the vectors, which preserves the Map of
253  // current vectors, performing MPI calls in the process. Due to the
254  // way Python garbage collection works, this may happen after
255  // MPI_Finalize has already been called and is an error. Resetting
256  // the pointers here prevents Clear from operating with the
257  // (now deallocated) vectors.
258  mpA.reset();
259  mpDx.reset();
260  mpb.reset();
261 
262  this->Clear();
263  }
264 
269  void SetScheme(typename TSchemeType::Pointer pScheme)
270  {
271  mpScheme = pScheme;
272  };
273 
278  typename TSchemeType::Pointer GetScheme()
279  {
280  return mpScheme;
281  };
282 
287  void SetBuilderAndSolver(typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver)
288  {
289  mpBuilderAndSolver = pNewBuilderAndSolver;
290  };
291 
296  typename TBuilderAndSolverType::Pointer GetBuilderAndSolver()
297  {
298  return mpBuilderAndSolver;
299  };
300 
305  void SetCalculateReactionsFlag(bool CalculateReactionsFlag)
306  {
307  mCalculateReactionsFlag = CalculateReactionsFlag;
308  GetBuilderAndSolver()->SetCalculateReactionsFlag(mCalculateReactionsFlag);
309  }
310 
316  {
317  return mCalculateReactionsFlag;
318  }
319 
325  {
326  mReformDofSetAtEachStep = Flag;
327  GetBuilderAndSolver()->SetReshapeMatrixFlag(mReformDofSetAtEachStep);
328  }
329 
335  {
336  return mReformDofSetAtEachStep;
337  }
338 
349  void SetEchoLevel(int Level) override
350  {
351  BaseType::SetEchoLevel(Level);
352  GetBuilderAndSolver()->SetEchoLevel(Level);
353  }
354 
355  //*********************************************************************************
363  typename SolvingStrategyType::Pointer Create(
364  ModelPart& rModelPart,
365  Parameters ThisParameters
366  ) const override
367  {
368  return Kratos::make_shared<ClassType>(rModelPart, ThisParameters);
369  }
370 
375  void Predict() override
376  {
377  KRATOS_TRY
379  //OPERATIONS THAT SHOULD BE DONE ONCE - internal check to avoid repetitions
380  //if the operations needed were already performed this does nothing
381  if(mInitializeWasPerformed == false)
382  Initialize();
383 
384  //initialize solution step
385  if (mSolutionStepIsInitialized == false)
387 
388  TSystemMatrixType& rA = *mpA;
389  TSystemVectorType& rDx = *mpDx;
390  TSystemVectorType& rb = *mpb;
391 
392  DofsArrayType& r_dof_set = GetBuilderAndSolver()->GetDofSet();
393 
394  this->GetScheme()->Predict(BaseType::GetModelPart(), r_dof_set, rA, rDx, rb);
395 
396  // Applying constraints if needed
397  auto& r_constraints_array = BaseType::GetModelPart().MasterSlaveConstraints();
398  const int local_number_of_constraints = r_constraints_array.size();
399  const int global_number_of_constraints = r_comm.SumAll(local_number_of_constraints);
400  if(global_number_of_constraints != 0) {
401  const auto& r_process_info = BaseType::GetModelPart().GetProcessInfo();
402 
403  block_for_each(r_constraints_array, [&r_process_info](MasterSlaveConstraint& rConstraint){
404  rConstraint.ResetSlaveDofs(r_process_info);
405  });
406  block_for_each(r_constraints_array, [&r_process_info](MasterSlaveConstraint& rConstraint){
407  rConstraint.Apply(r_process_info);
408  });
409 
410  //the following is needed since we need to eventually compute time derivatives after applying
411  //Master slave relations
412  TSparseSpace::SetToZero(rDx);
413  this->GetScheme()->Update(BaseType::GetModelPart(), r_dof_set, rA, rDx, rb);
414  }
415 
417 
418  KRATOS_CATCH("")
419  }
420 
424  void Initialize() override
425  {
426  KRATOS_TRY
427 
428  if (mInitializeWasPerformed == false)
429  {
430  //pointers needed in the solution
431  typename TSchemeType::Pointer p_scheme = GetScheme();
432 
433  //Initialize The Scheme - OPERATIONS TO BE DONE ONCE
434  if (p_scheme->SchemeIsInitialized() == false)
435  p_scheme->Initialize(BaseType::GetModelPart());
436 
437  //Initialize The Elements - OPERATIONS TO BE DONE ONCE
438  if (p_scheme->ElementsAreInitialized() == false)
439  p_scheme->InitializeElements(BaseType::GetModelPart());
440 
441  //Initialize The Conditions - OPERATIONS TO BE DONE ONCE
442  if (p_scheme->ConditionsAreInitialized() == false)
443  p_scheme->InitializeConditions(BaseType::GetModelPart());
444 
445  mInitializeWasPerformed = true;
446  }
447 
448  KRATOS_CATCH("")
449  }
450 
457  double Solve() override
458  {
459  BaseType::Solve();
460 
461  //calculate if needed the norm of Dx
462  double norm_dx = 0.00;
463  if (mCalculateNormDxFlag == true)
464  norm_dx = TSparseSpace::TwoNorm(*mpDx);
465 
466  return norm_dx;
467  }
468 
473  void Clear() override
474  {
475  KRATOS_TRY;
476 
477  // Setting to zero the internal flag to ensure that the dof sets are recalculated. Also clear the linear solver stored in the B&S
478  auto p_builder_and_solver = GetBuilderAndSolver();
479  if (p_builder_and_solver != nullptr) {
480  p_builder_and_solver->SetDofSetIsInitializedFlag(false);
481  p_builder_and_solver->Clear();
482  }
483 
484  // Clearing the system of equations
485  if (mpA != nullptr)
487  if (mpDx != nullptr)
489  if (mpb != nullptr)
491 
492  // Clearing scheme
493  auto p_scheme = GetScheme();
494  if (p_scheme != nullptr) {
495  GetScheme()->Clear();
496  }
497 
498  mInitializeWasPerformed = false;
499  mSolutionStepIsInitialized = false;
500 
501  KRATOS_CATCH("");
502  }
503 
509  void CalculateOutputData() override
510  {
511  TSystemMatrixType& rA = *mpA;
512  TSystemVectorType& rDx = *mpDx;
513  TSystemVectorType& rb = *mpb;
514 
515  GetScheme()->CalculateOutputData(BaseType::GetModelPart(),
516  GetBuilderAndSolver()->GetDofSet(),
517  rA, rDx, rb);
518  }
519 
525  void InitializeSolutionStep() override
526  {
527  KRATOS_TRY
528 
529  if (mSolutionStepIsInitialized == false)
530  {
531  //pointers needed in the solution
532  typename TSchemeType::Pointer p_scheme = GetScheme();
533  typename TBuilderAndSolverType::Pointer p_builder_and_solver = GetBuilderAndSolver();
534 
535  //set up the system, operation performed just once unless it is required
536  //to reform the dof set at each iteration
537  BuiltinTimer system_construction_time;
538  if (p_builder_and_solver->GetDofSetIsInitializedFlag() == false ||
539  mReformDofSetAtEachStep == true)
540  {
541  //setting up the list of the DOFs to be solved
542  BuiltinTimer setup_dofs_time;
543  p_builder_and_solver->SetUpDofSet(p_scheme, BaseType::GetModelPart());
544  KRATOS_INFO_IF("ResidualBasedLinearStrategy", BaseType::GetEchoLevel() > 0) << "Setup Dofs Time: " << setup_dofs_time << std::endl;
545 
546  //shaping correctly the system
547  BuiltinTimer setup_system_time;
548  p_builder_and_solver->SetUpSystem(BaseType::GetModelPart());
549  KRATOS_INFO_IF("ResidualBasedLinearStrategy", BaseType::GetEchoLevel() > 0) << "Setup System Time: " << setup_system_time << std::endl;
550 
551  //setting up the Vectors involved to the correct size
552  BuiltinTimer system_matrix_resize_time;
553  p_builder_and_solver->ResizeAndInitializeVectors(p_scheme, mpA, mpDx, mpb,
555  KRATOS_INFO_IF("ResidualBasedLinearStrategy", BaseType::GetEchoLevel() > 0) << "System Matrix Resize Time: " << system_matrix_resize_time << std::endl;
556  }
557 
558  KRATOS_INFO_IF("ResidualBasedLinearStrategy", BaseType::GetEchoLevel() > 0) << "System Construction Time: " << system_construction_time << std::endl;
559 
560  TSystemMatrixType& rA = *mpA;
561  TSystemVectorType& rDx = *mpDx;
562  TSystemVectorType& rb = *mpb;
563 
564  //initial operations ... things that are constant over the Solution Step
565  p_builder_and_solver->InitializeSolutionStep(BaseType::GetModelPart(), rA, rDx, rb);
566 
567  //initial operations ... things that are constant over the Solution Step
568  p_scheme->InitializeSolutionStep(BaseType::GetModelPart(), rA, rDx, rb);
569 
570  mSolutionStepIsInitialized = true;
571  }
572 
573  KRATOS_CATCH("")
574  }
575 
580  void FinalizeSolutionStep() override
581  {
582  KRATOS_TRY;
583  typename TSchemeType::Pointer p_scheme = GetScheme();
584  typename TBuilderAndSolverType::Pointer p_builder_and_solver = GetBuilderAndSolver();
585 
586  TSystemMatrixType &rA = *mpA;
587  TSystemVectorType &rDx = *mpDx;
588  TSystemVectorType &rb = *mpb;
589 
590  //Finalisation of the solution step,
591  //operations to be done after achieving convergence, for example the
592  //Final Residual Vector (mb) has to be saved in there
593  //to avoid error accumulation
594 
595  p_scheme->FinalizeSolutionStep(BaseType::GetModelPart(), rA, rDx, rb);
596  p_builder_and_solver->FinalizeSolutionStep(BaseType::GetModelPart(), rA, rDx, rb);
597 
598  //Cleaning memory after the solution
599  p_scheme->Clean();
600 
601  //reset flags for next step
602  mSolutionStepIsInitialized = false;
603 
604  //deallocate the systemvectors if needed
605  if (mReformDofSetAtEachStep == true)
606  {
610 
611  this->Clear();
612  }
613 
614  KRATOS_CATCH("");
615  }
616 
620  bool SolveSolutionStep() override
621  {
622  //pointers needed in the solution
623  typename TSchemeType::Pointer p_scheme = GetScheme();
624  typename TBuilderAndSolverType::Pointer p_builder_and_solver = GetBuilderAndSolver();
625 
626  TSystemMatrixType& rA = *mpA;
627  TSystemVectorType& rDx = *mpDx;
628  TSystemVectorType& rb = *mpb;
629 
630  p_scheme->InitializeNonLinIteration(BaseType::GetModelPart(), rA, rDx, rb);
631 
633  {
634  TSparseSpace::SetToZero(rA);
635  TSparseSpace::SetToZero(rDx);
636  TSparseSpace::SetToZero(rb);
637  // passing smart pointers instead of references here
638  // to prevent dangling pointer to system matrix when
639  // reusing ml preconditioners in the trilinos tpl
640  p_builder_and_solver->BuildAndSolve(p_scheme, BaseType::GetModelPart(), rA, rDx, rb);
642  }
643  else
644  {
645  TSparseSpace::SetToZero(rDx);
646  TSparseSpace::SetToZero(rb);
647  p_builder_and_solver->BuildRHSAndSolve(p_scheme, BaseType::GetModelPart(), rA, rDx, rb);
648  }
649 
650  // Debugging info
651  EchoInfo();
652 
653  //update results
654  DofsArrayType& r_dof_set = p_builder_and_solver->GetDofSet();
655  p_scheme->Update(BaseType::GetModelPart(), r_dof_set, rA, rDx, rb);
656 
657  //move the mesh if needed
659 
660  p_scheme->FinalizeNonLinIteration(BaseType::GetModelPart(), rA, rDx, rb);
661 
662  // Calculate reactions if required
663  if (mCalculateReactionsFlag == true)
664  p_builder_and_solver->CalculateReactions(p_scheme,
666  rA, rDx, rb);
667 
668  return true;
669  }
670 
676  {
677  TSystemMatrixType& mA = *mpA;
678 
679  return mA;
680  }
681 
687  {
688  TSystemVectorType& mb = *mpb;
689 
690  return mb;
691  }
692 
698  {
699  TSystemVectorType& mDx = *mpDx;
700 
701  return mDx;
702  }
703 
708  double GetResidualNorm() override
709  {
710  if (TSparseSpace::Size(*mpb) != 0)
711  return TSparseSpace::TwoNorm(*mpb);
712  else
713  return 0.0;
714  }
715 
720  int Check() override
721  {
722  KRATOS_TRY
723 
724  BaseType::Check();
725 
727 
728  GetScheme()->Check(BaseType::GetModelPart());
729 
730  return 0;
731 
732  KRATOS_CATCH("")
733  }
734 
740  {
741  Parameters default_parameters = Parameters(R"(
742  {
743  "name" : "linear_strategy",
744  "compute_norm_dx" : false,
745  "reform_dofs_at_each_step" : false,
746  "compute_reactions" : false,
747  "builder_and_solver_settings" : {},
748  "linear_solver_settings" : {},
749  "scheme_settings" : {}
750  })");
751 
752  // Getting base class default parameters
753  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
754  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
755  return default_parameters;
756  }
757 
762  static std::string Name()
763  {
764  return "linear_strategy";
765  }
766 
770 
774 
775 
779 
780 
784 
788 
790  std::string Info() const override
791  {
792  return "ResidualBasedLinearStrategy";
793  }
794 
796  void PrintInfo(std::ostream& rOStream) const override
797  {
798  rOStream << Info();
799  }
800 
802  void PrintData(std::ostream& rOStream) const override
803  {
804  rOStream << Info();
805  }
806 
810 
811 
813 
814 protected:
817 
821 
825 
829 
834  void AssignSettings(const Parameters ThisParameters) override
835  {
836  BaseType::AssignSettings(ThisParameters);
837  mCalculateNormDxFlag = ThisParameters["compute_norm_dx"].GetBool();
838  mReformDofSetAtEachStep = ThisParameters["reform_dofs_at_each_step"].GetBool();
839  mCalculateReactionsFlag = ThisParameters["compute_reactions"].GetBool();
840 
841  // Saving the scheme
842  if (ThisParameters["scheme_settings"].Has("name")) {
843  KRATOS_ERROR << "IMPLEMENTATION PENDING IN CONSTRUCTOR WITH PARAMETERS" << std::endl;
844  }
845 
846  // Setting up the default builder and solver
847  if (ThisParameters["builder_and_solver_settings"].Has("name")) {
848  KRATOS_ERROR << "IMPLEMENTATION PENDING IN CONSTRUCTOR WITH PARAMETERS" << std::endl;
849  }
850  }
851 
855 
859 
863 
865 
866 private:
869 
870 
874 
875  typename TSchemeType::Pointer mpScheme = nullptr;
876  typename TBuilderAndSolverType::Pointer mpBuilderAndSolver = nullptr;
877 
881 
889  bool mReformDofSetAtEachStep;
890 
891  bool mCalculateNormDxFlag;
892 
897  bool mCalculateReactionsFlag;
898 
899  bool mSolutionStepIsInitialized;
900 
901  bool mInitializeWasPerformed;
902 
906 
910  virtual void EchoInfo()
911  {
912  TSystemMatrixType& rA = *mpA;
913  TSystemVectorType& rDx = *mpDx;
914  TSystemVectorType& rb = *mpb;
915 
916  if (BaseType::GetEchoLevel() == 3) //if it is needed to print the debug info
917  {
918  KRATOS_INFO("LHS") << "SystemMatrix = " << rA << std::endl;
919  KRATOS_INFO("Dx") << "Solution obtained = " << rDx << std::endl;
920  KRATOS_INFO("RHS") << "RHS = " << rb << std::endl;
921  }
922  if (this->GetEchoLevel() == 4) //print to matrix market file
923  {
924  std::stringstream matrix_market_name;
925  matrix_market_name << "A_" << BaseType::GetModelPart().GetProcessInfo()[TIME] << ".mm";
926  TSparseSpace::WriteMatrixMarketMatrix((char*) (matrix_market_name.str()).c_str(), rA, false);
927 
928  std::stringstream matrix_market_vectname;
929  matrix_market_vectname << "b_" << BaseType::GetModelPart().GetProcessInfo()[TIME] << ".mm.rhs";
930  TSparseSpace::WriteMatrixMarketVector((char*) (matrix_market_vectname.str()).c_str(), rb);
931  }
932  }
933 
937 
938 
942 
943 
947 
948 
952 
956 
958 
959 }; /* Class ResidualBasedLinearStrategy */
960 
962 
965 
966 
968 
969 } /* namespace Kratos.*/
970 
971 #endif /* KRATOS_RESIDUALBASED_LINEAR_STRATEGY defined */
972 
Definition: builtin_timer.h:26
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
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
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > TBuilderAndSolverType
Definition: implicit_solving_strategy.h:84
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
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
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 a very simple strategy to solve linearly the problem.
Definition: residualbased_linear_strategy.h:64
ResidualBasedLinearStrategy< TSparseSpace, TDenseSpace, TLinearSolver > ClassType
Definition: residualbased_linear_strategy.h:76
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: residualbased_linear_strategy.h:74
double Solve() override
The problem of interest is solved.
Definition: residualbased_linear_strategy.h:457
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_linear_strategy.h:88
void Initialize() override
Initialization of member variables and prior operations.
Definition: residualbased_linear_strategy.h:424
void FinalizeSolutionStep() override
Performs all the required operations that should be done (for each step) after solving the solution s...
Definition: residualbased_linear_strategy.h:580
TSchemeType::Pointer GetScheme()
Get method for the time scheme.
Definition: residualbased_linear_strategy.h:278
ResidualBasedLinearStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TLinearSolver::Pointer pNewLinearSolver, bool CalculateReactionFlag=false, bool ReformDofSetAtEachStep=false, bool CalculateNormDxFlag=false, bool MoveMeshFlag=false)
Default constructor.
Definition: residualbased_linear_strategy.h:146
double GetResidualNorm() override
This method returns the residual norm.
Definition: residualbased_linear_strategy.h:708
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: residualbased_linear_strategy.h:762
TSystemVectorType & GetSystemVector() override
This method returns the RHS vector.
Definition: residualbased_linear_strategy.h:686
void Clear() override
Clears the internal storage.
Definition: residualbased_linear_strategy.h:473
bool GetReformDofSetAtEachStepFlag()
This method returns the flag mReformDofSetAtEachStep.
Definition: residualbased_linear_strategy.h:334
ResidualBasedLinearStrategy(ModelPart &rModelPart, Parameters ThisParameters)
Default constructor. (with parameters)
Definition: residualbased_linear_strategy.h:117
void CalculateOutputData() override
This operations should be called before printing the results when non trivial results (e....
Definition: residualbased_linear_strategy.h:509
void InitializeSolutionStep() override
Performs all the required operations that should be done (for each step) before solving the solution ...
Definition: residualbased_linear_strategy.h:525
bool GetCalculateReactionsFlag()
This method returns the flag mCalculateReactionsFlag.
Definition: residualbased_linear_strategy.h:315
std::string Info() const override
Turn back information as a string.
Definition: residualbased_linear_strategy.h:790
SolvingStrategyType::Pointer Create(ModelPart &rModelPart, Parameters ThisParameters) const override
Create method.
Definition: residualbased_linear_strategy.h:363
~ResidualBasedLinearStrategy() override
Destructor.
Definition: residualbased_linear_strategy.h:240
TSparseSpace SparseSpaceType
Definition: residualbased_linear_strategy.h:80
TSystemMatrixType & GetSystemMatrix() override
This method returns the LHS matrix.
Definition: residualbased_linear_strategy.h:675
SolvingStrategy< TSparseSpace, TDenseSpace > SolvingStrategyType
Definition: residualbased_linear_strategy.h:72
int Check() override
Function to perform expensive checks.
Definition: residualbased_linear_strategy.h:720
bool SolveSolutionStep() override
Solves the current step. This function returns true if a solution has been found, false otherwise.
Definition: residualbased_linear_strategy.h:620
void SetScheme(typename TSchemeType::Pointer pScheme)
Set method for the time scheme.
Definition: residualbased_linear_strategy.h:269
TBuilderAndSolverType::Pointer GetBuilderAndSolver()
Get method for the builder and solver.
Definition: residualbased_linear_strategy.h:296
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: residualbased_linear_strategy.h:739
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: residualbased_linear_strategy.h:834
BaseType::TSchemeType TSchemeType
Definition: residualbased_linear_strategy.h:82
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: residualbased_linear_strategy.h:802
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: residualbased_linear_strategy.h:796
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: residualbased_linear_strategy.h:96
ResidualBasedLinearStrategy()
Default constructor.
Definition: residualbased_linear_strategy.h:108
ResidualBasedLinearStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver, bool CalculateReactionFlag=false, bool ReformDofSetAtEachStep=false, bool CalculateNormDxFlag=false, bool MoveMeshFlag=false)
Constructor specifying the builder and solver.
Definition: residualbased_linear_strategy.h:199
TSystemVectorType & GetSolutionVector() override
This method returns the solution vector.
Definition: residualbased_linear_strategy.h:697
void SetBuilderAndSolver(typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver)
Set method for the builder and solver.
Definition: residualbased_linear_strategy.h:287
void Predict() override
Operation to predict the solution ... if it is not called a trivial predictor is used in which the va...
Definition: residualbased_linear_strategy.h:375
BaseType::TDataType TDataType
Definition: residualbased_linear_strategy.h:78
void SetCalculateReactionsFlag(bool CalculateReactionsFlag)
This method sets the flag mCalculateReactionsFlag.
Definition: residualbased_linear_strategy.h:305
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residualbased_linear_strategy.h:92
BaseType::TSystemVectorType TSystemVectorType
Definition: residualbased_linear_strategy.h:90
void SetEchoLevel(int Level) override
It sets the level of echo for the solving strategy.
Definition: residualbased_linear_strategy.h:349
void SetReformDofSetAtEachStepFlag(bool Flag)
This method sets the flag mReformDofSetAtEachStep.
Definition: residualbased_linear_strategy.h:324
BaseType::TBuilderAndSolverType TBuilderAndSolverType
Definition: residualbased_linear_strategy.h:84
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: residualbased_linear_strategy.h:98
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residualbased_linear_strategy.h:94
BaseType::DofsArrayType DofsArrayType
Definition: residualbased_linear_strategy.h:86
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedLinearStrategy)
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
virtual void SetEchoLevel(const int Level)
This sets the level of echo for the solving strategy.
Definition: solving_strategy.h:255
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
virtual double Solve()
The problem of interest is solved.
Definition: solving_strategy.h:183
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
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_INFO(label)
Definition: logger.h:250
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
bool Has(const std::string &ModelerName)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:24
double TwoNorm(SparseSpaceType &dummy, SparseSpaceType::VectorType &x)
Definition: add_strategies_to_python.cpp:164
TSpaceType::IndexType Size(TSpaceType &dummy, typename TSpaceType::VectorType const &rV)
Definition: add_strategies_to_python.cpp:111
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
double precision function mb(a)
Definition: TensorModule.f:849