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.
composite_criterion.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosSolidMechanicsApplication $
3 // Created by: $Author: JMCarbonell $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: May 2018 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_COMPOSITE_CRITERION_H_INCLUDED )
11 #define KRATOS_COMPOSITE_CRITERION_H_INCLUDED
12 
13 // System includes
14 
15 // External includes
16 
17 // Project includes
19 
20 namespace Kratos
21 {
22 
25 
28 
32 
36 
40 
44 
49 template<class TSparseSpace,class TDenseSpace>
50 class CompositeCriterion : public ConvergenceCriterion< TSparseSpace, TDenseSpace >
51 {
52  public:
55 
58  typedef typename BaseType::DataType DataType;
62 
63  typedef typename BaseType::Pointer BasePointerType;
64  typedef std::vector<BasePointerType> ConvergenceCriterionVectorType;
65 
68 
69 
73 
75  CompositeCriterion(BasePointerType pFirstCriterion, BasePointerType pSecondCriterion) : BaseType()
76  {
77  mConvergenceCriteria.push_back(pFirstCriterion);
78  mConvergenceCriteria.push_back(pSecondCriterion);
79  }
80 
82  CompositeCriterion(ConvergenceCriterionVectorType& rConvergenceCriteria) : BaseType(), mConvergenceCriteria(rConvergenceCriteria)
83  {
84  }
85 
88  :BaseType(rOther)
89  ,mConvergenceCriteria(rOther.mConvergenceCriteria)
90  {
91  }
92 
94  ~CompositeCriterion () override {}
95 
99 
108  void SetEchoLevel(int Level) override
109  {
110  BaseType::SetEchoLevel(Level);
111  for(typename ConvergenceCriterionVectorType::iterator it=mConvergenceCriteria.begin();
112  it!=mConvergenceCriteria.end(); ++it)
113  (*it)->SetEchoLevel(Level);
114  }
115 
119  bool PreCriteria(ModelPart& rModelPart,
120  DofsArrayType& rDofSet,
121  const SystemMatrixType& rA,
122  const SystemVectorType& rDx,
123  const SystemVectorType& rb) override
124  {
125  if(this->Is(LocalFlagType::AND)){
126 
127  for(typename ConvergenceCriterionVectorType::iterator it=mConvergenceCriteria.begin();
128  it!=mConvergenceCriteria.end(); ++it)
129  if( !((*it)->PreCriteria(rModelPart,rDofSet,rA,rDx,rb)) )
130  return false;
131 
132  return true;
133  }
134  else if (this->Is(LocalFlagType::OR)){
135 
136  for(typename ConvergenceCriterionVectorType::iterator it=mConvergenceCriteria.begin();
137  it!=mConvergenceCriteria.end(); ++it)
138  if( ((*it)->PreCriteria(rModelPart,rDofSet,rA,rDx,rb)) )
139  return true;
140 
141  return false;
142  }
143 
144  return false;
145  }
146 
150  bool PostCriteria(ModelPart& rModelPart,
151  DofsArrayType& rDofSet,
152  const SystemMatrixType& rA,
153  const SystemVectorType& rDx,
154  const SystemVectorType& rb) override
155  {
156  if(this->Is(LocalFlagType::AND)){
157 
158  for(typename ConvergenceCriterionVectorType::iterator it=mConvergenceCriteria.begin();
159  it!=mConvergenceCriteria.end(); ++it)
160  if( !((*it)->PostCriteria(rModelPart,rDofSet,rA,rDx,rb)) )
161  return false;
162 
163  return true;
164  }
165  else if (this->Is(LocalFlagType::OR)){
166 
167  for(typename ConvergenceCriterionVectorType::iterator it=mConvergenceCriteria.begin();
168  it!=mConvergenceCriteria.end(); ++it)
169  if( ((*it)->PostCriteria(rModelPart,rDofSet,rA,rDx,rb)) )
170  return true;
171 
172  return false;
173  }
174 
175  return false;
176  }
177 
179  DofsArrayType& rDofSet,
180  const SystemMatrixType& rA,
181  const SystemVectorType& rDx,
182  const SystemVectorType& rb) override
183  {
184  for(typename ConvergenceCriterionVectorType::iterator it=mConvergenceCriteria.begin();
185  it!=mConvergenceCriteria.end(); ++it)
186  (*it)->InitializeSolutionStep(rModelPart,rDofSet,rA,rDx,rb);
187  }
188 
189  void FinalizeSolutionStep(ModelPart& rModelPart,
190  DofsArrayType& rDofSet,
191  const SystemMatrixType& rA,
192  const SystemVectorType& rDx,
193  const SystemVectorType& rb) override
194  {
195  for(typename ConvergenceCriterionVectorType::iterator it=mConvergenceCriteria.begin();
196  it!=mConvergenceCriteria.end(); ++it)
197  (*it)->FinalizeSolutionStep(rModelPart,rDofSet,rA,rDx,rb);
198  }
199 
200 
208  int Check(ModelPart& rModelPart) override
209  {
210  KRATOS_TRY
211 
212  if( !(this->Is(LocalFlagType::AND) || this->Is(LocalFlagType::OR)) )
213  KRATOS_ERROR << "Flag AND or OR is not set for the Composite Convergence Criterion "<< std::endl;
214 
215  for(typename ConvergenceCriterionVectorType::iterator it=mConvergenceCriteria.begin();
216  it!=mConvergenceCriteria.end(); ++it)
217  if( ((*it)->Check(rModelPart)) != 0 )
218  return 1;
219 
220  return 0;
221 
222  KRATOS_CATCH("")
223  }
224 
228 
232 
236 
240 
242 
243  protected:
246 
250 
254 
258 
262 
266 
270 
272 
273  private:
276 
277 
281 
282  ConvergenceCriterionVectorType mConvergenceCriteria;
283 
287 
291 
295 
299 
303 
305 
306 }; // Class CompositeCriterion
307 
309 
312 
313 
317 
319 
321 
322 } // namespace Kratos.
323 
324 #endif // KRATOS_COMPOSITE_CRITERION_H_INCLUDED defined
This convergence criteria checks simultaneously different convergence criteria.
Definition: composite_criterion.hpp:51
BaseType::DataType DataType
Definition: composite_criterion.hpp:58
std::vector< BasePointerType > ConvergenceCriterionVectorType
Definition: composite_criterion.hpp:64
void SetEchoLevel(int Level) override
It sets the level of echo for the solving strategy.
Definition: composite_criterion.hpp:108
int Check(ModelPart &rModelPart) override
This function is designed to be called once to perform all the checks needed on the input provided.
Definition: composite_criterion.hpp:208
BaseType::SystemMatrixType SystemMatrixType
Definition: composite_criterion.hpp:60
ConvergenceCriterion< TSparseSpace, TDenseSpace > BaseType
Definition: composite_criterion.hpp:56
KRATOS_CLASS_POINTER_DEFINITION(CompositeCriterion)
Pointer definition of CompositeCriterion.
void FinalizeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const SystemMatrixType &rA, const SystemVectorType &rDx, const SystemVectorType &rb) override
Definition: composite_criterion.hpp:189
BaseType::SystemVectorType SystemVectorType
Definition: composite_criterion.hpp:61
void InitializeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const SystemMatrixType &rA, const SystemVectorType &rDx, const SystemVectorType &rb) override
Definition: composite_criterion.hpp:178
BaseType::LocalFlagType LocalFlagType
Definition: composite_criterion.hpp:57
CompositeCriterion(ConvergenceCriterionVectorType &rConvergenceCriteria)
Constructor.
Definition: composite_criterion.hpp:82
bool PostCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const SystemMatrixType &rA, const SystemVectorType &rDx, const SystemVectorType &rb) override
Definition: composite_criterion.hpp:150
~CompositeCriterion() override
Destructor.
Definition: composite_criterion.hpp:94
CompositeCriterion(CompositeCriterion const &rOther)
Copy constructor.
Definition: composite_criterion.hpp:87
BaseType::DofsArrayType DofsArrayType
Definition: composite_criterion.hpp:59
bool PreCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const SystemMatrixType &rA, const SystemVectorType &rDx, const SystemVectorType &rb) override
Definition: composite_criterion.hpp:119
BaseType::Pointer BasePointerType
Definition: composite_criterion.hpp:63
CompositeCriterion(BasePointerType pFirstCriterion, BasePointerType pSecondCriterion)
Constructor.
Definition: composite_criterion.hpp:75
Convergence Criterion base class.
Definition: convergence_criterion.hpp:52
TSparseSpace::DataType DataType
Definition: convergence_criterion.hpp:58
TSparseSpace::MatrixType SystemMatrixType
Definition: convergence_criterion.hpp:60
virtual void SetEchoLevel(int Level)
Definition: convergence_criterion.hpp:104
TSparseSpace::VectorType SystemVectorType
Definition: convergence_criterion.hpp:61
Solver local flags class definition.
Definition: solution_local_flags.hpp:74
bool Is(Flags const &rOther) const
Definition: flags.h:274
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
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