Chombo + EB  3.0
CH_Complex.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _CH_COMPLEX_H_
12 #define _CH_COMPLEX_H_
13 
14 #ifdef CH_USE_COMPLEX
15 
16 #include <complex>
17 using std::complex;
18 
19 #include "REAL.H"
20 
21 #include "BaseNamespaceHeader.H"
22 
23 /// Complex numbers suitable for use in FABs
24 /** Chombo has its own complex number class so it can:
25  * 1) provide the same class name regardless of the current precision
26  * (just like the Chombo "Real" type)
27  * 2) provide write access to the real and imaginary parts of the
28  * complex number without going through a constructor (this is not
29  * allowed by the C++ 1999 standard).
30  */
31 
32 class Complex : public complex<Real>
33 {
34 public:
35  ///
36  inline Complex()
37  {
38  }
39 
40  ///
41  inline Complex(const Real& re, const Real& im):complex<Real>(re, im)
42  {
43  }
44 
45  /// return a non-const reference to the real part of the complex number
46  inline Real & re();
47 
48  /// return a copy of the real part of the complex number
49  inline Real re() const
50  {
51  return real();
52  };
53 
54  /// return a non-const reference to the imaginary part of the complex number
55  inline Real & im();
56 
57  /// return a copy of the imaginary part of the complex number
58  inline Real im() const
59  {
60  return imag();
61  };
62 };
63 
64 //XXX dont check the compiler -- just assume this will work
65 //XXX#if defined(__GNUC__) || defined(__INTEL_COMPILER__) || defined(__IBMCPP__) || defined(__HP_aCC) || defined(__DECCXX)
66 
67 // The compilers we've seen implement complex as a 2-array of
68 // numbers of the appropriate type, with the real part first.
69 // Run the test program "Chombo/lib/test/BoxTools/test_complex.cpp" to check.
70 // This is the most likely implementation, and the only real problems are
71 // whether the compiler puts the data at the beginning of the class's
72 // memory, and whether it will allow the cast.
73 inline Real & Complex::re()
74 {
75  return (((Real*)this)[0]);
76 }
77 
78 inline Real & Complex::im()
79 {
80  return (((Real*)this)[1]);
81 }
82 
83 //XXX#else
84 //XXX#error Complex type is not implemented for this compiler; contact the Chombo developers.
85 //XXX#endif
86 
87 #include "BaseNamespaceFooter.H"
88 #endif //CH_USE_COMPLEX
89 #endif //_CH_COMPLEX_H_
double Real
Definition: REAL.H:33