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;
39 constexpr GpuComplex (
const T& a_r = T(),
const T& a_i = T()) noexcept
103 template <
typename U>
115 template <
typename U>
127 template <
typename U>
140 template <
typename U>
154 template <
typename U>
162 out <<
" + " << c.
m_imag <<
"i";
255template <
typename T,
typename U>
267template <
typename T,
typename U>
331 return GpuComplex<T>(a_r * std::cos(a_theta), a_r * std::sin(a_theta));
341 return polar<T>(std::exp(a_z.real()), a_z.imag());
351 const T
x = a_z.real();
352 const T
y = a_z.imag();
353 return x *
x +
y *
y;
367 if (s == T()) {
return s; }
370 return s * std::sqrt(
x *
x +
y *
y);
385 T t = std::sqrt(std::abs(
y) / 2);
390 T t = std::sqrt(2 * (
amrex::abs(a_z) + std::abs(
x)));
405 return std::atan2(a_z.imag(), a_z.real());
425 if (a_z.imag() == T() && a_z.real() > T()) {
426 return std::pow(a_z.real(), a_y);
430 return amrex::polar<T>(std::exp(a_y * t.
real()), a_y * t.
imag());
436 template <
typename T>
438 GpuComplex<T> complex_pow_unsigned (GpuComplex<T> a_z,
unsigned a_n)
440 GpuComplex<T> y = a_n % 2 ? a_z : GpuComplex<T>(1);
463 ?
GpuComplex<T>(1) / detail::complex_pow_unsigned(a_z, (
unsigned)(-a_n))
464 : detail::complex_pow_unsigned(a_z, a_n);
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
Definition AMReX_Amr.cpp:49
__host__ __device__ T arg(const GpuComplex< T > &a_z) noexcept
Return the angle of a complex number's polar representation.
Definition AMReX_GpuComplex.H:403
__host__ __device__ T norm(const GpuComplex< T > &a_z) noexcept
Return the norm (magnitude squared) of a complex number.
Definition AMReX_GpuComplex.H:349
__host__ __device__ 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:423
__host__ __device__ GpuComplex< T > operator*(const GpuComplex< T > &a_x, const GpuComplex< U > &a_y) noexcept
Multiply two complex numbers.
Definition AMReX_GpuComplex.H:257
__host__ __device__ GpuComplex< T > polar(const T &a_r, const T &a_theta) noexcept
Return a complex number given its polar representation.
Definition AMReX_GpuComplex.H:329
__host__ __device__ GpuComplex< T > log(const GpuComplex< T > &a_z) noexcept
Complex natural logarithm function.
Definition AMReX_GpuComplex.H:413
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:35
__host__ __device__ T abs(const GpuComplex< T > &a_z) noexcept
Return the absolute value of a complex number.
Definition AMReX_GpuComplex.H:361
__host__ __device__ 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:293
__host__ __device__ GpuComplex< T > exp(const GpuComplex< T > &a_z) noexcept
Complex expotential function.
Definition AMReX_GpuComplex.H:339
__host__ __device__ GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
Return the square root of a complex number.
Definition AMReX_GpuComplex.H:378
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Definition AMReX_AmrMesh.cpp:1236
__host__ __device__ XDim3 operator-(XDim3 const &a, XDim3 const &b)
Definition AMReX_Dim3.H:34
__host__ __device__ XDim3 operator+(XDim3 const &a, XDim3 const &b)
Definition AMReX_Dim3.H:28
A host / device complex number type, because std::complex doesn't work in device code with Cuda yet.
Definition AMReX_GpuComplex.H:30
__host__ __device__ GpuComplex< T > & operator*=(const U &a_t) noexcept
Multiply this complex number by a real.
Definition AMReX_GpuComplex.H:81
__host__ __device__ GpuComplex< T > & operator/=(const U &a_t) noexcept
Divide this complex number by a real.
Definition AMReX_GpuComplex.H:93
T m_imag
Definition AMReX_GpuComplex.H:33
friend std::ostream & operator<<(std::ostream &out, const GpuComplex< U > &c)
Print this complex number to an ostream.
Definition AMReX_GpuComplex.H:159
__host__ __device__ GpuComplex< T > & operator+=(const U &a_t) noexcept
Add a real number to this complex number.
Definition AMReX_GpuComplex.H:59
__host__ __device__ 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:39
T value_type
Definition AMReX_GpuComplex.H:31
__host__ __device__ constexpr T real() const noexcept
Return the real part.
Definition AMReX_GpuComplex.H:46
T m_real
Definition AMReX_GpuComplex.H:33
__host__ __device__ constexpr T imag() const noexcept
Return the imaginary part.
Definition AMReX_GpuComplex.H:52
__host__ __device__ GpuComplex< T > & operator-=(const U &a_t) noexcept
Subtract a real number from this complex number.
Definition AMReX_GpuComplex.H:70