From cd88daafaf6a6a7b61e4b79529d649cd0c1864e8 Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Fri, 2 Aug 2024 17:15:09 +0200 Subject: [PATCH] quicker alf --- pyphare/pyphare/pharesee/run/run.py | 16 ++++++++++++---- tests/functional/alfven_wave/alfven_wave1d.py | 13 ++++++++----- tests/functional/conservation/conserv.py | 1 - tests/functional/dispersion/dispersion.py | 1 - tests/functional/ionIonBeam/ion_ion_beam1d.py | 4 +--- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/pyphare/pyphare/pharesee/run/run.py b/pyphare/pyphare/pharesee/run/run.py index e791c018e..c965696f0 100644 --- a/pyphare/pyphare/pharesee/run/run.py +++ b/pyphare/pyphare/pharesee/run/run.py @@ -33,8 +33,9 @@ class Run: - def __init__(self, path): + def __init__(self, path, default_time=None): self.path = path + self.default_time_ = default_time import glob self.available_diags = glob.glob(os.path.join(self.path, "*.h5")) @@ -69,7 +70,7 @@ def _get(self, hierarchy, time, merged, interp): """ if merged: domain = self.GetDomainSize() - dl = self.GetDl() + dl = self.GetDl(time=time) # assumes all qties in the hierarchy have the same ghost width # so take the first patch data of the first patch of the first level.... @@ -248,8 +249,15 @@ def GetDl(self, level="finest", time=None): data_file = h5py.File(h5_filename, "r") - if time is None: - time = float(list(data_file[h5_time_grp_key].keys())[0]) + def _get_time(): + if time: + return time + if self.default_time_: + return self.default_time_ + self.default_time_ = float(list(data_file[h5_time_grp_key].keys())[0]) + return self.default_time_ + + time = _get_time() hier = self._get_hierarchy(time, h5_filename.split("/")[-1]) diff --git a/tests/functional/alfven_wave/alfven_wave1d.py b/tests/functional/alfven_wave/alfven_wave1d.py index 2c194d0cb..50c49350b 100644 --- a/tests/functional/alfven_wave/alfven_wave1d.py +++ b/tests/functional/alfven_wave/alfven_wave1d.py @@ -4,7 +4,7 @@ from pyphare.simulator.simulator import Simulator from pyphare.pharesee.hierarchy.fromh5 import get_times_from_h5 from pyphare.pharesee.run import Run -from pyphare.pharesee.hierarchy.hierarchy_utils import flat_finest_field + from tests.diagnostic import all_timestamps @@ -23,11 +23,14 @@ def config(): # configure the simulation + final_time = 1000 + time_step_nbr = 100000 + sim = ph.Simulation( smallest_patch_size=50, largest_patch_size=50, - time_step_nbr=100000, # number of time steps (not specified if time_step and final_time provided) - final_time=1000, # simulation final time (not specified if time_step and time_step_nbr provided) + time_step_nbr=time_step_nbr, # number of time steps (not specified if time_step and final_time provided) + final_time=final_time, # simulation final time (not specified if time_step and time_step_nbr provided) boundary_types="periodic", # boundary condition, string or tuple, length == len(cell) == len(dl) cells=1000, # integer or tuple length == dimension dl=1, # mesh size of the root level, float or tuple @@ -88,7 +91,7 @@ def vthz(x): ph.ElectronModel(closure="isothermal", Te=0.0) - timestamps = all_timestamps(sim) + timestamps = [0, int(final_time / 2), final_time] for quantity in ["E", "B"]: ph.ElectromagDiagnostics(quantity=quantity, write_timestamps=timestamps) @@ -145,7 +148,7 @@ def main(): if cpp.mpi_rank() == 0: vphi, t, phi, a, k = phase_speed(".", 0.01, 1000) - r = Run(".") + r = Run(".", 0) t = get_times_from_h5("EM_B.h5") fig, ax = plt.subplots(figsize=(9, 5), nrows=1) diff --git a/tests/functional/conservation/conserv.py b/tests/functional/conservation/conserv.py index 0d0e7724c..49f526410 100644 --- a/tests/functional/conservation/conserv.py +++ b/tests/functional/conservation/conserv.py @@ -5,7 +5,6 @@ from pyphare.pharesee.run import Run from pyphare.pharesee.hierarchy.fromh5 import get_times_from_h5 -import os import numpy as np from glob import glob diff --git a/tests/functional/dispersion/dispersion.py b/tests/functional/dispersion/dispersion.py index 39e751c79..63bfd16a3 100644 --- a/tests/functional/dispersion/dispersion.py +++ b/tests/functional/dispersion/dispersion.py @@ -4,7 +4,6 @@ from pyphare.simulator.simulator import Simulator -import matplotlib.pyplot as plt import matplotlib as mpl import numpy as np diff --git a/tests/functional/ionIonBeam/ion_ion_beam1d.py b/tests/functional/ionIonBeam/ion_ion_beam1d.py index 8b51656f5..75d2f9faa 100644 --- a/tests/functional/ionIonBeam/ion_ion_beam1d.py +++ b/tests/functional/ionIonBeam/ion_ion_beam1d.py @@ -5,15 +5,13 @@ from pyphare.pharesee.hierarchy.fromh5 import get_times_from_h5 from pyphare.pharesee.run import Run -from tests.diagnostic import all_timestamps import matplotlib.pyplot as plt import matplotlib as mpl import numpy as np from scipy.optimize import curve_fit from scipy.signal import find_peaks -from pyphare.pharesee import plotting -from pathlib import Path + mpl.use("Agg")