19#ifdef DEAL_II_WITH_PETSC
29#ifdef DEAL_II_WITH_PETSC
45 ierr = MatCreate(
comm, &dummy);
47 ierr = MatSetSizes(dummy, lr, lc, gr, gc);
49 ierr = MatSetType(dummy, MATAIJ);
51 ierr = MatSeqAIJSetPreallocation(dummy, 0,
nullptr);
53 ierr = MatMPIAIJSetPreallocation(dummy, 0,
nullptr, 0,
nullptr);
55 ierr = MatSetUp(dummy);
57 ierr = MatSetOption(dummy, MAT_NO_OFF_PROC_ENTRIES, PETSC_TRUE);
59 ierr = MatAssemblyBegin(dummy, MAT_FINAL_ASSEMBLY);
61 ierr = MatAssemblyEnd(dummy, MAT_FINAL_ASSEMBLY);
102 this->
sub_objects.reinit(n_block_rows, n_block_columns);
120 const std::vector<IndexSet> &cols,
131 std::vector<types::global_dof_index> row_sizes;
137 std::vector<types::global_dof_index> col_sizes;
152 p->
reinit(rows[r], cols[c], bdsp.
block(r, c), com);
164 reinit(sizes, sizes, bdsp, com);
179 std::vector<size_type> row_sizes(
m,
size_type(-1));
180 std::vector<size_type> col_sizes(
n,
size_type(-1));
181 std::vector<size_type> row_local_sizes(
m,
size_type(-1));
182 std::vector<size_type> col_local_sizes(
n,
size_type(-1));
193 row_local_sizes[r] = this->
sub_objects[r][c]->local_size();
208 "When passing empty sub-blocks of a block matrix, you need to make "
209 "sure that at least one block in each block row and block column is "
210 "non-empty. However, block row " +
212 " is completely empty "
213 "and so it is not possible to determine how many rows it should have."));
217 "When passing empty sub-blocks of a block matrix, you need to make "
218 "sure that at least one block in each block row and block column is "
219 "non-empty. However, block column " +
221 " is completely empty "
222 "and so it is not possible to determine how many columns it should have."));
224 create_dummy_mat(
comm,
225 static_cast<PetscInt
>(row_local_sizes[r]),
226 static_cast<PetscInt
>(row_sizes[r]),
227 static_cast<PetscInt
>(col_local_sizes[c]),
228 static_cast<PetscInt
>(col_sizes[c]));
233 ierr = MatDestroy(&dummy);
260 std::vector<Mat> psub_objects(
m *
n);
261 for (
unsigned int r = 0; r <
m; r++)
262 for (
unsigned int c = 0; c <
n; c++)
265 psub_objects[r *
n + c] = this->
sub_objects[r][c]->petsc_matrix();
267 ierr = MatCreateNest(
286 std::vector<IndexSet>
289 std::vector<IndexSet> index_sets;
293 index_sets.push_back(this->block(0, i).locally_owned_domain_indices());
300 std::vector<IndexSet>
303 std::vector<IndexSet> index_sets;
307 index_sets.push_back(this->block(i, 0).locally_owned_range_indices());
317 std::uint64_t n_nonzero = 0;
333 BlockSparseMatrix::operator
const Mat &()
const
335 return petsc_nest_matrix;
352 PetscInt nr = 1, nc = 1;
354 PetscErrorCode ierr =
355 PetscObjectTypeCompare(
reinterpret_cast<PetscObject
>(A),
359 std::vector<Mat> mats;
360 bool need_empty_matrices =
false;
363 ierr = MatNestGetSize(A, &nr, &nc);
365 for (PetscInt i = 0; i < nr; ++i)
367 for (PetscInt j = 0; j < nc; ++j)
370 ierr = MatNestGetSubMat(A, i, j, &sA);
373 need_empty_matrices =
true;
382 std::vector<size_type> r_block_sizes(nr, 0);
383 std::vector<size_type> c_block_sizes(nc, 0);
387 for (PetscInt i = 0; i < nr; ++i)
389 for (PetscInt j = 0; j < nc; ++j)
391 if (mats[i * nc + j])
397 if (need_empty_matrices)
401 if (need_empty_matrices || !isnest)
407 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)