16 #include <deal.II/lac/petsc_sparse_matrix.h> 18 #ifdef DEAL_II_WITH_PETSC 20 # include <deal.II/lac/dynamic_sparsity_pattern.h> 21 # include <deal.II/lac/exceptions.h> 22 # include <deal.II/lac/petsc_compatibility.h> 23 # include <deal.II/lac/petsc_vector_base.h> 24 # include <deal.II/lac/sparsity_pattern.h> 26 DEAL_II_NAMESPACE_OPEN
32 const int m = 0,
n = 0, n_nonzero_per_row = 0;
33 const PetscErrorCode ierr = MatCreateSeqAIJ(
34 PETSC_COMM_SELF,
m,
n, n_nonzero_per_row,
nullptr, &
matrix);
43 const bool is_symmetric)
52 const std::vector<size_type> &row_lengths,
53 const bool is_symmetric)
60 template <
typename SparsityPatternType>
62 const bool preset_nonzero_locations)
64 do_reinit(sparsity_pattern, preset_nonzero_locations);
82 const bool is_symmetric)
97 const std::vector<size_type> &row_lengths,
98 const bool is_symmetric)
110 template <
typename SparsityPatternType>
113 const bool preset_nonzero_locations)
120 do_reinit(sparsity_pattern, preset_nonzero_locations);
128 static MPI_Comm comm;
129 const PetscErrorCode ierr =
130 PetscObjectGetComm(reinterpret_cast<PetscObject>(
matrix), &comm);
141 const bool is_symmetric)
146 const PetscErrorCode ierr = MatCreateSeqAIJ(
147 PETSC_COMM_SELF,
m,
n, n_nonzero_per_row,
nullptr, &
matrix);
162 const std::vector<size_type> &row_lengths,
163 const bool is_symmetric)
165 Assert(row_lengths.size() ==
m,
176 const std::vector<PetscInt> int_row_lengths(row_lengths.begin(),
179 const PetscErrorCode ierr = MatCreateSeqAIJ(
180 PETSC_COMM_SELF,
m,
n, 0, int_row_lengths.data(), &
matrix);
192 template <
typename SparsityPatternType>
195 const bool preset_nonzero_locations)
197 std::vector<size_type> row_lengths(sparsity_pattern.n_rows());
198 for (
size_type i = 0; i < sparsity_pattern.n_rows(); ++i)
199 row_lengths[i] = sparsity_pattern.row_length(i);
202 sparsity_pattern.n_cols(),
219 if (preset_nonzero_locations ==
true)
221 std::vector<PetscInt> row_entries;
222 std::vector<PetscScalar> row_values;
223 for (
size_type i = 0; i < sparsity_pattern.n_rows(); ++i)
225 row_entries.resize(row_lengths[i]);
226 row_values.resize(row_lengths[i], 0.0);
227 for (
size_type j = 0; j < row_lengths[i]; ++j)
228 row_entries[j] = sparsity_pattern.column_number(i, j);
230 const PetscInt int_row = i;
231 const PetscErrorCode ierr = MatSetValues(
matrix,
251 const PetscErrorCode ierr = MatGetSize(
matrix, &
m, &
n);
261 const PetscErrorCode ierr = MatGetSize(
matrix, &
m, &
n);
307 DEAL_II_NAMESPACE_CLOSE
309 #endif // DEAL_II_WITH_PETSC PetscErrorCode destroy_matrix(Mat &matrix)
void Tmmult(MatrixBase &C, const MatrixBase &B, const VectorBase &V) const
virtual const MPI_Comm & get_mpi_communicator() const override
#define AssertThrow(cond, exc)
void set_matrix_option(Mat &matrix, const MatOption option_name, const PetscBool option_value=PETSC_FALSE)
PetscBool is_symmetric(const double tolerance=1.e-12)
void compress(const VectorOperation::values operation)
MatrixBase & operator=(const MatrixBase &)=delete
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)
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void mmult(MatrixBase &C, const MatrixBase &B, const VectorBase &V) const
void set_keep_zero_rows(Mat &matrix)
types::global_dof_index size_type
void mmult(SparseMatrix &C, const SparseMatrix &B, const MPI::Vector &V=MPI::Vector()) const
void Tmmult(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 close_matrix(Mat &matrix)