|
@@ -1,4 +1,5 @@
|
|
|
import numpy as np
|
|
|
+from epileptor.phi_2d_iterative import calculate
|
|
|
|
|
|
|
|
|
class PhiSolver:
|
|
@@ -11,14 +12,17 @@ class PhiSolver:
|
|
|
return sigma
|
|
|
|
|
|
def __init__(self, x_nh, y_nh, sigma):
|
|
|
- self.phi_prev = None
|
|
|
+ self.phi_prev = np.zeros((y_nh, x_nh))
|
|
|
+ # make on item nonzero so we don't divide on zero further
|
|
|
+ self.phi_prev[1, 1] = 1
|
|
|
self.x_nh = x_nh
|
|
|
self.y_nh = y_nh
|
|
|
self.sigma = sigma
|
|
|
self.A = self.inverse_matrix_coef_explicit()
|
|
|
|
|
|
def ode_step(self, nu):
|
|
|
- self.phi_prev, _ = self.iterative_step(nu, 1e-8, self.phi_prev)
|
|
|
+ # self.phi_prev, _ = self.iterative_step(nu, 1e-8, self.phi_prev)
|
|
|
+ self.phi_prev, _ = calculate(self.sigma, nu, 1e-8, self.phi_prev)
|
|
|
return self.phi_prev
|
|
|
# return self.inverse_step(nu)
|
|
|
|
|
@@ -304,7 +308,7 @@ if __name__ == "__main__":
|
|
|
import matplotlib.pyplot as plt
|
|
|
import timeit
|
|
|
|
|
|
- timeit_num = 1000
|
|
|
+ timeit_num = 10
|
|
|
x_nh = 40
|
|
|
y_nh = 40
|
|
|
y_h = x_h = 3
|
|
@@ -326,21 +330,27 @@ if __name__ == "__main__":
|
|
|
|
|
|
# inverse
|
|
|
phi_inverse = solver.inverse_step(nu)
|
|
|
- print('inverse time: {}'.format(timeit.timeit('solver.inverse_step(nu)', number=timeit_num, globals=globals())))
|
|
|
+ print('inverse time: {}'.format(
|
|
|
+ timeit.timeit('solver.inverse_step(nu)', number=timeit_num, globals=globals())
|
|
|
+ ))
|
|
|
|
|
|
# iterative
|
|
|
phi_iterative, _ = solver.iterative_step(nu, 1e-8)
|
|
|
- print('iterative time: {}'.format(timeit.timeit('solver.iterative_step(nu, 1e-8)', number=timeit_num, globals=globals())))
|
|
|
+ print('iterative time: {}'.format(
|
|
|
+ timeit.timeit('solver.iterative_step(nu, 1e-8)', number=timeit_num, globals=globals())
|
|
|
+ ))
|
|
|
|
|
|
- # iterative inverse
|
|
|
- phi_iterative_inverse, _ = solver.iterative_inverse_step(nu, 1e-6)
|
|
|
- # print('iterative inverse time: {}'.format(timeit.timeit()))
|
|
|
+ # iterative plain
|
|
|
+ phi_iterative_plain, _ = calculate(sigma, nu, 1e-8, np.ones(nu.shape))
|
|
|
+ print('iterative plain time: {}'.format(
|
|
|
+ timeit.timeit('calculate(sigma, nu, 1e-8, np.ones(nu.shape))', number=timeit_num, globals=globals())
|
|
|
+ ))
|
|
|
|
|
|
- print(np.allclose(phi_inverse, phi_iterative_inverse, atol=1e-3))
|
|
|
+ print(np.allclose(phi_inverse, phi_iterative_plain, atol=1e-3))
|
|
|
# idx = 10
|
|
|
- # print(np.hstack((phi_inverse[:, idx][:, np.newaxis], phi_iterative[:, idx][:, np.newaxis], phi_iterative_inverse[:, idx][:, np.newaxis])))
|
|
|
- # print(np.hstack((phi_inverse[idx, :][:, np.newaxis], phi_iterative[idx, :][:, np.newaxis], phi_iterative_inverse[idx, :][:, np.newaxis])))
|
|
|
- print(np.sum(phi_inverse), np.sum(phi_iterative), np.sum(phi_iterative_inverse))
|
|
|
+ # print(np.hstack((phi_inverse[:, idx][:, np.newaxis], phi_iterative[:, idx][:, np.newaxis], phi_iterative_plain[:, idx][:, np.newaxis])))
|
|
|
+ # print(np.hstack((phi_inverse[idx, :][:, np.newaxis], phi_iterative[idx, :][:, np.newaxis], phi_iterative_plain[idx, :][:, np.newaxis])))
|
|
|
+ print(np.sum(phi_inverse), np.sum(phi_iterative), np.sum(phi_iterative_plain))
|
|
|
|
|
|
x = np.linspace(0, x_h, x_nh)
|
|
|
y = np.linspace(0, y_h, y_nh)
|
|
@@ -355,15 +365,15 @@ if __name__ == "__main__":
|
|
|
ax_phi1 = plt.subplot(222, projection='3d')
|
|
|
ax_phi1.plot_surface(x, y, phi_inverse, cmap='plasma')
|
|
|
# ax_phi1.axis([x_h / 2 - 2 * x_h, x_h / 2 + 2 * x_h, 0, y_h])
|
|
|
- ax_phi1.set_title('Phi1')
|
|
|
+ ax_phi1.set_title('Phi inverse')
|
|
|
|
|
|
ax_phi2 = plt.subplot(223, projection='3d')
|
|
|
ax_phi2.plot_surface(x, y, phi_iterative, cmap='plasma')
|
|
|
# ax_phi2.axis([x_h / 2 - 2 * x_h, x_h / 2 + 2 * x_h, 0, y_h])
|
|
|
- ax_phi2.set_title('Phi2')
|
|
|
+ ax_phi2.set_title('Phi iterative numpy')
|
|
|
|
|
|
ax_phi3 = plt.subplot(224, projection='3d')
|
|
|
- ax_phi3.plot_surface(x, y, phi_iterative_inverse, cmap='plasma')
|
|
|
- ax_phi3.set_title('Phi3')
|
|
|
+ ax_phi3.plot_surface(x, y, phi_iterative_plain, cmap='plasma')
|
|
|
+ ax_phi3.set_title('Phi iterative plain')
|
|
|
|
|
|
plt.show()
|