TURTLE
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
kspace< be, dt > Class Template Reference

A class for handling Fourier representation tasks. More...

#include <kspace.hpp>

Inheritance diagram for kspace< be, dt >:
Inheritance graph
[legend]
Collaboration diagram for kspace< be, dt >:
Collaboration graph
[legend]

Public Member Functions

template<field_components fc>
 kspace (const field_layout< fc > *source_layout, const double DKX=1.0, const double DKY=1.0, const double DKZ=1.0)
 
 ~kspace () noexcept(false)
 
int store (hid_t stat_file)
 
template<typename rnumber , field_components fc>
void low_pass (typename fftw_interface< rnumber >::complex *__restrict__ a, const double kmax)
 
template<typename rnumber , field_components fc>
void Gauss_filter (typename fftw_interface< rnumber >::complex *__restrict__ a, const double sigma)
 Filter a field using a Gaussian kernel.
 
template<typename rnumber , field_components fc>
void ball_filter (typename fftw_interface< rnumber >::complex *__restrict__ a, const double sigma)
 Filter a field using a ball shaped top hat filter.
 
template<typename rnumber , field_components fc>
int filter (typename fftw_interface< rnumber >::complex *__restrict__ a, const double wavenumber, std::string filter_type=std::string("Gauss"))
 Filter a field.
 
template<typename rnumber , field_components fc>
int filter_calibrated_ell (typename fftw_interface< rnumber >::complex *__restrict__ a, const double wavenumber, std::string filter_type=std::string("Gauss"))
 Filter a field.
 
template<typename rnumber , field_components fc>
void dealias (typename fftw_interface< rnumber >::complex *__restrict__ a)
 
template<typename rnumber , field_components fc>
void cospectrum (const rnumber(*__restrict__ a)[2], const rnumber(*__restrict__ b)[2], const hid_t group, const std::string dset_name, const hsize_t toffset, const double wavenumber_exp=0)
 
template<typename rnumber , field_components fc>
void cospectrum (const rnumber(*__restrict__ a)[2], const hid_t group, const std::string dset_name, const hsize_t toffset, const double wavenumber_exp=0)
 
template<typename rnumber , field_components fc>
void cospectrum (const rnumber(*__restrict__ a)[2], std::vector< double > &spec, const double wavenumber_exp=0)
 
template<typename rnumber , field_components fc>
double L2norm (const rnumber(*__restrict__ a)[2])
 
template<class func_type >
void CLOOP (func_type expression)
 
template<class func_type >
void CLOOP_simd (func_type expression)
 
template<class func_type >
void CLOOP_K2 (func_type expression)
 
template<class func_type >
void CLOOP_K2_simd (func_type expression)
 
template<class func_type >
void CLOOP_K2_NXMODES (func_type expression)
 
template<typename rnumber >
void project_divfree (typename fftw_interface< rnumber >::complex *__restrict__ a, const bool maintain_energy=false)
 
template<typename rnumber >
void force_divfree (typename fftw_interface< rnumber >::complex *__restrict__ a)
 
template<typename rnumber >
void rotate_divfree (typename fftw_interface< rnumber >::complex *__restrict__ a)
 Rotate vector modes perpendicular to wavenumber This is different from project because it maintains the energy of the field, I want it in order to be able to generate random fields with prescribed spectra.
 

Data Fields

field_layout< ONE > * layout
 
double dkx
 
double dky
 
double dkz
 
double dk
 
double dk2
 
double kMx
 
double kMy
 
double kMz
 
double kM
 
double kM2
 
std::vector< doublekx
 
std::vector< doubleky
 
std::vector< doublekz
 
std::vector< doublekshell
 
std::vector< int64_tnshell
 
int nshells
 

Detailed Description

template<field_backend be, kspace_dealias_type dt>
class kspace< be, dt >

A class for handling Fourier representation tasks.

Template Parameters
befield backend, currently only FFTW is possible.
dtdealiasing mode, either ONE_HALF, TWO_THIRDS or SMOOTH.

Contains wavenumber information (specific to each MPI process). This includes values of kx, ky, kz, including lowest modes dkx etc, as well as number of modes within sferical shells and mean wavenumber within shells.

Constructor & Destructor Documentation

◆ kspace()

template<field_components fc>
kspace< be, dt >::kspace ( const field_layout< fc > * source_layout,
const double DKX = 1.0,
const double DKY = 1.0,
const double DKZ = 1.0 )

◆ ~kspace()

kspace< be, dt >::~kspace ( )

Member Function Documentation

◆ ball_filter()

void kspace< be, dt >::ball_filter ( typename fftw_interface< rnumber >::complex *__restrict__ a,
const double ell )

Filter a field using a ball shaped top hat filter.

Filter's mathematical expression in real space is as follows:

\[ \phi^b_\ell(r) = \frac{1}{\ell^3}\frac{6}{\pi} H(\ell/2 - r) \]

with the corresponding Fourier space expression:

\[ \hat{\phi^b_\ell}(k) = \frac{3}{2(k\ell/2)^3} \left(2\sin (k \ell/2) - k \ell \cos (k \ell/2)\right) \]

◆ CLOOP()

template<class func_type >
void kspace< be, dt >::CLOOP ( func_type expression)
inline

◆ CLOOP_K2()

template<class func_type >
void kspace< be, dt >::CLOOP_K2 ( func_type expression)
inline

◆ CLOOP_K2_NXMODES()

template<class func_type >
void kspace< be, dt >::CLOOP_K2_NXMODES ( func_type expression)
inline

◆ CLOOP_K2_simd()

template<class func_type >
void kspace< be, dt >::CLOOP_K2_simd ( func_type expression)
inline

◆ CLOOP_simd()

template<class func_type >
void kspace< be, dt >::CLOOP_simd ( func_type expression)
inline

◆ cospectrum() [1/3]

void kspace< be, dt >::cospectrum ( const rnumber(*) a[2],
const hid_t group,
const std::string dset_name,
const hsize_t toffset,
const double wavenumber_exp = 0 )

◆ cospectrum() [2/3]

void kspace< be, dt >::cospectrum ( const rnumber(*) a[2],
const rnumber(*) b[2],
const hid_t group,
const std::string dset_name,
const hsize_t toffset,
const double wavenumber_exp = 0 )

◆ cospectrum() [3/3]

void kspace< be, dt >::cospectrum ( const rnumber(*) a[2],
std::vector< double > & spec,
const double wavenumber_exp = 0 )

◆ dealias()

void kspace< be, dt >::dealias ( typename fftw_interface< rnumber >::complex *__restrict__ a)

◆ filter()

int kspace< be, dt >::filter ( typename fftw_interface< rnumber >::complex *__restrict__ a,
const double wavenumber,
std::string filter_type = std::string("Gauss") )

Filter a field.

Template Parameters
rnumbertype of real number, float or double.
fcfield components, ONE, THREE or THREExTHREE.
Returns
exit mode (integer), EXIT_SUCCESS or arbitrary value for failure.

This is a wrapper that can choose between a sharp Fourier spherical filter, a Gaussian filter and a sharp real space spherical filter.

Filter expressions in real space are as follows:

\[ \phi^b_\ell(r) = \frac{1}{\ell^3}\frac{6}{\pi} H(\ell/2 - r) \]

\[ \phi^g_\ell(r) = \frac{1}{\sigma_\ell^3}\frac{1}{(2\pi)^{3/2}} \exp\left(-\frac{1}{2}\left(\frac{r}{\sigma_\ell}\right)^2\right) \]

\[ \phi^s_\ell(r) = \frac{1}{2 \pi^2 r^3} \left(\sin k_\ell r - k_\ell r \cos k_\ell r\right) \]

and the corresponding expressions in Fourier space are:

\[ \hat{\phi^b_\ell}(k) = \frac{3}{2(k\ell/2)^3} \left(2\sin (k \ell/2) - k \ell \cos (k \ell/2)\right) \]

\[ \hat{\phi^g_\ell}(k) = \exp\left(-\frac{1}{2}k^2 \sigma_\ell^2\right) \]

\[ \hat{\phi^s_\ell}(k) = H(k_\ell - k) \]

\( k_\ell \) is given as a parameter, and then we use

\[ \ell = \pi / k_\ell, \sigma_\ell = \pi / k_\ell \]

For the Gaussian filter this is the same convention used in [Buzzicotti2017] .

See also filter_calibrated_ell.

◆ filter_calibrated_ell()

int kspace< be, dt >::filter_calibrated_ell ( typename fftw_interface< rnumber >::complex *__restrict__ a,
const double ell,
std::string filter_type = std::string("Gauss") )

Filter a field.

This is a wrapper that can choose between a sharp Fourier spherical filter, a Gaussian filter and a sharp real space spherical filter.

Filter expressions in real space are as follows:

embed:rst:leading-asterisk
*  .. math::
*      :nowrap:
*
*      \begin{eqnarray*}
*          \phi^b_\ell(r) &=&
*              \frac{1}{\ell^3}\frac{6}{\pi} H(\ell/2 - r) \\
*          \phi^g_\ell(r) &=&
*              \frac{1}{\sigma_\ell^3}\frac{1}{(2\pi)^{3/2}}
*              \exp\left(-\frac{1}{2}\left(\frac{r}{\sigma_\ell}\right)^2\right) \\
*          \phi^s_\ell(r) &=&
*              \frac{1}{2 \pi^2 r^3}
*              \left(\sin k_\ell r - k_\ell r \cos k_\ell r\right)
*      \end{eqnarray*}
*
*  

and the corresponding expressions in Fourier space are:

embed:rst:leading-asterisk
*  .. math::
*      :nowrap:
*
*      \begin{eqnarray*}
*          \hat{\phi^b_\ell}(k) &=&
*          \frac{3}{2(k\ell/2)^3}
*          \left(2\sin (k \ell/2) - k \ell \cos (k \ell/2)\right) \\
*          \hat{\phi^g_\ell}(k) &=&
*          \exp\left(-\frac{1}{2}k^2 \sigma_\ell^2\right) \\
*          \hat{\phi^s_\ell}(k) &=& H(k_\ell - k)
*      \end{eqnarray*}
*
*  

\(\sigma_\ell\) and \(k_\ell\) are calibrated such that the energy of the large scales is approximately the same (within the inertial range) independently of the shape of the filter.

This was done by hand, see [lalescu2018jfm]_ for details, with the results:

\[ \sigma_\ell = 0.23 \ell, k_\ell = 2.8 / \ell \]

◆ force_divfree()

template<typename rnumber >
void kspace< be, dt >::force_divfree ( typename fftw_interface< rnumber >::complex *__restrict__ a)
inline

◆ Gauss_filter()

void kspace< be, dt >::Gauss_filter ( typename fftw_interface< rnumber >::complex *__restrict__ a,
const double sigma )

Filter a field using a Gaussian kernel.

Template Parameters
rnumbertype of real number, float or double.
fcfield components, ONE, THREE or THREExTHREE.
Returns
nothing

Filter's mathematical expression in Fourier space is as follows:

\[ \hat{g}_\ell(\mathbf{k}) = \exp(-k^2 \sigma^2 / 2) \]

◆ L2norm()

double kspace< be, dt >::L2norm ( const rnumber(*) a[2])

◆ low_pass()

void kspace< be, dt >::low_pass ( typename fftw_interface< rnumber >::complex *__restrict__ a,
const double kmax )

◆ project_divfree()

template<typename rnumber >
void kspace< be, dt >::project_divfree ( typename fftw_interface< rnumber >::complex *__restrict__ a,
const bool maintain_energy = false )

◆ rotate_divfree()

template<typename rnumber >
void kspace< be, dt >::rotate_divfree ( typename fftw_interface< rnumber >::complex *__restrict__ a)

Rotate vector modes perpendicular to wavenumber This is different from project because it maintains the energy of the field, I want it in order to be able to generate random fields with prescribed spectra.

◆ store()

int kspace< be, dt >::store ( hid_t stat_file)

Field Documentation

◆ dk

double kspace< be, dt >::dk

◆ dk2

double kspace< be, dt >::dk2

◆ dkx

double kspace< be, dt >::dkx

◆ dky

double kspace< be, dt >::dky

◆ dkz

double kspace< be, dt >::dkz

◆ kM

double kspace< be, dt >::kM

◆ kM2

double kspace< be, dt >::kM2

◆ kMx

double kspace< be, dt >::kMx

◆ kMy

double kspace< be, dt >::kMy

◆ kMz

double kspace< be, dt >::kMz

◆ kshell

std::vector<double> kspace< be, dt >::kshell

◆ kx

std::vector<double> kspace< be, dt >::kx

◆ ky

std::vector<double> kspace< be, dt >::ky

◆ kz

std::vector<double> kspace< be, dt >::kz

◆ layout

field_layout<ONE>* kspace< be, dt >::layout

◆ nshell

std::vector<int64_t> kspace< be, dt >::nshell

◆ nshells

int kspace< be, dt >::nshells

The documentation for this class was generated from the following files: