Changed distance drawing procedure;
Changed mover to work with times instead of distance; Changed how interactions are done (recombination still tbd)
This commit is contained in:
@@ -15,6 +15,8 @@ class FreeMovement : public Interaction {
|
||||
|
||||
double microscopicCrossSection(double energy_eV);
|
||||
double macroscopicCrossSection(particle::Particle& particle);
|
||||
double drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator);
|
||||
};
|
||||
|
||||
}; // namespace interaction
|
||||
|
||||
@@ -33,12 +33,19 @@ class Interaction {
|
||||
virtual double microscopicCrossSection(double energy_eV);
|
||||
virtual double macroscopicCrossSection(particle::Particle& particle);
|
||||
|
||||
// return the time the given particle can travel in the laboratory frame
|
||||
// before this specific interaction occurs (also stores the velocity of the
|
||||
// target particle)
|
||||
virtual double drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator);
|
||||
|
||||
virtual InteractionOutput performInteraction(particle::Particle& particle,
|
||||
RandomNumbers* generator) = 0;
|
||||
|
||||
protected:
|
||||
std::function<double(double)> cross_section_;
|
||||
std::shared_ptr<species::Specie> target_;
|
||||
CartesianVector target_velocity_;
|
||||
};
|
||||
|
||||
}; // namespace interaction
|
||||
|
||||
@@ -4,10 +4,15 @@
|
||||
#include "simulation/electromagnetic_field.h"
|
||||
#include "simulation/particle.h"
|
||||
|
||||
|
||||
/*
|
||||
change the mfp_m variable to a time_s variable!
|
||||
*/
|
||||
|
||||
class Mover {
|
||||
public:
|
||||
virtual void move(particle::Particle* particle,
|
||||
double mfp_m,
|
||||
double collision_time_s,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field,
|
||||
GravityField* gravity_field) = 0;
|
||||
@@ -18,7 +23,7 @@ class BorisMover : public Mover {
|
||||
BorisMover(double maximal_time_step_s);
|
||||
|
||||
void move(particle::Particle* particle,
|
||||
double mfp_m,
|
||||
double collision_time_s,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field,
|
||||
GravityField* gravity_field);
|
||||
@@ -30,7 +35,7 @@ class BorisMover : public Mover {
|
||||
const blitz::TinyVector<double, 3>& electric_field,
|
||||
const blitz::TinyVector<double, 3>& magnetic_field,
|
||||
const blitz::TinyVector<double, 3>& gravity_field,
|
||||
double& moved_distance,
|
||||
// double& moved_distance,
|
||||
double timestep) const;
|
||||
};
|
||||
|
||||
@@ -39,7 +44,7 @@ class DriftMover : public Mover {
|
||||
DriftMover(double maximal_distance);
|
||||
|
||||
void move(particle::Particle* particle,
|
||||
double mfp_m,
|
||||
double collision_time_s,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field,
|
||||
GravityField* gravity_field);
|
||||
|
||||
@@ -48,6 +48,9 @@ class Particle {
|
||||
|
||||
double weight() const;
|
||||
|
||||
void indexNextInteration(const int index) { index_next_interaction_ = index; };
|
||||
int indexNextInteraction() { return index_next_interaction_; };
|
||||
|
||||
private:
|
||||
double weight_;
|
||||
|
||||
@@ -58,6 +61,9 @@ class Particle {
|
||||
// double time_in_bin_s_;
|
||||
long int interaction_counter_;
|
||||
|
||||
// index of the interaction with the sortest distance (-1 if that's none of them)
|
||||
int index_next_interaction_ = -1;
|
||||
|
||||
std::shared_ptr<species::TrackedSpecie> specie_;
|
||||
long int id_;
|
||||
|
||||
|
||||
@@ -53,6 +53,14 @@ class Simulation {
|
||||
double meanFreePath(particle::Particle& particle, RandomNumbers* random,
|
||||
std::vector<double>& macroscopic_cross_sections_m);
|
||||
|
||||
|
||||
// draw the individual collision times of the possible interactions and return the
|
||||
// minimum of them. Also sets the "nextInteractionIndex" in the particle to the
|
||||
// interaction of the chosen time.
|
||||
double collisionTime(particle::Particle& particle, RandomNumbers* random);
|
||||
interaction::InteractionOutput interact(particle::Particle& particle,
|
||||
RandomNumbers* random);
|
||||
|
||||
interaction::InteractionOutput interact(particle::Particle& particle,
|
||||
RandomNumbers* random,
|
||||
std::vector<double>& macroscopic_cross_sections_m);
|
||||
|
||||
@@ -42,7 +42,7 @@ class Specie {
|
||||
std::string name() const;
|
||||
|
||||
virtual DensityField* densityField() = 0;
|
||||
virtual VelocityDistribution* velocityDistibution() = 0;
|
||||
virtual VelocityDistribution* velocityDistribution() = 0;
|
||||
virtual DriftVelocity* driftVelocity() = 0;
|
||||
|
||||
protected:
|
||||
@@ -67,7 +67,7 @@ class TrackedSpecie : public Specie {
|
||||
std::shared_ptr<DynamicDensityField> density_for_drawing);
|
||||
|
||||
DensityField* densityField();
|
||||
VelocityDistribution* velocityDistibution();
|
||||
VelocityDistribution* velocityDistribution();
|
||||
DriftVelocity* driftVelocity();
|
||||
|
||||
DynamicDensityField* dynamicDensityField();
|
||||
@@ -122,7 +122,7 @@ class BackgroundSpecie : public Specie {
|
||||
std::shared_ptr<DriftVelocity> drift_velocity);
|
||||
|
||||
DensityField* densityField();
|
||||
VelocityDistribution* velocityDistibution();
|
||||
VelocityDistribution* velocityDistribution();
|
||||
DriftVelocity* driftVelocity();
|
||||
|
||||
private:
|
||||
|
||||
@@ -15,14 +15,14 @@ InteractionOutput ChargeExchange::performInteraction(
|
||||
RandomNumbers* generator) {
|
||||
DEBUG_LEVEL_3("Perform charge exchange.");
|
||||
|
||||
const auto x_impact = particle.position();
|
||||
const blitz::TinyVector<double, 3> v_target =
|
||||
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
target_->velocityDistibution()
|
||||
->rollVelocity(x_impact, generator->engine())
|
||||
.cartesianEntries();
|
||||
// const auto x_impact = particle.position();
|
||||
// const blitz::TinyVector<double, 3> v_target =
|
||||
// target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
// target_->velocityDistribution()
|
||||
// ->rollVelocity(x_impact, generator->engine())
|
||||
// .cartesianEntries();
|
||||
|
||||
particle.velocity(CartesianVector(v_target));
|
||||
particle.velocity(CartesianVector(target_velocity_));
|
||||
return InteractionOutput();
|
||||
}
|
||||
};
|
||||
@@ -19,17 +19,17 @@ InteractionOutput ClusterFormation::performInteraction(
|
||||
RandomNumbers* generator) {
|
||||
DEBUG_LEVEL_3("Perform cluster formation.");
|
||||
const auto x_impact = particle.position();
|
||||
const blitz::TinyVector<double, 3> v_target =
|
||||
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
target_->velocityDistibution()
|
||||
->rollVelocity(x_impact, generator->engine())
|
||||
.cartesianEntries();
|
||||
// const blitz::TinyVector<double, 3> v_target =
|
||||
// target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
// target_->velocityDistribution()
|
||||
// ->rollVelocity(x_impact, generator->engine())
|
||||
// .cartesianEntries();
|
||||
const double energy_eV =
|
||||
kinematic::kineticEnergy(v_target, target_->mass_kg()) *
|
||||
kinematic::kineticEnergy(target_velocity_.cartesianEntries(), target_->mass_kg()) *
|
||||
UnitConversion::JouleToeV;
|
||||
const blitz::TinyVector<double, 3> v_cluster =
|
||||
kinematic::velocity(energy_eV, product_->mass_kg()) *
|
||||
v_target / kinematic::norm(v_target);
|
||||
target_velocity_.cartesianEntries() / kinematic::norm(target_velocity_.cartesianEntries());
|
||||
// product inherits weight of the main particle (not the target, which is
|
||||
// assumed to be just a density, i.e. has no weight of its own)
|
||||
particle::Particle cluster(product_, x_impact, CartesianVector(v_cluster),
|
||||
|
||||
@@ -21,15 +21,16 @@ InteractionOutput ElasticScattering::performInteraction(
|
||||
DEBUG_LEVEL_3("Perform elastic scattering.");
|
||||
const blitz::TinyVector<double, 3> v_impact =
|
||||
particle.velocity().cartesianEntries();
|
||||
const auto x_impact = particle.position();
|
||||
const blitz::TinyVector<double, 3> v_target =
|
||||
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
target_->velocityDistibution()
|
||||
->rollVelocity(x_impact, generator->engine())
|
||||
.cartesianEntries();
|
||||
// const auto x_impact = particle.position();
|
||||
// const blitz::TinyVector<double, 3> v_target =
|
||||
// target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
// target_->velocityDistribution()
|
||||
// ->rollVelocity(x_impact, generator->engine())
|
||||
// .cartesianEntries();
|
||||
|
||||
const blitz::TinyVector<double, 3> v_laboratory =
|
||||
kinematic::velocityTargetFixed(v_impact, v_target, particle.mass_kg(),
|
||||
kinematic::velocityTargetFixed(v_impact, target_velocity_.cartesianEntries(),
|
||||
particle.mass_kg(),
|
||||
target_->mass_kg());
|
||||
|
||||
const double E_kin =
|
||||
@@ -41,8 +42,8 @@ InteractionOutput ElasticScattering::performInteraction(
|
||||
|
||||
const blitz::TinyVector<double, 3> v_impact_new =
|
||||
kinematic::rotateVelocityInCenterOfMassFrame(
|
||||
v_impact, v_target, particle.mass_kg(), target_->mass_kg(), theta,
|
||||
phi);
|
||||
v_impact, target_velocity_.cartesianEntries(), particle.mass_kg(),
|
||||
target_->mass_kg(), theta, phi);
|
||||
|
||||
particle.velocity(CartesianVector(v_impact_new));
|
||||
// no Gyrocentrum movement because boris push is used;
|
||||
|
||||
@@ -23,4 +23,8 @@ double FreeMovement::macroscopicCrossSection(particle::Particle& particle) {
|
||||
// returns a very small number, so the interaction will only be
|
||||
return SimConstants::minimal_macroscopic_cross_section;
|
||||
}
|
||||
double FreeMovement::drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
}; // namespace interaction
|
||||
@@ -35,22 +35,26 @@ InteractionOutput ElectronIonization::performInteraction(
|
||||
particle.velocity().cartesianEntries();
|
||||
const auto x_impact = particle.position();
|
||||
|
||||
blitz::TinyVector<double, 3> v_target;
|
||||
blitz::TinyVector<double, 3> v_laboratory;
|
||||
double E_impact;
|
||||
do {
|
||||
v_target =
|
||||
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
target_->velocityDistibution()
|
||||
->rollVelocity(x_impact, generator->engine())
|
||||
.cartesianEntries();
|
||||
// blitz::TinyVector<double, 3> v_target;
|
||||
blitz::TinyVector<double, 3> v_laboratory = kinematic::velocityTargetFixed(
|
||||
v_impact, target_velocity_.cartesianEntries(), particle.mass_kg(), target_->mass_kg()
|
||||
);
|
||||
|
||||
v_laboratory = kinematic::velocityTargetFixed(
|
||||
v_impact, v_target, particle.mass_kg(), target_->mass_kg());
|
||||
double E_impact = kinematic::kineticEnergy(v_laboratory, particle.mass_kg()) *
|
||||
UnitConversion::JouleToeV;
|
||||
// do {
|
||||
// v_target =
|
||||
// target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
// target_->velocityDistribution()
|
||||
// ->rollVelocity(x_impact, generator->engine())
|
||||
// .cartesianEntries();
|
||||
|
||||
E_impact = kinematic::kineticEnergy(v_laboratory, particle.mass_kg()) *
|
||||
UnitConversion::JouleToeV;
|
||||
} while (E_impact <= ionization_energy_eV_);
|
||||
// v_laboratory = kinematic::velocityTargetFixed(
|
||||
// v_impact, v_target, particle.mass_kg(), target_->mass_kg());
|
||||
|
||||
// E_impact = kinematic::kineticEnergy(v_laboratory, particle.mass_kg()) *
|
||||
// UnitConversion::JouleToeV;
|
||||
// } while (E_impact <= ionization_energy_eV_);
|
||||
|
||||
const double E_impact_new =
|
||||
energy_distribution_->rollImpactParticleEnergyAfterCollision(E_impact,
|
||||
@@ -83,13 +87,13 @@ InteractionOutput ElectronIonization::performInteraction(
|
||||
kinematic::rotateVector(v_lab_norm, azimuth_angle_impact_new,
|
||||
polar_angle_impact_new) *
|
||||
v_lab_impact_new +
|
||||
v_target;
|
||||
target_velocity_.cartesianEntries();
|
||||
|
||||
const blitz::TinyVector<double, 3> v_ejected =
|
||||
kinematic::rotateVector(v_lab_norm, azimuth_angle_ejected,
|
||||
polar_angle_ejected) *
|
||||
v_lab_ejected +
|
||||
v_target;
|
||||
target_velocity_.cartesianEntries();
|
||||
|
||||
particle.velocity(v_impact_new);
|
||||
|
||||
@@ -101,7 +105,7 @@ InteractionOutput ElectronIonization::performInteraction(
|
||||
output.add(
|
||||
particle::Particle(electron_, x_impact, CartesianVector(v_ejected),
|
||||
time_birth, weight_parent));
|
||||
output.add(particle::Particle(ion_, x_impact, CartesianVector(v_target),
|
||||
output.add(particle::Particle(ion_, x_impact, target_velocity_,
|
||||
time_birth, weight_parent));
|
||||
|
||||
return output;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "simulation/energy_binning.h"
|
||||
#include <math.h>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
std::vector<double> generateLogBinBorders(double bin_min,
|
||||
double bin_max,
|
||||
@@ -24,10 +26,11 @@ std::vector<double> generateLinearBinBorders(double bin_min,
|
||||
const double bin_size = (bin_max - bin_min) / num_bins;
|
||||
|
||||
std::vector<double> bin_borders;
|
||||
for (int i = 0; i <= num_bins; ++i) {
|
||||
for (int i = 0; i < num_bins; ++i) {
|
||||
const double bin_border = bin_size * i + bin_min;
|
||||
bin_borders.push_back(bin_border);
|
||||
}
|
||||
bin_borders.push_back(bin_max);
|
||||
return bin_borders;
|
||||
}
|
||||
|
||||
@@ -66,7 +69,6 @@ PitchAngleBinning::PitchAngleBinning(int num_bins) :
|
||||
pitch_angle_bin_borders_(generateLinearBinBorders(-1, 1, num_bins)) {}
|
||||
|
||||
int PitchAngleBinning::bin(double pitch_angle) const {
|
||||
|
||||
auto const it = std::lower_bound(pitch_angle_bin_borders_.begin(),
|
||||
pitch_angle_bin_borders_.end(),
|
||||
pitch_angle);
|
||||
|
||||
@@ -29,7 +29,8 @@ std::vector<particle::Particle> InteractionOutput::newParticles() {
|
||||
|
||||
Interaction::Interaction(std::function<double(double)> cross_section,
|
||||
std::shared_ptr<species::Specie> target)
|
||||
: cross_section_(cross_section), target_(target) {}
|
||||
: cross_section_(cross_section), target_(target),
|
||||
target_velocity_(blitz::TinyVector<double, 3> (0,0,0)) {};
|
||||
|
||||
// assumes that v_particle >> v_target
|
||||
double Interaction::macroscopicCrossSection(particle::Particle& particle) {
|
||||
@@ -61,4 +62,69 @@ double Interaction::microscopicCrossSection(double energy_eV) {
|
||||
return cross_section_(energy_eV);
|
||||
}
|
||||
|
||||
double Interaction::drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
CartesianVector particle_velocity = particle.velocity();
|
||||
|
||||
target_velocity_ = target_->velocityDistribution()->
|
||||
rollVelocity(particle.position(), generator->engine());
|
||||
|
||||
// if no drift velocity is present, then assume target at rest otherwise
|
||||
// use the drift velocity
|
||||
if(target_->driftVelocity()) {
|
||||
target_velocity_.add(target_->driftVelocity()->driftVelocity(particle.position()),
|
||||
particle.position());
|
||||
}
|
||||
|
||||
// masses are irrelevant for the transformation
|
||||
const blitz::TinyVector<double, 3> velocity_target_fixed =
|
||||
kinematic::velocityTargetFixed(particle_velocity.cartesianEntries(),
|
||||
target_velocity_.cartesianEntries(), 0, 0);
|
||||
|
||||
const double relative_velocity = kinematic::norm(velocity_target_fixed);
|
||||
|
||||
// std::stringstream out;
|
||||
// out << "particle "<< particle.specie()->name() <<" velocity: "
|
||||
// << particle_velocity.cartesianEntries();
|
||||
// out << "\ntarget "<< target_->name() <<" velocity: "
|
||||
// << target_velocity_.cartesianEntries();
|
||||
// out << "\nabsolute relative velocity: " << relative_velocity;
|
||||
|
||||
// check if the relative velocity is smaller than an epsilon compared to the larger
|
||||
// of the two present velocities (to avoid division by 0 if either is 0) probably
|
||||
// a better version possible
|
||||
if(relative_velocity/std::max(
|
||||
kinematic::norm(particle_velocity.cartesianEntries()),
|
||||
kinematic::norm(target_velocity_.cartesianEntries())
|
||||
) < SimConstants::compare_epsilon) {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
|
||||
const double energy_eV =
|
||||
kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg())*
|
||||
UnitConversion::JouleToeV;
|
||||
|
||||
const double crosssection = microscopicCrossSection(energy_eV);
|
||||
const double density = target_->densityField()->density(particle.position());
|
||||
|
||||
// out << "\ninverse mfp: " << crosssection*density << ", sigma: " << crosssection;
|
||||
// out << ", density: " << density;
|
||||
|
||||
const double random_number = generator->rollUniform(0.,1.);
|
||||
if (random_number == 0) {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
|
||||
const double distance_target_fixed =
|
||||
- 1./(crosssection * density) * log(generator->rollUniform(0.,1.));
|
||||
|
||||
// out << "\ndistance in target fixed frame: " << distance_target_fixed;
|
||||
|
||||
const double time = distance_target_fixed / relative_velocity;
|
||||
// out << "\ntime before collision: " << time;
|
||||
// DEBUG_LEVEL_3(out.str());
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
}; // namespace interaction
|
||||
+19
-18
@@ -21,7 +21,7 @@ BorisMover::BorisMover(double maximal_time_step_s)
|
||||
|
||||
// TBD: include F_g (simply add to electric force)
|
||||
void BorisMover::move(particle::Particle* particle,
|
||||
double mfp_m,
|
||||
double collision_time_s,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field,
|
||||
GravityField* gravity_field) {
|
||||
@@ -39,7 +39,7 @@ void BorisMover::move(particle::Particle* particle,
|
||||
// density)
|
||||
double max_time_alive = particle->specie()->dynamicDensityField()->physicalTime() -
|
||||
particle->timeAlive();
|
||||
double leftover_distance = mfp_m;
|
||||
double leftover_time = collision_time_s;
|
||||
|
||||
auto old_position = particle->position();
|
||||
double old_kinetic_energy = particle->kineticEnergy_eV();
|
||||
@@ -77,17 +77,17 @@ void BorisMover::move(particle::Particle* particle,
|
||||
|
||||
while (
|
||||
!(changed_position_bin || changed_energy_bin || left_simulation_domain ||
|
||||
changed_mu_bin || died_in_bin) && (leftover_distance > 0.)) {
|
||||
changed_mu_bin || died_in_bin) && (leftover_time > 0.)) {
|
||||
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);
|
||||
timestep = std::min(maximal_time_step_s_, leftover_time);
|
||||
timestep = std::min(timestep, max_distance / old_velocity);
|
||||
timestep = std::min(timestep, max_time_alive);
|
||||
|
||||
double moved_distance = 0.;
|
||||
// can probably be removed
|
||||
// double moved_distance = 0.;
|
||||
|
||||
const blitz::TinyVector<double, 3> E =
|
||||
electric_field->value(old_position).cartesianEntries(old_position);
|
||||
@@ -96,7 +96,7 @@ void BorisMover::move(particle::Particle* particle,
|
||||
const blitz::TinyVector<double, 3> g =
|
||||
gravity_field->value(old_position).cartesianEntries(old_position);
|
||||
|
||||
movementStep(particle, E, B, g, moved_distance, timestep);
|
||||
movementStep(particle, E, B, g, timestep);
|
||||
particle->increaseTimeAlive(timestep);
|
||||
// particle->increaseTimeInBin(timestep);
|
||||
|
||||
@@ -135,7 +135,7 @@ void BorisMover::move(particle::Particle* particle,
|
||||
died_in_bin =
|
||||
particle->specie()->terminator()->reachedMaxTimeAlive(particle);
|
||||
|
||||
leftover_distance -= moved_distance;
|
||||
leftover_time -= timestep;
|
||||
|
||||
// if max_time_alive == 0 but the difference between the time alive and
|
||||
// the endtime > 0 (think can happen due to numerical accuracy)
|
||||
@@ -157,7 +157,7 @@ void BorisMover::movementStep(
|
||||
const blitz::TinyVector<double, 3>& electric_field,
|
||||
const blitz::TinyVector<double, 3>& magnetic_field,
|
||||
const blitz::TinyVector<double, 3>& gravity_field,
|
||||
double& moved_distance,
|
||||
// double& moved_distance,
|
||||
double timestep) const {
|
||||
const blitz::TinyVector<double, 3> v =
|
||||
particle->velocity().cartesianEntries();
|
||||
@@ -241,8 +241,8 @@ void BorisMover::movementStep(
|
||||
const CartesianCoordinate distance(u_new * timestep);
|
||||
particle->move(distance);
|
||||
|
||||
moved_distance += std::sqrt(
|
||||
blitz::dot(distance.cartesianEntries(), distance.cartesianEntries()));
|
||||
// moved_distance += std::sqrt(
|
||||
// blitz::dot(distance.cartesianEntries(), distance.cartesianEntries()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -253,11 +253,11 @@ DriftMover::DriftMover(double maximal_distance)
|
||||
: maximal_distance_m_(maximal_distance){};
|
||||
|
||||
void DriftMover::move(particle::Particle* particle,
|
||||
double mfp_m,
|
||||
double collision_time_s,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field,
|
||||
GravityField* gravity_field) {
|
||||
double leftover_distance = mfp_m;
|
||||
double leftover_time = collision_time_s;
|
||||
|
||||
auto old_position = particle->position();
|
||||
auto old_velocity = particle->velocity();
|
||||
@@ -280,7 +280,7 @@ void DriftMover::move(particle::Particle* particle,
|
||||
while (
|
||||
!(changed_position_bin || changed_energy_bin || changed_mu_bin
|
||||
|| left_simulation_domain) &&
|
||||
(leftover_distance > 0.) && !(died_in_bin)) {
|
||||
(leftover_time > 0.) && !(died_in_bin)) {
|
||||
old_position = particle->position();
|
||||
old_velocity = particle->velocity();
|
||||
|
||||
@@ -324,14 +324,15 @@ void DriftMover::move(particle::Particle* particle,
|
||||
driftVelocity(force_over_charge, B);
|
||||
const double v_drift_norm = kinematic::norm(v_drift);
|
||||
|
||||
const double stepsize = std::min(leftover_distance, maximal_distance_m_);
|
||||
// const double stepsize = std::min(leftover_distance, maximal_distance_m_);
|
||||
// guard against very large timesteps i.e. v ~ 0 -> timestep = Inf
|
||||
// should be a very rare case (but has happend)
|
||||
const double timestep = std::min(
|
||||
stepsize / std::sqrt(v_parallel_norm*v_parallel_norm +
|
||||
double timestep = std::min(
|
||||
maximal_distance_m_ / std::sqrt(v_parallel_norm*v_parallel_norm +
|
||||
v_perp_norm*v_perp_norm +
|
||||
v_drift_norm*v_drift_norm),
|
||||
max_time_alive);
|
||||
timestep = std::min(timestep, collision_time_s);
|
||||
|
||||
const blitz::TinyVector<double, 3> movement_parallel =
|
||||
v_parallel * timestep;
|
||||
@@ -452,7 +453,7 @@ void DriftMover::move(particle::Particle* particle,
|
||||
left_simulation_domain =
|
||||
particle->specie()->terminator()->leftSimulationDomain(particle);
|
||||
|
||||
leftover_distance -= stepsize;
|
||||
// leftover_distance -= stepsize;
|
||||
}
|
||||
|
||||
// only log a particle in the bin where its movement ends, i.e. if
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <numeric>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "constants/sim_constants.h"
|
||||
#include "simulation/cpu_synchronizer.h"
|
||||
#include "simulation/current_collector.h"
|
||||
@@ -388,12 +389,13 @@ void Simulation::processUntilTermination(
|
||||
std::vector<double> macroscopic_cross_sections_m;
|
||||
|
||||
SimulationTimer::eventStartPoint(std::string("MFP calculation"));
|
||||
const double mfp_m = meanFreePath(particle, random_.get(),
|
||||
macroscopic_cross_sections_m);
|
||||
// const double mfp_m = meanFreePath(particle, random_.get(),
|
||||
// macroscopic_cross_sections_m);
|
||||
const double collision_time = collisionTime(particle, random_.get());
|
||||
SimulationTimer::eventStopPoint(std::string("MFP calculation"));
|
||||
|
||||
SimulationTimer::eventStartPoint(std::string("Mover"));
|
||||
particle.specie()->mover()->move(&particle, mfp_m, electric_field_.get(),
|
||||
particle.specie()->mover()->move(&particle, collision_time, electric_field_.get(),
|
||||
magnetic_field_.get(), gravity_field_.get());
|
||||
SimulationTimer::eventStopPoint(std::string("Mover"));
|
||||
|
||||
@@ -451,8 +453,8 @@ void Simulation::processUntilTermination(
|
||||
#endif
|
||||
|
||||
SimulationTimer::eventStartPoint(std::string("Interaction"));
|
||||
interaction::InteractionOutput output = interact(particle, random_.get(),
|
||||
macroscopic_cross_sections_m);
|
||||
interaction::InteractionOutput output = interact(particle, random_.get());//,
|
||||
// macroscopic_cross_sections_m);
|
||||
SimulationTimer::eventStopPoint(std::string("Interaction"));
|
||||
|
||||
particle.increaseInteractionCounter();
|
||||
@@ -501,6 +503,43 @@ double Simulation::meanFreePath(particle::Particle& particle,
|
||||
}
|
||||
}
|
||||
|
||||
// maybe rewrite to s.t. the min_element part can be removed (together with the
|
||||
// algorithm lib)
|
||||
double Simulation::collisionTime(particle::Particle& particle, RandomNumbers* random) {
|
||||
std::vector<double> collision_times;
|
||||
double tmp;
|
||||
|
||||
for(auto& interaction : particle.specie()->interactions()) {
|
||||
tmp = interaction->drawCollisionTime(particle, random);
|
||||
collision_times.push_back(tmp);
|
||||
}
|
||||
|
||||
std::stringstream out;
|
||||
out << "collision times:\n[ ";
|
||||
|
||||
for(auto& element : collision_times) {
|
||||
out << element << " ";
|
||||
}
|
||||
out << "]";
|
||||
|
||||
auto min_iterator = std::min_element(collision_times.begin(), collision_times.end());
|
||||
|
||||
particle.indexNextInteration((min_iterator - collision_times.begin()));
|
||||
|
||||
out << "\nmin value: " << *min_iterator;
|
||||
out << "\nindexNextInteraction: " << particle.indexNextInteraction();
|
||||
|
||||
DEBUG_LEVEL_3(out.str());
|
||||
|
||||
return *min_iterator;
|
||||
}
|
||||
|
||||
interaction::InteractionOutput Simulation::interact(
|
||||
particle::Particle& particle, RandomNumbers* random) {
|
||||
return particle.specie()->interactions().at(particle.indexNextInteraction())
|
||||
->performInteraction(particle, random);
|
||||
}
|
||||
|
||||
interaction::InteractionOutput Simulation::interact(
|
||||
particle::Particle& particle,
|
||||
RandomNumbers* random,
|
||||
|
||||
@@ -64,9 +64,13 @@ DensityField* TrackedSpecie::densityField() {
|
||||
return density_field_.get();
|
||||
}
|
||||
|
||||
VelocityDistribution* TrackedSpecie::velocityDistibution() {
|
||||
return velocity_distribution_.get();
|
||||
VelocityDistribution* TrackedSpecie::velocityDistribution() {
|
||||
// return velocity_distribution_.get();
|
||||
// return the distribution from the calculated density distribution instead of
|
||||
// the one (potentially) given at construction.
|
||||
return velocity_distribution_from_density_.get();
|
||||
}
|
||||
|
||||
DriftVelocity* TrackedSpecie::driftVelocity() {
|
||||
return drift_velocity_.get();
|
||||
}
|
||||
@@ -144,7 +148,7 @@ BackgroundSpecie::BackgroundSpecie(
|
||||
DensityField* BackgroundSpecie::densityField() {
|
||||
return density_field_.get();
|
||||
}
|
||||
VelocityDistribution* BackgroundSpecie::velocityDistibution() {
|
||||
VelocityDistribution* BackgroundSpecie::velocityDistribution() {
|
||||
return velocity_distribution_.get();
|
||||
}
|
||||
DriftVelocity* BackgroundSpecie::driftVelocity() {
|
||||
|
||||
Reference in New Issue
Block a user