Beispiel #1
0
T = 100

sol = solve_ivp(odesys, [0, T], np.block([Einit[1:-1], Hinit]), method='RK45')
Herr = np.zeros(len(xx))
Eerr = np.zeros(len(xx))

Herr = np.zeros(len(sol.t))
Eerr = np.zeros(len(sol.t))
ctr = 0
#Herr = np.zeros(len(sol.t))
#Eerr = np.zeros(len(sol.t))
H = H00 + np.zeros(N)
E = np.zeros(N)
t = sol.t
XX, TT = np.meshgrid(xx, t)
for k in range(1, 150):
    H = H + h.Hn(XX, TT, k, L)
    E = E + h.En(XX, TT, k, L)
Herr = np.amax(np.abs(sol.y[N - 2:] - np.transpose(H)), axis=0)
Eerr = np.amax(np.abs(sol.y[:N - 2] - np.transpose(E[:, 1:-1])), axis=0)

plt.semilogy(sol.t, Herr, '.', label='max H error')
plt.semilogy(sol.t, Eerr, '.', label='max E error')
plt.grid()
plt.xlabel('t')
plt.ylabel('error')
plt.title('MOL2, dx=' + str(dx))
plt.legend()
plt.tight_layout()
plt.show()
Beispiel #2
0
    ax1.set_ylabel('H')
    ax1.set_xlabel('x')

    ax2.plot(xx, sol.y[N:, index])
    ax2.set_xlim([0, L])
    ax2.set_ylim([0, 1])
    ax2.set_ylabel('E')
    ax2.set_xlabel('x')

    H = H00 + np.array([0.0 for i in range(N)])
    E = np.array([0.0 for i in range(N)])

    t = sol.t[index]
    for k in range(1, 100):
        H = H + h.Hn(xx, t, k, L)
        E = E + h.En(xx, t, k, L)

    ax3.plot(xx, H)
    ax3.set_xlim([0, L])
    ax3.set_ylim([0, 2])
    ax3.set_ylabel('H')
    ax3.set_xlabel('x')

    ax4.plot(xx, E)
    ax4.set_xlim([0, L])
    ax4.set_ylim([0, 1])
    ax4.set_ylabel('E')
    ax4.set_xlabel('x')

    plt.tight_layout()
Beispiel #3
0
T = 1000

sol = solve_ivp(odesys, [0, T], initial, rtol=1e-6, atol=1e-8, method='RK45')
#sol = solve_ivp(odesys, [0, T], initial, max_step=dx, method='RK45')
Herr = np.zeros(len(sol.t))
Eerr = np.zeros(len(sol.t))
Herrmin = np.zeros(len(sol.t))
Eerrmin = np.zeros(len(sol.t))

H = H00 + np.array([0.0 for i in range(N)])
E = np.array([0.0 for i in range(N)])
t = sol.t
XX, TT = np.meshgrid(xx, t)
for k in range(1, 151):
    H = H + h.Hn(XX, TT, k, L)
    E = E + h.En(XX, TT, k, L)

Herr = np.amax(np.abs(sol.y[:N] - np.transpose(H)), axis=0)
Eerr = np.amax(np.abs(sol.y[N:] - np.transpose(E)), axis=0)

Eyee = h.initial(xx)
Eyee[0] = 0
Eyee[-1] = 0

Hyee = h.initial(xx)
Hyee[0] = 0
Hyee[-1] = 0

dt = dx / 2

s = dt / (2 * dx)