1 /* $Id: petscmath.h,v 1.15 1999/05/12 03:35:01 bsmith Exp balay $ */ 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 #else 43 #define PetscReal(a) real(a) 44 #define PetscImaginary(a) imag(a) 45 #define PetscAbsScalar(a) abs(a) 46 #define PetscConj(a) conj(a) 47 #define PetscSqrtScalar(a) sqrt(a) 48 #endif 49 /* 50 The new complex class for GNU C++ is based on templates and is not backward 51 compatible with all previous complex class libraries. 52 */ 53 #if defined(PETSC_HAVE_STD_COMPLEX) 54 #define Scalar std::complex<double> 55 #elif defined(PETSC_HAVE_TEMPLATED_COMPLEX) 56 #define Scalar complex<double> 57 #else 58 #define Scalar complex 59 #endif 60 61 /* Compiling for real numbers only */ 62 #else 63 #define MPIU_SCALAR MPI_DOUBLE 64 #define PetscReal(a) (a) 65 #define PetscImaginary(a) (a) 66 #define PetscAbsScalar(a) ( ((a)<0.0) ? -(a) : (a) ) 67 #define Scalar double 68 #define PetscConj(a) (a) 69 #define PetscSqrtScalar(a) sqrt(a) 70 #endif 71 72 /* 73 Allows compiling PETSc so that matrix values are stored in 74 single precision but all other objects still use double 75 precision. This does not work for complex numbers in that case 76 it remains double 77 78 EXPERIMENTAL! NOT YET COMPLETELY WORKING 79 */ 80 #if defined(PETSC_USE_COMPLEX) 81 82 #define MatScalar Scalar 83 #define MatFloat double 84 85 #elif defined(PETSC_USE_MAT_SINGLE) 86 87 #define MatScalar float 88 #define MatFloat float 89 90 #else 91 92 #define MatScalar Scalar 93 #define MatFloat double 94 95 #endif 96 97 98 /* --------------------------------------------------------------------------*/ 99 100 /* 101 Certain objects may be created using either single 102 or double precision. 103 */ 104 typedef enum { SCALAR_DOUBLE, SCALAR_SINGLE } ScalarPrecision; 105 106 /* PETSC_i is the imaginary number, i */ 107 extern Scalar PETSC_i; 108 109 #define PetscMin(a,b) ( ((a)<(b)) ? (a) : (b) ) 110 #define PetscMax(a,b) ( ((a)<(b)) ? (b) : (a) ) 111 #define PetscAbsInt(a) ( ((a)<0) ? -(a) : (a) ) 112 #define PetscAbsDouble(a) ( ((a)<0) ? -(a) : (a) ) 113 114 /* ----------------------------------------------------------------------------*/ 115 /* 116 Basic constants 117 */ 118 #define PETSC_PI 3.14159265358979323846264 119 #define PETSC_DEGREES_TO_RADIANS 0.01745329251994 120 #define PETSC_MAX 1.e300 121 #define PETSC_MIN -1.e300 122 #define PETSC_MAX_INT 1000000000; 123 #define PETSC_MIN_INT -1000000000; 124 125 /* ----------------------------------------------------------------------------*/ 126 /* 127 PLogDouble variables are used to contain double precision numbers 128 that are not used in the numerical computations, but rather in logging, 129 timing etc. 130 */ 131 typedef double PLogDouble; 132 /* 133 Once PETSc is compiling with a ADIC enhanced version of MPI 134 we will create a new MPI_Datatype for the inactive double variables. 135 */ 136 #if defined(AD_DERIV_H) 137 /* extern MPI_Datatype MPIU_PLOGDOUBLE; */ 138 #else 139 #if !defined(USING_MPIUNI) 140 #define MPIU_PLOGDOUBLE MPI_DOUBLE 141 #endif 142 #endif 143 144 145 #endif 146