def pif_sim(): PhysicsModule.register("EMWave", EMWave) PhysicsModule.register("ChargedParticle", ChargedParticle) Diagnostic.register("ParticleDiagnostic", ParticleDiagnostic) # Diagnostic.register("FieldPlottingDiagnostic", FieldPlottingDiagnostic) ComputeTool.register("ForwardEuler", ForwardEuler) input_file = "tests/fixtures/particle_in_field/particle_in_field.toml" sim = construct_simulation_from_toml(input_file) return sim
""" def __init__(self, owner: Simulation, input_data: dict): super().__init__(owner, input_data) self.dt = None def initialize(self): self.dt = self.owner.clock.dt def push(self, position, momentum, mass, spring_constant): position[:] = position + self.dt * momentum / mass momentum[:] = momentum - self.dt * spring_constant * position PhysicsModule.register("BlockOnSpring", BlockOnSpring) Diagnostic.register("BlockDiagnostic", BlockDiagnostic) ComputeTool.register("BlockForwardEuler", ForwardEuler) ComputeTool.register("BackwardEuler", BackwardEuler) ComputeTool.register("Leapfrog", Leapfrog) @pytest.fixture def bos_run(): # Note: grid isn't used, but "gridless" sims aren't an option yet problem_config = { "Grid": {"N": 2, "x_min": 0, "x_max": 1}, "Clock": {"start_time": 0, "end_time": 10, "num_steps": 10}, "PhysicsModules": { "BlockOnSpring": { "mass": 1,
def print_diagnose(self, data): print(data) def csv_diagnose(self, data): self.csv.append(data) class ForwardEuler(ComputeTool): def __init__(self, owner: Simulation, input_data: dict): super().__init__(owner, input_data) self.dt = None def initialize(self): self.dt = self.owner.clock.dt def push(self, position, momentum, charge, mass, E, B): p0 = momentum.copy() momentum[:] = momentum + self.dt * E * charge position[:] = position + self.dt * p0 / mass PhysicsModule.register("EMWave", EMWave) PhysicsModule.register("ChargedParticle", ChargedParticle) Diagnostic.register("ParticleDiagnostic", ParticleDiagnostic) ComputeTool.register("ForwardEuler", ForwardEuler) input_file = "particle_in_field.toml" sim = Simulation(input_file) sim.run()