def plot(opt): """Plot just the stability criteria.""" import matplotlib.pyplot as plt Config = FloxConfiguration.fromfile(opt.configuration) Writer = HDF5Writer(opt.filename) fig = plt.figure(figsize=(11, 8.5)) for i, system in enumerate("stable critical unstable".split()): MVC = MultiViewController(fig, 3, 3, wspace=0.6, hspace=0.4) System = NDSystem2D.from_params(Config["system"]) Writer.read(System, "{}-{:d}".format(system, opt.mode)) print(System) MVC[0, i] = EvolutionViewStabilityTest("Temperature", opt.mode, System.nz // 3) MVC[1, i] = EvolutionViewStabilityTest("Vorticity", opt.mode, System.nz // 3) MVC[2, i] = EvolutionViewStabilityTest("Stream", opt.mode, System.nz // 3) MVC.views[0].ax.text(0.5, 1.25, system.capitalize(), transform=MVC.views[0].ax.transAxes, ha='center') MVC.update(System) fig.savefig(opt.plot, dpi=300)
def run(opt): """Run the systems.""" Config = FloxConfiguration.fromfile(opt.configuration) Writer = HDF5Writer(opt.filename) iterations = int(Config["iterations"]) chunks = Config["system.nt"] - 1 Stable = initialize(Config, opt) Stable.Rayleigh = critical_raleigh_number(Stable, opt.mode) * 0.8 print(Stable) LE_stable = LinearEvolverProcess(Stable, Writer, ('stable-{:d}'.format(opt.mode),), (Config['time'], iterations, chunks)) LE_stable.name = "Stable-LinearEvolver" LE_stable.start() Critical = initialize(Config, opt) Critical.Rayleigh = critical_raleigh_number(Critical, opt.mode) print(Critical) LE_critical = LinearEvolverProcess(Critical, Writer, ('critical-{:d}'.format(opt.mode),), (Config['time'], iterations, chunks)) LE_critical.name = "Critical-LinearEvolver" LE_critical.start() Unstable = initialize(Config, opt) Unstable.Rayleigh = critical_raleigh_number(Unstable, opt.mode) * 1.2 print(Unstable) LE_unstable = LinearEvolverProcess(Unstable, Writer, ('unstable-{:d}'.format(opt.mode),), (Config['time'], iterations, chunks)) LE_unstable.name = "Unstable-LinearEvolver" LE_unstable.start() LE_stable.join() LE_critical.join() LE_unstable.join()
def analyze(opt): """Analyze the data, showing the late time values of the stability criterion.""" import matplotlib.pyplot as plt Config = FloxConfiguration.fromfile(opt.configuration) Writer = HDF5Writer(opt.filename) for i, system in enumerate("stable critical unstable".split()): System = NDSystem2D.from_params(Config["system"]) Writer.read(System, "{}-{:d}".format(system, opt.mode)) print(System) print(System.diagnostic_string()) print(System.nz // 3) for array in System.list_arrays(): if array == "Time": continue data = System.engine[array][System.nz // 3, 1] ln_data = np.log(np.abs(data)) print("{:15.15s}: {}".format(array, data[-5:])) print("{:15.15s}: {}".format(array, np.diff(ln_data)[-4:]))
def animate(opt): """Animate the data sets.""" from astropy.utils.console import ProgressBar import matplotlib matplotlib.rcParams['text.usetex'] = False import matplotlib.pyplot as plt Config = FloxConfiguration.fromfile(opt.configuration) Writer = HDF5Writer(opt.filename) fig = plt.figure(figsize=(11, 8.5)) Plots = [] for i, system in enumerate("stable critical unstable".split()): MVC = MultiViewController(fig, 3, 3, wspace=0.6, hspace=0.4) System = NDSystem2D.from_params(Config["system"]) Writer.read(System, "{}-{:d}".format(system, opt.mode)) print(System) MVC[0, i] = EvolutionViewStabilityTest("Temperature", opt.mode, System.nz // 3) MVC[1, i] = EvolutionViewStabilityTest("Vorticity", opt.mode, System.nz // 3) MVC[2, i] = EvolutionViewStabilityTest("Stream", opt.mode, System.nz // 3) System.it = 2 MVC.update(System) Plots.append((MVC, System)) with ProgressBar(System.nit - 2) as pbar: def update(i): """Animation""" for MVC, System in Plots: System.it = i + 2 MVC.update(System) pbar.update(i) anim = animation.FuncAnimation(fig, update, frames=int(System.nit) - 2, repeat=False) # anim.save(opt.movie, writer='ffmpeg') plt.show()
def analyze(opt): """Analyze the data, showing the late time values of the stability criterion.""" import matplotlib.pyplot as plt Config = FloxConfiguration.fromfile(opt.configuration) Writer = HDF5Writer(opt.filename) for i,system in enumerate("stable critical unstable".split()): System = NDSystem2D.from_params(Config["system"]) Writer.read(System, "{}-{:d}".format(system, opt.mode)) print(System) print(System.diagnostic_string()) print(System.nz//3) for array in System.list_arrays(): if array == "Time": continue data = System.engine[array][System.nz//3, 1] ln_data = np.log(np.abs(data)) print("{:15.15s}: {}".format(array, data[-5:])) print("{:15.15s}: {}".format(array, np.diff(ln_data)[-4:]))
def plot(opt): """Plot just the stability criteria.""" import matplotlib.pyplot as plt Config = FloxConfiguration.fromfile(opt.configuration) Writer = HDF5Writer(opt.filename) fig = plt.figure(figsize=(11, 8.5)) for i,system in enumerate("stable critical unstable".split()): MVC = MultiViewController(fig, 3, 3, wspace=0.6, hspace=0.4) System = NDSystem2D.from_params(Config["system"]) Writer.read(System, "{}-{:d}".format(system, opt.mode)) print(System) MVC[0,i] = EvolutionViewStabilityTest("Temperature", opt.mode, System.nz//3) MVC[1,i] = EvolutionViewStabilityTest("Vorticity", opt.mode, System.nz//3) MVC[2,i] = EvolutionViewStabilityTest("Stream", opt.mode, System.nz//3) MVC.views[0].ax.text(0.5, 1.25, system.capitalize(), transform=MVC.views[0].ax.transAxes, ha='center') MVC.update(System) fig.savefig(opt.plot, dpi=300)
def run(opt): """Run the systems.""" Config = FloxConfiguration.fromfile(opt.configuration) Writer = HDF5Writer(opt.filename) iterations = int(Config["iterations"]) chunks = Config["system.nt"] - 1 Stable = initialize(Config, opt) Stable.Rayleigh = critical_raleigh_number(Stable, opt.mode) * 0.8 print(Stable) LE_stable = LinearEvolverProcess(Stable, Writer, ('stable-{:d}'.format(opt.mode), ), (Config['time'], iterations, chunks)) LE_stable.name = "Stable-LinearEvolver" LE_stable.start() Critical = initialize(Config, opt) Critical.Rayleigh = critical_raleigh_number(Critical, opt.mode) print(Critical) LE_critical = LinearEvolverProcess(Critical, Writer, ('critical-{:d}'.format(opt.mode), ), (Config['time'], iterations, chunks)) LE_critical.name = "Critical-LinearEvolver" LE_critical.start() Unstable = initialize(Config, opt) Unstable.Rayleigh = critical_raleigh_number(Unstable, opt.mode) * 1.2 print(Unstable) LE_unstable = LinearEvolverProcess(Unstable, Writer, ('unstable-{:d}'.format(opt.mode), ), (Config['time'], iterations, chunks)) LE_unstable.name = "Unstable-LinearEvolver" LE_unstable.start() LE_stable.join() LE_critical.join() LE_unstable.join()
def animate(opt): """Animate the data sets.""" from astropy.utils.console import ProgressBar import matplotlib matplotlib.rcParams['text.usetex'] = False import matplotlib.pyplot as plt Config = FloxConfiguration.fromfile(opt.configuration) Writer = HDF5Writer(opt.filename) fig = plt.figure(figsize=(11, 8.5)) Plots = [] for i,system in enumerate("stable critical unstable".split()): MVC = MultiViewController(fig, 3, 3, wspace=0.6, hspace=0.4) System = NDSystem2D.from_params(Config["system"]) Writer.read(System, "{}-{:d}".format(system, opt.mode)) print(System) MVC[0,i] = EvolutionViewStabilityTest("Temperature", opt.mode, System.nz//3) MVC[1,i] = EvolutionViewStabilityTest("Vorticity", opt.mode, System.nz//3) MVC[2,i] = EvolutionViewStabilityTest("Stream", opt.mode, System.nz//3) System.it = 2 MVC.update(System) Plots.append((MVC, System)) with ProgressBar(System.nit-2) as pbar: def update(i): """Animation""" for MVC, System in Plots: System.it = i+2 MVC.update(System) pbar.update(i) anim = animation.FuncAnimation(fig, update, frames=int(System.nit)-2, repeat=False) # anim.save(opt.movie, writer='ffmpeg') plt.show()
from matplotlib.colors import SymLogNorm def filename(extension=".yml", base=None): """Filenames related to this file!""" directory = os.path.dirname(__file__) base = os.path.splitext(os.path.basename(__file__))[0] if base is None else base return os.path.join(directory, base + extension) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('base', nargs="?", default='linear_op') opt = parser.parse_args() rcParams['text.usetex'] = False ipydb() Config = FloxConfiguration.fromfile(filename(".yml", base=opt.base)) System = NDSystem2D.from_params(Config["system"]) Writer = HDF5Writer(filename(".hdf5", base=opt.base)) Writer.read(System, 'main') System.it = 1 print(System) print(System.diagnostic_string()) fig = plt.figure(figsize=(10, 10)) MVC = MultiViewController(fig, 2, 2) MVC[0,0] = GridView("Temperature") MVC[1,0] = EvolutionViewStabilityTest("Temperature", 1, 33) MVC[0,1] = GridView("Vorticity", cmap='Blues', vmin=-1e-7, vmax=1e-7, norm=SymLogNorm(1e-9), perturbed=True) MVC[1,1] = EvolutionViewStabilityTest("Vorticity", 1, 33) MVC.update(System) plt.show()
from astropy.utils.console import ProgressBar import multiprocessing as mp import matplotlib.pyplot as plt import matplotlib from matplotlib import animation from Flox.process.evolver import EvolverProcessing from pyshell.util import ipydb, askip if __name__ == '__main__': mode = 1 Config = FloxConfiguration.fromfile(os.path.join(os.path.dirname(__file__),"linear_op.yml")) System = NDSystem2D.from_params(Config["system"]) System.Rayleigh = 1e6 System.Prandtl = 0.5 System.nz = 100 system.nn = 50 System.aspect = 3 System.nt = 500 System.initialize_arrays() stable_temperature_gradient(System) for m in range(1, system.nn//10): single_mode_linear_perturbation(System, m, eps=5e-3) # single_mode_linear_perturbation(System, 1, eps=5e-1) matplotlib.rcParams['text.usetex'] = False MVC = setup_movie(plt.figure(figsize=(10, 10))) MVC.update(System)
import os, os.path import queue from astropy.utils.console import ProgressBar import multiprocessing as mp import matplotlib.pyplot as plt import matplotlib from matplotlib import animation from Flox.process.evolver import EvolverProcessing from pyshell.util import ipydb, askip if __name__ == '__main__': mode = 1 Config = FloxConfiguration.fromfile( os.path.join(os.path.dirname(__file__), "linear_op.yml")) System = NDSystem2D.from_params(Config["system"]) System.Rayleigh = 1e6 System.Prandtl = 0.5 System.nz = 100 system.nn = 50 System.aspect = 3 System.nt = 500 System.initialize_arrays() stable_temperature_gradient(System) for m in range(1, system.nn // 10): single_mode_linear_perturbation(System, m, eps=5e-3) # single_mode_linear_perturbation(System, 1, eps=5e-1) matplotlib.rcParams['text.usetex'] = False MVC = setup_movie(plt.figure(figsize=(10, 10))) MVC.update(System)
def filename(extension=".yml", base=None): """Filenames related to this file!""" directory = os.path.dirname(__file__) base = os.path.splitext(os.path.basename(__file__))[0] if base is None else base return os.path.join(directory, base + extension) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('base', nargs="?", default='nonlinear') parser.add_argument('-s','--stability', type=int, help='Show stability plots') opt = parser.parse_args() rcParams['text.usetex'] = False ipydb() Config = FloxConfiguration.fromfile(filename(".yml", base="linear_op")) System = NDSystem2D.from_params(Config["system"]) Writer = HDF5Writer(filename(".hdf5", base=opt.base)) Writer.read(System, 'nonlinear') print(System) fig = plt.figure(figsize=(6,3.5)) MVC = setup_movie(fig, kwargs=[dict(cmap="hot", interpolation='bilinear')]) System.it = 2 MVC.update(System) System.infer_iteration() with ProgressBar(System.it) as PBar: def update(i): System.it = i MVC.update(System) PBar.update(i)
base = os.path.splitext( os.path.basename(__file__))[0] if base is None else base return os.path.join(directory, base + extension) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('base', nargs="?", default='nonlinear') parser.add_argument('-s', '--stability', type=int, help='Show stability plots') opt = parser.parse_args() rcParams['text.usetex'] = False ipydb() Config = FloxConfiguration.fromfile(filename(".yml", base="linear_op")) System = NDSystem2D.from_params(Config["system"]) Writer = HDF5Writer(filename(".hdf5", base=opt.base)) Writer.read(System, 'nonlinear') print(System) fig = plt.figure(figsize=(6, 3.5)) MVC = setup_movie(fig, kwargs=[dict(cmap="hot", interpolation='bilinear')]) System.it = 2 MVC.update(System) System.infer_iteration() with ProgressBar(System.it) as PBar: def update(i): System.it = i MVC.update(System) PBar.update(i)
from Flox.input import FloxConfiguration from Flox.nonlinear import NonlinearEvolver from Flox.io import HDF5Writer from Flox.ic import stable_temperature_gradient, standard_nonlinear_perturbation, single_mode_linear_perturbation from pyshell.util import ipydb, askip def filename(extension=".yml"): """docstring for filename""" base = os.path.splitext(__file__)[0] return base + extension if __name__ == '__main__': Config = FloxConfiguration.fromfile(filename(".yml")) System = NDSystem2D.from_params(Config["system"]) chunks = System.nt - System.it - 1 stable_temperature_gradient(System) single_mode_linear_perturbation(System, 1) print(System) print(System.diagnostic_string()) NLE = NonlinearEvolver.from_system(System) NLE.evolve_system(System, Config['time'], int(Config["iterations"]), chunks) print("") print(System) print(System.diagnostic_string()) Writer = HDF5Writer(filename(".hdf5")) Writer.write(System, 'main')
def filename(extension=".yml", base=None): """Filenames related to this file!""" directory = os.path.dirname(__file__) base = os.path.splitext( os.path.basename(__file__))[0] if base is None else base return os.path.join(directory, base + extension) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('base', nargs="?", default='linear_op') opt = parser.parse_args() rcParams['text.usetex'] = False ipydb() Config = FloxConfiguration.fromfile(filename(".yml", base=opt.base)) System = NDSystem2D.from_params(Config["system"]) Writer = HDF5Writer(filename(".hdf5", base=opt.base)) Writer.read(System, 'main') System.it = 1 print(System) print(System.diagnostic_string()) fig = plt.figure(figsize=(10, 10)) MVC = MultiViewController(fig, 2, 2) MVC[0, 0] = GridView("Temperature") MVC[1, 0] = EvolutionViewStabilityTest("Temperature", 1, 33) MVC[0, 1] = GridView("Vorticity", cmap='Blues', vmin=-1e-7, vmax=1e-7, norm=SymLogNorm(1e-9),
from Flox.input import FloxConfiguration from Flox.linear import LinearEvolver from Flox.io import HDF5Writer from Flox.ic import stable_temperature_gradient, standard_linear_perturbation, single_mode_linear_perturbation from pyshell.util import ipydb def filename(extension=".yml"): """docstring for filename""" base = os.path.splitext(__file__)[0] return base + extension if __name__ == '__main__': ipydb() Config = FloxConfiguration.fromfile(filename(".yml")) System = NDSystem2D.from_params(Config["system"]) iterations = int(Config["iterations"]) chunks = System.nt - System.it - 1 Writer = HDF5Writer(filename(".hdf5")) System.Rayleigh = 779.27 stable_temperature_gradient(System) single_mode_linear_perturbation(System, mode=1) print(System) print(System.diagnostic_string()) LE = LinearEvolver.from_system(System) LE.step(LE.delta_time()) LE.evolve_system(System, Config['time'], iterations, chunks) print("") print(System) print(System.diagnostic_string())
import matplotlib.pyplot as plt import matplotlib def filename(extension=".yml", base=None): """Filenames related to this file!""" directory = os.path.dirname(__file__) base = os.path.splitext(os.path.basename(__file__))[0] if base is None else base return os.path.join(directory, base + extension) if __name__ == '__main__': ipydb() plt.ion() Config = FloxConfiguration.fromfile(filename(".yml", "nonlinear_op")) System = NDSystem2D.from_params(Config["system"]) LSystem = NDSystem2D.from_params(Config["system"]) iterations = int(Config["iterations"]) chunks = System.nt - System.it - 1 stable_temperature_gradient(System) LSystem.read_packet(System.create_packet()) print("INITIAL") print(System) print(System.diagnostic_string()) LE = LinearEvolver.from_system(LSystem) LE.read_packet(LSystem.create_packet()) NLE = NonlinearEvolver.from_system(System) NLE.read_packet(System.create_packet())