Actual source code: fnlog.c

slepc-3.7.3 2016-09-29
Report Typos and Errors
  1: /*
  2:    Logarithm function  log(x)

  4:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5:    SLEPc - Scalable Library for Eigenvalue Problem Computations
  6:    Copyright (c) 2002-2016, Universitat Politecnica de Valencia, Spain

  8:    This file is part of SLEPc.

 10:    SLEPc is free software: you can redistribute it and/or modify it under  the
 11:    terms of version 3 of the GNU Lesser General Public License as published by
 12:    the Free Software Foundation.

 14:    SLEPc  is  distributed in the hope that it will be useful, but WITHOUT  ANY
 15:    WARRANTY;  without even the implied warranty of MERCHANTABILITY or  FITNESS
 16:    FOR  A  PARTICULAR PURPOSE. See the GNU Lesser General Public  License  for
 17:    more details.

 19:    You  should have received a copy of the GNU Lesser General  Public  License
 20:    along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
 21:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 22: */

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

 28: PetscErrorCode FNEvaluateFunction_Log(FN fn,PetscScalar x,PetscScalar *y)
 29: {
 31:   *y = PetscLogScalar(x);
 32:   return(0);
 33: }

 37: PetscErrorCode FNEvaluateDerivative_Log(FN fn,PetscScalar x,PetscScalar *y)
 38: {
 40:   if (x==0.0) SETERRQ(PETSC_COMM_SELF,1,"Derivative not defined in the requested value");
 41:   *y = 1.0/x;
 42:   return(0);
 43: }

 47: PetscErrorCode FNView_Log(FN fn,PetscViewer viewer)
 48: {
 50:   PetscBool      isascii;
 51:   char           str[50];

 54:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);
 55:   if (isascii) {
 56:     if (fn->beta==(PetscScalar)1.0) {
 57:       if (fn->alpha==(PetscScalar)1.0) {
 58:         PetscViewerASCIIPrintf(viewer,"  Logarithm: log(x)\n");
 59:       } else {
 60:         SlepcSNPrintfScalar(str,50,fn->alpha,PETSC_TRUE);
 61:         PetscViewerASCIIPrintf(viewer,"  Logarithm: log(%s*x)\n",str);
 62:       }
 63:     } else {
 64:       SlepcSNPrintfScalar(str,50,fn->beta,PETSC_TRUE);
 65:       if (fn->alpha==(PetscScalar)1.0) {
 66:         PetscViewerASCIIPrintf(viewer,"  Logarithm: %s*log(x)\n",str);
 67:       } else {
 68:         PetscViewerASCIIPrintf(viewer,"  Logarithm: %s",str);
 69:         PetscViewerASCIIUseTabs(viewer,PETSC_FALSE);
 70:         SlepcSNPrintfScalar(str,50,fn->alpha,PETSC_TRUE);
 71:         PetscViewerASCIIPrintf(viewer,"*log(%s*x)\n",str);
 72:         PetscViewerASCIIUseTabs(viewer,PETSC_TRUE);
 73:       }
 74:     }
 75:   }
 76:   return(0);
 77: }

 81: PETSC_EXTERN PetscErrorCode FNCreate_Log(FN fn)
 82: {
 84:   fn->ops->evaluatefunction    = FNEvaluateFunction_Log;
 85:   fn->ops->evaluatederivative  = FNEvaluateDerivative_Log;
 86:   fn->ops->view                = FNView_Log;
 87:   return(0);
 88: }