Further development on project 3
This commit is contained in:
@@ -31,6 +31,9 @@ int main(int argc, char* argv[]) {
|
||||
program.add_argument("-V", "--velocity-verlet")
|
||||
.help("Use Velocity Verlet solver instead of RK4")
|
||||
.flag();
|
||||
program.add_argument("-B", "--boris")
|
||||
.help("Use Boris solver instead of RK4")
|
||||
.flag();
|
||||
|
||||
try {
|
||||
program.parse_args(argc, argv);
|
||||
@@ -46,6 +49,7 @@ int main(int argc, char* argv[]) {
|
||||
bool use_euler = program.get<bool>("--euler");
|
||||
bool use_analytical = program.get<bool>("--analytical");
|
||||
bool use_velocity_verlet = program.get<bool>("--velocity-verlet");
|
||||
bool use_boris = program.get<bool>("--boris");
|
||||
|
||||
double B_0 = 1.0; // Tesla
|
||||
double V_0 = 0.025; // Volt
|
||||
@@ -71,52 +75,29 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
double dt = 50e-6 / N; // seconds
|
||||
|
||||
unique_ptr<Solver> solver;
|
||||
string solver_name;
|
||||
|
||||
if (use_euler) {
|
||||
EulerSolver solver(trap, dt);
|
||||
solver.simulate(N);
|
||||
solver.save("results/two_particles_" + std::to_string(n_particles) + (interactions ? "_with_interactions_" : "_no_interactions_") + std::to_string(N) + "_steps_euler");
|
||||
vector<arma::mat> positions = solver.get_positions();
|
||||
cout << "Final position of particle 1: " << endl;
|
||||
cout << positions.back().col(0) << endl;
|
||||
if (n_particles > 1) {
|
||||
cout << "Final position of particle 2: " << endl;
|
||||
cout << positions.back().col(1) << endl;
|
||||
}
|
||||
return 0;
|
||||
solver = make_unique<EulerSolver>(trap, dt);
|
||||
solver_name = "euler";
|
||||
} else if (use_velocity_verlet) {
|
||||
solver = make_unique<VelocityVerletSolver>(trap, dt);
|
||||
solver_name = "velocity_verlet";
|
||||
} else if (use_boris) {
|
||||
solver = make_unique<BorisSolver>(trap, dt);
|
||||
solver_name = "boris";
|
||||
} else if (use_analytical) {
|
||||
solver = make_unique<AnalyticalSolver>(trap, dt);
|
||||
solver_name = "analytical";
|
||||
} else {
|
||||
solver = make_unique<RK4Solver>(trap, dt);
|
||||
solver_name = "rk4";
|
||||
}
|
||||
|
||||
if (use_analytical) {
|
||||
AnalyticalSolver solver(trap, dt);
|
||||
solver.simulate(N);
|
||||
solver.save("results/two_particles_" + std::to_string(n_particles) + (interactions ? "_with_interactions_" : "_no_interactions_") + std::to_string(N) + "_steps_analytical");
|
||||
vector<arma::mat> positions = solver.get_positions();
|
||||
cout << "Final position of particle 1: " << endl;
|
||||
cout << positions.back().col(0) << endl;
|
||||
if (n_particles > 1) {
|
||||
cout << "Final position of particle 2: " << endl;
|
||||
cout << positions.back().col(1) << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (use_velocity_verlet) {
|
||||
VelocityVerletSolver solver(trap, dt);
|
||||
solver.simulate(N);
|
||||
solver.save("results/two_particles_" + std::to_string(n_particles) + (interactions ? "_with_interactions_" : "_no_interactions_") + std::to_string(N) + "_steps_velocity_verlet");
|
||||
vector<arma::mat> positions = solver.get_positions();
|
||||
cout << "Final position of particle 1: " << endl;
|
||||
cout << positions.back().col(0) << endl;
|
||||
if (n_particles > 1) {
|
||||
cout << "Final position of particle 2: " << endl;
|
||||
cout << positions.back().col(1) << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
RK4Solver solver(trap, dt);
|
||||
solver.simulate(N);
|
||||
solver.save("results/two_particles_" + std::to_string(n_particles) + (interactions ? "_with_interactions_" : "_no_interactions_") + std::to_string(N) + "_steps_rk4");
|
||||
vector<arma::mat> positions = solver.get_positions();
|
||||
solver->simulate(N);
|
||||
solver->save("results/two_particles_" + std::to_string(n_particles) + (interactions ? "_with_interactions_" : "_no_interactions_") + std::to_string(N) + "_steps_" + solver_name);
|
||||
vector<arma::mat> positions = solver->get_positions();
|
||||
cout << "Final position of particle 1: " << endl;
|
||||
cout << positions.back().col(0) << endl;
|
||||
if (n_particles > 1) {
|
||||
|
||||
Reference in New Issue
Block a user