1#ifndef AMREX_GPUCOMPLEX_H_
2#define AMREX_GPUCOMPLEX_H_
3#include <AMReX_Config.H>
12template <
typename T>
struct GpuComplex;
16T
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>
135 template <
typename U>
149 template <
typename U>
157 out <<
" + " << c.
m_imag <<
"i";
326 return GpuComplex<T>(a_r * std::cos(a_theta), a_r * std::sin(a_theta));
336 return polar<T>(std::exp(a_z.real()), a_z.imag());
346 const T
x = a_z.real();
347 const T y = a_z.imag();
348 return x *
x + y * y;
362 if (s == T()) {
return s; }
365 return s * std::sqrt(
x *
x + y * y);
380 T t = std::sqrt(std::abs(y) / 2);
385 T t = std::sqrt(2 * (
amrex::abs(a_z) + std::abs(
x)));
400 return std::atan2(a_z.imag(), a_z.real());
420 if (a_z.imag() == T() && a_z.real() > T()) {
421 return std::pow(a_z.real(), a_y);
425 return amrex::polar<T>(std::exp(a_y * t.
real()), a_y * t.
imag());
430 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 > log(const GpuComplex< T > &a_z) noexcept
Complex natural logarithm function.
Definition AMReX_GpuComplex.H:408
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
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 > sqrt(const GpuComplex< T > &a_z) noexcept
Return the square root of a complex number.
Definition AMReX_GpuComplex.H:373
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, const GpuComplex< T > &a_y) noexcept
Multiply two complex numbers.
Definition AMReX_GpuComplex.H:252
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 > 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 > 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 constexpr 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 GpuComplex< T > operator-(const GpuComplex< T > &a_x)
Negate a complex number.
Definition AMReX_GpuComplex.H:173
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Definition AMReX_AmrMesh.cpp:1236
Definition AMReX_FabArrayCommI.H:896
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 AMREX_FORCE_INLINE constexpr T real() const noexcept
Return the real part.
Definition AMReX_GpuComplex.H:45
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr 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
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_imag
Definition AMReX_GpuComplex.H:32
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
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr 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
T value_type
Definition AMReX_GpuComplex.H:30
T m_real
Definition AMReX_GpuComplex.H:32