Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
core_mesh.h File Reference

basic functions to work with mesh More...

#include "stdafx.h"
#include "params.hpp"
#include "precision.hpp"
#include "class_mesh.hpp"
#include "class_particles.hpp"
#include "class_vec_3d.hpp"
Include dependency graph for core_mesh.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  IT< points >
 : class for effective iteration of cube of mesh cells More...
 

Functions

void get_k_vec (size_t N, size_t index, int *k_vec)
 
void get_k_vec (size_t N, size_t index, Vec_3D< int > &k_vec)
 
double get_k_sq (size_t N, size_t index)
 
template<typename T >
void get_per (Vec_3D< T > &position, size_t per)
 
template<typename T >
void get_per (Vec_3D< T > &position, size_t perx, size_t pery, size_t perz)
 
void get_per (std::vector< Particle_v< double >> &particles, const size_t per)
 
double get_distance (const Vec_3D< double > &x_1, const Vec_3D< double > &x_2, size_t per)
 
Vec_3D< doubleget_sgn_distance (const Vec_3D< double > &x_from, const Vec_3D< double > &x_to, size_t per)
 
void assign_to (Mesh &field, const Vec_3D< double > &position, const double value)
 
void assign_to (std::vector< Mesh > &field, const Vec_3D< double > &position, const Vec_3D< double > &value)
 
void assign_from (const Mesh &field, const Vec_3D< double > &position, double &value, double mod=1)
 
void assign_from (const std::vector< Mesh > &field, const Vec_3D< double > &position, Vec_3D< double > &value, double mod=1)
 
void fftw_execute_dft_r2c (const FFTW_PLAN_TYPE &p_F, Mesh &rho)
 compute forward (real to complex) FFT on mesh (inplace) More...
 
void fftw_execute_dft_c2r (const FFTW_PLAN_TYPE &p_B, Mesh &rho)
 compute backward (complex to real) FFT on mesh (inplace) More...
 
void fftw_execute_dft_r2c_triple (const FFTW_PLAN_TYPE &p_F, std::vector< Mesh > &rho)
 compute three forward (real to complex) FFTs on vector of meshes (inplace) More...
 
void fftw_execute_dft_c2r_triple (const FFTW_PLAN_TYPE &p_B, std::vector< Mesh > &rho)
 compute three backward (complex to real) FFTs on vector of meshes (inplace) More...
 

Detailed Description

basic functions to work with mesh

Author
Michal Vrastil
Date
2018-06-24

Definition in file core_mesh.h.

Function Documentation

void assign_from ( const Mesh field,
const Vec_3D< double > &  position,
double value,
double  mod = 1 
)

Definition at line 224 of file core_mesh.cpp.

References IT< points >::iter(), Mesh::N, and IT< points >::vec.

Referenced by kick_step_no_momentum(), App_Var_Chi::ChiImpl::kick_step_w_chi(), App_Var_Chi::ChiImpl::kick_step_w_chi_no_momentum(), kick_step_w_momentum(), kick_step_w_momentum_pm(), and anonymous_namespace{mod_frozen_potential.cpp}::kick_step_w_pp().

225 {
226  IT<ORDER+1> it(position);
227  do{
228  #pragma omp atomic
229  value += field(it.vec) * mod * wgh_sch<ORDER>(position, it.vec, field.N);
230  } while( it.iter() );
231 }
: class for effective iteration of cube of mesh cells
Definition: core_mesh.h:66
size_t N
Definition: class_mesh.hpp:102
auto value(T const &val) -> Generator< T >
Definition: catch.hpp:3177
void assign_from ( const std::vector< Mesh > &  field,
const Vec_3D< double > &  position,
Vec_3D< double > &  value,
double  mod = 1 
)

< reuse the same weigh for every field in std::vector

Definition at line 233 of file core_mesh.cpp.

References IT< points >::iter(), IT< points >::vec, and w.

234 {
235  IT<ORDER+1> it(position);
236  FTYPE_t w;
237  do{
238  w = mod * wgh_sch<ORDER>(position, it.vec, field[0].N);
239  for (unsigned int i = 0; i < 3; i++)
240  {
241  #pragma omp atomic
242  value[i] += field[i](it.vec) * w;
243  }
244  } while( it.iter() );
245 }
: class for effective iteration of cube of mesh cells
Definition: core_mesh.h:66
static double w[2][28][111]
Definition: ccl_emu17.c:33
void assign_to ( Mesh field,
const Vec_3D< double > &  position,
const double  value 
)

Definition at line 201 of file core_mesh.cpp.

References IT< points >::iter(), Mesh::N, and IT< points >::vec.

Referenced by get_rho_from_par(), and get_vel_from_par().

202 {
203  IT<ORDER+1> it(position);
204  do{
205  #pragma omp atomic
206  field(it.vec) += value * wgh_sch<ORDER>(position, it.vec, field.N);
207  } while( it.iter() );
208 }
: class for effective iteration of cube of mesh cells
Definition: core_mesh.h:66
size_t N
Definition: class_mesh.hpp:102
auto value(T const &val) -> Generator< T >
Definition: catch.hpp:3177
void assign_to ( std::vector< Mesh > &  field,
const Vec_3D< double > &  position,
const Vec_3D< double > &  value 
)

< reuse the same weigh for every field in std::vector

Definition at line 210 of file core_mesh.cpp.

References IT< points >::iter(), IT< points >::vec, and w.

211 {
212  IT<ORDER+1> it(position);
213  FTYPE_t w;
214  do{
215  w = wgh_sch<ORDER>(position, it.vec, field[0].N);
216  for (size_t i = 0; i < 3; i++)
217  {
218  #pragma omp atomic
219  field[i](it.vec) += value[i] * w;
220  }
221  } while( it.iter() );
222 }
: class for effective iteration of cube of mesh cells
Definition: core_mesh.h:66
static double w[2][28][111]
Definition: ccl_emu17.c:33
void fftw_execute_dft_c2r ( const FFTW_PLAN_TYPE p_B,
Mesh rho 
)

compute backward (complex to real) FFT on mesh (inplace)

Parameters
p_Bplan for backward transformation
rhomesh upon which the transformation is performed

Definition at line 253 of file core_mesh.cpp.

References Mesh::complex(), FFTW_EXEC_C2R, and Mesh_base< T >::real().

Referenced by fftw_execute_dft_c2r_triple(), anonymous_namespace{test_chameleon.cpp}::get_grav_pot(), App_Var_AA::pot_corr(), and anonymous_namespace{chameleon.cpp}::ChiSolver< T >::set_linear_sol_at_level().

254 {
255  FFTW_EXEC_C2R(p_B, rho.complex(), rho.real());
256 }
FFTW_COMPLEX_TYPE * complex()
get fftw_complex pointer to data
Definition: class_mesh.hpp:111
T * real()
Definition: class_mesh.hpp:36
#define FFTW_EXEC_C2R
Definition: precision.hpp:35
void fftw_execute_dft_c2r_triple ( const FFTW_PLAN_TYPE p_B,
std::vector< Mesh > &  rho 
)

compute three backward (complex to real) FFTs on vector of meshes (inplace)

Parameters
p_Bplan for backward transformations
rhovector of meshes upon which the transformations are performed

Definition at line 263 of file core_mesh.cpp.

References fftw_execute_dft_c2r(), and get_per().

Referenced by App_Var_AA::AAImpl::aa_convolution(), App_Var_Chi::ChiImpl::get_chi_force(), App_Var_FP_mod::pot_corr(), App_Var< T >::pot_corr(), and App_Var< T >::Impl< T >::set_init_cond().

264 {
265  for (unsigned int i = 0; i < 3; i++) fftw_execute_dft_c2r(p_B, rho[i]);
266 }
void fftw_execute_dft_c2r(const FFTW_PLAN_TYPE &p_B, Mesh &rho)
compute backward (complex to real) FFT on mesh (inplace)
Definition: core_mesh.cpp:253
void fftw_execute_dft_r2c ( const FFTW_PLAN_TYPE p_F,
Mesh rho 
)

compute forward (real to complex) FFT on mesh (inplace)

Parameters
p_Fplan for forward transformation
rhomesh upon which the transformation is performed

Definition at line 247 of file core_mesh.cpp.

References Mesh::complex(), FFTW_EXEC_R2C, Mesh::N, pow(), and Mesh_base< T >::real().

Referenced by App_Var_AA::AAImpl::aa_convolution(), fftw_execute_dft_r2c_triple(), App_Var_Chi::ChiImpl::gen_pow_spec_binned(), gen_rho_dist_k(), App_Var< T >::Impl< T >::get_binned_power_spec(), App_Var_Chi::ChiImpl::get_chi_force(), anonymous_namespace{test_chameleon.cpp}::get_grav_pot(), anonymous_namespace{chameleon.cpp}::ChiSolver< T >::set_linear_sol_at_level(), and App_Var_PM::upd_pos().

248 {
249  FFTW_EXEC_R2C(p_F, rho.real(), rho.complex());
250  rho /= pow((FTYPE_t)rho.N, 3); //< normalization
251 }
FFTW_COMPLEX_TYPE * complex()
get fftw_complex pointer to data
Definition: class_mesh.hpp:111
T * real()
Definition: class_mesh.hpp:36
size_t N
Definition: class_mesh.hpp:102
#define FFTW_EXEC_R2C
Definition: precision.hpp:34
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
void fftw_execute_dft_r2c_triple ( const FFTW_PLAN_TYPE p_F,
std::vector< Mesh > &  rho 
)

compute three forward (real to complex) FFTs on vector of meshes (inplace)

Parameters
p_Fplan for forward transformations
rhovector of meshes upon which the transformations are performed

Definition at line 258 of file core_mesh.cpp.

References fftw_execute_dft_r2c().

Referenced by App_Var< T >::Impl< T >::print_vel_pwr().

259 {
260  for (unsigned int i = 0; i < 3; i++) fftw_execute_dft_r2c(p_F, rho[i]);
261 }
void fftw_execute_dft_r2c(const FFTW_PLAN_TYPE &p_F, Mesh &rho)
compute forward (real to complex) FFT on mesh (inplace)
Definition: core_mesh.cpp:247
double get_distance ( const Vec_3D< double > &  x_1,
const Vec_3D< double > &  x_2,
size_t  per 
)
double get_k_sq ( size_t  N,
size_t  index 
)

Definition at line 38 of file core_mesh.cpp.

References get_k_vec(), and pow2().

Referenced by gen_pot_k(), gen_rho_w_pow_k(), and anonymous_namespace{chameleon.cpp}::ChiSolver< T >::get_chi_k().

39 {
40  int k_vec[3];
41  FTYPE_t tmp = 0;
42  get_k_vec(N, index, k_vec);
43  for (unsigned int i = 0; i<3; i++) tmp += pow2(k_vec[i]);
44  return tmp;
45 }
T pow2(T base)
Definition: precision.hpp:52
void get_k_vec(size_t N, size_t index, int *k_vec)
Definition: core_mesh.cpp:20
void get_k_vec ( size_t  N,
size_t  index,
int *  k_vec 
)

Definition at line 20 of file core_mesh.cpp.

Referenced by gen_displ_k_S2(), get_k_sq(), pwr_spec_k(), pwr_spec_k_init(), and vel_pwr_spec_k().

21 {
22  k_vec[0] = index / ((N/2 + 1)*N);
23  k_vec[1] = (index / (N/2 + 1)) % N;
24  k_vec[2] = index % (N/2 + 1);
25 
26  for (unsigned int i = 0; i<2; i++) if (k_vec[i] > N/2) k_vec[i] -= N; // k_vec[2] is ALWAYS less or equal than N/2 (real FFTW)
27 }
void get_k_vec ( size_t  N,
size_t  index,
Vec_3D< int > &  k_vec 
)

Definition at line 29 of file core_mesh.cpp.

30 {
31  k_vec[0] = index / ((N/2 + 1)*N);
32  k_vec[1] = (index / (N/2 + 1)) % N;
33  k_vec[2] = index % (N/2 + 1);
34 
35  for (unsigned int i = 0; i<2; i++) if (k_vec[i] > N/2) k_vec[i] -= N; // k_vec[2] is ALWAYS less or equal than N/2 (real FFTW)
36 }
template<typename T >
void get_per ( Vec_3D< T > &  position,
size_t  per 
)

Definition at line 66 of file core_mesh.cpp.

67 {
68  for (T& pos : position) pos = get_per(pos, per);
69 }
static std::enable_if< std::is_integral< T >::value, T >::type get_per(T vec, size_t per)
Definition: core_mesh.cpp:48
template<typename T >
void get_per ( Vec_3D< T > &  position,
size_t  perx,
size_t  pery,
size_t  perz 
)

Definition at line 72 of file core_mesh.cpp.

73 {
74  position[0] = get_per(position[0], perx);
75  position[1] = get_per(position[1], pery);
76  position[2] = get_per(position[2], perz);
77 }
static std::enable_if< std::is_integral< T >::value, T >::type get_per(T vec, size_t per)
Definition: core_mesh.cpp:48
void get_per ( std::vector< Particle_v< double >> &  particles,
const size_t  per 
)

Definition at line 79 of file core_mesh.cpp.

References get_per().

80 {
81  const size_t Np = particles.size();
82  #pragma omp parallel for
83  for (size_t i = 0; i < Np; i++)
84  {
85  get_per(particles[i].position, per);
86  }
87 }
static std::enable_if< std::is_integral< T >::value, T >::type get_per(T vec, size_t per)
Definition: core_mesh.cpp:48
Vec_3D<double> get_sgn_distance ( const Vec_3D< double > &  x_from,
const Vec_3D< double > &  x_to,
size_t  per 
)

Definition at line 122 of file core_mesh.cpp.

References get_sgn_distance_1D(), wgh_sch(), and x.

Referenced by anonymous_namespace{mod_frozen_potential.cpp}::force_short().

123 {
124  Vec_3D<FTYPE_t> dst;
125  for (unsigned int i = 0; i < 3; i++) dst[i] = get_sgn_distance_1D(x_from[i], x_to[i], per);
126  return dst;
127 }
T get_sgn_distance_1D(T x_from, T x_to, size_t per)
Definition: core_mesh.cpp:104