Actual source code: fnexp.c
1: /*
2: Exponential function f(x) = beta*exp(alpha*x).
4: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5: SLEPc - Scalable Library for Eigenvalue Problem Computations
6: Copyright (c) 2002-2013, 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_Exp(FN fn,PetscScalar x,PetscScalar *y)
29: {
30: PetscScalar arg;
33: if (!fn->na) arg = x;
34: else arg = fn->alpha[0]*x;
35: if (!fn->nb) *y = PetscExpScalar(arg);
36: else *y = fn->beta[0]*PetscExpScalar(arg);
37: return(0);
38: }
42: PetscErrorCode FNEvaluateDerivative_Exp(FN fn,PetscScalar x,PetscScalar *yp)
43: {
44: PetscScalar arg,scal;
47: if (!fn->na) {
48: arg = x;
49: scal = 1.0;
50: } else {
51: arg = fn->alpha[0]*x;
52: scal = fn->alpha[0];
53: }
54: if (fn->nb) scal *= fn->beta[0];
55: *yp = scal*PetscExpScalar(arg);
56: return(0);
57: }
61: PetscErrorCode FNView_Exp(FN fn,PetscViewer viewer)
62: {
64: PetscBool isascii;
65: char str[50];
68: PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);
69: if (isascii) {
70: if (!fn->nb) {
71: if (!fn->na) {
72: PetscViewerASCIIPrintf(viewer," Exponential: exp(x)\n");
73: } else {
74: SlepcSNPrintfScalar(str,50,fn->alpha[0],PETSC_TRUE);
75: PetscViewerASCIIPrintf(viewer," Exponential: exp(%s*x)\n",str);
76: }
77: } else {
78: SlepcSNPrintfScalar(str,50,fn->beta[0],PETSC_TRUE);
79: if (!fn->na) {
80: PetscViewerASCIIPrintf(viewer," Exponential: %s*exp(x)\n",str);
81: } else {
82: PetscViewerASCIIPrintf(viewer," Exponential: %s",str);
83: SlepcSNPrintfScalar(str,50,fn->alpha[0],PETSC_TRUE);
84: PetscViewerASCIIPrintf(viewer,"*exp(%s*x)\n",str);
85: }
86: }
87: }
88: return(0);
89: }
93: PETSC_EXTERN PetscErrorCode FNCreate_Exp(FN fn)
94: {
96: fn->ops->evaluatefunction = FNEvaluateFunction_Exp;
97: fn->ops->evaluatederivative = FNEvaluateDerivative_Exp;
98: fn->ops->view = FNView_Exp;
99: return(0);
100: }