/usr/include/trilinos/Ifpack_DenseContainer.h is in libtrilinos-ifpack-dev 12.10.1-3.
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 | /*@HEADER
// ***********************************************************************
//
// Ifpack: Object-Oriented Algebraic Preconditioner Package
// Copyright (2002) 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 IFPACK_DENSECONTAINER_H
#define IFPACK_DENSECONTAINER_H
#include "Ifpack_ConfigDefs.h"
#include "Ifpack_Container.h"
#include "Epetra_SerialDenseMatrix.h"
#include "Epetra_SerialDenseSolver.h"
#include "Epetra_IntSerialDenseVector.h"
class Epetra_RowMatrix;
//! Ifpack_DenseContainer: a class to define containers for dense matrices.
/*!
<P>To understand what an IFPACK container is, please refer to the documentation
of the pure virtual class Ifpack_Container. Currently, containers are
used by class Ifpack_BlockRelaxation.
<P>Using block methods, one needs to store all diagonal blocks and
to be also to apply the inverse of each diagonal block. Using
class Ifpack_DenseContainer, one can store the blocks as dense
matrices, which can be advantageous when the
blocks are small. Otherwise,
class Ifpack_SparseContainer is probably more appropriate.
<P>A typical use of a container is as follows:
\code
#include "Ifpack_DenseContainer.h"
...
// local matrix of (5,5), with two vectors for solution and rhs.
Ifpack_Container* Container = new
Ifpack_DenseContainer(5,5);
// assign local rows 1, 5, 12, 13, 16 to this container
Container(0) = 1;
Container(1) = 5;
Container(2) = 12;
Container(3) = 13;
Container(4) = 16;
// Now extract the submatrix corresponding to rows and columns:
// 1. initialize the container.
Container.Initialize();
// 2. extract matrix values from an Epetra_RowMatrix A,
// and compute LU factors of the submatrix identified by rows
// and columns 1, 5, 12, 13 and 16 using LAPACK
Container.Compute(A);
// We can set the RHS as follows:
Container.RHS(0) = 1.0;
Container.RHS(1) = 2.0;
Container.RHS(2) = 3.0;
Container.RHS(3) = 4.0;
Container.RHS(4) = 5.0;
// The linear system with the submatrix is solved as follows:
Container.ApplyInverse().
\endcode
A call to Compute() computes the LU factorization of the
linear system matrix, using LAPACK (more precisely, by calling
the corresponding routines in Epetra_SerialDenseSolver).
The default behavior is
to store the matrix factors by overwriting the linear system matrix
itself. This way, method Apply() fails, as the original matrix
does no longer exists. An alternative is to call
\c KeepNonFactoredMatrix(true), which forces Ifpack_DenseContainer to
maintain in memory a copy of the non-factored matrix.
\author Marzio Sala, SNL 9214.
\date Last update Nov-04.
*/
class Ifpack_DenseContainer : public Ifpack_Container {
public:
//@{ Constructors/Destructors
//! Default constructor
Ifpack_DenseContainer(const int NumRows_in, const int NumVectors_in = 1) :
NumRows_(NumRows_in),
NumVectors_(NumVectors_in),
KeepNonFactoredMatrix_(false),
IsInitialized_(false),
IsComputed_(false),
ComputeFlops_(0.0),
ApplyFlops_(0.0),
ApplyInverseFlops_(0.0)
{}
//! Copy constructor
Ifpack_DenseContainer(const Ifpack_DenseContainer& rhs) :
NumRows_(rhs.NumRows()),
NumVectors_(rhs.NumVectors()),
KeepNonFactoredMatrix_(rhs.KeepNonFactoredMatrix()),
IsInitialized_(rhs.IsInitialized()),
IsComputed_(rhs.IsComputed())
{
Matrix_ = rhs.Matrix();
if (KeepNonFactoredMatrix_)
NonFactoredMatrix_ = rhs.NonFactoredMatrix();
LHS_ = rhs.LHS();
RHS_ = rhs.RHS();
ID_ = rhs.ID();
}
//! Destructor.
virtual ~Ifpack_DenseContainer()
{}
//@}
//@{ Overloaded operators.
//! Operator=
Ifpack_DenseContainer& operator=(const Ifpack_DenseContainer& rhs)
{
if (&rhs == this)
return(*this);
NumRows_ = rhs.NumRows();
NumVectors_ = rhs.NumVectors();
IsComputed_ = rhs.IsComputed();
KeepNonFactoredMatrix_ = rhs.KeepNonFactoredMatrix();
Matrix_ = rhs.Matrix();
if (KeepNonFactoredMatrix_)
NonFactoredMatrix_ = rhs.NonFactoredMatrix();
LHS_ = rhs.LHS();
RHS_ = rhs.RHS();
ID_ = rhs.ID();
return(*this);
}
//@}
//@{ Get/Set methods.
//! Returns the number of rows of the matrix and LHS/RHS.
virtual int NumRows() const;
//! Returns the number of vectors in LHS/RHS.
virtual int NumVectors() const
{
return(NumVectors_);
}
//! Sets the number of vectors for LHS/RHS.
virtual int SetNumVectors(const int NumVectors_in)
{
if (NumVectors_ == NumVectors_in)
return(0);
NumVectors_ = NumVectors_in;
IFPACK_CHK_ERR(RHS_.Reshape(NumRows_,NumVectors_));
IFPACK_CHK_ERR(LHS_.Reshape(NumRows_,NumVectors_));
// zero out vector elements
for (int i = 0 ; i < NumRows_ ; ++i)
for (int j = 0 ; j < NumVectors_ ; ++j) {
LHS_(i,j) = 0.0;
RHS_(i,j) = 0.0;
}
if (NumRows_!=0)
{
IFPACK_CHK_ERR(Solver_.SetVectors(LHS_,RHS_));
}
return(0);
}
//! Returns the i-th component of the vector Vector of LHS.
virtual double& LHS(const int i, const int Vector = 0);
//! Returns the i-th component of the vector Vector of RHS.
virtual double& RHS(const int i, const int Vector = 0);
//! Returns the ID associated to local row i.
/*!
* The set of (local) rows assigned to this container is defined
* by calling ID(i) = j, where i (from 0 to NumRows()) indicates
* the container-row, and j indicates the local row in the calling
* process.
*
* This is usually used to recorder the local row ID (on calling process)
* of the i-th row in the container.
*/
virtual int& ID(const int i);
//! Set the matrix element (row,col) to \c value.
virtual int SetMatrixElement(const int row, const int col,
const double value);
//! Sets all necessary parameters.
virtual int SetParameters(Teuchos::ParameterList& List)
{
return(0);
}
//! Returns \c true is the container has been successfully initialized.
virtual bool IsInitialized() const
{
return(IsInitialized_);
}
//! Returns \c true is the container has been successfully computed.
virtual bool IsComputed() const
{
return(IsComputed_);
}
//! Returns the label of \e this container.
virtual const char* Label() const
{
return(Label_.c_str());
}
//! If \c flag is \c true, keeps a copy of the non-factored matrix.
virtual int SetKeepNonFactoredMatrix(const bool flag)
{
KeepNonFactoredMatrix_ = flag;
return(0);
}
//! Returns KeepNonFactoredMatrix_.
virtual bool KeepNonFactoredMatrix() const
{
return(KeepNonFactoredMatrix_);
}
//! Returns the dense vector containing the LHS.
virtual const Epetra_SerialDenseMatrix& LHS() const
{
return(LHS_);
}
//! Returns the dense vector containing the RHS.
virtual const Epetra_SerialDenseMatrix& RHS() const
{
return(RHS_);
}
//! Returns the dense matrix or its factors.
virtual const Epetra_SerialDenseMatrix& Matrix() const
{
return(Matrix_);
}
//! Returns the non-factored dense matrix (only if stored).
virtual const Epetra_SerialDenseMatrix& NonFactoredMatrix() const
{
return(NonFactoredMatrix_);
}
//! Returns the integer dense vector of IDs.
virtual const Epetra_IntSerialDenseVector& ID() const
{
return(ID_);
}
//@}
//@{ Mathematical methods.
//! Initialize the container.
virtual int Initialize();
//! Finalizes the linear system matrix and prepares for the application of the inverse.
virtual int Compute(const Epetra_RowMatrix& Matrix_in);
//! Apply the matrix to RHS, results are stored in LHS.
virtual int Apply();
//! Apply the inverse of the matrix to RHS, results are stored in LHS.
virtual int ApplyInverse();
//@}
virtual double InitializeFlops() const
{
return(0.0);
}
virtual double ComputeFlops() const
{
return(ComputeFlops_);
}
virtual double ApplyFlops() const
{
return(ApplyFlops_);
}
virtual double ApplyInverseFlops() const
{
return(ApplyInverseFlops_);
}
//! Prints basic information on iostream. This function is used by operator<<.
virtual std::ostream& Print(std::ostream& os) const;
private:
//! Extract the submatrices identified by the ID set int ID().
virtual int Extract(const Epetra_RowMatrix& Matrix_in);
//! Number of rows in the container.
int NumRows_;
//! Number of vectors in the container.
int NumVectors_;
//! Dense matrix, that contains the non-factored matrix.
Epetra_SerialDenseMatrix NonFactoredMatrix_;
//! Dense matrix.
Epetra_SerialDenseMatrix Matrix_;
//! Dense vector representing the LHS.
Epetra_SerialDenseMatrix LHS_;
//! Dense vector representing the RHS.
Epetra_SerialDenseMatrix RHS_;
//! Dense solver (solution will be get using LAPACK).
Epetra_SerialDenseSolver Solver_;
//! Sets of local rows.
Epetra_IntSerialDenseVector ID_;
//! If \c true, keeps a copy of the non-factored matrix.
bool KeepNonFactoredMatrix_;
//! If \c true, the container has been successfully initialized.
bool IsInitialized_;
//! If \c true, the container has been successfully computed.
bool IsComputed_;
//! Label for \c this object
std::string Label_;
//! Flops in Compute().
double ComputeFlops_;
//! Flops in Apply().
double ApplyFlops_;
//! Flops in ApplyInverse().
double ApplyInverseFlops_;
};
#endif
|