Actual source code: fnlog.c
slepc-3.10.1 2018-10-23
Report Typos and Errors

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-2018, 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: */
     10: /*
     11:    Logarithm function  log(x)
     12: */

     14: #include <slepc/private/fnimpl.h>      /*I "slepcfn.h" I*/

     16: PetscErrorCode FNEvaluateFunction_Log(FN fn,PetscScalar x,PetscScalar *y)
     17: {
     19: #if !defined(PETSC_USE_COMPLEX)
     20:   if (x<0.0) SETERRQ(PETSC_COMM_SELF,1,"Function not defined in the requested value");
     21: #endif
     22:   *y = PetscLogScalar(x);
     23:   return(0);
     24: }

     26: PetscErrorCode FNEvaluateDerivative_Log(FN fn,PetscScalar x,PetscScalar *y)
     27: {
     29:   if (x==0.0) SETERRQ(PETSC_COMM_SELF,1,"Derivative not defined in the requested value");
     30: #if !defined(PETSC_USE_COMPLEX)
     31:   if (x<0.0) SETERRQ(PETSC_COMM_SELF,1,"Derivative not defined in the requested value");
     32: #endif
     33:   *y = 1.0/x;
     34:   return(0);
     35: }

     37: PetscErrorCode FNView_Log(FN fn,PetscViewer viewer)
     38: {
     40:   PetscBool      isascii;
     41:   char           str[50];

     44:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);
     45:   if (isascii) {
     46:     if (fn->beta==(PetscScalar)1.0) {
     47:       if (fn->alpha==(PetscScalar)1.0) {
     48:         PetscViewerASCIIPrintf(viewer,"  Logarithm: log(x)\n");
     49:       } else {
     50:         SlepcSNPrintfScalar(str,50,fn->alpha,PETSC_TRUE);
     51:         PetscViewerASCIIPrintf(viewer,"  Logarithm: log(%s*x)\n",str);
     52:       }
     53:     } else {
     54:       SlepcSNPrintfScalar(str,50,fn->beta,PETSC_TRUE);
     55:       if (fn->alpha==(PetscScalar)1.0) {
     56:         PetscViewerASCIIPrintf(viewer,"  Logarithm: %s*log(x)\n",str);
     57:       } else {
     58:         PetscViewerASCIIPrintf(viewer,"  Logarithm: %s",str);
     59:         PetscViewerASCIIUseTabs(viewer,PETSC_FALSE);
     60:         SlepcSNPrintfScalar(str,50,fn->alpha,PETSC_TRUE);
     61:         PetscViewerASCIIPrintf(viewer,"*log(%s*x)\n",str);
     62:         PetscViewerASCIIUseTabs(viewer,PETSC_TRUE);
     63:       }
     64:     }
     65:   }
     66:   return(0);
     67: }

     69: PETSC_EXTERN PetscErrorCode FNCreate_Log(FN fn)
     70: {
     72:   fn->ops->evaluatefunction    = FNEvaluateFunction_Log;
     73:   fn->ops->evaluatederivative  = FNEvaluateDerivative_Log;
     74:   fn->ops->view                = FNView_Log;
     75:   return(0);
     76: }