Skip to content

Commit 60ba68d

Browse files
Merge pull request #101 from PFLAREProject/second_solve_cg_supg
Added second solve option to SUPG CG FEM example
2 parents 3fdb505 + 9e31dfb commit 60ba68d

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

tests/adv_diff_cg_supg.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ static inline PetscErrorCode ComputeSUPGStabilization(PetscInt dim, PetscReal h,
7474
PetscFunctionReturn(PETSC_SUCCESS);
7575
}
7676

77-
// Dirichlet BC: u = 1.0 (for inflow boundaries)
77+
// Dirichlet BC: u = 0.0 (for inflow boundaries)
7878
static PetscErrorCode dirichlet_bc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
7979
{
80-
u[0] = 1.0;
80+
u[0] = 0.0;
8181
return PETSC_SUCCESS;
8282
}
8383

@@ -389,6 +389,9 @@ int main(int argc, char **argv)
389389
PetscCall(PetscInitialize(&argc, &argv, NULL, help));
390390
PetscCall(ProcessOptions(PETSC_COMM_WORLD, &options));
391391

392+
PetscBool second_solve= PETSC_FALSE;
393+
PetscOptionsGetBool(NULL, NULL, "-second_solve", &second_solve, NULL);
394+
392395
// Register the pflare types
393396
PCRegister_PFLARE();
394397

@@ -401,15 +404,29 @@ int main(int argc, char **argv)
401404
PetscCall(SetupSUPG(dm));
402405

403406
PetscCall(DMCreateGlobalVector(dm, &u));
404-
PetscCall(VecSet(u, 0.0));
407+
PetscCall(VecSet(u, 1.0));
405408
PetscCall(PetscObjectSetName((PetscObject)u, "adv_diff"));
406409
PetscCall(DMPlexSetSNESLocalFEM(dm, PETSC_FALSE, &options));
410+
// Only compute the jacobian once in case we're doing a second solve
411+
PetscInt lag = -2;
412+
PetscCall(SNESSetLagPreconditioner(snes, lag));
413+
PetscCall(SNESSetLagJacobian(snes, lag));
407414

408415
// Only solving a linear problem for now
409416
PetscCall(SNESSetType(snes, SNESKSPONLY));
410417

411418
PetscCall(SNESSetFromOptions(snes));
412419
PetscCall(SNESSolve(snes, NULL, u));
420+
421+
// Solve
422+
// We set x to 1 rather than random as the vecrandom doesn't yet have a
423+
// gpu implementation and we don't want a copy occuring back to the cpu
424+
if (second_solve)
425+
{
426+
PetscCall(VecSet(u, 1.0));
427+
PetscCall(SNESSolve(snes, NULL, u));
428+
}
429+
413430
PetscCall(SNESGetSolution(snes, &u));
414431
/* Cleanup */
415432
PetscCall(VecDestroy(&u));

0 commit comments

Comments
 (0)