Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_BandedContainer_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 #ifndef IFPACK2_BANDEDCONTAINER_DECL_HPP
43 #define IFPACK2_BANDEDCONTAINER_DECL_HPP
44 
47 
48 #include "Ifpack2_Container.hpp"
50 #include "Ifpack2_Details_LapackSupportsScalar.hpp"
51 #include "Tpetra_MultiVector.hpp"
52 #include "Tpetra_Map.hpp"
53 #include "Tpetra_RowMatrix.hpp"
54 #include "Teuchos_SerialDenseVector.hpp"
55 #include "Teuchos_SerialBandDenseMatrix.hpp"
56 
57 namespace Ifpack2 {
58 
104 template<class MatrixType,
105  class LocalScalarType,
106  const bool supportsLocalScalarType =
109 
112 template<class MatrixType,
113  class LocalScalarType>
114 class BandedContainer<MatrixType, LocalScalarType, true> :
115  public Container<MatrixType> {
116 public:
118 
119 
126  typedef MatrixType matrix_type;
128  typedef LocalScalarType local_scalar_type;
129 
131  typedef typename MatrixType::scalar_type scalar_type;
133  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
135  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
137  typedef typename MatrixType::node_type node_type;
138 
139  static_assert(std::is_same<MatrixType,
140  Tpetra::RowMatrix<typename MatrixType::scalar_type,
141  typename MatrixType::local_ordinal_type,
142  typename MatrixType::global_ordinal_type,
143  typename MatrixType::node_type> >::value,
144  "Ifpack2::BandedContainer: Please use MatrixType = Tpetra::RowMatrix.");
145 
154  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
155 
157 
159 
176  BandedContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
177  const Teuchos::ArrayView<const local_ordinal_type>& localRows);
178 
180  virtual ~BandedContainer ();
181 
183 
185 
190  virtual size_t getNumRows() const {
191  return numRows_;
192  }
193 
195  virtual bool isInitialized () const {
196  return IsInitialized_;
197  }
198 
200  virtual bool isComputed () const {
201  return IsComputed_;
202  }
203 
205  virtual void setParameters (const Teuchos::ParameterList& List);
206 
208 
210 
212  virtual void initialize ();
213 
215  virtual void compute ();
216 
218  virtual void
219  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
220  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
221  Teuchos::ETransp mode=Teuchos::NO_TRANS,
222  scalar_type alpha=Teuchos::ScalarTraits<scalar_type>::one(),
223  scalar_type beta=Teuchos::ScalarTraits<scalar_type>::zero()) const;
224 
226  virtual void
227  weightedApply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
228  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
229  const Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& D,
230  Teuchos::ETransp mode=Teuchos::NO_TRANS,
231  scalar_type alpha=Teuchos::ScalarTraits<scalar_type>::one(),
232  scalar_type beta=Teuchos::ScalarTraits<scalar_type>::zero()) const;
233 
235 
237 
241  virtual std::ostream& print (std::ostream& os) const;
242 
244 
246 
248  virtual std::string description () const;
249 
251  virtual void
252  describe (Teuchos::FancyOStream &out,
253  const Teuchos::EVerbosityLevel verbLevel =
254  Teuchos::Describable::verbLevel_default) const;
255 
257 private:
260 
262  void extract (const Teuchos::RCP<const row_matrix_type>& globalMatrix);
263 
267  void factor ();
268 
269  typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type,
270  global_ordinal_type, node_type> local_mv_type;
271 
280  void
281  applyImpl (const local_mv_type& X,
282  local_mv_type& Y,
283  Teuchos::ETransp mode,
284  const local_scalar_type alpha,
285  const local_scalar_type beta) const;
286 
288  size_t numRows_;
289 
291  Teuchos::RCP<Teuchos::SerialBandDenseMatrix<int, local_scalar_type> > diagBlock_;
292 
294  Teuchos::Array<int> ipiv_;
295 
297  Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> > localMap_;
298 
300  mutable Teuchos::RCP<local_mv_type> Y_;
301 
303  mutable Teuchos::RCP<local_mv_type> X_;
304 
306  bool IsInitialized_;
307 
309  bool IsComputed_;
310 
311  local_ordinal_type kl_; //< number of subdiagonals
312  local_ordinal_type ku_; //< number of superdiagonals
313 };
314 
318 template<class MatrixType, class LocalScalarType>
319 class BandedContainer<MatrixType, LocalScalarType, false> :
320  public Container<MatrixType> {
321 public:
323 
324 
331  typedef MatrixType matrix_type;
333  typedef LocalScalarType local_scalar_type;
334 
336  typedef typename MatrixType::scalar_type scalar_type;
338  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
340  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
342  typedef typename MatrixType::node_type node_type;
343 
344  static_assert(std::is_same<MatrixType,
345  Tpetra::RowMatrix<typename MatrixType::scalar_type,
346  typename MatrixType::local_ordinal_type,
347  typename MatrixType::global_ordinal_type,
348  typename MatrixType::node_type> >::value,
349  "Ifpack2::BandedContainer: Please use MatrixType = Tpetra::RowMatrix.");
350 
359  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
360 
362 
364 
381  BandedContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
382  const Teuchos::ArrayView<const local_ordinal_type>& localRows);
383 
385  virtual ~BandedContainer ();
386 
388 
390 
395  virtual size_t getNumRows() const {
396  return numRows_;
397  }
398 
400  virtual bool isInitialized () const {
401  return IsInitialized_;
402  }
403 
405  virtual bool isComputed () const {
406  return IsComputed_;
407  }
408 
410  virtual void setParameters (const Teuchos::ParameterList& List);
411 
413 
415 
417  virtual void initialize ();
418 
420  virtual void compute ();
421 
423  virtual void
424  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
425  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
426  Teuchos::ETransp mode=Teuchos::NO_TRANS,
427  scalar_type alpha=Teuchos::ScalarTraits<scalar_type>::one(),
428  scalar_type beta=Teuchos::ScalarTraits<scalar_type>::zero()) const;
429 
431  virtual void
432  weightedApply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
433  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
434  const Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& D,
435  Teuchos::ETransp mode=Teuchos::NO_TRANS,
436  scalar_type alpha=Teuchos::ScalarTraits<scalar_type>::one(),
437  scalar_type beta=Teuchos::ScalarTraits<scalar_type>::zero()) const;
438 
440 
442 
446  virtual std::ostream& print (std::ostream& os) const;
447 
449 
451 
453  virtual std::string description () const;
454 
456  virtual void
457  describe (Teuchos::FancyOStream &out,
458  const Teuchos::EVerbosityLevel verbLevel =
459  Teuchos::Describable::verbLevel_default) const;
460 
462 private:
465 
467  void extract (const Teuchos::RCP<const row_matrix_type>& globalMatrix);
468 
472  void factor ();
473 
474  typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type,
475  global_ordinal_type, node_type> local_mv_type;
476 
485  void
486  applyImpl (const local_mv_type& X,
487  local_mv_type& Y,
488  Teuchos::ETransp mode,
489  const local_scalar_type alpha,
490  const local_scalar_type beta) const;
491 
493  size_t numRows_;
494 
496  Teuchos::RCP<Teuchos::SerialBandDenseMatrix<int, local_scalar_type> > diagBlock_;
497 
499  Teuchos::Array<int> ipiv_;
500 
502  Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> > localMap_;
503 
505  mutable Teuchos::RCP<local_mv_type> Y_;
506 
508  mutable Teuchos::RCP<local_mv_type> X_;
509 
511  bool IsInitialized_;
512 
514  bool IsComputed_;
515 
516  local_ordinal_type kl_; //< number of subdiagonals
517  local_ordinal_type ku_; //< number of superdiagonals
518 };
519 
520 
521 }// namespace Ifpack2
522 
523 #endif // IFPACK2_BANDEDCONTAINER_DECL_HPP
MatrixType::scalar_type scalar_type
The type of entries in the input (global) matrix.
Definition: Ifpack2_BandedContainer_decl.hpp:131
Ifpack2::Container class declaration.
Container< MatrixType >::row_matrix_type row_matrix_type
The (base class) type of the input matrix.
Definition: Ifpack2_BandedContainer_decl.hpp:349
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input (global) matrix.
Definition: Ifpack2_BandedContainer_decl.hpp:340
Container< MatrixType >::row_matrix_type row_matrix_type
The (base class) type of the input matrix.
Definition: Ifpack2_BandedContainer_decl.hpp:144
MatrixType::node_type node_type
The Node type of the input (global) matrix.
Definition: Ifpack2_BandedContainer_decl.hpp:137
MatrixType::node_type node_type
The Node type of the input (global) matrix.
Definition: Ifpack2_BandedContainer_decl.hpp:342
LocalScalarType local_scalar_type
The second template parameter of this class.
Definition: Ifpack2_BandedContainer_decl.hpp:333
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input (global) matrix.
Definition: Ifpack2_BandedContainer_decl.hpp:133
Declaration and definition of the Ifpack2::Details::MultiVectorLocalGatherScatter class...
virtual size_t getNumRows() const
The number of rows in the local matrix on the calling process.
Definition: Ifpack2_BandedContainer_decl.hpp:395
virtual bool isComputed() const
Whether the container has been successfully computed.
Definition: Ifpack2_BandedContainer_decl.hpp:405
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input (global) matrix.
Definition: Ifpack2_BandedContainer_decl.hpp:135
virtual bool isComputed() const
Whether the container has been successfully computed.
Definition: Ifpack2_BandedContainer_decl.hpp:200
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input (global) matrix.
Definition: Ifpack2_BandedContainer_decl.hpp:338
virtual bool isInitialized() const
Whether the container has been successfully initialized.
Definition: Ifpack2_BandedContainer_decl.hpp:195
Interface for creating and solving a local linear problem.
Definition: Ifpack2_Container.hpp:103
LocalScalarType local_scalar_type
The second template parameter of this class.
Definition: Ifpack2_BandedContainer_decl.hpp:128
MatrixType matrix_type
The first template parameter of this class.
Definition: Ifpack2_BandedContainer_decl.hpp:126
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
MatrixType matrix_type
The first template parameter of this class.
Definition: Ifpack2_BandedContainer_decl.hpp:331
Type traits class that says whether Teuchos::LAPACK has a valid implementation for the given ScalarTy...
Definition: Ifpack2_Details_LapackSupportsScalar.hpp:17
Store and solve a local Banded linear problem.
Definition: Ifpack2_BandedContainer_decl.hpp:108
MatrixType::scalar_type scalar_type
The type of entries in the input (global) matrix.
Definition: Ifpack2_BandedContainer_decl.hpp:336
virtual bool isInitialized() const
Whether the container has been successfully initialized.
Definition: Ifpack2_BandedContainer_decl.hpp:400
virtual size_t getNumRows() const
The number of rows in the local matrix on the calling process.
Definition: Ifpack2_BandedContainer_decl.hpp:190