/usr/include/trilinos/Ifpack2_Diagonal_def.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 | /*@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_DIAGONAL_DEF_HPP
#define IFPACK2_DIAGONAL_DEF_HPP
#include "Ifpack2_Diagonal_decl.hpp"
#include "Tpetra_CrsMatrix.hpp"
namespace Ifpack2 {
template<class MatrixType>
Diagonal<MatrixType>::Diagonal (const Teuchos::RCP<const row_matrix_type>& A) :
matrix_ (A),
initializeTime_ (0.0),
computeTime_ (0.0),
applyTime_ (0.0),
numInitialize_ (0),
numCompute_ (0),
numApply_ (0),
isInitialized_ (false),
isComputed_ (false)
{}
template<class MatrixType>
Diagonal<MatrixType>::Diagonal (const Teuchos::RCP<const crs_matrix_type>& A) :
matrix_ (A),
initializeTime_ (0.0),
computeTime_ (0.0),
applyTime_ (0.0),
numInitialize_ (0),
numCompute_ (0),
numApply_ (0),
isInitialized_ (false),
isComputed_ (false)
{}
template<class MatrixType>
Diagonal<MatrixType>::Diagonal (const Teuchos::RCP<const vector_type>& diag) :
userInverseDiag_ (diag),
inverseDiag_ (diag),
initializeTime_ (0.0),
computeTime_ (0.0),
applyTime_ (0.0),
numInitialize_ (0),
numCompute_ (0),
numApply_ (0),
isInitialized_ (false),
isComputed_ (false)
{}
template<class MatrixType>
Diagonal<MatrixType>::~Diagonal ()
{}
template<class MatrixType>
Teuchos::RCP<const typename Diagonal<MatrixType>::map_type>
Diagonal<MatrixType>::getDomainMap () const
{
if (matrix_.is_null ()) {
if (userInverseDiag_.is_null ()) {
TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error, "Ifpack2::Diagonal::getDomainMap: "
"The input matrix A is null, and you did not provide a vector of "
"inverse diagonal entries. Please call setMatrix() with a nonnull "
"input matrix before calling this method.");
} else {
return userInverseDiag_->getMap ();
}
} else {
return matrix_->getDomainMap ();
}
}
template<class MatrixType>
Teuchos::RCP<const typename Diagonal<MatrixType>::map_type>
Diagonal<MatrixType>::getRangeMap () const
{
if (matrix_.is_null ()) {
if (userInverseDiag_.is_null ()) {
TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error, "Ifpack2::Diagonal::getRangeMap: "
"The input matrix A is null, and you did not provide a vector of "
"inverse diagonal entries. Please call setMatrix() with a nonnull "
"input matrix before calling this method.");
} else {
return userInverseDiag_->getMap ();
}
} else {
return matrix_->getRangeMap ();
}
}
template<class MatrixType>
void Diagonal<MatrixType>::
setParameters (const Teuchos::ParameterList& /*params*/)
{}
template<class MatrixType>
void Diagonal<MatrixType>::reset ()
{
inverseDiag_ = Teuchos::null;
offsets_ = offsets_type ();
isInitialized_ = false;
isComputed_ = false;
}
template<class MatrixType>
void Diagonal<MatrixType>::
setMatrix (const Teuchos::RCP<const row_matrix_type>& A)
{
if (A.getRawPtr () != matrix_.getRawPtr ()) { // it's a different matrix
reset ();
matrix_ = A;
}
}
template<class MatrixType>
void Diagonal<MatrixType>::initialize ()
{
// Either the matrix to precondition must be nonnull, or the user
// must have provided a Vector of diagonal entries.
TEUCHOS_TEST_FOR_EXCEPTION(
matrix_.is_null () && userInverseDiag_.is_null (), std::runtime_error,
"Ifpack2::Diagonal::initialize: The matrix to precondition is null, "
"and you did not provide a Tpetra::Vector of diagonal entries. "
"Please call setMatrix() with a nonnull input before calling this method.");
// If the user did provide an input matrix, then that takes
// precedence over the vector of inverse diagonal entries, if they
// provided one earlier. This is only possible if they created this
// Diagonal instance using the constructor that takes a
// Tpetra::Vector pointer, and then called setMatrix() with a
// nonnull input matrix.
if (! matrix_.is_null ()) {
// If you call initialize(), it means that you are asserting that
// the structure of the input sparse matrix may have changed.
// This means we should always recompute the diagonal offsets, if
// the input matrix is a Tpetra::CrsMatrix.
Teuchos::RCP<const crs_matrix_type> A_crs =
Teuchos::rcp_dynamic_cast<const crs_matrix_type> (matrix_);
if (A_crs.is_null ()) {
offsets_ = offsets_type (); // offsets are no longer valid
}
else {
const size_t lclNumRows = A_crs->getNodeNumRows ();
if (offsets_.dimension_0 () < lclNumRows) {
offsets_ = offsets_type (); // clear first to save memory
offsets_ = offsets_type ("offsets", lclNumRows);
}
A_crs->getCrsGraph ()->getLocalDiagOffsets (offsets_);
}
}
isInitialized_ = true;
++numInitialize_;
}
template<class MatrixType>
void Diagonal<MatrixType>::compute ()
{
// Either the matrix to precondition must be nonnull, or the user
// must have provided a Vector of diagonal entries.
TEUCHOS_TEST_FOR_EXCEPTION(
matrix_.is_null () && userInverseDiag_.is_null (), std::runtime_error,
"Ifpack2::Diagonal::compute: The matrix to precondition is null, "
"and you did not provide a Tpetra::Vector of diagonal entries. "
"Please call setMatrix() with a nonnull input before calling this method.");
if (! isInitialized_) {
initialize ();
}
// If the user did provide an input matrix, then that takes
// precedence over the vector of inverse diagonal entries, if they
// provided one earlier. This is only possible if they created this
// Diagonal instance using the constructor that takes a
// Tpetra::Vector pointer, and then called setMatrix() with a
// nonnull input matrix.
if (matrix_.is_null ()) { // accept the user's diagonal
inverseDiag_ = userInverseDiag_;
}
else {
Teuchos::RCP<vector_type> tmpVec (new vector_type (matrix_->getRowMap ()));
Teuchos::RCP<const crs_matrix_type> A_crs =
Teuchos::rcp_dynamic_cast<const crs_matrix_type> (matrix_);
if (A_crs.is_null ()) {
// Get the diagonal entries from the Tpetra::RowMatrix.
matrix_->getLocalDiagCopy (*tmpVec);
}
else {
// Get the diagonal entries from the Tpetra::CrsMatrix using the
// precomputed offsets.
A_crs->getLocalDiagCopy (*tmpVec, offsets_);
}
tmpVec->reciprocal (*tmpVec); // invert the diagonal entries
inverseDiag_ = tmpVec;
}
isComputed_ = true;
++numCompute_;
}
template<class MatrixType>
void Diagonal<MatrixType>::
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*/,
scalar_type alpha,
scalar_type beta) const
{
TEUCHOS_TEST_FOR_EXCEPTION(
! isComputed (), std::runtime_error, "Ifpack2::Diagonal::apply: You "
"must first call compute() before you may call apply(). Once you have "
"called compute(), you need not call it again unless the values in the "
"matrix have changed, or unless you have called setMatrix().");
// FIXME (mfh 12 Sep 2014) This assumes that row Map == range Map ==
// domain Map. If the preconditioner has a matrix, we should ask
// the matrix whether we need to do an Import before and/or an
// Export after.
Y.elementWiseMultiply (alpha, *inverseDiag_, X, beta);
++numApply_;
}
template <class MatrixType>
int Diagonal<MatrixType>::getNumInitialize() const {
return numInitialize_;
}
template <class MatrixType>
int Diagonal<MatrixType>::getNumCompute() const {
return numCompute_;
}
template <class MatrixType>
int Diagonal<MatrixType>::getNumApply() const {
return numApply_;
}
template <class MatrixType>
double Diagonal<MatrixType>::getInitializeTime() const {
return initializeTime_;
}
template<class MatrixType>
double Diagonal<MatrixType>::getComputeTime() const {
return computeTime_;
}
template<class MatrixType>
double Diagonal<MatrixType>::getApplyTime() const {
return applyTime_;
}
template <class MatrixType>
std::string Diagonal<MatrixType>::description () const
{
std::ostringstream out;
// Output is a valid YAML dictionary in flow style. If you don't
// like everything on a single line, you should call describe()
// instead.
out << "\"Ifpack2::Diagonal\": "
<< "{";
if (this->getObjectLabel () != "") {
out << "Label: \"" << this->getObjectLabel () << "\", ";
}
if (matrix_.is_null ()) {
out << "Matrix: null";
}
else {
out << "Matrix: not null"
<< ", Global matrix dimensions: ["
<< matrix_->getGlobalNumRows () << ", "
<< matrix_->getGlobalNumCols () << "]";
}
out << "}";
return out.str ();
}
template <class MatrixType>
void Diagonal<MatrixType>::
describe (Teuchos::FancyOStream &out,
const Teuchos::EVerbosityLevel verbLevel) const
{
using std::endl;
const Teuchos::EVerbosityLevel vl =
(verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
if (vl != Teuchos::VERB_NONE) {
Teuchos::OSTab tab0 (out);
out << "\"Ifpack2::Diagonal\":";
Teuchos::OSTab tab1 (out);
out << "Template parameter: "
<< Teuchos::TypeNameTraits<MatrixType>::name () << endl;
if (this->getObjectLabel () != "") {
out << "Label: \"" << this->getObjectLabel () << "\", ";
}
out << "Number of initialize calls: " << numInitialize_ << endl
<< "Number of compute calls: " << numCompute_ << endl
<< "Number of apply calls: " << numApply_ << endl;
}
}
} // namespace Ifpack2
#define IFPACK2_DIAGONAL_INSTANT(S,LO,GO,N) \
template class Ifpack2::Diagonal< Tpetra::RowMatrix<S, LO, GO, N> >;
#endif
|