21#ifdef DEAL_II_WITH_PETSC
42 ierr = MatCreate(
comm, &dummy);
44 ierr = MatSetSizes(dummy, lr, lc, gr, gc);
46 ierr = MatSetType(dummy, MATAIJ);
48 ierr = MatSeqAIJSetPreallocation(dummy, 0,
nullptr);
50 ierr = MatMPIAIJSetPreallocation(dummy, 0,
nullptr, 0,
nullptr);
52 ierr = MatSetUp(dummy);
54 ierr = MatSetOption(dummy, MAT_NO_OFF_PROC_ENTRIES, PETSC_TRUE);
56 ierr = MatAssemblyBegin(dummy, MAT_FINAL_ASSEMBLY);
58 ierr = MatAssemblyEnd(dummy, MAT_FINAL_ASSEMBLY);
100 this->
sub_objects.reinit(n_block_rows, n_block_columns);
118 const std::vector<IndexSet> &cols,
129 std::vector<types::global_dof_index> row_sizes;
134 std::vector<types::global_dof_index> col_sizes;
148 p->
reinit(rows[r], cols[c], bdsp.
block(r, c), com);
160 reinit(sizes, sizes, bdsp, com);
175 std::vector<size_type> row_sizes(
m,
size_type(-1));
176 std::vector<size_type> col_sizes(
n,
size_type(-1));
177 std::vector<size_type> row_local_sizes(
m,
size_type(-1));
178 std::vector<size_type> col_local_sizes(
n,
size_type(-1));
189 row_local_sizes[r] = this->
sub_objects[r][c]->local_size();
204 "When passing empty sub-blocks of a block matrix, you need to make "
205 "sure that at least one block in each block row and block column is "
206 "non-empty. However, block row " +
208 " is completely empty "
209 "and so it is not possible to determine how many rows it should have."));
213 "When passing empty sub-blocks of a block matrix, you need to make "
214 "sure that at least one block in each block row and block column is "
215 "non-empty. However, block column " +
217 " is completely empty "
218 "and so it is not possible to determine how many columns it should have."));
220 create_dummy_mat(
comm,
221 static_cast<PetscInt
>(row_local_sizes[r]),
222 static_cast<PetscInt
>(row_sizes[r]),
223 static_cast<PetscInt
>(col_local_sizes[c]),
224 static_cast<PetscInt
>(col_sizes[c]));
229 ierr = MatDestroy(&dummy);
256 std::vector<Mat> psub_objects(
m *
n);
257 for (
unsigned int r = 0; r <
m; r++)
258 for (
unsigned int c = 0; c <
n; c++)
261 psub_objects[r *
n + c] = this->
sub_objects[r][c]->petsc_matrix();
263 ierr = MatCreateNest(
282 std::vector<IndexSet>
285 std::vector<IndexSet> index_sets;
288 index_sets.push_back(this->block(0, i).locally_owned_domain_indices());
295 std::vector<IndexSet>
298 std::vector<IndexSet> index_sets;
301 index_sets.push_back(this->block(i, 0).locally_owned_range_indices());
311 std::uint64_t n_nonzero = 0;
327 BlockSparseMatrix::operator
const Mat &()
const
329 return petsc_nest_matrix;
346 PetscInt nr = 1, nc = 1;
348 PetscErrorCode ierr =
349 PetscObjectTypeCompare(
reinterpret_cast<PetscObject
>(A),
353 std::vector<Mat> mats;
354 bool need_empty_matrices =
false;
357 ierr = MatNestGetSize(A, &nr, &nc);
359 for (PetscInt i = 0; i < nr; ++i)
361 for (PetscInt j = 0; j < nc; ++j)
364 ierr = MatNestGetSubMat(A, i, j, &sA);
367 need_empty_matrices =
true;
376 std::vector<size_type> r_block_sizes(nr, 0);
377 std::vector<size_type> c_block_sizes(nc, 0);
381 for (PetscInt i = 0; i < nr; ++i)
383 for (PetscInt j = 0; j < nc; ++j)
385 if (mats[i * nc + j])
391 if (need_empty_matrices)
395 if (need_empty_matrices || !isnest)
401 ierr = PetscObjectReference(
reinterpret_cast<PetscObject
>(A));
void reinit(const unsigned int n_blocks, const size_type n_elements_per_block)
BlockIndices column_block_indices
unsigned int n_block_rows() const
void compress(VectorOperation::values operation)
unsigned int n_block_cols() const
BlockIndices row_block_indices
BlockType & block(const unsigned int row, const unsigned int column)
Table< 2, ObserverPointer< BlockType, BlockMatrixBase< SparseMatrix > > > sub_objects
size_type n_block_rows() const
SparsityPatternType & block(const size_type row, const size_type column)
size_type n_block_cols() const
EnableObserverPointer & operator=(const EnableObserverPointer &)
~BlockSparseMatrix() override
BaseClass::size_type size_type
void reinit(const size_type n_block_rows, const size_type n_block_columns)
BlockSparseMatrix & operator=(const BlockSparseMatrix &)
MPI_Comm get_mpi_communicator() const
void create_empty_matrices_if_needed()
std::uint64_t n_nonzero_elements() const
BaseClass::BlockType BlockType
std::vector< IndexSet > locally_owned_domain_indices() const
std::vector< IndexSet > locally_owned_range_indices() const
void compress(VectorOperation::values operation)
std::size_t n_nonzero_elements() const
virtual void reinit(const SparsityPattern &sparsity)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
#define AssertNothrow(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
void petsc_increment_state_counter(Vec v)