5 #include <gsl/gsl_sf_gamma.h>
48 MPI_Comm_rank(MPI_COMM_WORLD, &
ThisTask);
59 if (RestartSnapNum < 0) {
77 static void get_mean_separation(
double * MeanSeparation,
const double BoxSize,
const int64_t * NTotalInit);
101 double MeanSeparation[6] = {0};
105 if(RestartSnapNum == -1)
117 #pragma omp parallel for
121 P[i].Ti_drift = Ti_Current;
123 if(RestartSnapNum == -1 &&
P[i].Type == 5 )
126 BHP(i).Mass =
P[i].Mass;
133 P[i].Hsml = 0.1 * MeanSeparation[0];
138 for(j = 0; j < 3; j++) {
139 BHP(i).DFAccel[j] = 0;
140 BHP(i).DragAccel[j] = 0;
146 if(
P[i].Type != 0)
continue;
148 for(j = 0; j < 3; j++)
150 SPHP(i).HydroAccel[j] = 0;
153 if(!isfinite(
SPHP(i).DelayTime ))
154 endrun(6,
"Bad DelayTime %g for part %d id %ld\n",
SPHP(i).DelayTime, i,
P[i].ID);
155 SPHP(i).DtEntropy = 0;
157 if(RestartSnapNum == -1)
159 SPHP(i).Density = -1;
160 SPHP(i).EgyWtDensity = -1;
161 SPHP(i).DhsmlEgyDensityFactor = -1;
162 SPHP(i).Entropy = -1;
166 SPHP(i).DelayTime = 0;
167 SPHP(i).Metallicity = 0;
173 SPHP(i).MaxSignalVel = 0;
186 double mass = 0, masstot, omega;
190 #pragma omp parallel for reduction(+: mass) reduction(+: badmass)
195 P[i].Mass = MassTable[
P[i].Type] * ( 1. - (double)
P[i].Generation/generations);
201 MPI_Allreduce(&mass, &masstot, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
205 message(0,
"Warning: recovering from %ld Mass entries corrupted on disc\n",totbad);
213 if(fabs(omega -
CP->
Omega0) > 1.0e-3)
215 endrun(0,
"The mass content accounts only for Omega=%g,\nbut you specified Omega=%g in the parameterfile.\n",
225 MPI_Comm_size(Comm, &
NTask);
231 int64_t TotNumPartInit= 0;
239 const char * PARTICLE_TYPE_NAMES [] = {
"Gas",
"DarkMatter",
"Neutrino",
"Unknown",
"Star",
"BlackHole"};
243 message(0,
"% 11s: Total: %018ld Init: %018ld Mean-Sep %g \n",
248 int MaxPart = (int) (PartAllocFactor * TotNumPartInit /
NTask);
271 int64_t newSlots[6] = {0};
277 newSlots[
ptype] *= PartAllocFactor;
300 #pragma omp parallel for reduction(+: numzero) reduction(max:lastzero)
308 if((Pos[0] < 1e-35) && (Pos[1] < 1e-35) && (Pos[2] < 1e-35)) {
314 endrun(5,
"Particle positions contain %d zeros at particle %d. Pos %g %g %g. Likely write corruption!\n",
328 #pragma omp parallel for reduction(+: numprob) reduction(max:lastprob)
330 if(
P[i].Type != 5 &&
P[i].Type != 0)
333 P[i].Hsml = MeanSpacing[
P[i].Type];
339 message(5,
"Bad smoothing lengths %d last bad %d hsml %g id %ld\n", numprob, lastprob,
P[lastprob].Hsml,
P[lastprob].ID);
346 const double a3 = pow(atime, 3);
350 #pragma omp parallel for reduction(+: bad)
355 if(
SphP[i].Density <= 0 || !isfinite(
SphP[i].Density)) {
356 SphP[i].Density = meanbar;
359 if(
SphP[i].EgyWtDensity <= 0 || !isfinite(
SphP[i].EgyWtDensity)) {
360 SphP[i].EgyWtDensity =
SphP[i].Density;
363 if(
SphP[i].Entropy < minent)
364 SphP[i].Entropy = minent;
366 MPI_Allreduce(MPI_IN_PLACE, &bad, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
368 message(0,
"Detected bad densities in %d particles on disc\n",bad);
374 for(i = 0; i < 6; i++) {
375 if(NTotalInit[i] > 0)
376 MeanSeparation[i] = BoxSize / pow(NTotalInit[i], 1.0 / 3);
389 message(0,
"Converting u -> entropy, with density split sph\n");
392 #pragma omp parallel for
394 SphP[j].EgyWtDensity =
SphP[j].Density;
397 for(j = 0; j < 100; j++)
401 #pragma omp parallel for
404 olddensity[i] =
SphP[i].EgyWtDensity;
414 #pragma omp parallel for reduction(max: maxdiff)
416 double value = fabs(
SphP[i].EgyWtDensity - olddensity[i]) /
SphP[i].EgyWtDensity;
417 maxdiff =
DMAX(maxdiff,value);
419 MPI_Allreduce(MPI_IN_PLACE, &maxdiff, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
421 message(0,
"iteration %d, max relative change in EgyWtDensity = %g \n", j, maxdiff);
442 const double a3 = pow(atime, 3);
444 if(RestartSnapNum >= 0)
452 int64_t tot_sph, tot_bh;
457 if(tot_sph + tot_bh == 0)
475 #pragma omp parallel for
479 if(
P[i].Type != 0 &&
P[i].Type != 5)
484 while(10 * DesNumNgb *
P[i].Mass > massfactor * Tree.
Nodes[no].
mom.
mass)
495 pow(3.0 / (4 * M_PI) * DesNumNgb *
P[i].Mass / (massfactor * Tree.
Nodes[no].
mom.
mass),
499 if(
P[i].Hsml > 500.0 * MeanGasSeparation)
500 P[i].Hsml = MeanGasSeparation;
503 endrun(5,
"Bad hsml guess: i=%d, mass = %g type %d hsml %g no %d len %d treemass %g\n",
511 double molecular_weight;
516 u_init /= molecular_weight;
518 if(u_init < MinEgySpec)
532 density(&act, 1, 0, BlackHoleOn, 0, times,
CP, &sph_pred, NULL, &Tree);
539 #pragma omp parallel for
double GetNumNgb(enum DensityKernelType KernelType)
struct sph_pred_data slots_allocate_sph_pred_data(int nsph)
void slots_free_sph_pred_data(struct sph_pred_data *sph_scratch)
enum DensityKernelType GetDensityKernelType(void)
void density(const ActiveParticles *act, int update_hsml, int DoEgyDensity, int BlackHoleOn, double MinEgySpec, const DriftKickTimes times, Cosmology *CP, struct sph_pred_data *SPH_predicted, MyFloat *GradRho, const ForceTree *const tree)
void message(int where, const char *fmt,...)
void endrun(int where, const char *fmt,...)
void domain_test_id_uniqueness(struct part_manager_type *pman)
void fof_init(double DMMeanSeparation)
void force_tree_rebuild(ForceTree *tree, DomainDecomp *ddecomp, const int HybridNuGrav, const int DoMoments, const char *EmergencyOutputDir)
void force_tree_free(ForceTree *tree)
int force_get_father(int no, const ForceTree *tree)
void gravshort_set_softenings(double MeanDMSeparation)
int DensityIndependentSphOn(void)
static void check_omega(struct part_manager_type *PartManager, Cosmology *CP, int generations, double G, double *MassTable)
void check_density_entropy(Cosmology *CP, const double MinEgySpec, const double atime)
void set_init_params(ParameterSet *ps)
static struct init_params InitParams
void setup_smoothinglengths(int RestartSnapNum, DomainDecomp *ddecomp, Cosmology *CP, int BlackHoleOn, double MinEgySpec, double uu_in_cgs, const inttime_t Ti_Current, const double atime, const int64_t NTotGasInit)
static void check_smoothing_length(struct part_manager_type *PartManager, double *MeanSpacing)
static void check_positions(struct part_manager_type *PartManager)
static void init_alloc_particle_slot_memory(struct part_manager_type *PartManager, struct slots_manager_type *SlotsManager, const double PartAllocFactor, struct header_data *header, MPI_Comm Comm)
inttime_t init(int RestartSnapNum, const char *OutputDir, struct header_data *header, Cosmology *CP)
static void get_mean_separation(double *MeanSeparation, const double BoxSize, const int64_t *NTotalInit)
void init_timeline(int RestartSnapNum, double TimeMax, const struct header_data *header, const int SnapshotWithFOF)
static void setup_density_indep_entropy(const ActiveParticles *act, ForceTree *Tree, Cosmology *CP, struct sph_pred_data *sph_pred, double u_init, double a3, int BlackHoleOn, const inttime_t Ti_Current)
#define mymalloc(name, size)
double get_omega_nu_nopart(const _omega_nu *const omnu, const double a)
double param_get_double(ParameterSet *ps, const char *name)
struct part_manager_type PartManager[1]
void particle_alloc_memory(struct part_manager_type *PartManager, double BoxSize, int64_t MaxPart)
static peano_t PEANO(double *Pos, double BoxSize)
void petaio_read_snapshot(int num, const char *OutputDir, Cosmology *CP, struct header_data *header, struct part_manager_type *PartManager, struct slots_manager_type *SlotsManager, MPI_Comm Comm)
#define HYDROGEN_MASSFRAC
int get_generations(void)
size_t slots_reserve(int where, int64_t atleast[6], struct slots_manager_type *sman)
void slots_setup_topology(struct part_manager_type *pman, int64_t *NLocal, struct slots_manager_type *sman)
struct slots_manager_type SlotsManager[1]
int64_t NumActiveParticle
struct particle_data * Base
void sumup_large_ints(int n, int *src, int64_t *res)
#define MPIU_Barrier(comm)
inttime_t ti_from_loga(double loga)
inttime_t round_down_power_of_two(inttime_t dti)
void setup_sync_points(double TimeIC, double TimeMax, double no_snapshot_until_time, int SnapshotWithFOF)
DriftKickTimes init_driftkicktime(inttime_t Ti_Current)
inttime_t init_timebins(double TimeInit)
#define walltime_measure(name)
static enum TransferType ptype