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.
or_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_OR_CRITERIA_H)
15 #define KRATOS_OR_CRITERIA_H
16 
17 /* System includes */
18 
19 /* External includes */
20 
21 /* Project includes */
22 #include "includes/define.h"
23 #include "includes/model_part.h"
25 
26 namespace Kratos
27 {
30 
34 
38 
42 
46 
54 template<class TSparseSpace,
55  class TDenseSpace
56  >
58  : public ConvergenceCriteria< TSparseSpace, TDenseSpace >
59 {
60 public:
63 
66 
68 
71 
72  typedef TSparseSpace SparseSpaceType;
73 
74  typedef typename BaseType::TDataType TDataType;
75 
77 
79 
81 
83 
87 
88  //* Constructor.
89  explicit Or_Criteria()
90  : BaseType()
91  {
92  }
93 
99  explicit Or_Criteria(Kratos::Parameters ThisParameters)
100  :BaseType()
101  {
102  // Validate and assign defaults
103  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
104  this->AssignSettings(ThisParameters);
105 
106  KRATOS_ERROR << "IMPLEMENTATION PENDING IN CONSTRUCTOR WITH PARAMETERS" << std::endl;
107  }
108 
115  explicit Or_Criteria(
116  ConvergenceCriteriaPointerType pFirstCriterion,
117  ConvergenceCriteriaPointerType pSecondCriterion
118  ) :BaseType(),
119  mpFirstCriterion(pFirstCriterion),
120  mpSecondCriterion(pSecondCriterion)
121  {
122  this->mActualizeRHSIsNeeded = false;
123  if(mpFirstCriterion->GetActualizeRHSflag()) this->mActualizeRHSIsNeeded = true;
124  if(mpSecondCriterion->GetActualizeRHSflag()) this->mActualizeRHSIsNeeded = true;
125 
126  }
127 
130  explicit Or_Criteria(Or_Criteria const& rOther)
131  :BaseType(rOther),
132  mpFirstCriterion(rOther.mpFirstCriterion),
133  mpSecondCriterion(rOther.mpSecondCriterion)
134  {
135  this->mActualizeRHSIsNeeded = false;
136  if(mpFirstCriterion->GetActualizeRHSflag()) this->mActualizeRHSIsNeeded = true;
137  if(mpSecondCriterion->GetActualizeRHSflag()) this->mActualizeRHSIsNeeded = true;
138  }
139 
142  ~Or_Criteria () override {}
143 
144 
148 
152 
157  typename BaseType::Pointer Create(Parameters ThisParameters) const override
158  {
159  return Kratos::make_shared<ClassType>(ThisParameters);
160  }
161 
170  void SetEchoLevel(int Level) override
171  {
172  BaseType::SetEchoLevel(Level);
173  mpFirstCriterion->SetEchoLevel(Level);
174  mpSecondCriterion->SetEchoLevel(Level);
175  }
176 
187  ModelPart& rModelPart,
188  DofsArrayType& rDofSet,
189  const TSystemMatrixType& A,
190  const TSystemVectorType& Dx,
191  const TSystemVectorType& b
192  ) override
193  {
194  const bool first_criterion_result = mpFirstCriterion ->PreCriteria(rModelPart,rDofSet,A,Dx,b);
195  const bool second_criterion_result = mpSecondCriterion ->PreCriteria(rModelPart,rDofSet,A,Dx,b);
196 
197  return (first_criterion_result || second_criterion_result);
198  }
199 
210  ModelPart& rModelPart,
211  DofsArrayType& rDofSet,
212  const TSystemMatrixType& A,
213  const TSystemVectorType& Dx,
214  const TSystemVectorType& b
215  ) override
216  {
217  const bool first_criterion_result = mpFirstCriterion ->PostCriteria(rModelPart,rDofSet,A,Dx,b);
218  const bool second_criterion_result = mpSecondCriterion ->PostCriteria(rModelPart,rDofSet,A,Dx,b);
219 
220  return (first_criterion_result || second_criterion_result);
221  }
222 
227  void Initialize(ModelPart& rModelPart) override
228  {
229  mpFirstCriterion->Initialize(rModelPart);
230  mpSecondCriterion->Initialize(rModelPart);
231  }
232 
242  ModelPart& rModelPart,
243  DofsArrayType& rDofSet,
244  const TSystemMatrixType& A,
245  const TSystemVectorType& Dx,
246  const TSystemVectorType& b
247  ) override
248  {
249  mpFirstCriterion->InitializeSolutionStep(rModelPart,rDofSet,A,Dx,b);
250  mpSecondCriterion->InitializeSolutionStep(rModelPart,rDofSet,A,Dx,b);
251  }
252 
262  ModelPart& rModelPart,
263  DofsArrayType& rDofSet,
264  const TSystemMatrixType& A,
265  const TSystemVectorType& Dx,
266  const TSystemVectorType& b
267  ) override
268  {
269  mpFirstCriterion->InitializeNonLinearIteration(rModelPart,rDofSet,A,Dx,b);
270  mpSecondCriterion->InitializeNonLinearIteration(rModelPart,rDofSet,A,Dx,b);
271  }
272 
282  ModelPart& rModelPart,
283  DofsArrayType& rDofSet,
284  const TSystemMatrixType& A,
285  const TSystemVectorType& Dx,
286  const TSystemVectorType& b
287  ) override
288  {
289  mpFirstCriterion->FinalizeSolutionStep(rModelPart,rDofSet,A,Dx,b);
290  mpSecondCriterion->FinalizeSolutionStep(rModelPart,rDofSet,A,Dx,b);
291  }
292 
302  ModelPart& rModelPart,
303  DofsArrayType& rDofSet,
304  const TSystemMatrixType& A,
305  const TSystemVectorType& Dx,
306  const TSystemVectorType& b
307  ) override
308  {
309  mpFirstCriterion->FinalizeNonLinearIteration(rModelPart,rDofSet,A,Dx,b);
310  mpSecondCriterion->FinalizeNonLinearIteration(rModelPart,rDofSet,A,Dx,b);
311  }
312 
320  int Check(ModelPart& rModelPart) override
321  {
322  KRATOS_TRY
323 
324  const int check1 = mpFirstCriterion->Check(rModelPart);
325  const int check2 = mpSecondCriterion->Check(rModelPart);
326 
327  return check1 + check2;
328 
329  KRATOS_CATCH("");
330  }
331 
337  {
338  Parameters default_parameters = Parameters(R"(
339  {
340  "name" : "or_criteria",
341  "first_criterion_settings" : {
342  "name" : "residual_criteria",
343  "residual_absolute_tolerance" : 1.0e-4,
344  "residual_relative_tolerance" : 1.0e-9
345  },
346  "second_criterion_settings" : {
347  "name" : "displacement_criteria",
348  "displacement_relative_tolerance" : 1.0e-4,
349  "displacement_absolute_tolerance" : 1.0e-9
350  }
351  })");
352 
353  // Getting base class default parameters
354  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
355  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
356  return default_parameters;
357  }
358 
363  static std::string Name()
364  {
365  return "or_criteria";
366  }
367 
371 
375 
379 
381  std::string Info() const override
382  {
383  return "Or_Criteria";
384  }
385 
387  void PrintInfo(std::ostream& rOStream) const override
388  {
389  rOStream << Info();
390  }
391 
393  void PrintData(std::ostream& rOStream) const override
394  {
395  rOStream << Info();
396  }
397 
401 
403 
404 protected:
407 
411 
415 
419 
423 
427 
431 
433 
434 private:
437 
441 
442  ConvergenceCriteriaPointerType mpFirstCriterion;
443  ConvergenceCriteriaPointerType mpSecondCriterion;
444 
445 
449 
453 
457 
461 
465 
467 
468 }; /* Class Or_Criteria */
469 
471 
474 
475 
477 
478 } /* namespace Kratos.*/
479 
480 #endif /* KRATOS_OR_CRITERIA_H defined */
481 
This is the base class to define the different convergence criterion considered.
Definition: convergence_criteria.h:58
bool mActualizeRHSIsNeeded
Definition: convergence_criteria.h:447
virtual Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const
This method validate and assign default parameters.
Definition: convergence_criteria.h:466
TSparseSpace::MatrixType TSystemMatrixType
Matrix type definition.
Definition: convergence_criteria.h:72
virtual Parameters GetDefaultParameters() const
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: convergence_criteria.h:384
virtual void SetEchoLevel(int Level)
It sets the level of echo for the solving strategy.
Definition: convergence_criteria.h:195
TSparseSpace::DataType TDataType
Data type definition.
Definition: convergence_criteria.h:70
TSparseSpace::VectorType TSystemVectorType
Vector type definition.
Definition: convergence_criteria.h:74
virtual void AssignSettings(const Parameters ThisParameters)
This method assigns settings to member variables.
Definition: convergence_criteria.h:479
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
This convergence criteria checks simultaneously two convergence criteria (one of them must be satisfi...
Definition: or_criteria.h:59
Or_Criteria()
Definition: or_criteria.h:89
void FinalizeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &A, const TSystemVectorType &Dx, const TSystemVectorType &b) override
This function finalizes the solution step.
Definition: or_criteria.h:281
void SetEchoLevel(int Level) override
It sets the level of echo for the solving strategy.
Definition: or_criteria.h:170
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: or_criteria.h:393
TSparseSpace SparseSpaceType
Definition: or_criteria.h:72
Or_Criteria(Or_Criteria const &rOther)
Definition: or_criteria.h:130
BaseType::DofsArrayType DofsArrayType
Definition: or_criteria.h:76
bool PostCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &A, const TSystemVectorType &Dx, const TSystemVectorType &b) override
Criteria that need to be called after getting the solution.
Definition: or_criteria.h:209
void FinalizeNonLinearIteration(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &A, const TSystemVectorType &Dx, const TSystemVectorType &b) override
This function finalizes the non linear iteration.
Definition: or_criteria.h:301
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: or_criteria.h:363
BaseType::Pointer Create(Parameters ThisParameters) const override
Create method.
Definition: or_criteria.h:157
Or_Criteria(ConvergenceCriteriaPointerType pFirstCriterion, ConvergenceCriteriaPointerType pSecondCriterion)
Default constructor.
Definition: or_criteria.h:115
Or_Criteria< TSparseSpace, TDenseSpace > ClassType
The definition of the current class.
Definition: or_criteria.h:70
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: or_criteria.h:387
BaseType::TDataType TDataType
Definition: or_criteria.h:74
KRATOS_CLASS_POINTER_DEFINITION(Or_Criteria)
Or_Criteria(Kratos::Parameters ThisParameters)
Default constructor. (with parameters)
Definition: or_criteria.h:99
void InitializeNonLinearIteration(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &A, const TSystemVectorType &Dx, const TSystemVectorType &b) override
This function initializes the non linear iteration.
Definition: or_criteria.h:261
ConvergenceCriteria< TSparseSpace, TDenseSpace > BaseType
Definition: or_criteria.h:67
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: or_criteria.h:336
std::string Info() const override
Turn back information as a string.
Definition: or_criteria.h:381
int Check(ModelPart &rModelPart) override
This function is designed to be called once to perform all the checks needed on the input provided.
Definition: or_criteria.h:320
BaseType::TSystemMatrixType TSystemMatrixType
Definition: or_criteria.h:78
BaseType::TSystemVectorType TSystemVectorType
Definition: or_criteria.h:80
void Initialize(ModelPart &rModelPart) override
This function initialize the convergence criteria.
Definition: or_criteria.h:227
~Or_Criteria() override
Definition: or_criteria.h:142
void InitializeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &A, const TSystemVectorType &Dx, const TSystemVectorType &b) override
This function initializes the solution step.
Definition: or_criteria.h:241
ConvergenceCriteria< TSparseSpace, TDenseSpace >::Pointer ConvergenceCriteriaPointerType
Definition: or_criteria.h:82
bool PreCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &A, const TSystemVectorType &Dx, const TSystemVectorType &b) override
Criterias that need to be called before getting the solution.
Definition: or_criteria.h:186
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
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
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
A
Definition: sensitivityMatrix.py:70