Actual source code: fnsqrt.c
slepc-3.6.1 2015-09-03
1: /*
2: Square root function sqrt(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_Sqrt(FN fn,PetscScalar x,PetscScalar *y)
29: {
31: *y = PetscSqrtScalar(x);
32: return(0);
33: }
37: PetscErrorCode FNEvaluateDerivative_Sqrt(FN fn,PetscScalar x,PetscScalar *y)
38: {
40: *y = 1.0/(2.0*PetscSqrtScalar(x));
41: return(0);
42: }
46: PetscErrorCode FNView_Sqrt(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," Square root: sqrt(x)\n");
58: } else {
59: SlepcSNPrintfScalar(str,50,fn->alpha,PETSC_TRUE);
60: PetscViewerASCIIPrintf(viewer," Square root: sqrt(%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," Square root: %s*sqrt(x)\n",str);
66: } else {
67: PetscViewerASCIIPrintf(viewer," Square root: %s",str);
68: SlepcSNPrintfScalar(str,50,fn->alpha,PETSC_TRUE);
69: PetscViewerASCIIPrintf(viewer,"*sqrt(%s*x)\n",str);
70: }
71: }
72: }
73: return(0);
74: }
78: PETSC_EXTERN PetscErrorCode FNCreate_Sqrt(FN fn)
79: {
81: fn->ops->evaluatefunction = FNEvaluateFunction_Sqrt;
82: fn->ops->evaluatederivative = FNEvaluateDerivative_Sqrt;
83: fn->ops->view = FNView_Sqrt;
84: return(0);
85: }