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.
and_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_AND_CRITERIA_H)
15 #define KRATOS_AND_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 {
28 
31 
35 
39 
43 
47 
55 template<class TSparseSpace,
56  class TDenseSpace
57  >
59  : public ConvergenceCriteria< TSparseSpace, TDenseSpace >
60 {
61 public:
64 
67 
69 
72 
73  typedef TSparseSpace SparseSpaceType;
74 
75  typedef typename BaseType::TDataType TDataType;
76 
78 
80 
82 
84 
88 
89  //* Constructor.
90  explicit And_Criteria()
91  : BaseType()
92  {
93  }
94 
100  explicit And_Criteria(Kratos::Parameters ThisParameters)
101  :BaseType()
102  {
103  // Validate and assign defaults
104  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
105  this->AssignSettings(ThisParameters);
106 
107  KRATOS_ERROR << "IMPLEMENTATION PENDING IN CONSTRUCTOR WITH PARAMETERS" << std::endl;
108  }
109 
116  explicit And_Criteria(
117  ConvergenceCriteriaPointerType pFirstCriterion,
118  ConvergenceCriteriaPointerType pSecondCriterion
119  ) :BaseType(),
120  mpFirstCriterion(pFirstCriterion),
121  mpSecondCriterion(pSecondCriterion)
122  {
123  this->mActualizeRHSIsNeeded = false;
124  if(mpFirstCriterion->GetActualizeRHSflag()) this->mActualizeRHSIsNeeded = true;
125  if(mpSecondCriterion->GetActualizeRHSflag()) this->mActualizeRHSIsNeeded = true;
126  }
127 
132  explicit And_Criteria(And_Criteria const& rOther)
133  :BaseType(rOther),
134  mpFirstCriterion(rOther.mpFirstCriterion),
135  mpSecondCriterion(rOther.mpSecondCriterion)
136  {
137  this->mActualizeRHSIsNeeded = false;
138  if(mpFirstCriterion->GetActualizeRHSflag()) this->mActualizeRHSIsNeeded = true;
139  if(mpSecondCriterion->GetActualizeRHSflag()) this->mActualizeRHSIsNeeded = true;
140  }
141 
144  ~And_Criteria () override {}
145 
149 
153 
158  typename BaseType::Pointer Create(Parameters ThisParameters) const override
159  {
160  return Kratos::make_shared<ClassType>(ThisParameters);
161  }
162 
171  void SetEchoLevel(int Level) override
172  {
173  BaseType::SetEchoLevel(Level);
174  mpFirstCriterion->SetEchoLevel(Level);
175  mpSecondCriterion->SetEchoLevel(Level);
176  }
177 
188  ModelPart& rModelPart,
189  DofsArrayType& rDofSet,
190  const TSystemMatrixType& A,
191  const TSystemVectorType& Dx,
192  const TSystemVectorType& b
193  ) override
194  {
195  const bool first_criterion_result = mpFirstCriterion ->PreCriteria(rModelPart,rDofSet,A,Dx,b);
196  const bool second_criterion_result = mpSecondCriterion ->PreCriteria(rModelPart,rDofSet,A,Dx,b);
197 
198  return (first_criterion_result && second_criterion_result);
199  }
200 
211  ModelPart& rModelPart,
212  DofsArrayType& rDofSet,
213  const TSystemMatrixType& A,
214  const TSystemVectorType& Dx,
215  const TSystemVectorType& b
216  ) override
217  {
218  const bool first_criterion_result = mpFirstCriterion ->PostCriteria(rModelPart,rDofSet,A,Dx,b);
219  const bool second_criterion_result = mpSecondCriterion ->PostCriteria(rModelPart,rDofSet,A,Dx,b);
220 
221  return (first_criterion_result && second_criterion_result);
222  }
223 
228  void Initialize(ModelPart& rModelPart) override
229  {
230  mpFirstCriterion->Initialize(rModelPart);
231  mpSecondCriterion->Initialize(rModelPart);
232  }
233 
243  ModelPart& rModelPart,
244  DofsArrayType& rDofSet,
245  const TSystemMatrixType& A,
246  const TSystemVectorType& Dx,
247  const TSystemVectorType& b
248  ) override
249  {
250  mpFirstCriterion->InitializeSolutionStep(rModelPart,rDofSet,A,Dx,b);
251  mpSecondCriterion->InitializeSolutionStep(rModelPart,rDofSet,A,Dx,b);
252  }
253 
263  ModelPart& rModelPart,
264  DofsArrayType& rDofSet,
265  const TSystemMatrixType& A,
266  const TSystemVectorType& Dx,
267  const TSystemVectorType& b
268  ) override
269  {
270  mpFirstCriterion->InitializeNonLinearIteration(rModelPart,rDofSet,A,Dx,b);
271  mpSecondCriterion->InitializeNonLinearIteration(rModelPart,rDofSet,A,Dx,b);
272  }
273 
283  ModelPart& rModelPart,
284  DofsArrayType& rDofSet,
285  const TSystemMatrixType& A,
286  const TSystemVectorType& Dx,
287  const TSystemVectorType& b
288  ) override
289  {
290  mpFirstCriterion->FinalizeSolutionStep(rModelPart,rDofSet,A,Dx,b);
291  mpSecondCriterion->FinalizeSolutionStep(rModelPart,rDofSet,A,Dx,b);
292  }
293 
303  ModelPart& rModelPart,
304  DofsArrayType& rDofSet,
305  const TSystemMatrixType& A,
306  const TSystemVectorType& Dx,
307  const TSystemVectorType& b
308  ) override
309  {
310  mpFirstCriterion->FinalizeNonLinearIteration(rModelPart,rDofSet,A,Dx,b);
311  mpSecondCriterion->FinalizeNonLinearIteration(rModelPart,rDofSet,A,Dx,b);
312  }
313 
321  int Check(ModelPart& rModelPart) override
322  {
323  KRATOS_TRY
324 
325  const int check1 = mpFirstCriterion->Check(rModelPart);
326  const int check2 = mpSecondCriterion->Check(rModelPart);
327 
328  return check1 + check2;
329 
330  KRATOS_CATCH("");
331  }
332 
338  {
339  Parameters default_parameters = Parameters(R"(
340  {
341  "name" : "and_criteria",
342  "first_criterion_settings" : {
343  "name" : "residual_criteria",
344  "residual_absolute_tolerance" : 1.0e-4,
345  "residual_relative_tolerance" : 1.0e-9
346  },
347  "second_criterion_settings" : {
348  "name" : "displacement_criteria",
349  "displacement_relative_tolerance" : 1.0e-4,
350  "displacement_absolute_tolerance" : 1.0e-9
351  }
352  })");
353 
354  // Getting base class default parameters
355  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
356  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
357  return default_parameters;
358  }
359 
364  static std::string Name()
365  {
366  return "and_criteria";
367  }
368 
372 
376 
380 
382  std::string Info() const override
383  {
384  return "And_Criteria";
385  }
386 
388  void PrintInfo(std::ostream& rOStream) const override
389  {
390  rOStream << Info();
391  }
392 
394  void PrintData(std::ostream& rOStream) const override
395  {
396  rOStream << Info();
397  }
398 
402 
404 
405 protected:
408 
412 
416 
420 
424 
428 
432 
434 
435 private:
438 
439 
443 
444  ConvergenceCriteriaPointerType mpFirstCriterion;
445  ConvergenceCriteriaPointerType mpSecondCriterion;
446 
450 
454 
458 
462 
466 
468 
469 }; /* Class And_Criteria */
470 
472 
475 
477 
478 } /* namespace Kratos.*/
479 
480 #endif /* KRATOS_AND_CRITERIA_H defined */
481 
This convergence criteria checks simultaneously two convergence criteria (both must be satisfied)
Definition: and_criteria.h:60
BaseType::TDataType TDataType
Definition: and_criteria.h:75
TSparseSpace SparseSpaceType
Definition: and_criteria.h:73
And_Criteria< TSparseSpace, TDenseSpace > ClassType
The definition of the current class.
Definition: and_criteria.h:71
void SetEchoLevel(int Level) override
It sets the level of echo for the solving strategy.
Definition: and_criteria.h:171
BaseType::TSystemMatrixType TSystemMatrixType
Definition: and_criteria.h:79
~And_Criteria() override
Definition: and_criteria.h:144
BaseType::DofsArrayType DofsArrayType
Definition: and_criteria.h:77
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: and_criteria.h:394
void Initialize(ModelPart &rModelPart) override
This function initialize the convergence criteria.
Definition: and_criteria.h:228
And_Criteria(Kratos::Parameters ThisParameters)
Default constructor. (with parameters)
Definition: and_criteria.h:100
void InitializeNonLinearIteration(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &A, const TSystemVectorType &Dx, const TSystemVectorType &b) override
This function initializes the non linear iteration.
Definition: and_criteria.h:262
KRATOS_CLASS_POINTER_DEFINITION(And_Criteria)
int Check(ModelPart &rModelPart) override
This function is designed to be called once to perform all the checks needed on the input provided.
Definition: and_criteria.h:321
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: and_criteria.h:364
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: and_criteria.h:337
And_Criteria()
Definition: and_criteria.h:90
And_Criteria(And_Criteria const &rOther)
Copy constructor.
Definition: and_criteria.h:132
std::string Info() const override
Turn back information as a string.
Definition: and_criteria.h:382
void FinalizeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &A, const TSystemVectorType &Dx, const TSystemVectorType &b) override
This function finalizes the solution step.
Definition: and_criteria.h:282
BaseType::Pointer Create(Parameters ThisParameters) const override
Create method.
Definition: and_criteria.h:158
ConvergenceCriteria< TSparseSpace, TDenseSpace > BaseType
Definition: and_criteria.h:68
BaseType::TSystemVectorType TSystemVectorType
Definition: and_criteria.h:81
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: and_criteria.h:388
ConvergenceCriteria< TSparseSpace, TDenseSpace >::Pointer ConvergenceCriteriaPointerType
Definition: and_criteria.h:83
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: and_criteria.h:210
void InitializeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &A, const TSystemVectorType &Dx, const TSystemVectorType &b) override
This function initializes the solution step.
Definition: and_criteria.h:242
void FinalizeNonLinearIteration(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &A, const TSystemVectorType &Dx, const TSystemVectorType &b) override
This function finalizes the non linear iteration.
Definition: and_criteria.h:302
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: and_criteria.h:187
And_Criteria(ConvergenceCriteriaPointerType pFirstCriterion, ConvergenceCriteriaPointerType pSecondCriterion)
Default constructor.
Definition: and_criteria.h:116
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 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