Corrected errors in Movers; added number of
mpi procs to output
This commit is contained in:
@@ -35,9 +35,12 @@ class BorisMover : public Mover {
|
||||
|
||||
// single update step of the Boris push algorithm
|
||||
// updates moved_distance by the distance the particle moved during the update step
|
||||
// the electric_field and magnetic_field TinyVectors have to contain the electric and
|
||||
// magnetic fields in Cartesian coordinates
|
||||
void movementStep(particle::Particle* particle,
|
||||
const blitz::TinyVector<double, 3>& electric_field,
|
||||
const blitz::TinyVector<double, 3>& magnetic_field,
|
||||
const double timestep,
|
||||
double& moved_distance) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -27,6 +27,9 @@ void SimulationOutput::addDeletionLoggerOutput(OutputTask task) {
|
||||
void SimulationOutput::writeMetaData(
|
||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species) {
|
||||
if (MpiCommunication::mpi_rank == 0) {
|
||||
// write number of processes that have been used in the simulation
|
||||
writer.write(MpiCommunication::mpiSize(), "/NumberProcesses");
|
||||
|
||||
for (auto& pair : species) {
|
||||
writeMetaData(pair.second.get());
|
||||
}
|
||||
|
||||
+25
-16
@@ -24,6 +24,7 @@ void BorisMover::move(particle::Particle* particle,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field) {
|
||||
double leftover_distance = mfp_m;
|
||||
double timestep = 0;
|
||||
|
||||
auto old_position = particle->position();
|
||||
double old_kinetic_energy = particle->kineticEnergy_eV();
|
||||
@@ -44,6 +45,11 @@ void BorisMover::move(particle::Particle* particle,
|
||||
old_position = particle->position();
|
||||
old_kinetic_energy = particle->kineticEnergy_eV();
|
||||
|
||||
double old_velocity = particle->absoluteVelocity();
|
||||
|
||||
timestep = std::min(maximal_time_step_s_,
|
||||
(leftover_distance + SimConstants::random_lower_limit)/old_velocity);
|
||||
|
||||
double moved_distance = 0.;
|
||||
|
||||
const blitz::TinyVector<double, 3> E =
|
||||
@@ -51,9 +57,9 @@ void BorisMover::move(particle::Particle* particle,
|
||||
const blitz::TinyVector<double, 3> B =
|
||||
magnetic_field->value(old_position).cartesianEntries(old_position);
|
||||
|
||||
movementStep(particle, E, B, moved_distance);
|
||||
particle->increaseTimeAlive(maximal_time_step_s_);
|
||||
particle->increaseTimeInBin(maximal_time_step_s_);
|
||||
movementStep(particle, E, B, timestep, moved_distance);
|
||||
particle->increaseTimeAlive(timestep);
|
||||
particle->increaseTimeInBin(timestep);
|
||||
|
||||
auto new_position = particle->position();
|
||||
|
||||
@@ -81,6 +87,7 @@ void BorisMover::movementStep(
|
||||
particle::Particle* particle,
|
||||
const blitz::TinyVector<double, 3>& electric_field,
|
||||
const blitz::TinyVector<double, 3>& magnetic_field,
|
||||
const double timestep,
|
||||
double& moved_distance) const {
|
||||
const blitz::TinyVector<double, 3> v =
|
||||
particle->velocity().cartesianEntries();
|
||||
@@ -88,21 +95,21 @@ void BorisMover::movementStep(
|
||||
const double q = particle->charge_C();
|
||||
|
||||
const double u_minus_x =
|
||||
v(0) + (q * electric_field(0) * maximal_time_step_s_) / (2. * m);
|
||||
v(0) + (q * electric_field(0) * timestep) / (2. * m);
|
||||
const double u_minus_y =
|
||||
v(1) + (q * electric_field(1) * maximal_time_step_s_) / (2. * m);
|
||||
v(1) + (q * electric_field(1) * timestep) / (2. * m);
|
||||
const double u_minus_z =
|
||||
v(2) + (q * electric_field(2) * maximal_time_step_s_) / (2. * m);
|
||||
v(2) + (q * electric_field(2) * timestep) / (2. * m);
|
||||
|
||||
const double gamma = kinematic::relativisticGamma(
|
||||
blitz::TinyVector<double, 3>(u_minus_x, u_minus_y, u_minus_z));
|
||||
|
||||
const double temp_1_x =
|
||||
(q * magnetic_field(0) * maximal_time_step_s_) / (2 * m * gamma);
|
||||
(q * magnetic_field(0) * timestep) / (2 * m * gamma);
|
||||
const double temp_1_y =
|
||||
(q * magnetic_field(1) * maximal_time_step_s_) / (2 * m * gamma);
|
||||
(q * magnetic_field(1) * timestep) / (2 * m * gamma);
|
||||
const double temp_1_z =
|
||||
(q * magnetic_field(2) * maximal_time_step_s_) / (2 * m * gamma);
|
||||
(q * magnetic_field(2) * timestep) / (2 * m * gamma);
|
||||
|
||||
const double u_prime_x =
|
||||
u_minus_x + (u_minus_y * temp_1_z - u_minus_z * temp_1_y);
|
||||
@@ -129,16 +136,16 @@ void BorisMover::movementStep(
|
||||
u_minus_z + (u_prime_x * temp_2_y - u_prime_y * temp_2_x);
|
||||
|
||||
const double u_new_x =
|
||||
u_plus_x + (q * electric_field(0) * maximal_time_step_s_) / (2. * m);
|
||||
u_plus_x + (q * electric_field(0) * timestep) / (2. * m);
|
||||
const double u_new_y =
|
||||
u_plus_y + (q * electric_field(1) * maximal_time_step_s_) / (2. * m);
|
||||
u_plus_y + (q * electric_field(1) * timestep) / (2. * m);
|
||||
const double u_new_z =
|
||||
u_plus_z + (q * electric_field(2) * maximal_time_step_s_) / (2. * m);
|
||||
u_plus_z + (q * electric_field(2) * timestep) / (2. * m);
|
||||
const blitz::TinyVector<double, 3> u_new(u_new_x, u_new_y, u_new_z);
|
||||
|
||||
particle->velocity(CartesianVector(u_new));
|
||||
|
||||
const CartesianCoordinate distance(u_new * maximal_time_step_s_);
|
||||
const CartesianCoordinate distance(u_new * timestep);
|
||||
particle->move(distance);
|
||||
|
||||
moved_distance += std::sqrt(
|
||||
@@ -222,16 +229,18 @@ void DriftMover::move(particle::Particle* particle,
|
||||
const double gyro_radius = particle->mass_kg() * v_perp_norm /
|
||||
(B_norm * particle->charge_C());
|
||||
|
||||
// direction of the magnetic part of the Lorentz force for a positive charge
|
||||
const blitz::TinyVector<double, 3> velocity_normal =
|
||||
(-1) * blitz::cross(B, v_perp);
|
||||
blitz::cross(v_perp, B);
|
||||
|
||||
// calculate the vector pointing from the gyro center to the particle position
|
||||
const blitz::TinyVector<double, 3> offset_to_gyro_center =
|
||||
gyro_radius * velocity_normal / kinematic::norm(velocity_normal);
|
||||
-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;
|
||||
// negative charges gyrate acc to right hand rule (wrt the magnetic field direction)
|
||||
const double total_rotation_angle = -gyro_frequency * timestep;
|
||||
// move the particle around the gyro center
|
||||
const blitz::TinyVector<double, 3> movement_around_gyro_center =
|
||||
kinematic::rotateVector(offset_to_gyro_center, B,
|
||||
|
||||
Reference in New Issue
Block a user