Date: 2024-12-02T08:57:18+00:00

Actual source code: zmfnf.c
slepc-3.22.2 2024-12-02
Report Typos and Errors

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain

      6:    This file is part of SLEPc.
      7:    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
      8:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      9: */

     11: #include <petsc/private/fortranimpl.h>
     12: #include <slepcmfn.h>

     14: #if defined(PETSC_HAVE_FORTRAN_CAPS)
     15: #define mfnmonitordefault_                MFNMONITORDEFAULT
     16: #define mfnmonitorset_                    MFNMONITORSET
     17: #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
     18: #define mfnmonitordefault_                mfnmonitordefault
     19: #define mfnmonitorset_                    mfnmonitorset
     20: #endif

     22: /*
     23:    These are not usually called from Fortran but allow Fortran users
     24:    to transparently set these monitors from .F code
     25: */
     26: SLEPC_EXTERN void mfnmonitordefault_(MFN *mfn,PetscInt *it,PetscReal *errest,PetscViewerAndFormat **ctx,PetscErrorCode *ierr)
     27: {
     28:   *ierr = MFNMonitorDefault(*mfn,*it,*errest,*ctx);
     29: }

     31: static struct {
     32:   PetscFortranCallbackId monitor;
     33:   PetscFortranCallbackId monitordestroy;
     34: } _cb;

     36: /* These are not extern C because they are passed into non-extern C user level functions */
     37: static PetscErrorCode ourmonitor(MFN mfn,PetscInt i,PetscReal d,void* ctx)
     38: {
     39:   PetscObjectUseFortranCallback(mfn,_cb.monitor,(MFN*,PetscInt*,PetscReal*,void*,PetscErrorCode*),(&mfn,&i,&d,_ctx,&ierr));
     40: }

     42: static PetscErrorCode ourdestroy(void** ctx)
     43: {
     44:   MFN mfn = (MFN)*ctx;
     45:   PetscObjectUseFortranCallback(mfn,_cb.monitordestroy,(void*,PetscErrorCode*),(_ctx,&ierr));
     46: }

     48: SLEPC_EXTERN void mfnmonitorset_(MFN *mfn,void (*monitor)(MFN*,PetscInt*,PetscReal*,void*,PetscErrorCode*),void *mctx,void (*monitordestroy)(void *,PetscErrorCode*),PetscErrorCode *ierr)
     49: {
     50:   CHKFORTRANNULLOBJECT(mctx);
     51:   CHKFORTRANNULLFUNCTION(monitordestroy);
     52:   if ((PetscVoidFunction)monitor == (PetscVoidFunction)mfnmonitordefault_) {
     53:     *ierr = MFNMonitorSet(*mfn,(PetscErrorCode (*)(MFN,PetscInt,PetscReal,void*))MFNMonitorDefault,*(PetscViewerAndFormat**)mctx,(PetscErrorCode (*)(void**))PetscViewerAndFormatDestroy);
     54:   } else {
     55:     *ierr = PetscObjectSetFortranCallback((PetscObject)*mfn,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.monitor,(PetscVoidFunction)monitor,mctx); if (*ierr) return;
     56:     *ierr = PetscObjectSetFortranCallback((PetscObject)*mfn,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.monitordestroy,(PetscVoidFunction)monitordestroy,mctx); if (*ierr) return;
     57:     *ierr = MFNMonitorSet(*mfn,ourmonitor,*mfn,ourdestroy);
     58:   }
     59: }