1 /* $Id: petscmath.h,v 1.16 1999/05/27 19:41:20 balay Exp bsmith $ */ 2 /* 3 4 PETSc mathematics include file. Defines certain basic mathematical 5 constants and functions for working with single and double precision 6 floating point numbers as well as complex and integers. 7 8 This file is included by petsc.h and should not be used directly. 9 10 */ 11 12 #if !defined(__PETSCMATH_H) 13 #define __PETSCMATH_H 14 #include <math.h> 15 16 /* 17 18 Defines operations that are different for complex and real numbers; 19 note that one cannot really mix the use of complex and real in the same 20 PETSc program. All PETSc objects in one program are built around the object 21 Scalar which is either always a double or a complex. 22 23 */ 24 #if defined(PETSC_USE_COMPLEX) 25 26 #if defined (PETSC_HAVE_STD_COMPLEX) 27 #include <complex> 28 #elif defined(PETSC_HAVE_NONSTANDARD_COMPLEX_H) 29 #include PETSC_HAVE_NONSTANDARD_COMPLEX_H 30 #else 31 #include <complex.h> 32 #endif 33 34 extern MPI_Datatype MPIU_COMPLEX; 35 #define MPIU_SCALAR MPIU_COMPLEX 36 #if defined (PETSC_HAVE_STD_COMPLEX) 37 #define PetscReal(a) (a).real() 38 #define PetscImaginary(a) (a).imag() 39 #define PetscAbsScalar(a) std::abs(a) 40 #define PetscConj(a) std::conj(a) 41 #define PetscSqrtScalar(a) std::sqrt(a) 42 #define PetscPowScalar(a,b) std::pow(a,b) 43 #define PetscExpScalar(a) std::exp(a) 44 #define PetscSinScalar(a) std::sin(a) 45 #define PetscCosScalar(a) std::cos(a) 46 #else 47 #define PetscReal(a) real(a) 48 #define PetscImaginary(a) imag(a) 49 #define PetscAbsScalar(a) abs(a) 50 #define PetscConj(a) conj(a) 51 #define PetscSqrtScalar(a) sqrt(a) 52 #define PetscPowScalar(a,b) pow(a,b) 53 #define PetscExpScalar(a) exp(a) 54 #define PetscSinScalar(a) sin(a) 55 #define PetscCosScalar(a) cos(a) 56 #endif 57 /* 58 The new complex class for GNU C++ is based on templates and is not backward 59 compatible with all previous complex class libraries. 60 */ 61 #if defined(PETSC_HAVE_STD_COMPLEX) 62 #define Scalar std::complex<double> 63 #elif defined(PETSC_HAVE_TEMPLATED_COMPLEX) 64 #define Scalar complex<double> 65 #else 66 #define Scalar complex 67 #endif 68 69 /* Compiling for real numbers only */ 70 #else 71 #define MPIU_SCALAR MPI_DOUBLE 72 #define PetscReal(a) (a) 73 #define PetscImaginary(a) (a) 74 #define PetscAbsScalar(a) ( ((a)<0.0) ? -(a) : (a) ) 75 #define Scalar double 76 #define PetscConj(a) (a) 77 #define PetscSqrtScalar(a) sqrt(a) 78 #define PetscPowScalar(a,b) pow(a,b) 79 #define PetscExpScalar(a) exp(a) 80 #define PetscSinScalar(a) sin(a) 81 #define PetscCosScalar(a) cos(a) 82 #endif 83 84 /* 85 Allows compiling PETSc so that matrix values are stored in 86 single precision but all other objects still use double 87 precision. This does not work for complex numbers in that case 88 it remains double 89 90 EXPERIMENTAL! NOT YET COMPLETELY WORKING 91 */ 92 #if defined(PETSC_USE_COMPLEX) 93 94 #define MatScalar Scalar 95 #define MatFloat double 96 97 #elif defined(PETSC_USE_MAT_SINGLE) 98 99 #define MatScalar float 100 #define MatFloat float 101 102 #else 103 104 #define MatScalar Scalar 105 #define MatFloat double 106 107 #endif 108 109 110 /* --------------------------------------------------------------------------*/ 111 112 /* 113 Certain objects may be created using either single 114 or double precision. 115 */ 116 typedef enum { SCALAR_DOUBLE, SCALAR_SINGLE } ScalarPrecision; 117 118 /* PETSC_i is the imaginary number, i */ 119 extern Scalar PETSC_i; 120 121 #define PetscMin(a,b) ( ((a)<(b)) ? (a) : (b) ) 122 #define PetscMax(a,b) ( ((a)<(b)) ? (b) : (a) ) 123 #define PetscAbsInt(a) ( ((a)<0) ? -(a) : (a) ) 124 #define PetscAbsDouble(a) ( ((a)<0) ? -(a) : (a) ) 125 126 /* ----------------------------------------------------------------------------*/ 127 /* 128 Basic constants 129 */ 130 #define PETSC_PI 3.14159265358979323846264 131 #define PETSC_DEGREES_TO_RADIANS 0.01745329251994 132 #define PETSC_MAX 1.e300 133 #define PETSC_MIN -1.e300 134 #define PETSC_MAX_INT 1000000000; 135 #define PETSC_MIN_INT -1000000000; 136 137 /* ----------------------------------------------------------------------------*/ 138 /* 139 PLogDouble variables are used to contain double precision numbers 140 that are not used in the numerical computations, but rather in logging, 141 timing etc. 142 */ 143 typedef double PLogDouble; 144 /* 145 Once PETSc is compiling with a ADIC enhanced version of MPI 146 we will create a new MPI_Datatype for the inactive double variables. 147 */ 148 #if defined(AD_DERIV_H) 149 /* extern MPI_Datatype MPIU_PLOGDOUBLE; */ 150 #else 151 #if !defined(USING_MPIUNI) 152 #define MPIU_PLOGDOUBLE MPI_DOUBLE 153 #endif 154 #endif 155 156 157 #endif 158