vnew = v + (vk1 + 2 * vk2 + 2 * vk3 + vk4) / 6 return ynew, vnew def euler(y, v, t, dt): # simple euler integrator vnew = v + accel(y, v, t) * dt ynew = y + vnew * dt + 1 / 2 * accel(y, vnew, t) * dt**2 return ynew, vnew positions_eu, positions_rk = [], [] y_eu, y_rk = np.array(y), np.array(y) v_eu, v_rk = np.array(v), np.array(v) t = 0 pb = ProgressBar(0, Nsteps, c="blue", ETA=0) for i in pb.range(): y_eu, v_eu = euler(y_eu, v_eu, t, dt) y_rk, v_rk = rk4(y_rk, v_rk, t, dt) t += dt positions_eu.append(y_eu) # store result of integration positions_rk.append(y_rk) pb.print("Integrate: RK-4 and Euler") #################################################### # Visualize the result #################################################### vp = Plotter(interactive=0, axes=2) # choose axes type nr.2 vp.ytitle = "u(x,t)" vp.ztitle = "" # will not draw z axis for i in x:
import numpy as np from Forces.forces import relu_force from Solvers.solvers import take_euler_step # Params N = 200 T = 100 r_max = 1.0 r_eq = 0.8 dt = 0.1 # Initialise cells ini_x = np.random.uniform(low=-1.0, high=1.0, size=N) ini_y = np.random.uniform(low=-1.0, high=1.0, size=N) ini_z = np.random.uniform(low=-1.0, high=1.0, size=N) X = np.column_stack((ini_x, ini_y, ini_z)) from vedo import ProgressBar, Spheres, interactive pb = ProgressBar(0, T, c='red') for t in pb.range(): take_euler_step(X, N, dt, relu_force, r_max, r_eq) Spheres(X, c='b', r=0.3).show(axes=1, interactive=0) pb.print() interactive()