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 
57 namespace Ifpack2 {
58 
104 template<class MatrixType,
105  class LocalScalarType,
106  const bool supportsLocalScalarType =
108 class DenseContainer {};
109 
112 template<typename MatrixType, typename LocalScalarType>
113 class DenseContainer<MatrixType, LocalScalarType, true> :
114  public Container<MatrixType> {
115 public:
117 
118 
125  typedef MatrixType matrix_type;
127  typedef LocalScalarType local_scalar_type;
128 
130  typedef typename MatrixType::scalar_type scalar_type;
132  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
134  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
136  typedef typename MatrixType::node_type node_type;
137 
138  static_assert(std::is_same<MatrixType,
139  Tpetra::RowMatrix<typename MatrixType::scalar_type,
140  typename MatrixType::local_ordinal_type,
141  typename MatrixType::global_ordinal_type,
142  typename MatrixType::node_type> >::value,
143  "Ifpack2::DenseContainer: Please use MatrixType = Tpetra::RowMatrix.");
144 
153  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
154 
156 
158 
172  DenseContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
173  const Teuchos::ArrayView<const local_ordinal_type>& localRows);
174 
176  virtual ~DenseContainer ();
177 
179 
181 
186  virtual size_t getNumRows () const {
187  return numRows_;
188  }
189 
191  virtual bool isInitialized () const {
192  return IsInitialized_;
193  }
194 
196  virtual bool isComputed () const {
197  return IsComputed_;
198  }
199 
201  virtual void setParameters(const Teuchos::ParameterList& List);
202 
204 
206 
208  virtual void initialize ();
209 
211  virtual void compute ();
212 
214  virtual void
215  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
216  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
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  virtual void
223  weightedApply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
224  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
225  const Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& D,
226  Teuchos::ETransp mode=Teuchos::NO_TRANS,
227  scalar_type alpha=Teuchos::ScalarTraits<scalar_type>::one(),
228  scalar_type beta=Teuchos::ScalarTraits<scalar_type>::zero()) const;
229 
231 
233 
237  virtual std::ostream& print (std::ostream& os) const;
238 
240 
242 
244  virtual std::string description () const;
245 
247  virtual void
248  describe (Teuchos::FancyOStream &out,
249  const Teuchos::EVerbosityLevel verbLevel =
250  Teuchos::Describable::verbLevel_default) const;
251 
253 private:
256 
258  void extract (const Teuchos::RCP<const row_matrix_type>& globalMatrix);
259 
263  void factor ();
264 
265  typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type,
266  global_ordinal_type, node_type> local_mv_type;
267 
276  void
277  applyImpl (const local_mv_type& X,
278  local_mv_type& Y,
279  Teuchos::ETransp mode,
280  const local_scalar_type alpha,
281  const local_scalar_type beta) const;
282 
284  size_t numRows_;
285 
287  Teuchos::SerialDenseMatrix<int, local_scalar_type> diagBlock_;
288 
290  Teuchos::Array<int> ipiv_;
291 
293  Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> > localMap_;
294 
296  mutable Teuchos::RCP<local_mv_type> Y_;
297 
299  mutable Teuchos::RCP<local_mv_type> X_;
300 
302  bool IsInitialized_;
303 
305  bool IsComputed_;
306 };
307 
310 template<class MatrixType, class LocalScalarType>
311 class DenseContainer<MatrixType, LocalScalarType, false> :
312  public Container<MatrixType> {
313 public:
315 
316 
323  typedef MatrixType matrix_type;
325  typedef LocalScalarType local_scalar_type;
326 
328  typedef typename MatrixType::scalar_type scalar_type;
330  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
332  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
334  typedef typename MatrixType::node_type node_type;
335 
336  static_assert(std::is_same<MatrixType,
337  Tpetra::RowMatrix<typename MatrixType::scalar_type,
338  typename MatrixType::local_ordinal_type,
339  typename MatrixType::global_ordinal_type,
340  typename MatrixType::node_type> >::value,
341  "Ifpack2::DenseContainer: Please use MatrixType = Tpetra::RowMatrix.");
342 
351  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
352 
354 
356 
370  DenseContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
371  const Teuchos::ArrayView<const local_ordinal_type>& localRows);
372 
374  virtual ~DenseContainer ();
375 
377 
379 
384  virtual size_t getNumRows () const {
385  return numRows_;
386  }
387 
389  virtual bool isInitialized () const {
390  return IsInitialized_;
391  }
392 
394  virtual bool isComputed () const {
395  return IsComputed_;
396  }
397 
399  virtual void setParameters(const Teuchos::ParameterList& List);
400 
402 
404 
406  virtual void initialize ();
407 
409  virtual void compute ();
410 
412  virtual void
413  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
414  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
415  Teuchos::ETransp mode=Teuchos::NO_TRANS,
416  scalar_type alpha=Teuchos::ScalarTraits<scalar_type>::one(),
417  scalar_type beta=Teuchos::ScalarTraits<scalar_type>::zero()) const;
418 
420  virtual void
421  weightedApply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
422  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
423  const Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& D,
424  Teuchos::ETransp mode=Teuchos::NO_TRANS,
425  scalar_type alpha=Teuchos::ScalarTraits<scalar_type>::one(),
426  scalar_type beta=Teuchos::ScalarTraits<scalar_type>::zero()) const;
427 
429 
431 
435  virtual std::ostream& print (std::ostream& os) const;
436 
438 
440 
442  virtual std::string description () const;
443 
445  virtual void
446  describe (Teuchos::FancyOStream &out,
447  const Teuchos::EVerbosityLevel verbLevel =
448  Teuchos::Describable::verbLevel_default) const;
449 
451 private:
454 
456  void extract (const Teuchos::RCP<const row_matrix_type>& globalMatrix);
457 
461  void factor ();
462 
463  typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type,
464  global_ordinal_type, node_type> local_mv_type;
465 
474  void
475  applyImpl (const local_mv_type& X,
476  local_mv_type& Y,
477  Teuchos::ETransp mode,
478  const local_scalar_type alpha,
479  const local_scalar_type beta) const;
480 
482  size_t numRows_;
483 
485  Teuchos::SerialDenseMatrix<int, local_scalar_type> diagBlock_;
486 
488  Teuchos::Array<int> ipiv_;
489 
491  Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> > localMap_;
492 
494  mutable Teuchos::RCP<local_mv_type> Y_;
495 
497  mutable Teuchos::RCP<local_mv_type> X_;
498 
500  bool IsInitialized_;
501 
503  bool IsComputed_;
504 };
505 
506 } // namespace Ifpack2
507 
508 #endif // IFPACK2_DENSECONTAINER_DECL_HPP
virtual bool isComputed() const
Whether the container has been successfully computed.
Definition: Ifpack2_DenseContainer_decl.hpp:394
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:341
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input (global) matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:332
virtual bool isInitialized() const
Whether the container has been successfully initialized.
Definition: Ifpack2_DenseContainer_decl.hpp:389
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:191
Store and solve a local dense linear problem.
Definition: Ifpack2_DenseContainer_decl.hpp:108
LocalScalarType local_scalar_type
The second template parameter of this class.
Definition: Ifpack2_DenseContainer_decl.hpp:325
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input (global) matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:134
Container< MatrixType >::row_matrix_type row_matrix_type
The (base class) type of the input matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:143
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input (global) matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:330
LocalScalarType local_scalar_type
The second template parameter of this class.
Definition: Ifpack2_DenseContainer_decl.hpp:127
MatrixType::node_type node_type
The Node type of the input (global) matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:136
MatrixType::scalar_type scalar_type
The type of entries in the input (global) matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:328
MatrixType matrix_type
The first template parameter of this class.
Definition: Ifpack2_DenseContainer_decl.hpp:125
MatrixType::scalar_type scalar_type
The type of entries in the input (global) matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:130
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input (global) matrix.
Definition: Ifpack2_DenseContainer_decl.hpp:132
virtual bool isComputed() const
Whether the container has been successfully computed.
Definition: Ifpack2_DenseContainer_decl.hpp:196
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:334
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:323
virtual size_t getNumRows() const
The number of rows in the local matrix on the calling process.
Definition: Ifpack2_DenseContainer_decl.hpp:186
virtual size_t getNumRows() const
The number of rows in the local matrix on the calling process.
Definition: Ifpack2_DenseContainer_decl.hpp:384
Type traits class that says whether Teuchos::LAPACK has a valid implementation for the given ScalarTy...
Definition: Ifpack2_Details_LapackSupportsScalar.hpp:17