adjusted Drift Mover to be able to handle gradB
This commit is contained in:
+70
-19
@@ -203,10 +203,14 @@ void DriftMover::move(particle::Particle* particle,
|
||||
while (
|
||||
!(changed_position_bin || changed_energy_bin || left_simulation_domain) &&
|
||||
(leftover_distance > 0.) && !(died_in_bin)) {
|
||||
std::stringstream out;
|
||||
old_position = particle->position();
|
||||
old_velocity = particle->velocity();
|
||||
|
||||
out << "cylinder vector pos: " << old_position.cartesianEntries() <<"\n";
|
||||
|
||||
old_kinetic_energy = particle->kineticEnergy_eV();
|
||||
// out << " old kinetic Energy: " << old_kinetic_energy << "\n";
|
||||
|
||||
blitz::TinyVector<double, 3> force_over_charge =
|
||||
electric_field->value(old_position).cartesianEntries(old_position);
|
||||
@@ -218,30 +222,40 @@ void DriftMover::move(particle::Particle* particle,
|
||||
const blitz::TinyVector<double, 3> B =
|
||||
magnetic_field->value(old_position).cartesianEntries(old_position);
|
||||
const double B_norm = kinematic::norm(B);
|
||||
// Todo: add calculation of divB here
|
||||
// use Kassiopeia paper for reference
|
||||
|
||||
out << " B(cyli): " << magnetic_field->value(old_position).cylinderEntries()<<"\n";
|
||||
|
||||
const blitz::TinyVector<double, 3> v_parallel =
|
||||
kinematic::parallelVector(old_velocity.cartesianEntries(), B);
|
||||
const double v_parallel_norm = kinematic::norm(v_parallel);
|
||||
// out << " v_parallel: " << v_parallel << "\n";
|
||||
|
||||
const blitz::TinyVector<double, 3> v_perp =
|
||||
kinematic::perpendicularVector(old_velocity.cartesianEntries(), B);
|
||||
const double v_perp_norm = kinematic::norm(v_perp);
|
||||
out << " v_perp: " << v_perp << "\n";
|
||||
|
||||
// not sure if correct. It might be that the centrifugal force includes only the
|
||||
// perpendicular part of grad(B)
|
||||
// magnetic moment force / q
|
||||
force_over_charge += -(particle->mass_kg()/particle->charge_C() *
|
||||
(v_perp_norm*v_perp_norm/2) *
|
||||
magnetic_field->gradientValue(old_position).cartesianEntries(old_position) /
|
||||
B_norm);
|
||||
const double magnetic_moment = (particle->mass_kg()*(v_perp_norm*v_perp_norm/2))/B_norm;
|
||||
out << " magnetic moment: " << magnetic_moment << "\n";
|
||||
|
||||
force_over_charge += -(magnetic_moment / particle->charge_C() *
|
||||
magnetic_field->gradientValue(old_position).cartesianEntries(old_position));
|
||||
// out << " gradB (cyli): "
|
||||
// << magnetic_field->gradientValue(old_position).cylinderEntries(old_position)
|
||||
// << "\n";
|
||||
// centrifugal force / q
|
||||
force_over_charge += -(particle->mass_kg()/particle->charge_C() *
|
||||
(v_parallel_norm*v_parallel_norm) *
|
||||
kinematic::perpendicularVector(magnetic_field->
|
||||
gradientValue(old_position).cartesianEntries(old_position), B) /
|
||||
B_norm);
|
||||
// debugging
|
||||
// const blitz::TinyVector<double, 3> tmpfrc = -(particle->mass_kg()/particle->charge_C() *
|
||||
// (v_perp_norm*v_perp_norm/2) *
|
||||
// magnetic_field->gradientValue(old_position).cartesianEntries(old_position) /
|
||||
// B_norm);
|
||||
// out << " gradB force/q: " << tmpfrc << "\n";
|
||||
|
||||
const blitz::TinyVector<double, 3> v_drift = driftVelocity(force_over_charge, B);
|
||||
const double v_drift_norm = kinematic::norm(v_drift);
|
||||
@@ -252,19 +266,22 @@ void DriftMover::move(particle::Particle* particle,
|
||||
const double timestep = std::min(
|
||||
stepsize / (v_parallel_norm + v_perp_norm + v_drift_norm),
|
||||
max_time_alive);
|
||||
// out << " timestep: " << timestep << "\n";
|
||||
|
||||
const blitz::TinyVector<double, 3> movement_parallel =
|
||||
v_parallel * timestep;
|
||||
const blitz::TinyVector<double, 3> movement_drift = v_drift * timestep;
|
||||
|
||||
|
||||
const blitz::TinyVector<double, 3> force_over_charge_parallel =
|
||||
kinematic::parallelVector(force_over_charge, B);
|
||||
|
||||
const blitz::TinyVector<double, 3> dv_electric =
|
||||
timestep * particle->charge_C() * force_over_charge_parallel / particle->mass_kg();
|
||||
|
||||
if (v_perp_norm > SimConstants::compare_epsilon) {
|
||||
const double gyro_radius = particle->mass_kg() * v_perp_norm /
|
||||
(B_norm * std::abs(particle->charge_C()));
|
||||
(B_norm * particle->charge_C());
|
||||
// out << " gyroradius: " << gyro_radius << "\n";
|
||||
|
||||
const blitz::TinyVector<double, 3> velocity_normal =
|
||||
(-1) * blitz::cross(B, v_perp);
|
||||
@@ -272,23 +289,56 @@ void DriftMover::move(particle::Particle* particle,
|
||||
const blitz::TinyVector<double, 3> offset_to_gyro_center =
|
||||
gyro_radius * velocity_normal / kinematic::norm(velocity_normal);
|
||||
|
||||
const blitz::TinyVector<double, 3> guiding_center =
|
||||
(offset_to_gyro_center + old_position.cartesianEntries());
|
||||
out << " guiding center: " << guiding_center << "\n";
|
||||
out << " offset gyro: " << offset_to_gyro_center << "\n";
|
||||
out << " movement parallel:" << movement_parallel << "\n";
|
||||
|
||||
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 double total_rotation_angle = -gyro_frequency * timestep;
|
||||
out << " tot rot angle: " << total_rotation_angle << "\n";
|
||||
const blitz::TinyVector<double, 3> movement_around_gyro_center =
|
||||
offset_to_gyro_center - kinematic::rotateVector(offset_to_gyro_center,
|
||||
B, total_rotation_angle);
|
||||
// out << " movement around gyro: " << movement_around_gyro_center << "\n";
|
||||
|
||||
const double v_parallel_new_norm = kinematic::norm(v_parallel + dv_electric);
|
||||
// v_perp by conservation of magn. moment
|
||||
const blitz::TinyVector<double, 3> new_position = old_position.cartesianEntries()
|
||||
+ movement_parallel + movement_drift
|
||||
+ movement_around_gyro_center;
|
||||
const blitz::TinyVector<double, 3> B_new =
|
||||
magnetic_field->value(CartesianCoordinate(new_position))
|
||||
.cartesianEntries(CartesianCoordinate(new_position));
|
||||
|
||||
const double v_perp_new_norm =
|
||||
sqrt(2*magnetic_moment*kinematic::norm(B_new)/particle->mass_kg());
|
||||
|
||||
const blitz::TinyVector<double, 3> v_perp_rotated =
|
||||
kinematic::rotateVector(v_perp, B, total_rotation_angle);
|
||||
// out << " v_perp,rotated: " << v_perp_rotated << "\n";
|
||||
|
||||
DEBUG_LEVEL_3(out.str());
|
||||
|
||||
particle->move(CartesianCoordinate(movement_parallel + movement_drift +
|
||||
movement_around_gyro_center));
|
||||
|
||||
particle->velocity(
|
||||
CartesianVector(v_parallel + v_perp_rotated + dv_electric));
|
||||
// project v_parallel and v_perp onto the new direction of B
|
||||
const blitz::TinyVector<double, 3> v_parallel_new =
|
||||
kinematic::parallelVector(v_parallel + dv_electric, B_new);
|
||||
const blitz::TinyVector<double, 3> v_perpendicular_new =
|
||||
kinematic::perpendicularVector(v_perp_rotated, B_new);
|
||||
|
||||
// use the new direction for the actual velocity (nec. for mu to be const)
|
||||
const blitz::TinyVector<double, 3> v_new =
|
||||
v_parallel_new/kinematic::norm(v_parallel_new) * v_parallel_new_norm +
|
||||
v_perpendicular_new/kinematic::norm(v_perpendicular_new) * v_perp_new_norm;
|
||||
|
||||
particle->velocity(CartesianVector(v_new));
|
||||
} else {
|
||||
// neccessary to adjust as well? i.e. adjust the direction of v_parallel
|
||||
particle->move(CartesianCoordinate(movement_parallel + movement_drift));
|
||||
particle->velocity(CartesianVector(v_parallel + dv_electric));
|
||||
}
|
||||
@@ -313,6 +363,7 @@ void DriftMover::move(particle::Particle* particle,
|
||||
particle->specie()->terminator()->leftSimulationDomain(particle);
|
||||
|
||||
leftover_distance -= stepsize;
|
||||
DEBUG_LEVEL_3(out.str());
|
||||
}
|
||||
|
||||
particle->specie()->dynamicDensityField()->logMovement(
|
||||
|
||||
Reference in New Issue
Block a user