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
102 template <
typename U>
114 template <
typename U>
126 template <
typename U>
139 template <
typename U>
153 template <
typename U>
161 out <<
" + " << c.
m_imag <<
"i";
254template <
typename T,
typename U>
266template <
typename T,
typename U>
330 return GpuComplex<T>(a_r * std::cos(a_theta), a_r * std::sin(a_theta));
340 return polar<T>(std::exp(a_z.real()), a_z.imag());
350 const T
x = a_z.real();
351 const T
y = a_z.imag();
352 return x *
x +
y *
y;
366 if (s == T()) {
return s; }
369 return s * std::sqrt(
x *
x +
y *
y);
384 T t = std::sqrt(std::abs(
y) / 2);
389 T t = std::sqrt(2 * (
amrex::abs(a_z) + std::abs(
x)));
404 return std::atan2(a_z.imag(), a_z.real());
424 if (a_z.imag() == T() && a_z.real() > T()) {
425 return std::pow(a_z.real(), a_y);
429 return amrex::polar<T>(std::exp(a_y * t.
real()), a_y * t.
imag());
434 template <
typename T>
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
__host__ __device__ GpuComplex< T > complex_pow_unsigned(GpuComplex< T > a_z, unsigned a_n)
Definition AMReX_GpuComplex.H:436
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:402
__host__ __device__ T norm(const GpuComplex< T > &a_z) noexcept
Return the norm (magnitude squared) of a complex number.
Definition AMReX_GpuComplex.H:348
__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:422
__host__ __device__ GpuComplex< T > operator*(const GpuComplex< T > &a_x, const GpuComplex< U > &a_y) noexcept
Multiply two complex numbers.
Definition AMReX_GpuComplex.H:256
__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:328
__host__ __device__ GpuComplex< T > log(const GpuComplex< T > &a_z) noexcept
Complex natural logarithm function.
Definition AMReX_GpuComplex.H:412
__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:360
__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:292
__host__ __device__ GpuComplex< T > exp(const GpuComplex< T > &a_z) noexcept
Complex expotential function.
Definition AMReX_GpuComplex.H:338
__host__ __device__ GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
Return the square root of a complex number.
Definition AMReX_GpuComplex.H:377
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
Definition AMReX_FabArrayCommI.H:1000
A host / device complex number type, because std::complex doesn't work in device code with Cuda yet.
Definition AMReX_GpuComplex.H:29
__host__ __device__ GpuComplex< T > & operator*=(const U &a_t) noexcept
Multiply this complex number by a real.
Definition AMReX_GpuComplex.H:80
__host__ __device__ GpuComplex< T > & operator/=(const U &a_t) noexcept
Divide this complex number by a real.
Definition AMReX_GpuComplex.H:92
T m_imag
Definition AMReX_GpuComplex.H:32
friend std::ostream & operator<<(std::ostream &out, const GpuComplex< U > &c)
Print this complex number to an ostream.
Definition AMReX_GpuComplex.H:158
__host__ __device__ GpuComplex< T > & operator+=(const U &a_t) noexcept
Add a real number to this complex number.
Definition AMReX_GpuComplex.H:58
__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:38
T value_type
Definition AMReX_GpuComplex.H:30
__host__ __device__ constexpr T real() const noexcept
Return the real part.
Definition AMReX_GpuComplex.H:45
T m_real
Definition AMReX_GpuComplex.H:32
__host__ __device__ constexpr T imag() const noexcept
Return the imaginary part.
Definition AMReX_GpuComplex.H:51
__host__ __device__ GpuComplex< T > & operator-=(const U &a_t) noexcept
Subtract a real number from this complex number.
Definition AMReX_GpuComplex.H:69