Reference documentation for deal.II version GIT relicensing-35-gbe64a602e6 2024-03-01 21:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
petsc_sparse_matrix.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2004 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_petsc_sparse_matrix_h
16#define dealii_petsc_sparse_matrix_h
17
18
19#include <deal.II/base/config.h>
20
21#ifdef DEAL_II_WITH_PETSC
22
26
27# include <petscis.h>
28# include <petscistypes.h>
29
30# include <vector>
31
33// forward declaration
34# ifndef DOXYGEN
35template <typename MatrixType>
36class BlockMatrixBase;
37# endif
38
39namespace PETScWrappers
40{
53 class SparseMatrix : public MatrixBase
54 {
55 public:
63 struct Traits
64 {
69 static const bool zero_addition_can_be_elided = true;
70 };
71
76
83 explicit SparseMatrix(const Mat &);
84
100 const size_type n,
101 const size_type n_nonzero_per_row,
102 const bool is_symmetric = false);
103
121 const size_type n,
122 const std::vector<size_type> &row_lengths,
123 const bool is_symmetric = false);
124
142 template <typename SparsityPatternType>
143 explicit SparseMatrix(const SparsityPatternType &sparsity_pattern,
144 const bool preset_nonzero_locations = true);
145
156 operator=(const double d);
157
161 SparseMatrix(const SparseMatrix &) = delete;
162
167 operator=(const SparseMatrix &) = delete;
168
174 void
175 reinit(const size_type m,
176 const size_type n,
177 const size_type n_nonzero_per_row,
178 const bool is_symmetric = false);
179
185 void
186 reinit(const size_type m,
187 const size_type n,
188 const std::vector<size_type> &row_lengths,
189 const bool is_symmetric = false);
190
216 template <typename SparsityPatternType>
217 void
218 reinit(const SparsityPatternType &sparsity_pattern,
219 const bool preset_nonzero_locations = true);
220
224 size_t
225 m() const;
226
230 size_t
231 n() const;
232
239 void
241 const SparseMatrix &B,
242 const MPI::Vector &V = MPI::Vector()) const;
243
251 void
253 const SparseMatrix &B,
254 const MPI::Vector &V = MPI::Vector()) const;
255
256 private:
261 void
262 do_reinit(const size_type m,
263 const size_type n,
264 const size_type n_nonzero_per_row,
265 const bool is_symmetric = false);
266
270 void
271 do_reinit(const size_type m,
272 const size_type n,
273 const std::vector<size_type> &row_lengths,
274 const bool is_symmetric = false);
275
279 template <typename SparsityPatternType>
280 void
281 do_reinit(const SparsityPatternType &sparsity_pattern,
282 const bool preset_nonzero_locations);
283
284 // To allow calling protected prepare_add() and prepare_set().
285 friend class BlockMatrixBase<SparseMatrix>;
286 };
287
288 namespace MPI
289 {
367 {
368 public:
373
381 struct Traits
382 {
390 static const bool zero_addition_can_be_elided = false;
391 };
392
396 SparseMatrix();
397
404 explicit SparseMatrix(const Mat &);
405
409 ~SparseMatrix() override;
410
433 template <typename SparsityPatternType>
434 SparseMatrix(const MPI_Comm communicator,
435 const SparsityPatternType &sparsity_pattern,
436 const std::vector<size_type> &local_rows_per_process,
437 const std::vector<size_type> &local_columns_per_process,
438 const unsigned int this_process,
439 const bool preset_nonzero_locations = true);
440
451 operator=(const value_type d);
452
453
458 void
459 copy_from(const SparseMatrix &other);
460
480 template <typename SparsityPatternType>
481 void
482 reinit(const MPI_Comm communicator,
483 const SparsityPatternType &sparsity_pattern,
484 const std::vector<size_type> &local_rows_per_process,
485 const std::vector<size_type> &local_columns_per_process,
486 const unsigned int this_process,
487 const bool preset_nonzero_locations = true);
488
495 template <typename SparsityPatternType>
496 void
497 reinit(const IndexSet &local_partitioning,
498 const SparsityPatternType &sparsity_pattern,
499 const MPI_Comm communicator);
500
507 template <typename SparsityPatternType>
508 void
509 reinit(const IndexSet &local_rows,
510 const IndexSet &local_columns,
511 const SparsityPatternType &sparsity_pattern,
512 const MPI_Comm communicator);
513
519 void
520 reinit(const SparseMatrix &other);
521
531 template <typename SparsityPatternType>
532 void
533 reinit(const IndexSet &local_rows,
534 const IndexSet &local_active_rows,
535 const IndexSet &local_columns,
536 const IndexSet &local_active_columns,
537 const SparsityPatternType &sparsity_pattern,
538 const MPI_Comm communicator);
539
548 int,
549 int,
550 << "The number of local rows " << arg1
551 << " must be larger than the total number of rows "
552 << arg2);
570 PetscScalar
571 matrix_norm_square(const Vector &v) const;
572
581 PetscScalar
582 matrix_scalar_product(const Vector &u, const Vector &v) const;
583
590
598
605 void
607 const SparseMatrix &B,
608 const MPI::Vector &V = MPI::Vector()) const;
609
617 void
619 const SparseMatrix &B,
620 const MPI::Vector &V = MPI::Vector()) const;
621
622 private:
626 template <typename SparsityPatternType>
627 void
628 do_reinit(const MPI_Comm comm,
629 const SparsityPatternType &sparsity_pattern,
630 const std::vector<size_type> &local_rows_per_process,
631 const std::vector<size_type> &local_columns_per_process,
632 const unsigned int this_process,
633 const bool preset_nonzero_locations);
634
638 template <typename SparsityPatternType>
639 void
640 do_reinit(const MPI_Comm comm,
641 const IndexSet &local_rows,
642 const IndexSet &local_columns,
643 const SparsityPatternType &sparsity_pattern);
644
649 template <typename SparsityPatternType>
650 void
652 const IndexSet &local_rows,
653 const IndexSet &local_active_rows,
654 const IndexSet &local_columns,
655 const IndexSet &local_active_columns,
656 const SparsityPatternType &sparsity_pattern);
657
658 // To allow calling protected prepare_add() and prepare_set().
659 friend class BlockMatrixBase<SparseMatrix>;
660 };
661
662 } // namespace MPI
663} // namespace PETScWrappers
664
666
667#endif // DEAL_II_WITH_PETSC
668
669#endif
SparseMatrix & operator=(const value_type d)
void copy_from(const SparseMatrix &other)
void reinit(const MPI_Comm communicator, const SparsityPatternType &sparsity_pattern, const std::vector< size_type > &local_rows_per_process, const std::vector< size_type > &local_columns_per_process, const unsigned int this_process, const bool preset_nonzero_locations=true)
void mmult(SparseMatrix &C, const SparseMatrix &B, const MPI::Vector &V=MPI::Vector()) const
PetscScalar matrix_scalar_product(const Vector &u, const Vector &v) const
void Tmmult(SparseMatrix &C, const SparseMatrix &B, const MPI::Vector &V=MPI::Vector()) const
PetscScalar matrix_norm_square(const Vector &v) const
void do_reinit(const MPI_Comm comm, const SparsityPatternType &sparsity_pattern, const std::vector< size_type > &local_rows_per_process, const std::vector< size_type > &local_columns_per_process, const unsigned int this_process, const bool preset_nonzero_locations)
PetscBool is_symmetric(const double tolerance=1.e-12)
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)
void Tmmult(SparseMatrix &C, const SparseMatrix &B, const MPI::Vector &V=MPI::Vector()) const
void reinit(const size_type m, const size_type n, const size_type n_nonzero_per_row, const bool is_symmetric=false)
SparseMatrix(const SparseMatrix &)=delete
SparseMatrix & operator=(const SparseMatrix &)=delete
SparseMatrix & operator=(const double d)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
static ::ExceptionBase & ExcLocalRowsTooLarge(int arg1, int arg2)
#define DeclException2(Exception2, type1, type2, outsequence)
Definition exceptions.h:539
unsigned int global_dof_index
Definition types.h:81
*braid_SplitCommworld & comm