XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
complex.hpp
Go to the documentation of this file.
1 #ifndef COMPLEX_HPP
2 #define COMPLEX_HPP
3 
4 #include "space_settings.hpp"
5 
6 struct Complex {
7  double real;
8  double imag;
9 
10  // Constructor to initialize the complex numbers
11  // Initializes to zero
12  // Initializes to real if provided one argument
13  KOKKOS_INLINE_FUNCTION Complex(double r = 0.0, double i = 0.0) : real(r), imag(i) {}
14 
15  // Overload the + operator
16  KOKKOS_INLINE_FUNCTION Complex operator+(const Complex& other) const {
17  return Complex(real + other.real, imag + other.imag);
18  }
19 
20  // Overload the * operator
21  KOKKOS_INLINE_FUNCTION Complex operator*(const Complex& other) const {
22  return Complex(real * other.real - imag * other.imag,
23  real * other.imag + imag * other.real);
24  }
25 
26  // Overload the * operator
27  KOKKOS_INLINE_FUNCTION Complex operator*(double scalar) const {
28  return Complex(real * scalar, imag * scalar);
29  }
30 
31  // Multiply two complex numbers, but keep only the real component
32  KOKKOS_INLINE_FUNCTION static double r_mult(const Complex& a, const Complex& b) {
33  return a.real * b.real - a.imag * b.imag;
34  }
35 
36  KOKKOS_INLINE_FUNCTION static Complex expc(const Complex& c) {
37  double exp_real = exp(c.real);
38  return Complex(exp_real * cos(c.imag), exp_real * sin(c.imag));
39  }
40 
41  // exp of Complex(0.0, imag_in)
42  KOKKOS_INLINE_FUNCTION static Complex exp_i(double imag_in) {
43  return Complex(cos(imag_in), sin(imag_in));
44  }
45 };
46 
47 #endif
static KOKKOS_INLINE_FUNCTION double r_mult(const Complex &a, const Complex &b)
Definition: complex.hpp:32
double imag
Definition: complex.hpp:8
double real
Definition: complex.hpp:7
KOKKOS_INLINE_FUNCTION Complex(double r=0.0, double i=0.0)
Definition: complex.hpp:13
KOKKOS_INLINE_FUNCTION Complex operator+(const Complex &other) const
Definition: complex.hpp:16
static KOKKOS_INLINE_FUNCTION Complex expc(const Complex &c)
Definition: complex.hpp:36
static KOKKOS_INLINE_FUNCTION Complex exp_i(double imag_in)
Definition: complex.hpp:42
KOKKOS_INLINE_FUNCTION Complex operator*(const Complex &other) const
Definition: complex.hpp:21
Definition: complex.hpp:6
KOKKOS_INLINE_FUNCTION Complex operator*(double scalar) const
Definition: complex.hpp:27