Skip to content

Commit 4af980f

Browse files
committed
Added SNESFormResidual
1 parent 076cd31 commit 4af980f

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

examples/Hdiv-mixed/include/matops.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
PetscErrorCode ApplyLocal_Ceed(User user, Vec X, Vec Y);
1010
PetscErrorCode MatMult_Ceed(Mat A, Vec X, Vec Y);
11+
PetscErrorCode SNESFormResidual_Ceed(SNES snes, Vec X, Vec Y, void *ctx);
1112
PetscErrorCode ComputeError(User user, Vec X, CeedVector target,
1213
CeedScalar *l2_error_u, CeedScalar *l2_error_p);
1314

examples/Hdiv-mixed/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ int main(int argc, char **argv) {
8888
CeedMemType mem_type_backend;
8989
CeedGetPreferredMemType(ceed, &mem_type_backend);
9090
// ---------------------------------------------------------------------------
91-
// Set-up DM
91+
// Setup DM
9292
// ---------------------------------------------------------------------------
9393
// PETSc objects
9494
DM dm;

examples/Hdiv-mixed/src/matops.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#include "../include/setup-libceed.h"
33

44
// -----------------------------------------------------------------------------
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
77
// -----------------------------------------------------------------------------
88
PetscErrorCode ApplyLocal_Ceed(User user, Vec X, Vec Y) {
99
PetscScalar *x, *y;
@@ -55,6 +55,25 @@ PetscErrorCode MatMult_Ceed(Mat A, Vec X, Vec Y) {
5555
PetscFunctionReturn(0);
5656
};
5757

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+
5877
// -----------------------------------------------------------------------------
5978
// This function calculates the error in the final solution
6079
// -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)