-
-
Notifications
You must be signed in to change notification settings - Fork 360
Update C++ implementations for Verlet algorithms #299
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
} | ||
|
||
int main() { | ||
double time, vel; |
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.
Why not just print straight to console.
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.
It makes the printing lines less cluttered, and it needs to be done anyway for the commands that return pairs, because I don't want to write operator<<
for the pair type.
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.
Overall LGTM
#include <iostream> | ||
#include <utility> | ||
|
||
typedef std::pair<double, double> vpair; |
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.
using vpair = std::pair<double, double>;
is preferable way.
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 I would prefer a simple struct with descriptive fields over the pair anyway. std::pair
is alright for utility types but I dislike it for types that should have some semantic meaning.
} | ||
|
||
int main() { | ||
double time, vel; |
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.
|
||
// Note that depending on the simulation, you might want to have the verlet | ||
// loop outside. | ||
time_vel_pair = velocity_verlet(5.0, -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.
you can use std::tie
@@ -16,8 +19,7 @@ double verlet(double pos, double acc, double dt) { | |||
return time; | |||
} | |||
|
|||
// Simple function for stormer-verlet | |||
double stormer_verlet(double pos, double acc, double dt) { | |||
std::pair<double, double> stormer_verlet(double pos, double acc, double 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.
use vpair
} | ||
|
||
double velocity_verlet(double pos, double acc, double dt) { | ||
std::pair<double, double> velocity_verlet(double pos, double acc, double 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.
use vpair
<< time << std::endl; | ||
|
||
timestep timestep_sv = stormer_verlet(5.0, -10, 0.01); | ||
std::cout << "Time for Stormer Verlet integration is: " \ |
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.
Why is there a backslash?
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 prefer to use an explicit line continuation indicator even when not required.
Done according to #257.