Update formatting
This commit is contained in:
@@ -45,8 +45,9 @@ PenningTrap::PenningTrap(std::vector<Particle> particles, double B_0,
|
||||
|
||||
void PenningTrap::set_pertubation(double f, double omega_V)
|
||||
{
|
||||
this->perturbation
|
||||
= [f, omega_V](double t) { return f * std::cos(omega_V * t); };
|
||||
this->perturbation = [f, omega_V](double t) {
|
||||
return f * std::cos(omega_V * t);
|
||||
};
|
||||
}
|
||||
|
||||
void PenningTrap::reinitialize(double f, double omega_V, double t)
|
||||
@@ -167,9 +168,9 @@ void PenningTrap::evolve_RK4(double dt, bool particle_interaction)
|
||||
std::vector<Particle> original_particles = this->particles;
|
||||
std::vector<Particle> tmp_particles = this->particles;
|
||||
|
||||
vec_3d (PenningTrap::*force)(uint)
|
||||
= particle_interaction ? &PenningTrap::total_force
|
||||
: &PenningTrap::total_force_external;
|
||||
vec_3d (PenningTrap::*force)(uint) =
|
||||
particle_interaction ? &PenningTrap::total_force
|
||||
: &PenningTrap::total_force_external;
|
||||
|
||||
size_t size = this->particles.size();
|
||||
|
||||
@@ -188,10 +189,10 @@ void PenningTrap::evolve_RK4(double dt, bool particle_interaction)
|
||||
this->k_v[i][j] = (this->*force)(j) / this->particles[j].m;
|
||||
this->k_r[i][j] = this->particles[j].v_vec;
|
||||
|
||||
tmp_particles[j].v_vec
|
||||
= original_particles[j].v_vec + this->v_func(i, j, dt);
|
||||
tmp_particles[j].r_vec
|
||||
= original_particles[j].r_vec + this->r_func(i, j, dt);
|
||||
tmp_particles[j].v_vec =
|
||||
original_particles[j].v_vec + this->v_func(i, j, dt);
|
||||
tmp_particles[j].r_vec =
|
||||
original_particles[j].r_vec + this->r_func(i, j, dt);
|
||||
}
|
||||
this->particles = tmp_particles;
|
||||
}
|
||||
@@ -205,9 +206,9 @@ void PenningTrap::evolve_forward_euler(double dt, bool particle_interaction)
|
||||
vec_3d force_res[size];
|
||||
Particle *p;
|
||||
|
||||
vec_3d (PenningTrap::*force)(uint)
|
||||
= particle_interaction ? &PenningTrap::total_force
|
||||
: &PenningTrap::total_force_external;
|
||||
vec_3d (PenningTrap::*force)(uint) =
|
||||
particle_interaction ? &PenningTrap::total_force
|
||||
: &PenningTrap::total_force_external;
|
||||
|
||||
// Calculating the force for each particle is independent and therefore
|
||||
// a good candidate for parallel execution
|
||||
@@ -220,9 +221,8 @@ void PenningTrap::evolve_forward_euler(double dt, bool particle_interaction)
|
||||
// this as well
|
||||
#pragma omp parallel for private(p)
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
p = &this->particles[i];
|
||||
p->r_vec += dt * p->v_vec;
|
||||
p->v_vec += dt * force_res[i] / p->m;
|
||||
p->r_vec += dt * this->particles[i].v_vec;
|
||||
p->v_vec += dt * force_res[i] / this->particles[i].m;
|
||||
}
|
||||
|
||||
this->t += dt;
|
||||
@@ -241,11 +241,9 @@ simulation_t PenningTrap::simulate(double time, uint steps, std::string method,
|
||||
void (PenningTrap::*func)(double, bool);
|
||||
if (method == "rk4") {
|
||||
func = &PenningTrap::evolve_RK4;
|
||||
}
|
||||
else if (method == "euler") {
|
||||
} else if (method == "euler") {
|
||||
func = &PenningTrap::evolve_forward_euler;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
std::cout << "Not a valid method!" << std::endl;
|
||||
abort();
|
||||
}
|
||||
@@ -273,8 +271,8 @@ void PenningTrap::write_simulation_to_dir(std::string path, double time,
|
||||
abort();
|
||||
}
|
||||
|
||||
simulation_t res
|
||||
= this->simulate(time, steps, method, particle_interaction);
|
||||
simulation_t res =
|
||||
this->simulate(time, steps, method, particle_interaction);
|
||||
|
||||
std::ofstream ofile;
|
||||
|
||||
@@ -308,11 +306,9 @@ double PenningTrap::fraction_of_particles_left(double time, uint steps,
|
||||
void (PenningTrap::*func)(double, bool);
|
||||
if (method == "rk4") {
|
||||
func = &PenningTrap::evolve_RK4;
|
||||
}
|
||||
else if (method == "euler") {
|
||||
} else if (method == "euler") {
|
||||
func = &PenningTrap::evolve_forward_euler;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
std::cout << "Not a valid method!" << std::endl;
|
||||
abort();
|
||||
}
|
||||
@@ -323,7 +319,7 @@ double PenningTrap::fraction_of_particles_left(double time, uint steps,
|
||||
|
||||
int particles_left = 0;
|
||||
|
||||
// A reduction is perfect here
|
||||
// A reduction is perfect here
|
||||
#pragma omp parallel for reduction(+ : particles_left)
|
||||
for (size_t i = 0; i < this->particles.size(); i++) {
|
||||
if (arma::norm(this->particles[i].r_vec) < this->d) {
|
||||
|
||||
Reference in New Issue
Block a user