12#include "gadgetconfig.h"
22#include "../cooling_sfr/cooling.h"
23#include "../data/allvars.h"
24#include "../data/dtypes.h"
25#include "../data/mymalloc.h"
26#include "../domain/domain.h"
27#include "../gravtree/gravtree.h"
29#include "../io/snap_io.h"
30#include "../lightcone/lightcone_massmap_io.h"
31#include "../lightcone/lightcone_particle_io.h"
32#include "../logs/logs.h"
33#include "../main/main.h"
34#include "../main/simulation.h"
35#include "../ngbtree/ngbtree.h"
36#include "../sort/parallel_sort.h"
37#include "../system/system.h"
51#if defined(NGENIC_TEST) && defined(PERIODIC) && defined(PMGRID)
54#if defined(POWERSPEC_ON_OUTPUT)
68#ifdef OUTPUT_NON_SYNCHRONIZED_ALLOWED
86#ifdef LIGHTCONE_PARTICLES
87 mpi_printf(
"LIGHTCONE_PARTICLES: Lp.NumPart=%d Checked %d box replicas out of list of length %d\n", Lp.NumPart,
88 LightCone.NumLastCheck, LightCone.NumBoxes);
90#ifdef LIGHTCONE_MASSMAPS
91 mpi_printf(
"LIGHTCONE_MASSMAPS: Mp.NumPart=%d \n", Mp.NumPart);
93#if defined(LIGHTCONE_MASSMAPS) || defined(LIGHTCONE_PARTICLES_GROUPS)
109 set_non_standard_physics_for_current_time();
119#ifdef LIGHTCONE_PARTICLES
120 LightCone.lightcone_clear_boxlist(
All.
Time);
152 calculate_non_standard_physics_end_of_step();
205#ifdef STOP_AFTER_STEP
208 mpi_printf(
"RUN: We have reached the timestep specified with STOP_AFTER_STEP and therefore stop.");
216 if(check_for_interruption_of_run())
230void sim::set_non_standard_physics_for_current_time(
void)
233 CoolSfr.IonizeParams();
243void sim::calculate_non_standard_physics_end_of_step(
void)
247 CoolSfr.sfr_create_star_particles(&
Sp);
248 CoolSfr.cooling_and_starformation(&
Sp);
250 CoolSfr.cooling_only(&
Sp);
254#ifdef MEASURE_TOTAL_MOMENTUM
268int sim::check_for_interruption_of_run(
void)
278 if((fd = fopen(stopfname,
"r")))
281 printf(
"stop-file detected. stopping.\n");
287 if((fd = fopen(stopfname,
"r")))
290 printf(
"restart-file detected. writing restart files.\n");
297 printf(
"reaching time-limit. stopping.\n");
318 if((fd = fopen(contfname,
"w")))
373#ifndef OUTPUT_NON_SYNCHRONIZED_ALLOWED
383 while(ti_min > timax)
387 double multiplier = ti / ((double)timax);
415 Terminate(
"TimeBetSnapshot > 1.0 required for your simulation.\n");
420 Terminate(
"TimeBetSnapshot > 0.0 required for your simulation.\n");
435 Terminate(
"Can't determine next output time.\n");
445#ifndef OUTPUT_NON_SYNCHRONIZED_ALLOWED
455 while(ti_min > timax)
459 double multiplier = ti / ((double)timax);
479 Terminate(
"Can't determine next output time.\n");
487 mpi_printf(
"\nSNAPSHOT: There is no valid time for a further snapshot file.\n");
509#if defined(LIGHTCONE_MASSMAPS)
512 LightCone.lightcone_massmap_flush(1);
515#ifndef OUTPUT_NON_SYNCHRONIZED_ALLOWED
522 Terminate(
"P[i].Ti_Current != All.Ti_Current");
524#if defined(STARFORMATION) && defined(FOF)
533#ifndef OUTPUT_NON_SYNCHRONIZED_ALLOWED
540 mpi_printf(
"\nFOF: We shall first compute a group catalog for this snapshot file\n");
557#if defined(MERGERTREE) && defined(SUBFIND)
558 MergerTree.CurrTotNsubhalos = FoF.TotNsubhalos;
559 MergerTree.CurrNsubhalos = FoF.Nsubhalos;
563 MergerTree.PrevTotNsubhalos = FoF.TotNsubhalos;
564 MergerTree.PrevNsubhalos = FoF.Nsubhalos;
568 Sp.
P[n].PrevSubhaloNr =
Sp.
PS[n].SubhaloNr;
569 Sp.
P[n].PrevSizeOfSubhalo =
Sp.
PS[n].SizeOfSubhalo;
570 Sp.
P[n].PrevRankInSubhalo =
Sp.
PS[n].RankInSubhalo;
572 if(
Sp.
P[n].PrevSubhaloNr.get() >= MergerTree.PrevTotNsubhalos &&
Sp.
P[n].PrevSubhaloNr.get() !=
HALONR_MAX)
573 Terminate(
"Sp.P[n].PrevSubhaloNr=%lld MergerTree.PrevTotNsubhalos=%lld\n", (
long long)
Sp.
P[n].PrevSubhaloNr.get(),
574 (
long long)MergerTree.PrevTotNsubhalos);
576 if(
Sp.
P[n].PrevSizeOfSubhalo.get() > 0 &&
Sp.
P[n].PrevSubhaloNr.get() ==
HALONR_MAX)
577 Terminate(
"Sp.P[n].PrevSizeOfSubhalo=%d Sp.P[n].PrevSubhaloNr=%lld\n", (
int)
Sp.
P[n].PrevSizeOfSubhalo.get(),
578 (
long long)
Sp.
P[n].PrevSubhaloNr.get());
589#ifdef SUBFIND_ORPHAN_TREATMENT
613#if defined(POWERSPEC_ON_OUTPUT) && defined(PERIODIC) && defined(PMGRID)
620#ifndef OUTPUT_NON_SYNCHRONIZED_ALLOWED
635#if defined(LIGHTCONE_PARTICLES)
636 if(Lp.TestIfAboveFillFactor(std::min<int>(Lp.MaxPart,
Sp.
MaxPart)))
638#if defined(LIGHTCONE_PARTICLES_GROUPS) && defined(FOF)
642 mpi_printf(
"\nLIGHTCONE_PARTICLES_GROUPS: We shall first compute a group catalogue for the lightcone particles\n");
646 int *numlist = (
int *)
Mem.mymalloc(
"numlist", Lp.NumPart *
sizeof(
int));
648 MPI_Allgather(&Lp.NumPart, 1, MPI_INT, numlist, 1, MPI_INT,
Communicator);
654 for(
int i = 0; i < Lp.NumPart; i++)
655 Lp.P[i].ID.set(newID++);
668 for(
int i = 0; i < Lp.NumPart; i++)
671 Lp.PS[i].OriginIndex = i;
678 FoF.fof_fof(
All.LightconeFileCount,
"lc_fof",
"lc_groups", inner_distance);
684 MergerTree.Ntrees = 0;
689 long long NumLP_tot = Lp.NumPart;
690 MPI_Allreduce(MPI_IN_PLACE, &NumLP_tot, 1, MPI_LONG_LONG, MPI_SUM,
Communicator);
691 mpi_printf(
"\nLIGHTCONE: writing particle lightcone conesnap files #%d ... (NumLP_tot = %lld)\n",
All.LightconeFileCount,
694 for(
int i = 0; i < Lp.NumPart; i++)
698 vec2pix_ring(LIGHTCONE_ORDER_NSIDE, pos, &Lp.P[i].ipnest);
701#if !defined(LIGHTCONE_PARTICLES_GROUPS)
706 for(
int conenr = 0; conenr < LightCone.Nlightcones; conenr++)
707 Lcone.lightcone_save(
All.LightconeFileCount, conenr,
false);
709 mpi_printf(
"LIGHTCONE: done with writing files.\n");
711 All.LightconeFileCount++;
715#if defined(LIGHTCONE_PARTICLES_GROUPS) && defined(FOF)
717 for(
int n = 0; n < Lp.NumPart; n++)
719 Lp.PS[n].TargetTask = Lp.PS[n].OriginTask;
720 Lp.PS[n].TargetIndex = Lp.PS[n].OriginIndex;
733 int ncount[2] = {0, 0};
735 for(
int n = 0; n < Lp.NumPart; n++)
737 if(Lp.P[n].getFlagSaveDistance())
739 Lp.P[n--] = Lp.P[--Lp.NumPart];
749 mpi_printf(
"LIGHTCONE_PARTICLES_GROUPS: We could store %lld particles from the buffer, but had to keep %lld\n", nsum[0],
global_data_all_processes All
void particle_exchange_based_on_PS(MPI_Comm Communicator)
void domain_decomposition(domain_options mode)
double get_comoving_distance_for_scalefactor(double ascale)
int flush_everything(void)
void write_cpu_log(void)
Write the FdBalance and FdCPU files.
void output_log_messages(void)
Write the FdInfo and FdTimeBin files.
void compute_statistics(void)
Computes new global statistics if needed (done by energy_statistics())
void log_debug_md5(const char *msg)
void compute_total_momentum(void)
void update_maxhsml(void)
void update_velocities(void)
void mpi_printf(const char *fmt,...)
domain< simparticles > Domain
void do_hydro_step_second_half(void)
void do_hydro_step_first_half(void)
void find_hydro_timesteps(void)
void find_timesteps_and_do_gravity_step_first_half(void)
performs the first half step kick operator for the gravity
void do_gravity_step_second_half(void)
performs the second gravity half step kick operator
void create_snapshot_if_desired(void)
Check if a snapshot should be saved.
void endrun(void)
This function aborts the simulations.
void reconstruct_timebins(void)
TimeBinData TimeBinsGravity
TimeBinData TimeBinsHydro
integertime find_next_sync_point(void)
This function finds the next synchronization point of the system. (i.e. the earliest point of time an...
void make_list_of_active_particles(void)
void drift_all_particles(void)
void mark_active_timebins(void)
void write_snapshot(int num, mysnaptype snap_type)
Save snapshot to disk.
void compute_densities(void)
void treeallocate(int max_partindex, partset *Pptr, domain< partset > *Dptr)
int treebuild(int ninsert, int *indexlist)
#define MAXLEN_PATH_EXTRA
#define LIGHTCONE_ALLOC_FAC
@ MOST_BOUND_PARTICLE_SNAPHOT
int32_t MySignedIntPosType
#define TIMER_START(counter)
Starts the timer counter.
#define TIMER_STOP(counter)
Stops the timer counter.
void sumup_large_ints(int n, int *src, long long *res, MPI_Comm comm)
double mycxxsort_parallel(T *begin, T *end, Comp comp, MPI_Comm comm)
void timebins_allocate(void)
double get_absolutetime_from_integertime(integertime ti)
double TimeOfFirstSnapshot
int ComovingIntegrationOn
int SmallestTimeBinWithDomainDecomposition
char OutputDir[MAXLEN_PATH]
integertime Ti_lastoutput
integertime Ti_nextoutput
double OutputListTimes[MAXLEN_OUTPUTLIST]
void set_cosmo_factors_for_current_time(void)
double TimeLastRestartFile
char OutputListFlag[MAXLEN_OUTPUTLIST]
double CpuTimeBetRestartFile
int HighestOccupiedTimeBin
std::atomic< integertime > Ti_Current