Actual source code: fnlog.c

slepc-3.6.1 2015-09-03
Report Typos and Errors
  1: /*
  2:    Logarithm function  log(x)

  4:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5:    SLEPc - Scalable Library for Eigenvalue Problem Computations
  6:    Copyright (c) 2002-2015, 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:   *y = 1.0/x;
 41:   return(0);
 42: }

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

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

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