58 MPI_Comm_rank(MPI_COMM_WORLD, &
ThisTask);
75 const char mode[3]=
"a+";
79 MPI_Comm_rank(MPI_COMM_WORLD, &
ThisTask);
80 memset(fds, 0,
sizeof(
struct OutputFD));
88 if(RestartSnapNum != -1) {
99 endrun(1,
"Failed to open blackhole detail %s\n", buf);
112 endrun(1,
"error in opening file '%s'\n", buf);
118 if(!(fds->
FdCPU = fopen(buf, mode)))
119 endrun(1,
"error in opening file '%s'\n", buf);
125 if(!(fds->
FdEnergy = fopen(buf, mode)))
126 endrun(1,
"error in opening file '%s'\n", buf);
130 if(StarformationOn) {
133 if(!(fds->
FdSfr = fopen(buf, mode)))
134 endrun(1,
"error in opening file '%s'\n", buf);
141 if(!(fds->
FdHelium = fopen(buf, mode)))
142 endrun(1,
"error in opening file '%s'\n", buf);
165 void write_cpu_log(
int NumCurrentTiStep,
const double atime, FILE * FdCPU,
double ElapsedTime)
172 MPI_Comm_size(MPI_COMM_WORLD, &
NTask);
173 fprintf(FdCPU,
"Step %d, Time: %g, MPIs: %d Threads: %d Elapsed: %g\n", NumCurrentTiStep, atime,
NTask, omp_get_max_threads(), ElapsedTime);
195 a3 = Time * Time * Time;
197 double redshift = 1. / Time - 1;
198 memset(&sys, 0,
sizeof(sys));
201 #pragma omp parallel for
205 double entr = 0, egyspec;
207 sys.MassComp[
P[i].Type] +=
P[i].Mass;
209 sys.EnergyPotComp[
P[i].Type] += 0.5 *
P[i].Mass *
P[i].Potential / a1;
211 sys.EnergyKinComp[
P[i].Type] +=
212 0.5 *
P[i].Mass * (
P[i].Vel[0] *
P[i].Vel[0] +
P[i].Vel[1] *
P[i].Vel[1] +
P[i].Vel[2] *
P[i].Vel[2]) / a2;
217 entr =
SPHP(i).Entropy;
219 sys.EnergyIntComp[0] +=
P[i].Mass * egyspec;
220 double ne =
SPHP(i).Ne;
224 for(j = 0; j < 3; j++)
226 sys.MomentumComp[
P[i].Type][j] +=
P[i].Mass *
P[i].Vel[j];
227 sys.CenterOfMassComp[
P[i].Type][j] +=
P[i].Mass *
P[i].Pos[j];
230 sys.AngMomentumComp[
P[i].Type][0] +=
P[i].Mass * (
P[i].Pos[1] *
P[i].Vel[2] -
P[i].Pos[2] *
P[i].Vel[1]);
231 sys.AngMomentumComp[
P[i].Type][1] +=
P[i].Mass * (
P[i].Pos[2] *
P[i].Vel[0] -
P[i].Pos[0] *
P[i].Vel[2]);
232 sys.AngMomentumComp[
P[i].Type][2] +=
P[i].Mass * (
P[i].Pos[0] *
P[i].Vel[1] -
P[i].Pos[1] *
P[i].Vel[0]);
237 MPI_Reduce(&sys.MassComp[0], &SysState.MassComp[0], 6, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
238 MPI_Reduce(&sys.EnergyPotComp[0], &SysState.EnergyPotComp[0], 6, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
239 MPI_Reduce(&sys.EnergyIntComp[0], &SysState.EnergyIntComp[0], 6, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
240 MPI_Reduce(&sys.EnergyKinComp[0], &SysState.EnergyKinComp[0], 6, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
241 MPI_Reduce(&sys.TemperatureComp[0], &SysState.TemperatureComp[0], 6, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
242 MPI_Reduce(&sys.MomentumComp[0][0], &SysState.MomentumComp[0][0], 6 * 4, MPI_DOUBLE, MPI_SUM, 0,
244 MPI_Reduce(&sys.AngMomentumComp[0][0], &SysState.AngMomentumComp[0][0], 6 * 4, MPI_DOUBLE, MPI_SUM, 0,
246 MPI_Reduce(&sys.CenterOfMassComp[0][0], &SysState.CenterOfMassComp[0][0], 6 * 4, MPI_DOUBLE, MPI_SUM, 0,
249 MPI_Comm_rank(MPI_COMM_WORLD, &
ThisTask);
252 for(i = 0; i < 6; i++) {
253 SysState.EnergyTotComp[i] = SysState.EnergyKinComp[i] +
254 SysState.EnergyPotComp[i] + SysState.EnergyIntComp[i];
257 SysState.Mass = SysState.EnergyKin = SysState.EnergyPot = SysState.EnergyInt = SysState.EnergyTot = 0;
259 for(i = 0; i < 6; i++)
261 if(SysState.MassComp[i] > 0) {
262 SysState.TemperatureComp[i] /= SysState.MassComp[i];
266 for(j = 0; j < 3; j++)
267 SysState.Momentum[j] = SysState.AngMomentum[j] = SysState.CenterOfMass[j] = 0;
269 for(i = 0; i < 6; i++)
271 SysState.Mass += SysState.MassComp[i];
272 SysState.EnergyKin += SysState.EnergyKinComp[i];
273 SysState.EnergyPot += SysState.EnergyPotComp[i];
274 SysState.EnergyInt += SysState.EnergyIntComp[i];
275 SysState.EnergyTot += SysState.EnergyTotComp[i];
277 for(j = 0; j < 3; j++)
279 SysState.Momentum[j] += SysState.MomentumComp[i][j];
280 SysState.AngMomentum[j] += SysState.AngMomentumComp[i][j];
281 SysState.CenterOfMass[j] += SysState.CenterOfMassComp[i][j];
285 for(i = 0; i < 6; i++)
286 for(j = 0; j < 3; j++)
287 if(SysState.MassComp[i] > 0)
288 SysState.CenterOfMassComp[i][j] /= SysState.MassComp[i];
290 for(j = 0; j < 3; j++)
291 if(SysState.Mass > 0)
292 SysState.CenterOfMass[j] /= SysState.Mass;
294 for(i = 0; i < 6; i++)
296 SysState.CenterOfMassComp[i][3] = SysState.MomentumComp[i][3] = SysState.AngMomentumComp[i][3] = 0;
297 for(j = 0; j < 3; j++)
299 SysState.CenterOfMassComp[i][3] +=
300 SysState.CenterOfMassComp[i][j] * SysState.CenterOfMassComp[i][j];
301 SysState.MomentumComp[i][3] += SysState.MomentumComp[i][j] * SysState.MomentumComp[i][j];
302 SysState.AngMomentumComp[i][3] +=
303 SysState.AngMomentumComp[i][j] * SysState.AngMomentumComp[i][j];
305 SysState.CenterOfMassComp[i][3] = sqrt(SysState.CenterOfMassComp[i][3]);
306 SysState.MomentumComp[i][3] = sqrt(SysState.MomentumComp[i][3]);
307 SysState.AngMomentumComp[i][3] = sqrt(SysState.AngMomentumComp[i][3]);
310 SysState.CenterOfMass[3] = SysState.Momentum[3] = SysState.AngMomentum[3] = 0;
312 for(j = 0; j < 3; j++)
314 SysState.CenterOfMass[3] += SysState.CenterOfMass[j] * SysState.CenterOfMass[j];
315 SysState.Momentum[3] += SysState.Momentum[j] * SysState.Momentum[j];
316 SysState.AngMomentum[3] += SysState.AngMomentum[j] * SysState.AngMomentum[j];
319 SysState.CenterOfMass[3] = sqrt(SysState.CenterOfMass[3]);
320 SysState.Momentum[3] = sqrt(SysState.Momentum[3]);
321 SysState.AngMomentum[3] = sqrt(SysState.AngMomentum[3]);
325 MPI_Bcast(&SysState,
sizeof(
struct state_of_system), MPI_BYTE, 0, MPI_COMM_WORLD);
341 message(0,
"Time %g Mean Temperature of Gas %g\n",
345 "%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g\n",
double get_temp(double density, double ienergy, double helium, const struct UVBG *uvbg, double *ne_init)
struct UVBG get_local_UVBG(double redshift, const struct UVBG *const GlobalUVBG, const double *const Pos, const double *const PosOffset)
struct UVBG get_global_UVBG(double redshift)
void message(int where, const char *fmt,...)
void endrun(int where, const char *fmt,...)
void param_get_string2(ParameterSet *ps, const char *name, char *dst, size_t len)
int param_get_int(ParameterSet *ps, const char *name)
struct part_manager_type PartManager[1]
#define HYDROGEN_MASSFRAC
void write_cpu_log(int NumCurrentTiStep, const double atime, FILE *FdCPU, double ElapsedTime)
void close_outputfiles(struct OutputFD *fds)
void energy_statistics(FILE *FdEnergy, const double Time, struct part_manager_type *PartManager)
static struct stats_params StatsParams
void open_outputfiles(int RestartSnapNum, struct OutputFD *fds, const char *OutputDir, int BlackHoleOn, int StarformationOn)
struct state_of_system compute_global_quantities_of_system(const double Time, struct part_manager_type *PartManager)
void set_stats_params(ParameterSet *ps)
void fastpm_path_ensure_dirname(const char *path)
char * fastpm_strdup_printf(const char *fmt,...)
FILE * FdBlackholeDetails
double CurrentParticleOffset[3]
double AngMomentumComp[6][4]
double MomentumComp[6][4]
double CenterOfMassComp[6][4]
double TemperatureComp[6]
int WriteBlackHoleDetails
void walltime_summary(int root, MPI_Comm comm)
void walltime_report(FILE *fp, int root, MPI_Comm comm)