265 using number =
typename Matrix::value_type;
291 Ai.resize(matrix.n_nonzero_elements());
292 Ax.resize(matrix.n_nonzero_elements());
294 Az.resize(matrix.n_nonzero_elements());
299 Ap[row] =
Ap[row - 1] + matrix.get_row_length(row - 1);
309 for (size_type row = row_begin; row < row_end; ++row)
311 long int index = Ap[row];
312 for (typename Matrix::const_iterator p = matrix.begin(row);
313 p != matrix.end(row);
317 Ai[index] = p->column();
318 Ax[index] = std::real(p->value());
319 if (numbers::NumberTraits<number>::is_complex == true)
320 Az[index] = std::imag(p->value());
325 Assert(index == Ap[row + 1], ExcInternalError());
328 parallel_grainsize(matrix));
337 status = umfpack_dl_symbolic(N,
342 &symbolic_decomposition,
346 status = umfpack_zl_symbolic(N,
352 &symbolic_decomposition,
356 ExcUMFPACKError(
"umfpack_dl_symbolic", status));
359 status = umfpack_dl_numeric(Ap.data(),
362 symbolic_decomposition,
363 &numeric_decomposition,
367 status = umfpack_zl_numeric(Ap.data(),
371 symbolic_decomposition,
372 &numeric_decomposition,
377 umfpack_dl_free_symbolic(&symbolic_decomposition);
378 if (status == UMFPACK_WARNING_singular_matrix)
385 "UMFPACK reports that the matrix is singular, "
386 "but that the factorization was successful anyway. "
387 "You can try and see whether you can still "
388 "solve a linear system with such a factorization "
389 "by catching and ignoring this exception, "
390 "though in practice this will typically not "
395 ExcUMFPACKError(
"umfpack_dl_numeric", status));
444# ifdef DEAL_II_WITH_COMPLEX_VALUES
474 for (
unsigned int i = 0; i < rhs_and_solution.size(); ++i)
476 rhs_re(i) = std::real(rhs_and_solution(i));
477 rhs_im(i) = std::imag(rhs_and_solution(i));
492 const int status = umfpack_zl_solve(
transpose ? UMFPACK_A : UMFPACK_Aat,
508 for (
unsigned int i = 0; i < rhs_and_solution.size(); ++i)
509 rhs_and_solution(i) = {solution_re(i), solution_im(i)};
524 for (
unsigned int i = 0; i < rhs.
size(); ++i)
525 rhs_real_or_imag(i) = std::real(rhs(i));
529 rhs_and_solution = rhs_real_or_imag;
534 for (
unsigned int i = 0; i < rhs.
size(); ++i)
535 rhs_real_or_imag(i) = std::imag(rhs(i));
539 for (
unsigned int i = 0; i < rhs.
size(); ++i)
540 rhs_and_solution(i).imag(rhs_real_or_imag(i));
545 (void)rhs_and_solution;
549 "This function can't be called if deal.II has been configured "
550 "with DEAL_II_WITH_COMPLEX_VALUES=FALSE."));
942 if constexpr (std::is_same_v<Matrix, SparseMatrix<double>>)
949 nnz = matrix.n_actually_nonzero_elements();
952 a = std::make_unique<double[]>(
nnz);
957 irn = std::make_unique<MUMPS_INT[]>(
nnz);
958 jcn = std::make_unique<MUMPS_INT[]>(
nnz);
966 for (
size_type row = 0; row < matrix.m(); ++row)
968 for (
typename Matrix::const_iterator ptr = matrix.begin(row);
969 ptr != matrix.end(row);
971 if (
std::abs(ptr->value()) > 0.0 && ptr->column() >= row)
973 a[n_non_zero_elements] = ptr->value();
974 irn[n_non_zero_elements] = row + 1;
975 jcn[n_non_zero_elements] = ptr->column() + 1;
977 ++n_non_zero_elements;
983 for (
size_type row = 0; row < matrix.m(); ++row)
985 for (
typename Matrix::const_iterator ptr = matrix.begin(row);
986 ptr != matrix.end(row);
990 a[n_non_zero_elements] = ptr->value();
991 irn[n_non_zero_elements] = row + 1;
992 jcn[n_non_zero_elements] = ptr->column() + 1;
993 ++n_non_zero_elements;
998 id.nnz = n_non_zero_elements;
1005# ifdef DEAL_II_WITH_TRILINOS
1006 std::is_same_v<Matrix, TrilinosWrappers::SparseMatrix> ||
1008 std::is_same_v<Matrix, PETScWrappers::MPI::SparseMatrix>)
1012 matrix.get_mpi_communicator(),
1015 ExcMessage(
"The matrix communicator must match the MUMPS "
1020 id.nnz = matrix.n_nonzero_elements();
1028# ifdef DEAL_II_WITH_TRILINOS
1029 if constexpr (std::is_same_v<Matrix, TrilinosWrappers::SparseMatrix>)
1031 const auto &trilinos_matrix = matrix.trilinos_matrix();
1032# ifdef DEAL_II_TRILINOS_WITH_EPETRA
1033 local_non_zeros = trilinos_matrix.NumMyNonzeros();
1035# if DEAL_II_TRILINOS_VERSION_GTE(13, 4, 0)
1036 local_non_zeros = trilinos_matrix.getLocalNumEntries();
1038 local_non_zeros = trilinos_matrix.getNodeNumEntries();
1044 if constexpr (std::is_same_v<Matrix, PETScWrappers::MPI::SparseMatrix>)
1046# ifdef DEAL_II_WITH_PETSC
1051 MatGetInfo(petsc_matrix, MAT_LOCAL, &info);
1052 local_non_zeros = (
size_type)info.nz_used;
1059 irn = std::make_unique<MUMPS_INT[]>(local_non_zeros);
1060 jcn = std::make_unique<MUMPS_INT[]>(local_non_zeros);
1061 a = std::make_unique<double[]>(local_non_zeros);
1066 if constexpr (std::is_same_v<Matrix,
1069# ifdef DEAL_II_WITH_PETSC
1074 PetscInt rstart, rend;
1075 MatGetOwnershipRange(petsc_matrix, &rstart, &rend);
1076 for (PetscInt i = rstart; i < rend; i++)
1079 const PetscInt *cols;
1080 const PetscScalar *values;
1081 MatGetRow(petsc_matrix, i, &n_cols, &cols, &values);
1083 for (PetscInt j = 0; j < n_cols; j++)
1087 irn[n_non_zero_local] = i + 1;
1088 jcn[n_non_zero_local] = cols[j] + 1;
1089 a[n_non_zero_local] = values[j];
1095 MatRestoreRow(petsc_matrix, i, &n_cols, &cols, &values);
1106# ifdef DEAL_II_WITH_TRILINOS
1107 else if constexpr (std::is_same_v<Matrix,
1110 const auto &trilinos_matrix = matrix.trilinos_matrix();
1111# ifdef DEAL_II_TRILINOS_WITH_EPETRA
1112 const unsigned int n_local_rows = trilinos_matrix.NumMyRows();
1114# if DEAL_II_TRILINOS_VERSION_GTE(13, 4, 0)
1115 const unsigned int n_local_rows =
1116 trilinos_matrix.getLocalNumRows();
1118 const unsigned int n_local_rows =
1119 trilinos_matrix.getNodeNumRows();
1122 for (
unsigned int local_row = 0; local_row < n_local_rows;
1126# ifdef DEAL_II_TRILINOS_WITH_EPETRA
1129 int ierr = trilinos_matrix.ExtractMyRowView(local_row,
1137 "Error extracting global row view from Trilinos matrix. Error code " +
1138 std::to_string(ierr) +
"."));
1140 const auto global_row =
1144 typename std::decay_t<
decltype(trilinos_matrix)>::
1145 local_inds_host_view_type local_cols;
1146 typename std::decay_t<
1147 decltype(trilinos_matrix)>::values_host_view_type values;
1149 trilinos_matrix.getLocalRowView(local_row,
1152 num_entries = local_cols.size();
1154 const auto global_row =
1155 trilinos_matrix.getRowMap()->getGlobalElement(local_row);
1158 for (
int j = 0; j < num_entries; ++j)
1160# ifdef DEAL_II_TRILINOS_WITH_EPETRA
1161 const auto global_column_id =
1165 const auto global_column_id =
1166 trilinos_matrix.getColMap()->getGlobalElement(
1169 if (global_column_id >= global_row)
1171 irn[n_non_zero_local] = global_row + 1;
1172# ifdef DEAL_II_TRILINOS_WITH_EPETRA
1173 jcn[n_non_zero_local] =
1175 trilinos_matrix, local_cols[j]) +
1178 jcn[n_non_zero_local] =
1179 trilinos_matrix.getColMap()->getGlobalElement(
1183 a[n_non_zero_local] = values[j];
1191 irhs_loc[local_row] = global_row + 1;
1204 if constexpr (std::is_same_v<Matrix,
1207# ifdef DEAL_II_WITH_PETSC
1212 PetscInt rstart, rend;
1213 MatGetOwnershipRange(petsc_matrix, &rstart, &rend);
1214 for (PetscInt i = rstart; i < rend; i++)
1217 const PetscInt *cols;
1218 const PetscScalar *values;
1219 MatGetRow(petsc_matrix, i, &n_cols, &cols, &values);
1221 for (PetscInt j = 0; j < n_cols; j++)
1223 irn[n_non_zero_local] = i + 1;
1224 jcn[n_non_zero_local] = cols[j] + 1;
1225 a[n_non_zero_local] = values[j];
1230 MatRestoreRow(petsc_matrix, i, &n_cols, &cols, &values);
1241# ifdef DEAL_II_WITH_TRILINOS
1242 else if constexpr (std::is_same_v<Matrix,
1245 const auto &trilinos_matrix = matrix.trilinos_matrix();
1246# ifdef DEAL_II_TRILINOS_WITH_EPETRA
1247 const unsigned int n_local_rows = trilinos_matrix.NumMyRows();
1249# if DEAL_II_TRILINOS_VERSION_GTE(13, 4, 0)
1250 const unsigned int n_local_rows =
1251 trilinos_matrix.getLocalNumRows();
1253 const unsigned int n_local_rows =
1254 trilinos_matrix.getNodeNumRows();
1257 for (
unsigned int local_row = 0; local_row < n_local_rows;
1261# ifdef DEAL_II_TRILINOS_WITH_EPETRA
1264 int ierr = trilinos_matrix.ExtractMyRowView(local_row,
1272 "Error extracting global row view from Trilinos matrix. Error code " +
1273 std::to_string(ierr) +
"."));
1275 typename std::decay_t<
decltype(trilinos_matrix)>::
1276 local_inds_host_view_type local_cols;
1277 typename std::decay_t<
1278 decltype(trilinos_matrix)>::values_host_view_type values;
1280 trilinos_matrix.getLocalRowView(local_row,
1283 num_entries = local_cols.size();
1286# ifdef DEAL_II_TRILINOS_WITH_EPETRA
1287 const auto global_row =
1291 const auto global_row =
1292 trilinos_matrix.getRowMap()->getGlobalElement(local_row);
1294 for (
int j = 0; j < num_entries; ++j)
1296 irn[n_non_zero_local] = global_row + 1;
1297# ifdef DEAL_II_TRILINOS_WITH_EPETRA
1298 jcn[n_non_zero_local] =
1303 jcn[n_non_zero_local] =
1304 trilinos_matrix.getColMap()->getGlobalElement(
1308 a[n_non_zero_local] = values[j];
1315 irhs_loc[local_row] = global_row + 1;
1327 id.nnz_loc = n_non_zero_local;
1328 id.irn_loc =
irn.get();
1329 id.jcn_loc =
jcn.get();
1410 if constexpr (std::is_same_v<VectorType, Vector<double>>)
1423# ifdef DEAL_II_WITH_TRILINOS
1424 std::is_same_v<VectorType, TrilinosWrappers::MPI::Vector> ||
1426 std::is_same_v<VectorType, PETScWrappers::MPI::Vector> ||
1427 std::is_same_v<VectorType, LinearAlgebra::distributed::Vector<double>>)
1429# ifdef DEAL_II_WITH_TRILINOS
1430 if constexpr (std::is_same_v<VectorType, TrilinosWrappers::MPI::Vector>)
1432# ifdef DEAL_II_TRILINOS_WITH_EPETRA
1433 id.rhs_loc =
const_cast<double *
>(src.begin());
1440 if constexpr (std::is_same_v<
1443 id.rhs_loc =
const_cast<double *
>(src.begin());
1444 else if constexpr (std::is_same_v<VectorType, PETScWrappers::MPI::Vector>)
1446# ifdef DEAL_II_WITH_PETSC
1447 PetscScalar *local_array;
1451 id.rhs_loc = local_array;
1464 rhs.resize(
id.lrhs_loc);
1465 id.rhs =
rhs.data();
1477 const IndexSet &locally_owned = dst.locally_owned_elements();
1483 const std::vector<size_type> sizes =
1485 const std::vector<types::global_dof_index> displs =
1491 std::vector<std::vector<double>> objects_to_send;
1496 objects_to_send.resize(
n_procs);
1497 for (
unsigned int proc = 0; proc <
n_procs; ++proc)
1499 objects_to_send[proc].resize(sizes[proc]);
1501 objects_to_send[proc][i] =
rhs[displs[proc] + i];
1507 const std::vector<double> local_values =
1513 dst[local_idx] = local_values[idx++];