1 /* $Id: petscmath.h,v 1.7 1998/05/30 00:05:39 balay 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 */ 9 #include "petsc.h" 10 11 #if !defined(__PETSCMATH_PACKAGE) 12 #define __PETSCMATH_PACKAGE 13 #include <math.h> 14 15 /* 16 17 Defines operations that are different for complex and real numbers; 18 note that one cannot really mix the use of complex and real in the same 19 PETSc program. All PETSc objects in one program are built around the object 20 Scalar which is either always a double or a complex. 21 22 */ 23 #if defined(USE_PETSC_COMPLEX) 24 25 #if defined (PARCH_nt) 26 #include <complex> 27 #elif defined(HAVE_NONSTANDARD_COMPLEX_H) 28 #include HAVE_NONSTANDARD_COMPLEX_H 29 #else 30 #include <complex.h> 31 #endif 32 33 extern MPI_Datatype MPIU_COMPLEX; 34 #define MPIU_SCALAR MPIU_COMPLEX 35 #if defined (PARCH_nt) 36 #define PetscReal(a) (a).real() 37 #define PetscImaginary(a) (a).imag() 38 #define PetscAbsScalar(a) std::abs(a) 39 #define PetscConj(a) std::conj(a) 40 #define PetscSqrtScalar(a) std::sqrt(a) 41 #else 42 #define PetscReal(a) real(a) 43 #define PetscImaginary(a) imag(a) 44 #define PetscAbsScalar(a) abs(a) 45 #define PetscConj(a) conj(a) 46 #define PetscSqrtScalar(a) sqrt(a) 47 #endif 48 /* 49 The new complex class for GNU C++ is based on templates and is not backward 50 compatible with all previous complex class libraries. 51 */ 52 #if defined(PARCH_nt) 53 #define Scalar std::complex<double> 54 #elif defined(USES_TEMPLATED_COMPLEX) 55 #define Scalar complex<double> 56 #else 57 #define Scalar complex 58 #endif 59 60 /* Compiling for real numbers only */ 61 #else 62 #define MPIU_SCALAR MPI_DOUBLE 63 #define PetscReal(a) (a) 64 #define PetscImaginary(a) (a) 65 #define PetscAbsScalar(a) ( ((a)<0.0) ? -(a) : (a) ) 66 #define Scalar double 67 #define PetscConj(a) (a) 68 #define PetscSqrtScalar(a) sqrt(a) 69 #endif 70 71 /* --------------------------------------------------------------------------*/ 72 73 /* 74 Certain objects may be created using either single 75 or double precision. 76 */ 77 typedef enum { SCALAR_DOUBLE, SCALAR_SINGLE } ScalarPrecision; 78 79 /* PETSC_i is the imaginary number, i */ 80 extern Scalar PETSC_i; 81 82 #define PetscMin(a,b) ( ((a)<(b)) ? (a) : (b) ) 83 #define PetscMax(a,b) ( ((a)<(b)) ? (b) : (a) ) 84 #define PetscAbsInt(a) ( ((a)<0) ? -(a) : (a) ) 85 #define PetscAbsDouble(a) ( ((a)<0) ? -(a) : (a) ) 86 87 /* ----------------------------------------------------------------------------*/ 88 /* 89 Basic constants 90 */ 91 #define PETSC_PI 3.14159265358979323846264 92 #define PETSC_DEGREES_TO_RADIANS 0.01745329251994 93 #define PETSC_MAX 1.e300 94 #define PETSC_MIN -1.e300 95 #define PETSC_MAX_INT 1000000000; 96 #define PETSC_MIN_INT -1000000000; 97 98 /* ----------------------------------------------------------------------------*/ 99 /* 100 PLogDouble variables are used to contain double precision numbers 101 that are not used in the numerical computations, but rather in logging, 102 timing etc. 103 */ 104 typedef double PLogDouble; 105 /* 106 Once PETSc is compiling with a ADIC enhanced version of MPI 107 we will create a new MPI_Datatype for the inactive double variables. 108 */ 109 #if defined(AD_DERIV_H) 110 /* extern MPI_Datatype MPIU_PLOGDOUBLE; */ 111 #else 112 #if !defined(PETSC_USING_MPIUNI) 113 #define MPIU_PLOGDOUBLE MPI_DOUBLE 114 #endif 115 #endif 116 117 118 #endif 119