omega, v, err = solver.iterate_solver(Ns, verbose=True, tol=1e-8) # Normalize eigenmodes y = np.vstack([ system.result["dvx"].real, system.result["dvx"].imag, system.result["dvz"].real, system.result["dvz"].imag, ]) val = np.max(np.abs(y)) for key in system.variables: system.result[key] /= val # Save system pickle object save_system(system, "./khi_hydro_delta.p") from psecas import write_athena # Write files for loading into Athena write_athena( system, Nz=256, Lz=2.0, path="./", name="khi_hydro_delta", ) # Print out some information Lx = 2 * np.pi / system.kx print('')
from psecas.systems.kh_uniform import KelvinHelmholtzUniform """ This example shows how the eigenmodes can be stored in text format which can be loaded into the MHD code Athena (Stone, J. et al, 2008). It also shows how to save a system using Python's pickle package. """ # Set up a grid grid = FourierGrid(N=64, zmin=0, zmax=2) # Set up the system of equations kx = 4.627762711864407 # kx = 2*np.pi system = KelvinHelmholtzUniform(grid, beta=1e3, nu=1e-2, kx=kx) # Set up a solver solver = Solver(grid, system) # Iteratively solve Ns = np.hstack((np.arange(1, 5) * 32, np.arange(3, 12) * 64)) solver.iterate_solver(Ns, verbose=True, tol=1e-10) # Write files for loading into Athena write_athena(system, Nz=256, Lz=2.0) # Write directly to the Athena directory write_athena(system, Nz=256, Lz=2.0, path='/Users/berlok/codes/athena/bin/') save_system(system, '/Users/berlok/codes/athena/bin/kh-visc.p')
solver.keep_result(omega, vec * np.exp(-1j * phi), mode=0) # Normalize eigenmodes y = np.vstack([ system.result["dvx"].real, system.result["dvx"].imag, system.result["dvz"].real, system.result["dvz"].imag, ]) val = np.max(np.abs(y)) for key in system.variables: system.result[key] /= val # Save system pickle object save_system(system, "./khi_nu.p") # Print out some information Lx = 2 * np.pi / system.kx print('') print('Eigenvalue is:', omega) print('Lx should be:', Lx) # Make a plot plt.figure(1) plt.plot(kxmax, omega.real, "+") plot_solution(system, filename='./khi_nu.pdf') # Write files for loading into Athena s = system c_dic = {}
omega, v, err = solver.iterate_solver(Ns, verbose=True, tol=1e-10) # Normalize eigenmodes y = np.vstack([ system.result["dvx"].real, system.result["dvx"].imag, system.result["dvz"].real, system.result["dvz"].imag, ]) val = np.max(np.abs(y)) for key in system.variables: system.result[key] /= val # Save system pickle object save_system(system, "./khi_hydro.p") # Print out some information Lx = 2 * np.pi / system.kx print('') print('Eigenvalue is:', omega) print('Lx should be:', Lx) # Make a plot plt.figure(1) plt.plot(kxmax, omega.real, "+") plot_solution(system, filename='./khi_hydro.pdf') # Write files for loading into Athena s = system c_dic = {}
(a, b) = golden_section(f, 3.512295, 3.513135, tol=1e-5) # Create initial conditions for Athena simulation if False: from psecas import write_athena, save_system kxmax = 3.5128286141291243 grid = FourierGrid(N=64, zmin=0.0, zmax=2.0) system = KelvinHelmholtzHydroOnly(grid, u0=1.0, delta=1.0, kx=kxmax) solver = Solver(grid, system) Ns = np.hstack((np.arange(1, 5) * 16, np.arange(3, 12) * 32)) omega, v, err = solver.iterate_solver(Ns, verbose=False, tol=1e-6) # Write files for loading into Athena # write_athena(system, Nz=256, Lz=2.0) # Write directly to the Athena directory write_athena( system, Nz=256, Lz=2.0, path='/Users/berlok/codes/athena/bin/' ) save_system(system, '/Users/berlok/codes/athena/bin/kh-with-delta.p') plt.figure(1) plt.plot(kxmax, omega.real, '+') Lx = 2 * np.pi / system.kx print(Lx)
omega, v, err = solver.iterate_solver(Ns, verbose=True, tol=1e-8) # Normalize eigenmodes y = np.vstack([ system.result["dvx"].real, system.result["dvx"].imag, system.result["dvz"].real, system.result["dvz"].imag, ]) val = np.max(np.abs(y)) for key in system.variables: system.result[key] /= val # Save system pickle object save_system(system, "./khi_mhd_beta5.p") # Print out some information Lx = 2 * np.pi / system.kx print('') print('Eigenvalue is:', omega) print('Lx should be:', Lx) # Make a plot plt.figure(1) plt.plot(kxmax, omega.real, "+") plot_solution(system, filename='./khi_mhd_beta5.pdf') # Write files for loading into Athena s = system c_dic = {}