33 PetscFunctionBeginUser;
78 PetscFunctionBeginUser;
89 TS ts, Vec u0, Vec u, PetscReal dt, PetscReal time, PetscBool *
converged)
91 TSConvergedReason reason;
92 #if !PETSC_VERSION_LESS_THAN(3, 8, 0) 93 PetscInt current_step;
97 PetscFunctionBeginUser;
98 PetscValidHeaderSpecific(ts, TS_CLASSID, 1);
99 PetscValidType(ts, 1);
100 PetscValidHeaderSpecific(u0, VEC_CLASSID, 2);
101 PetscValidType(u0, 2);
102 PetscValidHeaderSpecific(u, VEC_CLASSID, 3);
103 PetscValidType(u, 3);
104 #if PETSC_VERSION_LESS_THAN(3, 19, 3) 112 #if !PETSC_VERSION_LESS_THAN(3, 7, 0) 130 #if !PETSC_VERSION_LESS_THAN(3, 8, 0) 134 SETERRQ(PetscObjectComm((PetscObject)ts), PETSC_ERR_SUP,
"Require PETSc-3.8.x or higher ");
150 *
converged = reason > 0 ? PETSC_TRUE : PETSC_FALSE;
163 PetscInt i,
j, Mx, My, xs, ys, xm, ym;
164 PetscReal hx, hy, sx, sy;
165 PetscScalar u, uxx, uyy, **uarray, **
f, **udot;
169 PetscFunctionBeginUser;
188 hx = 1.0 / (PetscReal)(Mx - 1);
189 sx = 1.0 / (hx * hx);
190 hy = 1.0 / (PetscReal)(My - 1);
191 sy = 1.0 / (hy * hy);
211 for (
j = ys;
j < ys + ym;
j++)
213 for (i = xs; i < xs + xm; i++)
216 if (i == 0 ||
j == 0 || i == Mx - 1 ||
j == My - 1)
220 f[
j][i] = uarray[
j][i];
224 if (i == 0 &&
j == 0)
226 f[
j][i] = uarray[
j][i] - uarray[
j + 1][i + 1];
228 else if (i == Mx - 1 &&
j == 0)
230 f[
j][i] = uarray[
j][i] - uarray[
j + 1][i - 1];
232 else if (i == 0 &&
j == My - 1)
234 f[
j][i] = uarray[
j][i] - uarray[
j - 1][i + 1];
236 else if (i == Mx - 1 &&
j == My - 1)
238 f[
j][i] = uarray[
j][i] - uarray[
j - 1][i - 1];
242 f[
j][i] = uarray[
j][i] - uarray[
j][i + 1];
244 else if (i == Mx - 1)
246 f[
j][i] = uarray[
j][i] - uarray[
j][i - 1];
250 f[
j][i] = uarray[
j][i] - uarray[
j + 1][i];
252 else if (
j == My - 1)
254 f[
j][i] = uarray[
j][i] - uarray[
j - 1][i];
262 uxx = (-2.0 * u + uarray[
j][i - 1] + uarray[
j][i + 1]);
263 uyy = (-2.0 * u + uarray[
j - 1][i] + uarray[
j + 1][i]);
267 uxx = 2.0 * uxx / 3.0 + (0.5 * (uarray[
j - 1][i - 1] + uarray[
j - 1][i + 1] +
268 uarray[
j + 1][i - 1] + uarray[
j + 1][i + 1]) -
271 uyy = 2.0 * uyy / 3.0 + (0.5 * (uarray[
j - 1][i - 1] + uarray[
j - 1][i + 1] +
272 uarray[
j + 1][i - 1] + uarray[
j + 1][i + 1]) -
276 f[
j][i] = udot[
j][i] - (uxx * sx + uyy * sy);
297 TS ts, PetscReal , Vec , Vec , PetscReal
a, Mat J, Mat Jpre,
void * )
299 PetscInt i,
j, Mx, My, xs, ys, xm, ym, nc;
301 MatStencil col[5], row;
302 PetscScalar vals[5], hx, hy, sx, sy;
304 PetscFunctionBeginUser;
322 hx = 1.0 / (PetscReal)(Mx - 1);
323 sx = 1.0 / (hx * hx);
324 hy = 1.0 / (PetscReal)(My - 1);
325 sy = 1.0 / (hy * hy);
327 for (
j = ys;
j < ys + ym;
j++)
329 for (i = xs; i < xs + xm; i++)
334 if (PETSC_TRUE && (i == 0 || i == Mx - 1 ||
j == 0 ||
j == My - 1))
340 else if (PETSC_FALSE && i == 0)
349 else if (PETSC_FALSE && i == Mx - 1)
358 else if (PETSC_FALSE &&
j == 0)
367 else if (PETSC_FALSE &&
j == My - 1)
386 vals[nc++] = 2.0 * (sx + sy) +
a;
394 LibmeshPetscCallQ(MatSetValuesStencil(Jpre, 1, &row, nc, col, vals, INSERT_VALUES));
414 PetscInt i,
j, xs, ys, xm, ym, Mx, My;
416 PetscReal hx, hy,
x,
y, r;
418 PetscFunctionBeginUser;
435 hx = 1.0 / (PetscReal)(Mx - 1);
436 hy = 1.0 / (PetscReal)(My - 1);
445 for (
j = ys;
j < ys + ym;
j++)
448 for (i = xs; i < xs + xm; i++)
451 r = PetscSqrtReal((
x - .5) * (
x - .5) + (
y - .5) * (
y - .5));
453 u[
j][i] = PetscExpReal(
c * r * r * r);
PetscErrorCode FormIJacobian(TS ts, PetscReal, Vec, Vec, PetscReal a, Mat J, Mat Jpre, void *)
PetscErrorCode FormIFunction(TS ts, PetscReal, Vec U, Vec Udot, Vec F, void *)
const std::vector< double > y
static const std::string F
bool converged(const std::vector< std::pair< unsigned int, Real >> &residuals, const std::vector< Real > &abs_tolerances)
Based on the residuals, determine if the iterative process converged or not.
PetscErrorCode PETScExternalSolverCreate(MPI_Comm comm, TS *ts)
const std::vector< double > x
Real f(Real x)
Test function for Brents method.
PetscErrorCode PETScExternalSolverDestroy(TS ts)
LibmeshPetscCallQ(DMShellGetContext(dm, &ctx))
PetscErrorCode FormInitialSolution(TS ts, Vec U, void *)
PetscErrorCode externalPETScDiffusionFDMSolve(TS ts, Vec u0, Vec u, PetscReal dt, PetscReal time, PetscBool *converged)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
PetscFunctionReturn(LIBMESH_PETSC_SUCCESS)