Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_DenseContainer_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 
43 #ifndef IFPACK2_DENSECONTAINER_DECL_HPP
44 #define IFPACK2_DENSECONTAINER_DECL_HPP
45 
48 
49 #include "Ifpack2_Container.hpp"
51 #include "Ifpack2_Details_LapackSupportsScalar.hpp"
52 #include "Tpetra_MultiVector.hpp"
53 #include "Tpetra_Map.hpp"
54 #include "Tpetra_RowMatrix.hpp"
55 #include "Teuchos_SerialDenseMatrix.hpp"
56 #include "Tpetra_Experimental_BlockCrsMatrix_decl.hpp"
57 
58 namespace Ifpack2 {
59 
105 template<class MatrixType,
106  class LocalScalarType,
107  const bool supportsLocalScalarType =
109 class DenseContainer {};
110 
113 template<typename MatrixType, typename LocalScalarType>
114 class DenseContainer<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::DenseContainer: Please use MatrixType = Tpetra::RowMatrix.");
145 
154  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
155 
156  typedef Tpetra::Experimental::BlockCrsMatrix<scalar_type, local_ordinal_type,
157  global_ordinal_type, node_type> block_crs_matrix_type;
158 
160 
162 
176  DenseContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
177  const Teuchos::ArrayView<const local_ordinal_type>& localRows);
178 
180  virtual ~DenseContainer ();
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  applyBlockCrs (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  apply (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  Teuchos::ETransp mode=Teuchos::NO_TRANS,
230  scalar_type alpha=Teuchos::ScalarTraits<scalar_type>::one(),
231  scalar_type beta=Teuchos::ScalarTraits<scalar_type>::zero()) const;
232 
234  virtual void
235  weightedApply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
236  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
237  const Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& D,
238  Teuchos::ETransp mode=Teuchos::NO_TRANS,
239  scalar_type alpha=Teuchos::ScalarTraits<scalar_type>::one(),
240  scalar_type beta=Teuchos::ScalarTraits<scalar_type>::zero()) const;
241 
243 
245 
249  virtual std::ostream& print (std::ostream& os) const;
250 
252 
254 
256  virtual std::string description () const;
257 
259  virtual void
260  describe (Teuchos::FancyOStream &out,
261  const Teuchos::EVerbosityLevel verbLevel =
262  Teuchos::Describable::verbLevel_default) const;
263 
265 private:
266 
269 
271  void extractBlockCrs (const Teuchos::RCP<const block_crs_matrix_type>& globalMatrix);
272 
274  void extract (const Teuchos::RCP<const row_matrix_type>& globalMatrix);
275 
279  void factor ();
280 
281  typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type,
282  global_ordinal_type, node_type> local_mv_type;
283 
284  typedef Tpetra::Experimental::BlockMultiVector<local_scalar_type, local_ordinal_type,
285  global_ordinal_type, node_type> local_block_mv_type;
286 
295  void
296  applyImpl (const local_mv_type& X,
297  local_mv_type& Y,
298  Teuchos::ETransp mode,
299  const local_scalar_type alpha,
300  const local_scalar_type beta) const;
301 
302  void
303  applyImplBlockCrs (const local_mv_type& X,
304  local_mv_type& Y,
305  Teuchos::ETransp mode,
306  const local_scalar_type alpha,
307  const local_scalar_type beta) const;
308 
309  bool hasBlockCrsMatrix_;
310 
312  size_t numRows_;
313 
314  int blockSize_;
315 
317  Teuchos::SerialDenseMatrix<int, local_scalar_type> diagBlock_;
318 
320  Teuchos::Array<int> ipiv_;
321 
323  Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> > localMap_;
324 
326  mutable Teuchos::RCP<local_mv_type> Y_;
327 
329  mutable Teuchos::RCP<local_mv_type> X_;
330 
331  mutable Teuchos::RCP<local_block_mv_type> blockY_;
332  mutable Teuchos::RCP<local_block_mv_type> blockX_;
333 
335  bool IsInitialized_;
336 
338  bool IsComputed_;
339 };
340 
343 template<class MatrixType, class LocalScalarType>
344 class DenseContainer<MatrixType, LocalScalarType, false> :
345  public Container<MatrixType> {
346 public:
348 
349 
356  typedef MatrixType matrix_type;
358  typedef LocalScalarType local_scalar_type;
359 
361  typedef typename MatrixType::scalar_type scalar_type;
363  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
365  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
367  typedef typename MatrixType::node_type node_type;
368 
369  static_assert(std::is_same<MatrixType,
370  Tpetra::RowMatrix<typename MatrixType::scalar_type,
371  typename MatrixType::local_ordinal_type,
372  typename MatrixType::global_ordinal_type,
373  typename MatrixType::node_type> >::value,
374  "Ifpack2::DenseContainer: Please use MatrixType = Tpetra::RowMatrix.");
375 
384  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
385 
386  typedef Tpetra::Experimental::BlockCrsMatrix<scalar_type, local_ordinal_type,
387  global_ordinal_type, node_type> block_crs_matrix_type;
388 
390 
392 
406  DenseContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
407  const Teuchos::ArrayView<const local_ordinal_type>& localRows);
408 
410  virtual ~DenseContainer ();
411 
413 
415 
420  virtual size_t getNumRows () const {
421  return numRows_;
422  }
423 
425  virtual bool isInitialized () const {
426  return IsInitialized_;
427  }
428 
430  virtual bool isComputed () const {
431  return IsComputed_;
432  }
433 
435  virtual void setParameters(const Teuchos::ParameterList& List);
436 
438 
440 
442  virtual void initialize ();
443 
445  virtual void compute ();
446 
448  virtual void
449  applyBlockCrs (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
450  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
451  Teuchos::ETransp mode=Teuchos::NO_TRANS,
452  scalar_type alpha=Teuchos::ScalarTraits<scalar_type>::one(),
453  scalar_type beta=Teuchos::ScalarTraits<scalar_type>::zero()) const;
454 
456  virtual void
457  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
458  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
459  Teuchos::ETransp mode=Teuchos::NO_TRANS,
460  scalar_type alpha=Teuchos::ScalarTraits<scalar_type>::one(),
461  scalar_type beta=Teuchos::ScalarTraits<scalar_type>::zero()) const;
462 
464  virtual void
465  weightedApply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
466  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
467  const Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& D,
468  Teuchos::ETransp mode=Teuchos::NO_TRANS,
469  scalar_type alpha=Teuchos::ScalarTraits<scalar_type>::one(),
470  scalar_type beta=Teuchos::ScalarTraits<scalar_type>::zero()) const;
471 
473 
475 
479  virtual std::ostream& print (std::ostream& os) const;
480 
482 
484 
486  virtual std::string description () const;
487 
489  virtual void
490  describe (Teuchos::FancyOStream &out,
491  const Teuchos::EVerbosityLevel verbLevel =
492  Teuchos::Describable::verbLevel_default) const;
493 
495 private:
498 
500  void extractBlockCrs (const Teuchos::RCP<const block_crs_matrix_type>& globalMatrix);
501 
503  void extract (const Teuchos::RCP<const row_matrix_type>& globalMatrix);
504 
508  void factor ();
509 
510  typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type,
511  global_ordinal_type, node_type> local_mv_type;
512 
513  typedef Tpetra::Experimental::BlockMultiVector<local_scalar_type, local_ordinal_type,
514  global_ordinal_type, node_type> local_block_mv_type;
515 
524  void
525  applyImpl (const local_mv_type& X,
526  local_mv_type& Y,
527  Teuchos::ETransp mode,
528  const local_scalar_type alpha,
529  const local_scalar_type beta) const;
530 
531  void
532  applyImplBlockCrs (const local_mv_type& X,
533  local_mv_type& Y,
534  Teuchos::ETransp mode,
535  const local_scalar_type alpha,
536  const local_scalar_type beta) const;
537 
539  size_t numRows_;
540 
541  int blockSize_;
542 
544  Teuchos::SerialDenseMatrix<int, local_scalar_type> diagBlock_;
545 
547  Teuchos::Array<int> ipiv_;
548 
550  Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> > localMap_;
551 
553  mutable Teuchos::RCP<local_mv_type> Y_;
554 
556  mutable Teuchos::RCP<local_mv_type> X_;
557 
558  mutable Teuchos::RCP<local_block_mv_type> blockY_;
559  mutable Teuchos::RCP<local_block_mv_type> blockX_;
560 
562  bool IsInitialized_;
563 
565  bool IsComputed_;
566 };
567 
568 } // namespace Ifpack2
569 
570 #endif // IFPACK2_DENSECONTAINER_DECL_HPP
virtual bool isComputed() const
Whether the container has been successfully computed.
Definition: Ifpack2_DenseContainer_decl.hpp:430
Ifpack2::Container class declaration.
Container< MatrixType >::row_matrix_type row_matrix_type
The (base class) type of the input matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:374
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input (global) matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:365
virtual bool isInitialized() const
Whether the container has been successfully initialized.
Definition: Ifpack2_DenseContainer_decl.hpp:425
Declaration and definition of the Ifpack2::Details::MultiVectorLocalGatherScatter class...
virtual bool isInitialized() const
Whether the container has been successfully initialized.
Definition: Ifpack2_DenseContainer_decl.hpp:195
Store and solve a local dense linear problem.
Definition: Ifpack2_DenseContainer_decl.hpp:109
LocalScalarType local_scalar_type
The second template parameter of this class.
Definition: Ifpack2_DenseContainer_decl.hpp:358
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input (global) matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:135
Container< MatrixType >::row_matrix_type row_matrix_type
The (base class) type of the input matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:144
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input (global) matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:363
LocalScalarType local_scalar_type
The second template parameter of this class.
Definition: Ifpack2_DenseContainer_decl.hpp:128
MatrixType::node_type node_type
The Node type of the input (global) matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:137
MatrixType::scalar_type scalar_type
The type of entries in the input (global) matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:361
MatrixType matrix_type
The first template parameter of this class.
Definition: Ifpack2_DenseContainer_decl.hpp:126
MatrixType::scalar_type scalar_type
The type of entries in the input (global) matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:131
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input (global) matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:133
virtual bool isComputed() const
Whether the container has been successfully computed.
Definition: Ifpack2_DenseContainer_decl.hpp:200
Interface for creating and solving a local linear problem.
Definition: Ifpack2_Container.hpp:103
MatrixType::node_type node_type
The Node type of the input (global) matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:367
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_DenseContainer_decl.hpp:356
virtual size_t getNumRows() const
The number of rows in the local matrix on the calling process.
Definition: Ifpack2_DenseContainer_decl.hpp:190
virtual size_t getNumRows() const
The number of rows in the local matrix on the calling process.
Definition: Ifpack2_DenseContainer_decl.hpp:420
Type traits class that says whether Teuchos::LAPACK has a valid implementation for the given ScalarTy...
Definition: Ifpack2_Details_LapackSupportsScalar.hpp:17