186 const SparsityPatternType &sparsity_pattern)
188 Assert(sparsity_pattern.n_rows() == local_rows.
size(),
190 "SparsityPattern and IndexSet have different number of rows"));
192 sparsity_pattern.n_cols() == local_columns.
size(),
194 "SparsityPattern and IndexSet have different number of columns"));
196 ExcMessage(
"PETSc only supports contiguous row/column ranges"));
207 Assert(row_owners == sparsity_pattern.n_rows(),
210 "Each row has to be owned by exactly one owner (n_rows()=") +
211 std::to_string(sparsity_pattern.n_rows()) +
212 " but sum(local_rows.n_elements())=" +
213 std::to_string(row_owners) +
")"));
215 col_owners == sparsity_pattern.n_cols(),
218 "Each column has to be owned by exactly one owner (n_cols()=") +
219 std::to_string(sparsity_pattern.n_cols()) +
220 " but sum(local_columns.n_elements())=" +
221 std::to_string(col_owners) +
")"));
228 PetscErrorCode ierr = MatCreate(communicator, &
matrix);
231 ierr = MatSetSizes(
matrix,
234 sparsity_pattern.n_rows(),
235 sparsity_pattern.n_cols());
241 ierr = MatSetType(
matrix, MATAIJ);
265 const PetscInt local_row_end =
275 std::vector<PetscInt>
277 rowstart_in_window(local_row_end - local_row_start + 1, 0),
280 unsigned int n_cols = 0;
281 for (PetscInt i = local_row_start; i < local_row_end; ++i)
283 const PetscInt
row_length = sparsity_pattern.row_length(i);
284 rowstart_in_window[i + 1 - local_row_start] =
285 rowstart_in_window[i - local_row_start] +
row_length;
288 colnums_in_window.resize(n_cols + 1, -1);
294 PetscInt *ptr = colnums_in_window.data();
295 for (PetscInt i = local_row_start; i < local_row_end; ++i)
296 for (
typename SparsityPatternType::iterator p =
297 sparsity_pattern.begin(i);
298 p != sparsity_pattern.end(i);
311 ierr = MatMPIAIJSetPreallocationCSR(
matrix,
312 rowstart_in_window.data(),
313 colnums_in_window.data(),
315 ierr = MatSeqAIJSetPreallocationCSR(
matrix,
316 rowstart_in_window.data(),
317 colnums_in_window.data(),
325 ierr = MatSeqAIJSetPreallocationCSR(
matrix, &i, &i,
nullptr);
327 ierr = MatMPIAIJSetPreallocationCSR(
matrix, &i, &i,
nullptr);
343 const SparsityPatternType &sparsity_pattern,
344 const std::vector<size_type> &local_rows_per_process,
345 const std::vector<size_type> &local_columns_per_process,
346 const unsigned int this_process,
347 const bool preset_nonzero_locations)
349 Assert(local_rows_per_process.size() == local_columns_per_process.size(),
351 local_columns_per_process.size()));
363 for (
unsigned int p = 0; p < this_process; ++p)
364 local_row_start += local_rows_per_process[p];
366 local_row_start + local_rows_per_process[this_process];
371 PetscErrorCode ierr = MatCreate(communicator, &
matrix);
374 ierr = MatSetSizes(
matrix,
375 local_rows_per_process[this_process],
376 local_columns_per_process[this_process],
377 sparsity_pattern.n_rows(),
378 sparsity_pattern.n_cols());
384 ierr = MatSetType(
matrix, MATAIJ);
400 if (preset_nonzero_locations ==
true)
413 std::vector<PetscInt>
415 rowstart_in_window(local_row_end - local_row_start + 1, 0),
419 for (
size_type i = local_row_start; i < local_row_end; ++i)
422 rowstart_in_window[i + 1 - local_row_start] =
423 rowstart_in_window[i - local_row_start] +
row_length;
426 colnums_in_window.resize(n_cols + 1, -1);
432 PetscInt *ptr = colnums_in_window.data();
433 for (
size_type i = local_row_start; i < local_row_end; ++i)
434 for (
typename SparsityPatternType::iterator p =
435 sparsity_pattern.begin(i);
436 p != sparsity_pattern.end(i);
449 ierr = MatSeqAIJSetPreallocationCSR(
matrix,
450 rowstart_in_window.data(),
451 colnums_in_window.data(),
453 ierr = MatMPIAIJSetPreallocationCSR(
matrix,
454 rowstart_in_window.data(),
455 colnums_in_window.data(),
471 const IndexSet &local_active_columns,
472 const SparsityPatternType &sparsity_pattern)
474# if DEAL_II_PETSC_VERSION_GTE(3, 10, 0)
475 Assert(sparsity_pattern.n_rows() == local_rows.
size(),
477 "SparsityPattern and IndexSet have different number of rows."));
479 sparsity_pattern.n_cols() == local_columns.
size(),
481 "SparsityPattern and IndexSet have different number of columns"));
483 ExcMessage(
"PETSc only supports contiguous row/column ranges"));
494 Assert(row_owners == sparsity_pattern.n_rows(),
497 "Each row has to be owned by exactly one owner (n_rows()=") +
498 std::to_string(sparsity_pattern.n_rows()) +
499 " but sum(local_rows.n_elements())=" +
500 std::to_string(row_owners) +
")"));
502 col_owners == sparsity_pattern.n_cols(),
505 "Each column has to be owned by exactly one owner (n_cols()=") +
506 std::to_string(sparsity_pattern.n_cols()) +
507 " but sum(local_columns.n_elements())=" +
508 std::to_string(col_owners) +
")"));
518 std::vector<PetscInt> idx_glob_row(n_local_active_rows);
519 std::vector<PetscInt> idx_glob_col(n_local_active_cols);
530 IS is_glob_row, is_glob_col;
532 ISLocalToGlobalMapping l2gmap_row;
533 ierr = ISCreateGeneral(communicator,
539 ierr = ISLocalToGlobalMappingCreateIS(is_glob_row, &l2gmap_row);
541 ierr = ISDestroy(&is_glob_row);
544 ISLocalToGlobalMappingViewFromOptions(l2gmap_row,
nullptr,
"-view_map");
548 ISLocalToGlobalMapping l2gmap_col;
549 ierr = ISCreateGeneral(communicator,
555 ierr = ISLocalToGlobalMappingCreateIS(is_glob_col, &l2gmap_col);
557 ierr = ISDestroy(&is_glob_col);
560 ISLocalToGlobalMappingViewFromOptions(l2gmap_col,
nullptr,
"-view_map");
564 ierr = MatCreateIS(communicator,
568 sparsity_pattern.n_rows(),
569 sparsity_pattern.n_cols(),
574 ierr = ISLocalToGlobalMappingDestroy(&l2gmap_row);
576 ierr = ISLocalToGlobalMappingDestroy(&l2gmap_col);
593 ierr = MatISGetLocalMat(
matrix, &local_matrix);
595 ierr = MatSetType(local_matrix,
604 const PetscInt local_row_start = 0;
605 const PetscInt local_row_end = local_active_rows.
n_elements();
610 std::vector<PetscInt> rowstart_in_window(local_row_end -
614 unsigned int global_row_index = 0;
616 unsigned int n_cols = 0;
617 unsigned int global_row_index = 0;
618 for (PetscInt i = local_row_start; i < local_row_end; ++i)
622 sparsity_pattern.row_length(global_row_index);
623 rowstart_in_window[i + 1 - local_row_start] =
624 rowstart_in_window[i - local_row_start] +
row_length;
627 colnums_in_window.resize(n_cols + 1, -1);
634 std::map<unsigned int, unsigned int> loc_act_cols_inv;
635 for (
unsigned int i = 0; i < local_active_columns.
n_elements(); ++i)
641 PetscInt *ptr = colnums_in_window.data();
642 for (PetscInt i = local_row_start; i < local_row_end; ++i)
645 for (
typename SparsityPatternType::iterator p =
646 sparsity_pattern.begin(global_row_index);
647 p != sparsity_pattern.end(global_row_index);
649 *ptr = loc_act_cols_inv[p->column()];
656 ierr = MatSeqAIJSetPreallocationCSR(local_matrix,
657 rowstart_in_window.data(),
658 colnums_in_window.data(),
665 ierr = MatSeqAIJSetPreallocationCSR(local_matrix, &i, &i,
nullptr);
674 ierr = MatISRestoreLocalMat(
matrix, &local_matrix);
681 (void)local_active_rows;
683 (void)local_active_columns;
684 (void)sparsity_pattern;
687 "BDDC preconditioner requires PETSc 3.10.0 or newer"));