Ifpack2 Templated Preconditioning Package Version 1.0
Ifpack2_LocalFilter_decl.hpp
1/*@HEADER
2// ***********************************************************************
3//
4// Ifpack2: Templated 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_LOCALFILTER_DECL_HPP
44#define IFPACK2_LOCALFILTER_DECL_HPP
45
46#include "Ifpack2_ConfigDefs.hpp"
47#include "Ifpack2_Details_RowMatrix.hpp"
48#include <type_traits>
49#include <vector>
50
51
52namespace Ifpack2 {
53
159template<class MatrixType>
161 virtual public Ifpack2::Details::RowMatrix<MatrixType>,
162 virtual public Teuchos::Describable
163{
164private:
165 // Tpetra needs C++11 now because Kokkos needs C++11 now.
166 // Thus, Ifpack2 needs C++11.
167 static_assert (std::is_same<
168 MatrixType,
169 Tpetra::RowMatrix<
170 typename MatrixType::scalar_type,
171 typename MatrixType::local_ordinal_type,
172 typename MatrixType::global_ordinal_type,
173 typename MatrixType::node_type> >::value,
174 "Ifpack2::LocalFilter: MatrixType must be a Tpetra::RowMatrix specialization.");
175
176public:
178
179
181 typedef typename MatrixType::scalar_type scalar_type;
182
184 typedef typename MatrixType::local_ordinal_type local_ordinal_type;
185
187 typedef typename MatrixType::global_ordinal_type global_ordinal_type;
188
190 typedef typename MatrixType::node_type node_type;
191
192
193 typedef typename MatrixType::global_inds_host_view_type global_inds_host_view_type;
194 typedef typename MatrixType::local_inds_host_view_type local_inds_host_view_type;
195 typedef typename MatrixType::values_host_view_type values_host_view_type;
196
197 typedef typename MatrixType::nonconst_global_inds_host_view_type nonconst_global_inds_host_view_type;
198 typedef typename MatrixType::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
199 typedef typename MatrixType::nonconst_values_host_view_type nonconst_values_host_view_type;
200
201
203 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
204
205
206
208 typedef Tpetra::RowMatrix<scalar_type,
211 node_type> row_matrix_type;
212
214 typedef Tpetra::Map<local_ordinal_type,
216 node_type> map_type;
217
218 typedef typename row_matrix_type::mag_type mag_type;
219
221
223
225 virtual std::string description () const;
226
228 virtual void
229 describe (Teuchos::FancyOStream &out,
230 const Teuchos::EVerbosityLevel verbLevel =
231 Teuchos::Describable::verbLevel_default) const;
232
234
236
242 explicit LocalFilter (const Teuchos::RCP<const row_matrix_type>& A);
243
245 virtual ~LocalFilter();
246
248
250
252 virtual Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
253
254
256 virtual Teuchos::RCP<const map_type> getRowMap() const;
257
259 virtual Teuchos::RCP<const map_type> getColMap() const;
260
262 virtual Teuchos::RCP<const map_type> getDomainMap() const;
263
265 virtual Teuchos::RCP<const map_type> getRangeMap() const;
266
268 virtual Teuchos::RCP<const Tpetra::RowGraph<local_ordinal_type,global_ordinal_type,node_type> >
269 getGraph () const;
270
272 virtual global_size_t getGlobalNumRows() const;
273
275 virtual global_size_t getGlobalNumCols() const;
276
278 virtual size_t getNodeNumRows() const;
279
281 virtual size_t getNodeNumCols() const;
282
284 virtual global_ordinal_type getIndexBase() const;
285
287 virtual global_size_t getGlobalNumEntries() const;
288
290 virtual size_t getNodeNumEntries() const;
291
297 virtual size_t getNumEntriesInGlobalRow (global_ordinal_type globalRow) const;
298
304 virtual size_t getNumEntriesInLocalRow (local_ordinal_type localRow) const;
305
307 virtual size_t getGlobalMaxNumRowEntries() const;
308
310 virtual size_t getNodeMaxNumRowEntries() const;
311
313 virtual bool hasColMap() const;
314
316 virtual bool isLocallyIndexed() const;
317
319 virtual bool isGloballyIndexed() const;
320
322 virtual bool isFillComplete() const;
323
325 virtual bool supportsRowViews() const;
326
328
330
344 virtual void
345 getGlobalRowCopy (global_ordinal_type GlobalRow,
346 nonconst_global_inds_host_view_type &Indices,
347 nonconst_values_host_view_type &Values,
348 size_t& NumEntries) const;
349#ifdef TPETRA_ENABLE_DEPRECATED_CODE
350 virtual void
351 getGlobalRowCopy (global_ordinal_type GlobalRow,
352 const Teuchos::ArrayView<global_ordinal_type> &Indices,
353 const Teuchos::ArrayView<scalar_type> &Values,
354 size_t &NumEntries) const;
355#endif
356
370 virtual void
371 getLocalRowCopy (local_ordinal_type LocalRow,
372 nonconst_local_inds_host_view_type &Indices,
373 nonconst_values_host_view_type &Values,
374 size_t& NumEntries) const;
375#ifdef TPETRA_ENABLE_DEPRECATED_CODE
376
377 virtual void
378 getLocalRowCopy (local_ordinal_type LocalRow,
379 const Teuchos::ArrayView<local_ordinal_type> &Indices,
380 const Teuchos::ArrayView<scalar_type> &Values,
381 size_t &NumEntries) const ;
382#endif
384
394 virtual void
395 getGlobalRowView (global_ordinal_type GlobalRow,
396 global_inds_host_view_type &indices,
397 values_host_view_type &values) const;
398#ifdef TPETRA_ENABLE_DEPRECATED_CODE
399 virtual void
400 getGlobalRowView (global_ordinal_type GlobalRow,
401 Teuchos::ArrayView<const global_ordinal_type> &indices,
402 Teuchos::ArrayView<const scalar_type> &values) const;
403#endif
404
406
416 virtual void
417 getLocalRowView (local_ordinal_type LocalRow,
418 local_inds_host_view_type & indices,
419 values_host_view_type & values) const;
420#ifdef TPETRA_ENABLE_DEPRECATED_CODE
421 virtual void
422 getLocalRowView (local_ordinal_type LocalRow,
423 Teuchos::ArrayView<const local_ordinal_type> &indices,
424 Teuchos::ArrayView<const scalar_type> &values) const;
425#endif
432 virtual void
433 getLocalDiagCopy (Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> &diag) const;
434
436
438
448 virtual void leftScale(const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& x);
449
459 virtual void rightScale(const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& x);
460
469 virtual mag_type getFrobeniusNorm() const;
470
477 virtual void
478 apply (const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> &X,
479 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> &Y,
480 Teuchos::ETransp mode = Teuchos::NO_TRANS,
481 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
482 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
483
485 virtual bool hasTransposeApply() const;
486
488 virtual Teuchos::RCP<const row_matrix_type> getUnderlyingMatrix() const;
489
491private:
493 typedef Tpetra::RowGraph<local_ordinal_type,
495 node_type> row_graph_type;
497 void
498 applyNonAliased (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
499 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &Y,
500 Teuchos::ETransp mode,
501 scalar_type alpha,
502 scalar_type beta) const;
503
516 static bool
517 mapPairIsFitted (const map_type& map1, const map_type& map2);
518
522 // If both pairs of Maps of the original matrix A are fitted on this
523 // process, then this process can use a fast "view" implementation.
524 static bool
525 mapPairsAreFitted (const row_matrix_type& A);
526
528 Teuchos::RCP<const row_matrix_type> A_;
529
531 Teuchos::RCP<const map_type> localRowMap_;
532
534 Teuchos::RCP<const map_type> localDomainMap_;
535
537 Teuchos::RCP<const map_type> localRangeMap_;
538
540 size_t NumNonzeros_;
542 size_t MaxNumEntries_;
544 size_t MaxNumEntriesA_;
546 std::vector<size_t> NumEntries_;
547
549 mutable nonconst_local_inds_host_view_type localIndices_;
550 mutable nonconst_local_inds_host_view_type localIndicesForGlobalCopy_;
552 mutable nonconst_values_host_view_type Values_;
553
554};// class LocalFilter
555
556}// namespace Ifpack2
557
558#endif /* IFPACK2_LOCALFILTER_DECL_HPP */
All Ifpack2 implementations of Tpetra::RowMatrix must inherit from this class.
Definition: Ifpack2_Details_RowMatrix.hpp:67
Access only local rows and columns of a sparse matrix.
Definition: Ifpack2_LocalFilter_decl.hpp:163
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object to the given output stream.
Definition: Ifpack2_LocalFilter_def.hpp:941
virtual Teuchos::RCP< const Tpetra::RowGraph< local_ordinal_type, global_ordinal_type, node_type > > getGraph() const
The (locally filtered) matrix's graph.
Definition: Ifpack2_LocalFilter_def.hpp:285
virtual Teuchos::RCP< const map_type > getDomainMap() const
Returns the Map that describes the domain distribution in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:265
virtual size_t getGlobalMaxNumRowEntries() const
The maximum number of entries across all rows/columns on all processes.
Definition: Ifpack2_LocalFilter_def.hpp:387
virtual void leftScale(const Tpetra::Vector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &x)
Scales the RowMatrix on the left with the Vector x.
Definition: Ifpack2_LocalFilter_def.hpp:677
virtual void getGlobalRowCopy(global_ordinal_type GlobalRow, nonconst_global_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const
Get the entries in the given row, using global indices.
Definition: Ifpack2_LocalFilter_def.hpp:431
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
Type of the Tpetra::RowMatrix specialization that this class uses.
Definition: Ifpack2_LocalFilter_decl.hpp:211
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_LocalFilter_decl.hpp:203
virtual bool isGloballyIndexed() const
Whether the underlying sparse matrix is globally (opposite of locally) indexed.
Definition: Ifpack2_LocalFilter_def.hpp:415
virtual Teuchos::RCP< const row_matrix_type > getUnderlyingMatrix() const
Return matrix that LocalFilter was built on.
Definition: Ifpack2_LocalFilter_def.hpp:981
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_LocalFilter_decl.hpp:181
virtual Teuchos::RCP< const map_type > getRangeMap() const
Returns the Map that describes the range distribution in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:275
virtual mag_type getFrobeniusNorm() const
The Frobenius norm of the (locally filtered) matrix.
Definition: Ifpack2_LocalFilter_def.hpp:890
virtual size_t getNumEntriesInGlobalRow(global_ordinal_type globalRow) const
The current number of entries on this node in the specified global row.
Definition: Ifpack2_LocalFilter_def.hpp:347
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_LocalFilter_decl.hpp:190
virtual global_size_t getGlobalNumCols() const
The number of global columns in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:302
virtual bool hasColMap() const
Whether this matrix has a well-defined column Map.
Definition: Ifpack2_LocalFilter_def.hpp:401
virtual void getGlobalRowView(global_ordinal_type GlobalRow, global_inds_host_view_type &indices, values_host_view_type &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
Definition: Ifpack2_LocalFilter_def.hpp:612
virtual size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:338
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_LocalFilter_decl.hpp:187
virtual bool isFillComplete() const
Returns true if fillComplete() has been called.
Definition: Ifpack2_LocalFilter_def.hpp:422
virtual bool isLocallyIndexed() const
Whether the underlying sparse matrix is locally (opposite of globally) indexed.
Definition: Ifpack2_LocalFilter_def.hpp:408
virtual Teuchos::RCP< const map_type > getColMap() const
Returns the Map that describes the column distribution in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:255
virtual bool hasTransposeApply() const
Whether this operator supports applying the transpose or conjugate transpose.
Definition: Ifpack2_LocalFilter_def.hpp:874
virtual size_t getNodeMaxNumRowEntries() const
The maximum number of entries across all rows/columns on this process.
Definition: Ifpack2_LocalFilter_def.hpp:394
virtual void getLocalDiagCopy(Tpetra::Vector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &diag) const
Get the diagonal entries of the (locally filtered) matrix.
Definition: Ifpack2_LocalFilter_def.hpp:662
virtual size_t getNodeNumCols() const
The number of columns in the (locally filtered) matrix.
Definition: Ifpack2_LocalFilter_def.hpp:316
LocalFilter(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition: Ifpack2_LocalFilter_def.hpp:88
virtual global_ordinal_type getIndexBase() const
Returns the index base for global indices for this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:324
virtual bool supportsRowViews() const
Returns true if RowViews are supported.
Definition: Ifpack2_LocalFilter_def.hpp:881
virtual std::string description() const
A one-line description of this object.
Definition: Ifpack2_LocalFilter_def.hpp:921
virtual global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:331
virtual ~LocalFilter()
Destructor.
Definition: Ifpack2_LocalFilter_def.hpp:227
virtual void apply(const Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &X, Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, scalar_type alpha=Teuchos::ScalarTraits< scalar_type >::one(), scalar_type beta=Teuchos::ScalarTraits< scalar_type >::zero()) const
Compute Y = beta*Y + alpha*A_local*X.
Definition: Ifpack2_LocalFilter_def.hpp:697
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_LocalFilter_decl.hpp:184
virtual void rightScale(const Tpetra::Vector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &x)
Scales the RowMatrix on the right with the Vector x.
Definition: Ifpack2_LocalFilter_def.hpp:687
virtual void getLocalRowCopy(local_ordinal_type LocalRow, nonconst_local_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const
Get the entries in the given row, using local indices.
Definition: Ifpack2_LocalFilter_def.hpp:490
virtual size_t getNumEntriesInLocalRow(local_ordinal_type localRow) const
The current number of entries on this node in the specified local row.
Definition: Ifpack2_LocalFilter_def.hpp:366
virtual void getLocalRowView(local_ordinal_type LocalRow, local_inds_host_view_type &indices, values_host_view_type &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
Definition: Ifpack2_LocalFilter_def.hpp:636
virtual size_t getNodeNumRows() const
The number of rows owned on the calling process.
Definition: Ifpack2_LocalFilter_def.hpp:309
virtual global_size_t getGlobalNumRows() const
The number of global rows in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:295
Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > map_type
Type of the Tpetra::Map specialization that this class uses.
Definition: Ifpack2_LocalFilter_decl.hpp:216
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the communicator.
Definition: Ifpack2_LocalFilter_def.hpp:233
virtual Teuchos::RCP< const map_type > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
Definition: Ifpack2_LocalFilter_def.hpp:245
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:73