1 #ifndef AMREX_GPUCOMPLEX_H_
2 #define AMREX_GPUCOMPLEX_H_
3 #include <AMReX_Config.H>
12 template <
typename T>
struct GpuComplex;
16 T
norm (
const GpuComplex<T>& a_z) noexcept;
38 constexpr
GpuComplex (
const T& a_r = T(),
const T& a_i = T()) noexcept
110 template <
typename U>
122 template <
typename U>
126 const T a_r =
m_real * a_z.real() -
m_imag * a_z.imag();
135 template <
typename U>
149 template <
typename U>
153 template <
typename U>
157 out <<
" + " << c.
m_imag <<
"i";
178 template <
typename T>
190 template <
typename T>
202 template <
typename T>
214 template <
typename T>
226 template <
typename T>
238 template <
typename T>
250 template <
typename T>
262 template <
typename T>
274 template <
typename T>
286 template <
typename T>
298 template <
typename T>
310 template <
typename T>
322 template <
typename T>
326 return GpuComplex<T>(a_r * std::cos(a_theta), a_r * std::sin(a_theta));
332 template <
typename T>
336 return polar<T>(
std::exp(a_z.real()), a_z.imag());
342 template <
typename T>
346 const T
x = a_z.real();
347 const T y = a_z.imag();
348 return x *
x + y * y;
354 template <
typename T>
362 if (s == T()) {
return s; }
371 template <
typename T>
396 template <
typename T>
400 return std::atan2(a_z.imag(), a_z.real());
406 template <
typename T>
416 template <
typename T>
420 if (a_z.imag() == T() && a_z.real() > T()) {
430 template <
typename T>
451 template <
typename T>
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > complex_pow_unsigned(GpuComplex< T > a_z, unsigned a_n)
Definition: AMReX_GpuComplex.H:432
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > operator/(const GpuComplex< T > &a_x, const GpuComplex< T > &a_y) noexcept
Divide a complex number by another one.
Definition: AMReX_GpuComplex.H:288
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > log(const GpuComplex< T > &a_z) noexcept
Complex natural logarithm function.
Definition: AMReX_GpuComplex.H:408
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & max(const T &a, const T &b) noexcept
Definition: AMReX_Algorithm.H:35
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > polar(const T &a_r, const T &a_theta) noexcept
Return a complex number given its polar representation.
Definition: AMReX_GpuComplex.H:324
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T abs(const GpuComplex< T > &a_z) noexcept
Return the absolute value of a complex number.
Definition: AMReX_GpuComplex.H:356
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, int a_n) noexcept
Raise a complex number to an integer power.
Definition: AMReX_GpuComplex.H:453
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T norm(const GpuComplex< T > &a_z) noexcept
Return the norm (magnitude squared) of a complex number.
Definition: AMReX_GpuComplex.H:344
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T arg(const GpuComplex< T > &a_z) noexcept
Return the angle of a complex number's polar representation.
Definition: AMReX_GpuComplex.H:398
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
Raise a complex number to a (real) power.
Definition: AMReX_GpuComplex.H:418
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > operator-(const GpuComplex< T > &a_x)
Negate a complex number.
Definition: AMReX_GpuComplex.H:173
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > exp(const GpuComplex< T > &a_z) noexcept
Complex expotential function.
Definition: AMReX_GpuComplex.H:334
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > operator+(const GpuComplex< T > &a_x)
Identity operation on a complex number.
Definition: AMReX_GpuComplex.H:166
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Definition: AMReX_AmrMesh.cpp:1236
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > operator*(const GpuComplex< T > &a_x, const GpuComplex< T > &a_y) noexcept
Multiply two complex numbers.
Definition: AMReX_GpuComplex.H:252
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
Return the square root of a complex number.
Definition: AMReX_GpuComplex.H:373
Definition: AMReX_FabArrayCommI.H:841
A host / device complex number type, because std::complex doesn't work in device code with Cuda yet.
Definition: AMReX_GpuComplex.H:29
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE GpuComplex(const T &a_r=T(), const T &a_i=T()) noexcept
Construct a complex number given the real and imaginary part.
Definition: AMReX_GpuComplex.H:38
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE T real() const noexcept
Return the real part.
Definition: AMReX_GpuComplex.H:45
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > & operator-=(const T &a_t) noexcept
Subtract a real number from this complex number.
Definition: AMReX_GpuComplex.H:67
friend std::ostream & operator<<(std::ostream &out, const GpuComplex< U > &c)
Print this complex number to an ostream.
Definition: AMReX_GpuComplex.H:154
T m_imag
Definition: AMReX_GpuComplex.H:32
T value_type
Definition: AMReX_GpuComplex.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > & operator/=(const T &a_t) noexcept
Divide this complex number by a real.
Definition: AMReX_GpuComplex.H:88
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > & operator*=(const T &a_t) noexcept
Multiply this complex number by a real.
Definition: AMReX_GpuComplex.H:77
T m_real
Definition: AMReX_GpuComplex.H:32
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE T imag() const noexcept
Return the imaginary part.
Definition: AMReX_GpuComplex.H:51
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > & operator+=(const T &a_t) noexcept
Add a real number to this complex number.
Definition: AMReX_GpuComplex.H:57