Last active
February 27, 2019 20:55
-
-
Save Ben1980/cc5ccb883ac619072b677dcc895e2172 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| double Inverse(double value) { return -value; } | |
| Particle GenerateStandardParticle(double xPosition, double yPosition) | |
| { | |
| ParticleBuilder particleBuilder; | |
| return particleBuilder | |
| .position({xPosition, yPosition}) | |
| .mass(1e10) | |
| .build(); | |
| } | |
| TEST_CASE( "Explicit euler algorithm with two point mass", "[euler]" ) | |
| { | |
| Solver solver; | |
| const std::vector<Particle> particlesX = { GenerateStandardParticle(0.5, 0), | |
| GenerateStandardParticle(-0.5, 0)}; | |
| const std::vector<Particle> particlesY = { GenerateStandardParticle(0, 0.5), | |
| GenerateStandardParticle(0, -0.5)}; | |
| const double EPSILON = 1e-3; | |
| //Solution | |
| const double acceleration = -0.6674079993; //m/s^2 | |
| const double velocity = -0.06674079993; //m/s | |
| const double position = 0.48665184; //m | |
| SECTION( "Two still standing point mass are attracting each other in x-direction" ) { | |
| std::vector<Particle> result = solver.solve(particlesX, EPSILON); | |
| Particle &particle = result.front(); | |
| REQUIRE(particle.acceleration.x == Approx(acceleration)); | |
| REQUIRE(particle.velocity.x == Approx(velocity)); | |
| REQUIRE(particle.position.x == Approx(position)); | |
| particle = result.back(); | |
| REQUIRE(particle.acceleration.x == Approx(Inverse(acceleration))); | |
| REQUIRE(particle.velocity.x == Approx(Inverse(velocity))); | |
| REQUIRE(particle.position.x == Approx(Inverse(position))); | |
| } | |
| SECTION( "Two still standing point mass are attracting each other in y-direction" ) { | |
| std::vector<Particle> result = solver.solve(particlesY, EPSILON); | |
| Particle &particle = result.front(); | |
| REQUIRE(particle.acceleration.y == Approx(acceleration)); | |
| REQUIRE(particle.velocity.y == Approx(velocity)); | |
| REQUIRE(particle.position.y == Approx(position)); | |
| particle = result.back(); | |
| REQUIRE(particle.acceleration.y == Approx(Inverse(acceleration))); | |
| REQUIRE(particle.velocity.y == Approx(Inverse(velocity))); | |
| REQUIRE(particle.position.y == Approx(Inverse(position))); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment