def main(): from pybindlibs.cpp import mpi_rank config() simulator = Simulator(gv.sim) simulator.initialize() simulator.run() if mpi_rank() == 0: times, first_mode, ampl, gamma, damped_mode, omega \ = growth_b_right_hand(os.path.join(os.curdir, "ion_ion_beam1d")) fig, (ax1, ax2) = plt.subplots(2, 1) ax1.set_title("Right Hand Resonant mode (Beam instability)") ax1.stem(times, first_mode, linefmt='-k', basefmt=' ', use_line_collection=True) ax1.plot(times, yaebx(times, ampl, gamma), color='r', linestyle='-', marker='') ax1.text(0.04, 0.80, "From Gary et al., 1985 (ApJ : 10.1086/162797)", transform=ax1.transAxes) ax1.set_ylabel("Most unstable mode") ax1.set_title("Right Hand Resonant mode (Beam instability)") ax1.text(0.30, 0.50, "gamma = {:5.3f}... expected 0.09".format(gamma), transform=ax1.transAxes) ax2.plot(times, damped_mode, color='g', linestyle='', marker='o') ax2.set_xlabel("Time") ax2.set_ylabel("Real mode") ax2.text(0.48, 0.30, "~ 3 periods until t=50", transform=ax2.transAxes) ax2.text(0.40, 0.20, "omega (real) = {:5.3f}... expected 0.19".format(omega), transform=ax2.transAxes) fig.savefig("ion_ion_beam1d.png") # compare with the values given gary et al. 1985 assert np.fabs(gamma-0.09) < 2e-2
class DataWranglerTest(unittest.TestCase): def __init__(self, *args, **kwargs): super(DataWranglerTest, self).__init__(*args, **kwargs) self.dw = None self.simulator = None def test_1d(self): for interp in range(1, 4): self.simulator = Simulator(populate_simulation(1, interp)) self.simulator.initialize() self.dw = self.simulator.data_wrangler() print("\n", self.dw.lvl0IonDensity()) print("\n", self.dw.lvl0BulkVelocity()) print("\n", self.dw.lvl0PopDensity()) print("\n", self.dw.lvl0PopFluxes()) print("\n", self.dw.lvl0EM()) for pop, particles in self.dw.getPatchLevel( 0).getParticles().items(): for key, patches in particles.items(): for patch in patches: self.assertTrue(isinstance(patch.lower, np.ndarray)) self.assertTrue(isinstance(patch.upper, np.ndarray)) self.simulator = None def tearDown(self): del self.dw if self.simulator is not None: self.simulator.reset()
def main(): config() simulator = Simulator(gv.sim) simulator.initialize() simulator.run() if cpp.mpi_rank() == 0: b = hierarchy_from(h5_filename="phare_outputs/EM_B.h5") plot(b)
def main(): from pybindlibs.cpp import mpi_rank withTagging(diagdir="withTagging") simulator = Simulator(gv.sim) simulator.initialize().run() gv.sim = None noRefinement(diagdir="noRefinement") simulator = Simulator(gv.sim) simulator.initialize().run() gv.sim = None if mpi_rank() == 0: make_figure()
def main(): for name,config in zip(("uni", "td"),(config_uni, config_td)): params=[{"vx":-1,"diagdir":name + "_vxm2"}, {"vx":2,"diagdir":name + "_vx2"}] for param in params: if param["vx"] >-1: continue print("-----------------------------------") print(param) print("-----------------------------------") config(**param) simulator = Simulator(gv.sim) simulator.initialize() simulator.run() gv.sim = None
class SimulatorRefineBoxInputs(unittest.TestCase): def __init__(self, *args, **kwargs): super(SimulatorRefineBoxInputs, self).__init__(*args, **kwargs) self.simulator = None def dup(dic): dic = NoOverwriteDict(dic) dic.update(diags.copy()) dic.update( {"diags_fn": lambda model: dump_all_diags(model.populations)}) return dic """ The first set of boxes "B0": [(10,), (14,)] Are configured to force there to be a single patch on L0 This creates a case with MPI that there are an unequal number of Patches across MPI domains. This case must be handled and not hang due to collective calls not being handled properly. """ valid1D = [ dup({ "cells": [65], "refinement_boxes": { "L0": { "B0": [(10, ), (14, )] } } }), dup({ "cells": [65], "refinement_boxes": { "L0": { "B0": [(5, ), (55, )] } } }), dup({ "cells": [65], "refinement_boxes": { "L0": { "B0": Box(5, 55) } } }), dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 55)] } }), dup({ "cells": [65], "refinement_boxes": { 0: [Box(5, 55)] } }), dup({ "cells": [65], "refinement_boxes": { 0: [Box(0, 55)] } }), dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 14), Box(15, 25)] } }), dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(12, 48)], "L2": [Box(60, 64)] } }), dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(12, 48)] } }), dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(20, 30)] } }), dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(11, 49)] }, "nesting_buffer": 1 }), dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(10, 50)] } }), dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(15, 49)] } }), dup({ "cells": [65], "refinement_boxes": None, "smallest_patch_size": 20, "largest_patch_size": 20, "nesting_buffer": 10 }), ] invalid1D = [ # finer box outside lower dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 24)], "L1": [Box(9, 30)] } }), # finer box outside upper dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 24)], "L1": [Box(15, 50)] } }), # overlapping boxes dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 15), Box(15, 25)] } }), # box.upper outside domain dup({ "cells": [55], "refinement_boxes": { "L0": { "B0": [(5, ), (65, )] } } }), # largest_patch_size > smallest_patch_size dup({ "smallest_patch_size": 100, "largest_patch_size": 64, }), # refined_particle_nbr doesn't exist dup({"refined_particle_nbr": 1}), # L2 box incompatible with L1 box due to nesting buffer dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(11, 49)] }, "nesting_buffer": 2 }), # negative nesting buffer dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(11, 49)] }, "nesting_buffer": -1 }), # too large nesting buffer dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(11, 49)] }, "nesting_buffer": 33 }), dup({ "cells": [65], "refinement_boxes": None, "largest_patch_size": 20, "nesting_buffer": 46 }), ] def tearDown(self): if self.simulator is not None: self.simulator.reset() def _do_dim(self, dim, input, valid: bool = False): for interp in range(1, 4): try: self.simulator = Simulator( populate_simulation(dim, interp, **input)) self.simulator.initialize() self.assertTrue(valid) self.simulator.dump(self.simulator.currentTime(), self.simulator.timeStep()) self.simulator = None except ValueError as e: self.assertTrue(not valid) @data(*valid1D) def test_1d_valid(self, input): self._do_dim(1, input, True) @data(*invalid1D) def test_1d_invalid(self, input): self._do_dim(1, input)
def getHierarchy(self, interp_order, refinement_boxes, qty, nbr_part_per_cell=100, diag_outputs="phare_outputs", density=lambda x: 0.3 + 1. / np.cosh((x - 6) / 4.)**2, beam=False, smallest_patch_size=10, largest_patch_size=10, cells=120, dl=0.1): from pyphare.pharein import global_vars global_vars.sim = None startMPI() Simulation(smallest_patch_size=smallest_patch_size, largest_patch_size=largest_patch_size, time_step_nbr=30000, final_time=30., boundary_types="periodic", cells=cells, dl=dl, interp_order=interp_order, refinement_boxes=refinement_boxes, diag_options={ "format": "phareh5", "options": { "dir": diag_outputs, "mode": "overwrite" } }) def beam_density(x): return np.zeros_like(x) + 0.3 def by(x): from pyphare.pharein.global_vars import sim L = sim.simulation_domain() return 0.1 * np.cos(2 * np.pi * x / L[0]) def bz(x): from pyphare.pharein.global_vars import sim L = sim.simulation_domain() return 0.1 * np.sin(2 * np.pi * x / L[0]) def bx(x): return 1. def vx(x): from pyphare.pharein.global_vars import sim L = sim.simulation_domain() return 0.1 * np.cos(2 * np.pi * x / L[0]) + 0.2 def vy(x): from pyphare.pharein.global_vars import sim L = sim.simulation_domain() return 0.1 * np.cos(2 * np.pi * x / L[0]) def vz(x): from pyphare.pharein.global_vars import sim L = sim.simulation_domain() return 0.1 * np.sin(2 * np.pi * x / L[0]) def vthx(x): return 0.01 + np.zeros_like(x) def vthy(x): return 0.01 + np.zeros_like(x) def vthz(x): return 0.01 + np.zeros_like(x) if beam: MaxwellianFluidModel(bx=bx, by=by, bz=bz, protons={ "charge": 1, "density": density, "vbulkx": vx, "vbulky": vy, "vbulkz": vz, "vthx": vthx, "vthy": vthy, "vthz": vthz, "nbr_part_per_cell": nbr_part_per_cell, "init": { "seed": 1337 } }, beam={ "charge": 1, "density": beam_density, "vbulkx": vx, "vbulky": vy, "vbulkz": vz, "vthx": vthx, "vthy": vthy, "vthz": vthz, "nbr_part_per_cell": nbr_part_per_cell, "init": { "seed": 1337 } }) else: MaxwellianFluidModel(bx=bx, by=by, bz=bz, protons={ "charge": 1, "density": density, "vbulkx": vx, "vbulky": vy, "vbulkz": vz, "vthx": vthx, "vthy": vthy, "vthz": vthz, "nbr_part_per_cell": nbr_part_per_cell, "init": { "seed": 1337 } }) ElectronModel(closure="isothermal", Te=0.12) for quantity in ["E", "B"]: ElectromagDiagnostics(quantity=quantity, write_timestamps=np.zeros(1), compute_timestamps=np.zeros(1)) for quantity in ["density", "bulkVelocity"]: FluidDiagnostics(quantity=quantity, write_timestamps=np.zeros(1), compute_timestamps=np.zeros(1)) poplist = ["protons", "beam"] if beam else ["protons"] for pop in poplist: for quantity in ["density", "flux"]: FluidDiagnostics(quantity=quantity, write_timestamps=np.zeros(1), compute_timestamps=np.zeros(1), population_name=pop) for quantity in ['domain', 'levelGhost', 'patchGhost']: ParticleDiagnostics(quantity=quantity, compute_timestamps=np.zeros(1), write_timestamps=np.zeros(1), population_name=pop) simulator = Simulator(global_vars.sim) simulator.initialize() if qty == "b": b_hier = hierarchy_from(h5_filename=diag_outputs + "/EM_B.h5") return b_hier is_particle_type = qty == "particles" or qty == "particles_patch_ghost" if is_particle_type: particle_hier = None if qty == "particles": particle_hier = hierarchy_from(h5_filename=diag_outputs + "/ions_pop_protons_domain.h5") particle_hier = hierarchy_from(h5_filename=diag_outputs + "/ions_pop_protons_levelGhost.h5", hier=particle_hier) if is_particle_type: particle_hier = hierarchy_from(h5_filename=diag_outputs + "/ions_pop_protons_patchGhost.h5", hier=particle_hier) if qty == "particles": merge_particles(particle_hier) if is_particle_type: return particle_hier if qty == "moments": mom_hier = hierarchy_from(h5_filename=diag_outputs + "/ions_density.h5") mom_hier = hierarchy_from(h5_filename=diag_outputs + "/ions_bulkVelocity.h5", hier=mom_hier) mom_hier = hierarchy_from(h5_filename=diag_outputs + "/ions_pop_protons_density.h5", hier=mom_hier) mom_hier = hierarchy_from(h5_filename=diag_outputs + "/ions_pop_protons_flux.h5", hier=mom_hier) if beam: mom_hier = hierarchy_from(h5_filename=diag_outputs + "/ions_pop_beam_density.h5", hier=mom_hier) mom_hier = hierarchy_from(h5_filename=diag_outputs + "/ions_pop_beam_flux.h5", hier=mom_hier) return mom_hier
def main(): cases = [0.01,0.05,0.1,0.3,0.5,0.75,1,2] dls = [0.2, 0.1] nbrcells = [100,200] nbrdts = [25000, 100000] for vth in cases: for dl, nbrcell, nbrdt in zip(dls, nbrcells, nbrdts): uniform(vth, dl, nbrcell, nbrdt) simulator = Simulator(gv.sim) simulator.initialize() simulator.run() gv.sim = None paths = glob("*vth*") runs_vth = {} Bnrj_vth = {} K_vth = {} times_vth={} #extract vth and dx from the name of the directory vthdx = np.asarray(sorted([[float(x) for x in path.split("/")[-1].strip("vth").split("dx")] for path in paths], key=lambda x:x[1])) paths = sorted(paths, key=lambda path: float(paths[0].split("/")[-1].strip("vth").split("dx")[1])) #now for each directory, extract magnetic and kinetic energies for path in paths: runs_vth[path], Bnrj_vth[path], K_vth[path], times_vth[path] = energies(path) # we want to plot things as a function of the thermal velocity # for dx=0.1 and 0.2 so extract their values vth0p2 = np.asarray([x[0] for x in vthdx if x[1] == 0.2]) vth0p1 = np.asarray([x[0] for x in vthdx if x[1] == 0.1]) # we will plot the variation of the kinetic energy # relative to is "initial value", by "initial" we mean # its average over some time interval at the start of the run. # here we take 3,4 because before there is some kind of irrelevant transient K0 = {} for path,K in K_vth.items(): it1, it2 = avg_interval(3,4, times_vth[path]) K0[path] = np.mean(K[it1:it2+1]) # calculate the relative variation of kinetic enery for both cases rel_K0p2 = np.asarray([np.abs(K[-1]-K0[path])/K0[path]*100 for path,K in K_vth.items() if "dx0.2" in path]) rel_K0p1 = np.asarray([np.abs(K[-1]-K0[path])/K0[path]*100 for path,K in K_vth.items() if "dx0.1" in path]) fig, ax = plt.subplots() id2 = np.argsort(vth0p2) id1 = np.argsort(vth0p1) ax.plot(vth0p2[id2], rel_K0p2[id2], marker="o", label="dx = 0.2 (dt=0.002, 25k steps)") ax.plot(vth0p1[id1], rel_K0p1[id1], marker="o", label="dx = 0.1 (dt=5e-4, 100k steps)") ax.set_xscale("log") ax.set_yscale("log") ax.set_ylabel(r"$\Delta K$ (%)") ax.set_xlabel("Vth") ax.set_title("kinetic energy evolution as a function of Vth") ax.legend() fig.tight_layout() fig.savefig("K.png")
def main(): config() simulator = Simulator(gv.sim) simulator.initialize() simulator.run()
class SimulatorRefinedParticleNbr(unittest.TestCase): def __init__(self, *args, **kwargs): super(SimulatorRefinedParticleNbr, self).__init__(*args, **kwargs) with open(os.path.join(project_root, "res/amr/splitting.yml"), 'r') as stream: try: self.yaml_root = yaml.safe_load(stream) except yaml.YAMLError as exc: print(exc) sys.exit(1) # while splitting particles may leave the domain area # so we remove the particles from the border cells of each patch def _less_per_dim(self, dim, refined_particle_nbr, patch): if dim == 1: return refined_particle_nbr * 2 cellNbr = patch.upper - patch.lower + 1 if dim == 2: return refined_particle_nbr * ((cellNbr[0] * 2 + (cellNbr[1] * 2))) raise ValueError("Unhandled dimension for function") def _check_deltas_and_weights(self, dim, interp, refined_particle_nbr): yaml_dim = self.yaml_root["dimension_" + str(dim)] yaml_interp = yaml_dim["interp_" + str(interp)] yaml_n_particles = yaml_interp["N_particles_" + str(refined_particle_nbr)] yaml_delta = [float(s) for s in str(yaml_n_particles["delta"]).split(" ")] yaml_weight = [float(s) for s in str(yaml_n_particles["weight"]).split(" ")] splitter_t = splitter_type(dim, interp, refined_particle_nbr) np.testing.assert_allclose(yaml_delta, splitter_t.delta) np.testing.assert_allclose(yaml_weight, splitter_t.weight) def _do_dim(self, dim, min_diff, max_diff): from pyphare.pharein.simulation import valid_refined_particle_nbr for interp in range(1, 4): prev_split_particle_max = 0 for refined_particle_nbr in valid_refined_particle_nbr[dim][interp]: self._check_deltas_and_weights(dim, interp, refined_particle_nbr) simInput = NoOverwriteDict({"refined_particle_nbr": refined_particle_nbr}) self.simulator = Simulator(populate_simulation(dim, interp, **simInput)) self.simulator.initialize() dw = self.simulator.data_wrangler() max_per_pop = 0 leaving_particles = 0 for pop, particles in dw.getPatchLevel(1).getParticles().items(): per_pop = 0 for key, patches in particles.items(): for patch in patches: leaving_particles += self._less_per_dim(dim, refined_particle_nbr, patch) per_pop += patch.data.size() max_per_pop = max(max_per_pop, per_pop) prev_min_diff = prev_split_particle_max * min_diff # while splitting particles may leave the domain area # so we remove the particles from the border cells of each patch self.assertTrue( max_per_pop > prev_min_diff - (leaving_particles) ) if prev_split_particle_max > 0: prev_max_diff = prev_min_diff * dim * max_diff self.assertTrue(max_per_pop < prev_max_diff) prev_split_particle_max = max_per_pop self.simulator = None """ 1d refine 10 cells in 1d, ppc 100 10 * 2 * ppc = 200 10 * 3 * ppc = 300 300 / 200 = 1.5 10 * 4 * ppc = 400 500 / 400 = 1.33 10 * 5 * ppc = 500 500 / 400 = 1.25 taking the minimul diff across permutations current to previous should be at least this times bigger """ PREVIOUS_ITERATION_MIN_DIFF_1d = 1.25 PREVIOUS_ITERATION_MAX_DIFF_1d = 1.50 def test_1d(self): This = type(self) self._do_dim(1, This.PREVIOUS_ITERATION_MIN_DIFF_1d, This.PREVIOUS_ITERATION_MAX_DIFF_1d) """ 2d refine 10x10 cells in 2d, ppc 100 10 * 10 * 4 * ppc = 400 10 * 10 * 8 * ppc = 800 800 / 400 = 1.5 10 * 10 * 9 * ppc = 900 900 / 800 = 1.125 """ PREVIOUS_ITERATION_MIN_DIFF_2d = 1.125 PREVIOUS_ITERATION_MAX_DIFF_2d = 1.50 def test_2d(self): This = type(self) self._do_dim(2, This.PREVIOUS_ITERATION_MIN_DIFF_2d, This.PREVIOUS_ITERATION_MAX_DIFF_2d) def tearDown(self): # needed in case exception is raised in test and Simulator # not reset properly if self.simulator is not None: self.simulator.reset()
def main(): config() s = Simulator(gv.sim, post_advance=post_advance) s.initialize() post_advance(0) s.run()
class SimulatorValidation(unittest.TestCase): def __init__(self, *args, **kwargs): super(SimulatorValidation, self).__init__(*args, **kwargs) self.simulator = None def tearDown(self): if self.simulator is not None: self.simulator.reset() def _do_dim(self, dim, input, valid: bool = False): for interp in range(1, 4): try: self.simulator = Simulator( populate_simulation(dim, interp, **input)) self.simulator.initialize() self.assertTrue(valid) self.simulator = None except ValueError as e: self.assertTrue(not valid) """ The first set of boxes "B0": [(10,), (14,)] Are configured to force there to be a single patch on L0 This creates a case with MPI that there are an unequal number of Patches across MPI domains. This case must be handled and not hang due to collective calls not being handled properly. """ valid1D = [ dup({ "cells": [65], "refinement_boxes": { "L0": { "B0": [(10, ), (14, )] } } }), dup({ "cells": [65], "refinement_boxes": { "L0": { "B0": [(5, ), (55, )] } } }), dup({ "cells": [65], "refinement_boxes": { "L0": { "B0": Box(5, 55) } } }), dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 55)] } }), dup({ "cells": [65], "refinement_boxes": { 0: [Box(5, 55)] } }), dup({ "cells": [65], "refinement_boxes": { 0: [Box(0, 55)] } }), dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 14), Box(15, 25)] } }), dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(12, 48)], "L2": [Box(60, 64)] } }), dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(12, 48)] } }), dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(20, 30)] } }), dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(11, 49)] }, "nesting_buffer": 1 }), dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(10, 50)] } }), dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(15, 49)] } }), dup({ "cells": [65], "refinement_boxes": None, "smallest_patch_size": 20, "largest_patch_size": 20, "nesting_buffer": 10 }), # finer box is within set of coarser boxes dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 9), Box(10, 15)], "L1": [Box(11, 29)] } }), ] invalid1D = [ # finer box outside lower dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 24)], "L1": [Box(9, 30)] } }), # finer box outside upper dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 24)], "L1": [Box(15, 50)] } }), # overlapping boxes dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 15), Box(15, 25)] } }), # box.upper outside domain dup({ "cells": [55], "refinement_boxes": { "L0": { "B0": [(5, ), (65, )] } } }), # largest_patch_size > smallest_patch_size dup({ "smallest_patch_size": 100, "largest_patch_size": 64, }), # refined_particle_nbr doesn't exist dup({"refined_particle_nbr": 1}), # L2 box incompatible with L1 box due to nesting buffer dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(11, 49)] }, "nesting_buffer": 2 }), # negative nesting buffer dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(11, 49)] }, "nesting_buffer": -1 }), # too large nesting buffer dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 25)], "L1": [Box(11, 49)] }, "nesting_buffer": 33 }), dup({ "cells": [65], "refinement_boxes": None, "largest_patch_size": 20, "nesting_buffer": 46 }), # finer box is not within set of coarser boxes dup({ "cells": [65], "refinement_boxes": { "L0": [Box(5, 9), Box(11, 15)], "L1": [Box(11, 29)] } }), ] @data(*valid1D) def test_1d_valid(self, input): self._do_dim(1, input, True) @data(*invalid1D) def test_1d_invalid(self, input): self._do_dim(1, input) valid2D = [ dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 55)] } }), dup({ "smallest_patch_size": None, "largest_patch_size": None }), dup({ "smallest_patch_size": (10, 10), "largest_patch_size": (20, 20) }), dup({ "smallest_patch_size": [10, 10], "largest_patch_size": [20, 20] }), dup({ "smallest_patch_size": (10, 10), "largest_patch_size": None }), dup({ "smallest_patch_size": None, "largest_patch_size": (20, 20) }), dup({"smallest_patch_size": (10, 10)}), dup({"largest_patch_size": (20, 20)}), dup({ "smallest_patch_size": 10, "largest_patch_size": (20, 20) }), dup({ "smallest_patch_size": (10, 10), "largest_patch_size": 20 }), dup({ "smallest_patch_size": [10, 10], "largest_patch_size": (20, 20) }), dup({ "smallest_patch_size": (10, 10), "largest_patch_size": [20, 20] }), dup({ "cells": [65, 65], "refinement_boxes": None, "smallest_patch_size": 20, "largest_patch_size": 20, "nesting_buffer": 10 }), dup({ "cells": [65, 65], "refinement_boxes": { "L0": { "B0": Box2D(5, 55) } } }), dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 55)] } }), dup({ "cells": [65, 65], "refinement_boxes": { 0: [Box2D(5, 55)] } }), dup({ "cells": [65, 65], "refinement_boxes": { 0: [Box2D(0, 55)] } }), dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 14), Box2D(15, 25)] } }), dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 25)], "L1": [Box2D(12, 48)], "L2": [Box2D(60, 64)] } }), dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 25)], "L1": [Box2D(12, 48)] } }), dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 25)], "L1": [Box2D(20, 30)] } }), dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 25)], "L1": [Box2D(11, 49)] }, "nesting_buffer": 1 }), dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 25)], "L1": [Box2D(10, 50)] } }), dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 25)], "L1": [Box2D(15, 49)] } }), ] invalid2D = [ # finer box outside lower dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 24)], "L1": [Box2D(9, 30)] } }), # finer box outside lower dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 24)], "L1": [Box2D(9, 30)] } }), # finer box outside upper dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 24)], "L1": [Box2D(15, 50)] } }), # overlapping boxes dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 15), Box2D(15, 25)] } }), # box.upper outside domain dup({ "cells": [55, 55], "refinement_boxes": { "L0": { "B0": Box2D( 5, 65, ) } } }), # largest_patch_size > smallest_patch_size dup({ "smallest_patch_size": 100, "largest_patch_size": 64, }), # refined_particle_nbr doesn't exist dup({"refined_particle_nbr": 1}), # L2 box incompatible with L1 box due to nesting buffer dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 25)], "L1": [Box2D(11, 49)] }, "nesting_buffer": 2 }), # negative nesting buffer dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 25)], "L1": [Box2D(11, 49)] }, "nesting_buffer": -1 }), # too large nesting buffer dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 25)], "L1": [Box2D(11, 49)] }, "nesting_buffer": 33 }), dup({ "cells": [65, 65], "refinement_boxes": None, "largest_patch_size": 20, "nesting_buffer": 46 }), # finer box is not within set of coarser boxes dup({ "cells": [65, 65], "refinement_boxes": { "L0": [Box2D(5, 9), Box2D(11, 15)], "L1": [Box2D(11, 29)] } }), ] @data(*valid2D) def test_2d_valid(self, input): self._do_dim(2, input, True) @data(*invalid2D) def test_2d_invalid(self, input): self._do_dim(2, input)
def main(): fromNoise() simulator = Simulator(gv.sim) simulator.initialize() simulator.run()