Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
petsc_parallel_sparse_matrix.h
1 // ---------------------------------------------------------------------
2 // @f$Id: petsc_parallel_sparse_matrix.h 30233 2013-08-05 22:41:29Z heister @f$
3 //
4 // Copyright (C) 2004 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__petsc_parallel_sparse_matrix_h
18 #define __deal2__petsc_parallel_sparse_matrix_h
19 
20 #include <deal.II/base/config.h>
21 
22 #ifdef DEAL_II_WITH_PETSC
23 
24 # include <deal.II/lac/exceptions.h>
25 # include <deal.II/lac/petsc_matrix_base.h>
26 # include <deal.II/lac/petsc_parallel_vector.h>
27 # include <vector>
28 
29 DEAL_II_NAMESPACE_OPEN
30 
31 
32 // forward declaration
33 template <typename Matrix> class BlockMatrixBase;
34 
35 
36 namespace PETScWrappers
37 {
38  namespace MPI
39  {
40 
41 
42 
117  class SparseMatrix : public MatrixBase
118  {
119  public:
124 
136  struct Traits
137  {
152  static const bool zero_addition_can_be_elided = false;
153  };
154 
159  SparseMatrix ();
160 
164  ~SparseMatrix ();
165 
196  SparseMatrix (const MPI_Comm &communicator,
197  const size_type m,
198  const size_type n,
199  const size_type local_rows,
200  const size_type local_columns,
201  const size_type n_nonzero_per_row,
202  const bool is_symmetric = false);
203 
237  SparseMatrix (const MPI_Comm &communicator,
238  const size_type m,
239  const size_type n,
240  const size_type local_rows,
241  const size_type local_columns,
242  const std::vector<size_type> &row_lengths,
243  const bool is_symmetric = false);
244 
285  template <typename SparsityType>
286  SparseMatrix (const MPI_Comm &communicator,
287  const SparsityType &sparsity_pattern,
288  const std::vector<size_type> &local_rows_per_process,
289  const std::vector<size_type> &local_columns_per_process,
290  const unsigned int this_process,
291  const bool preset_nonzero_locations = true);
292 
310 
311 
316  void copy_from(const SparseMatrix &other);
317 
326  void reinit (const MPI_Comm &communicator,
327  const size_type m,
328  const size_type n,
329  const size_type local_rows,
330  const size_type local_columns,
331  const size_type n_nonzero_per_row,
332  const bool is_symmetric = false);
333 
342  void reinit (const MPI_Comm &communicator,
343  const size_type m,
344  const size_type n,
345  const size_type local_rows,
346  const size_type local_columns,
347  const std::vector<size_type> &row_lengths,
348  const bool is_symmetric = false);
349 
384  template <typename SparsityType>
385  void reinit (const MPI_Comm &communicator,
386  const SparsityType &sparsity_pattern,
387  const std::vector<size_type> &local_rows_per_process,
388  const std::vector<size_type> &local_columns_per_process,
389  const unsigned int this_process,
390  const bool preset_nonzero_locations = true);
391 
398  template <typename SparsityType>
399  void reinit (const IndexSet &local_rows,
400  const IndexSet &local_columns,
401  const SparsityType &sparsity_pattern,
402  const MPI_Comm &communicator);
403 
409  virtual const MPI_Comm &get_mpi_communicator () const;
410 
416  DeclException2 (ExcLocalRowsTooLarge,
417  int, int,
418  << "The number of local rows " << arg1
419  << " must be larger than the total number of rows " << arg2);
421 
448  PetscScalar matrix_norm_square (const Vector &v) const;
449 
462  PetscScalar matrix_scalar_product (const Vector &u,
463  const Vector &v) const;
464 
465  private:
466 
471  MPI_Comm communicator;
472 
481  void do_reinit (const size_type m,
482  const size_type n,
483  const size_type local_rows,
484  const size_type local_columns,
485  const size_type n_nonzero_per_row,
486  const bool is_symmetric = false);
487 
491  void do_reinit (const size_type m,
492  const size_type n,
493  const size_type local_rows,
494  const size_type local_columns,
495  const std::vector<size_type> &row_lengths,
496  const bool is_symmetric = false);
497 
501  template <typename SparsityType>
502  void do_reinit (const SparsityType &sparsity_pattern,
503  const std::vector<size_type> &local_rows_per_process,
504  const std::vector<size_type> &local_columns_per_process,
505  const unsigned int this_process,
506  const bool preset_nonzero_locations);
507 
511  template <typename SparsityType>
512  void do_reinit (const IndexSet &local_rows,
513  const IndexSet &local_columns,
514  const SparsityType &sparsity_pattern);
515 
522  };
523 
524 
525 
526 // -------- template and inline functions ----------
527 
528  inline
529  const MPI_Comm &
531  {
532  return communicator;
533  }
534  }
535 }
536 
537 DEAL_II_NAMESPACE_CLOSE
538 
539 #endif // DEAL_II_WITH_PETSC
540 
541 /*---------------------------- petsc_parallel_sparse_matrix.h ---------------------------*/
542 
543 #endif
544 /*---------------------------- petsc_parallel_sparse_matrix.h ---------------------------*/
void reinit(const MPI_Comm &communicator, const size_type m, const size_type n, const size_type local_rows, const size_type local_columns, const size_type n_nonzero_per_row, const bool is_symmetric=false)
void do_reinit(const size_type m, const size_type n, const size_type local_rows, const size_type local_columns, const size_type n_nonzero_per_row, const bool is_symmetric=false)
virtual const MPI_Comm & get_mpi_communicator() const
DeclException2(ExcLocalRowsTooLarge, int, int,<< "The number of local rows "<< arg1<< " must be larger than the total number of rows "<< arg2)
size_type n() const
size_type m() const
PetscBool is_symmetric(const double tolerance=1.e-12)
void copy_from(const SparseMatrix &other)
unsigned int global_dof_index
Definition: types.h:100
PetscScalar matrix_norm_square(const Vector &v) const
PetscScalar matrix_scalar_product(const Vector &u, const Vector &v) const
types::global_dof_index size_type
SparseMatrix & operator=(const value_type d)