mirror of
https://github.com/Findus23/rebound-collisions.git
synced 2024-09-19 15:53:48 +02:00
log energy every 100 years
This commit is contained in:
parent
f97b0928b4
commit
60e5175738
2 changed files with 15 additions and 2 deletions
|
@ -18,6 +18,13 @@ int hb_sun_collision_index = 0;
|
|||
|
||||
int needs_synchronize = 0;
|
||||
|
||||
FILE *logfile;
|
||||
|
||||
void init_logfile(char *filename) {
|
||||
FILE *f = fopen(filename, "a");
|
||||
logfile = f;
|
||||
}
|
||||
|
||||
void heartbeat(struct reb_simulation *sim) {
|
||||
if ((sim->steps_done % 10) == 0) {
|
||||
const struct reb_particle *const particles = sim->particles;
|
||||
|
@ -60,4 +67,7 @@ void heartbeat(struct reb_simulation *sim) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if ((sim->steps_done % 10000) == 0) { // ~ every 100 years
|
||||
fprintf(logfile, "%f, %f\n", sim->t, reb_tools_energy(sim));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import re
|
||||
import time
|
||||
from ctypes import Structure, c_uint32, c_double, c_uint, cdll, c_int
|
||||
from ctypes import Structure, c_uint32, c_double, c_uint, cdll, c_int, create_string_buffer, c_char_p
|
||||
from dataclasses import dataclass
|
||||
from math import radians
|
||||
from pathlib import Path
|
||||
from shutil import copy
|
||||
from sys import argv
|
||||
|
@ -173,6 +172,10 @@ def main(fn: Path, testrun=False):
|
|||
|
||||
check_heartbeat_needs_recompile()
|
||||
clibheartbeat = cdll.LoadLibrary("heartbeat/heartbeat.so")
|
||||
clibheartbeat.init_logfile.argtypes = [c_char_p]
|
||||
logfile = create_string_buffer(128)
|
||||
logfile.value = str(fn.with_suffix(".energylog.csv")).encode()
|
||||
clibheartbeat.init_logfile(logfile)
|
||||
sim.heartbeat = clibheartbeat.heartbeat
|
||||
innermost_semimajor_axis = third_kepler_law(
|
||||
orbital_period=sim.dt * year * MIN_TIMESTEP_PER_ORBIT
|
||||
|
|
Loading…
Reference in a new issue