From b28245f1a84a03fa704c4a2a930c0cc50352480d Mon Sep 17 00:00:00 2001 From: csendlinger Date: Wed, 14 May 2025 16:41:19 +0200 Subject: [PATCH] Bin based drawing implemented (debug output not yet removed) --- include/simulation/density_field.h | 2 + .../simulation/event_position_distribution.h | 6 + include/simulation/injector.h | 4 +- include/simulation/random_numbers.h | 29 +++++ include/simulation/simulation.h | 5 +- include/simulation/species.h | 6 + include/simulation/velocity_distribution.h | 9 ++ src/simulation/density_field.cpp | 4 + .../event_position_distribution.cpp | 23 ++++ src/simulation/injector.cpp | 34 ++++-- src/simulation/random_numbers.cpp | 53 +++++++++ src/simulation/simulation.cpp | 70 ++++++++---- src/simulation/species.cpp | 16 ++- src/simulation/velocity_distribution.cpp | 103 ++++++++++++++++++ 14 files changed, 328 insertions(+), 36 deletions(-) diff --git a/include/simulation/density_field.h b/include/simulation/density_field.h index d655781..398f495 100755 --- a/include/simulation/density_field.h +++ b/include/simulation/density_field.h @@ -48,6 +48,8 @@ class DynamicDensityField : public DensityField { // return the particle number stored in the density of this object double particleNumber(); +// return the particle number at the given index + double particleNumber(blitz::TinyVector index); // returns true if the old pitch angle and the new pitch angle are in different bins // of the pitch angle binning diff --git a/include/simulation/event_position_distribution.h b/include/simulation/event_position_distribution.h index 78e469e..b2f84c4 100755 --- a/include/simulation/event_position_distribution.h +++ b/include/simulation/event_position_distribution.h @@ -46,6 +46,12 @@ class PositionDistributionFromDensity { // draw a position from the density provided at construction using the rejection method CylinderCoordinate drawPosition(std::mt19937* engine); + +// draw a position uniformly distributed within the bin of the given index +// (note that the r-dependence of the particle number in a uniform density distribution +// is not incorporated) + CylinderCoordinate drawPosition(std::mt19937* engine, int r_idx, int phi_idx, + int z_idx); // sets the maximum density value needed for the rejection method // should not be called frequently, since during each call the density field is // recalculated from scratch by the DynamicDensityField object diff --git a/include/simulation/injector.h b/include/simulation/injector.h index 6159c3c..6b32b5f 100755 --- a/include/simulation/injector.h +++ b/include/simulation/injector.h @@ -46,14 +46,14 @@ class Injector { // the new particles are then appened to the vector queue // the magnetic field is necessary for the determination of the direction of the // injected particles -// the weight scales the time a particle contributes to a certain bin +// the weight_factor scales the time a particle contributes to a certain bin // and the injection time specifies the time the particle is injected (has to be // between T, T+\DeltaT) void drawNewParticleFromDensityField(std::mt19937* engine, std::shared_ptr specie, std::vector& queue, std::shared_ptr field, - const double weight, + const double weight_factor, const double injection_time); void initInjectionTimeDistribution(double delta_t); diff --git a/include/simulation/random_numbers.h b/include/simulation/random_numbers.h index 25c59e7..d55fa13 100755 --- a/include/simulation/random_numbers.h +++ b/include/simulation/random_numbers.h @@ -5,6 +5,8 @@ #include #include +#include "blitz/array.h" + class RandomNumbers { public: RandomNumbers(int seed); @@ -19,4 +21,31 @@ class RandomNumbers { std::uniform_real_distribution real_distribution_; }; +// class to handle a random walk through a density field, where every +// bin is visited exactly once +class RandomIndex { + public: + // num_bins: contains the number of bins of all dimensions of a + // density binning (order: radial, azimuthal, longitudinal, + // pitch angle, energy) + RandomIndex(blitz::TinyVector num_bins); + +// get the next index + blitz::TinyVector index(); + +// check if all bins have been visited + bool visited_all(); + +// create a new random order and reset the check if all bins have been visited + void reshuffle(std::mt19937* engine); + + private: + const blitz::TinyVector num_bins_; + + std::vector one_dimensional_indices_; + + size_t total_bin_number_; + size_t current_index_in_vector_; +}; + #endif /* RANDOM_NUMBERS_H */ diff --git a/include/simulation/simulation.h b/include/simulation/simulation.h index 6e2121a..53d308a 100755 --- a/include/simulation/simulation.h +++ b/include/simulation/simulation.h @@ -38,7 +38,7 @@ class Simulation { // at the 0th timestep void processEvents(int events, const double beta_particle_weight); - void processDensityEvents(int events, const double weight_factor); + void processDensityEvents(int particles_per_bin, const double weight_factor); void processUntilTermination(particle::Particle& particle); private: @@ -48,7 +48,8 @@ class Simulation { RandomNumbers* random, const double weight_factor, const int current, - std::map& particleNumbers); + std::map& particleNumbers, + bool& all_bins_done); double meanFreePath(particle::Particle& particle, RandomNumbers* random, std::vector& macroscopic_cross_sections_m); diff --git a/include/simulation/species.h b/include/simulation/species.h index 33a6b9d..5636493 100755 --- a/include/simulation/species.h +++ b/include/simulation/species.h @@ -7,6 +7,7 @@ #include "simulation/parameter.h" +class RandomIndex; class Mover; class Terminator; class Reflector; @@ -91,6 +92,9 @@ class TrackedSpecie : public Specie { // getter for the raw pointer to the VelocityDistributionFromDensityField object VelocityDistributionFromDensityField* velocityDistributionFromDensityField(); +// getter for the raw pointer to the RandomIndex object + RandomIndex* randomIndex(); + private: std::shared_ptr density_field_; std::shared_ptr velocity_distribution_; @@ -109,6 +113,8 @@ class TrackedSpecie : public Specie { position_distribution_from_density_; std::shared_ptr velocity_distribution_from_density_; + + std::shared_ptr random_index_; }; class BackgroundSpecie : public Specie { diff --git a/include/simulation/velocity_distribution.h b/include/simulation/velocity_distribution.h index 0b9efca..434939d 100755 --- a/include/simulation/velocity_distribution.h +++ b/include/simulation/velocity_distribution.h @@ -55,6 +55,15 @@ class VelocityDistributionFromDensityField : public VelocityDistribution { CartesianVector rollVelocity( const Coordinate& position, std::mt19937* engine, std::shared_ptr magnetic_field); + +// return a velocity vector drawn uniformly in the bin specifed by index + CartesianVector drawVelocity(const blitz::TinyVector index, + std::mt19937* engine); + CartesianVector drawVelocity(const blitz::TinyVector index, + std::mt19937* engine, + const Coordinate& position, + std::shared_ptr magnetic_field); + private: // mass of the species of which the density field is a part of const double mass_kg_; diff --git a/src/simulation/density_field.cpp b/src/simulation/density_field.cpp index db273b7..5ec29fe 100755 --- a/src/simulation/density_field.cpp +++ b/src/simulation/density_field.cpp @@ -307,6 +307,10 @@ double DynamicDensityField::particleNumber() { return particleNumber; } +double DynamicDensityField::particleNumber(blitz::TinyVector index) { + return time_in_bin_s_(index); +} + blitz::Array DynamicDensityField:: sliceSpectrumArray(const Coordinate& position) const { blitz::TinyVector position_bin = diff --git a/src/simulation/event_position_distribution.cpp b/src/simulation/event_position_distribution.cpp index 2a680fa..3bb6dff 100755 --- a/src/simulation/event_position_distribution.cpp +++ b/src/simulation/event_position_distribution.cpp @@ -87,4 +87,27 @@ CylinderCoordinate PositionDistributionFromDensity::drawPosition(std::mt19937* e return CylinderCoordinate( blitz::TinyVector(random_r, random_phi, random_z)); +} + +CylinderCoordinate PositionDistributionFromDensity::drawPosition(std::mt19937* engine, + int r_idx, int phi_idx, int z_idx) { + double left_bin_border_radial = density_->positionBinning() + ->radial_binning.binBorders()[r_idx]; + double left_bin_border_azimuthal = density_->positionBinning() + ->azimuth_binning.binBorders()[phi_idx]; + double left_bin_border_longitudinal = density_->positionBinning() + ->longitudinal_binning.binBorders()[z_idx]; + + auto stepsize = density_->positionBinning()->stepsize(); + + double r_rndm, phi_rndm, z_rndm; + + r_rndm = density_values(*engine); + phi_rndm = density_values(*engine); + z_rndm = density_values(*engine); + + return CylinderCoordinate(blitz::TinyVector + (left_bin_border_radial + stepsize(0)*r_rndm, + left_bin_border_azimuthal + stepsize(1) * phi_rndm, + left_bin_border_longitudinal + stepsize(2) * z_rndm)); } \ No newline at end of file diff --git a/src/simulation/injector.cpp b/src/simulation/injector.cpp index 68f4267..d5302d2 100755 --- a/src/simulation/injector.cpp +++ b/src/simulation/injector.cpp @@ -9,6 +9,7 @@ #include "simulation/density_field.h" #include "simulation/velocity_distribution.h" #include "simulation/electromagnetic_field.h" +#include "simulation/random_numbers.h" #include Injector::Injector( @@ -87,18 +88,27 @@ void Injector::drawNewParticleFromDensityField(std::mt19937* engine, std::shared_ptr specie, std::vector& queue, std::shared_ptr magnetic_field, - const double weight, + const double weight_factor, const double injection_time) { -// draw the position - CylinderCoordinate position = - specie->positionDistributionFromDensity()->drawPosition(engine); + blitz::TinyVector index = specie->randomIndex()->index(); -// check if density was empty (i.e. phi value lower than 0) - if (position.cylinderEntries()(1) < 0) { - DEBUG_LEVEL_3(specie->name() + ": has zero density"); + std::stringstream out; + out << "drawn index: " << index; + // DEBUG_LEVEL_1(out.str()); + const double num_part_in_bin = specie->densityForDrawing()->particleNumber(index); + out << "\nnumber of particles (" << specie->name() << ") at index: " << num_part_in_bin; + + if(num_part_in_bin == 0) { return; } +// draw the position + CylinderCoordinate position = + specie->positionDistributionFromDensity()->drawPosition(engine, + index(0), index(1), index(2)); + + out << "\ndrawn position: " << position.cylinderEntries(); + DEBUG_LEVEL_3("Injected z position: " + std::to_string(position.cylinderEntries()(2))); DEBUG_LEVEL_3("Injected r position: " + @@ -112,16 +122,20 @@ void Injector::drawNewParticleFromDensityField(std::mt19937* engine, if(kinematic::norm(magnetic_field->value(position). cartesianEntries(position)) == 0) { velocity = specie->velocityDistributionFromDensityField()-> - rollVelocity(position, engine); + drawVelocity(index, engine); } else { velocity = specie->velocityDistributionFromDensityField()-> - rollVelocity(position, engine, magnetic_field); + drawVelocity(index, engine, position, magnetic_field); } + out << "\ndrawn velocity: " << velocity.cartesianEntries(); + DEBUG_LEVEL_2(out.str()); + particle::Particle drawn_particle(specie, position, - velocity, injection_time, weight); + velocity, injection_time, weight_factor*num_part_in_bin); queue.push_back(drawn_particle); + } double Injector::timePassed() const { diff --git a/src/simulation/random_numbers.cpp b/src/simulation/random_numbers.cpp index d01c339..8b16790 100755 --- a/src/simulation/random_numbers.cpp +++ b/src/simulation/random_numbers.cpp @@ -1,4 +1,5 @@ #include "simulation/random_numbers.h" +#include RandomNumbers::RandomNumbers(int seed) : engine_(std::make_shared(seed)), @@ -15,3 +16,55 @@ double RandomNumbers::rollUniform(double min, double max) { std::mt19937* RandomNumbers::engine() { return engine_.get(); } + +// does NOT shuffle the indices! +RandomIndex::RandomIndex(blitz::TinyVector num_bins) : + num_bins_(num_bins){ + + total_bin_number_ = blitz::product(num_bins_); + + one_dimensional_indices_.reserve(total_bin_number_); + + for(size_t i = 0; i < total_bin_number_; ++i) { + one_dimensional_indices_.push_back(i); + } + + current_index_in_vector_ = 0; +} + +void RandomIndex::reshuffle(std::mt19937* engine) { + current_index_in_vector_ = 0; + std::shuffle(std::begin(one_dimensional_indices_), + std::end(one_dimensional_indices_), *engine); +} + +bool RandomIndex::visited_all() { + return current_index_in_vector_ == total_bin_number_ - 1; +} + +// return the next index in the shuffled index vector. Returns the last +// index if all bins have been visited. Reshuffling resets this. +blitz::TinyVector RandomIndex::index() { + size_t tmp_one_dimensional_idx = one_dimensional_indices_[current_index_in_vector_]; + + blitz::TinyVector return_index{0,0,0,0,0}; + + int tmp = 0; + + size_t current_prod = total_bin_number_; + + for(int d = 4; d >= 0; d--) { + current_prod /= num_bins_(d); + + tmp = tmp_one_dimensional_idx / current_prod; + + return_index(d) = tmp; + + tmp_one_dimensional_idx -= tmp * current_prod; + } + + if(!visited_all()) + current_index_in_vector_++; + + return return_index; +} \ No newline at end of file diff --git a/src/simulation/simulation.cpp b/src/simulation/simulation.cpp index 131ea4b..c41232a 100755 --- a/src/simulation/simulation.cpp +++ b/src/simulation/simulation.cpp @@ -61,6 +61,10 @@ void Simulation::init(Parameter& parameter) { DEBUG_LEVEL_0("Init random numbers."); random_ = generator::buildRandomNumbers(parameter); + for(auto& tracked_specie : tracked_species_) { + tracked_specie.second->randomIndex()->reshuffle(random_->engine()); + } + DEBUG_LEVEL_0("Init poisson solver."); poisson_solver_ = generator::buildPoissonSolver(parameter); electric_field_->updateDynamicField(poisson_solver_->staticElectricField()); @@ -134,25 +138,26 @@ void Simulation::start() { static_cast(beta_decay_events*MpiCommunication::mpiSize()); // number of density events per timestep and CPU - const int density_events = - parameter_.intValue(json_path({"Simulation", "DensityEventsPerCPU"}), 0); + const int particles_per_bin = + parameter_.intValue(json_path({"Simulation", + "NumberDensityParticlesPerBinPerCPU"}), 0); // calculate a 'stride' for the density events s.t. the same number of syncs // would be performed - const int density_stride = std::ceil(density_events * + const int density_stride = std::ceil(particles_per_bin * (static_cast(event_stride)/beta_decay_events)); // calculate the scaling factor for the particle weight for particles // drawn from the density const double density_weight_factor = - 1./(MpiCommunication::mpiSize()*density_events); + 1./(MpiCommunication::mpiSize()*particles_per_bin); - DEBUG_LEVEL_0("Density events per cpu: " + std::to_string(density_events)); + DEBUG_LEVEL_0("Number of particles per bin per CPU: " + std::to_string(particles_per_bin)); SIM_INFO("Number of Timesteps: " + std::to_string(number_timesteps)); SIM_INFO("Simulated events before cpu sync: " + std::to_string(event_stride)); int leftover_events_time_resolution = beta_decay_events; - int leftover_density_events = density_events; + int leftover_density_events = particles_per_bin; const double delta_t = time_resolution_events*injector_->timePassed(); @@ -203,7 +208,7 @@ void Simulation::start() { std::to_string(leftover_density_events)); // process both density and beta events before a cpu synchronization - processDensityEvents(density_events_of_cycle, density_weight_factor); + processDensityEvents(particles_per_bin, density_weight_factor); processEvents(events_of_cycle, beta_particle_weight); DEBUG_LEVEL_1("Processing timestep: " + std::to_string(timesteps)); @@ -255,7 +260,7 @@ void Simulation::start() { } leftover_events_time_resolution = beta_decay_events; - leftover_density_events = density_events; + leftover_density_events = particles_per_bin; timer_->increaseTimestep(delta_t); timesteps++; @@ -318,9 +323,12 @@ void Simulation::processEvents(int events, const double beta_particle_weight) { } } -void Simulation::processDensityEvents(int events, const double weight_factor) { +void Simulation::processDensityEvents(int particles_per_bin, const double weight_factor) { DEBUG_LEVEL_0("Processing density events."); + // number of full grid traversions int current_event = 0; + // set to true if all grids of all species have been visited + bool all_bins_done = false; // calculate the number of particles currently contained within the densities // of the different tracked species before injection in order to avoid @@ -331,7 +339,7 @@ void Simulation::processDensityEvents(int events, const double weight_factor) { particleNumbers[pair.first] = (pair.second->densityForDrawing()->particleNumber()); } - while ((current_event < events) || (!queue_.empty())) { + while ((current_event < particles_per_bin) || (!queue_.empty())) { DEBUG_LEVEL_2("Current event: " + std::to_string(current_event)); if (queue_.empty()) { @@ -341,7 +349,8 @@ void Simulation::processDensityEvents(int events, const double weight_factor) { SimulationTimer::eventStartPoint(std::string("DensityInjection")); new_particles = determineInjectedDensityParticles(random_.get(), - weight_factor, current_event, particleNumbers); + weight_factor, current_event, particleNumbers, + all_bins_done); SimulationTimer::eventStopPoint(std::string("DensityInjection")); #if defined debug_level3 @@ -357,17 +366,25 @@ void Simulation::processDensityEvents(int events, const double weight_factor) { // if no new particles could be injected from the density, it is not possible // that during another iteration cycle new particles will be injected // (drawing field only changes after timesteps) - if(new_particles.empty()) { - return; + + if(all_bins_done) { + current_event += 1; + for(auto& element : tracked_species_) { + element.second->randomIndex()->reshuffle(random_->engine()); + } + } + + if(!new_particles.empty()) { + queue_.insert(queue_.end(), new_particles.begin(), new_particles.end()); + } else { + continue; } - current_event += 1; - queue_.insert(queue_.end(), new_particles.begin(), new_particles.end()); } DEBUG_LEVEL_2("Particles in queue: " + std::to_string(queue_.size())); const int particle_number = - particleNumberFromQueue(queue_.size(), random_.get()); + particleNumberFromQueue(queue_.size(), random_.get()); // extract particle from queue here, so that an extension of the queue does // not mess up the reference @@ -573,7 +590,8 @@ std::vector Simulation::determineInjectedParticles( // weight_factor has to be such that particleNumber * weight_factor = weight std::vector Simulation::determineInjectedDensityParticles( RandomNumbers* random, const double weight_factor, const int current, - std::map& particleNumbers) { + std::map& particleNumbers, bool& all_bins_done) { + std::vector new_particles{}; if(!new_particles.empty()) { @@ -583,8 +601,15 @@ std::vector Simulation::determineInjectedDensityParticles( const double injection_time = timer_->time() - timer_->getDeltaT(); + bool tmp_done = false; + all_bins_done = true; + for(auto& pair: tracked_species_) { + + tmp_done = pair.second->randomIndex()->visited_all(); + if (particleNumbers[pair.first] == 0) { + all_bins_done = all_bins_done && true; DEBUG_LEVEL_3("No particles in density of species: " + pair.second->name()); continue; } @@ -599,11 +624,14 @@ std::vector Simulation::determineInjectedDensityParticles( } #endif - double weight = particleNumbers[pair.first]*weight_factor; - - injector_->drawNewParticleFromDensityField(random->engine(), + if(!tmp_done) { + injector_->drawNewParticleFromDensityField(random->engine(), pair.second, new_particles, magnetic_field_, - weight, injection_time); + weight_factor, injection_time); + } + + // if species is not done tmp_done && ... = false + all_bins_done = all_bins_done && tmp_done; } return new_particles; } diff --git a/src/simulation/species.cpp b/src/simulation/species.cpp index e00cdf8..89400d8 100755 --- a/src/simulation/species.cpp +++ b/src/simulation/species.cpp @@ -10,6 +10,7 @@ #include "simulation/terminator.h" #include "simulation/velocity_distribution.h" #include "simulation/event_position_distribution.h" +#include "simulation/random_numbers.h" namespace species { @@ -58,7 +59,20 @@ TrackedSpecie::TrackedSpecie( std::make_shared(density_for_drawing)), velocity_distribution_from_density_( std::make_shared( - density_for_drawing, mass_kg)) {} + density_for_drawing, mass_kg)) { + blitz::TinyVector num_bins; + auto tmp = density_field->positionBinning()->numBins(); + num_bins(0) = tmp(0); num_bins(1) = tmp(1); num_bins(2) = tmp(2); + + num_bins(3) = density_field->pitchAngleBinning()->numBins(); + num_bins(4) = density_field->energyBinning()->numBins(); + + random_index_ = std::make_shared (RandomIndex(num_bins)); +} + +RandomIndex* TrackedSpecie::randomIndex() { + return random_index_.get(); +} DensityField* TrackedSpecie::densityField() { return density_field_.get(); diff --git a/src/simulation/velocity_distribution.cpp b/src/simulation/velocity_distribution.cpp index 6030a03..54581da 100755 --- a/src/simulation/velocity_distribution.cpp +++ b/src/simulation/velocity_distribution.cpp @@ -95,6 +95,7 @@ CartesianVector VelocityDistributionFromDensityField::rollVelocity( return CartesianVector(v_direction * vMagnitude); } +// can NOT be removed, needed for drawing of velocity of interaction partners CartesianVector VelocityDistributionFromDensityField::rollVelocity( const Coordinate& position, std::mt19937* engine, std::shared_ptr magnetic_field) { @@ -149,6 +150,108 @@ CartesianVector VelocityDistributionFromDensityField::rollVelocity( const double vMagnitude = kinematic::velocity(energy_eV, mass_kg_); + blitz::TinyVector v_perp = + perpendicularNormalVector(cartesianB_values); + + blitz::TinyVector v_direction = pitchAngle + * cartesianB_values/Bmagnitude + + std::sqrt(1 - pitchAngle*pitchAngle) + * kinematic::rotateVector(v_perp, cartesianB_values, theta); + + return CartesianVector(v_direction * vMagnitude); +} + +// if valid is false after function, the number of particles in the cell at the given index +// is 0 +CartesianVector VelocityDistributionFromDensityField::drawVelocity( + const blitz::TinyVector index, std::mt19937* engine) { + + // const double number_particles_in_bin = density_field_->particleNumber(index); + + const double energy_step = energyBinBorders_[index(4) + 1] + - energyBinBorders_[index(4)]; + + const double pitch_angle_step = pitchAngleBinBorders_[index(3) + 1] + - pitchAngleBinBorders_[index(3)]; + + double energy_eV = energyBinBorders_[index(4)] + + theta_distribution_(*engine)*energy_step; + + double pitchAngle = pitchAngleBinBorders_[index(3)] + + theta_distribution_(*engine)*pitch_angle_step; + + // construct the velocity + + const double theta = theta_distribution_(*engine)*2*M_PI; + + blitz::TinyVector zDirection(0,0,1); + + const double vMagnitude = kinematic::velocity(energy_eV, mass_kg_); + +// vector perpendicular to e_z + blitz::TinyVector v_perp(1,0,0); + + blitz::TinyVector v_direction = pitchAngle * zDirection + + std::sqrt(1 - pitchAngle*pitchAngle) + * kinematic::rotateVector(v_perp, zDirection, theta); + + return CartesianVector(v_direction * vMagnitude); +} + +CartesianVector VelocityDistributionFromDensityField::drawVelocity( + const blitz::TinyVector index, std::mt19937* engine, + const Coordinate& position, + std::shared_ptr magnetic_field) { + + // since a 0 is included in the bin borders for the energy + const double energy_step = energyBinBorders_[index(4) + 2] + - energyBinBorders_[index(4) + 1]; + + const double pitch_angle_step = pitchAngleBinBorders_[index(3) + 1] + - pitchAngleBinBorders_[index(3)]; + + double energy_eV = energyBinBorders_[index(4) + 1] + + theta_distribution_(*engine)*energy_step; + + double pitchAngle = pitchAngleBinBorders_[index(3)] + + theta_distribution_(*engine)*pitch_angle_step; + +#ifdef debug + if((std::isnan(pitchAngle)) || (std::isnan(energy_eV))) { + std::stringstream out; + out << "pitchAngle: " << pitchAngle; + out << "\nenergy value: " << energy_eV; + // out << "\nenergy values: " << energyValues; + // out << "\npitch angle values: " << pitchAngleValues; + out << "\nenergy bin borders: [ "; + for(auto element : energyBinBorders_) { + out << element << " "; + } + out << "]"; + + ERROR(out.str()); + } + + std::stringstream out; + out << "left Pitchangle value: "<< pitchAngleBinBorders_[index(3)]; + out << "\nright Pitchangle value: " << pitchAngleBinBorders_[index(3)+1]; + out << "\npitchAngle: " << pitchAngle; + out << "\nleft energy value: "<< energyBinBorders_[index(4) + 1]; + out << "\nright energy value: " << energyBinBorders_[index(4)+2]; + out << "\nenergy value: " << energy_eV; + DEBUG_LEVEL_2(out.str()); +#endif + + // construct the velocity + + const double theta = theta_distribution_(*engine)*2*M_PI; + + blitz::TinyVector cartesianB_values = + magnetic_field->value(position).cartesianEntries(position); + const double Bmagnitude = kinematic::norm(cartesianB_values); + + const double vMagnitude = kinematic::velocity(energy_eV, mass_kg_); + blitz::TinyVector v_perp = perpendicularNormalVector(cartesianB_values);