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