@@ -74,10 +74,10 @@ static inline PetscErrorCode ComputeSUPGStabilization(PetscInt dim, PetscReal h,
74
74
PetscFunctionReturn (PETSC_SUCCESS );
75
75
}
76
76
77
- // Dirichlet BC: u = 1 .0 (for inflow boundaries)
77
+ // Dirichlet BC: u = 0 .0 (for inflow boundaries)
78
78
static PetscErrorCode dirichlet_bc (PetscInt dim , PetscReal time , const PetscReal x [], PetscInt Nc , PetscScalar * u , void * ctx )
79
79
{
80
- u [0 ] = 1 .0 ;
80
+ u [0 ] = 0 .0 ;
81
81
return PETSC_SUCCESS ;
82
82
}
83
83
@@ -389,6 +389,9 @@ int main(int argc, char **argv)
389
389
PetscCall (PetscInitialize (& argc , & argv , NULL , help ));
390
390
PetscCall (ProcessOptions (PETSC_COMM_WORLD , & options ));
391
391
392
+ PetscBool second_solve = PETSC_FALSE ;
393
+ PetscOptionsGetBool (NULL , NULL , "-second_solve" , & second_solve , NULL );
394
+
392
395
// Register the pflare types
393
396
PCRegister_PFLARE ();
394
397
@@ -401,15 +404,29 @@ int main(int argc, char **argv)
401
404
PetscCall (SetupSUPG (dm ));
402
405
403
406
PetscCall (DMCreateGlobalVector (dm , & u ));
404
- PetscCall (VecSet (u , 0 .0 ));
407
+ PetscCall (VecSet (u , 1 .0 ));
405
408
PetscCall (PetscObjectSetName ((PetscObject )u , "adv_diff" ));
406
409
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 ));
407
414
408
415
// Only solving a linear problem for now
409
416
PetscCall (SNESSetType (snes , SNESKSPONLY ));
410
417
411
418
PetscCall (SNESSetFromOptions (snes ));
412
419
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
+
413
430
PetscCall (SNESGetSolution (snes , & u ));
414
431
/* Cleanup */
415
432
PetscCall (VecDestroy (& u ));
0 commit comments