LCOV - code coverage report
Current view: top level - sys/classes/fn/tests - test2.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 43 43 100.0 %
Date: 2024-11-21 00:40:22 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       3             :    SLEPc - Scalable Library for Eigenvalue Problem Computations
       4             :    Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain
       5             : 
       6             :    This file is part of SLEPc.
       7             :    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
       8             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       9             : */
      10             : 
      11             : static char help[] = "Test exponential function.\n\n";
      12             : 
      13             : #include <slepcfn.h>
      14             : 
      15           1 : int main(int argc,char **argv)
      16             : {
      17           1 :   FN             fn,fncopy;
      18           1 :   PetscScalar    x,y,yp,tau,eta,alpha,beta;
      19           1 :   char           strx[50],str[50];
      20             : 
      21           1 :   PetscFunctionBeginUser;
      22           1 :   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
      23           1 :   PetscCall(FNCreate(PETSC_COMM_WORLD,&fn));
      24           1 :   PetscCall(FNSetFromOptions(fn));
      25             : 
      26             :   /* plain exponential exp(x) */
      27           1 :   PetscCall(FNSetType(fn,FNEXP));
      28           1 :   PetscCall(FNView(fn,NULL));
      29           1 :   x = 2.2;
      30           1 :   PetscCall(SlepcSNPrintfScalar(strx,sizeof(strx),x,PETSC_FALSE));
      31           1 :   PetscCall(FNEvaluateFunction(fn,x,&y));
      32           1 :   PetscCall(FNEvaluateDerivative(fn,x,&yp));
      33           1 :   PetscCall(SlepcSNPrintfScalar(str,sizeof(str),y,PETSC_FALSE));
      34           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"  f(%s)=%s\n",strx,str));
      35           1 :   PetscCall(SlepcSNPrintfScalar(str,sizeof(str),yp,PETSC_FALSE));
      36           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"  f'(%s)=%s\n",strx,str));
      37             : 
      38             :   /* exponential with scaling factors eta*exp(tau*x) */
      39           1 :   PetscCall(FNSetType(fn,FNEXP));
      40           1 :   tau = -0.2;
      41           1 :   eta = 1.3;
      42           1 :   PetscCall(FNSetScale(fn,tau,eta));
      43           1 :   PetscCall(FNView(fn,NULL));
      44           1 :   x = 2.2;
      45           1 :   PetscCall(SlepcSNPrintfScalar(strx,sizeof(strx),x,PETSC_FALSE));
      46           1 :   PetscCall(FNEvaluateFunction(fn,x,&y));
      47           1 :   PetscCall(FNEvaluateDerivative(fn,x,&yp));
      48           1 :   PetscCall(SlepcSNPrintfScalar(str,sizeof(str),y,PETSC_FALSE));
      49           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"  f(%s)=%s\n",strx,str));
      50           1 :   PetscCall(SlepcSNPrintfScalar(str,sizeof(str),yp,PETSC_FALSE));
      51           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"  f'(%s)=%s\n",strx,str));
      52             : 
      53             :   /* test FNDuplicate */
      54           1 :   PetscCall(FNDuplicate(fn,PetscObjectComm((PetscObject)fn),&fncopy));
      55             : 
      56             :   /* test FNGetScale */
      57           1 :   PetscCall(FNGetScale(fncopy,&alpha,&beta));
      58           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"Parameters:\n - alpha: "));
      59           1 :   PetscCall(SlepcSNPrintfScalar(str,sizeof(str),alpha,PETSC_FALSE));
      60           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"%s ",str));
      61           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n - beta: "));
      62           1 :   PetscCall(SlepcSNPrintfScalar(str,sizeof(str),beta,PETSC_FALSE));
      63           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"%s ",str));
      64           1 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n"));
      65             : 
      66           1 :   PetscCall(FNDestroy(&fn));
      67           1 :   PetscCall(FNDestroy(&fncopy));
      68           1 :   PetscCall(SlepcFinalize());
      69             :   return 0;
      70             : }
      71             : 
      72             : /*TEST
      73             : 
      74             :    test:
      75             :       suffix: 1
      76             :       nsize: 1
      77             :       filter: grep -v "computing matrix functions"
      78             : 
      79             : TEST*/

Generated by: LCOV version 1.14