Date: 2026-03-31T13:23:21+00:00

Actual source code: test2.c

      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: static char help[] = "Test exponential function.\n\n";

     13: #include <slepcfn.h>

     15: int main(int argc,char **argv)
     16: {
     17:   FN             fn,fncopy;
     18:   PetscScalar    x,y,yp,tau,eta,alpha,beta;
     19:   char           strx[50],str[50];

     21:   PetscFunctionBeginUser;
     22:   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
     23:   PetscCall(FNCreate(PETSC_COMM_WORLD,&fn));
     24:   PetscCall(FNSetFromOptions(fn));

     26:   /* plain exponential exp(x) */
     27:   PetscCall(FNSetType(fn,FNEXP));
     28:   PetscCall(FNView(fn,NULL));
     29:   x = 2.2;
     30:   PetscCall(SlepcSNPrintfScalar(strx,sizeof(strx),x,PETSC_FALSE));
     31:   PetscCall(FNEvaluateFunction(fn,x,&y));
     32:   PetscCall(FNEvaluateDerivative(fn,x,&yp));
     33:   PetscCall(SlepcSNPrintfScalar(str,sizeof(str),y,PETSC_FALSE));
     34:   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"  f(%s)=%s\n",strx,str));
     35:   PetscCall(SlepcSNPrintfScalar(str,sizeof(str),yp,PETSC_FALSE));
     36:   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"  f'(%s)=%s\n",strx,str));

     38:   /* exponential with scaling factors eta*exp(tau*x) */
     39:   PetscCall(FNSetType(fn,FNEXP));
     40:   tau = -0.2;
     41:   eta = 1.3;
     42:   PetscCall(FNSetScale(fn,tau,eta));
     43:   PetscCall(FNView(fn,NULL));
     44:   x = 2.2;
     45:   PetscCall(SlepcSNPrintfScalar(strx,sizeof(strx),x,PETSC_FALSE));
     46:   PetscCall(FNEvaluateFunction(fn,x,&y));
     47:   PetscCall(FNEvaluateDerivative(fn,x,&yp));
     48:   PetscCall(SlepcSNPrintfScalar(str,sizeof(str),y,PETSC_FALSE));
     49:   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"  f(%s)=%s\n",strx,str));
     50:   PetscCall(SlepcSNPrintfScalar(str,sizeof(str),yp,PETSC_FALSE));
     51:   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"  f'(%s)=%s\n",strx,str));

     53:   /* test FNDuplicate */
     54:   PetscCall(FNDuplicate(fn,PetscObjectComm((PetscObject)fn),&fncopy));

     56:   /* test FNGetScale */
     57:   PetscCall(FNGetScale(fncopy,&alpha,&beta));
     58:   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"Parameters:\n - alpha: "));
     59:   PetscCall(SlepcSNPrintfScalar(str,sizeof(str),alpha,PETSC_FALSE));
     60:   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"%s ",str));
     61:   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n - beta: "));
     62:   PetscCall(SlepcSNPrintfScalar(str,sizeof(str),beta,PETSC_FALSE));
     63:   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"%s ",str));
     64:   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n"));

     66:   PetscCall(FNDestroy(&fn));
     67:   PetscCall(FNDestroy(&fncopy));
     68:   PetscCall(SlepcFinalize());
     69:   return 0;
     70: }

     72: /*TEST

     74:    test:
     75:       suffix: 1
     76:       nsize: 1
     77:       filter: grep -v "computing matrix functions"

     79: TEST*/