Date: 2022-10-01T06:39:10+00:00

Actual source code: test2.c
slepc-3.18.0 2022-10-01
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: 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];

     22:   SlepcInitialize(&argc,&argv,(char*)0,help);
     23:   FNCreate(PETSC_COMM_WORLD,&fn);
     24:   FNSetFromOptions(fn);

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

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

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

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

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

     72: /*TEST

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

     79: TEST*/