Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_GSPreconditioner.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef STOKHOS_GSPRECONDITIONER_HPP
11 #define STOKHOS_GSPRECONDITIONER_HPP
12 
13 #include "Teuchos_RCP.hpp"
14 #include "Stokhos_Operator.hpp"
16 #include "Teuchos_LAPACK.hpp"
17 
18 namespace Stokhos {
19 
20  template <typename ordinal_type, typename value_type>
22  public Stokhos::Operator<ordinal_type,value_type> {
23  public:
24 
28  const ordinal_type sym_) : A(A_), sym(sym_) {}
29 
31  virtual ~GSPreconditioner() {}
32 
33  // m is the number of GS iterations to solve Mz=r
34  // If sym=0 then do symmetric Gauss Seidel
38  ordinal_type m) const {
39  Result.assign(Input);
40  ordinal_type n=A.numRows();
41  ordinal_type info;
43 
44  //Get lower triangular part of A
46  for (ordinal_type i=0; i<n; i++){
47  for (ordinal_type j=0; j<n; j++){
48  if (j>i)
49  L(i,j)=0;
50  }
51  }
52 
53  if (sym==0){
54  //Get inv(diag(A))=D
56  for (ordinal_type i=0; i<n; i++){
57  for (ordinal_type j=0; j<n; j++){
58  D(i,i)=1/A(i,i);
59  }
60  }
61 
62  //Get upper triangular part of A
64  for (ordinal_type i=0; i<n; i++){
65  for (ordinal_type j=0; j<n; j++){
66  if (i>j)
67  U(i,j)=0;
68  }
69  }
70 
71  Result.assign(Input);
72 
73  //compute M=(L+D)inv(diagA)
76 
77  //Forward solve Lz=r
78  lapack.TRTRS('L', 'N', 'N', M.numRows(), 1, M.values(), M.stride(), Result.values(), Result.stride(),&info);
79 
80  //Backward solve Uw=z
81  lapack.TRTRS('U', 'N', 'N', U.numRows(), 1, U.values(), U.stride(), Result.values(), Result.stride(),&info);
82 
83  }
84  else{
85  lapack.TRTRS('L', 'N', 'N', L.numRows(), 1, L.values(), L.stride(), Result.values(), Result.stride(),&info);
86  }
87 
88  return 0;
89  }
90 
91  protected:
93 
95  }; // class GSPreconditioner
96 
97 } // namespace Stokhos
98 
99 #endif // STOKHOS_GSPRECONDITIONER_HPP
100 
ScalarType * values() const
virtual ~GSPreconditioner()
Destructor.
int multiply(ETransp transa, ETransp transb, ScalarType alpha, const SerialDenseMatrix< OrdinalType, ScalarType > &A, const SerialDenseMatrix< OrdinalType, ScalarType > &B, ScalarType beta)
void TRTRS(const char &UPLO, const char &TRANS, const char &DIAG, const OrdinalType &n, const OrdinalType &nrhs, const ScalarType *A, const OrdinalType &lda, ScalarType *B, const OrdinalType &ldb, OrdinalType *info) const
virtual ordinal_type ApplyInverse(const Teuchos::SerialDenseMatrix< ordinal_type, value_type > &Input, Teuchos::SerialDenseMatrix< ordinal_type, value_type > &Result, ordinal_type m) const
Returns the result of a Operator inverse applied to a Teuchos::SerialDenseMatrix Input in Result...
GSPreconditioner(const Teuchos::SerialDenseMatrix< ordinal_type, value_type > &A_, const ordinal_type sym_)
Constructor.
const Teuchos::SerialDenseMatrix< ordinal_type, value_type > & A
SerialDenseMatrix< OrdinalType, ScalarType > & assign(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
int n
OrdinalType stride() const
OrdinalType numRows() const