18 #ifdef DEAL_II_WITH_PETSC
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);
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);
311 #endif // DEAL_II_WITH_PETSC