Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
anonymous_namespace{test_chameleon.cpp} Namespace Reference

Functions

template<typename T >
mean (const std::vector< T > &data)
 
double mean (const Mesh &data)
 
void get_neighbor_gridindex (std::vector< size_t > &index_list, size_t i, size_t N)
 
void init_overdensity (Sim_Param &sim, Mesh &rho, MultiGrid< 3, CHI_PREC_t > &rho_grid)
 
void get_grav_pot (Mesh &rho, const FFTW_PLAN_TYPE &p_F, const FFTW_PLAN_TYPE &p_B, double box_size, double phi_prefactor)
 
template<typename T >
static int sgn (T val)
 
void print_mesh (const std::string &file_name, const Mesh &pot, const double mod=-1-CHI_MIN)
 

Function Documentation

void anonymous_namespace{test_chameleon.cpp}::get_grav_pot ( Mesh rho,
const FFTW_PLAN_TYPE p_F,
const FFTW_PLAN_TYPE p_B,
double  box_size,
double  phi_prefactor 
)

Definition at line 73 of file test_chameleon.cpp.

References fftw_execute_dft_c2r(), fftw_execute_dft_r2c(), gen_pot_k(), Mesh::N, and pow().

Referenced by TEST_CASE().

74 {
75  fftw_execute_dft_r2c(p_F, rho);
76  gen_pot_k(rho);
77  fftw_execute_dft_c2r(p_B, rho);
78  rho *= pow(box_size / rho.N, 2) // computing units (laplace)
79  * phi_prefactor; // prefactor of poisson equation
80 }
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
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 gen_pot_k(const Mesh &rho_k, Mesh &pot_k)
Definition: core_app.cpp:496
size_t N
Definition: class_mesh.hpp:102
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
void anonymous_namespace{test_chameleon.cpp}::get_neighbor_gridindex ( std::vector< size_t > &  index_list,
size_t  i,
size_t  N 
)

Definition at line 20 of file test_chameleon.cpp.

Referenced by anonymous_namespace{chameleon.cpp}::ChiSolver< T >::check_surr_dens(), anonymous_namespace{chameleon.cpp}::ChiSolver< T >::correct_sol(), and TEST_CASE().

21 {
22  index_list = std::vector<size_t>(7);
23  index_list[0] = i;
24  for(size_t j = 0, n = 1; j < 3; j++, n *= N){
25  size_t ii = i/n % N;
26  size_t iminus = ii >= 1 ? ii - 1 : N - 1;
27  size_t iplus = ii <= N-2 ? ii + 1 : 0;
28  index_list[2*j+1] = i + (iminus - ii) * n;
29  index_list[2*j+2] = i + (iplus - ii) * n;
30  }
31 }
void anonymous_namespace{test_chameleon.cpp}::init_overdensity ( Sim_Param sim,
Mesh rho,
MultiGrid< 3, CHI_PREC_t > &  rho_grid 
)

Definition at line 33 of file test_chameleon.cpp.

References mfunc_bm::iz, Mesh_base< T >::length, mean(), Test_Opt::N_grid, pow2(), Test_Opt::R_sphere, REQUIRE, Test_Opt::rho_b, Test_Opt::rho_sphere, Sim_Param::test_opt, and anonymous_namespace{chameleon.cpp}::transform_Mesh_to_MultiGrid().

Referenced by TEST_CASE().

34 {
35  const size_t N = sim.test_opt.N_grid;
36  const FTYPE_t R = sim.test_opt.R_sphere;
37  const FTYPE_t rho_0 = sim.test_opt.rho_sphere;
38  const size_t N_tot = rho.length;
39 
40  FTYPE_t mean_rho;
41  FTYPE_t R2_;
42  const FTYPE_t R2 = R*R;
43  size_t ix0 = N/2, iy0 = N/2, iz0 = N/2;
44 
45  #pragma omp parallel for private(R2_)
46  for (size_t ix = 0; ix < N; ++ix)
47  {
48  for (size_t iy = 0; iy < N; ++iy)
49  {
50  for (size_t iz = 0; iz < N; ++iz)
51  {
52  R2_ = pow2(ix - ix0) + pow2(iy - iy0) + pow2(iz - iz0);
53  rho(ix, iy, iz) = R2_ <= R2 ? rho_0 : 0;
54  }
55  }
56  }
57  mean_rho = mean(rho);
58 
59  if (mean_rho > 1) throw std::out_of_range("invalid values of sphere parameters (overdensity: " + std::to_string(-mean_rho) + " < -1)");
60 
61  rho -= mean_rho;
62  transform_Mesh_to_MultiGrid(rho, rho_grid);
63 
64  // check density
65  REQUIRE( mean(rho) == Approx(0.) );
66  REQUIRE( rho(ix0, iy0, iz0) == Approx(rho_0 - mean_rho) );
67  REQUIRE( rho(0, 0, 0) == Approx(-mean_rho) );
68 
69  // update background underdensity
70  sim.test_opt.rho_b = -mean_rho;
71 }
T pow2(T base)
Definition: precision.hpp:52
double R_sphere
Definition: params.hpp:148
int iz
Definition: mfunc_bm.py:17
void transform_Mesh_to_MultiGrid(const Mesh &mesh, MultiGrid< 3, T > &mltgrid)
Definition: chameleon.cpp:108
#define REQUIRE(...)
Definition: catch.hpp:13849
double rho_sphere
Definition: params.hpp:148
Test_Opt test_opt
Definition: params.hpp:211
size_t length
Definition: class_mesh.hpp:32
size_t N_grid
Definition: params.hpp:150
double rho_b
Definition: params.hpp:154
template<typename T >
T anonymous_namespace{test_chameleon.cpp}::mean ( const std::vector< T > &  data)

Definition at line 8 of file test_chameleon.cpp.

References growth_allz::T.

9 {
10  T tmp(0);
11 
12  #pragma omp parallel for reduction(+:tmp)
13  for (auto it = data.begin(); it < data.end(); ++it) tmp += *it;
14 
15  return tmp / data.size();
16 }
double anonymous_namespace{test_chameleon.cpp}::mean ( const Mesh data)

Definition at line 18 of file test_chameleon.cpp.

References Mesh_base< T >::data.

Referenced by init_overdensity().

18 { return mean(data.data); }
std::vector< T > data
Definition: class_mesh.hpp:33
void anonymous_namespace{test_chameleon.cpp}::print_mesh ( const std::string &  file_name,
const Mesh pot,
const double  mod = -1 - CHI_MIN 
)

Definition at line 87 of file test_chameleon.cpp.

References Mesh::N, pow2(), and sqrt().

Referenced by TEST_CASE().

88 {
89  Ofstream File(file_name);
90  size_t N = pot.N;
91  int ix0 = N/2, iy0 = N/2, iz0 = N/2;
92 
93  auto print_r_chi = [&File, ix0, iy0, iz0,&pot, mod]
94  (int i, int j, int k)
95  {
96  Vec_3D<size_t> pos(i, j, k); //< to call periodic position on Mesh
97  FTYPE_t r = sqrt(pow2(i - ix0) + pow2(j - iy0) + pow2(k - iz0));
98  File << r << "\t" << pot(pos) + mod << "\n";
99  };
100 
101  for (size_t i = 0; i < N; ++i)
102  {
103  print_r_chi(i, i, i);
104  print_r_chi(i, i, i + 1);
105  print_r_chi(i, i + 1, i + 1);
106  }
107 }
T pow2(T base)
Definition: precision.hpp:52
Grid< NDIM, T > sqrt(Grid< NDIM, T > lhs)
Definition: grid.h:231
size_t N
Definition: class_mesh.hpp:102
template<typename T >
static int anonymous_namespace{test_chameleon.cpp}::sgn ( val)
static

Definition at line 82 of file test_chameleon.cpp.

References growth_allz::T.

83 {
84  return (T(0) < val) - (val < T(0));
85 }