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.
aitken_convergence_accelerator.hpp
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ \.
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Original author: Ruben Zorrilla
9 //
10 
11 #if !defined(KRATOS_AITKEN_CONVERGENCE_ACCELERATOR)
12 #define KRATOS_AITKEN_CONVERGENCE_ACCELERATOR
13 
14 /* System includes */
15 
16 /* External includes */
17 
18 /* Project includes */
20 #include "utilities/math_utils.h"
21 
22 namespace Kratos
23 {
27 
31 
35 
39 
42 
48 template<class TSparseSpace, class TDenseSpace>
49 class AitkenConvergenceAccelerator: public ConvergenceAccelerator<TSparseSpace, TDenseSpace>
50 {
51 public:
52 
56 
58 
59  typedef typename BaseType::Pointer BaseTypePointer;
60 
61  typedef typename BaseType::VectorType VectorType;
63 
67 
72  explicit AitkenConvergenceAccelerator(Parameters rConvAcceleratorParameters)
73  {
74  Parameters aitken_default_parameters(R"(
75  {
76  "solver_type" : "Relaxation",
77  "acceleration_type" : "Aitken",
78  "w_0" : 0.825,
79  "interface_block_newton" : false
80  }
81  )");
82 
83  rConvAcceleratorParameters.ValidateAndAssignDefaults(aitken_default_parameters);
84 
85  mOmega_0 = rConvAcceleratorParameters["w_0"].GetDouble();
86  }
87 
88 
89  AitkenConvergenceAccelerator(double rOmegaInitial = 0.825)
90  {
91  mOmega_0 = rOmegaInitial;
92  }
93 
98  {
99  mOmega_0 = rOther.mOmega_0;
100  }
101 
106  {
107  return BaseTypePointer( new AitkenConvergenceAccelerator(*this) );
108  }
109 
114  () {}
115 
117 
121 
124 
128  void InitializeSolutionStep() override
129  {
130  KRATOS_TRY;
131 
133 
134  KRATOS_CATCH( "" );
135  }
136 
143  void UpdateSolution(const VectorType& rResidualVector,
144  VectorType& rIterationGuess) override
145  {
146  KRATOS_TRY;
147 
148  VectorPointerType pAux(new VectorType(rResidualVector));
149  std::swap(mpResidualVector_1, pAux);
150 
152  {
154  }
155  else
156  {
157  VectorType Aux1minus0(*mpResidualVector_1); // Auxiliar copy of mResidualVector_1
158  TSparseSpace::UnaliasedAdd(Aux1minus0, -1.0, *mpResidualVector_0); // mResidualVector_1 - mResidualVector_0
159 
160  double den = TSparseSpace::Dot(Aux1minus0, Aux1minus0);
161  double num = TSparseSpace::Dot(*mpResidualVector_0, Aux1minus0);
162 
163  mOmega_1 = -mOmega_0*(num/den);
164 
166  mOmega_0 = mOmega_1;
167  }
168 
169  KRATOS_CATCH( "" );
170  }
171 
176  {
177  KRATOS_TRY;
178 
179  // mpResidualVector_0 = mpResidualVector_1;
182 
183  KRATOS_CATCH( "" );
184  }
185 
187 
191 
195 
199 
203 
204 protected:
205 
209 
212 
214 
215  double mOmega_0;
216  double mOmega_1 = 0.0;
217 
220 
222 
226 
230 
234 
238 
242 
243 private:
244 
248 
252 
256 
260 
264 
268 
272 
276 
277 }; /* Class AitkenConvergenceAccelerator */
278 
280 
284 
288 
289 } /* namespace Kratos.*/
290 
291 #endif /* KRATOS_AITKEN_CONVERGENCE_ACCELERATOR defined */
Aitken convergence accelerator Aitken formula-based.
Definition: aitken_convergence_accelerator.hpp:50
AitkenConvergenceAccelerator(const AitkenConvergenceAccelerator &rOther)
Definition: aitken_convergence_accelerator.hpp:97
virtual ~AitkenConvergenceAccelerator()
Definition: aitken_convergence_accelerator.hpp:114
BaseType::VectorType VectorType
Definition: aitken_convergence_accelerator.hpp:61
double mOmega_1
Definition: aitken_convergence_accelerator.hpp:216
VectorPointerType mpResidualVector_0
Definition: aitken_convergence_accelerator.hpp:218
AitkenConvergenceAccelerator(Parameters rConvAcceleratorParameters)
Definition: aitken_convergence_accelerator.hpp:72
void FinalizeNonLinearIteration() override
Definition: aitken_convergence_accelerator.hpp:175
VectorPointerType mpResidualVector_1
Definition: aitken_convergence_accelerator.hpp:219
BaseType::VectorPointerType VectorPointerType
Definition: aitken_convergence_accelerator.hpp:62
void InitializeSolutionStep() override
Definition: aitken_convergence_accelerator.hpp:128
ConvergenceAccelerator< TSparseSpace, TDenseSpace > BaseType
Definition: aitken_convergence_accelerator.hpp:57
KRATOS_CLASS_POINTER_DEFINITION(AitkenConvergenceAccelerator)
void UpdateSolution(const VectorType &rResidualVector, VectorType &rIterationGuess) override
Definition: aitken_convergence_accelerator.hpp:143
virtual BaseTypePointer Clone()
Definition: aitken_convergence_accelerator.hpp:105
unsigned int mConvergenceAcceleratorIteration
Definition: aitken_convergence_accelerator.hpp:213
AitkenConvergenceAccelerator(double rOmegaInitial=0.825)
Definition: aitken_convergence_accelerator.hpp:89
BaseType::Pointer BaseTypePointer
Definition: aitken_convergence_accelerator.hpp:59
double mOmega_0
Definition: aitken_convergence_accelerator.hpp:215
Base class for convergence accelerators This class is intended to be the base of any convergence acce...
Definition: convergence_accelerator.h:43
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
double GetDouble() const
This method returns the double contained in the current Parameter.
Definition: kratos_parameters.cpp:657
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
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
TSparseSpace::VectorType VectorType
Definition: convergence_accelerator.h:50
TSparseSpace::VectorPointerType VectorPointerType
Definition: convergence_accelerator.h:53
double Dot(SparseSpaceType &dummy, SparseSpaceType::VectorType &rX, SparseSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:85
void UnaliasedAdd(TSpaceType &dummy, typename TSpaceType::VectorType &x, const double A, const typename TSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:170
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21