1af0996ceSBarry Smith #include <petsc/private/fortranimpl.h> 2af0996ceSBarry Smith #include <petsc/private/snesimpl.h> 3a63a1bedSMatthew G. Knepley #if defined(PETSC_HAVE_FORTRAN_CAPS) 4a63a1bedSMatthew G. Knepley #define dmsnessetjacobianlocal_ DMSNESSETJACOBIANLOCAL 5a63a1bedSMatthew G. Knepley #define dmsnessetfunctionlocal_ DMSNESSETFUNCTIONLOCAL 6a63a1bedSMatthew G. Knepley #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE) 7a63a1bedSMatthew G. Knepley #define dmsnessetjacobianlocal_ dmsnessetjacobianlocal 8a63a1bedSMatthew G. Knepley #define dmsnessetfunctionlocal_ dmsnessetfunctionlocal 9a63a1bedSMatthew G. Knepley #endif 10a63a1bedSMatthew G. Knepley 11a63a1bedSMatthew G. Knepley static struct { 12a63a1bedSMatthew G. Knepley PetscFortranCallbackId lf; 13a63a1bedSMatthew G. Knepley PetscFortranCallbackId lj; 14a63a1bedSMatthew G. Knepley } _cb; 15a63a1bedSMatthew G. Knepley 16d1e9a80fSBarry Smith static PetscErrorCode sourlj(DM dm, Vec X, Mat J, Mat P, void *ptr) 17a63a1bedSMatthew G. Knepley { 18a63a1bedSMatthew G. Knepley PetscErrorCode ierr; 19*19caf8f3SSatish Balay void (*func)(DM*,Vec*,Mat*,Mat*,void*,PetscErrorCode*),*ctx; 20a63a1bedSMatthew G. Knepley DMSNES sdm; 21a63a1bedSMatthew G. Knepley 22a63a1bedSMatthew G. Knepley PetscFunctionBegin; 23a63a1bedSMatthew G. Knepley ierr = DMGetDMSNES(dm, &sdm);CHKERRQ(ierr); 24a63a1bedSMatthew G. Knepley ierr = PetscObjectGetFortranCallback((PetscObject) sdm, PETSC_FORTRAN_CALLBACK_SUBTYPE, _cb.lj, (PetscVoidFunction *) &func, &ctx);CHKERRQ(ierr); 25d1e9a80fSBarry Smith (*func)(&dm, &X, &J, &P, ctx, &ierr);CHKERRQ(ierr); 26a63a1bedSMatthew G. Knepley PetscFunctionReturn(0); 27a63a1bedSMatthew G. Knepley } 28a63a1bedSMatthew G. Knepley 29*19caf8f3SSatish Balay PETSC_EXTERN void dmsnessetjacobianlocal_(DM *dm, void (*jac)(DM*,Vec*,Mat*,Mat*,void*,PetscErrorCode*), void *ctx, PetscErrorCode *ierr) 30a63a1bedSMatthew G. Knepley { 31a63a1bedSMatthew G. Knepley DMSNES sdm; 32a63a1bedSMatthew G. Knepley 33a63a1bedSMatthew G. Knepley *ierr = DMGetDMSNESWrite(*dm, &sdm); if (*ierr) return; 34a63a1bedSMatthew G. Knepley *ierr = PetscObjectSetFortranCallback((PetscObject) sdm, PETSC_FORTRAN_CALLBACK_SUBTYPE, &_cb.lj, (PetscVoidFunction) jac, ctx); if (*ierr) return; 35430b4d03SJed Brown *ierr = DMSNESSetJacobianLocal(*dm, sourlj, NULL); 36a63a1bedSMatthew G. Knepley } 37a63a1bedSMatthew G. Knepley 38a63a1bedSMatthew G. Knepley static PetscErrorCode sourlf(DM dm, Vec X, Vec F, void *ptr) 39a63a1bedSMatthew G. Knepley { 40a63a1bedSMatthew G. Knepley PetscErrorCode ierr; 41*19caf8f3SSatish Balay void (*func)(DM*,Vec*,Vec*,void*,PetscErrorCode*), *ctx; 42a63a1bedSMatthew G. Knepley DMSNES sdm; 43a63a1bedSMatthew G. Knepley 44a63a1bedSMatthew G. Knepley PetscFunctionBegin; 45a63a1bedSMatthew G. Knepley ierr = DMGetDMSNES(dm, &sdm);CHKERRQ(ierr); 46a63a1bedSMatthew G. Knepley ierr = PetscObjectGetFortranCallback((PetscObject) sdm, PETSC_FORTRAN_CALLBACK_SUBTYPE, _cb.lf, (PetscVoidFunction *) &func, &ctx);CHKERRQ(ierr); 47a63a1bedSMatthew G. Knepley (*func)(&dm, &X, &F, ctx, &ierr);CHKERRQ(ierr); 48a63a1bedSMatthew G. Knepley PetscFunctionReturn(0); 49a63a1bedSMatthew G. Knepley } 50a63a1bedSMatthew G. Knepley 51*19caf8f3SSatish Balay PETSC_EXTERN void dmsnessetfunctionlocal_(DM *dm, void (*func)(DM*,Vec*,Vec*,void*,PetscErrorCode*), void *ctx, PetscErrorCode *ierr) 52a63a1bedSMatthew G. Knepley { 53a63a1bedSMatthew G. Knepley DMSNES sdm; 54a63a1bedSMatthew G. Knepley 55a63a1bedSMatthew G. Knepley *ierr = DMGetDMSNESWrite(*dm, &sdm); if (*ierr) return; 56a63a1bedSMatthew G. Knepley *ierr = PetscObjectSetFortranCallback((PetscObject) sdm, PETSC_FORTRAN_CALLBACK_SUBTYPE, &_cb.lf, (PetscVoidFunction) func, ctx); if (*ierr) return; 57430b4d03SJed Brown *ierr = DMSNESSetFunctionLocal(*dm, sourlf, NULL); 58a63a1bedSMatthew G. Knepley } 59