reduced number of calls to atan2 (in mover only
for the Boris push algo), changed drawing of uniformly distributed unit vector
This commit is contained in:
@@ -62,20 +62,25 @@ double Interaction::microscopicCrossSection(double energy_eV) {
|
|||||||
return cross_section_(energy_eV);
|
return cross_section_(energy_eV);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// think i need to include the magnetic field for it to be really correct
|
||||||
double Interaction::drawCollisionTime(particle::Particle& particle,
|
double Interaction::drawCollisionTime(particle::Particle& particle,
|
||||||
RandomNumbers* generator) {
|
RandomNumbers* generator) {
|
||||||
CartesianVector particle_velocity = particle.velocity();
|
CartesianVector particle_velocity = particle.velocity();
|
||||||
|
CylinderCoordinate particle_cylinderPosition(particle.position().cylinderEntries());
|
||||||
|
|
||||||
target_velocity_ = target_->velocityDistribution()->
|
target_velocity_ = target_->velocityDistribution()->
|
||||||
rollVelocity(particle.position(), generator->engine());
|
rollVelocity(particle.position(), generator->engine());
|
||||||
|
|
||||||
// if no drift velocity is present, then assume target at rest otherwise
|
// // if no drift velocity is present, then assume target at rest otherwise
|
||||||
// use the drift velocity
|
// // use the drift velocity
|
||||||
if(target_->driftVelocity()) {
|
if(target_->driftVelocity()) {
|
||||||
target_velocity_.add(target_->driftVelocity()->driftVelocity(particle.position()),
|
// auto tmp = target_->driftVelocity()->driftVelocity(particle.position());
|
||||||
|
target_velocity_.add(target_->driftVelocity()->driftVelocity(particle_cylinderPosition),
|
||||||
particle.position());
|
particle.position());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// target_velocity_ = CartesianVector(blitz::TinyVector<double, 3>(0.,0.,0.));
|
||||||
|
|
||||||
// masses are irrelevant for the transformation
|
// masses are irrelevant for the transformation
|
||||||
const blitz::TinyVector<double, 3> velocity_target_fixed =
|
const blitz::TinyVector<double, 3> velocity_target_fixed =
|
||||||
kinematic::velocityTargetFixed(particle_velocity.cartesianEntries(),
|
kinematic::velocityTargetFixed(particle_velocity.cartesianEntries(),
|
||||||
@@ -104,8 +109,11 @@ double Interaction::drawCollisionTime(particle::Particle& particle,
|
|||||||
kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg())*
|
kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg())*
|
||||||
UnitConversion::JouleToeV;
|
UnitConversion::JouleToeV;
|
||||||
|
|
||||||
|
// out << "energy collision time: " << energy_eV;
|
||||||
|
|
||||||
const double crosssection = microscopicCrossSection(energy_eV);
|
const double crosssection = microscopicCrossSection(energy_eV);
|
||||||
const double density = target_->densityField()->density(particle.position());
|
// out << "\ncross section: " << crosssection;
|
||||||
|
const double density = target_->densityField()->density(particle_cylinderPosition);
|
||||||
|
|
||||||
// out << "\ninverse mfp: " << crosssection*density << ", sigma: " << crosssection;
|
// out << "\ninverse mfp: " << crosssection*density << ", sigma: " << crosssection;
|
||||||
// out << ", density: " << density;
|
// out << ", density: " << density;
|
||||||
@@ -116,7 +124,7 @@ double Interaction::drawCollisionTime(particle::Particle& particle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const double distance_target_fixed =
|
const double distance_target_fixed =
|
||||||
- 1./(crosssection * density) * log(generator->rollUniform(0.,1.));
|
- 1./(crosssection * density) * log(random_number);
|
||||||
|
|
||||||
// out << "\ndistance in target fixed frame: " << distance_target_fixed;
|
// out << "\ndistance in target fixed frame: " << distance_target_fixed;
|
||||||
|
|
||||||
|
|||||||
+29
-18
@@ -41,11 +41,14 @@ void BorisMover::move(particle::Particle* particle,
|
|||||||
particle->timeAlive();
|
particle->timeAlive();
|
||||||
double leftover_time = collision_time_s;
|
double leftover_time = collision_time_s;
|
||||||
|
|
||||||
auto old_position = particle->position();
|
// auto old_position = particle->position();
|
||||||
|
CartesianCoordinate old_position_cart = particle->position();
|
||||||
|
CylinderCoordinate old_position_cyl(old_position_cart);
|
||||||
|
|
||||||
double old_kinetic_energy = particle->kineticEnergy_eV();
|
double old_kinetic_energy = particle->kineticEnergy_eV();
|
||||||
|
|
||||||
blitz::TinyVector<double, 3> B_old =
|
blitz::TinyVector<double, 3> B_old =
|
||||||
magnetic_field->value(old_position).cartesianEntries(old_position);
|
magnetic_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||||
|
|
||||||
double old_mu;
|
double old_mu;
|
||||||
// if magnetic field is 0 use e_z as a reference for the pitch angle
|
// if magnetic field is 0 use e_z as a reference for the pitch angle
|
||||||
@@ -53,11 +56,10 @@ void BorisMover::move(particle::Particle* particle,
|
|||||||
if (kinematic::norm(B_old) == 0) {
|
if (kinematic::norm(B_old) == 0) {
|
||||||
old_mu = kinematic::cosPitchAngle(
|
old_mu = kinematic::cosPitchAngle(
|
||||||
blitz::TinyVector<double, 3>(0,0,1),
|
blitz::TinyVector<double, 3>(0,0,1),
|
||||||
particle->velocity().cartesianEntries(old_position));
|
particle->velocity().cartesianEntries(old_position_cart));
|
||||||
} else {
|
} else {
|
||||||
old_mu = kinematic::cosPitchAngle(
|
old_mu = kinematic::cosPitchAngle(
|
||||||
magnetic_field->value(old_position).cartesianEntries(old_position),
|
B_old, particle->velocity().cartesianEntries(old_position_cart));
|
||||||
particle->velocity().cartesianEntries(old_position));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double timestep = 0;
|
double timestep = 0;
|
||||||
@@ -78,7 +80,8 @@ void BorisMover::move(particle::Particle* particle,
|
|||||||
while (
|
while (
|
||||||
!(changed_position_bin || changed_energy_bin || left_simulation_domain ||
|
!(changed_position_bin || changed_energy_bin || left_simulation_domain ||
|
||||||
changed_mu_bin || died_in_bin) && (leftover_time > 0.)) {
|
changed_mu_bin || died_in_bin) && (leftover_time > 0.)) {
|
||||||
old_position = particle->position();
|
old_position_cart = particle->position();
|
||||||
|
old_position_cyl = CylinderCoordinate(old_position_cart);
|
||||||
old_kinetic_energy = particle->kineticEnergy_eV();
|
old_kinetic_energy = particle->kineticEnergy_eV();
|
||||||
|
|
||||||
double old_velocity = particle->absoluteVelocity();
|
double old_velocity = particle->absoluteVelocity();
|
||||||
@@ -90,11 +93,11 @@ void BorisMover::move(particle::Particle* particle,
|
|||||||
// double moved_distance = 0.;
|
// double moved_distance = 0.;
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> E =
|
const blitz::TinyVector<double, 3> E =
|
||||||
electric_field->value(old_position).cartesianEntries(old_position);
|
electric_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||||
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_cyl).cartesianEntries(old_position_cart);
|
||||||
const blitz::TinyVector<double, 3> g =
|
const blitz::TinyVector<double, 3> g =
|
||||||
gravity_field->value(old_position).cartesianEntries(old_position);
|
gravity_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||||
|
|
||||||
movementStep(particle, E, B, g, timestep);
|
movementStep(particle, E, B, g, timestep);
|
||||||
particle->increaseTimeAlive(timestep);
|
particle->increaseTimeAlive(timestep);
|
||||||
@@ -113,8 +116,7 @@ void BorisMover::move(particle::Particle* particle,
|
|||||||
new_velocity.cartesianEntries(new_position));
|
new_velocity.cartesianEntries(new_position));
|
||||||
} else {
|
} else {
|
||||||
new_mu = kinematic::cosPitchAngle(
|
new_mu = kinematic::cosPitchAngle(
|
||||||
magnetic_field->value(new_position).cartesianEntries(new_position),
|
B_new, new_velocity.cartesianEntries(new_position));
|
||||||
new_velocity.cartesianEntries(new_position));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
changed_mu_bin =
|
changed_mu_bin =
|
||||||
@@ -123,7 +125,7 @@ void BorisMover::move(particle::Particle* particle,
|
|||||||
|
|
||||||
changed_position_bin =
|
changed_position_bin =
|
||||||
particle->specie()->dynamicDensityField()->changedPositionBin(
|
particle->specie()->dynamicDensityField()->changedPositionBin(
|
||||||
old_position, new_position);
|
old_position_cyl, new_position);
|
||||||
|
|
||||||
changed_energy_bin =
|
changed_energy_bin =
|
||||||
particle->specie()->dynamicDensityField()->changedEnergyBin(
|
particle->specie()->dynamicDensityField()->changedEnergyBin(
|
||||||
@@ -147,9 +149,9 @@ void BorisMover::move(particle::Particle* particle,
|
|||||||
}
|
}
|
||||||
if(died_in_bin)
|
if(died_in_bin)
|
||||||
particle->specie()->dynamicDensityField()->logMovement(
|
particle->specie()->dynamicDensityField()->logMovement(
|
||||||
old_position, old_kinetic_energy, old_mu, particle->weight());
|
old_position_cyl, old_kinetic_energy, old_mu, particle->weight());
|
||||||
// particle->resetTimeInBin();
|
// particle->resetTimeInBin();
|
||||||
particle->specie()->currentCollector()->collect(particle, old_position);
|
particle->specie()->currentCollector()->collect(particle, old_position_cyl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BorisMover::movementStep(
|
void BorisMover::movementStep(
|
||||||
@@ -164,6 +166,7 @@ void BorisMover::movementStep(
|
|||||||
const double m = particle->mass_kg();
|
const double m = particle->mass_kg();
|
||||||
const double q = particle->charge_C();
|
const double q = particle->charge_C();
|
||||||
|
|
||||||
|
/*
|
||||||
const double u_minus_x =
|
const double u_minus_x =
|
||||||
v(0) + (q * electric_field(0) * timestep) / (2. * m)
|
v(0) + (q * electric_field(0) * timestep) / (2. * m)
|
||||||
+ (gravity_field(0) * timestep) / 2.;
|
+ (gravity_field(0) * timestep) / 2.;
|
||||||
@@ -218,11 +221,14 @@ void BorisMover::movementStep(
|
|||||||
u_plus_z + (q * electric_field(2) * timestep) / (2. * m)
|
u_plus_z + (q * electric_field(2) * timestep) / (2. * m)
|
||||||
+ (gravity_field(2) * timestep) / 2.;
|
+ (gravity_field(2) * timestep) / 2.;
|
||||||
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);
|
||||||
|
*/
|
||||||
|
|
||||||
|
blitz::TinyVector<double, 3> acceleration = q * electric_field / m +
|
||||||
|
gravity_field;
|
||||||
/*
|
/*
|
||||||
Might be slower, but essentially the same code
|
Might be slower, but essentially the same code */
|
||||||
const blitz::TinyVector<double, 3> u_minus =
|
const blitz::TinyVector<double, 3> u_minus =
|
||||||
v + (q * electric_field * maximal_time_step_s_) / (2. * m);
|
v + (acceleration * maximal_time_step_s_) / (2.);
|
||||||
const double gamma = kinematic::relativisticGamma(u_minus);;
|
const double gamma = kinematic::relativisticGamma(u_minus);;
|
||||||
const blitz::TinyVector<double, 3> temp_1 =
|
const blitz::TinyVector<double, 3> temp_1 =
|
||||||
(q * magnetic_field * maximal_time_step_s_) / (2. * m * gamma);
|
(q * magnetic_field * maximal_time_step_s_) / (2. * m * gamma);
|
||||||
@@ -233,8 +239,7 @@ void BorisMover::movementStep(
|
|||||||
const blitz::TinyVector<double, 3> u_plus =
|
const blitz::TinyVector<double, 3> u_plus =
|
||||||
u_minus + (blitz::cross(u_prime, temp_2));
|
u_minus + (blitz::cross(u_prime, temp_2));
|
||||||
const blitz::TinyVector<double, 3> u_new =
|
const blitz::TinyVector<double, 3> u_new =
|
||||||
u_plus + (q * electric_field * maximal_time_step_s_) / (2. * m);
|
u_plus + (acceleration * maximal_time_step_s_) / (2.);
|
||||||
*/
|
|
||||||
|
|
||||||
particle->velocity(CartesianVector(u_new));
|
particle->velocity(CartesianVector(u_new));
|
||||||
|
|
||||||
@@ -416,19 +421,23 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
? particle->specie()->dynamicDensityField()
|
? particle->specie()->dynamicDensityField()
|
||||||
->timeResolution()*SimConstants::compare_epsilon
|
->timeResolution()*SimConstants::compare_epsilon
|
||||||
: (max_time_alive - timestep);
|
: (max_time_alive - timestep);
|
||||||
|
#ifdef debug_level3
|
||||||
if (max_time_alive == 0) {
|
if (max_time_alive == 0) {
|
||||||
DEBUG_LEVEL_3("Mover: max_time_alive is 0.");
|
DEBUG_LEVEL_3("Mover: max_time_alive is 0.");
|
||||||
DEBUG_LEVEL_3("Mover: particle time alive: " +
|
DEBUG_LEVEL_3("Mover: particle time alive: " +
|
||||||
std::to_string(particle->timeAlive()));
|
std::to_string(particle->timeAlive()));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
const auto new_position = particle->position();
|
const auto new_position = particle->position();
|
||||||
|
|
||||||
died_in_bin =
|
died_in_bin =
|
||||||
particle->specie()->terminator()->reachedMaxTimeAlive(particle);
|
particle->specie()->terminator()->reachedMaxTimeAlive(particle);
|
||||||
|
#ifdef debug_level3
|
||||||
if(died_in_bin) {
|
if(died_in_bin) {
|
||||||
DEBUG_LEVEL_3("Mover: particle died in bin.");
|
DEBUG_LEVEL_3("Mover: particle died in bin.");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
changed_position_bin =
|
changed_position_bin =
|
||||||
particle->specie()->dynamicDensityField()->changedPositionBin(
|
particle->specie()->dynamicDensityField()->changedPositionBin(
|
||||||
@@ -445,10 +454,12 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
changed_mu_bin = particle->specie()->dynamicDensityField()
|
changed_mu_bin = particle->specie()->dynamicDensityField()
|
||||||
->changedPitchAngleBin(old_mu, new_mu);
|
->changedPitchAngleBin(old_mu, new_mu);
|
||||||
|
|
||||||
|
#ifdef debug_level3
|
||||||
if(changed_mu_bin) {
|
if(changed_mu_bin) {
|
||||||
DEBUG_LEVEL_3("cos(pitch old): " + std::to_string(old_mu));
|
DEBUG_LEVEL_3("cos(pitch old): " + std::to_string(old_mu));
|
||||||
DEBUG_LEVEL_3("cos(pitch new): " + std::to_string(new_mu));
|
DEBUG_LEVEL_3("cos(pitch new): " + std::to_string(new_mu));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
left_simulation_domain =
|
left_simulation_domain =
|
||||||
particle->specie()->terminator()->leftSimulationDomain(particle);
|
particle->specie()->terminator()->leftSimulationDomain(particle);
|
||||||
|
|||||||
@@ -14,10 +14,14 @@ IsotropicDistribution::IsotropicDistribution(
|
|||||||
blitz::TinyVector<double, 3> rollUnitVector(std::mt19937* engine) {
|
blitz::TinyVector<double, 3> rollUnitVector(std::mt19937* engine) {
|
||||||
std::uniform_real_distribution<double> distribution(0.0, 1.0);
|
std::uniform_real_distribution<double> distribution(0.0, 1.0);
|
||||||
const double theta = distribution(*engine) * 2 * M_PI;
|
const double theta = distribution(*engine) * 2 * M_PI;
|
||||||
const double phi = std::acos(1. - 2.*distribution(*engine));
|
// const double phi = std::acos(1. - 2.*distribution(*engine));
|
||||||
return blitz::TinyVector<double, 3>(std::cos(theta) * std::sin(phi),
|
double cosphi = 1. - 2.*distribution(*engine);
|
||||||
std::sin(theta) * std::sin(phi),
|
// phi in [0, pi] --> sin(phi) > 0
|
||||||
std::cos(phi));
|
double sinphi = std::sqrt(1 - cosphi*cosphi);
|
||||||
|
|
||||||
|
return blitz::TinyVector<double, 3>(std::cos(theta) * sinphi,
|
||||||
|
std::sin(theta) * sinphi,
|
||||||
|
cosphi);
|
||||||
}
|
}
|
||||||
|
|
||||||
CartesianVector IsotropicDistribution::rollVelocity(std::mt19937* engine) {
|
CartesianVector IsotropicDistribution::rollVelocity(std::mt19937* engine) {
|
||||||
|
|||||||
Reference in New Issue
Block a user