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.
solution_strategy.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: March 2018 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_SOLUTION_STRATEGY_H_INCLUDED)
11 #define KRATOS_SOLUTION_STRATEGY_H_INCLUDED
12 
13 // System includes
14 
15 // External includes
16 
17 // Project includes
20 
21 namespace Kratos
22 {
23 
26 
30 
34 
38 
42 
47 template<class TSparseSpace,
48  class TDenseSpace,
49  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
50  >
51 class SolutionStrategy : public Flags
52 {
53  public:
54 
59 
62  typedef typename TSparseSpace::MatrixPointerType SystemMatrixPointerType;
63  typedef typename TSparseSpace::VectorPointerType SystemVectorPointerType;
64 
67 
68 
71 
72 
76 
77 
79  SolutionStrategy(ModelPart& rModelPart) : Flags(), mrModelPart(rModelPart) { mEchoLevel = 0; }
80 
82  SolutionStrategy(ModelPart& rModelPart, Flags& rOptions) : Flags(), mOptions(rOptions), mrModelPart(rModelPart) {mEchoLevel = 0; }
83 
85  ~SolutionStrategy() override {}
86 
90 
94 
103  virtual bool Solve()
104  {
105  KRATOS_TRY
106 
107  this->InitializeSolutionStep();
108 
109  bool converged = this->SolveSolutionStep();
110 
111  // implementation of the adaptive time reduction
112  if( this->IsNot(LocalFlagType::ADAPTIVE_SOLUTION) )
113  converged = true;
114 
115  if(converged)
116  this->FinalizeSolutionStep();
117 
118  return converged;
119 
120  KRATOS_CATCH("")
121  }
122 
127  virtual void InitializeSolutionStep() {}
128 
133  virtual void FinalizeSolutionStep() {}
134 
138  virtual bool SolveSolutionStep() {return true;}
139 
143  virtual bool SolveIteration() {return true;}
144 
148  virtual void Clear() {}
149 
154  virtual int Check()
155  {
156  KRATOS_TRY
157 
158  for (ModelPart::ElementsContainerType::iterator it_elem = GetModelPart().ElementsBegin();
159  it_elem != GetModelPart().ElementsEnd(); it_elem++)
160  {
161  it_elem->Check(GetModelPart().GetProcessInfo());
162  }
163 
164  for (ModelPart::ConditionsContainerType::iterator it_cond = GetModelPart().ConditionsBegin();
165  it_cond != GetModelPart().ConditionsEnd(); it_cond++)
166  {
167  it_cond->Check(GetModelPart().GetProcessInfo());
168  }
169 
170  return 0;
171 
172  KRATOS_CATCH("")
173  }
174 
178 
190  virtual void SetEchoLevel(const int Level)
191  {
192  mEchoLevel = Level;
193  }
194 
206  virtual int GetEchoLevel()
207  {
208  return mEchoLevel;
209  }
210 
211 
215  void SetOptions(Flags& rOptions)
216  {
217  mOptions = rOptions;
218  }
219 
225  {
226  return mOptions;
227  }
228 
229 
234  virtual unsigned int GetMaxIterationNumber()
235  {
236  return 0;
237  }
238 
244  {
245  return mrModelPart;
246  };
247 
251 
255 
257 
258  protected:
261 
265 
266  // Flags to set options
268 
269  // Level of echo for the solution strategy
271 
275 
279  virtual void Initialize(){};
280 
285  virtual void Predict(){};
286 
291  virtual void Update(){};
292 
296  virtual void Finalize(){};
297 
310 
311  private:
312 
319 
320  ModelPart& mrModelPart;
321 
337 
339  SolutionStrategy(SolutionStrategy const& Other) {};
340 
342 
343 };
344 
346 
349 
353 
355 
357 
358 } // namespace Kratos.
359 #endif // KRATOS_SOLUTION_STRATEGY_H_INCLUDED defined
Definition: flags.h:58
bool IsNot(Flags const &rOther) const
Definition: flags.h:291
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
ConditionIterator ConditionsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1371
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
Solution Buider and Solver base class.
Definition: solution_builder_and_solver.hpp:63
Solution scheme base class.
Definition: solution_scheme.hpp:54
Solution strategy base class.
Definition: solution_strategy.hpp:52
virtual void Clear()
Clears the internal storage.
Definition: solution_strategy.hpp:148
TSparseSpace::VectorPointerType SystemVectorPointerType
Definition: solution_strategy.hpp:63
virtual void Initialize()
Initialization of member variables and prior operations.
Definition: solution_strategy.hpp:279
virtual bool Solve()
The problem of interest is solved.
Definition: solution_strategy.hpp:103
SolutionStrategy(ModelPart &rModelPart, Flags &rOptions)
Constructor.
Definition: solution_strategy.hpp:82
ModelPart::DofsArrayType DofsArrayType
Definition: solution_strategy.hpp:58
virtual void Finalize()
Finalization of member variables and prior operations.
Definition: solution_strategy.hpp:296
SolutionStrategy(ModelPart &rModelPart)
Constructor.
Definition: solution_strategy.hpp:79
Flags & GetOptions()
Get strategy options.
Definition: solution_strategy.hpp:224
virtual bool SolveIteration()
Solves the current iteration. This function returns true if a solution has been found,...
Definition: solution_strategy.hpp:143
virtual void Update()
Operation to update the solution ... if it is not called a trivial updater is used in which the value...
Definition: solution_strategy.hpp:291
~SolutionStrategy() override
Destructor.
Definition: solution_strategy.hpp:85
virtual void InitializeSolutionStep()
Performs all the required operations that should be done (for each step) before solving the solution ...
Definition: solution_strategy.hpp:127
SolverLocalFlags LocalFlagType
Definition: solution_strategy.hpp:57
SolutionScheme< TSparseSpace, TDenseSpace > SchemeType
Definition: solution_strategy.hpp:65
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solution_strategy.hpp:243
Flags mOptions
Definition: solution_strategy.hpp:267
TSparseSpace::MatrixPointerType SystemMatrixPointerType
Definition: solution_strategy.hpp:62
TSparseSpace::MatrixType SystemMatrixType
Definition: solution_strategy.hpp:60
virtual void Predict()
Operation to predict the solution ... if it is not called a trivial predictor is used in which the va...
Definition: solution_strategy.hpp:285
KRATOS_CLASS_POINTER_DEFINITION(SolutionStrategy)
Pointer definition of SolutionStrategy.
void SetOptions(Flags &rOptions)
Sets strategy options.
Definition: solution_strategy.hpp:215
virtual int Check()
Function to perform expensive checks.
Definition: solution_strategy.hpp:154
virtual void FinalizeSolutionStep()
Performs all the required operations that should be done (for each step) after solving the solution s...
Definition: solution_strategy.hpp:133
SolutionBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > BuilderAndSolverType
Definition: solution_strategy.hpp:66
virtual unsigned int GetMaxIterationNumber()
This method gets the flag mMaxIterationNumber.
Definition: solution_strategy.hpp:234
TSparseSpace::VectorType SystemVectorType
Definition: solution_strategy.hpp:61
virtual void SetEchoLevel(const int Level)
This sets the level of echo for the solution strategy.
Definition: solution_strategy.hpp:190
virtual bool SolveSolutionStep()
Solves the current step. This function returns true if a solution has been found, false otherwise.
Definition: solution_strategy.hpp:138
int mEchoLevel
Definition: solution_strategy.hpp:270
virtual int GetEchoLevel()
This returns the level of echo for the solution strategy.
Definition: solution_strategy.hpp:206
Solver local flags class definition.
Definition: solution_local_flags.hpp:48
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
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