Skip to content

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

Merged
merged 2 commits into from
Jul 21, 2018
Merged

Reimplemented Verlet Integration in Python #256

merged 2 commits into from
Jul 21, 2018

Conversation

Butt4cak3
Copy link
Contributor

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 that Simulation 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.

self.acc = acc
while pos > 0:
time += dt
prev_pos, pos = pos, pos * 2 - prev_pos + acc * dt * dt
Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, the second one.

Copy link
Contributor Author

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)
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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.

@Gathros Gathros added the Implementation Edit This provides an edit to an algorithm implementation. (Code and maybe md files are edited.) label Jul 16, 2018
@Butt4cak3 Butt4cak3 requested review from zsparal and jiegillet July 17, 2018 12:25
jiegillet
jiegillet previously approved these changes Jul 21, 2018
Copy link
Member

@jiegillet jiegillet left a 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

@jiegillet
Copy link
Member

jiegillet commented Jul 21, 2018

Gosh, imagine that, conflicts caused by files being moved around. @Butt4cak3, can you fix these?

@Butt4cak3
Copy link
Contributor Author

Done.

Copy link
Member

@jiegillet jiegillet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers

@jiegillet jiegillet merged commit f76495a into master Jul 21, 2018
@Butt4cak3 Butt4cak3 deleted the verlet-python branch July 21, 2018 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation Edit This provides an edit to an algorithm implementation. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants