/usr/include/deal.II/lac/petsc_sparse_matrix.h is in libdeal.ii-dev 6.3.1-1.1.
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 | //---------------------------------------------------------------------------
// $Id: petsc_sparse_matrix.h 20107 2009-11-13 15:40:05Z kronbichler $
// Version: $Name$
//
// Copyright (C) 2004, 2005, 2006, 2007, 2009 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
// to the file deal.II/doc/license.html for the text and
// further information on this license.
//
//---------------------------------------------------------------------------
#ifndef __deal2__petsc_sparse_matrix_h
#define __deal2__petsc_sparse_matrix_h
#include <base/config.h>
#ifdef DEAL_II_USE_PETSC
# include <lac/exceptions.h>
# include <lac/petsc_matrix_base.h>
# include <vector>
DEAL_II_NAMESPACE_OPEN
// forward declaration
template <typename MatrixType> class BlockMatrixBase;
namespace PETScWrappers
{
/**
* Implementation of a sequential sparse matrix class based on PETSC. All the
* functionality is actually in the base class, except for the calls to
* generate a sequential sparse matrix. This is possible since PETSc only works
* on an abstract matrix type and internally distributes to functions that do
* the actual work depending on the actual matrix type (much like using
* virtual functions). Only the functions creating a matrix of specific type
* differ, and are implemented in this particular class.
*
* @ingroup PETScWrappers
* @ingroup Matrix1
* @author Wolfgang Bangerth, 2004
*/
class SparseMatrix : public MatrixBase
{
public:
/**
* A structure that describes some of
* the traits of this class in terms of
* its run-time behavior. Some other
* classes (such as the block matrix
* classes) that take one or other of
* the matrix classes as its template
* parameters can tune their behavior
* based on the variables in this
* class.
*/
struct Traits
{
/**
* It is safe to elide additions of
* zeros to individual elements of
* this matrix.
*/
static const bool zero_addition_can_be_elided = true;
};
/**
* Default constructor. Create an empty
* matrix.
*/
SparseMatrix ();
/**
* Create a sparse matrix of dimensions
* @p m times @p n, with an
* initial guess of
* @p n_nonzero_per_row nonzero
* elements per row. PETSc is able to
* cope with the situation that more
* than this number of elements is
* later allocated for a row, but this
* involves copying data, and is thus
* expensive.
*
* The @p is_symmetric flag determines
* whether we should tell PETSc that
* the matrix is going to be symmetric
* (as indicated by the call
* <tt>MatSetOption(mat,
* MAT_SYMMETRIC)</tt>. Note that the
* PETSc documentation states that one
* cannot form an ILU decomposition of
* a matrix for which this flag has
* been set to @p true, only an
* ICC. The default value of this flag
* is @p false.
*/
SparseMatrix (const unsigned int m,
const unsigned int n,
const unsigned int n_nonzero_per_row,
const bool is_symmetric = false);
/**
* Initialize a rectangular matrix with
* @p m rows and @p n
* columns. The maximal number of
* nonzero entries for each row
* separately is given by the
* @p row_lengths array.
*
* Just as for the other constructors:
* PETSc is able to cope with the
* situation that more than this number
* of elements is later allocated for a
* row, but this involves copying data,
* and is thus expensive.
*
* The @p is_symmetric flag determines
* whether we should tell PETSc that
* the matrix is going to be symmetric
* (as indicated by the call
* <tt>MatSetOption(mat,
* MAT_SYMMETRIC)</tt>. Note that the
* PETSc documentation states that one
* cannot form an ILU decomposition of
* a matrix for which this flag has
* been set to @p true, only an
* ICC. The default value of this flag
* is @p false.
*/
SparseMatrix (const unsigned int m,
const unsigned int n,
const std::vector<unsigned int> &row_lengths,
const bool is_symmetric = false);
/**
* Initialize a sparse matrix using the
* given sparsity pattern.
*
* Note that PETSc can be very slow
* if you do not provide it with a
* good estimate of the lengths of
* rows. Using the present function
* is a very efficient way to do
* this, as it uses the exact number
* of nonzero entries for each row of
* the matrix by using the given
* sparsity pattern argument. If the
* @p preset_nonzero_locations flag
* is @p true, this function in
* addition not only sets the correct
* row sizes up front, but also
* pre-allocated the correct nonzero
* entries in the matrix.
*
* PETsc allows to later add
* additional nonzero entries to a
* matrix, by simply writing to these
* elements. However, this will then
* lead to additional memory
* allocations which are very
* inefficient and will greatly slow
* down your program. It is therefore
* significantly more efficient to
* get memory allocation right from
* the start.
*/
template <typename SparsityType>
SparseMatrix (const SparsityType &sparsity_pattern,
const bool preset_nonzero_locations = true);
/**
* This operator assigns a scalar to
* a matrix. Since this does usually
* not make much sense (should we set
* all matrix entries to this value?
* Only the nonzero entries of the
* sparsity pattern?), this operation
* is only allowed if the actual
* value to be assigned is zero. This
* operator only exists to allow for
* the obvious notation
* <tt>matrix=0</tt>, which sets all
* elements of the matrix to zero,
* but keep the sparsity pattern
* previously used.
*/
SparseMatrix & operator = (const double d);
/**
* Throw away the present matrix and
* generate one that has the same
* properties as if it were created by
* the constructor of this class with
* the same argument list as the
* present function.
*/
void reinit (const unsigned int m,
const unsigned int n,
const unsigned int n_nonzero_per_row,
const bool is_symmetric = false);
/**
* Throw away the present matrix and
* generate one that has the same
* properties as if it were created by
* the constructor of this class with
* the same argument list as the
* present function.
*/
void reinit (const unsigned int m,
const unsigned int n,
const std::vector<unsigned int> &row_lengths,
const bool is_symmetric = false);
/**
* Initialize a sparse matrix using the
* given sparsity pattern.
*
* Note that PETSc can be very slow
* if you do not provide it with a
* good estimate of the lengths of
* rows. Using the present function
* is a very efficient way to do
* this, as it uses the exact number
* of nonzero entries for each row of
* the matrix by using the given
* sparsity pattern argument. If the
* @p preset_nonzero_locations flag
* is @p true, this function in
* addition not only sets the correct
* row sizes up front, but also
* pre-allocated the correct nonzero
* entries in the matrix.
*
* PETsc allows to later add
* additional nonzero entries to a
* matrix, by simply writing to these
* elements. However, this will then
* lead to additional memory
* allocations which are very
* inefficient and will greatly slow
* down your program. It is therefore
* significantly more efficient to
* get memory allocation right from
* the start.
*
* Despite the fact that it would
* seem to be an obvious win, setting
* the @p preset_nonzero_locations
* flag to @p true doesn't seem to
* accelerate program. Rather on the
* contrary, it seems to be able to
* slow down entire programs
* somewhat. This is suprising, since
* we can use efficient function
* calls into PETSc that allow to
* create multiple entries at once;
* nevertheless, given the fact that
* it is inefficient, the respective
* flag has a default value equal to
* @p false.
*/
template <typename SparsityType>
void reinit (const SparsityType &sparsity_pattern,
const bool preset_nonzero_locations = true);
/**
* Return a reference to the MPI
* communicator object in use with this
* matrix. Since this is a sequential
* matrix, it returns the MPI_COMM_SELF
* communicator.
*/
virtual const MPI_Comm & get_mpi_communicator () const;
private:
/**
* Do the actual work for the
* respective reinit() function and the
* matching constructor, i.e. create a
* matrix. Getting rid of the previous
* matrix is left to the caller.
*/
void do_reinit (const unsigned int m,
const unsigned int n,
const unsigned int n_nonzero_per_row,
const bool is_symmetric = false);
/**
* Same as previous function.
*/
void do_reinit (const unsigned int m,
const unsigned int n,
const std::vector<unsigned int> &row_lengths,
const bool is_symmetric = false);
/**
* Same as previous function.
*/
template <typename SparsityType>
void do_reinit (const SparsityType &sparsity_pattern,
const bool preset_nonzero_locations);
/**
* To allow calling protected
* prepare_add() and
* prepare_set().
*/
friend class BlockMatrixBase<SparseMatrix>;
};
}
DEAL_II_NAMESPACE_CLOSE
#endif // DEAL_II_USE_PETSC
/*---------------------------- petsc_sparse_matrix.h ---------------------------*/
#endif
/*---------------------------- petsc_sparse_matrix.h ---------------------------*/
|