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