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.
convergence_criteria.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_BASE_CONVERGENCE_CRITERIA_H )
15 #define KRATOS_BASE_CONVERGENCE_CRITERIA_H
16 
17 /* System includes */
18 
19 /* External includes */
20 
21 /* Project includes */
22 #include "includes/model_part.h"
24 
25 namespace Kratos
26 {
29 
33 
37 
41 
45 
54 template<class TSparseSpace,
55  class TDenseSpace //= DenseSpace<double>
56  >
58 {
59 public:
62 
65 
68 
70  typedef typename TSparseSpace::DataType TDataType;
79 
82 
86 
90  {
91  mActualizeRHSIsNeeded = false;
93  SetEchoLevel(1);
94  }
95 
100  explicit ConvergenceCriteria(Kratos::Parameters ThisParameters)
101  {
102  // Validate and assign defaults
103  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
104  this->AssignSettings(ThisParameters);
105 
106  mActualizeRHSIsNeeded = false;
108  }
109 
112  explicit ConvergenceCriteria( ConvergenceCriteria const& rOther)
115  ,mEchoLevel(rOther.mEchoLevel)
116  {
117  }
118 
122  {
123  }
124 
128 
132 
136 
141  virtual typename ClassType::Pointer Create(Parameters ThisParameters) const
142  {
143  return Kratos::make_shared<ClassType>(ThisParameters);
144  }
145 
151  virtual std::vector<TSystemVectorType>& GetRHS_Element_Components()
152  {
153  KRATOS_ERROR <<"Asking for Global Components to the CONVERGENCE CRITERION base class which is not component wise and not contains this member variable" << std::endl;
154  }
155 
161  virtual std::vector< Variable< LocalSystemVectorType > >& GetRHS_Element_Variables()
162  {
163  KRATOS_ERROR <<"Asking for Global Components to the CONVERGENCE CRITERION base class which is not component wise and not contains this member variable" << std::endl;
164  }
165 
171  virtual std::vector<TSystemVectorType>& GetRHS_Condition_Components()
172  {
173  KRATOS_ERROR <<"Asking for Global Components to the CONVERGENCE CRITERION base class which is not component wise and not contains this member variable" << std::endl;
174  }
175 
181  virtual std::vector< Variable< LocalSystemVectorType > >& GetRHS_Condition_Variables()
182  {
183  KRATOS_ERROR <<"Asking for Global Components to the CONVERGENCE CRITERION base class which is not component wise and not contains this member variable" << std::endl;
184  }
185 
195  virtual void SetEchoLevel(int Level)
196  {
197  mEchoLevel = Level;
198  }
199 
210  {
211  return mEchoLevel;
212  }
213 
218  void SetActualizeRHSFlag(bool ActualizeRHSIsNeeded)
219  {
220  mActualizeRHSIsNeeded = ActualizeRHSIsNeeded;
221  }
222 
228  {
229  return mActualizeRHSIsNeeded;
230  }
231 
241  virtual bool PreCriteria(
242  ModelPart& rModelPart,
243  DofsArrayType& rDofSet,
244  const TSystemMatrixType& rA,
245  const TSystemVectorType& rDx,
246  const TSystemVectorType& rb
247  )
248  {
249  return true;
250  }
251 
261  virtual bool PostCriteria(
262  ModelPart& rModelPart,
263  DofsArrayType& rDofSet,
264  const TSystemMatrixType& rA,
265  const TSystemVectorType& rDx,
266  const TSystemVectorType& rb
267  )
268  {
269  return true;
270  }
271 
276  virtual void Initialize(ModelPart& rModelPart)
277  {
279  }
280 
285  virtual bool IsInitialized()
286  {
288  }
289 
300  ModelPart& rModelPart,
301  DofsArrayType& rDofSet,
302  const TSystemMatrixType& rA,
303  const TSystemVectorType& rDx,
304  const TSystemVectorType& rb
305  )
306  {
307  }
308 
319  ModelPart& rModelPart,
320  DofsArrayType& rDofSet,
321  const TSystemMatrixType& rA,
322  const TSystemVectorType& rDx,
323  const TSystemVectorType& rb
324  )
325  {
326  }
327 
337  virtual void FinalizeSolutionStep(
338  ModelPart& rModelPart,
339  DofsArrayType& rDofSet,
340  const TSystemMatrixType& rA,
341  const TSystemVectorType& rDx,
342  const TSystemVectorType& rb
343  )
344  {
345  }
346 
357  ModelPart& rModelPart,
358  DofsArrayType& rDofSet,
359  const TSystemMatrixType& rA,
360  const TSystemVectorType& rDx,
361  const TSystemVectorType& rb
362  )
363  {
364  }
365 
372  virtual int Check(ModelPart& rModelPart)
373  {
374  KRATOS_TRY
375 
376  return 0;
377  KRATOS_CATCH("");
378  }
379 
385  {
386  const Parameters default_parameters = Parameters(R"(
387  {
388  "name" : "convergence_criteria",
389  "echo_level" : 1
390  })");
391  return default_parameters;
392  }
393 
398  static std::string Name()
399  {
400  return "convergence_criteria";
401  }
402 
406 
410 
414 
416  virtual std::string Info() const
417  {
418  return "ConvergenceCriteria";
419  }
420 
422  virtual void PrintInfo(std::ostream& rOStream) const
423  {
424  rOStream << Info();
425  }
426 
428  virtual void PrintData(std::ostream& rOStream) const
429  {
430  rOStream << Info();
431  }
432 
436 
438 
439 protected:
442 
446 
447  bool mActualizeRHSIsNeeded = false;
449 
451 
455 
459 
467  Parameters ThisParameters,
468  const Parameters DefaultParameters
469  ) const
470  {
471  ThisParameters.ValidateAndAssignDefaults(DefaultParameters);
472  return ThisParameters;
473  }
474 
479  virtual void AssignSettings(const Parameters ThisParameters)
480  {
481  mEchoLevel = ThisParameters["echo_level"].GetInt();
482  }
483 
484 
488 
492 
496 
498 
499 private:
502 
506 
510 
514 
518 
522 
526 
528 
529 }; /* Class ConvergenceCriteria */
530 } /* namespace Kratos.*/
531 
532 #endif /* KRATOS_BASE_CONVERGENCE_CRITERIA_H defined */
533 
This is the base class to define the different convergence criterion considered.
Definition: convergence_criteria.h:58
KRATOS_CLASS_POINTER_DEFINITION(ConvergenceCriteria)
Pointer definition of ConvergenceCriteria.
ConvergenceCriteria(Kratos::Parameters ThisParameters)
Constructor with Parameters.
Definition: convergence_criteria.h:100
ConvergenceCriteria< TSparseSpace, TDenseSpace > ClassType
The definition of the current class.
Definition: convergence_criteria.h:67
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: convergence_criteria.h:428
bool GetActualizeRHSflag()
This method gets the flag mActualizeRHSIsNeeded.
Definition: convergence_criteria.h:227
TDenseSpace::VectorType LocalSystemVectorType
Local system vector type definition.
Definition: convergence_criteria.h:78
virtual int Check(ModelPart &rModelPart)
This function is designed to be called once to perform all the checks needed on the input provided....
Definition: convergence_criteria.h:372
virtual ClassType::Pointer Create(Parameters ThisParameters) const
Create method.
Definition: convergence_criteria.h:141
int GetEchoLevel()
This returns the level of echo for the solving strategy.
Definition: convergence_criteria.h:209
virtual std::vector< TSystemVectorType > & GetRHS_Element_Components()
Get component wise element components.
Definition: convergence_criteria.h:151
virtual bool PostCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb)
Criterias that need to be called after getting the solution.
Definition: convergence_criteria.h:261
int mEchoLevel
This "flag" is set in order to know if it is convergence criteria is initialized.
Definition: convergence_criteria.h:450
bool mActualizeRHSIsNeeded
Definition: convergence_criteria.h:447
virtual std::vector< Variable< LocalSystemVectorType > > & GetRHS_Element_Variables()
Get component wise element variables.
Definition: convergence_criteria.h:161
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: convergence_criteria.h:398
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: convergence_criteria.h:422
virtual std::string Info() const
Turn back information as a string.
Definition: convergence_criteria.h:416
virtual Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const
This method validate and assign default parameters.
Definition: convergence_criteria.h:466
virtual bool PreCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb)
Criterias that need to be called before getting the solution.
Definition: convergence_criteria.h:241
TSparseSpace::MatrixType TSystemMatrixType
Matrix type definition.
Definition: convergence_criteria.h:72
ModelPart::DofsArrayType DofsArrayType
DoF array type definition.
Definition: convergence_criteria.h:81
virtual std::vector< TSystemVectorType > & GetRHS_Condition_Components()
Get component wise condition components.
Definition: convergence_criteria.h:171
virtual std::vector< Variable< LocalSystemVectorType > > & GetRHS_Condition_Variables()
Get component wise condition variables.
Definition: convergence_criteria.h:181
virtual void InitializeNonLinearIteration(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb)
This function initializes the non-linear iteration.
Definition: convergence_criteria.h:318
virtual Parameters GetDefaultParameters() const
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: convergence_criteria.h:384
ConvergenceCriteria(ConvergenceCriteria const &rOther)
Definition: convergence_criteria.h:112
virtual void SetEchoLevel(int Level)
It sets the level of echo for the solving strategy.
Definition: convergence_criteria.h:195
virtual void Initialize(ModelPart &rModelPart)
This function initialize the convergence criteria.
Definition: convergence_criteria.h:276
virtual void FinalizeNonLinearIteration(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb)
This function finalizes the non-linear iteration.
Definition: convergence_criteria.h:356
ConvergenceCriteria()
Definition: convergence_criteria.h:89
TSparseSpace::DataType TDataType
Data type definition.
Definition: convergence_criteria.h:70
TSparseSpace::VectorType TSystemVectorType
Vector type definition.
Definition: convergence_criteria.h:74
virtual void FinalizeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb)
This function finalizes the solution step.
Definition: convergence_criteria.h:337
bool mConvergenceCriteriaIsInitialized
This "flag" is set in order to know if it is necessary to actualize the RHS.
Definition: convergence_criteria.h:448
TDenseSpace::MatrixType LocalSystemMatrixType
Local system matrix type definition.
Definition: convergence_criteria.h:76
virtual ~ConvergenceCriteria()
Definition: convergence_criteria.h:121
virtual void InitializeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb)
This function initializes the solution step.
Definition: convergence_criteria.h:299
virtual void AssignSettings(const Parameters ThisParameters)
This method assigns settings to member variables.
Definition: convergence_criteria.h:479
virtual bool IsInitialized()
This function returns if the convergence criteria is initialized.
Definition: convergence_criteria.h:285
void SetActualizeRHSFlag(bool ActualizeRHSIsNeeded)
This method sets the flag mActualizeRHSIsNeeded.
Definition: convergence_criteria.h:218
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
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 ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
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
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
Vector VectorType
Definition: geometrical_transformation_utilities.h:56
Matrix MatrixType
Definition: geometrical_transformation_utilities.h:55
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21