1*3f1db9ecSBarry Smith /* $Id: petscmath.h,v 1.12 1998/07/23 22:50:59 bsmith Exp bsmith $ */ 2e489efc1SBarry Smith /* 3314da920SBarry Smith 4314da920SBarry Smith PETSc mathematics include file. Defines certain basic mathematical 5314da920SBarry Smith constants and functions for working with single and double precision 6314da920SBarry Smith floating point numbers as well as complex and integers. 7314da920SBarry Smith 8e7029fe1SSatish Balay This file is included by petsc.h and should not be used directly. 9e7029fe1SSatish Balay 10e489efc1SBarry Smith */ 11e489efc1SBarry Smith 12488ecbafSBarry Smith #if !defined(__PETSCMATH_H) 13488ecbafSBarry Smith #define __PETSCMATH_H 140a5f7794SBarry Smith #include <math.h> 150a5f7794SBarry Smith 16314da920SBarry Smith /* 17f4ccad53SBarry Smith 18f4ccad53SBarry Smith Defines operations that are different for complex and real numbers; 19f4ccad53SBarry Smith note that one cannot really mix the use of complex and real in the same 20f4ccad53SBarry Smith PETSc program. All PETSc objects in one program are built around the object 21f4ccad53SBarry Smith Scalar which is either always a double or a complex. 22f4ccad53SBarry Smith 23e489efc1SBarry Smith */ 240a5f7794SBarry Smith #if defined(USE_PETSC_COMPLEX) 25adc17e78SSatish Balay 26df9b3741SSatish Balay #if defined (PARCH_nt) 27df9b3741SSatish Balay #include <complex> 28df9b3741SSatish Balay #elif defined(HAVE_NONSTANDARD_COMPLEX_H) 29adc17e78SSatish Balay #include HAVE_NONSTANDARD_COMPLEX_H 30adc17e78SSatish Balay #else 31adc17e78SSatish Balay #include <complex.h> 32adc17e78SSatish Balay #endif 33adc17e78SSatish Balay 34adc17e78SSatish Balay extern MPI_Datatype MPIU_COMPLEX; 35adc17e78SSatish Balay #define MPIU_SCALAR MPIU_COMPLEX 363f6de6efSSatish Balay #if defined (PARCH_nt) 37df9b3741SSatish Balay #define PetscReal(a) (a).real() 38df9b3741SSatish Balay #define PetscImaginary(a) (a).imag() 393f6de6efSSatish Balay #define PetscAbsScalar(a) std::abs(a) 403f6de6efSSatish Balay #define PetscConj(a) std::conj(a) 4118a7d68fSSatish Balay #define PetscSqrtScalar(a) std::sqrt(a) 42e489efc1SBarry Smith #else 43e489efc1SBarry Smith #define PetscReal(a) real(a) 44e489efc1SBarry Smith #define PetscImaginary(a) imag(a) 45e489efc1SBarry Smith #define PetscAbsScalar(a) abs(a) 46e489efc1SBarry Smith #define PetscConj(a) conj(a) 4718a7d68fSSatish Balay #define PetscSqrtScalar(a) sqrt(a) 48adc17e78SSatish Balay #endif 49e489efc1SBarry Smith /* 50e489efc1SBarry Smith The new complex class for GNU C++ is based on templates and is not backward 51e489efc1SBarry Smith compatible with all previous complex class libraries. 52e489efc1SBarry Smith */ 53df9b3741SSatish Balay #if defined(PARCH_nt) 54df9b3741SSatish Balay #define Scalar std::complex<double> 55df9b3741SSatish Balay #elif defined(USES_TEMPLATED_COMPLEX) 56e489efc1SBarry Smith #define Scalar complex<double> 57e489efc1SBarry Smith #else 58e489efc1SBarry Smith #define Scalar complex 59e489efc1SBarry Smith #endif 60e489efc1SBarry Smith 61e489efc1SBarry Smith /* Compiling for real numbers only */ 62e489efc1SBarry Smith #else 63e489efc1SBarry Smith #define MPIU_SCALAR MPI_DOUBLE 64e489efc1SBarry Smith #define PetscReal(a) (a) 65e489efc1SBarry Smith #define PetscImaginary(a) (a) 66e489efc1SBarry Smith #define PetscAbsScalar(a) ( ((a)<0.0) ? -(a) : (a) ) 67e489efc1SBarry Smith #define Scalar double 68e489efc1SBarry Smith #define PetscConj(a) (a) 6918a7d68fSSatish Balay #define PetscSqrtScalar(a) sqrt(a) 70e489efc1SBarry Smith #endif 71e489efc1SBarry Smith 72*3f1db9ecSBarry Smith /* 73*3f1db9ecSBarry Smith Allows compiling PETSc so that matrix values are stored in 74*3f1db9ecSBarry Smith single precision but all other objects still use double 75*3f1db9ecSBarry Smith precision. This does not work for complex numbers in that case 76*3f1db9ecSBarry Smith it remains double 77*3f1db9ecSBarry Smith 78*3f1db9ecSBarry Smith EXPERIMENTAL! NOT YET COMPLETELY WORKING 79*3f1db9ecSBarry Smith */ 80*3f1db9ecSBarry Smith #if defined(USE_PETSC_COMPLEX) 81*3f1db9ecSBarry Smith 82*3f1db9ecSBarry Smith #define MatScalar Scalar 83*3f1db9ecSBarry Smith #define MatFloat double 84*3f1db9ecSBarry Smith 85*3f1db9ecSBarry Smith #elif defined(USE_MAT_SINGLE) 86*3f1db9ecSBarry Smith 87*3f1db9ecSBarry Smith #define MatScalar float 88*3f1db9ecSBarry Smith #define MatFloat float 89*3f1db9ecSBarry Smith 90*3f1db9ecSBarry Smith #else 91*3f1db9ecSBarry Smith 92*3f1db9ecSBarry Smith #define MatScalar Scalar 93*3f1db9ecSBarry Smith #define MatFloat double 94*3f1db9ecSBarry Smith 95*3f1db9ecSBarry Smith #endif 96*3f1db9ecSBarry Smith 97*3f1db9ecSBarry Smith 98314da920SBarry Smith /* --------------------------------------------------------------------------*/ 99314da920SBarry Smith 100e489efc1SBarry Smith /* 101e489efc1SBarry Smith Certain objects may be created using either single 102e489efc1SBarry Smith or double precision. 103e489efc1SBarry Smith */ 104e489efc1SBarry Smith typedef enum { SCALAR_DOUBLE, SCALAR_SINGLE } ScalarPrecision; 105e489efc1SBarry Smith 106e489efc1SBarry Smith /* PETSC_i is the imaginary number, i */ 107e489efc1SBarry Smith extern Scalar PETSC_i; 108e489efc1SBarry Smith 109e489efc1SBarry Smith #define PetscMin(a,b) ( ((a)<(b)) ? (a) : (b) ) 110e489efc1SBarry Smith #define PetscMax(a,b) ( ((a)<(b)) ? (b) : (a) ) 111e489efc1SBarry Smith #define PetscAbsInt(a) ( ((a)<0) ? -(a) : (a) ) 112e489efc1SBarry Smith #define PetscAbsDouble(a) ( ((a)<0) ? -(a) : (a) ) 113e489efc1SBarry Smith 114314da920SBarry Smith /* ----------------------------------------------------------------------------*/ 115314da920SBarry Smith /* 116314da920SBarry Smith Basic constants 117314da920SBarry Smith */ 118314da920SBarry Smith #define PETSC_PI 3.14159265358979323846264 119314da920SBarry Smith #define PETSC_DEGREES_TO_RADIANS 0.01745329251994 120e489efc1SBarry Smith #define PETSC_MAX 1.e300 121e489efc1SBarry Smith #define PETSC_MIN -1.e300 1220a5f7794SBarry Smith #define PETSC_MAX_INT 1000000000; 1230a5f7794SBarry Smith #define PETSC_MIN_INT -1000000000; 124e489efc1SBarry Smith 125314da920SBarry Smith /* ----------------------------------------------------------------------------*/ 126e489efc1SBarry Smith /* 127e489efc1SBarry Smith PLogDouble variables are used to contain double precision numbers 128e489efc1SBarry Smith that are not used in the numerical computations, but rather in logging, 129e489efc1SBarry Smith timing etc. 130e489efc1SBarry Smith */ 131e489efc1SBarry Smith typedef double PLogDouble; 132e489efc1SBarry Smith /* 133e489efc1SBarry Smith Once PETSc is compiling with a ADIC enhanced version of MPI 134e489efc1SBarry Smith we will create a new MPI_Datatype for the inactive double variables. 135e489efc1SBarry Smith */ 136e489efc1SBarry Smith #if defined(AD_DERIV_H) 137e489efc1SBarry Smith /* extern MPI_Datatype MPIU_PLOGDOUBLE; */ 138e489efc1SBarry Smith #else 139488ecbafSBarry Smith #if !defined(USING_MPIUNI) 140e489efc1SBarry Smith #define MPIU_PLOGDOUBLE MPI_DOUBLE 141e489efc1SBarry Smith #endif 142e489efc1SBarry Smith #endif 143e489efc1SBarry Smith 144e489efc1SBarry Smith 145e489efc1SBarry Smith #endif 146