Commit 264920f4 authored by Olaf's avatar Olaf

Build in check to avoid errors in continuing on old calculations

parent c50964f0
......@@ -160,8 +160,32 @@ def extract_file_data(file):
mass = np.asarray(mass)
#return
return pos, velo, mass, n, t, barnes_hut, theta, approximation
def compatibility_check(n, bodies, n_asteroids):
"""
Checks whether the calculations can be continued and processed succesfully.
Parameters
----------
n: int
total number of bodies in saved data
bodies: list of objects.Body class objects
Contains objects.Body class objects with initialization parameters
n_asteroids: int
total number of asteroids in saved data
"""
nbodies = 0
non_ast = 0
for i in range(len(bodies)):
if isinstance(bodies[i], Asteroids):
nbodies += bodies[i].N
else:
nbodies += 1
if nbodies != n:
print("Total number of bodies in saved data: ", n, ", of which", n_asteroids, "are asteroids.")
raise ValueError("Check if number of bodies in predef.py is the same as in previous calculations")
def force_calc(mass, positions, D):
......@@ -372,6 +396,7 @@ def dynamics(bodies, D, h, t_max, barnes_hut, theta, approximation, j, startsave
T = round(t_max/h)
if continue_calc:
positions, velo, mass, n, t_init, barnes_hut, theta, approximation = extract_file_data(filename)
compatibility_check(mass.shape[0], bodies, mass.shape[0] - n)
elif not continue_calc:
positions, velo, mass, n = extract_data(bodies, D)
t_init = 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment