Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_TriDiContainer_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_TRIDICONTAINER_DECL_HPP
43 #define IFPACK2_TRIDICONTAINER_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_SerialTriDiMatrix.hpp"
56 #include <type_traits>
57 
58 namespace Ifpack2 {
59 
105 template<class MatrixType,
106  class LocalScalarType,
107  const bool supportsLocalScalarType =
109 class TriDiContainer {};
110 
113 template<class MatrixType,
114  class LocalScalarType>
115 class TriDiContainer<MatrixType, LocalScalarType, true> :
116  public Container<MatrixType> {
117 public:
119 
120 
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, Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> >::value,
140  "Ifpack2::TriDiContainer: MatrixType must be a Tpetra::RowMatrix specialization.");
141 
150  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
151 
153 
155 
169  TriDiContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
170  const Teuchos::ArrayView<const local_ordinal_type>& localRows);
171 
173  virtual ~TriDiContainer ();
174 
176 
178 
183  virtual size_t getNumRows() const;
184 
186  virtual bool isInitialized() const;
187 
189  virtual bool isComputed() const;
190 
192  virtual void setParameters(const Teuchos::ParameterList& List);
193 
195 
197 
199  virtual void initialize ();
200 
202  virtual void compute ();
203 
205  virtual void
206  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
207  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
208  Teuchos::ETransp mode=Teuchos::NO_TRANS,
209  scalar_type alpha=Teuchos::ScalarTraits<scalar_type>::one(),
210  scalar_type beta=Teuchos::ScalarTraits<scalar_type>::zero()) const;
211 
213  virtual void
214  weightedApply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
215  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
216  const Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& D,
217  Teuchos::ETransp mode=Teuchos::NO_TRANS,
218  scalar_type alpha=Teuchos::ScalarTraits<scalar_type>::one(),
219  scalar_type beta=Teuchos::ScalarTraits<scalar_type>::zero()) const;
220 
222 
224 
228  virtual std::ostream& print (std::ostream& os) const;
229 
231 
233 
235  virtual std::string description () const;
236 
238  virtual void
239  describe (Teuchos::FancyOStream &out,
240  const Teuchos::EVerbosityLevel verbLevel =
241  Teuchos::Describable::verbLevel_default) const;
242 
244 private:
247 
249  void extract (const Teuchos::RCP<const row_matrix_type>& globalMatrix);
250 
254  void factor ();
255 
256  typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type,
257  global_ordinal_type, node_type> local_mv_type;
258 
267  void
268  applyImpl (const local_mv_type& X,
269  local_mv_type& Y,
270  Teuchos::ETransp mode,
271  const local_scalar_type alpha,
272  const local_scalar_type beta) const;
273 
275  size_t numRows_;
276 
278  Teuchos::SerialTriDiMatrix<int, local_scalar_type> diagBlock_;
279 
281  Teuchos::Array<int> ipiv_;
282 
284  Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> > localMap_;
285 
287  mutable Teuchos::RCP<local_mv_type> Y_;
288 
290  mutable Teuchos::RCP<local_mv_type> X_;
291 
293  bool IsInitialized_;
294 
296  bool IsComputed_;
297 };
298 
302 template<class MatrixType,
303  class LocalScalarType>
304 class TriDiContainer<MatrixType, LocalScalarType, false> :
305  public Container<MatrixType> {
306 public:
308 
309 
315  typedef MatrixType matrix_type;
317  typedef LocalScalarType local_scalar_type;
318 
320  typedef typename MatrixType::scalar_type scalar_type;
322  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
324  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
326  typedef typename MatrixType::node_type node_type;
327 
328  static_assert (std::is_same<MatrixType, Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> >::value,
329  "Ifpack2::TriDiContainer: MatrixType must be a Tpetra::RowMatrix specialization.");
330 
339  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
340 
342 
344 
358  TriDiContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
359  const Teuchos::ArrayView<const local_ordinal_type>& localRows);
360 
362  virtual ~TriDiContainer ();
363 
365 
367 
372  virtual size_t getNumRows() const;
373 
375  virtual bool isInitialized() const;
376 
378  virtual bool isComputed() const;
379 
381  virtual void setParameters(const Teuchos::ParameterList& List);
382 
384 
386 
388  virtual void initialize ();
389 
391  virtual void compute ();
392 
394  virtual void
395  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
396  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
397  Teuchos::ETransp mode=Teuchos::NO_TRANS,
398  scalar_type alpha=Teuchos::ScalarTraits<scalar_type>::one(),
399  scalar_type beta=Teuchos::ScalarTraits<scalar_type>::zero()) const;
400 
402  virtual void
403  weightedApply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
404  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
405  const Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& D,
406  Teuchos::ETransp mode=Teuchos::NO_TRANS,
407  scalar_type alpha=Teuchos::ScalarTraits<scalar_type>::one(),
408  scalar_type beta=Teuchos::ScalarTraits<scalar_type>::zero()) const;
409 
411 
413 
417  virtual std::ostream& print (std::ostream& os) const;
418 
420 
422 
424  virtual std::string description () const;
425 
427  virtual void
428  describe (Teuchos::FancyOStream &out,
429  const Teuchos::EVerbosityLevel verbLevel =
430  Teuchos::Describable::verbLevel_default) const;
431 
433 private:
436 
438  void extract (const Teuchos::RCP<const row_matrix_type>& globalMatrix);
439 
443  void factor ();
444 
445  typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type,
446  global_ordinal_type, node_type> local_mv_type;
447 
456  void
457  applyImpl (const local_mv_type& X,
458  local_mv_type& Y,
459  Teuchos::ETransp mode,
460  const local_scalar_type alpha,
461  const local_scalar_type beta) const;
462 
464  size_t numRows_;
465 
467  Teuchos::SerialTriDiMatrix<int, local_scalar_type> diagBlock_;
468 
470  Teuchos::Array<int> ipiv_;
471 
473  Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> > localMap_;
474 
476  mutable Teuchos::RCP<local_mv_type> Y_;
477 
479  mutable Teuchos::RCP<local_mv_type> X_;
480 
482  bool IsInitialized_;
483 
485  bool IsComputed_;
486 };
487 
488 }// namespace Ifpack2
489 
490 #endif // IFPACK2_TRIDICONTAINER_DECL_HPP
MatrixType::node_type node_type
The Node type of the input (global) matrix.
Definition: Ifpack2_TriDiContainer_decl.hpp:137
LocalScalarType local_scalar_type
The second template parameter of this class.
Definition: Ifpack2_TriDiContainer_decl.hpp:317
Store and solve a local TriDi linear problem.
Definition: Ifpack2_TriDiContainer_decl.hpp:109
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input (global) matrix.
Definition: Ifpack2_TriDiContainer_decl.hpp:322
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input (global) matrix.
Definition: Ifpack2_TriDiContainer_decl.hpp:324
Ifpack2::Container class declaration.
LocalScalarType local_scalar_type
The second template parameter of this class.
Definition: Ifpack2_TriDiContainer_decl.hpp:128
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input (global) matrix.
Definition: Ifpack2_TriDiContainer_decl.hpp:133
MatrixType matrix_type
The first template parameter of this class.
Definition: Ifpack2_TriDiContainer_decl.hpp:315
MatrixType::scalar_type scalar_type
The type of entries in the input (global) matrix.
Definition: Ifpack2_TriDiContainer_decl.hpp:131
Declaration and definition of the Ifpack2::Details::MultiVectorLocalGatherScatter class...
MatrixType::node_type node_type
The Node type of the input (global) matrix.
Definition: Ifpack2_TriDiContainer_decl.hpp:326
MatrixType matrix_type
The first template parameter of this class.
Definition: Ifpack2_TriDiContainer_decl.hpp:126
Container< MatrixType >::row_matrix_type row_matrix_type
The (base class) type of the input matrix.
Definition: Ifpack2_TriDiContainer_decl.hpp:140
Interface for creating and solving a local linear problem.
Definition: Ifpack2_Container.hpp:103
MatrixType::scalar_type scalar_type
The type of entries in the input (global) matrix.
Definition: Ifpack2_TriDiContainer_decl.hpp:320
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input (global) matrix.
Definition: Ifpack2_TriDiContainer_decl.hpp:135
Type traits class that says whether Teuchos::LAPACK has a valid implementation for the given ScalarTy...
Definition: Ifpack2_Details_LapackSupportsScalar.hpp:17
Container< MatrixType >::row_matrix_type row_matrix_type
The (base class) type of the input matrix.
Definition: Ifpack2_TriDiContainer_decl.hpp:329