GADGET-4
ngenic.h
Go to the documentation of this file.
1/*******************************************************************************
2 * \copyright This file is part of the GADGET4 N-body/SPH code developed
3 * \copyright by Volker Springel. Copyright (C) 2014-2020 by Volker Springel
4 * \copyright (vspringel@mpa-garching.mpg.de) and all contributing authors.
5 *******************************************************************************/
6
12#ifndef NGENIC_H
13#define NGENIC_H
14
15#ifdef NGENIC
16
17#ifndef PERIODIC
18#error NGENIC requires PERIODIC
19#endif
20
21#include <fftw3.h>
22
23#ifdef DOUBLEPRECISION_FFTW
24typedef double fft_real;
25typedef fftw_complex fft_complex;
26#else
27typedef float fft_real;
28typedef fftwf_complex fft_complex;
29#endif
30
31#include "../data/simparticles.h"
32#include "../pm/pm_mpi_fft.h"
33
34class ngenic : public pm_mpi_fft
35{
36 private:
37 simparticles *Sp;
38
39 public:
40 ngenic(MPI_Comm comm, simparticles *Sp_ptr) : setcomm(comm), pm_mpi_fft(comm) /* constructor */ { Sp = Sp_ptr; }
41
42 public:
43 void ngenic_displace_particles(void);
44
45 void create_grid(void);
46
47 private:
48 double ngenic_power_spec(double k);
49 double ngenic_f1_omega(double a);
50 double ngenic_f2_omega(double a);
51 double ngenic_growth_factor(double astart, double aend);
52 void ngenic_initialize_powerspectrum(void);
53 void free_power_table(void);
54
55 double Dplus;
56
57 unsigned int *seedtable;
58
59 fft_plan myplan;
60 size_t maxfftsize;
61
62 struct partbuf
63 {
64 MyIntPosType IntPos[3];
65 };
66 partbuf *partin, *partout;
67
68 size_t nimport, nexport;
69
70 size_t *Sndpm_count, *Sndpm_offset;
71 size_t *Rcvpm_count, *Rcvpm_offset;
72
73 gsl_rng *rnd_generator;
74 gsl_rng *rnd_generator_conjugate;
75
76 struct disp_data
77 {
78 fft_real deltapos[3];
79 };
80
81 disp_data *Pdisp;
82
83 void ngenic_distribute_particles();
84 void ngenic_setup_modes_in_kspace(fft_complex *fft_of_grid);
85 void ngenic_readout_disp(fft_real *grid, int axis, double pfac, double vfac);
86 void ngenic_initialize_ffts(void);
87 void ngenic_get_derivate_from_fourier_field(int axes1, int axes2, fft_complex *fft_of_grid);
88 void ngenic_compute_transform_of_source_potential(fft_real *pot);
89 void print_spec(void);
90
91 double R8;
92
93 double AA, BB, CC;
94 double nu;
95 double Norm;
96
97 int NPowerTable;
98
99 struct pow_table
100 {
101 double logk, logD;
102 bool operator<(const pow_table &other) const { return logk < other.logk; }
103 };
104 pow_table *PowerTable;
105
106 double ngenic_powerspec_tabulated(double k);
107 double ngenic_powerspec_efstathiou(double k);
108 double ngenic_powerspec_eh(double k);
109 double ngenic_tophat_sigma2(double R);
110 double ngenic_tk_eh(double k);
111 double ngenic_growth(double a);
112 void read_power_table(void);
113
114 static double ngenic_growth_int(double a, void *param)
115 {
116 return pow(a / (All.Omega0 + (1 - All.Omega0 - All.OmegaLambda) * a + All.OmegaLambda * a * a * a), 1.5);
117 }
118
119 double fnl(double x, double A, double B, double alpha, double beta, double V, double gf) /* Peacock & Dodds formula */
120 {
121 return x * pow((1 + B * beta * x + pow(A * x, alpha * beta)) / (1 + pow(pow(A * x, alpha) * gf * gf * gf / (V * sqrt(x)), beta)),
122 1 / beta);
123 }
124
125 struct myparams
126 {
127 double R;
128 ngenic *obj;
129 };
130
131 static double sigma2_int(double lnk, void *param)
132 {
133 myparams *par = (myparams *)param;
134 double r_tophat = par->R;
135
136 double k = exp(lnk);
137 double kr = r_tophat * k;
138 double kr2 = kr * kr;
139 double kr3 = kr2 * kr;
140
141 if(kr < 1e-8)
142 return 0;
143
144 double w = 3 * (sin(kr) / kr3 - cos(kr) / kr2);
145 double x = 4 * M_PI * k * k * w * w * par->obj->ngenic_power_spec(k);
146
147 return k * x;
148 }
149};
150
151#endif
152#endif
global_data_all_processes All
Definition: main.cc:40
#define M_PI
Definition: constants.h:56
bool operator<(const location &left, const location &right)
Definition: dtypes.h:172
uint32_t MyIntPosType
Definition: dtypes.h:35
expr exp(half arg)
Definition: half.hpp:2724
expr cos(half arg)
Definition: half.hpp:2823
expr sin(half arg)
Definition: half.hpp:2816
expr pow(half base, half exp)
Definition: half.hpp:2803
expr sqrt(half arg)
Definition: half.hpp:2777