Add guard against zero gyro radius in drift mover
This commit is contained in:
+26
-41
@@ -135,23 +135,6 @@ void BorisMover::movementStep(
|
|||||||
u_plus_z + (q * electric_field(2) * maximal_time_step_s_) / (2. * m);
|
u_plus_z + (q * electric_field(2) * maximal_time_step_s_) / (2. * m);
|
||||||
const blitz::TinyVector<double, 3> u_new(u_new_x, u_new_y, u_new_z);
|
const blitz::TinyVector<double, 3> u_new(u_new_x, u_new_y, u_new_z);
|
||||||
|
|
||||||
/*
|
|
||||||
Might be slower, but essentially the same code
|
|
||||||
const blitz::TinyVector<double, 3> u_minus =
|
|
||||||
v + (q * electric_field * maximal_time_step_s_) / (2. * m);
|
|
||||||
const double gamma = kinematic::relativisticGamma(u_minus);;
|
|
||||||
const blitz::TinyVector<double, 3> temp_1 =
|
|
||||||
(q * magnetic_field * maximal_time_step_s_) / (2. * m * gamma);
|
|
||||||
const blitz::TinyVector<double, 3> u_prime =
|
|
||||||
u_minus + (blitz::cross(u_minus, temp_1));
|
|
||||||
const blitz::TinyVector<double, 3> temp_2 =
|
|
||||||
(2. * temp_1) / (1. + (blitz::dot(temp_1, temp_1)));
|
|
||||||
const blitz::TinyVector<double, 3> u_plus =
|
|
||||||
u_minus + (blitz::cross(u_prime, temp_2));
|
|
||||||
const blitz::TinyVector<double, 3> u_new =
|
|
||||||
u_plus + (q * electric_field * maximal_time_step_s_) / (2. * m);
|
|
||||||
*/
|
|
||||||
|
|
||||||
particle->velocity(CartesianVector(u_new));
|
particle->velocity(CartesianVector(u_new));
|
||||||
|
|
||||||
const CartesianCoordinate distance(u_new * maximal_time_step_s_);
|
const CartesianCoordinate distance(u_new * maximal_time_step_s_);
|
||||||
@@ -196,8 +179,6 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
const blitz::TinyVector<double, 3> B =
|
const blitz::TinyVector<double, 3> B =
|
||||||
magnetic_field->value(old_position).cartesianEntries(old_position);
|
magnetic_field->value(old_position).cartesianEntries(old_position);
|
||||||
const double B_norm = kinematic::norm(B);
|
const double B_norm = kinematic::norm(B);
|
||||||
// Todo: add calculation of divB here
|
|
||||||
// use Kassiopeia paper for reference
|
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> v_parallel =
|
const blitz::TinyVector<double, 3> v_parallel =
|
||||||
kinematic::parallelVector(old_velocity.cartesianEntries(), B);
|
kinematic::parallelVector(old_velocity.cartesianEntries(), B);
|
||||||
@@ -207,15 +188,6 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
kinematic::perpendicularVector(old_velocity.cartesianEntries(), B);
|
kinematic::perpendicularVector(old_velocity.cartesianEntries(), B);
|
||||||
const double v_perp_norm = kinematic::norm(v_perp);
|
const double v_perp_norm = kinematic::norm(v_perp);
|
||||||
|
|
||||||
const double gyro_radius = particle->mass_kg() * v_perp_norm /
|
|
||||||
(B_norm * std::abs(particle->charge_C()));
|
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> velocity_normal =
|
|
||||||
(-1) * blitz::cross(v_parallel, v_perp);
|
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> offset_to_gyro_center =
|
|
||||||
gyro_radius * velocity_normal / kinematic::norm(velocity_normal);
|
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> v_drift = driftVelocity(B, E);
|
const blitz::TinyVector<double, 3> v_drift = driftVelocity(B, E);
|
||||||
const double v_drift_norm = kinematic::norm(v_drift);
|
const double v_drift_norm = kinematic::norm(v_drift);
|
||||||
|
|
||||||
@@ -225,30 +197,43 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
|
|
||||||
const blitz::TinyVector<double, 3> movement_parallel =
|
const blitz::TinyVector<double, 3> movement_parallel =
|
||||||
v_parallel * timestep;
|
v_parallel * timestep;
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> movement_drift = v_drift * timestep;
|
const blitz::TinyVector<double, 3> movement_drift = v_drift * timestep;
|
||||||
|
|
||||||
const double gyro_frequency =
|
|
||||||
particle->charge_C() * B_norm / particle->mass_kg();
|
|
||||||
const double total_rotation_angle = gyro_frequency * timestep;
|
|
||||||
const blitz::TinyVector<double, 3> movement_around_gyro_center =
|
|
||||||
kinematic::rotateVector(offset_to_gyro_center, v_parallel,
|
|
||||||
total_rotation_angle) -
|
|
||||||
offset_to_gyro_center;
|
|
||||||
|
|
||||||
particle->move(CartesianCoordinate(movement_parallel + movement_drift +
|
|
||||||
movement_around_gyro_center));
|
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> E_parallel =
|
const blitz::TinyVector<double, 3> E_parallel =
|
||||||
kinematic::parallelVector(E, B);
|
kinematic::parallelVector(E, B);
|
||||||
const blitz::TinyVector<double, 3> dv_electric =
|
const blitz::TinyVector<double, 3> dv_electric =
|
||||||
timestep * particle->charge_C() * E_parallel / particle->mass_kg();
|
timestep * particle->charge_C() * E_parallel / particle->mass_kg();
|
||||||
|
|
||||||
|
if (v_perp_norm > 0.) {
|
||||||
|
const double gyro_radius = particle->mass_kg() * v_perp_norm /
|
||||||
|
(B_norm * std::abs(particle->charge_C()));
|
||||||
|
|
||||||
|
const blitz::TinyVector<double, 3> velocity_normal =
|
||||||
|
(-1) * blitz::cross(B, v_perp);
|
||||||
|
|
||||||
|
const blitz::TinyVector<double, 3> offset_to_gyro_center =
|
||||||
|
gyro_radius * velocity_normal / kinematic::norm(velocity_normal);
|
||||||
|
|
||||||
|
const double gyro_frequency =
|
||||||
|
particle->charge_C() * B_norm / particle->mass_kg();
|
||||||
|
const double total_rotation_angle = gyro_frequency * timestep;
|
||||||
|
const blitz::TinyVector<double, 3> movement_around_gyro_center =
|
||||||
|
kinematic::rotateVector(offset_to_gyro_center, B,
|
||||||
|
total_rotation_angle) -
|
||||||
|
offset_to_gyro_center;
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> v_perp_rotated =
|
const blitz::TinyVector<double, 3> v_perp_rotated =
|
||||||
kinematic::rotateVector(v_perp, v_parallel, total_rotation_angle);
|
kinematic::rotateVector(v_perp, B, total_rotation_angle);
|
||||||
|
|
||||||
|
particle->move(CartesianCoordinate(movement_parallel + movement_drift +
|
||||||
|
movement_around_gyro_center));
|
||||||
|
|
||||||
particle->velocity(
|
particle->velocity(
|
||||||
CartesianVector(v_parallel + v_perp_rotated + dv_electric));
|
CartesianVector(v_parallel + v_perp_rotated + dv_electric));
|
||||||
|
} else {
|
||||||
|
particle->move(CartesianCoordinate(movement_parallel + movement_drift));
|
||||||
|
particle->velocity(CartesianVector(v_parallel + dv_electric));
|
||||||
|
}
|
||||||
|
|
||||||
particle->increaseTimeAlive(timestep);
|
particle->increaseTimeAlive(timestep);
|
||||||
particle->increaseTimeInBin(timestep);
|
particle->increaseTimeInBin(timestep);
|
||||||
|
|||||||
Reference in New Issue
Block a user