void reb_step(struct reb_simulation* const r){ // Update walltime struct timeval time_beginning; gettimeofday(&time_beginning,NULL); // A 'DKD'-like integrator will do the first 'D' part. PROFILING_START() if (r->pre_timestep_modifications){ reb_integrator_synchronize(r); r->pre_timestep_modifications(r); r->ri_whfast.recalculate_coordinates_this_timestep = 1; r->ri_mercurius.recalculate_coordinates_this_timestep = 1; } reb_integrator_part1(r); PROFILING_STOP(PROFILING_CAT_INTEGRATOR) // Update and simplify tree. // Prepare particles for distribution to other nodes. // This function also creates the tree if called for the first time. if (r->tree_needs_update || r->gravity==REB_GRAVITY_TREE || r->collision==REB_COLLISION_TREE){ // Check for root crossings. PROFILING_START() reb_boundary_check(r); PROFILING_STOP(PROFILING_CAT_BOUNDARY) // Update tree (this will remove particles which left the box) PROFILING_START() reb_tree_update(r); PROFILING_STOP(PROFILING_CAT_GRAVITY) }
void heartbeat(struct reb_simulation* r){ if(reb_output_check(r, 20.*M_PI)){ reb_output_timing(r, tmax); } if(reb_output_check(r, 40.)){ reb_integrator_synchronize(r); reb_output_orbits(r,"orbits.txt"); reb_move_to_com(r); } }
void heartbeat(struct reb_simulation* r){ if (reb_output_check(r, 10000.)){ reb_output_timing(r, tmax); reb_integrator_synchronize(r); FILE* f = fopen("energy.txt","a"); double e = reb_tools_energy(r); fprintf(f,"%e %e\n",r->t, fabs((e-e_init)/e_init)); fclose(f); } }
void heartbeat(struct reb_simulation* r){ if (r->t > next_output){ next_output *= 1.02; reb_integrator_synchronize(r); FILE* f = fopen("energy.txt","a"); double e = energy(r); fprintf(f, "%e %.16e\n", r->t, fabs((e-e_init)/e_init)); fclose(f); } }
void heartbeat(struct reb_simulation* r){ if (reb_output_check(r, 10.*2.*M_PI)){ reb_output_timing(r, 0); } if (reb_output_check(r, 2.*M_PI)){ // Once per year, output the relative energy error to a text file FILE* f = fopen("energy.txt","a"); reb_integrator_synchronize(r); double e = reb_tools_energy(r); fprintf(f,"%e %e\n",r->t, fabs((e-e_init)/e_init)); fclose(f); } }