#include "NBody.hpp" extern FILE *snapshotsFile, *diagnosticsFile; extern void* me; // Pointing to NBody class; /////////////////////////////////// NBody::put_snapshot() Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ // // Writes a single snapshot on the output snapshot file. // /////////////////////////////////// NBody::put_snapshot() Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ void NBody::put_snapshot() { if (snapshotsFile == NULL){ std::cout << "Error: snapshot file not opened." << std::endl; ((NBody*)me)->cleanup(); exit(1); } // cout.precision(16); // Full double precision; fprintf(snapshotsFile, "%d\n", numParticles); // Total particle number; fprintf(snapshotsFile, "%f\n", curr_time_step); // Current time; for (int i = 0; i < numParticles ; i++){ fprintf(snapshotsFile, "%f\t", pos[i*4+3]); // Mass of particle i; for (int k = 0; k < 3; k++) fprintf(snapshotsFile, "%f\t", pos[i*4+k]); // Position of particle i; for (int k = 0; k < 3; k++) fprintf(snapshotsFile, "%f\t", vel[i*4+k]); // Velocity of particle i; fprintf(snapshotsFile, "\n"); } fprintf(snapshotsFile, "\n"); } /////////////////////////////////// NBody::epot_particle() Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ // // Computes the potential energy of a single particle; // /////////////////////////////////// NBody::epot_particle() Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ float NBody::epot_particle(int currPart) { float ePot = 0.0; for (int i=0; icleanup(); exit(1); } // cout.precision(16); // Full double precision; fprintf(diagnosticsFile, "At time t = %f, after %ld steps:\n", curr_time_step, taken_steps); fprintf(diagnosticsFile, " E_init = %f,\n E_tot = %f,\n E_kin = %f,\n E_pot = %f\n", Etot_init, Etot, Ekin, Epot); fprintf(diagnosticsFile, " Absolute energy error: E_tot - E_init = %f\n", Etot - Etot_init); fprintf(diagnosticsFile, " Relative energy error: (E_tot - E_init) / E_init = %f\n", (Etot - Etot_init) / Etot_init); }else{ initFlag = false; } }