Skip to content

Commit

Permalink
Whistler test now works in both directions
Browse files Browse the repository at this point in the history
  • Loading branch information
UCaromel committed Jul 30, 2024
1 parent 77c9dc5 commit 2daa8af
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 180 deletions.
95 changes: 0 additions & 95 deletions diagnostics/orszag-tang/plotJ.py

This file was deleted.

99 changes: 52 additions & 47 deletions diagnostics/whistlerwave/plotJ.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
from matplotlib.animation import FuncAnimation
import os

nx = 128
Dx = 0.05
nx = 1
ny = 128
Dx = 1
Dy = 0.1

Dt = 0.000625
nghost = 2

nghostJ = nghost + 1

Dt = 0.04

Jx = []
Jy = []
Jz = []
times = []
Expand All @@ -20,71 +26,70 @@ def read_file(filename):
return df

for filename in os.listdir(results_dir):
if filename.startswith("Jy_") and filename.endswith(".txt"):
if filename.startswith("Jx_") and filename.endswith(".txt"):
time_str = filename.split('_')[1].split('.')[0]
time = float(time_str)
times.append(time)

df = read_file(os.path.join(results_dir, filename))
Jy.append(df.values.reshape((7,135)))
Jx.append(df.values.reshape((ny + 2*nghostJ + 1, nx + 2*nghostJ)))

if filename.startswith("Jy_") and filename.endswith(".txt"):

df = read_file(os.path.join(results_dir, filename))
Jy.append(df.values.reshape((ny + 2*nghostJ, nx + 2*nghostJ + 1)))

if filename.startswith("Jz_") and filename.endswith(".txt"):

df = read_file(os.path.join(results_dir, filename))
Jz.append(df.values.reshape((8,135)))
Jz.append(df.values.reshape((ny + 2*nghostJ + 1, nx + 2*nghostJ + 1)))

x=Dx*np.arange(135)-2*Dx
x=Dx*np.arange(nx + 2*nghostJ )-nghostJ*Dx
y=Dy*np.arange(ny + 2*nghostJ+1)-nghostJ*Dy

def update(frame):
# def update(frame):

m = 10
lx = nx*Dx
k = 2*np.pi/lx * m
expectedJy = -k * np.cos(k*x + k**2 * times[frame]*Dt + 0.5488135)*0.01
expectedJz = -k * np.sin(k*x + k**2 * times[frame]*Dt + 0.5488135)*0.01
# m = 4
# ly = ny*Dy
# k = 2*np.pi/ly * m
# #expectedJy = -k * np.cos(k*x + k**2 * times[frame]*Dt + 0.5488135)*0.01
# #expectedJz = -k * np.sin(k*x + k**2 * times[frame]*Dt + 0.5488135)*0.01

plt.clf()
# plt.clf()

#plt.plot(x, expectedJy, 'y-', marker = '+')
#plt.plot(x, expectedJz, 'g-', marker = 'x')
# #plt.plot(x, expectedJy, 'y-', marker = '+')
# #plt.plot(x, expectedJz, 'g-', marker = 'x')

plt.plot(x, Jy[frame][3,:], 'b-', marker = 'o')
#plt.plot(x, Jz[frame][2,:], 'r--',marker = '*')
# plt.plot(y, Jx[frame][:,3], 'b-', marker = 'o')
# #plt.plot(x, Jz[frame][2,:], 'r--',marker = '*')

#plt.plot(x, Jy2[frame][2,:], 'y-', marker = 'o')
#plt.plot(x, Jz2[frame][2,:], 'g--',marker = '*')
# #plt.plot(x, Jy2[frame][2,:], 'y-', marker = 'o')
# #plt.plot(x, Jz2[frame][2,:], 'g--',marker = '*')

plt.xlabel('x')
plt.grid(True)
#plt.yscale("log")
plt.tight_layout()

eps = 1e-7
min_val = np.min(Jy) - eps
max_val = np.max(Jz) + eps

plt.ylim(min_val, max_val)
plt.axvline(x[2], ls='--', color='k')
plt.axvline(x[-3], ls='--', color='k')
# plt.xlabel('x')
# plt.grid(True)
# #plt.yscale("log")
# plt.tight_layout()
# plt.axvline(y[2], ls='--', color='k')
# plt.axvline(y[-3], ls='--', color='k')


fig = plt.figure(figsize=(8, 6))
ani = FuncAnimation(fig, update, frames=len(times), interval=500)
# fig = plt.figure(figsize=(8, 6))
# ani = FuncAnimation(fig, update, frames=len(times), interval=500)

# Define a function for manually stepping through the frames
def onclick(event):
if event.key == 'right':
ani.frame_seq = ani.new_frame_seq()
fig.canvas.draw()
# # Define a function for manually stepping through the frames
# def onclick(event):
# if event.key == 'right':
# ani.frame_seq = ani.new_frame_seq()
# fig.canvas.draw()

# Connect the key press event to the function
fig.canvas.mpl_connect('key_press_event', onclick)
# # Connect the key press event to the function
# fig.canvas.mpl_connect('key_press_event', onclick)

plt.show()
# plt.show()

"""plt.plot(x, Jy[10][2,:], 'b-', marker = 'o')
plt.plot(x, Jz[10][2,:], 'r--',marker = '*')
plt.axvline(x[2], ls='--', color='k')
plt.axvline(x[-3], ls='--', color='k')
plt.plot(y, Jx[7][:,3], 'b-', marker = 'o')
plt.axvline(y[3], ls='--', color='k')
plt.axvline(y[-4], ls='--', color='k')

plt.show()"""
plt.show()
6 changes: 3 additions & 3 deletions diagnostics/whistlerwave/plot_anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Dx = 0.1


quantity_name = 'By'
quantity_name = 'Bx'
fixed_index = 0
ny = 1

Expand Down Expand Up @@ -89,7 +89,7 @@ def update(frame):

w = (k**2 /2) *(np.sqrt(1+4/k**2) + 1)

expected_value = 1e-7 * np.cos(k * x -w * times[frame] + 0.5488135)
expected_value = 1e-7 * np.cos(k * x + w * times[frame] + 0.5488135)

plt.clf()
plt.plot(x, quantities[quantity_name][frame, fixed_index, :], color='blue', marker = 'x', markersize=3) # t,y,x
Expand All @@ -112,7 +112,7 @@ def update(frame):
#plt.axvline(x[-2]-Dx/2, ls='--', color='k')

fig = plt.figure(figsize=(8, 6))
ani = FuncAnimation(fig, update, frames=len(times), interval=100)
ani = FuncAnimation(fig, update, frames=len(times), interval=10)

# Define a function for manually stepping through the frames
def onclick(event):
Expand Down
Loading

0 comments on commit 2daa8af

Please sign in to comment.