MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Classes | Typedefs | Functions
proto.h File Reference
#include <bigfile.h>
#include <stdint.h>
#include "power.h"
#include "allvars.h"
#include "libgadget/petapm.h"
Include dependency graph for proto.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  IDGenerator
 

Typedefs

typedef struct IDGenerator IDGenerator
 

Functions

void idgen_init (IDGenerator *idgen, PetaPM *pm, int Ngrid, double BoxSize)
 
uint64_t idgen_create_id_from_index (IDGenerator *idgen, int index)
 
void idgen_create_pos_from_index (IDGenerator *idgen, int index, double pos[3])
 
void displacement_fields (PetaPM *pm, enum TransferType Type, struct ic_part_data *dispICP, const int NumPart, Cosmology *CP, const struct genic_config GenicConfig)
 
int setup_grid (IDGenerator *idgen, double shift, double mass, struct ic_part_data *ICP)
 
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)
 
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)
 
void saveheader (BigFile *bf, int64_t TotNumPartCDM, int64_t TotNumPartGas, int64_t TotNuPart, double nufrac, const double BoxSize, Cosmology *CP, const struct genic_config GenicConfig)
 
void compute_mass (double *mass, int64_t TotNumPartCDM, int64_t TotNumPartGas, int64_t TotNuPart, double nufrac, const double BoxSize, Cosmology *CP, const struct genic_config GenicConfig)
 
void write_particle_data (IDGenerator *idgen, const int Type, BigFile *bf, const uint64_t FirstID, const int SavePrePos, int NumFiles, int NumWriters, struct ic_part_data *curICP)
 
void read_parameterfile (char *fname, struct genic_config *GenicConfig, int *ShowBacktrace, double *MaxMemSizePerNode, Cosmology *CP)
 
void _bigfile_utils_create_block_from_c_array (BigFile *bf, void *baseptr, const char *name, const char *dtype, size_t dims[], ptrdiff_t elsize, int NumFiles, int NumWriters, MPI_Comm comm)
 

Typedef Documentation

◆ IDGenerator

typedef struct IDGenerator IDGenerator

Function Documentation

◆ _bigfile_utils_create_block_from_c_array()

void _bigfile_utils_create_block_from_c_array ( BigFile *  bf,
void *  baseptr,
const char *  name,
const char *  dtype,
size_t  dims[],
ptrdiff_t  elsize,
int  NumFiles,
int  NumWriters,
MPI_Comm  comm 
)

Definition at line 18 of file save.c.

19 {
20  BigBlock block;
21  BigArray array;
22  BigBlockPtr ptr;
23  ptrdiff_t strides[2];
24  int64_t TotNumPart;
25  MPI_Allreduce(&dims[0], &TotNumPart, 1, MPI_INT64, MPI_SUM, comm);
26 
27  strides[1] = dtype_itemsize(dtype);
28  strides[0] = elsize;
29 
30  big_array_init(&array, baseptr, dtype, 2, dims, strides);
31 
32  if(0 != big_file_mpi_create_block(bf, &block, name, dtype, dims[1], NumFiles, TotNumPart, comm)) {
33  endrun(0, "%s:%s\n", big_file_get_error_message(), name);
34  }
35 
36  if(0 != big_block_seek(&block, &ptr, 0)) {
37  endrun(0, "Failed to seek:%s\n", big_file_get_error_message());
38  }
39 
40  if(0 != big_block_mpi_write(&block, &ptr, &array, NumWriters, comm)) {
41  endrun(0, "Failed to write :%s\n", big_file_get_error_message());
42  }
43 
44  if(0 != big_block_mpi_close(&block, comm)) {
45  endrun(0, "%s:%s\n", big_file_get_error_message(), name);
46  }
47 }
const char * name
Definition: densitykernel.c:93
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147
#define MPI_INT64
Definition: system.h:12
int TotNumPart
Definition: test_exchange.c:24

References endrun(), MPI_INT64, name, and TotNumPart.

Referenced by save_transfer(), and saveblock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compute_mass()

void compute_mass ( double *  mass,
int64_t  TotNumPartCDM,
int64_t  TotNumPartGas,
int64_t  TotNuPart,
double  nufrac,
const double  BoxSize,
Cosmology CP,
const struct genic_config  GenicConfig 
)

Definition at line 90 of file save.c.

91 {
92  double UnitTime_in_s = GenicConfig.units.UnitLength_in_cm / GenicConfig.units.UnitVelocity_in_cm_per_s;
93  double Grav = GRAVITY / pow(GenicConfig.units.UnitLength_in_cm, 3) * GenicConfig.units.UnitMass_in_g * pow(UnitTime_in_s, 2);
94  const double OmegatoMass = 3 * CP->Hubble * CP->Hubble / (8 * M_PI * Grav) * pow(BoxSize, 3);
95  double OmegaCDM = CP->Omega0;
96  mass[0] = mass[2] = mass[3] = mass[4] = mass[5] = 0;
97  if (TotNumPartGas > 0) {
98  mass[0] = (CP->OmegaBaryon) * 3 * CP->Hubble * CP->Hubble / (8 * M_PI * Grav) * pow(BoxSize, 3) / TotNumPartGas;
99  OmegaCDM -= CP->OmegaBaryon;
100  }
101  if(CP->MNu[0] + CP->MNu[1] + CP->MNu[2] > 0) {
102  double OmegaNu = get_omega_nu(&CP->ONu, 1);
103  OmegaCDM -= OmegaNu;
104  if(TotNuPart > 0) {
105  mass[2] = nufrac * OmegaNu * OmegatoMass / TotNuPart;
106  }
107  }
108  mass[1] = OmegaCDM * OmegatoMass / TotNumPartCDM;
109 }
double get_omega_nu(const _omega_nu *const omnu, const double a)
#define GRAVITY
Definition: physconst.h:5
static Cosmology * CP
Definition: power.c:27
double Omega0
Definition: cosmology.h:10
double OmegaBaryon
Definition: cosmology.h:19
double MNu[3]
Definition: cosmology.h:25
_omega_nu ONu
Definition: cosmology.h:24
double Hubble
Definition: cosmology.h:21
double UnitMass_in_g
Definition: unitsystem.h:8
double UnitLength_in_cm
Definition: unitsystem.h:10
double UnitVelocity_in_cm_per_s
Definition: unitsystem.h:9
struct UnitSystem units
Definition: allvars.h:35

References CP, get_omega_nu(), GRAVITY, Cosmology::Hubble, Cosmology::MNu, Cosmology::Omega0, Cosmology::OmegaBaryon, Cosmology::ONu, UnitSystem::UnitLength_in_cm, UnitSystem::UnitMass_in_g, genic_config::units, and UnitSystem::UnitVelocity_in_cm_per_s.

Referenced by main(), and saveheader().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ displacement_fields()

void displacement_fields ( PetaPM pm,
enum TransferType  Type,
struct ic_part_data dispICP,
const int  NumPart,
Cosmology CP,
const struct genic_config  GenicConfig 
)

Definition at line 150 of file zeldovich.c.

150  {
151 
152  /*MUST set this before doing force.*/
153  ptype = Type;
154  curICP = dispICP;
155  PetaPMParticleStruct pstruct = {
156  curICP,
157  sizeof(curICP[0]),
158  ((char*) &curICP[0].Pos[0]) - (char*) curICP,
159  ((char*) &curICP[0].Mass) - (char*) curICP,
160  NULL,
161  NULL,
162  NumPart,
163  };
164 
165  int i;
166  #pragma omp parallel for
167  for(i = 0; i < NumPart; i++)
168  {
169  memset(&curICP[i].Disp[0], 0, sizeof(curICP[i].Disp));
170  memset(&curICP[i].Vel[0], 0, sizeof(curICP[i].Vel));
171  curICP[i].Density = 0;
172  }
173 
174 
175  /* This reads out the displacements into P.Disp and the velocities into P.Vel.
176  * Disp is used to avoid changing the particle positions mid-way through.
177  * Note that for the velocities we do NOT just use the velocity transfer functions.
178  * The reason is because of the gauge: velocity transfer is in synchronous gauge for CLASS,
179  * newtonian gauge for CAMB. But we want N-body gauge, which we get by taking the time derivative
180  * of the synchronous gauge density perturbations. See arxiv:1505.04756*/
182  {"Density", density_transfer, readout_density},
183  {"DispX", disp_x_transfer, readout_disp_x},
184  {"DispY", disp_y_transfer, readout_disp_y},
185  {"DispZ", disp_z_transfer, readout_disp_z},
186  {"VelX", vel_x_transfer, readout_vel_x},
187  {"VelY", vel_y_transfer, readout_vel_y},
188  {"VelZ", vel_z_transfer, readout_vel_z},
189  {NULL, NULL, NULL },
190  };
191 
192  /*Set up the velocity pre-factors*/
193  const double hubble_a = hubble_function(CP, GenicConfig.TimeIC);
194 
195  double vel_prefac = GenicConfig.TimeIC * hubble_a;
196 
197  if(GenicConfig.UsePeculiarVelocity) {
198  /* already for peculiar velocity */
199  message(0, "Producing Peculiar Velocity in the output.\n");
200  } else {
201  vel_prefac /= sqrt(GenicConfig.TimeIC); /* converts to Gadget velocity */
202  }
203 
204  if(!GenicConfig.PowerP.ScaleDepVelocity) {
205  vel_prefac *= F_Omega(CP, GenicConfig.TimeIC);
206  /* If different transfer functions are disabled, we can copy displacements to velocities
207  * and we don't need the extra transfers.*/
208  functions[4].name = NULL;
209  }
210 
211  int Nregions;
212  struct ic_prep_data icprep = {dispICP, NumPart};
213  PetaPMRegion * regions = petapm_force_init(pm,
214  makeregion,
215  &pstruct,
216  &Nregions,
217  &icprep);
218 
219  /*This allocates the memory*/
220  pfft_complex * rho_k = petapm_alloc_rhok(pm);
221 
223  rho_k, GenicConfig.UnitaryAmplitude, GenicConfig.InvertPhase, GenicConfig.Seed);
224 
225  petapm_force_c2r(pm, rho_k, regions, Nregions, functions);
226 
227  myfree(rho_k);
228  myfree(regions);
230 
231  double maxdisp = 0, maxvel = 0;
232 
233  #pragma omp parallel for reduction(max:maxdisp, maxvel)
234  for(i = 0; i < NumPart; i++)
235  {
236  int k;
237  double absv = 0;
238  for(k = 0; k < 3; k++)
239  {
240  double dis = curICP[i].Disp[k];
241  if(dis > maxdisp)
242  maxdisp = dis;
243  /*Copy displacements to positions.*/
244  curICP[i].Pos[k] += curICP[i].Disp[k];
245  /*Copy displacements to velocities if not done already*/
246  if(!GenicConfig.PowerP.ScaleDepVelocity)
247  curICP[i].Vel[k] = curICP[i].Disp[k];
248  curICP[i].Vel[k] *= vel_prefac;
249  absv += curICP[i].Vel[k] * curICP[i].Vel[k];
250  curICP[i].Pos[k] = periodic_wrap(curICP[i].Pos[k], pm->BoxSize);
251  }
252  if(absv > maxvel)
253  maxvel = absv;
254  }
255  MPI_Allreduce(MPI_IN_PLACE, &maxdisp, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
256  message(0, "Type = %d max disp = %g in units of cell sep %g \n", ptype, maxdisp, maxdisp / (pm->BoxSize / pm->Nmesh) );
257 
258  MPI_Allreduce(MPI_IN_PLACE, &maxvel, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
259  message(0, "Max vel=%g km/s, vel_prefac= %g hubble_a=%g fom=%g \n", sqrt(maxvel), vel_prefac, hubble_a, F_Omega(CP, GenicConfig.TimeIC));
260 
261  walltime_measure("/Disp/Finalize");
262  MPIU_Barrier(MPI_COMM_WORLD);
263 }
double hubble_function(const Cosmology *CP, double a)
Definition: cosmology.c:58
double F_Omega(Cosmology *CP, double a)
Definition: cosmology.c:148
void message(int where, const char *fmt,...)
Definition: endrun.c:175
static PetaPMFunctions functions[]
Definition: gravpm.c:32
#define myfree(x)
Definition: mymalloc.h:19
void petapm_force_finish(PetaPM *pm)
Definition: petapm.c:348
void petapm_force_c2r(PetaPM *pm, pfft_complex *rho_k, PetaPMRegion *regions, const int Nregions, PetaPMFunctions *functions)
Definition: petapm.c:317
pfft_complex * petapm_alloc_rhok(PetaPM *pm)
Definition: petapm.c:50
PetaPMRegion * petapm_get_fourier_region(PetaPM *pm)
Definition: petapm.c:64
PetaPMRegion * petapm_force_init(PetaPM *pm, petapm_prepare_func prepare, PetaPMParticleStruct *pstruct, int *Nregions, void *userdata)
Definition: petapm.c:251
const char * name
Definition: petapm.h:94
int Nmesh
Definition: petapm.h:68
double BoxSize
Definition: petapm.h:70
Definition: petapm.h:7
int UnitaryAmplitude
Definition: allvars.h:23
struct power_params PowerP
Definition: allvars.h:34
int Seed
Definition: allvars.h:22
int InvertPhase
Definition: allvars.h:24
int UsePeculiarVelocity
Definition: allvars.h:39
double TimeIC
Definition: allvars.h:38
float Vel[3]
Definition: allvars.h:11
double Pos[3]
Definition: allvars.h:10
float Density
Definition: allvars.h:13
float Disp[3]
Definition: allvars.h:12
int NumPart
Definition: glass.c:174
int ScaleDepVelocity
Definition: power.h:11
#define MPIU_Barrier(comm)
Definition: system.h:103
#define walltime_measure(name)
Definition: walltime.h:8
static double periodic_wrap(double x, const double BoxSize)
Definition: zeldovich.c:35
static PetaPMRegion * makeregion(PetaPM *pm, PetaPMParticleStruct *pstruct, void *userdata, int *Nregions)
Definition: zeldovich.c:113
static void readout_density(PetaPM *pm, int i, double *mesh, double weight)
Definition: zeldovich.c:338
static void readout_vel_z(PetaPM *pm, int i, double *mesh, double weight)
Definition: zeldovich.c:347
static void readout_disp_y(PetaPM *pm, int i, double *mesh, double weight)
Definition: zeldovich.c:354
static void gaussian_fill(int Nmesh, PetaPMRegion *region, pfft_complex *rho_k, int UnitaryAmplitude, int InvertPhase, const int Seed)
Definition: zeldovich.c:362
static void vel_y_transfer(PetaPM *pm, int64_t k2, int kpos[3], pfft_complex *value)
Definition: zeldovich.c:318
static void readout_vel_y(PetaPM *pm, int i, double *mesh, double weight)
Definition: zeldovich.c:344
static enum TransferType ptype
Definition: zeldovich.c:146
static void readout_vel_x(PetaPM *pm, int i, double *mesh, double weight)
Definition: zeldovich.c:341
static void disp_x_transfer(PetaPM *pm, int64_t k2, int kpos[3], pfft_complex *value)
Definition: zeldovich.c:325
static void vel_x_transfer(PetaPM *pm, int64_t k2, int kpos[3], pfft_complex *value)
Definition: zeldovich.c:315
static void readout_disp_z(PetaPM *pm, int i, double *mesh, double weight)
Definition: zeldovich.c:357
static void density_transfer(PetaPM *pm, int64_t k2, int kpos[3], pfft_complex *value)
Definition: zeldovich.c:276
static void disp_y_transfer(PetaPM *pm, int64_t k2, int kpos[3], pfft_complex *value)
Definition: zeldovich.c:328
static void vel_z_transfer(PetaPM *pm, int64_t k2, int kpos[3], pfft_complex *value)
Definition: zeldovich.c:321
static void readout_disp_x(PetaPM *pm, int i, double *mesh, double weight)
Definition: zeldovich.c:351
static struct ic_part_data * curICP
Definition: zeldovich.c:148
static void disp_z_transfer(PetaPM *pm, int64_t k2, int kpos[3], pfft_complex *value)
Definition: zeldovich.c:331

References PetaPM::BoxSize, CP, curICP, ic_part_data::Density, density_transfer(), ic_part_data::Disp, disp_x_transfer(), disp_y_transfer(), disp_z_transfer(), F_Omega(), functions, gaussian_fill(), hubble_function(), genic_config::InvertPhase, makeregion(), ic_part_data::Mass, message(), MPIU_Barrier, myfree, PetaPMFunctions::name, PetaPM::Nmesh, ic_prep_data::NumPart, periodic_wrap(), petapm_alloc_rhok(), petapm_force_c2r(), petapm_force_finish(), petapm_force_init(), petapm_get_fourier_region(), ic_part_data::Pos, genic_config::PowerP, ptype, readout_density(), readout_disp_x(), readout_disp_y(), readout_disp_z(), readout_vel_x(), readout_vel_y(), readout_vel_z(), power_params::ScaleDepVelocity, genic_config::Seed, genic_config::TimeIC, genic_config::UnitaryAmplitude, genic_config::UsePeculiarVelocity, ic_part_data::Vel, vel_x_transfer(), vel_y_transfer(), vel_z_transfer(), and walltime_measure.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ glass_evolve()

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 
)

Definition at line 73 of file glass.c.

74 {
75  int i;
76  int step = 0;
77  double t_x = 0;
78  double t_v = 0;
79  double t_f = 0;
80 
81  /*Allocate memory for a power spectrum*/
82  powerspectrum_alloc(pm->ps, pm->Nmesh, omp_get_max_threads(), 0, pm->BoxSize*UnitLength_in_cm);
83 
84  glass_force(pm, t_x, ICP, NumPart);
85 
86  /* Our pick of the units ensures there is an oscillation period of 2 * M_PI.
87  *
88  * (don't ask me how this worked -- I think I failed this problem in physics undergrad. )
89  * We use 4 steps per oscillation, and end at
90  *
91  * 12 + 1 = 13, the first time phase is M_PI / 2, a close encounter to the minimum.
92  *
93  * */
94  for(step = 0; step < nsteps; step++) {
95  /* leap-frog, K D D F K */
96  double dt = M_PI / 2; /* step size */
97  double hdt = 0.5 * dt; /* half a step */
98  int d;
99  /*
100  * Use inverted gravity with a damping term proportional to the velocity.
101  *
102  * The magic setup was studied in
103  * https://github.com/rainwoodman/fastpm-python/blob/1be020b/Example/Glass.ipynb
104  * */
105 
106  /* Kick */
107  for(i = 0; i < NumPart; i ++) {
108  for(d = 0; d < 3; d ++) {
109  /* mind the damping term */
110  ICP[i].Vel[d] += (ICP[i].Disp[d] - ICP[i].Vel[d]) * hdt;
111  }
112  }
113  t_x += hdt;
114 
115  /* Drift */
116  for(i = 0; i < NumPart; i ++) {
117  for(d = 0; d < 3; d ++) {
118  ICP[i].Pos[d] += ICP[i].Vel[d] * dt;
119  }
120  }
121  t_v += dt;
122 
123  glass_force(pm, t_x, ICP, NumPart);
124  t_f = t_x;
125 
126  /* Kick */
127  for(i = 0; i < NumPart; i ++) {
128  for(d = 0; d < 3; d ++) {
129  /* mind the damping term */
130  ICP[i].Vel[d] += (ICP[i].Disp[d] - ICP[i].Vel[d]) * hdt;
131  }
132  }
133 
134  t_x += 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));
136  glass_stats(ICP, NumPart);
137 
138  /*Now save the power spectrum*/
139  powerspectrum_save(pm->ps, OutputDir, pkoutname, t_f, 1.0);
140  }
141 
142  /*We are done with the power spectrum, free it*/
143  powerspectrum_free(pm->ps);
144 }
static void glass_stats(struct ic_part_data *ICP, int NumPart)
Definition: glass.c:148
static void glass_force(PetaPM *pm, double t_f, struct ic_part_data *ICP, const int NumPart)
Definition: glass.c:181
static double UnitLength_in_cm
Definition: power.c:26
void powerspectrum_save(Power *ps, const char *OutputDir, const char *filename, const double Time, const double D1)
Definition: powerspectrum.c:92
void powerspectrum_free(Power *ps)
Definition: powerspectrum.c:44
void powerspectrum_alloc(Power *ps, const int nbins, const int nthreads, const int MassiveNuLinResp, const double BoxSize_in_cm)
Definition: powerspectrum.c:16
Power ps[1]
Definition: petapm.h:76

References PetaPM::BoxSize, ic_part_data::Disp, glass_force(), glass_stats(), message(), PetaPM::Nmesh, ic_part_data::Pos, powerspectrum_alloc(), powerspectrum_free(), powerspectrum_save(), PetaPM::ps, UnitLength_in_cm, and ic_part_data::Vel.

Referenced by main(), and setup_glass().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idgen_create_id_from_index()

uint64_t idgen_create_id_from_index ( IDGenerator idgen,
int  index 
)

Definition at line 69 of file zeldovich.c.

70 {
71  int i = index / (idgen->size[2] * idgen->size[1]) + idgen->offset[0];
72  int j = (index % (idgen->size[1] * idgen->size[2])) / idgen->size[2] + idgen->offset[1];
73  int k = (index % idgen->size[2]) + idgen->offset[2];
74  uint64_t id = ((uint64_t) i) * idgen->Ngrid * idgen->Ngrid + ((uint64_t)j) * idgen->Ngrid + k + 1;
75  return id;
76 }
int Ngrid
Definition: proto.h:12
int size[3]
Definition: proto.h:10
int offset[3]
Definition: proto.h:11

References IDGenerator::Ngrid, IDGenerator::offset, and IDGenerator::size.

Referenced by main(), and write_particle_data().

Here is the caller graph for this function:

◆ idgen_create_pos_from_index()

void idgen_create_pos_from_index ( IDGenerator idgen,
int  index,
double  pos[3] 
)

Definition at line 79 of file zeldovich.c.

80 {
81  int x = index / (idgen->size[2] * idgen->size[1]) + idgen->offset[0];
82  int y = (index % (idgen->size[1] * idgen->size[2])) / idgen->size[2] + idgen->offset[1];
83  int z = (index % idgen->size[2]) + idgen->offset[2];
84 
85  pos[0] = x * idgen->BoxSize / idgen->Ngrid;
86  pos[1] = y * idgen->BoxSize / idgen->Ngrid;
87  pos[2] = z * idgen->BoxSize / idgen->Ngrid;
88 }
double BoxSize
Definition: proto.h:13

References IDGenerator::BoxSize, IDGenerator::Ngrid, IDGenerator::offset, and IDGenerator::size.

Referenced by setup_glass(), and setup_grid().

Here is the caller graph for this function:

◆ idgen_init()

void idgen_init ( IDGenerator idgen,
PetaPM pm,
int  Ngrid,
double  BoxSize 
)

Definition at line 48 of file zeldovich.c.

49 {
50 
51  int * ThisTask2d = petapm_get_thistask2d(pm);
52  int * NTask2d = petapm_get_ntask2d(pm);
53  idgen->NumPart = 1;
54  int k;
55  for(k = 0; k < 2; k ++) {
56  idgen->offset[k] = (ThisTask2d[k]) * Ngrid / NTask2d[k];
57  idgen->size[k] = (ThisTask2d[k] + 1) * Ngrid / NTask2d[k];
58  idgen->size[k] -= idgen->offset[k];
59  idgen->NumPart *= idgen->size[k];
60  }
61  idgen->offset[2] = 0;
62  idgen->size[2] = Ngrid;
63  idgen->NumPart *= idgen->size[2];
64  idgen->Ngrid = Ngrid;
65  idgen->BoxSize = BoxSize;
66 }
int * petapm_get_ntask2d(PetaPM *pm)
Definition: petapm.c:77
int * petapm_get_thistask2d(PetaPM *pm)
Definition: petapm.c:74
int NumPart
Definition: proto.h:14

References IDGenerator::BoxSize, IDGenerator::Ngrid, IDGenerator::NumPart, IDGenerator::offset, petapm_get_ntask2d(), petapm_get_thistask2d(), and IDGenerator::size.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_parameterfile()

void read_parameterfile ( char *  fname,
struct genic_config GenicConfig,
int *  ShowBacktrace,
double *  MaxMemSizePerNode,
Cosmology CP 
)

Definition at line 75 of file params.c.

76 {
77 
78  /* read parameter file on all processes for simplicty */
80  int ThisTask;
81 
82  if(0 != param_parse_file(ps, fname)) {
83  endrun(0, "Parsing %s failed. \n", fname);
84  }
85  if(0 != param_validate(ps)) {
86  endrun(0, "Validation of %s failed.\n", fname);
87  }
88 
89  message(0, "----------- Running with Parameters ----------\n");
90 
91  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
92  if(ThisTask == 0)
93  param_dump(ps, stdout);
94 
95  message(0, "----------------------------------------------\n");
96 
97  /*Cosmology*/
98  CP->Omega0 = param_get_double(ps, "Omega0");
99  CP->OmegaLambda = param_get_double(ps, "OmegaLambda");
100  CP->OmegaBaryon = param_get_double(ps, "OmegaBaryon");
101  CP->HubbleParam = param_get_double(ps, "HubbleParam");
102  CP->Omega_fld = param_get_double(ps, "Omega_fld");
103  CP->w0_fld = param_get_double(ps,"w0_fld");
104  CP->wa_fld = param_get_double(ps,"wa_fld");
105  CP->Omega_ur = param_get_double(ps, "Omega_ur");
106  if(CP->OmegaLambda > 0 && CP->Omega_fld > 0)
107  endrun(0, "Cannot have OmegaLambda and Omega_fld (evolving dark energy) at the same time!\n");
108  CP->CMBTemperature = param_get_double(ps, "CMBTemperature");
109  CP->RadiationOn = param_get_double(ps, "RadiationOn");
110  CP->MNu[0] = param_get_double(ps, "MNue");
111  CP->MNu[1] = param_get_double(ps, "MNum");
112  CP->MNu[2] = param_get_double(ps, "MNut");
113  GenicConfig->WDM_therm_mass = param_get_double(ps, "MWDM_therm");
114  *MaxMemSizePerNode = param_get_double(ps, "MaxMemSizePerNode");
115  if(*MaxMemSizePerNode <= 1) {
116  (*MaxMemSizePerNode) *= get_physmem_bytes() / (1024 * 1024);
117  }
118 
119  GenicConfig->ProduceGas = param_get_int(ps, "ProduceGas");
120  GenicConfig->InvertPhase = param_get_int(ps, "InvertPhase");
121  /*Unit system*/
122  GenicConfig->units.UnitVelocity_in_cm_per_s = param_get_double(ps, "UnitVelocity_in_cm_per_s");
123  GenicConfig->units.UnitLength_in_cm = param_get_double(ps, "UnitLength_in_cm");
124  GenicConfig->units.UnitMass_in_g = param_get_double(ps, "UnitMass_in_g");
125 
126 
127  *ShowBacktrace = param_get_int(ps, "ShowBacktrace");
128 
129  double Redshift = param_get_double(ps, "Redshift");
130 
131  /*Parameters of the power spectrum*/
132  GenicConfig->PowerP.InputPowerRedshift = param_get_double(ps, "InputPowerRedshift");
133  if(GenicConfig->PowerP.InputPowerRedshift < 0)
134  GenicConfig->PowerP.InputPowerRedshift = Redshift;
135  GenicConfig->PowerP.Sigma8 = param_get_double(ps, "Sigma8");
136  /*Always specify Sigm8 at z=0*/
137  if(GenicConfig->PowerP.Sigma8 > 0)
138  GenicConfig->PowerP.InputPowerRedshift = 0;
139  GenicConfig->PowerP.FileWithInputSpectrum = param_get_string(ps, "FileWithInputSpectrum");
140  GenicConfig->PowerP.FileWithTransferFunction = param_get_string(ps, "FileWithTransferFunction");
141  GenicConfig->PowerP.DifferentTransferFunctions = param_get_int(ps, "DifferentTransferFunctions");
142  GenicConfig->PowerP.ScaleDepVelocity = param_get_int(ps, "ScaleDepVelocity");
143  /* By default ScaleDepVelocity follows DifferentTransferFunctions.*/
144  if(GenicConfig->PowerP.ScaleDepVelocity < 0) {
145  GenicConfig->PowerP.ScaleDepVelocity = GenicConfig->PowerP.DifferentTransferFunctions;
146  }
147  GenicConfig->PowerP.WhichSpectrum = param_get_int(ps, "WhichSpectrum");
148  GenicConfig->PowerP.PrimordialIndex = param_get_double(ps, "PrimordialIndex");
149  GenicConfig->PowerP.PrimordialRunning = param_get_double(ps, "PrimordialRunning");
150 
151  /*Simulation parameters*/
152  GenicConfig->UsePeculiarVelocity = param_get_int(ps, "UsePeculiarVelocity");
153  GenicConfig->SavePrePos = param_get_int(ps, "SavePrePos");
154  GenicConfig->PrePosGridCenter = param_get_int(ps, "PrePosGridCenter");
155  GenicConfig->BoxSize = param_get_double(ps, "BoxSize");
156  GenicConfig->Nmesh = param_get_int(ps, "Nmesh");
157  GenicConfig->Ngrid = param_get_int(ps, "Ngrid");
158  GenicConfig->NgridGas = param_get_int(ps, "NgridGas");
159  if(GenicConfig->NgridGas < 0)
160  GenicConfig->NgridGas = GenicConfig->Ngrid;
161  if(!GenicConfig->ProduceGas)
162  GenicConfig->NgridGas = 0;
163  /*Enable 'hybrid' neutrinos*/
164  GenicConfig->NGridNu = param_get_int(ps, "NgridNu");
165  /* Convert physical km/s at z=0 in an unperturbed universe to
166  * internal gadget (comoving) velocity units at starting redshift.*/
167  GenicConfig->Max_nuvel = param_get_double(ps, "Max_nuvel") * pow(1+Redshift, 1.5) * (GenicConfig->units.UnitVelocity_in_cm_per_s/1e5);
168  GenicConfig->Seed = param_get_int(ps, "Seed");
169  GenicConfig->UnitaryAmplitude = param_get_int(ps, "UnitaryAmplitude");
170  param_get_string2(ps, "OutputDir", GenicConfig->OutputDir, sizeof(GenicConfig->OutputDir));
171  param_get_string2(ps, "FileBase", GenicConfig->InitCondFile, sizeof(GenicConfig->InitCondFile));
172  GenicConfig->MakeGlassGas = param_get_int(ps, "MakeGlassGas");
173  /* We want to use a baryon glass by default if we have different transfer functions,
174  * since that is the way we reproduce the linear growth. Otherwise use a grid by default.*/
175  if(GenicConfig->MakeGlassGas < 0) {
176  if(GenicConfig->PowerP.DifferentTransferFunctions)
177  GenicConfig->MakeGlassGas = 1;
178  else
179  GenicConfig->MakeGlassGas = 0;
180  }
181  GenicConfig->MakeGlassCDM = param_get_int(ps, "MakeGlassCDM");
182 
183  int64_t NumPartPerFile = param_get_int(ps, "NumPartPerFile");
184 
185  int64_t Ngrid = GenicConfig->Ngrid;
186  if(Ngrid < GenicConfig->NgridGas)
187  Ngrid = GenicConfig->NgridGas;
188  GenicConfig->NumFiles = ( Ngrid*Ngrid*Ngrid + NumPartPerFile - 1) / NumPartPerFile;
189  GenicConfig->NumWriters = param_get_int(ps, "NumWriters");
190  if(GenicConfig->PowerP.DifferentTransferFunctions && GenicConfig->PowerP.InputPowerRedshift != Redshift
191  && (GenicConfig->ProduceGas || CP->MNu[0] + CP->MNu[1] + CP->MNu[2]))
192  message(0, "WARNING: Using different transfer functions but also rescaling power to account for linear growth. NOT what you want!\n");
193  if((CP->MNu[0] + CP->MNu[1] + CP->MNu[2] > 0) || GenicConfig->PowerP.DifferentTransferFunctions || GenicConfig->PowerP.ScaleDepVelocity)
194  if(0 == strlen(GenicConfig->PowerP.FileWithTransferFunction))
195  endrun(0,"For massive neutrinos, different transfer functions, or scale dependent growth functions you must specify a transfer function file\n");
196  if(!CP->RadiationOn && (CP->MNu[0] + CP->MNu[1] + CP->MNu[2] > 0))
197  endrun(0,"You want massive neutrinos but no background radiation: this will give an inconsistent cosmology.\n");
198 
199  if(GenicConfig->Nmesh == 0) {
200  GenicConfig->Nmesh = 2*Ngrid;
201  }
202  /*Set some units*/
203  GenicConfig->TimeIC = 1 / (1 + Redshift);
204  double UnitTime_in_s = GenicConfig->units.UnitLength_in_cm / GenicConfig->units.UnitVelocity_in_cm_per_s;
205 
206  CP->Hubble = HUBBLE * UnitTime_in_s;
207 }
static int ShowBacktrace
Definition: endrun.c:100
static ParameterSet * create_parameters(void)
Definition: params.c:13
double param_get_double(ParameterSet *ps, const char *name)
Definition: paramset.c:336
void param_get_string2(ParameterSet *ps, const char *name, char *dst, size_t len)
Definition: paramset.c:355
int param_parse_file(ParameterSet *ps, const char *filename)
Definition: paramset.c:234
int param_get_int(ParameterSet *ps, const char *name)
Definition: paramset.c:368
void param_dump(ParameterSet *ps, FILE *stream)
Definition: paramset.c:192
char * param_get_string(ParameterSet *ps, const char *name)
Definition: paramset.c:346
int param_validate(ParameterSet *ps)
Definition: paramset.c:177
#define HUBBLE
Definition: physconst.h:25
double wa_fld
Definition: cosmology.h:17
double Omega_ur
Definition: cosmology.h:18
double Omega_fld
Definition: cosmology.h:15
int RadiationOn
Definition: cosmology.h:23
double HubbleParam
Definition: cosmology.h:20
double CMBTemperature
Definition: cosmology.h:9
double OmegaLambda
Definition: cosmology.h:14
double w0_fld
Definition: cosmology.h:16
int MakeGlassGas
Definition: allvars.h:28
double Max_nuvel
Definition: allvars.h:26
double BoxSize
Definition: allvars.h:20
int NGridNu
Definition: allvars.h:18
char OutputDir[100]
Definition: allvars.h:36
int Ngrid
Definition: allvars.h:18
int PrePosGridCenter
Definition: allvars.h:25
int ProduceGas
Definition: allvars.h:21
int MakeGlassCDM
Definition: allvars.h:29
int Nmesh
Definition: allvars.h:19
int SavePrePos
Definition: allvars.h:33
char InitCondFile[100]
Definition: allvars.h:37
int NgridGas
Definition: allvars.h:18
double WDM_therm_mass
Definition: allvars.h:27
int NumFiles
Definition: allvars.h:30
int NumWriters
Definition: allvars.h:31
char * FileWithTransferFunction
Definition: power.h:12
int DifferentTransferFunctions
Definition: power.h:10
double PrimordialIndex
Definition: power.h:16
int WhichSpectrum
Definition: power.h:9
double Sigma8
Definition: power.h:14
char * FileWithInputSpectrum
Definition: power.h:13
double InputPowerRedshift
Definition: power.h:15
double PrimordialRunning
Definition: power.h:17
double get_physmem_bytes(void)
Definition: system.c:467
int ThisTask
Definition: test_exchange.c:23

References genic_config::BoxSize, Cosmology::CMBTemperature, CP, create_parameters(), power_params::DifferentTransferFunctions, endrun(), power_params::FileWithInputSpectrum, power_params::FileWithTransferFunction, get_physmem_bytes(), Cosmology::Hubble, HUBBLE, Cosmology::HubbleParam, genic_config::InitCondFile, power_params::InputPowerRedshift, genic_config::InvertPhase, genic_config::MakeGlassCDM, genic_config::MakeGlassGas, genic_config::Max_nuvel, message(), Cosmology::MNu, genic_config::Ngrid, genic_config::NgridGas, genic_config::NGridNu, genic_config::Nmesh, genic_config::NumFiles, genic_config::NumWriters, Cosmology::Omega0, Cosmology::Omega_fld, Cosmology::Omega_ur, Cosmology::OmegaBaryon, Cosmology::OmegaLambda, genic_config::OutputDir, param_dump(), param_get_double(), param_get_int(), param_get_string(), param_get_string2(), param_parse_file(), param_validate(), genic_config::PowerP, genic_config::PrePosGridCenter, power_params::PrimordialIndex, power_params::PrimordialRunning, genic_config::ProduceGas, Cosmology::RadiationOn, genic_config::SavePrePos, power_params::ScaleDepVelocity, genic_config::Seed, ShowBacktrace, power_params::Sigma8, ThisTask, genic_config::TimeIC, genic_config::UnitaryAmplitude, UnitSystem::UnitLength_in_cm, UnitSystem::UnitMass_in_g, genic_config::units, UnitSystem::UnitVelocity_in_cm_per_s, genic_config::UsePeculiarVelocity, Cosmology::w0_fld, Cosmology::wa_fld, genic_config::WDM_therm_mass, and power_params::WhichSpectrum.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveheader()

void saveheader ( BigFile *  bf,
int64_t  TotNumPartCDM,
int64_t  TotNumPartGas,
int64_t  TotNuPart,
double  nufrac,
const double  BoxSize,
Cosmology CP,
const struct genic_config  GenicConfig 
)

Definition at line 112 of file save.c.

112  {
113  BigBlock bheader;
114  if(0 != big_file_mpi_create_block(bf, &bheader, "Header", NULL, 0, 0, 0, MPI_COMM_WORLD)) {
115  endrun(0, "failed to create block %s:%s\n", "Header",
116  big_file_get_error_message());
117  }
118 
119  int64_t totnumpart[6] = {TotNumPartGas, TotNumPartCDM, TotNuPart, 0, 0, 0};
120  double mass[6] = {0};
121  compute_mass(mass, TotNumPartCDM, TotNumPartGas, TotNuPart, nufrac, BoxSize, CP, GenicConfig);
122 
123  double redshift = 1.0 / GenicConfig.TimeIC - 1.;
124 
125  int rt =(0 != big_block_set_attr(&bheader, "TotNumPart", totnumpart, "i8", 6)) ||
126  (0 != big_block_set_attr(&bheader, "MassTable", mass, "f8", 6)) ||
127  (big_block_set_attr(&bheader, "Time", &GenicConfig.TimeIC, "f8", 1)) ||
128  (big_block_set_attr(&bheader, "Redshift", &redshift, "f8", 1)) ||
129  (big_block_set_attr(&bheader, "BoxSize", &BoxSize, "f8", 1)) ||
130  (big_block_set_attr(&bheader, "UsePeculiarVelocity", &GenicConfig.UsePeculiarVelocity, "i4", 1)) ||
131  (big_block_set_attr(&bheader, "Omega0", &CP->Omega0, "f8", 1)) ||
132  (big_block_set_attr(&bheader, "FractionNuInParticles", &nufrac, "f8", 1)) ||
133  (big_block_set_attr(&bheader, "OmegaBaryon", &CP->OmegaBaryon, "f8", 1)) ||
134  (big_block_set_attr(&bheader, "OmegaLambda", &CP->OmegaLambda, "f8", 1)) ||
135  (big_block_set_attr(&bheader, "UnitLength_in_cm", &GenicConfig.units.UnitLength_in_cm, "f8", 1)) ||
136  (big_block_set_attr(&bheader, "UnitMass_in_g", &GenicConfig.units.UnitMass_in_g, "f8", 1)) ||
137  (big_block_set_attr(&bheader, "UnitVelocity_in_cm_per_s", &GenicConfig.units.UnitVelocity_in_cm_per_s, "f8", 1)) ||
138  (big_block_set_attr(&bheader, "HubbleParam", &CP->HubbleParam, "f8", 1)) ||
139  (big_block_set_attr(&bheader, "InvertPhase", &GenicConfig.InvertPhase, "i4", 1)) ||
140  (big_block_set_attr(&bheader, "Seed", &GenicConfig.Seed, "i8", 1)) ||
141  (big_block_set_attr(&bheader, "UnitaryAmplitude", &GenicConfig.UnitaryAmplitude, "i4", 1));
142  if(rt) {
143  endrun(0, "failed to create attr %s",
144  big_file_get_error_message());
145  }
146 
147  if(0 != big_block_mpi_close(&bheader, MPI_COMM_WORLD)) {
148  endrun(0, "failed to close block %s:%s", "Header",
149  big_file_get_error_message());
150  }
151 }
void compute_mass(double *mass, int64_t TotNumPartCDM, int64_t TotNumPartGas, int64_t TotNuPart, double nufrac, const double BoxSize, Cosmology *CP, const struct genic_config GenicConfig)
Definition: save.c:90

References compute_mass(), CP, endrun(), Cosmology::HubbleParam, genic_config::InvertPhase, Cosmology::Omega0, Cosmology::OmegaBaryon, Cosmology::OmegaLambda, genic_config::Seed, genic_config::TimeIC, genic_config::UnitaryAmplitude, UnitSystem::UnitLength_in_cm, UnitSystem::UnitMass_in_g, genic_config::units, UnitSystem::UnitVelocity_in_cm_per_s, and genic_config::UsePeculiarVelocity.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_glass()

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 
)

Definition at line 41 of file glass.c.

42 {
43  gsl_rng * rng = gsl_rng_alloc(gsl_rng_ranlxd1);
44  int ThisTask;
45  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
46  gsl_rng_set(rng, seed + ThisTask);
47  memset(ICP, 0, idgen->NumPart*sizeof(struct ic_part_data));
48 
49  int i;
50  /* Note: this loop should nto be omp because
51  * of the call to gsl_rng_uniform*/
52  for(i = 0; i < idgen->NumPart; i ++) {
53  int k;
54  idgen_create_pos_from_index(idgen, i, &ICP[i].Pos[0]);
55  /* a spread of 3 will kill most of the grid anisotropy structure;
56  * and still being local */
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;
60  }
61  ICP[i].Mass = mass;
62  }
63 
64  gsl_rng_free(rng);
65 
66  char * fn = fastpm_strdup_printf("powerspectrum-glass-%08X", seed);
67  glass_evolve(pm, 14, fn, ICP, idgen->NumPart, UnitLength_in_cm, OutputDir);
68  myfree(fn);
69 
70  return idgen->NumPart;
71 }
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)
Definition: glass.c:73
void idgen_create_pos_from_index(IDGenerator *idgen, int index, double pos[3])
Definition: zeldovich.c:79
char * fastpm_strdup_printf(const char *fmt,...)
Definition: string.c:41
float Mass
Definition: allvars.h:14

References IDGenerator::BoxSize, fastpm_strdup_printf(), glass_evolve(), idgen_create_pos_from_index(), ic_part_data::Mass, myfree, IDGenerator::Ngrid, IDGenerator::NumPart, ic_part_data::Pos, ThisTask, and UnitLength_in_cm.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_grid()

int setup_grid ( IDGenerator idgen,
double  shift,
double  mass,
struct ic_part_data ICP 
)

Definition at line 91 of file zeldovich.c.

92 {
93  memset(ICP, 0, idgen->NumPart*sizeof(struct ic_part_data));
94 
95  int i;
96  #pragma omp parallel for
97  for(i = 0; i < idgen->NumPart; i ++) {
98  idgen_create_pos_from_index(idgen, i, &ICP[i].Pos[0]);
99  ICP[i].Pos[0] += shift;
100  ICP[i].Pos[1] += shift;
101  ICP[i].Pos[2] += shift;
102  ICP[i].Mass = mass;
103  }
104  return idgen->NumPart;
105 }
void idgen_create_pos_from_index(IDGenerator *idgen, int index, double pos[3])
Definition: zeldovich.c:79

References idgen_create_pos_from_index(), ic_part_data::Mass, IDGenerator::NumPart, and ic_part_data::Pos.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_particle_data()

void write_particle_data ( IDGenerator idgen,
const int  Type,
BigFile *  bf,
const uint64_t  FirstID,
const int  SavePrePos,
int  NumFiles,
int  NumWriters,
struct ic_part_data curICP 
)

Definition at line 61 of file save.c.

68 {
69  /* Write particles */
70  if(SavePrePos)
71  saveblock(bf, &curICP[0].PrePos, Type, "PrePosition", "f8", 3, idgen->NumPart, sizeof(curICP[0]), NumFiles, NumWriters);
72  saveblock(bf, &curICP[0].Density, Type, "ICDensity", "f4", 1, idgen->NumPart, sizeof(curICP[0]), NumFiles, NumWriters);
73  saveblock(bf, &curICP[0].Pos, Type, "Position", "f8", 3, idgen->NumPart, sizeof(curICP[0]), NumFiles, NumWriters);
74  saveblock(bf, &curICP[0].Vel, Type, "Velocity", "f4", 3, idgen->NumPart, sizeof(curICP[0]), NumFiles, NumWriters);
75  /*Generate and write IDs*/
76  uint64_t * ids = (uint64_t *) mymalloc("IDs", idgen->NumPart * sizeof(uint64_t));
77  memset(ids, 0, idgen->NumPart * sizeof(uint64_t));
78  int i;
79  #pragma omp parallel for
80  for(i = 0; i < idgen->NumPart; i++)
81  {
82  ids[i] = idgen_create_id_from_index(idgen, i) + FirstID;
83  }
84  saveblock(bf, ids, Type, "ID", "u8", 1, idgen->NumPart, sizeof(uint64_t), NumFiles, NumWriters);
85  myfree(ids);
86  walltime_measure("/Write");
87 }
static struct ic_part_data * curICP
Definition: glass.c:177
#define mymalloc(name, size)
Definition: mymalloc.h:15
uint64_t idgen_create_id_from_index(IDGenerator *idgen, int index)
Definition: zeldovich.c:69
static void saveblock(BigFile *bf, void *baseptr, int ptype, const char *bname, const char *dtype, int items_per_particle, const int NumPart, ptrdiff_t elsize, int NumFiles, int NumWriters)
Definition: save.c:49

References curICP, idgen_create_id_from_index(), myfree, mymalloc, IDGenerator::NumPart, saveblock(), and walltime_measure.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function: