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.
ilu_preconditioner.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: Pooyan Dadvand
11 // Riccardo Rossi
12 //
13 
14 #if !defined(KRATOS_ILU_PRECONDITIONER_H_INCLUDED )
15 #define KRATOS_ILU_PRECONDITIONER_H_INCLUDED
16 
17 // System includes
18 
19 // External includes
20 
21 // Project includes
22 #include "includes/define.h"
23 
24 namespace Kratos
25 {
26 
27 
30 
34 
38 
42 
46 
49 
51 
52 template<class TSparseSpaceType, class TDenseSpaceType>
53 class ILUPreconditioner : public Preconditioner<TSparseSpaceType, TDenseSpaceType>
54 {
55 public:
58 
61 
62 
64 
65 
67 
69 
71 
75 
78  {
79  L = NULL;
80  iL = NULL;
81  jL = NULL;
82  U = NULL;
83  iU = NULL;
84  jU = NULL;
85  }
86 
87 
90 
91 
93  ~ILUPreconditioner() override
94  {
95  if ( L!=NULL) delete[] L;
96  if (iL!=NULL) delete[] iL;
97  if (jL!=NULL) delete[] jL;
98  if ( U!=NULL) delete[] U;
99  if (iU!=NULL) delete[] iU;
100  if (jU!=NULL) delete[] jU;
101 
102  L = NULL;
103  iL = NULL;
104  jL = NULL;
105  U = NULL;
106  iU = NULL;
107  jU = NULL;
108  }
109 
110 
111 
115 
118  {
119  mILUSize = Other.mILUSize;
120  unsigned int size = Other.iL[mILUSize];
121  L = new double[size];
122  U = new double[size];
123  iL = new int[mILUSize+1];
124  jL = new int[size];
125  iU = new int[mILUSize+1];
126  jU = new int[size];
127 
128 
129  std::copy(Other.L, Other.L+size, L);
130  std::copy(Other.U, Other.U+size, U);
131  std::copy(Other.iL, Other.iL+mILUSize+1, iL);
132  std::copy(Other.jL, Other.jL+size, jL);
133  std::copy(Other.iU, Other.iU+mILUSize+1, iU);
134  std::copy(Other.jU, Other.jU+size, jU);
135 
136 
137  return *this;
138  }
139 
140 
141 
145 
146 
147 
148  void Mult(SparseMatrixType& rA, VectorType& rX, VectorType& rY) override
149  {
150  VectorType z = rX;
151  TSparseSpaceType::Mult(rA,z, rY);
152  ApplyLeft(rY);
153  }
154 
156  {
157  VectorType z = rX;
160  }
161 
167  {
168  const int size = TSparseSpaceType::Size(rX);
169  VectorType temp(size);
170  double sum;
171  int i, indexj;
172  for (i=0; i<size; i++)
173  {
174  sum=rX[i];
175  for (indexj=iL[i]; indexj<iL[i+1]; indexj++)
176  {
177  sum=sum-L[indexj]*temp[jL[indexj]];
178  }
179  temp[i]=sum;
180  }
181  for (i=size-1; i>=0; i--)
182  {
183  sum=temp[i];
184  for (indexj=iU[i]+1; indexj<iU[i+1]; indexj++)
185  {
186  sum=sum-U[indexj]*rX[jU[indexj]];
187  }
188  rX[i]=sum/U[iU[i]];
189  }
190  return rX;
191  }
192 
198  {
199  const int size = TSparseSpaceType::Size(rX);
200  VectorType temp(size);
201  int i, indexj;
202  double tempi, rxi;
203  for (i=0; i<size; i++) temp[i]=rX[i];
204  for (i=0; i<size; i++)
205  {
206  temp[i]=temp[i]/U[iU[i]];
207  tempi=temp[i];
208  for (indexj=iU[i]+1; indexj<iU[i+1]; indexj++)
209  {
210  temp[jU[indexj]]=temp[jU[indexj]]-tempi*U[indexj];
211  }
212  }
213  for (i=0; i<size; i++) rX[i]=temp[i];
214  for (i=size-1; i>=0; i--)
215  {
216  rxi=rX[i];
217  for (indexj=iL[i]; indexj<iL[i+1]; indexj++)
218  {
219  rX[jL[indexj]]=rX[jL[indexj]]-rxi*L[indexj];
220  }
221  }
222  return rX;
223  }
224 
225 
226 
227 
231 
232 
236 
237 
241 
243  std::string Info() const override
244  {
245  return "ILUPreconditioner";
246  }
247 
248 
250  void PrintInfo(std::ostream& OStream) const override
251  {
252  OStream << "ILUPreconditioner";
253  }
254 
255 
256  void PrintData(std::ostream& OStream) const override
257  {
258  }
259 
260 
261 
265 
266 
268 
269 protected:
272 
273 
277 
278  unsigned int mILUSize;
279  int *iL, *jL, *iU, *jU;
280  double *L, *U;
281 
282 
286 
287 
291 
292 
296 
297 
301 
302 
306 
307 
309 
310 private:
313 
314 
318 
322 
323 
327 
328 
332 
333 
337 
338 
342 
343 
345 
346 }; // Class ILUPreconditioner
347 
349 
350 
352 
355 
356 
360 
361 
363 template<class TSparseSpaceType, class TDenseSpaceType>
364 inline std::istream& operator >> (std::istream& IStream,
366 {
367  return IStream;
368 }
369 
370 
372 template<class TSparseSpaceType, class TDenseSpaceType>
373 inline std::ostream& operator << (std::ostream& OStream,
375 {
376  rThis.PrintInfo(OStream);
377  OStream << std::endl;
378  rThis.PrintData(OStream);
379 
380 
381  return OStream;
382 }
384 
385 
386 } // namespace Kratos.
387 
388 
389 #endif // KRATOS_ILU_PRECONDITIONER_H_INCLUDED defined
390 
ILUPreconditioner class.
Definition: ilu_preconditioner.h:54
double * L
Definition: ilu_preconditioner.h:280
VectorType & ApplyLeft(VectorType &rX) override
Definition: ilu_preconditioner.h:166
ILUPreconditioner & operator=(const ILUPreconditioner &Other)
Assignment operator.
Definition: ilu_preconditioner.h:117
void TransposeMult(SparseMatrixType &rA, VectorType &rX, VectorType &rY) override
Definition: ilu_preconditioner.h:155
int * iL
Definition: ilu_preconditioner.h:279
TDenseSpaceType::MatrixType DenseMatrixType
Definition: ilu_preconditioner.h:70
double * U
Definition: ilu_preconditioner.h:280
TSparseSpaceType::VectorType VectorType
Definition: ilu_preconditioner.h:68
void Mult(SparseMatrixType &rA, VectorType &rX, VectorType &rY) override
Definition: ilu_preconditioner.h:148
unsigned int mILUSize
Definition: ilu_preconditioner.h:278
Preconditioner< TSparseSpaceType, TDenseSpaceType > BaseType
Definition: ilu_preconditioner.h:63
VectorType & ApplyTransposeLeft(VectorType &rX) override
Definition: ilu_preconditioner.h:197
int * jU
Definition: ilu_preconditioner.h:279
void PrintInfo(std::ostream &OStream) const override
Print information about this object.
Definition: ilu_preconditioner.h:250
ILUPreconditioner()
Default constructor.
Definition: ilu_preconditioner.h:77
int * jL
Definition: ilu_preconditioner.h:279
KRATOS_CLASS_POINTER_DEFINITION(ILUPreconditioner)
Counted pointer of ILUPreconditioner.
void PrintData(std::ostream &OStream) const override
Print object's data.
Definition: ilu_preconditioner.h:256
~ILUPreconditioner() override
Destructor.
Definition: ilu_preconditioner.h:93
int * iU
Definition: ilu_preconditioner.h:279
TSparseSpaceType::MatrixType SparseMatrixType
Definition: ilu_preconditioner.h:66
ILUPreconditioner(const ILUPreconditioner &Other)
Copy constructor.
Definition: ilu_preconditioner.h:89
std::string Info() const override
Return information about this object.
Definition: ilu_preconditioner.h:243
Preconditioner class.
Definition: preconditioner.h:75
z
Definition: GenerateWind.py:163
Vector VectorType
Definition: geometrical_transformation_utilities.h:56
Matrix MatrixType
Definition: geometrical_transformation_utilities.h:55
void TransposeMult(SparseSpaceType &dummy, SparseSpaceType::MatrixType &rA, SparseSpaceType::VectorType &rX, SparseSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:104
TSpaceType::IndexType Size(TSpaceType &dummy, typename TSpaceType::VectorType const &rV)
Definition: add_strategies_to_python.cpp:111
void Mult(TSpaceType &dummy, typename TSpaceType::MatrixType &rA, typename TSpaceType::VectorType &rX, typename TSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:98
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
TExpressionType::data_type sum(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:675
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
float temp
Definition: rotating_cone.py:85
integer i
Definition: TensorModule.f:17