/usr/include/deal.II/lac/block_sparse_matrix_ez.h is in libdeal.ii-dev 8.1.0-4.
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 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | // ---------------------------------------------------------------------
// $Id: block_sparse_matrix_ez.h 30040 2013-07-18 17:06:48Z maier $
//
// Copyright (C) 2002 - 2013 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------
#ifndef __deal2__block_sparse_matrix_ez_h
#define __deal2__block_sparse_matrix_ez_h
//TODO: Derive BlockSparseMatrixEZ from BlockMatrixBase, like all the other block matrices as well; this would allow to instantiate a few functions with this template argument as well (in particular ConstraintMatrix::distribute_local_to_global)
#include <deal.II/base/config.h>
#include <deal.II/base/exceptions.h>
#include <deal.II/base/subscriptor.h>
#include <deal.II/base/table.h>
#include <deal.II/base/smartpointer.h>
#include <deal.II/lac/block_indices.h>
#include <deal.II/lac/sparse_matrix_ez.h>
DEAL_II_NAMESPACE_OPEN
template <typename Number> class BlockVector;
/*! @addtogroup Matrix1
*@{
*/
/**
* A block matrix consisting of blocks of type SparseMatrixEZ.
*
* Like the other Block-objects, this matrix can be used like a
* SparseMatrixEZ, when it comes to access to entries. Then, there
* are functions for the multiplication with BlockVector and
* access to the individual blocks.
*
* @see @ref GlossBlockLA "Block (linear algebra)"
* @author Guido Kanschat, 2002, 2003
*/
template<typename Number>
class BlockSparseMatrixEZ : public Subscriptor
{
public:
/**
* Declare type for container size.
*/
typedef types::global_dof_index size_type;
/**
* Default constructor. The
* result is an empty object with
* zero dimensions.
*/
BlockSparseMatrixEZ ();
/**
* Constructor setting up an
* object with given unmber of
* block rows and columns. The
* blocks themselves still have
* zero dimension.
*/
BlockSparseMatrixEZ (const unsigned int block_rows,
const unsigned int block_cols);
/**
* Copy constructor. This is
* needed for some container
* classes. It creates an object
* of the same number of block
* rows and columns. Since it
* calls the copy constructor of
* SparseMatrixEZ, the
* block s must be empty.
*/
BlockSparseMatrixEZ (const BlockSparseMatrixEZ<Number> &);
/**
* Copy operator. Like the copy
* constructor, this may be
* called for objects with empty
* blocks only.
*/
BlockSparseMatrixEZ &operator = (const BlockSparseMatrixEZ<Number> &);
/**
* 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.
*/
BlockSparseMatrixEZ &operator = (const double d);
/**
* Set matrix to zero dimensions
* and release memory.
*/
void clear ();
/**
* Initialize to given block
* numbers. After this
* operation, the matrix will
* have the block dimensions
* provided. Each block will have
* zero dimensions and must be
* initialized
* subsequently. After setting
* the sizes of the blocks,
* collect_sizes() must be
* called to update internal data
* structures.
*/
void reinit (const unsigned int n_block_rows,
const unsigned int n_block_cols);
/**
* This function collects the
* sizes of the sub-objects and
* stores them in internal
* arrays, in order to be able to
* relay global indices into the
* matrix to indices into the
* subobjects. You *must* call
* this function each time after
* you have changed the size of
* the sub-objects.
*/
void collect_sizes ();
/**
* Access the block with the
* given coordinates.
*/
SparseMatrixEZ<Number> &
block (const unsigned int row,
const unsigned int column);
/**
* Access the block with the
* given coordinates. Version for
* constant objects.
*/
const SparseMatrixEZ<Number> &
block (const unsigned int row,
const unsigned int column) const;
/**
* Return the number of blocks in a
* column.
*/
unsigned int n_block_rows () const;
/**
* Return the number of blocks in a
* row.
*/
unsigned int n_block_cols () const;
/**
* Return whether the object is
* empty. It is empty if no
* memory is allocated, which is
* the same as that both
* dimensions are zero. This
* function is just the
* concatenation of the
* respective call to all
* sub-matrices.
*/
bool empty () const;
/**
* Return number of rows of this
* matrix, which equals the
* dimension of the image
* space. It is the sum of rows
* of the rows of sub-matrices.
*/
size_type n_rows () const;
/**
* Return number of columns of
* this matrix, which equals the
* dimension of the range
* space. It is the sum of
* columns of the columns of
* sub-matrices.
*/
size_type n_cols () const;
/**
* Return the dimension of the
* image space. To remember: the
* matrix is of dimension
* $m \times n$.
*/
size_type m () const;
/**
* Return the dimension of the
* range space. To remember: the
* matrix is of dimension
* $m \times n$.
*/
size_type n () const;
/**
* Set the element <tt>(i,j)</tt>
* to @p value. Throws an error
* if the entry does not exist or
* if <tt>value</tt> is not a
* finite number. Still, it is
* allowed to store zero values
* in non-existent fields.
*/
void set (const size_type i,
const size_type j,
const Number value);
/**
* Add @p value to the element
* <tt>(i,j)</tt>. Throws an
* error if the entry does not
* exist or if <tt>value</tt> is
* not a finite number. Still, it
* is allowed to store zero
* values in non-existent fields.
*/
void add (const size_type i, const size_type j,
const Number value);
/**
* Matrix-vector multiplication:
* let $dst = M*src$ with $M$
* being this matrix.
*/
template <typename somenumber>
void vmult (BlockVector<somenumber> &dst,
const BlockVector<somenumber> &src) const;
/**
* Matrix-vector multiplication:
* let $dst = M^T*src$ with $M$
* being this matrix. This
* function does the same as
* vmult() but takes the
* transposed matrix.
*/
template <typename somenumber>
void Tvmult (BlockVector<somenumber> &dst,
const BlockVector<somenumber> &src) const;
/**
* Adding Matrix-vector
* multiplication. Add $M*src$ on
* $dst$ with $M$ being this
* matrix.
*/
template <typename somenumber>
void vmult_add (BlockVector<somenumber> &dst,
const BlockVector<somenumber> &src) const;
/**
* Adding Matrix-vector
* multiplication. Add $M^T*src$
* to $dst$ with $M$ being this
* matrix. This function does the
* same as vmult_add() but takes
* the transposed matrix.
*/
template <typename somenumber>
void Tvmult_add (BlockVector<somenumber> &dst,
const BlockVector<somenumber> &src) const;
/**
* Print statistics. If @p full
* is @p true, prints a
* histogram of all existing row
* lengths and allocated row
* lengths. Otherwise, just the
* relation of allocated and used
* entries is shown.
*/
template <class STREAM>
void print_statistics (STREAM &s, bool full = false);
private:
/**
* Object storing and managing
* the transformation of row
* indices to indices of the
* sub-objects.
*/
BlockIndices row_indices;
/**
* Object storing and managing
* the transformation of column
* indices to indices of the
* sub-objects.
*/
BlockIndices column_indices;
/**
* The actual matrices
*/
Table<2, SparseMatrixEZ<Number> > blocks;
};
/*@}*/
/*----------------------------------------------------------------------*/
template <typename Number>
inline
unsigned int
BlockSparseMatrixEZ<Number>::n_block_rows () const
{
return row_indices.size();
}
template <typename Number>
inline
typename BlockSparseMatrixEZ<Number>::size_type
BlockSparseMatrixEZ<Number>::n_rows () const
{
return row_indices.total_size();
}
template <typename Number>
inline
unsigned int
BlockSparseMatrixEZ<Number>::n_block_cols () const
{
return column_indices.size();
}
template <typename Number>
inline
typename BlockSparseMatrixEZ<Number>::size_type
BlockSparseMatrixEZ<Number>::n_cols () const
{
return column_indices.total_size();
}
template <typename Number>
inline
SparseMatrixEZ<Number> &
BlockSparseMatrixEZ<Number>::block (const unsigned int row,
const unsigned int column)
{
Assert (row<n_block_rows(), ExcIndexRange (row, 0, n_block_rows()));
Assert (column<n_block_cols(), ExcIndexRange (column, 0, n_block_cols()));
return blocks[row][column];
}
template <typename Number>
inline
const SparseMatrixEZ<Number> &
BlockSparseMatrixEZ<Number>::block (const unsigned int row,
const unsigned int column) const
{
Assert (row<n_block_rows(), ExcIndexRange (row, 0, n_block_rows()));
Assert (column<n_block_cols(), ExcIndexRange (column, 0, n_block_cols()));
return blocks[row][column];
}
template <typename Number>
inline
typename BlockSparseMatrixEZ<Number>::size_type
BlockSparseMatrixEZ<Number>::m () const
{
return n_rows();
}
template <typename Number>
inline
typename BlockSparseMatrixEZ<Number>::size_type
BlockSparseMatrixEZ<Number>::n () const
{
return n_cols();
}
template <typename Number>
inline
void
BlockSparseMatrixEZ<Number>::set (const size_type i,
const size_type j,
const Number value)
{
Assert (numbers::is_finite(value), ExcNumberNotFinite());
const std::pair<size_type,size_type>
row_index = row_indices.global_to_local (i),
col_index = column_indices.global_to_local (j);
block(row_index.first,col_index.first).set (row_index.second,
col_index.second,
value);
}
template <typename Number>
inline
void
BlockSparseMatrixEZ<Number>::add (const size_type i,
const size_type j,
const Number value)
{
Assert (numbers::is_finite(value), ExcNumberNotFinite());
const std::pair<unsigned int,size_type>
row_index = row_indices.global_to_local (i),
col_index = column_indices.global_to_local (j);
block(row_index.first,col_index.first).add (row_index.second,
col_index.second,
value);
}
template <typename Number>
template <typename somenumber>
void
BlockSparseMatrixEZ<Number>::vmult (BlockVector<somenumber> &dst,
const BlockVector<somenumber> &src) const
{
Assert (dst.n_blocks() == n_block_rows(),
ExcDimensionMismatch(dst.n_blocks(), n_block_rows()));
Assert (src.n_blocks() == n_block_cols(),
ExcDimensionMismatch(src.n_blocks(), n_block_cols()));
dst = 0.;
for (unsigned int row=0; row<n_block_rows(); ++row)
for (unsigned int col=0; col<n_block_cols(); ++col)
block(row,col).vmult_add (dst.block(row),
src.block(col));
}
template <typename Number>
template <typename somenumber>
void
BlockSparseMatrixEZ<Number>::
vmult_add (BlockVector<somenumber> &dst,
const BlockVector<somenumber> &src) const
{
Assert (dst.n_blocks() == n_block_rows(),
ExcDimensionMismatch(dst.n_blocks(), n_block_rows()));
Assert (src.n_blocks() == n_block_cols(),
ExcDimensionMismatch(src.n_blocks(), n_block_cols()));
for (unsigned int row=0; row<n_block_rows(); ++row)
for (unsigned int col=0; col<n_block_cols(); ++col)
block(row,col).vmult_add (dst.block(row),
src.block(col));
}
template <typename Number>
template <typename somenumber>
void
BlockSparseMatrixEZ<Number>::
Tvmult (BlockVector<somenumber> &dst,
const BlockVector<somenumber> &src) const
{
Assert (dst.n_blocks() == n_block_cols(),
ExcDimensionMismatch(dst.n_blocks(), n_block_cols()));
Assert (src.n_blocks() == n_block_rows(),
ExcDimensionMismatch(src.n_blocks(), n_block_rows()));
dst = 0.;
for (unsigned int row=0; row<n_block_rows(); ++row)
for (unsigned int col=0; col<n_block_cols(); ++col)
block(row,col).Tvmult_add (dst.block(col),
src.block(row));
}
template <typename Number>
template <typename somenumber>
void
BlockSparseMatrixEZ<Number>::
Tvmult_add (BlockVector<somenumber> &dst,
const BlockVector<somenumber> &src) const
{
Assert (dst.n_blocks() == n_block_cols(),
ExcDimensionMismatch(dst.n_blocks(), n_block_cols()));
Assert (src.n_blocks() == n_block_rows(),
ExcDimensionMismatch(src.n_blocks(), n_block_rows()));
for (unsigned int row=0; row<n_block_rows(); ++row)
for (unsigned int col=0; col<n_block_cols(); ++col)
block(row,col).Tvmult_add (dst.block(col),
src.block(row));
}
template <typename number>
template <class STREAM>
inline
void
BlockSparseMatrixEZ<number>::print_statistics (STREAM &out, bool full)
{
size_type used_total = 0;
size_type allocated_total = 0;
size_type reserved_total = 0;
std::vector<size_type> used_by_line_total;
size_type used;
size_type allocated;
size_type reserved;
std::vector<size_type> used_by_line;
for (size_type i=0; i<n_block_rows(); ++i)
for (size_type j=0; j<n_block_cols(); ++j)
{
used_by_line.clear();
out << "block:\t" << i << '\t' << j << std::endl;
block(i,j).compute_statistics (used, allocated, reserved,
used_by_line, full);
out << "used:" << used << std::endl
<< "allocated:" << allocated << std::endl
<< "reserved:" << reserved << std::endl;
used_total += used;
allocated_total += allocated;
reserved_total += reserved;
if (full)
{
used_by_line_total.resize(used_by_line.size());
for (size_type i=0; i< used_by_line.size(); ++i)
if (used_by_line[i] != 0)
{
out << "row-entries\t" << i
<< "\trows\t" << used_by_line[i]
<< std::endl;
used_by_line_total[i] += used_by_line[i];
}
}
}
out << "Total" << std::endl
<< "used:" << used_total << std::endl
<< "allocated:" << allocated_total << std::endl
<< "reserved:" << reserved_total << std::endl;
for (size_type i=0; i< used_by_line_total.size(); ++i)
if (used_by_line_total[i] != 0)
{
out << "row-entries\t" << i
<< "\trows\t" << used_by_line_total[i]
<< std::endl;
}
}
DEAL_II_NAMESPACE_CLOSE
#endif //__deal2__block_sparse_matrix_ez_h
|