79 ierr = KSPSetInitialGuessNonzero(
m_KSP, PETSC_TRUE);
80 PISM_CHK(ierr,
"KSPSetInitialGuessNonzero");
82 ierr = KSPSetInitialGuessNonzero(
m_KSP, PETSC_FALSE);
83 PISM_CHK(ierr,
"KSPSetInitialGuessNonzero");
98 KSPConvergedReason reason;
99 ierr = KSPGetConvergedReason(
m_KSP, &reason);
100 PISM_CHK(ierr,
"KSPGetConvergedReason");
105 "PISM ERROR: KSP iteration failed while solving the Poisson equation\n"
106 " reason = %d = '%s'\n",
107 reason, KSPConvergedReasons[reason]);
110 KSPConvergedReasons[reason]);
114 PetscInt ksp_iterations = 0;
115 ierr = KSPGetIterationNumber(
m_KSP, &ksp_iterations);
116 PISM_CHK(ierr,
"KSPGetIterationNumber");
118 return ksp_iterations;
160 PetscErrorCode ierr = 0;
165 C_x = 1.0 / (dx * dx),
166 C_y = 1.0 / (dy * dy);
174 ierr = MatZeroEntries(A);
PISM_CHK(ierr,
"MatZeroEntries");
181 MatStencil row, col[ncol];
184 for (
int m = 0; m < ncol; m++) {
188 for (
auto p =
m_grid->points(); p; p.next()) {
189 const int i = p.i(), j = p.j();
200 const int I[] = {i, i - 1, i, i + 1, i};
203 const int J[] = {j + 1, j, j, j, j - 1};
208 for (
int m = 0; m < ncol; m++) {
213 auto M = mask.
star(i, j);
220 N = M.n == 2 ? 0.0 : 1.0,
221 E = M.e == 2 ? 0.0 : 1.0,
222 W = M.w == 2 ? 0.0 : 1.0,
223 S = M.s == 2 ? 0.0 : 1.0;
227 N = j == My - 1 ? 0.0 : N;
228 E = i == Mx - 1 ? 0.0 : E;
229 W = i == 0 ? 0.0 : W;
230 S = j == 0 ? 0.0 :
S;
234 double L[ncol] = {- N * C_y,
235 - W * C_x, (W + E) * C_x + (N +
S) * C_y, - E * C_x,
238 ierr = MatSetValuesStencil(A, nrow, &row, ncol, col,
L, INSERT_VALUES);
239 PISM_CHK(ierr,
"MatSetValuesStencil");
243 double D[ncol] = {0.0,
247 ierr = MatSetValuesStencil(A, nrow, &row, ncol, col,
D, INSERT_VALUES);
248 PISM_CHK(ierr,
"MatSetValuesStencil");
257 ierr = MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
PISM_CHK(ierr,
"MatAssemblyBegin");
258 ierr = MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);
PISM_CHK(ierr,
"MatAssemblyif");
261 ierr = MatSetOption(A, MAT_NEW_NONZERO_LOCATION_ERR, PETSC_TRUE);