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