Reference documentation for deal.II version 9.1.0-pre
petsc_sparse_matrix.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2004 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_petsc_sparse_matrix_h
17 # define dealii_petsc_sparse_matrix_h
18 
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_vector.h>
27 
28 # include <vector>
29 
30 DEAL_II_NAMESPACE_OPEN
31 // forward declaration
32 template <typename MatrixType>
33 class BlockMatrixBase;
34 
35 
36 namespace PETScWrappers
37 {
51  class SparseMatrix : public MatrixBase
52  {
53  public:
61  struct Traits
62  {
67  static const bool zero_addition_can_be_elided = true;
68  };
69 
73  SparseMatrix();
74 
89  SparseMatrix(const size_type m,
90  const size_type n,
91  const size_type n_nonzero_per_row,
92  const bool is_symmetric = false);
93 
110  SparseMatrix(const size_type m,
111  const size_type n,
112  const std::vector<size_type> &row_lengths,
113  const bool is_symmetric = false);
114 
132  template <typename SparsityPatternType>
133  explicit SparseMatrix(const SparsityPatternType &sparsity_pattern,
134  const bool preset_nonzero_locations = true);
135 
145  SparseMatrix &
146  operator=(const double d);
147 
153  void
154  reinit(const size_type m,
155  const size_type n,
156  const size_type n_nonzero_per_row,
157  const bool is_symmetric = false);
158 
164  void
165  reinit(const size_type m,
166  const size_type n,
167  const std::vector<size_type> &row_lengths,
168  const bool is_symmetric = false);
169 
195  template <typename SparsityPatternType>
196  void
197  reinit(const SparsityPatternType &sparsity_pattern,
198  const bool preset_nonzero_locations = true);
199 
205  virtual const MPI_Comm &
206  get_mpi_communicator() const override;
207 
211  size_t
212  m() const;
213 
217  size_t
218  n() const;
219 
226  void
227  mmult(SparseMatrix & C,
228  const SparseMatrix &B,
229  const MPI::Vector & V = MPI::Vector()) const;
230 
238  void
239  Tmmult(SparseMatrix & C,
240  const SparseMatrix &B,
241  const MPI::Vector & V = MPI::Vector()) const;
242 
243  private:
247  SparseMatrix(const SparseMatrix &) = delete;
251  SparseMatrix &
252  operator=(const SparseMatrix &) = delete;
253 
259  void
260  do_reinit(const size_type m,
261  const size_type n,
262  const size_type n_nonzero_per_row,
263  const bool is_symmetric = false);
264 
268  void
269  do_reinit(const size_type m,
270  const size_type n,
271  const std::vector<size_type> &row_lengths,
272  const bool is_symmetric = false);
273 
277  template <typename SparsityPatternType>
278  void
279  do_reinit(const SparsityPatternType &sparsity_pattern,
280  const bool preset_nonzero_locations);
281 
286  };
287 
288  namespace MPI
289  {
367  class SparseMatrix : public MatrixBase
368  {
369  public:
374 
382  struct Traits
383  {
391  static const bool zero_addition_can_be_elided = false;
392  };
393 
397  SparseMatrix();
398 
402  ~SparseMatrix() override;
403 
426  DEAL_II_DEPRECATED
427  SparseMatrix(const MPI_Comm &communicator,
428  const size_type m,
429  const size_type n,
430  const size_type local_rows,
431  const size_type local_columns,
432  const size_type n_nonzero_per_row,
433  const bool is_symmetric = false,
434  const size_type n_offdiag_nonzero_per_row = 0);
435 
459  DEAL_II_DEPRECATED
460  SparseMatrix(const MPI_Comm & communicator,
461  const size_type m,
462  const size_type n,
463  const size_type local_rows,
464  const size_type local_columns,
465  const std::vector<size_type> &row_lengths,
466  const bool is_symmetric = false,
467  const std::vector<size_type> &offdiag_row_lengths =
468  std::vector<size_type>());
469 
492  template <typename SparsityPatternType>
493  SparseMatrix(const MPI_Comm & communicator,
494  const SparsityPatternType & sparsity_pattern,
495  const std::vector<size_type> &local_rows_per_process,
496  const std::vector<size_type> &local_columns_per_process,
497  const unsigned int this_process,
498  const bool preset_nonzero_locations = true);
499 
509  SparseMatrix &
510  operator=(const value_type d);
511 
512 
517  void
518  copy_from(const SparseMatrix &other);
519 
528  DEAL_II_DEPRECATED
529  void
530  reinit(const MPI_Comm &communicator,
531  const size_type m,
532  const size_type n,
533  const size_type local_rows,
534  const size_type local_columns,
535  const size_type n_nonzero_per_row,
536  const bool is_symmetric = false,
537  const size_type n_offdiag_nonzero_per_row = 0);
538 
547  DEAL_II_DEPRECATED
548  void
549  reinit(const MPI_Comm & communicator,
550  const size_type m,
551  const size_type n,
552  const size_type local_rows,
553  const size_type local_columns,
554  const std::vector<size_type> &row_lengths,
555  const bool is_symmetric = false,
556  const std::vector<size_type> &offdiag_row_lengths =
557  std::vector<size_type>());
558 
578  template <typename SparsityPatternType>
579  void
580  reinit(const MPI_Comm & communicator,
581  const SparsityPatternType & sparsity_pattern,
582  const std::vector<size_type> &local_rows_per_process,
583  const std::vector<size_type> &local_columns_per_process,
584  const unsigned int this_process,
585  const bool preset_nonzero_locations = true);
586 
593  template <typename SparsityPatternType>
594  void
595  reinit(const IndexSet & local_rows,
596  const IndexSet & local_columns,
597  const SparsityPatternType &sparsity_pattern,
598  const MPI_Comm & communicator);
599 
605  void
606  reinit(const SparseMatrix &other);
607 
612  virtual const MPI_Comm &
613  get_mpi_communicator() const override;
614 
622  DeclException2(ExcLocalRowsTooLarge,
623  int,
624  int,
625  << "The number of local rows " << arg1
626  << " must be larger than the total number of rows "
627  << arg2);
629 
645  PetscScalar
646  matrix_norm_square(const Vector &v) const;
647 
656  PetscScalar
657  matrix_scalar_product(const Vector &u, const Vector &v) const;
658 
663  IndexSet
664  locally_owned_domain_indices() const;
665 
671  IndexSet
672  locally_owned_range_indices() const;
673 
680  void
681  mmult(SparseMatrix & C,
682  const SparseMatrix &B,
683  const MPI::Vector & V = MPI::Vector()) const;
684 
692  void
693  Tmmult(SparseMatrix & C,
694  const SparseMatrix &B,
695  const MPI::Vector & V = MPI::Vector()) const;
696 
697  private:
701  MPI_Comm communicator;
702 
711  DEAL_II_DEPRECATED
712  void
713  do_reinit(const size_type m,
714  const size_type n,
715  const size_type local_rows,
716  const size_type local_columns,
717  const size_type n_nonzero_per_row,
718  const bool is_symmetric = false,
719  const size_type n_offdiag_nonzero_per_row = 0);
720 
727  DEAL_II_DEPRECATED
728  void
729  do_reinit(const size_type m,
730  const size_type n,
731  const size_type local_rows,
732  const size_type local_columns,
733  const std::vector<size_type> &row_lengths,
734  const bool is_symmetric = false,
735  const std::vector<size_type> &offdiag_row_lengths =
736  std::vector<size_type>());
737 
741  template <typename SparsityPatternType>
742  void
743  do_reinit(const SparsityPatternType & sparsity_pattern,
744  const std::vector<size_type> &local_rows_per_process,
745  const std::vector<size_type> &local_columns_per_process,
746  const unsigned int this_process,
747  const bool preset_nonzero_locations);
748 
752  template <typename SparsityPatternType>
753  void
754  do_reinit(const IndexSet & local_rows,
755  const IndexSet & local_columns,
756  const SparsityPatternType &sparsity_pattern);
757 
761  friend class BlockMatrixBase<SparseMatrix>;
762  };
763 
764 
765 
766  // -------- template and inline functions ----------
767 
768  inline const MPI_Comm &
770  {
771  return communicator;
772  }
773  } // namespace MPI
774 } // namespace PETScWrappers
775 
776 DEAL_II_NAMESPACE_CLOSE
777 
778 # endif // DEAL_II_WITH_PETSC
779 
780 #endif
781 /*--------------------------- petsc_sparse_matrix.h -------------------------*/
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:420
PetscScalar matrix_scalar_product(const VectorBase &u, const VectorBase &v) const
virtual const MPI_Comm & get_mpi_communicator() const override
void Tmmult(SparseMatrix &C, const SparseMatrix &B, const MPI::Vector &V=MPI::Vector()) const
PetscBool is_symmetric(const double tolerance=1.e-12)
unsigned long long int global_dof_index
Definition: types.h:72
SparseMatrix & operator=(const double d)
void reinit(const size_type m, const size_type n, const size_type n_nonzero_per_row, const bool is_symmetric=false)
PetscScalar matrix_norm_square(const VectorBase &v) const
types::global_dof_index size_type
void mmult(SparseMatrix &C, const SparseMatrix &B, const MPI::Vector &V=MPI::Vector()) const
void do_reinit(const size_type m, const size_type n, const size_type n_nonzero_per_row, const bool is_symmetric=false)