Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_Experimental_RBILUK_decl.hpp
Go to the documentation of this file.
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack2: Tempated Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
45 
46 #ifndef IFPACK2_EXPERIMENTALCRSRBILUK_DECL_HPP
47 #define IFPACK2_EXPERIMENTALCRSRBILUK_DECL_HPP
48 
49 #include <Tpetra_Experimental_BlockCrsMatrix.hpp>
50 
51 #include <Ifpack2_RILUK.hpp>
52 
53 namespace Ifpack2 {
54 
55 namespace Experimental {
56 
57 template <class scalar_type, class impl_scalar_type>
58 struct BlockMatrixOperations
59 {
60 
61  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
62 
63  typedef Teuchos::ScalarTraits<magnitude_type> STM;
64 
65  void square_matrix_matrix_multiply(const impl_scalar_type * a, const impl_scalar_type * b, impl_scalar_type * c,
66  const int nrows, const impl_scalar_type alpha = STM::one(), const impl_scalar_type beta = STM::zero() ) const
67  {
68  for (int i = 0; i < nrows*nrows; ++i)
69  c[i] = beta*c[i];
70 
71  for (int i = 0; i < nrows; ++i)
72  {
73 
74  const int ioffset = i*nrows;
75  for (int k = 0; k < nrows; ++k)
76  {
77  const int koffset = k*nrows;
78  const impl_scalar_type val = alpha*a[ioffset+k];
79  for (int j = 0; j < nrows; ++j)
80  {
81  c[ioffset+j] += val*b[koffset+j];
82  }
83  }
84  }
85 
86  }
87 
88 
89 };
90 
161 template<class MatrixType>
162 class RBILUK : virtual public Ifpack2::RILUK< Tpetra::RowMatrix< typename MatrixType::scalar_type,
163  typename MatrixType::local_ordinal_type, typename MatrixType::global_ordinal_type, typename MatrixType::node_type> >
164 {
165  public:
166 
168 
169  typedef typename MatrixType::scalar_type scalar_type;
171 
172  //typedef typename MatrixType::impl_scalar_type impl_scalar_type;
173  typedef typename MatrixType::scalar_type impl_scalar_type;
174 
176  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
177 
179  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
180 
182  typedef typename MatrixType::node_type node_type;
183 
185  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
186 
188  typedef Tpetra::RowMatrix<scalar_type,
189  local_ordinal_type,
190  global_ordinal_type,
191  node_type> row_matrix_type;
192 
194  typedef Tpetra::CrsMatrix<scalar_type,
195  local_ordinal_type,
196  global_ordinal_type,
197  node_type> crs_matrix_type;
198 
199  typedef Tpetra::Experimental::BlockCrsMatrix<scalar_type,
200  local_ordinal_type,
201  global_ordinal_type,
202  node_type> block_crs_matrix_type;
203 
204  template <class NewMatrixType> friend class RBILUK;
206 
208 
209  RBILUK (const Teuchos::RCP<const row_matrix_type>& A_in);
213 
217  RBILUK (const Teuchos::RCP<const block_crs_matrix_type>& A_in);
218 
219  private:
222  RBILUK (const RBILUK<MatrixType> & src);
223 
224  public:
225 
227  virtual ~RBILUK ();
229 
231  void initialize ();
232 
241  void compute ();
242 
244 
245 
246  // Declare that we intend to overload RILUK::setMatrix, not hide it.
247  // This avoids build warnings that the method below "hides
248  // overloaded virtual function" (e.g., Clang 3.5).
249  //
250  // NOTE: If the base class of this class changes, e.g., if its
251  // template parameter changes, then be sure to change the code below
252  // to refer to the proper base class.
253  using RILUK<Tpetra::RowMatrix<typename MatrixType::scalar_type,
254  typename MatrixType::local_ordinal_type,
255  typename MatrixType::global_ordinal_type,
256  typename MatrixType::node_type> >::setMatrix;
257 
280  void
281  setMatrix (const Teuchos::RCP<const block_crs_matrix_type>& A);
282 
284 
286 
288  std::string description () const;
289 
291 
293 
323  void
324  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
325  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
326  Teuchos::ETransp mode = Teuchos::NO_TRANS,
327  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one (),
328  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero ()) const;
330 
331 public:
332 
334  Teuchos::RCP<const block_crs_matrix_type> getBlockMatrix () const;
335 
337  const block_crs_matrix_type& getLBlock () const;
338 
340  const block_crs_matrix_type& getDBlock () const;
341 
343  const block_crs_matrix_type& getUBlock () const;
344 
345 private:
346  typedef Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> MV;
347  typedef Teuchos::ScalarTraits<impl_scalar_type> STS;
348  typedef Teuchos::ScalarTraits<magnitude_type> STM;
349  typedef typename block_crs_matrix_type::little_block_type little_block_type;
350  typedef typename block_crs_matrix_type::little_vec_type little_vec_type;
351 
352  void allocate_L_and_U_blocks();
353  void initAllValues (const block_crs_matrix_type& A);
354 
356  Teuchos::RCP<const row_matrix_type> A_;
357 
359  Teuchos::RCP<const block_crs_matrix_type> A_block_;
360 
362  local_ordinal_type blockSize_;
363 
365  Teuchos::RCP<block_crs_matrix_type> L_block_;
367  Teuchos::RCP<block_crs_matrix_type> U_block_;
369  Teuchos::RCP<block_crs_matrix_type> D_block_;
370 
372  Teuchos::RCP<block_crs_matrix_type> D_block_inverse_;
373 
374  BlockMatrixOperations<scalar_type,impl_scalar_type> blockMatOpts;
375 
376  void square_matrix_matrix_multiply(const impl_scalar_type * a, const impl_scalar_type * b, impl_scalar_type * c,
377  const int nrows, const impl_scalar_type alpha = STM::one(), const impl_scalar_type beta = STM::zero() ) const
378  {
379  for (int i = 0; i < nrows*nrows; ++i)
380  c[i] = beta*c[i];
381 
382  for (int i = 0; i < nrows; ++i)
383  {
384 
385  const int ioffset = i*nrows;
386  for (int k = 0; k < nrows; ++k)
387  {
388  const int koffset = k*nrows;
389  const impl_scalar_type val = alpha*a[ioffset+k];
390  for (int j = 0; j < nrows; ++j)
391  {
392  c[ioffset+j] += val*b[koffset+j];
393  }
394  }
395  }
396 
397  }
398 
399 };
400 
401 
402 } // namepsace Experimental
403 
404 } // namespace Ifpack2
405 
406 #endif /* IFPACK2_EXPERIMENTALCRSRBILUK_DECL_HPP */
Ifpack2 features that are experimental. Use at your own risk.
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Experimental_RBILUK_decl.hpp:179
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Experimental_RBILUK_decl.hpp:170
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Experimental_RBILUK_decl.hpp:185
ILU(k) factorization of a given Tpetra::RowMatrix.
Definition: Ifpack2_RILUK_decl.hpp:243
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Experimental_RBILUK_decl.hpp:182
Tpetra::CrsMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > crs_matrix_type
Tpetra::CrsMatrix specialization used by this class for representing L and U.
Definition: Ifpack2_Experimental_RBILUK_decl.hpp:197
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Experimental_RBILUK_decl.hpp:176
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
Tpetra::RowMatrix specialization used by this class.
Definition: Ifpack2_Experimental_RBILUK_decl.hpp:191
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
ILU(k) factorization of a given Tpetra::Experimental::BlockCrsMatrix.
Definition: Ifpack2_Experimental_RBILUK_decl.hpp:162