|
2 | 2 | #include "../include/setup-libceed.h" |
3 | 3 |
|
4 | 4 | // ----------------------------------------------------------------------------- |
5 | | -// This function uses libCEED to compute the action of the Laplacian with |
6 | | -// Dirichlet boundary conditions |
| 5 | +// Apply the local action of a libCEED operator and store result in PETSc vector |
| 6 | +// i.e. compute A X = Y |
7 | 7 | // ----------------------------------------------------------------------------- |
8 | 8 | PetscErrorCode ApplyLocal_Ceed(User user, Vec X, Vec Y) { |
9 | 9 | PetscScalar *x, *y; |
@@ -55,6 +55,25 @@ PetscErrorCode MatMult_Ceed(Mat A, Vec X, Vec Y) { |
55 | 55 | PetscFunctionReturn(0); |
56 | 56 | }; |
57 | 57 |
|
| 58 | +// ----------------------------------------------------------------------------- |
| 59 | +// This function uses libCEED to compute the non-linear residual |
| 60 | +// ----------------------------------------------------------------------------- |
| 61 | +PetscErrorCode SNESFormResidual_Ceed(SNES snes, Vec X, Vec Y, void *ctx) { |
| 62 | + User user = (User)ctx; |
| 63 | + |
| 64 | + PetscFunctionBeginUser; |
| 65 | + |
| 66 | + // Use computed BCs |
| 67 | + PetscCall( VecZeroEntries(user->X_loc) ); |
| 68 | + PetscCall( DMPlexInsertBoundaryValues(user->dm, PETSC_TRUE, user->X_loc, |
| 69 | + 1.0, NULL, NULL, NULL) ); |
| 70 | + |
| 71 | + // libCEED for local action of residual evaluator |
| 72 | + PetscCall( ApplyLocalCeedOp(X, Y, user) ); |
| 73 | + |
| 74 | + PetscFunctionReturn(0); |
| 75 | +}; |
| 76 | + |
58 | 77 | // ----------------------------------------------------------------------------- |
59 | 78 | // This function calculates the error in the final solution |
60 | 79 | // ----------------------------------------------------------------------------- |
|
0 commit comments