diff --git a/src/amr/multiphysics_integrator.hpp b/src/amr/multiphysics_integrator.hpp index 521b244327..7f61e243be 100644 --- a/src/amr/multiphysics_integrator.hpp +++ b/src/amr/multiphysics_integrator.hpp @@ -645,20 +645,6 @@ namespace solver - // bool existloadBalancererOnRange_(int coarsestLevel, int finestLevel) - // { - // for (auto iLevel = coarsestLevel; iLevel <= finestLevel; ++iLevel) - // { - // if (levelDescriptors_[iLevel].loadBalancerIndex != LevelDescriptor::NOT_SET) - // { - // return true; - // } - // } - // return false; - // } - - - bool existModelOnRange_(int coarsestLevel, int finestLevel) { bool hasModel = true; diff --git a/src/amr/wrappers/integrator.hpp b/src/amr/wrappers/integrator.hpp index c8e65aa3c0..609499ee1e 100644 --- a/src/amr/wrappers/integrator.hpp +++ b/src/amr/wrappers/integrator.hpp @@ -29,21 +29,29 @@ namespace PHARE::amr template class Integrator { - int static constexpr rebalance_coarsest_default = 0; - std::size_t static constexpr rebalance_coarsest_every_default = 1000; + int static constexpr rebalance_coarsest_every_default = 1000; bool static _rebalance_coarsest(initializer::PHAREDict const& dict) { - return initializer::dict_get(dict, "simulation/advanced/integrator/rebalance_coarsest", - rebalance_coarsest_default) + return initializer::dict_get(dict, "simulation/advanced/integrator/rebalance_coarsest", 0) > 0; } - std::size_t static _rebalance_coarsest_every(initializer::PHAREDict const& dict) + bool static _rebalance_coarsest_on_init(initializer::PHAREDict const& dict) { return initializer::dict_get(dict, - "simulation/advanced/integrator/rebalance_coarsest_every", - rebalance_coarsest_every_default); + "simulation/advanced/integrator/rebalance_coarsest_on_init", 0) + > 0; + } + + std::size_t static _rebalance_coarsest_every(initializer::PHAREDict const& dict) + { + auto in + = initializer::dict_get(dict, "simulation/advanced/integrator/rebalance_coarsest_every", + rebalance_coarsest_every_default); + if (in < 0) + throw std::runtime_error("rebalance_coarsest_every must be positive"); + return static_cast(in); } bool static _is_tagging_refinement(initializer::PHAREDict const& dict) @@ -53,8 +61,6 @@ class Integrator == std::string{"auto"}; } - - public: static constexpr std::size_t dimension = _dimension; @@ -65,6 +71,11 @@ class Integrator or (time_step_idx > 0 and rebalance_coarsest_every > 0 and time_step_idx % rebalance_coarsest_every == 0)); + PHARE_LOG_LINE_STR(is_tagging_refinement + << " " << time_step_idx << " " << rebalance_coarsest << " " + << rebalance_coarsest_on_init << " " << rebalance_coarsest_every << " " + << rebalance_coarsest_now); + auto new_time = timeRefIntegrator_->advanceHierarchy(dt, rebalance_coarsest_now); ++time_step_idx; return new_time; @@ -81,8 +92,8 @@ class Integrator private: bool is_tagging_refinement = false; - bool rebalance_coarsest = true; - bool rebalance_coarsest_on_init = true; + bool rebalance_coarsest = false; + bool rebalance_coarsest_on_init = false; std::size_t time_step_idx = 0; std::size_t const rebalance_coarsest_every = rebalance_coarsest_every_default; @@ -115,6 +126,7 @@ Integrator<_dimension>::Integrator( double startTime, double endTime) : is_tagging_refinement{_is_tagging_refinement(dict)} , rebalance_coarsest{_rebalance_coarsest(dict)} + , rebalance_coarsest_on_init{_rebalance_coarsest_on_init(dict)} , rebalance_coarsest_every{_rebalance_coarsest_every(dict)} { loadBalancer->setSAMRAI_MPI( diff --git a/tests/functional/harris/harris_2d.py b/tests/functional/harris/harris_2d.py index 1c0075a3cd..fcf2031084 100644 --- a/tests/functional/harris/harris_2d.py +++ b/tests/functional/harris/harris_2d.py @@ -1,7 +1,10 @@ #!/usr/bin/env python3 +from datetime import datetime + import pyphare.pharein as ph from pyphare.simulator.simulator import Simulator, startMPI +from pyphare.pharesee.run import Run import numpy as np import matplotlib.pyplot as plt @@ -14,27 +17,37 @@ cpp = cpp_lib() startMPI() -diag_outputs = "phare_outputs/test/harris/2d" -from datetime import datetime +diag_outputs0 = "phare_outputs/balanceL1/harris/2d" +diag_outputs1 = "phare_outputs/balanceL1/harris/2d_rebal" + +time_step = 0.001 +time_step_nbr = 30000 +final_time = time_step * time_step_nbr +# array([10., 20., 30., 40., 50.]) +timestamps = np.arange( + 0, final_time + time_step, time_step * time_step_nbr / 5, dtype=float +)[1:] -def config(): + +def config(diag_dig, **kwargs): sim = ph.Simulation( + dl=(0.2, 0.2), + cells=(100, 100), + time_step=time_step, + time_step_nbr=time_step_nbr, smallest_patch_size=15, largest_patch_size=25, - time_step_nbr=1000, - time_step=0.001, - # boundary_types="periodic", - cells=(100, 100), - dl=(0.2, 0.2), - refinement_boxes={}, + max_nbr_levels=2, + refinement="tagging", hyper_resistivity=0.001, resistivity=0.001, diag_options={ "format": "phareh5", - "options": {"dir": diag_outputs, "mode": "overwrite"}, + "options": {"dir": diag_dig, "mode": "overwrite"}, }, - strict=True, + restart_options=dict(dir=diag_dig, mode="overwrite", timestamps=timestamps), + **kwargs, ) def density(x, y): @@ -93,31 +106,19 @@ def T(x, y): assert np.all(temp > 0) return temp - def vx(x, y): - return 0.0 - - def vy(x, y): + def vxyz(x, y): return 0.0 - def vz(x, y): - return 0.0 - - def vthx(x, y): - return np.sqrt(T(x, y)) - - def vthy(x, y): - return np.sqrt(T(x, y)) - - def vthz(x, y): + def vthxyz(x, y): return np.sqrt(T(x, y)) vvv = { - "vbulkx": vx, - "vbulky": vy, - "vbulkz": vz, - "vthx": vthx, - "vthy": vthy, - "vthz": vthz, + "vbulkx": vxyz, + "vbulky": vxyz, + "vbulkz": vxyz, + "vthx": vthxyz, + "vthy": vthxyz, + "vthz": vthxyz, "nbr_part_per_cell": 100, } @@ -127,49 +128,73 @@ def vthz(x, y): bz=bz, protons={"charge": 1, "density": density, **vvv, "init": {"seed": 12334}}, ) - ph.ElectronModel(closure="isothermal", Te=0.0) - - dt = 10 * sim.time_step - nt = sim.final_time / dt + 1 - timestamps = dt * np.arange(nt) - for quantity in ["E", "B"]: ph.ElectromagDiagnostics( quantity=quantity, write_timestamps=timestamps, compute_timestamps=timestamps, ) - + ph.global_vars.sim = None return sim -def get_time(path, time, datahier=None): - time = "{:.10f}".format(time) - from pyphare.pharesee.hierarchy import hierarchy_from - - datahier = hierarchy_from(h5_filename=path + "/EM_E.h5", time=time, hier=datahier) - datahier = hierarchy_from(h5_filename=path + "/EM_B.h5", time=time, hier=datahier) - return datahier - - -def post_advance(new_time): +def plot(diag_dir): if cpp.mpi_rank() == 0: - print(f"running tests at time {new_time}") - from tests.simulator.test_advance import AdvanceTestBase - - test = AdvanceTestBase() - test.base_test_overlaped_fields_are_equal( - get_time(diag_outputs, new_time), new_time - ) - print(f"tests passed") + run = Run(diag_dir) + for time in timestamps: + run.GetDivB(time).plot( + filename=f"{diag_dir}/harris_divb_t{time}.png", plot_patches=True + ) + run.GetB(time).plot( + filename=f"{diag_dir}/harris_bx_t{time}.png", + qty="Bx", + plot_patches=True, + ) + run.GetB(time).plot( + filename=f"{diag_dir}/harris_by_t{time}.png", + qty="By", + plot_patches=True, + ) + run.GetB(time).plot( + filename=f"{diag_dir}/harris_bz_t{time}.png", + qty="Bz", + plot_patches=True, + ) + + run.GetJ(time).plot( + filename=f"{diag_dir}/harris_Jz_t{time}.png", + qty="Jz", + plot_patches=True, + vmin=-2, + vmax=2, + ) + + cpp.mpi_barrier() + + +def run(sim, diag_dir): + ph.global_vars.sim = sim + + Simulator(sim).run().reset() + + plot(diag_dir) + + ph.global_vars.sim = None def main(): - s = Simulator(config(), post_advance=post_advance) - s.initialize() - post_advance(0) - s.run() + sim0 = config(diag_outputs0) + sim1 = config( + diag_outputs1, + advanced={ + "integrator/rebalance_coarsest": 1, + "integrator/rebalance_coarsest_every": 5000, + "integrator/flexible_load_tolerance": 0.5, + }, + ) + # run(sim0, diag_outputs0) + run(sim1, diag_outputs1) if __name__ == "__main__": diff --git a/tests/simulator/__init__.py b/tests/simulator/__init__.py index 56ca9e9d91..b2a29eef8c 100644 --- a/tests/simulator/__init__.py +++ b/tests/simulator/__init__.py @@ -1,7 +1,10 @@ import unittest + +from copy import deepcopy + + from datetime import datetime import pyphare.pharein as ph, numpy as np -from pyphare.pharein import ElectronModel def parse_cli_args(pop_from_sys=True): @@ -30,32 +33,35 @@ def basicSimulatorArgs(dim: int, interp: int, **kwargs): from pyphare.pharein.simulation import valid_refined_particle_nbr from pyphare.pharein.simulation import check_patch_size + args = deepcopy(kwargs) + cells = kwargs.get("cells", [20 for i in range(dim)]) if not isinstance(cells, (list, tuple)): cells = [cells] * dim _, smallest_patch_size = check_patch_size(dim, interp_order=interp, cells=cells) - dl = [1.0 / v for v in cells] - b0 = [[3] * dim, [8] * dim] + args = { "interp_order": interp, "smallest_patch_size": smallest_patch_size, "largest_patch_size": [20] * dim, "time_step_nbr": 1000, - "final_time": 1.0, + "time_step": 0.001, "boundary_types": ["periodic"] * dim, "cells": cells, - "dl": dl, - "refinement_boxes": {"L0": {"B0": b0}}, + "dl": [1.0 / v for v in cells], "refined_particle_nbr": valid_refined_particle_nbr[dim][interp][0], "diag_options": {}, "nesting_buffer": 0, - "strict": True, + # "strict": True, } - for k, v in kwargs.items(): - if k in args: - args[k] = v + args.update(deepcopy(kwargs)) + + if "refinement" not in kwargs and "refinement_boxes" not in kwargs: + b0 = [[3] * dim, [8] * dim] + args["refinement_boxes"] = {"L0": {"B0": b0}} + print("merged", args) return args @@ -139,20 +145,20 @@ def makeBasicModel(extra_pops={}): ) -def populate_simulation(dim, interp, **input): +def populate_simulation(ndim=1, interp=1, model_fn=None, diags_fn=None, **simInput): ph.global_vars.sim = None - simulation = ph.Simulation(**basicSimulatorArgs(dim, interp, **input)) + simulation = ph.Simulation(**basicSimulatorArgs(ndim, interp, **simInput)) extra_pops = {} - if "populations" in input: - for pop, vals in input["populations"].items(): + if "populations" in simInput: + for pop, vals in simInput["populations"].items(): extra_pops[pop] = defaultPopulationSettings() extra_pops[pop].update(vals) - model = makeBasicModel(extra_pops) - if "diags_fn" in input: - input["diags_fn"](model) + model = model_fn() if model_fn else makeBasicModel(extra_pops) + if diags_fn: + diags_fn(model) - ElectronModel(closure="isothermal", Te=0.12) + ph.ElectronModel(closure="isothermal", Te=0.12) return simulation diff --git a/tests/simulator/test_load_balancing.py b/tests/simulator/test_load_balancing.py index f14ea8237c..a5205785c3 100644 --- a/tests/simulator/test_load_balancing.py +++ b/tests/simulator/test_load_balancing.py @@ -24,10 +24,10 @@ mpi_size = cpp.mpi_size() time_step_nbr = 2 time_step = 0.005 -smallest_patch_size = 5 -largest_patch_size = 5 -rebalance_coarsest = False -cells = (100, 100) +# smallest_patch_size = 5 +# largest_patch_size = 5 +rebalance_coarsest = True +cells = (25, 25) dl = (0.2, 0.2) diag_outputs = "phare_outputs/harris/2d/load_balancing" timestamps = [x * time_step for x in range(time_step_nbr + 1)] @@ -41,7 +41,8 @@ def config(): time_step=time_step, cells=cells, dl=dl, - refinement_boxes={}, + refinement="tagging", + max_nbr_levels=2, hyper_resistivity=0.001, resistivity=0.001, diag_options={ @@ -49,8 +50,10 @@ def config(): "options": {"dir": diag_outputs, "mode": "overwrite"}, }, advanced={ - "integrator/rebalance_coarsest": rebalance_coarsest, - "integrator/flexible_load_tolerance": 0.05, + "integrator/rebalance_coarsest": 1, + "integrator/rebalance_coarsest_every": 1, + # "integrator/rebalance_coarsest_on_init": 1, + # "integrator/flexible_load_tolerance": 0.05, }, loadbalancing="nppc", # homogeneous", ) @@ -63,7 +66,7 @@ def ppc_by_icell(x, y): # print("ppc", ppc) ppc[np.where(np.isclose(y, 10, atol=0.1))] = 590 # print("ppc", ppc) - return ppc + return 100 # ppc def density(x, y): L = sim.simulation_domain()[1] diff --git a/tests/simulator/test_restarts.py b/tests/simulator/test_restarts.py index 62e7d06af3..a67ad49c2d 100644 --- a/tests/simulator/test_restarts.py +++ b/tests/simulator/test_restarts.py @@ -17,59 +17,85 @@ from pyphare.pharesee.run import Run from pyphare.simulator.simulator import Simulator -from tests.simulator import SimulatorTest +from tests.simulator import SimulatorTest, populate_simulation from tests.diagnostic import dump_all_diags np.set_printoptions(precision=33) def permute(dic, expected_num_levels): - # from pyphare.pharein.simulation import supported_dimensions # eventually + from pyphare.pharein.simulation import supported_dimensions + dims = [1] # supported_dimensions() return [ [dim, interp, dic, expected_num_levels] for dim in dims for interp in [1, 2, 3] ] -def setup_model(ppc=100): - def density(x): +nppc = 100 +timestep = 0.001 +out = "phare_outputs/restarts" + +simArgs = dict( + # we are saving at timestep 4, and we have seen that restarted simulations with refinement boxes + # have regridding in places that don't exist in the original simulation + # we compare the immediate next timestep of both simulations with refinement boxes, as we have seen + # in this way neither simulations have any regrids, so are still comparable + time_step_nbr=5, # avoid regrid for refinement boxes https://github.com/LLNL/SAMRAI/issues/199 + time_step=timestep, + boundary_types="periodic", + cells=50, + dl=0.3, + diag_options=dict(format="phareh5", options=dict(dir=out, mode="overwrite")), + restart_options=dict(dir=out, mode="overwrite"), + advanced={ + # "integrator/rebalance_coarsest": 1, + # "integrator/rebalance_coarsest_every": 1, + # "integrator/rebalance_coarsest_on_init": 1, + # "integrator/flexible_load_tolerance": 0.05, + }, +) + + +def setup_model(ppc): + def density(*xyz): return 1.0 - def bx(x): + def bx(*xyz): return 0.0 def S(x, x0, l): return 0.5 * (1 + np.tanh((x - x0) / l)) - def by(x): + def by(*xyz): L = ph.global_vars.sim.simulation_domain()[0] v1, v2 = -1, 1.0 - return v1 + (v2 - v1) * (S(x, L * 0.25, 1) - S(x, L * 0.75, 1)) + return v1 + (v2 - v1) * (S(xyz[0], L * 0.25, 1) - S(xyz[0], L * 0.75, 1)) - def bz(x): + def bz(*xyz): return 0.5 - def b2(x): - return bx(x) ** 2 + by(x) ** 2 + bz(x) ** 2 + def b2(*xyz): + return bx(xyz[0]) ** 2 + by(xyz[0]) ** 2 + bz(xyz[0]) ** 2 - def T(x): + def T(*xyz): K = 1 - return 1 / density(x) * (K - b2(x) * 0.5) + return 1 / density(xyz[0]) * (K - b2(xyz[0]) * 0.5) - def vx(x): + def vx(*xyz): return 2.0 - def vy(x): + def vy(*xyz): return 0.0 - def vz(x): + def vz(*xyz): return 0.0 - def vxalpha(x): + def vxalpha(*xyz): return 3.0 - def vthxyz(x): - return T(x) + def vthxyz(*xyz): + return T(xyz[0]) vvv = { "vbulkx": vx, @@ -112,22 +138,21 @@ def vthxyz(x): return model -timestep = 0.001 -out = "phare_outputs/restarts" -simArgs = dict( - # we are saving at timestep 4, and we have seen that restarted simulations with refinement boxes - # have regridding in places that don't exist in the original simulation - # we compare the immediate next timestep of both simulations with refinement boxes, as we have seen - # in this way neither simulations have any regrids, so are still comparable - time_step_nbr=5, # avoid regrid for refinement boxes https://github.com/LLNL/SAMRAI/issues/199 - time_step=timestep, - boundary_types="periodic", - cells=200, - dl=0.3, - diag_options=dict(format="phareh5", options=dict(dir=out, mode="overwrite")), - restart_options=dict(dir=out, mode="overwrite"), - advanced={"integrator/rebalance_coarsest": False}, -) +class ModelFunctor: + def __init__(self, ppc=None): + self.nppc = ppc or nppc + print("self.nppc", self.nppc) + + def __call__(self): + return setup_model(self.nppc) + + +class DiagsFunctor: + def __init__(self, timestamps): + self.timestamps = timestamps + + def __call__(self, model): + dump_all_diags(model.populations, timestamps=np.array(self.timestamps)) def dup(dic={}): @@ -146,10 +171,6 @@ def tearDown(self): if self.simulator is not None: self.simulator.reset() self.simulator = None - ph.global_vars.sim = None - - def ddt_test_id(self): - return self._testMethodName.split("_")[-1] def check_diags(self, diag_dir0, diag_dir1, pops, timestamps, expected_num_levels): if cpp.mpi_rank() > 0: @@ -265,11 +286,15 @@ def test_restarts(self, ndim, interp, simInput, expected_num_levels): simput["restart_options"]["dir"] = local_out simput["restart_options"]["timestamps"] = [timestep * restart_idx] simput["diag_options"]["options"]["dir"] = local_out - ph.global_vars.sim = None - ph.global_vars.sim = ph.Simulation(**simput) - assert "restart_time" not in ph.global_vars.sim.restart_options - model = setup_model() - dump_all_diags(model.populations, timestamps=np.array(timestamps)) + sim = populate_simulation( + ndim, + interp, + model_fn=ModelFunctor(), + diags_fn=DiagsFunctor(timestamps), + **simput, + ) + print("sim", sim, sim.restart_options) + assert "restart_time" not in sim.restart_options Simulator(ph.global_vars.sim).run().reset() self.register_diag_dir_for_cleanup(local_out) diag_dir0 = local_out @@ -278,17 +303,20 @@ def test_restarts(self, ndim, interp, simInput, expected_num_levels): local_out = f"{local_out}_n2" simput["diag_options"]["options"]["dir"] = local_out simput["restart_options"]["restart_time"] = restart_time - ph.global_vars.sim = None - ph.global_vars.sim = ph.Simulation(**simput) - assert "restart_time" in ph.global_vars.sim.restart_options - model = setup_model() - dump_all_diags(model.populations, timestamps=np.array(timestamps)) + sim = populate_simulation( + ndim, + interp, + model_fn=ModelFunctor(), + diags_fn=DiagsFunctor(timestamps), + **simput, + ) + assert "restart_time" in sim.restart_options Simulator(ph.global_vars.sim).run().reset() self.register_diag_dir_for_cleanup(local_out) diag_dir1 = local_out self.check_diags( - diag_dir0, diag_dir1, model.populations, timestamps, expected_num_levels + diag_dir0, diag_dir1, sim.model.populations, timestamps, expected_num_levels ) @data( @@ -340,18 +368,19 @@ def test_restarts_elapsed_time(self, ndim, interp, simInput, expected_num_levels ] simput["restart_options"]["dir"] = diag_dir0 simput["diag_options"]["options"]["dir"] = diag_dir0 - ph.global_vars.sim = None - ph.global_vars.sim = ph.Simulation(**simput) - self.assertEqual( - [seconds], ph.global_vars.sim.restart_options["elapsed_timestamps"] + sim = populate_simulation( + ndim, + interp, + model_fn=ModelFunctor(), + diags_fn=DiagsFunctor(timestamps), + **simput, ) + self.assertEqual([seconds], sim.restart_options["elapsed_timestamps"]) - assert "restart_time" not in ph.global_vars.sim.restart_options - model = setup_model() - dump_all_diags(model.populations, timestamps=np.array(timestamps)) + assert "restart_time" not in sim.restart_options # autodump false to ignore possible init dump - simulator = Simulator(ph.global_vars.sim, auto_dump=False).initialize() + simulator = Simulator(sim, auto_dump=False).initialize() time.sleep(5) simulator.advance().dump() # should trigger restart on "restart_idx" advance @@ -362,17 +391,20 @@ def test_restarts_elapsed_time(self, ndim, interp, simInput, expected_num_levels # second restarted simulation simput["diag_options"]["options"]["dir"] = diag_dir1 simput["restart_options"]["restart_time"] = time_step - ph.global_vars.sim = None del simput["restart_options"]["elapsed_timestamps"] - ph.global_vars.sim = ph.Simulation(**simput) - assert "restart_time" in ph.global_vars.sim.restart_options - model = setup_model() - dump_all_diags(model.populations, timestamps=np.array(timestamps)) + sim = populate_simulation( + ndim, + interp, + model_fn=ModelFunctor(), + diags_fn=DiagsFunctor(timestamps), + **simput, + ) + assert "restart_time" in sim.restart_options Simulator(ph.global_vars.sim).run().reset() self.register_diag_dir_for_cleanup(diag_dir1) self.check_diags( - diag_dir0, diag_dir1, model.populations, timestamps, expected_num_levels + diag_dir0, diag_dir1, sim.model.populations, timestamps, expected_num_levels ) def test_mode_conserve(self, ndim=1, interp=1, simput=dup(simArgs)): @@ -387,30 +419,24 @@ def test_mode_conserve(self, ndim=1, interp=1, simput=dup(simArgs)): simput["restart_options"]["dir"] = local_out simput["restart_options"]["timestamps"] = [timestep * 4] - ph.global_vars.sim = ph.Simulation(**simput) - self.assertEqual(len(ph.global_vars.sim.restart_options["timestamps"]), 1) - self.assertEqual(ph.global_vars.sim.restart_options["timestamps"][0], 0.004) - model = setup_model() + sim = populate_simulation(ndim, interp, model_fn=ModelFunctor(), **simput) + self.assertEqual(len(sim.restart_options["timestamps"]), 1) + self.assertEqual(sim.restart_options["timestamps"][0], 0.004) Simulator(ph.global_vars.sim).run().reset() # second simulation (not restarted) - ph.global_vars.sim = None simput["restart_options"]["mode"] = "conserve" - ph.global_vars.sim = ph.Simulation(**simput) - self.assertEqual(len(ph.global_vars.sim.restart_options["timestamps"]), 0) + sim = populate_simulation(ndim, interp, model_fn=ModelFunctor(), **simput) + self.assertEqual(len(sim.restart_options["timestamps"]), 0) def test_input_validation_trailing_slash(self): if cpp.mpi_size() > 1: return # no need to test in parallel - simulation_args = dup() - simulation_args["restart_options"]["dir"] += ( - simulation_args["restart_options"]["dir"] + "//" - ) - sim = ph.Simulation(**simulation_args) - model = setup_model() + simput = dup() + simput["restart_options"]["dir"] += simput["restart_options"]["dir"] + "//" + sim = populate_simulation(model_fn=ModelFunctor(), **simput) Simulator(sim).run().reset() - ph.global_vars.sim = None @data( ([timedelta(hours=1), timedelta(hours=2)], True), @@ -486,10 +512,10 @@ def test_elapsed_timestamps_are_valid(self, elapsed_timestamps, valid): # simput["restart_options"]["timestamps"] = [timestep * 1] # simput["diag_options"]["options"]["dir"] = local_out # ph.global_vars.sim = None - # ph.global_vars.sim = ph.Simulation(**simput) - # assert "restart_time" not in ph.global_vars.sim.restart_options + # sim = populate_simulation(ndim, interp, **simput) + # assert "restart_time" not in sim.restart_options # model = setup_model() - # dump_all_diags(model.populations, timestamps=np.array(timestamps)) + # dump_all_diags(sim.model.populations, timestamps=np.array(timestamps)) # Simulator(ph.global_vars.sim).run().reset() # self.register_diag_dir_for_cleanup(local_out) # diag_dir0 = local_out @@ -500,16 +526,16 @@ def test_elapsed_timestamps_are_valid(self, elapsed_timestamps, valid): # simput["restart_options"]["restart_time"] = restart_time # simput["advanced"]["integrator/rebalance_coarsest"] = True # ph.global_vars.sim = None - # ph.global_vars.sim = ph.Simulation(**simput) - # assert "restart_time" in ph.global_vars.sim.restart_options + # sim = populate_simulation(ndim, interp, **simput) + # assert "restart_time" in sim.restart_options # model = setup_model() - # dump_all_diags(model.populations, timestamps=np.array(timestamps)) + # dump_all_diags(sim.model.populations, timestamps=np.array(timestamps)) # Simulator(ph.global_vars.sim).run().reset() # self.register_diag_dir_for_cleanup(local_out) # diag_dir1 = local_out # self.check_diags( - # diag_dir0, diag_dir1, model.populations, timestamps, expected_num_levels + # diag_dir0, diag_dir1, sim.model.populations, timestamps, expected_num_levels # )