SU2
matrix_structure.hpp
Go to the documentation of this file.
1 
35 #pragma once
36 
37 #include "./mpi_structure.hpp"
38 #include <limits>
39 #include <iostream>
40 #include <cmath>
41 #include <cstdlib>
42 
43 #include "config_structure.hpp"
44 #include "geometry_structure.hpp"
45 #include "vector_structure.hpp"
46 
47 using namespace std;
48 
49 const su2double eps = numeric_limits<su2double>::epsilon();
59 class CSysMatrix {
60 private:
61  unsigned long nPoint,
62  nPointDomain,
63  nVar,
64  nEqn;
65  su2double *matrix;
66  su2double *ILU_matrix;
67  unsigned long *row_ptr;
68  unsigned long *col_ind;
69  unsigned long nnz;
70  su2double *block;
71  su2double *block_inverse;
72  su2double *block_weight;
73  su2double *prod_block_vector;
74  su2double *prod_row_vector;
75  su2double *aux_vector;
76  su2double *sum_vector;
77  su2double *invM;
79  bool *LineletBool;
80  vector<unsigned long> *LineletPoint;
81  unsigned long nLinelet;
82  su2double **UBlock, **invUBlock, **LBlock,
83  **yVector, **zVector, **rVector, *LFBlock,
84  *LyVector, *FzVector;
85  unsigned long max_nElem;
86 
87 public:
88 
92  CSysMatrix(void);
93 
97  ~CSysMatrix(void);
98 
106  void Initialize(unsigned long nPoint, unsigned long nPointDomain, unsigned short nVar, unsigned short nEqn,
107  bool EdgeConnect, CGeometry *geometry, CConfig *config);
108 
119  void SetIndexes(unsigned long val_nPoint, unsigned long val_nPointDomain, unsigned short val_nVar, unsigned short val_nEq, unsigned long* val_row_ptr, unsigned long* val_col_ind, unsigned long val_nnz, CConfig *config);
120 
124  void SetValZero(void);
125 
131  su2double *GetBlock(unsigned long block_i, unsigned long block_j);
132 
138  su2double GetBlock(unsigned long block_i, unsigned long block_j, unsigned short iVar, unsigned short jVar);
139 
146  void SetBlock(unsigned long block_i, unsigned long block_j, su2double **val_block);
147 
154  void SetBlock(unsigned long block_i, unsigned long block_j, su2double *val_block);
155 
162  void AddBlock(unsigned long block_i, unsigned long block_j, su2double **val_block);
163 
170  void SubtractBlock(unsigned long block_i, unsigned long block_j, su2double **val_block);
171 
177  su2double *GetBlock_ILUMatrix(unsigned long block_i, unsigned long block_j);
178 
185  void SetBlock_ILUMatrix(unsigned long block_i, unsigned long block_j, su2double *val_block);
186 
187 
194  void SetBlockTransposed_ILUMatrix(unsigned long block_i, unsigned long block_j, su2double *val_block);
195 
202  void SubtractBlock_ILUMatrix(unsigned long block_i, unsigned long block_j, su2double *val_block);
203 
210  void AddVal2Diag(unsigned long block_i, su2double val_matrix);
211 
218  void SetVal2Diag(unsigned long block_i, su2double val_matrix);
219 
226  void MatrixVectorProduct(su2double *matrix, su2double *vector, su2double *product);
227 
234  void MatrixMatrixProduct(su2double *matrix_a, su2double *matrix_b, su2double *product);
235 
240  void DeleteValsRowi(unsigned long i);
241 
248  su2double MatrixDeterminant(su2double **a, unsigned long n);
249 
256  void MatrixCoFactor(su2double **a, unsigned long n, su2double **b) ;
257 
263  void MatrixTranspose(su2double **a, unsigned long n) ;
264 
272  void Gauss_Elimination(unsigned long block_i, su2double* rhs, bool transposed = false);
273 
280  void Gauss_Elimination(su2double* Block, su2double* rhs);
281 
288  void Gauss_Elimination_ILUMatrix(unsigned long block_i, su2double* rhs);
289 
298  void ProdBlockVector(unsigned long block_i, unsigned long block_j, const CSysVector & vec);
299 
306  void UpperProduct(CSysVector & vec, unsigned long row_i);
307 
314  void LowerProduct(CSysVector & vec, unsigned long row_i);
315 
322  void DiagonalProduct(CSysVector & vec, unsigned long row_i);
323 
330  void SendReceive_Solution(CSysVector & x, CGeometry *geometry, CConfig *config);
331 
338  void SendReceive_SolutionTransposed(CSysVector & x, CGeometry *geometry, CConfig *config);
339 
346  void RowProduct(const CSysVector & vec, unsigned long row_i);
347 
354  void MatrixVectorProduct(const CSysVector & vec, CSysVector & prod);
355 
363  void MatrixVectorProduct(const CSysVector & vec, CSysVector & prod, CGeometry *geometry, CConfig *config);
364 
372  void MatrixVectorProductTransposed(const CSysVector & vec, CSysVector & prod, CGeometry *geometry, CConfig *config);
373 
377  void GetMultBlockBlock(su2double *c, su2double *a, su2double *b);
378 
382  void GetMultBlockVector(su2double *c, su2double *a, su2double *b);
383 
387  void GetSubsBlock(su2double *c, su2double *a, su2double *b);
388 
392  void GetSubsVector(su2double *c, su2double *a, su2double *b);
393 
399  void InverseDiagonalBlock(unsigned long block_i, su2double *invBlock, bool transpose = false);
400 
406  void InverseDiagonalBlock_ILUMatrix(unsigned long block_i, su2double *invBlock);
407 
413  void InverseBlock(su2double *Block, su2double *invBlock);
414 
418  void BuildJacobiPreconditioner(bool transpose = false);
419 
427  void ComputeJacobiPreconditioner(const CSysVector & vec, CSysVector & prod, CGeometry *geometry, CConfig *config);
428 
442  unsigned long Jacobi_Smoother(const CSysVector & b, CSysVector & x, CMatrixVectorProduct & mat_vec, su2double tol, unsigned long m, su2double *residual, bool monitoring, CGeometry *geometry, CConfig *config);
443 
448  void BuildILUPreconditioner(bool transposed = false);
449 
457  void ComputeILUPreconditioner(const CSysVector & vec, CSysVector & prod, CGeometry *geometry, CConfig *config);
458 
472  unsigned long ILU0_Smoother(const CSysVector & b, CSysVector & x, CMatrixVectorProduct & mat_vec, su2double tol, unsigned long m, su2double *residual, bool monitoring, CGeometry *geometry, CConfig *config);
473 
479  void ComputeLU_SGSPreconditioner(const CSysVector & vec, CSysVector & prod, CGeometry *geometry, CConfig *config);
480 
494  unsigned long LU_SGS_Smoother(const CSysVector & b, CSysVector & x, CMatrixVectorProduct & mat_vec, su2double tol, unsigned long m, su2double *residual, bool monitoring, CGeometry *geometry, CConfig *config);
495 
501  unsigned short BuildLineletPreconditioner(CGeometry *geometry, CConfig *config);
502 
508  void ComputeLineletPreconditioner(const CSysVector & vec, CSysVector & prod, CGeometry *geometry, CConfig *config);
509 
516  void ComputeResidual(const CSysVector & sol, const CSysVector & f, CSysVector & res);
517 
518 };
519 
525 private:
526  CSysMatrix* sparse_matrix;
527  CGeometry* geometry;
528  CConfig* config;
530 public:
531 
538  CSysMatrixVectorProduct(CSysMatrix & matrix_ref, CGeometry *geometry_ref, CConfig *config_ref);
539 
544 
550  void operator()(const CSysVector & u, CSysVector & v) const;
551 };
552 
558 private:
559  CSysMatrix* sparse_matrix;
560  CGeometry* geometry;
561  CConfig* config;
563 public:
564 
571  CSysMatrixVectorProductTransposed(CSysMatrix & matrix_ref, CGeometry *geometry_ref, CConfig *config_ref);
572 
577 
583  void operator()(const CSysVector & u, CSysVector & v) const;
584 };
585 
591 private:
592  CSysMatrix* sparse_matrix;
593  CGeometry* geometry;
594  CConfig* config;
596 public:
597 
604  CJacobiPreconditioner(CSysMatrix & matrix_ref, CGeometry *geometry_ref, CConfig *config_ref);
605 
610 
616  void operator()(const CSysVector & u, CSysVector & v) const;
617 };
618 
624 private:
625  CSysMatrix* sparse_matrix;
626  CGeometry* geometry;
627  CConfig* config;
629 public:
630 
637  CJacobiTransposedPreconditioner(CSysMatrix & matrix_ref, CGeometry *geometry_ref, CConfig *config_ref);
638 
643 
649  void operator()(const CSysVector & u, CSysVector & v) const;
650 };
651 
657 private:
658  CSysMatrix* sparse_matrix;
659  CGeometry* geometry;
660  CConfig* config;
662 public:
663 
670  CILUPreconditioner(CSysMatrix & matrix_ref, CGeometry *geometry_ref, CConfig *config_ref);
671 
676 
682  void operator()(const CSysVector & u, CSysVector & v) const;
683 };
684 
690 private:
691  CSysMatrix* sparse_matrix;
692  CGeometry* geometry;
693  CConfig* config;
695 public:
696 
703  CLU_SGSPreconditioner(CSysMatrix & matrix_ref, CGeometry *geometry_ref, CConfig *config_ref);
704 
709 
715  void operator()(const CSysVector & u, CSysVector & v) const;
716 };
717 
723 private:
724  CSysMatrix* sparse_matrix;
725  CGeometry* geometry;
726  CConfig* config;
728 public:
729 
736  CLineletPreconditioner(CSysMatrix & matrix_ref, CGeometry *geometry_ref, CConfig *config_ref);
737 
742 
748  void operator()(const CSysVector & u, CSysVector & v) const;
749 };
750 
751 #include "matrix_structure.inl"
Definition: matrix_structure.hpp:557
Headers of the main subroutines for creating the geometrical structure. The subroutines and functions...
All the information about the definition of the physical problem. The subroutines and functions are i...
Parent class for defining the geometry of the problem (complete geometry, multigrid agglomerated geom...
Definition: geometry_structure.hpp:72
Headers of the mpi interface for generalized datatypes. The subroutines and functions are in the mpi_...
~CJacobiTransposedPreconditioner()
destructor of the class
Definition: matrix_structure.hpp:642
abstract base class for defining matrix-vector products
Definition: vector_structure.hpp:363
~CILUPreconditioner()
destructor of the class
Definition: matrix_structure.hpp:675
abstract base class for defining preconditioning operation
Definition: vector_structure.hpp:380
~CSysMatrixVectorProduct()
destructor of the class
Definition: matrix_structure.hpp:543
~CSysMatrixVectorProductTransposed()
destructor of the class
Definition: matrix_structure.hpp:576
specialization of preconditioner that uses CSysMatrix class
Definition: matrix_structure.hpp:689
~CJacobiPreconditioner()
destructor of the class
Definition: matrix_structure.hpp:609
~CLU_SGSPreconditioner()
destructor of the class
Definition: matrix_structure.hpp:708
Main class for defining sparse matrices-by-blocks with compressed row format.
Definition: matrix_structure.hpp:59
specialization of preconditioner that uses CSysMatrix class
Definition: matrix_structure.hpp:656
Headers for the classes related to linear solvers (CG, FGMRES, etc) The subroutines and functions are...
specialization of preconditioner that uses CSysMatrix class
Definition: matrix_structure.hpp:590
Class for holding and manipulating vectors needed by linear solvers.
Definition: vector_structure.hpp:60
specialization of preconditioner that uses CSysMatrix class
Definition: matrix_structure.hpp:722
const su2double eps
machine epsilon
Definition: matrix_structure.hpp:49
specialization of preconditioner that uses CSysMatrix class
Definition: matrix_structure.hpp:623
specialization of matrix-vector product that uses CSysMatrix class
Definition: matrix_structure.hpp:524
~CLineletPreconditioner()
destructor of the class
Definition: matrix_structure.hpp:741
In-Line subroutines of the matrix_structure.hpp file.
Main class for defining the problem; basically this class reads the configuration file...
Definition: config_structure.hpp:68