xref: /petsc/src/snes/impls/shell/ftn-custom/zsnesshellf.c (revision c8b0c2b58db46088bcb0f3a2497e96cb9efa794b)
1 #include <petsc/private/ftnimpl.h>
2 #include <petscsnes.h>
3 
4 #if defined(PETSC_HAVE_FORTRAN_CAPS)
5   #define snesshellsetsolve_ SNESSHELLSETSOLVE
6 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
7   #define snesshellsetsolve_ snesshellsetsolve
8 #endif
9 
10 static PetscErrorCode oursnesshellsolve(SNES snes, Vec x)
11 {
12   void (*func)(SNES *, Vec *, PetscErrorCode *);
13   PetscCall(PetscObjectQueryFunction((PetscObject)snes, "SNESShellSolve_C", &func));
14   PetscCheck(func, PetscObjectComm((PetscObject)snes), PETSC_ERR_USER, "SNESShellSetSolve() must be called before SNESSolve()");
15   PetscCallFortranVoidFunction(func(&snes, &x, &ierr));
16   return PETSC_SUCCESS;
17 }
18 
19 PETSC_EXTERN void snesshellsetsolve_(SNES *snes, void (*func)(SNES *, Vec *, PetscErrorCode *), PetscErrorCode *ierr)
20 {
21   *ierr = PetscObjectComposeFunction((PetscObject)*snes, "SNESShellSolve_C", (PetscVoidFn *)func);
22   if (*ierr) return;
23   *ierr = SNESShellSetSolve(*snes, oursnesshellsolve);
24 }
25