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
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)
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