-
-
Notifications
You must be signed in to change notification settings - Fork 359
Reimplemented Verlet Integration in Python #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
self.acc = acc | ||
while pos > 0: | ||
time += dt | ||
prev_pos, pos = pos, pos * 2 - prev_pos + acc * dt * dt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know about this one. I thought about changing it to the following, but I wasn't sure, so feel free to tell me your opinion.
next_pos = pos * 2 - prev_pos + acc * dt * dt
prev_pos, pos = pos, next_pos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your method is definitely easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're both my methods. I just wasn't sure which one to use. Which one do you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, the second one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree.
print("Time: {:.10f}".format(time)) | ||
print() | ||
|
||
time, vel = stormer_verlet(5, -10, 0.01) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think other methods just return time
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct. I thought that if I already have the vel
variable, I might as well do something with it. Especially in stormer_verlet
in Julia, the vel
variable is assigned a value but it is never actually used anywhere.
But I can get it in line with everything else. I probably should, since I was talking about bringing language implementations closer to each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you are right. The stormer-verlet is basically just verlet with a velocity term. Maybe we should output it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean... My answer to that is in the code =P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, leave it. I think it's fine and an improvement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a good change, it's simpler to read. I'll merge it
Gosh, imagine that, conflicts caused by files being moved around. @Butt4cak3, can you fix these? |
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cheers
During a recent discussion about #243 I noticed that the Python version of our Verlet Integration example code is vastly different from all other implementations. It creates a
Simulation
class and the 3 Verlet algorithms are classes that inherit from thatSimulation
class.I changed the code to more closely match the other language implementations because I think that introducing classes and inheritance to a piece of example code like this is a bit excessive. Tell me what you think.