/usr/include/trilinos/Ifpack2_OverlappingRowMatrix_decl.hpp is in libtrilinos-ifpack2-dev 12.12.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | /*@HEADER
// ***********************************************************************
//
// Ifpack2: Tempated Object-Oriented Algebraic Preconditioner Package
// Copyright (2009) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
//
// ***********************************************************************
//@HEADER
*/
#ifndef IFPACK2_OVERLAPPINGROWMATRIX_DECL_HPP
#define IFPACK2_OVERLAPPINGROWMATRIX_DECL_HPP
#include "Ifpack2_ConfigDefs.hpp"
#include "Tpetra_RowMatrix.hpp"
#include "Tpetra_CrsMatrix_decl.hpp" // only need the declaration here
#include "Tpetra_Import.hpp"
#include "Tpetra_Map.hpp"
#include <type_traits>
namespace Ifpack2 {
/// \class OverlappingRowMatrix
/// \brief Sparse matrix (Tpetra::RowMatrix subclass) with ghost rows.
/// \tparam MatrixType Tpetra::RowMatrix specialization.
template<class MatrixType>
class OverlappingRowMatrix :
virtual public Tpetra::RowMatrix<typename MatrixType::scalar_type,
typename MatrixType::local_ordinal_type,
typename MatrixType::global_ordinal_type,
typename MatrixType::node_type> {
public:
//! \name Typedefs
//@{
typedef typename MatrixType::scalar_type scalar_type;
typedef typename MatrixType::local_ordinal_type local_ordinal_type;
typedef typename MatrixType::global_ordinal_type global_ordinal_type;
typedef typename MatrixType::node_type node_type;
typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type,
global_ordinal_type, node_type> row_matrix_type;
static_assert(std::is_same<MatrixType, row_matrix_type>::value, "Ifpack2::OverlappingRowMatrix: The template parameter MatrixType must be a Tpetra::RowMatrix specialization. Please don't use Tpetra::CrsMatrix (a subclass of Tpetra::RowMatrix) here anymore. The constructor can take either a RowMatrix or a CrsMatrix just fine.");
typedef typename row_matrix_type::mag_type mag_type;
//@}
//! \name Constructors and destructor
//@{
/// Standard constructor.
///
/// \param A [in] The input matrix. Currently this class requires
/// that A be a Tpetra::CrsMatrix instance with the same first
/// four template parameters as MatrixType, and with a default
/// fifth template parameter. Furthermore, A must have a
/// nonoverlapping row Map and must be distributed over more than
/// one MPI process.
///
/// \param overlapLevel [in] The number of levels of overlap.
OverlappingRowMatrix (const Teuchos::RCP<const row_matrix_type>& A,
const int overlapLevel);
//! Destructor
~OverlappingRowMatrix ();
//@}
//! @name Matrix query methods
//@{
//! The communicator over which the matrix is distributed.
virtual Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
//! The matrix's Node instance.
virtual Teuchos::RCP<node_type> getNode() const;
//! The Map that describes the distribution of rows over processes.
virtual Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >
getRowMap () const;
//! The Map that describes the distribution of columns over processes.
virtual Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >
getColMap () const;
/// \brief The Map that describes the domain of this matrix.
///
/// The domain is the distribution of valid input vectors of apply().
virtual Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >
getDomainMap () const;
/// \brief The Map that describes the range of this matrix.
///
/// The domain is the distribution of valid output vectors of apply().
virtual Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >
getRangeMap () const;
//! This matrix's graph.
virtual Teuchos::RCP<const Tpetra::RowGraph<local_ordinal_type, global_ordinal_type, node_type> >
getGraph () const;
//! The global number of rows in this matrix.
virtual global_size_t getGlobalNumRows () const;
//! The global number of columns in this matrix.
virtual global_size_t getGlobalNumCols () const;
//! The number of rows owned by the calling process.
virtual size_t getNodeNumRows () const;
/// \brief The number of columns owned by the calling process.
///
/// This is the number of columns needed to apply the forward
/// operator on the calling process, that is, the number of elements
/// listed in the column Map on the calling process.
virtual size_t getNodeNumCols () const;
//! The index base for global indices for this matrix.
virtual global_ordinal_type getIndexBase () const;
//! The global number of entries in this matrix.
virtual global_size_t getGlobalNumEntries () const;
//! The number of entries in this matrix owned by the calling process.
virtual size_t getNodeNumEntries () const;
/// \brief The number of entries in the given global row that are
/// owned by the calling process.
///
/// \param globalRow [in] Global index of the row.
///
/// \return Teuchos::OrdinalTraits<size_t>::invalid() if the
/// specified row (either in the input matrix or in the overlap
/// matrix) is not owned by the calling process, else the number
/// of entries in that row that are owned by the calling process.
virtual size_t getNumEntriesInGlobalRow (global_ordinal_type globalRow) const;
/// \brief The number of entries in the given local row that are
/// owned by the calling process.
///
/// \param globalRow [in] Local index of the row.
///
/// \return Teuchos::OrdinalTraits<size_t>::invalid() if the
/// specified row (either in the input matrix or in the overlap
/// matrix) is not owned by the calling process, else the number
/// of entries in that row that are owned by the calling process.
virtual size_t getNumEntriesInLocalRow (local_ordinal_type localRow) const;
//! The global number of diagonal entries.
virtual global_size_t getGlobalNumDiags () const;
//! The number of diagonal entries owned by the calling process.
virtual size_t getNodeNumDiags () const;
//! The maximum number of entries in any row on any process.
virtual size_t getGlobalMaxNumRowEntries () const;
//! The maximum number of entries in any row on the calling process.
virtual size_t getNodeMaxNumRowEntries() const;
//! Whether this matrix has a column Map.
virtual bool hasColMap() const;
//! Whether this matrix is lower triangular.
virtual bool isLowerTriangular() const;
//! Whether this matrix is upper triangular.
virtual bool isUpperTriangular() const;
//! Whether this matrix is locally indexed.
virtual bool isLocallyIndexed () const;
//! Whether this matrix is globally indexed.
virtual bool isGloballyIndexed () const;
//! \c true if fillComplete() has been called, else \c false.
virtual bool isFillComplete() const;
//! \c true if row views are supported, else \c false.
virtual bool supportsRowViews() const;
//@}
//! @name Extraction methods
//@{
//! Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage.
/*!
\param LocalRow - (In) Global row number for which indices are desired.
\param Indices - (Out) Global column indices corresponding to values.
\param Values - (Out) Matrix values.
\param NumEntries - (Out) Number of indices.
Note: A std::runtime_error exception is thrown if either \c Indices or \c Values is not large enough to hold the data associated
with row \c GlobalRow. If \c GlobalRow does not belong to this node, then \c Indices and \c Values are unchanged and \c NumIndices is
returned as Teuchos::OrdinalTraits<size_t>::invalid().
*/
virtual void
getGlobalRowCopy (global_ordinal_type GlobalRow,
const Teuchos::ArrayView<global_ordinal_type> &Indices,
const Teuchos::ArrayView<scalar_type> &Values,
size_t &NumEntries) const;
//! Extract a list of entries in a specified local row of the graph. Put into storage allocated by calling routine.
/*!
\param LocalRow - (In) Local row number for which indices are desired.
\param Indices - (Out) Local column indices corresponding to values.
\param Values - (Out) Matrix values.
\param NumIndices - (Out) Number of indices.
Note: A std::runtime_error exception is thrown if either \c Indices or \c Values is not large enough to hold the data associated
with row \c LocalRow. If \c LocalRow is not valid for this node, then \c Indices and \c Values are unchanged and \c NumIndices is
returned as Teuchos::OrdinalTraits<size_t>::invalid().
*/
virtual void
getLocalRowCopy (local_ordinal_type LocalRow,
const Teuchos::ArrayView<local_ordinal_type> &Indices,
const Teuchos::ArrayView<scalar_type> &Values,
size_t &NumEntries) const;
//! Extract a const, non-persisting view of global indices in a specified row of the matrix.
/*!
\param GlobalRow - (In) Global row number for which indices are desired.
\param Indices - (Out) Global column indices corresponding to values.
\param Values - (Out) Row values
\pre <tt>isLocallyIndexed() == false</tt>
\post <tt>indices.size() == getNumEntriesInGlobalRow(GlobalRow)</tt>
Note: If \c GlobalRow does not belong to this node, then \c indices is set to null.
*/
virtual void
getGlobalRowView (global_ordinal_type GlobalRow,
Teuchos::ArrayView<const global_ordinal_type> &indices,
Teuchos::ArrayView<const scalar_type> &values) const;
//! Extract a const, non-persisting view of local indices in a specified row of the matrix.
/*!
\param LocalRow - (In) Local row number for which indices are desired.
\param Indices - (Out) Global column indices corresponding to values.
\param Values - (Out) Row values
\pre <tt>isGloballyIndexed() == false</tt>
\post <tt>indices.size() == getNumEntriesInLocalRow(LocalRow)</tt>
Note: If \c LocalRow does not belong to this node, then \c indices is set to null.
*/
virtual void
getLocalRowView (local_ordinal_type LocalRow,
Teuchos::ArrayView<const local_ordinal_type> &indices,
Teuchos::ArrayView<const scalar_type> &values) const;
//! \brief Get a copy of the diagonal entries owned by this node, with local row indices.
/*! Returns a distributed Vector object partitioned according to this matrix's row map, containing the
the zero and non-zero diagonals owned by this node. */
virtual
void getLocalDiagCopy (Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &diag) const;
//@}
//! \name Mathematical methods
//@{
/**
* \brief Scales the RowMatrix on the left with the Vector x.
*
* This matrix will be scaled such that A(i,j) = x(i)*A(i,j)
* where i denoes the global row number of A and
* j denotes the global column number of A.
*
* \param x A vector to left scale this matrix.
*/
virtual void
leftScale (const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& x);
/**
* \brief Scales the RowMatrix on the right with the Vector x.
*
* This matrix will be scaled such that A(i,j) = x(j)*A(i,j)
* where i denoes the global row number of A and
* j denotes the global column number of A.
*
* \param x A vector to right scale this matrix.
*/
virtual void
rightScale (const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& x);
//! Returns the Frobenius norm of the matrix.
/** Computes and returns the Frobenius norm of the matrix, defined as:
\f$ \|A\|_F = \sqrt{\sum_{i,j} \|\a_{ij}\|^2} \f$
*/
virtual mag_type
getFrobeniusNorm () const;
//! \brief Computes the operator-multivector application.
/*! Loosely, performs \f$Y = \alpha \cdot A^{\textrm{mode}} \cdot X + \beta \cdot Y\f$. However, the details of operation
vary according to the values of \c alpha and \c beta. Specifically
- if <tt>beta == 0</tt>, apply() <b>must</b> overwrite \c Y, so that any values in \c Y (including NaNs) are ignored.
- if <tt>alpha == 0</tt>, apply() <b>may</b> short-circuit the operator, so that any values in \c X (including NaNs) are ignored.
This is analagous to the *Multiply* function in Ifpack, not the *Apply*
*/
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;
//! Whether this operator's apply() method can apply the adjoint (transpose).
virtual bool hasTransposeApply() const;
virtual void
importMultiVector (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> &OvX,
Tpetra::CombineMode CM = Tpetra::INSERT);
virtual void
exportMultiVector (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &OvX,
Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
Tpetra::CombineMode CM = Tpetra::ADD);
//@}
std::string description() const;
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const;
virtual Teuchos::RCP<const row_matrix_type> getUnderlyingMatrix() const;
private:
typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
typedef Tpetra::Import<local_ordinal_type, global_ordinal_type, node_type> import_type;
typedef Tpetra::Export<local_ordinal_type, global_ordinal_type, node_type> export_type;
typedef Tpetra::RowGraph<local_ordinal_type, global_ordinal_type, node_type> row_graph_type;
typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> crs_matrix_type;
typedef Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> vector_type;
//! The input matrix to the constructor.
Teuchos::RCP<const row_matrix_type> A_;
Tpetra::global_size_t NumGlobalRows_;
Tpetra::global_size_t NumGlobalNonzeros_;
size_t MaxNumEntries_;
int OverlapLevel_;
// Wrapper matrix objects
Teuchos::RCP<const map_type> RowMap_;
Teuchos::RCP<const map_type> ColMap_;
Teuchos::RCP<const import_type> Importer_;
//! The matrix containing only the overlap rows.
Teuchos::RCP<row_matrix_type> ExtMatrix_;
Teuchos::RCP<map_type> ExtMap_;
Teuchos::RCP<import_type> ExtImporter_;
//! Graph of the matrix (as returned by getGraph()).
Teuchos::RCP<const row_graph_type> graph_;
//! Used in apply(), to avoid allocation each time.
mutable Teuchos::Array<local_ordinal_type> Indices_;
//! Used in apply(), to avoid allocation each time.
mutable Teuchos::Array<scalar_type> Values_;
}; // class OverlappingRowMatrix
} // namespace Ifpack2
#endif // IFPACK2_OVERLAPPINGROWMATRIX_DECL_HPP
|