// [InlineData(1000, 0.001F, 20, 0.01F)] public async Task Simulate_particles_collisions_tests( float time, float timeStep, int stepsPerSnapshot, float particlesBounceEfficiencyFactor) { World.ParticlesBounceFactor = particlesBounceEfficiencyFactor; const string simulationInitStateId = "particles_collisions_test_init_state"; var fileWorldStateLoader = new FileWorldStateLoader(_filePathBuilder); var worldInitState = fileWorldStateLoader.First(simulationInitStateId); var simulationId = $"particles_collisions_test_T_{time}_TS_{timeStep}_SPS_{stepsPerSnapshot}_BE_{particlesBounceEfficiencyFactor}"; DeleteSimulationSnapshotsFile(simulationId); var worldSimulator = new WorldSimulator(_fileWorldStateSaver); await worldSimulator.RunWorldAsync(worldInitState, new SimulationParams(time, timeStep, simulationId, stepsPerSnapshot)); var worldFinalState = worldSimulator.WorldTimeSteps.Last(); var particlesFinalVelocity = worldFinalState.Particles.Select(p => p.V.Length()).ToArray(); var particlesInitVelocity = worldInitState.Particles.Select(p => p.V.Length()).ToArray(); for (int i = 0; i < particlesInitVelocity.Length; i++) { particlesFinalVelocity[i].Should().BeInRange( particlesInitVelocity[i] * particlesBounceEfficiencyFactor / 1.01F, particlesInitVelocity[i] * particlesBounceEfficiencyFactor * 1.01F ); } }
public async Task WorldSnapshotIsSavedAfterEveryStep(int simulationTime, int expectedSnapshotCount) { // arrange var world = RandomWorld(4); var worldSimulator = new WorldSimulator(new FileWorldStateSaver(_filePathBuilder)); await worldSimulator.RunWorldAsync(world, new SimulationParams(simulationTime, 1, SimulationId, 1)); var fileWorldStateLoader = new FileWorldStateLoader(_filePathBuilder); // act var snapshots = fileWorldStateLoader.All(SimulationId).ToArray(); // assert snapshots.Length.Should().Be(expectedSnapshotCount); var snapshotsAsJson = snapshots.Select(JsonConvert.SerializeObject); var expectedSnapshots = worldSimulator.WorldTimeSteps.Select(JsonConvert.SerializeObject); snapshotsAsJson.Should().BeEquivalentTo(expectedSnapshots); }
// [InlineData(1000, 0.2F, 5, 0.2)] // [InlineData(1000, 0.05F, 5, 0.8)] // [InlineData(100, 0.01F, 10, 1)] public async Task Run_particles_triangular_random_benchmark_world_parametrized( float time, float timeStep, int stepsPerSnapshot, float particlesBounceEfficiencyFactor) { World.ParticlesBounceFactor = particlesBounceEfficiencyFactor; var simulationInitStateId = "particles_triangular_random_init_state"; var fileWorldStateLoader = new FileWorldStateLoader(_filePathBuilder); var worldInitState = fileWorldStateLoader.First(simulationInitStateId); var simulationId = $"particles_triangular_random_T_{time}_TS_{timeStep}_SPS_{stepsPerSnapshot}_BE_{particlesBounceEfficiencyFactor}"; DeleteSimulationSnapshotsFile(simulationId); var worldSimulator = new WorldSimulator(_fileWorldStateSaver); await worldSimulator.RunWorldAsync(worldInitState, new SimulationParams(time, timeStep, simulationId, stepsPerSnapshot)); }
public async Task CanLoadSimulationFirstAndLastStep() { // arrange var world = RandomWorld(4); var worldSimulator = new WorldSimulator(new FileWorldStateSaver(_filePathBuilder)); await worldSimulator.RunWorldAsync(world, new SimulationParams(3, 1, SimulationId, 1)); var fileWorldStateLoader = new FileWorldStateLoader(_filePathBuilder); // act var firstSnapshot = fileWorldStateLoader.First(SimulationId); var lastSnapshot = fileWorldStateLoader.Last(SimulationId); // assert var firstSnapshotAsJson = JsonConvert.SerializeObject(firstSnapshot); var expectedFirstWorldAsJson = JsonConvert.SerializeObject(worldSimulator.WorldTimeSteps.First()); firstSnapshotAsJson.Should().Be(expectedFirstWorldAsJson); var lastSnapshotAsJson = JsonConvert.SerializeObject(lastSnapshot); var expectedLastWorldAsJson = JsonConvert.SerializeObject(worldSimulator.WorldTimeSteps.Last()); lastSnapshotAsJson.Should().Be(expectedLastWorldAsJson); }