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