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