18#ifdef DEAL_II_WITH_PETSC
34 ierr = MatCreate(
comm, &dummy);
36 ierr = MatSetSizes(dummy, lr, lc, gr, gc);
38 ierr = MatSetType(dummy, MATAIJ);
40 ierr = MatSeqAIJSetPreallocation(dummy, 0,
nullptr);
42 ierr = MatMPIAIJSetPreallocation(dummy, 0,
nullptr, 0,
nullptr);
44 ierr = MatSetUp(dummy);
46 ierr = MatSetOption(dummy, MAT_NO_OFF_PROC_ENTRIES, PETSC_TRUE);
48 ierr = MatAssemblyBegin(dummy, MAT_FINAL_ASSEMBLY);
50 ierr = MatAssemblyEnd(dummy, MAT_FINAL_ASSEMBLY);
93 this->
sub_objects.reinit(n_block_rows, n_block_columns);
111 const std::vector<IndexSet> &cols,
122 std::vector<types::global_dof_index> row_sizes;
127 std::vector<types::global_dof_index> col_sizes;
141 p->
reinit(rows[r], cols[c], bdsp.
block(r, c), com);
153 reinit(sizes, sizes, bdsp, com);
168 std::vector<size_type> row_sizes(
m,
size_type(-1));
169 std::vector<size_type> col_sizes(
n,
size_type(-1));
170 std::vector<size_type> row_local_sizes(
m,
size_type(-1));
171 std::vector<size_type> col_local_sizes(
n,
size_type(-1));
182 row_local_sizes[r] = this->
sub_objects[r][c]->local_size();
197 "When passing empty sub-blocks of a block matrix, you need to make "
198 "sure that at least one block in each block row and block column is "
199 "non-empty. However, block row " +
201 " is completely empty "
202 "and so it is not possible to determine how many rows it should have."));
206 "When passing empty sub-blocks of a block matrix, you need to make "
207 "sure that at least one block in each block row and block column is "
208 "non-empty. However, block column " +
210 " is completely empty "
211 "and so it is not possible to determine how many columns it should have."));
212 Mat dummy = ::create_dummy_mat(
214 static_cast<PetscInt
>(row_local_sizes[r]),
215 static_cast<PetscInt
>(row_sizes[r]),
216 static_cast<PetscInt
>(col_local_sizes[c]),
217 static_cast<PetscInt
>(col_sizes[c]));
222 ierr = MatDestroy(&dummy);
249 std::vector<Mat> psub_objects(
m *
n);
250 for (
unsigned int r = 0; r <
m; r++)
251 for (
unsigned int c = 0; c <
n; c++)
254 psub_objects[r *
n + c] = this->
sub_objects[r][c]->petsc_matrix();
256 ierr = MatCreateNest(
275 std::vector<IndexSet>
278 std::vector<IndexSet> index_sets;
281 index_sets.push_back(this->block(0, i).locally_owned_domain_indices());
288 std::vector<IndexSet>
291 std::vector<IndexSet> index_sets;
294 index_sets.push_back(this->block(i, 0).locally_owned_range_indices());
304 std::uint64_t n_nonzero = 0;
320 BlockSparseMatrix::operator
const Mat &()
const
322 return petsc_nest_matrix;
339 PetscInt nr = 1, nc = 1;
341 PetscErrorCode ierr =
342 PetscObjectTypeCompare(
reinterpret_cast<PetscObject
>(A),
346 std::vector<Mat> mats;
347 bool need_empty_matrices =
false;
350 ierr = MatNestGetSize(A, &nr, &nc);
352 for (PetscInt i = 0; i < nr; ++i)
354 for (PetscInt j = 0; j < nc; ++j)
357 ierr = MatNestGetSubMat(A, i, j, &sA);
360 need_empty_matrices =
true;
369 std::vector<size_type> r_block_sizes(nr, 0);
370 std::vector<size_type> c_block_sizes(nc, 0);
374 for (PetscInt i = 0; i < nr; ++i)
376 for (PetscInt j = 0; j < nc; ++j)
378 if (mats[i * nc + j])
384 if (need_empty_matrices)
388 if (need_empty_matrices || !isnest)
394 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)