7 #include <gsl/gsl_rng.h>
43 gsl_rng * rng = gsl_rng_alloc(gsl_rng_ranlxd1);
45 MPI_Comm_rank(MPI_COMM_WORLD, &
ThisTask);
52 for(i = 0; i < idgen->
NumPart; i ++) {
57 for(k = 0; k < 3; k++) {
58 double rand = idgen->
BoxSize / idgen->
Ngrid * 3 * (gsl_rng_uniform(rng) - 0.5);
59 ICP[i].
Pos[k] += shift + rand;
94 for(step = 0; step < nsteps; step++) {
97 double hdt = 0.5 * dt;
107 for(i = 0; i < NumPart; i ++) {
108 for(d = 0; d < 3; d ++) {
110 ICP[i].
Vel[d] += (ICP[i].
Disp[d] - ICP[i].
Vel[d]) * hdt;
116 for(i = 0; i < NumPart; i ++) {
117 for(d = 0; d < 3; d ++) {
118 ICP[i].
Pos[d] += ICP[i].
Vel[d] * dt;
127 for(i = 0; i < NumPart; i ++) {
128 for(d = 0; d < 3; d ++) {
130 ICP[i].
Vel[d] += (ICP[i].
Disp[d] - ICP[i].
Vel[d]) * hdt;
135 message(0,
"Generating glass, step = %d, t_f= %g, t_v = %g, t_x = %g\n", step, t_f / (2 * M_PI), t_v / (2 *M_PI), t_x / (2 * M_PI));
153 for(i = 0; i < NumPart; i++)
156 for(k = 0; k < 3; k++)
158 double dis = ICP[i].
Disp[k];
159 double vel = ICP[i].
Vel[k];
164 MPI_Allreduce(MPI_IN_PLACE, &disp2, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
165 MPI_Allreduce(MPI_IN_PLACE, &vel2, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
166 MPI_Allreduce(MPI_IN_PLACE, &n, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
168 message(0,
"Force std = %g, vel std = %g\n", sqrt(disp2 / n), sqrt(vel2 / n));
186 (
char*) &ICP[0].
Pos[0] - (
char*) ICP,
187 (
char*) &ICP[0].
Mass - (
char*) ICP,
195 #pragma omp parallel for
196 for(i = 0; i < NumPart; i++)
237 double max[3] = {0, 0, 0.};
240 for(i = 0; i < NumPart; i ++) {
241 for(k = 0; k < 3; k ++) {
242 if(min[k] > ICP[i].
Pos[k])
243 min[k] = ICP[i].
Pos[k];
244 if(max[k] < ICP[i].
Pos[k])
245 max[k] = ICP[i].
Pos[k];
248 totmass += ICP[i].
Mass;
251 MPI_Allreduce(MPI_IN_PLACE, &totmass, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
256 for(k = 0; k < 3; k ++) {
285 const double smth = 1.0 / k2;
323 return 1 / 6.0 * (8 * sin (w) - sin (2 * w));
335 tmp0 = - value[0][1] * fac;
336 tmp1 = value[0][0] * fac;
void message(int where, const char *fmt,...)
int setup_glass(IDGenerator *idgen, PetaPM *pm, double shift, int seed, double mass, struct ic_part_data *ICP, const double UnitLength_in_cm, const char *OutputDir)
static double diff_kernel(double w)
static void glass_stats(struct ic_part_data *ICP, int NumPart)
static void force_x_transfer(PetaPM *pm, int64_t k2, int kpos[3], pfft_complex *value)
void glass_evolve(PetaPM *pm, int nsteps, const char *pkoutname, struct ic_part_data *ICP, const int NumPart, const double UnitLength_in_cm, const char *OutputDir)
static void readout_force_z(PetaPM *pm, int i, double *mesh, double weight)
static void readout_force_x(PetaPM *pm, int i, double *mesh, double weight)
static void force_z_transfer(PetaPM *pm, int64_t k2, int kpos[3], pfft_complex *value)
static void force_y_transfer(PetaPM *pm, int64_t k2, int kpos[3], pfft_complex *value)
static void readout_force_y(PetaPM *pm, int i, double *mesh, double weight)
static PetaPMRegion * _prepare(PetaPM *pm, PetaPMParticleStruct *pstruct, void *userdata, int *Nregions)
static void potential_transfer(PetaPM *pm, int64_t k2, int kpos[3], pfft_complex *value)
static struct ic_part_data * curICP
static PetaPMGlobalFunctions global_functions
static PetaPMFunctions functions[]
static void force_transfer(PetaPM *pm, int k, pfft_complex *value)
static void glass_force(PetaPM *pm, double t_f, struct ic_part_data *ICP, const int NumPart)
void powerspectrum_add_mode(Power *PowerSpectrum, const int64_t k2, const int kpos[3], pfft_complex *const value, const double invwindow, double Nmesh)
void measure_power_spectrum(PetaPM *pm, int64_t k2, int kpos[3], pfft_complex *value)
#define mymalloc2(name, size)
void petapm_region_init_strides(PetaPMRegion *region)
void petapm_force(PetaPM *pm, petapm_prepare_func prepare, PetaPMGlobalFunctions *global_functions, PetaPMFunctions *functions, PetaPMParticleStruct *pstruct, void *userdata)
static double UnitLength_in_cm
void powerspectrum_save(Power *ps, const char *OutputDir, const char *filename, const double Time, const double D1)
void powerspectrum_free(Power *ps)
void powerspectrum_sum(Power *ps)
void powerspectrum_zero(Power *ps)
void powerspectrum_alloc(Power *ps, const int nbins, const int nthreads, const int MassiveNuLinResp, const double BoxSize_in_cm)
void idgen_create_pos_from_index(IDGenerator *idgen, int index, double pos[3])
char * fastpm_strdup_printf(const char *fmt,...)
struct ic_part_data * curICP
#define walltime_measure(name)