186 const SparsityPatternType &sparsity_pattern)
191 sparsity_pattern.n_rows()),
192 sparsity_pattern.n_rows());
194 sparsity_pattern.n_cols()),
195 sparsity_pattern.n_cols());
197 Assert(sparsity_pattern.n_rows() == local_rows.
size(),
199 "SparsityPattern and IndexSet have different number of rows"));
201 sparsity_pattern.n_cols() == local_columns.
size(),
203 "SparsityPattern and IndexSet have different number of columns"));
205 ExcMessage(
"PETSc only supports contiguous row/column ranges"));
216 Assert(row_owners == sparsity_pattern.n_rows(),
219 "Each row has to be owned by exactly one owner (n_rows()=") +
220 std::to_string(sparsity_pattern.n_rows()) +
221 " but sum(local_rows.n_elements())=" +
222 std::to_string(row_owners) +
")"));
224 col_owners == sparsity_pattern.n_cols(),
227 "Each column has to be owned by exactly one owner (n_cols()=") +
228 std::to_string(sparsity_pattern.n_cols()) +
229 " but sum(local_columns.n_elements())=" +
230 std::to_string(col_owners) +
")"));
237 PetscErrorCode ierr = MatCreate(communicator, &
matrix);
240 ierr = MatSetSizes(
matrix,
243 sparsity_pattern.n_rows(),
244 sparsity_pattern.n_cols());
250 ierr = MatSetType(
matrix, MATAIJ);
274 const PetscInt local_row_end =
284 std::vector<PetscInt> rowstart_in_window(local_row_end -
289 unsigned int n_cols = 0;
290 for (PetscInt i = local_row_start; i < local_row_end; ++i)
292 const PetscInt
row_length = sparsity_pattern.row_length(i);
293 rowstart_in_window[i + 1 - local_row_start] =
294 rowstart_in_window[i - local_row_start] +
row_length;
297 colnums_in_window.resize(n_cols + 1, -1);
303 PetscInt *ptr = colnums_in_window.data();
304 for (PetscInt i = local_row_start; i < local_row_end; ++i)
305 for (
typename SparsityPatternType::iterator p =
306 sparsity_pattern.begin(i);
307 p != sparsity_pattern.end(i);
320 ierr = MatMPIAIJSetPreallocationCSR(
matrix,
321 rowstart_in_window.data(),
322 colnums_in_window.data(),
324 ierr = MatSeqAIJSetPreallocationCSR(
matrix,
325 rowstart_in_window.data(),
326 colnums_in_window.data(),
334 ierr = MatSeqAIJSetPreallocationCSR(
matrix, &i, &i,
nullptr);
336 ierr = MatMPIAIJSetPreallocationCSR(
matrix, &i, &i,
nullptr);
352 const SparsityPatternType &sparsity_pattern,
353 const std::vector<size_type> &local_rows_per_process,
354 const std::vector<size_type> &local_columns_per_process,
355 const unsigned int this_process,
356 const bool preset_nonzero_locations)
358 Assert(local_rows_per_process.size() == local_columns_per_process.size(),
360 local_columns_per_process.size()));
366 sparsity_pattern.n_rows()),
367 sparsity_pattern.n_rows());
369 sparsity_pattern.n_cols()),
370 sparsity_pattern.n_cols());
380 for (
unsigned int p = 0; p < this_process; ++p)
381 local_row_start += local_rows_per_process[p];
383 local_row_start + local_rows_per_process[this_process];
388 PetscErrorCode ierr = MatCreate(communicator, &
matrix);
391 ierr = MatSetSizes(
matrix,
392 local_rows_per_process[this_process],
393 local_columns_per_process[this_process],
394 sparsity_pattern.n_rows(),
395 sparsity_pattern.n_cols());
401 ierr = MatSetType(
matrix, MATAIJ);
417 if (preset_nonzero_locations ==
true)
430 std::vector<PetscInt> rowstart_in_window(local_row_end -
436 for (
size_type i = local_row_start; i < local_row_end; ++i)
439 const auto row_start =
440 rowstart_in_window[i - local_row_start] +
row_length;
441 const auto petsc_row_start =
static_cast<PetscInt
>(row_start);
443 rowstart_in_window[i + 1 - local_row_start] = petsc_row_start;
446 colnums_in_window.resize(n_cols + 1, -1);
452 PetscInt *ptr = colnums_in_window.data();
453 for (
size_type i = local_row_start; i < local_row_end; ++i)
454 for (
typename SparsityPatternType::iterator p =
455 sparsity_pattern.begin(i);
456 p != sparsity_pattern.end(i);
459 const auto petsc_column =
static_cast<PetscInt
>(p->column());
473 ierr = MatSeqAIJSetPreallocationCSR(
matrix,
474 rowstart_in_window.data(),
475 colnums_in_window.data(),
477 ierr = MatMPIAIJSetPreallocationCSR(
matrix,
478 rowstart_in_window.data(),
479 colnums_in_window.data(),
495 const IndexSet &local_active_columns,
496 const SparsityPatternType &sparsity_pattern)
501 sparsity_pattern.n_rows()),
502 sparsity_pattern.n_rows());
504 sparsity_pattern.n_cols()),
505 sparsity_pattern.n_cols());
507# if DEAL_II_PETSC_VERSION_GTE(3, 10, 0)
508 Assert(sparsity_pattern.n_rows() == local_rows.
size(),
510 "SparsityPattern and IndexSet have different number of rows."));
512 sparsity_pattern.n_cols() == local_columns.
size(),
514 "SparsityPattern and IndexSet have different number of columns"));
516 ExcMessage(
"PETSc only supports contiguous row/column ranges"));
527 Assert(row_owners == sparsity_pattern.n_rows(),
530 "Each row has to be owned by exactly one owner (n_rows()=") +
531 std::to_string(sparsity_pattern.n_rows()) +
532 " but sum(local_rows.n_elements())=" +
533 std::to_string(row_owners) +
")"));
535 col_owners == sparsity_pattern.n_cols(),
538 "Each column has to be owned by exactly one owner (n_cols()=") +
539 std::to_string(sparsity_pattern.n_cols()) +
540 " but sum(local_columns.n_elements())=" +
541 std::to_string(col_owners) +
")"));
551 std::vector<PetscInt> idx_glob_row(n_local_active_rows);
552 std::vector<PetscInt> idx_glob_col(n_local_active_cols);
563 IS is_glob_row, is_glob_col;
565 ISLocalToGlobalMapping l2gmap_row;
566 ierr = ISCreateGeneral(communicator,
572 ierr = ISLocalToGlobalMappingCreateIS(is_glob_row, &l2gmap_row);
574 ierr = ISDestroy(&is_glob_row);
577 ISLocalToGlobalMappingViewFromOptions(l2gmap_row,
nullptr,
"-view_map");
581 ISLocalToGlobalMapping l2gmap_col;
582 ierr = ISCreateGeneral(communicator,
588 ierr = ISLocalToGlobalMappingCreateIS(is_glob_col, &l2gmap_col);
590 ierr = ISDestroy(&is_glob_col);
593 ISLocalToGlobalMappingViewFromOptions(l2gmap_col,
nullptr,
"-view_map");
597 ierr = MatCreateIS(communicator,
601 sparsity_pattern.n_rows(),
602 sparsity_pattern.n_cols(),
607 ierr = ISLocalToGlobalMappingDestroy(&l2gmap_row);
609 ierr = ISLocalToGlobalMappingDestroy(&l2gmap_col);
626 ierr = MatISGetLocalMat(
matrix, &local_matrix);
628 ierr = MatSetType(local_matrix,
637 const PetscInt local_row_start = 0;
638 const PetscInt local_row_end = local_active_rows.
n_elements();
643 std::vector<PetscInt> rowstart_in_window(local_row_end -
647 unsigned int global_row_index = 0;
649 unsigned int n_cols = 0;
650 unsigned int global_row_index = 0;
651 for (PetscInt i = local_row_start; i < local_row_end; ++i)
655 sparsity_pattern.row_length(global_row_index);
656 rowstart_in_window[i + 1 - local_row_start] =
657 rowstart_in_window[i - local_row_start] +
row_length;
660 colnums_in_window.resize(n_cols + 1, -1);
667 std::map<unsigned int, unsigned int> loc_act_cols_inv;
668 for (
unsigned int i = 0; i < local_active_columns.
n_elements(); ++i)
674 PetscInt *ptr = colnums_in_window.data();
675 for (PetscInt i = local_row_start; i < local_row_end; ++i)
678 for (
typename SparsityPatternType::iterator p =
679 sparsity_pattern.begin(global_row_index);
680 p != sparsity_pattern.end(global_row_index);
682 *ptr = loc_act_cols_inv[p->column()];
689 ierr = MatSeqAIJSetPreallocationCSR(local_matrix,
690 rowstart_in_window.data(),
691 colnums_in_window.data(),
698 ierr = MatSeqAIJSetPreallocationCSR(local_matrix, &i, &i,
nullptr);
707 ierr = MatISRestoreLocalMat(
matrix, &local_matrix);
714 (void)local_active_rows;
716 (void)local_active_columns;
717 (void)sparsity_pattern;
720 "BDDC preconditioner requires PETSc 3.10.0 or newer"));