Removed drawing infrastructure
This commit is contained in:
@@ -82,7 +82,6 @@ SpeciesBuilder::SpeciesBuilder(Parameter& parameter) {
|
||||
fillTerminator(parameter);
|
||||
fillReflector(parameter);
|
||||
fillTrackedDensity(parameter);
|
||||
fillDensityDrawingType(parameter);
|
||||
|
||||
buildSpecies();
|
||||
fillInteractions(parameter);
|
||||
@@ -307,13 +306,6 @@ void SpeciesBuilder::fillTrackedDensity(Parameter& parameter) {
|
||||
}
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillDensityDrawingType(Parameter& parameter) {
|
||||
for(auto& b : tracked_species_info) {
|
||||
b.second.explicitly_stored = parameter.boolValue(
|
||||
json_path_append(b.second.path_in_json, {"StoreInQueue"}), false);
|
||||
}
|
||||
}
|
||||
|
||||
void SpeciesBuilder::buildSpecies() {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Build species from info.");
|
||||
@@ -327,15 +319,9 @@ void SpeciesBuilder::buildSpecies() {
|
||||
}
|
||||
|
||||
for (auto& b : tracked_species_info) {
|
||||
#ifdef debug
|
||||
std::stringstream out;
|
||||
out << b.second.name << ": stored in queue? " << (b.second.explicitly_stored ? "true": "false");
|
||||
DEBUG_LEVEL_1(out.str());
|
||||
#endif
|
||||
tracked_species[b.first] =
|
||||
std::shared_ptr<species::TrackedSpecie>(new species::TrackedSpecie(
|
||||
b.second.type, b.second.name, b.second.mass_kg, b.second.charge_C,
|
||||
b.second.explicitly_stored,
|
||||
b.second.mover, b.second.terminator, b.second.reflector,
|
||||
b.second.density_field, b.second.velocity_distribution,
|
||||
b.second.drift_velocity, b.second.density_drawing_field));
|
||||
|
||||
@@ -83,28 +83,6 @@ DynamicDensityField::DynamicDensityField(
|
||||
pitch_angle_binning.binIndexMax()),
|
||||
blitz::Range(energy_binning.binIndexMin(),
|
||||
energy_binning.binIndexMax()))),
|
||||
// deleted_particles_(initiate5DArray<long int>(
|
||||
// blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
// position_binning.radial_binning.binIndexMax()),
|
||||
// blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||
// position_binning.azimuth_binning.binIndexMax()),
|
||||
// blitz::Range(position_binning.longitudinal_binning.binIndexMin(),
|
||||
// position_binning.longitudinal_binning.binIndexMax()),
|
||||
// blitz::Range(pitch_angle_binning.binIndexMin(),
|
||||
// pitch_angle_binning.binIndexMax()),
|
||||
// blitz::Range(energy_binning.binIndexMin(),
|
||||
// energy_binning.binIndexMax()))),
|
||||
// sync_deleted_particles_(initiate5DArray<long int>(
|
||||
// blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
// position_binning.radial_binning.binIndexMax()),
|
||||
// blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||
// position_binning.azimuth_binning.binIndexMax()),
|
||||
// blitz::Range(position_binning.longitudinal_binning.binIndexMin(),
|
||||
// position_binning.longitudinal_binning.binIndexMax()),
|
||||
// blitz::Range(pitch_angle_binning.binIndexMin(),
|
||||
// pitch_angle_binning.binIndexMax()),
|
||||
// blitz::Range(energy_binning.binIndexMin(),
|
||||
// energy_binning.binIndexMax()))),
|
||||
density_per_m3_(initiate4DArray<double>(
|
||||
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
position_binning.radial_binning.binIndexMax()),
|
||||
@@ -304,19 +282,6 @@ void DynamicDensityField::recalculateDensityArray() {
|
||||
// SimulationTimer::eventStopPoint("recalcDensityArray");
|
||||
}
|
||||
|
||||
double DynamicDensityField::particleNumber() {
|
||||
blitz::Array<double, 3> density = densityArray();
|
||||
double particleNumber = blitz::sum(density * bin_volume_m3_);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("particle number: " + std::to_string(particleNumber));
|
||||
#endif
|
||||
return particleNumber;
|
||||
}
|
||||
|
||||
double DynamicDensityField::particleNumber(blitz::TinyVector<int, 5> index) {
|
||||
return time_in_bin_s_(index);
|
||||
}
|
||||
|
||||
blitz::Array<double, 1> DynamicDensityField::
|
||||
sliceSpectrumArray(const Coordinate& position) const {
|
||||
blitz::TinyVector<int, 3> position_bin =
|
||||
@@ -341,10 +306,8 @@ blitz::Array<double, 1> DynamicDensityField::
|
||||
void DynamicDensityField::resetDynamicDensityField() {
|
||||
//timer_->resetTime(); // time stays global
|
||||
time_in_bin_s_ = 0.;
|
||||
// deleted_particles_ = 0.;
|
||||
density_per_m3_ = 0.;
|
||||
sync_time_in_bin_s_ = 0.;
|
||||
// sync_deleted_particles_ = 0.;
|
||||
}
|
||||
|
||||
void DynamicDensityField::restartTimer(double time, double delta_t) {
|
||||
|
||||
@@ -16,8 +16,7 @@ EventPositionDistribution::EventPositionDistribution(
|
||||
density_values(
|
||||
std::uniform_real_distribution<double>(density.min, density.max)) {}
|
||||
|
||||
CylinderCoordinate EventPositionDistribution::rollPosition(
|
||||
std::mt19937* engine) {
|
||||
CylinderCoordinate EventPositionDistribution::rollPosition(std::mt19937* engine) {
|
||||
double random_number_z;
|
||||
double random_numer_r;
|
||||
double random_number_phi;
|
||||
@@ -38,82 +37,4 @@ CylinderCoordinate EventPositionDistribution::rollPosition(
|
||||
|
||||
return CylinderCoordinate(blitz::TinyVector<double, 3>(
|
||||
random_numer_r, random_number_phi, random_number_z));
|
||||
}
|
||||
|
||||
PositionDistributionFromDensity::PositionDistributionFromDensity(
|
||||
std::shared_ptr<DynamicDensityField> density):
|
||||
density_(density),
|
||||
std_unifrm(std::uniform_real_distribution<double>(0.,1.)) {
|
||||
/************************************************************************************
|
||||
// get the extent of the domain of the DynamicDensityField object to be used for
|
||||
// the rejection method
|
||||
double rmin = density->positionBinning()->radial_binning.binBorders().front();
|
||||
double rmax = density->positionBinning()->radial_binning.binBorders().back();
|
||||
|
||||
double phimin = 0;
|
||||
double phimax = 2*M_PI;
|
||||
|
||||
double zmin = density->positionBinning()->longitudinal_binning.binBorders().front();
|
||||
double zmax = density->positionBinning()->longitudinal_binning.binBorders().back();
|
||||
|
||||
// initialize the distributions
|
||||
r_values = std::uniform_real_distribution<double>(rmin*rmin, rmax*rmax);
|
||||
phi_values = std::uniform_real_distribution<double>(phimin, phimax);
|
||||
z_values = std::uniform_real_distribution<double>(zmin, zmax);
|
||||
**************************************************************************************/
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
void PositionDistributionFromDensity::setMaximumDensity() {
|
||||
maximum_density_ = blitz::max(density_->densityArray());
|
||||
}
|
||||
|
||||
CylinderCoordinate PositionDistributionFromDensity::drawPosition(std::mt19937* engine) {
|
||||
if(isEqual(maximum_density_, 0.)) {
|
||||
// abuse the phi coordinate as a check if the density was zero
|
||||
// only works if phi \in (0, 2pi)
|
||||
return CylinderCoordinate(blitz::TinyVector<double,3>(0,-1,0));
|
||||
}
|
||||
|
||||
double random_r, random_phi, random_z, random_n;
|
||||
|
||||
do {
|
||||
random_r = std::sqrt(r_values(*engine));
|
||||
random_phi = phi_values(*engine);
|
||||
random_z = z_values(*engine);
|
||||
random_n = density_values(*engine);
|
||||
// might be bad that the value gets recalculated for each call of density_->density(...)
|
||||
} while (random_n*maximum_density_ >= density_->density(CylinderCoordinate(
|
||||
blitz::TinyVector<double,3>(random_r, random_phi, random_z))));
|
||||
|
||||
return CylinderCoordinate(
|
||||
blitz::TinyVector<double, 3>(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 = std_unifrm(*engine);
|
||||
phi_rndm = std_unifrm(*engine);
|
||||
z_rndm = std_unifrm(*engine);
|
||||
|
||||
double radius = std::sqrt(left_bin_border_radial*left_bin_border_radial +
|
||||
(2*left_bin_border_radial + stepsize(0))
|
||||
*stepsize(0)*r_rndm);
|
||||
|
||||
return CylinderCoordinate(blitz::TinyVector<double, 3>
|
||||
(radius,
|
||||
left_bin_border_azimuthal + stepsize(1) * phi_rndm,
|
||||
left_bin_border_longitudinal + stepsize(2) * z_rndm));
|
||||
}
|
||||
@@ -113,60 +113,6 @@ void Injector::setWeights(const double physical_number, const int numerical_numb
|
||||
#endif
|
||||
}
|
||||
|
||||
void Injector::drawNewParticleFromDensityField(std::mt19937* engine,
|
||||
std::shared_ptr<species::TrackedSpecie> specie,
|
||||
std::vector<particle::Particle>& queue,
|
||||
std::shared_ptr<MagneticField> magnetic_field,
|
||||
const double weight_factor) {
|
||||
blitz::TinyVector<int, 5> index = specie->randomIndex()->index();
|
||||
|
||||
const double num_part_in_bin = specie->densityForDrawing()->particleNumber(index);
|
||||
|
||||
if(num_part_in_bin == 0) {
|
||||
#if defined(debug_level2) || defined(debug_level3)
|
||||
std::stringstream out;
|
||||
out << "index: "<< index <<" has no particles";
|
||||
// DEBUG_LEVEL_2(out.str());
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
// draw the position
|
||||
CylinderCoordinate position =
|
||||
specie->positionDistributionFromDensity()->drawPosition(engine,
|
||||
index(0), index(1), index(2));
|
||||
// draw the velocity
|
||||
CartesianVector velocity(blitz::TinyVector<double, 3>(0,0,0));
|
||||
|
||||
// in case the magnetic field is 0 at the current position draw the velocity
|
||||
// with respect to the z-axis otherwise use the magnetic field
|
||||
if(kinematic::norm(magnetic_field->value(position).
|
||||
cartesianEntries(position)) == 0) {
|
||||
velocity = specie->velocityDistributionFromDensityField()->
|
||||
drawVelocity(index, engine);
|
||||
} else {
|
||||
velocity = specie->velocityDistributionFromDensityField()->
|
||||
drawVelocity(index, engine, position, magnetic_field);
|
||||
}
|
||||
|
||||
#if defined(debug_level2) || defined(debug_level3)
|
||||
std::stringstream out;
|
||||
out << specie->name() << ":\n";
|
||||
out << "\ndrawn index: " << index;
|
||||
out << "\nnumber of particles (" << specie->name() << ") at index: " << num_part_in_bin;
|
||||
out << "\ndrawn position: " << position.cylinderEntries();
|
||||
out << "\ndrawn velocity: " << velocity.cartesianEntries();
|
||||
if(num_part_in_bin > 0)
|
||||
DEBUG_LEVEL_2(out.str());
|
||||
#endif
|
||||
|
||||
particle::Particle drawn_particle(specie, position,
|
||||
velocity, weight_factor*num_part_in_bin);
|
||||
|
||||
queue.push_back(drawn_particle);
|
||||
|
||||
}
|
||||
|
||||
double Injector::timePassed() const {
|
||||
return 1 / activity_;
|
||||
}
|
||||
|
||||
@@ -150,6 +150,13 @@ void BorisMover::move(particle::Particle* particle,
|
||||
}
|
||||
|
||||
#ifdef debug_level3
|
||||
double new_mu;
|
||||
if (kinematic::norm(B) == 0) {
|
||||
new_mu = kinematic::cosPitchAngle(
|
||||
blitz::TinyVector<double, 3>(0,0,1), particle->velocity().cartesianEntries());
|
||||
} else {
|
||||
new_mu = kinematic::cosPitchAngle(B, particle->velocity().cartesianEntries());
|
||||
}
|
||||
if((changed_energy_bin || changed_position_bin) && !left_simulation_domain && !died_in_bin && (leftover_time > 0)) {
|
||||
std::stringstream out;
|
||||
out << "move(...) interrupted by change in ";
|
||||
@@ -163,7 +170,7 @@ void BorisMover::move(particle::Particle* particle,
|
||||
// out << "mu bin: ";
|
||||
// out << old_mu << " (old), " << new_mu;
|
||||
} else {
|
||||
out <<"unknown bin... " << changed_energy_bin << changed_position_bin << changed_mu_bin << left_simulation_domain << died_in_bin << leftover_time;
|
||||
out <<"unknown bin... " << changed_energy_bin << changed_position_bin << left_simulation_domain << died_in_bin << leftover_time;
|
||||
}
|
||||
out << "\n(gyroradius = " << particle->mass_kg()*std::sqrt(1-new_mu*new_mu)*particle->absoluteVelocity()/(particle->specie()->charge_C()*kinematic::norm(B)) << " m";
|
||||
out << " energy: " << particle->kineticEnergy_eV() <<" eV)";
|
||||
|
||||
+20
-149
@@ -79,10 +79,6 @@ void Simulation::init(Parameter& parameter) {
|
||||
#endif
|
||||
random_ = generator::buildRandomNumbers(parameter);
|
||||
|
||||
for(auto& tracked_specie : tracked_species_) {
|
||||
tracked_specie.second->randomIndex()->reshuffle(random_->engine());
|
||||
}
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Init poisson solver.");
|
||||
#endif
|
||||
@@ -164,32 +160,10 @@ void Simulation::start() {
|
||||
|
||||
injector_->setWeights(time_resolution_events, beta_decay_events);
|
||||
|
||||
// number of density events per timestep and CPU
|
||||
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
|
||||
int density_stride = particles_per_bin;
|
||||
if(beta_decay_events != 0) {
|
||||
density_stride = std::ceil(particles_per_bin *
|
||||
(static_cast<double>(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::mpi_size*particles_per_bin);
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Number of particles per bin per CPU: " + std::to_string(particles_per_bin));
|
||||
#endif
|
||||
|
||||
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 = particles_per_bin;
|
||||
|
||||
const double delta_t = time_resolution_events*injector_->timePassed();
|
||||
|
||||
@@ -211,8 +185,6 @@ void Simulation::start() {
|
||||
// cpu sync is done
|
||||
int events_of_cycle =
|
||||
eventsOfCycle(event_stride, leftover_events_time_resolution);
|
||||
int density_events_of_cycle =
|
||||
eventsOfCycle(density_stride, leftover_density_events);
|
||||
|
||||
#ifdef debug_level1
|
||||
DEBUG_LEVEL_1("Events of cycle: " + std::to_string(events_of_cycle));
|
||||
@@ -225,12 +197,10 @@ void Simulation::start() {
|
||||
#ifdef debug
|
||||
SIM_INFO("Leftover events this timestep this CPU: " +
|
||||
std::to_string(leftover_events_time_resolution));
|
||||
SIM_INFO("Leftover density events this timestep this CPU: " +
|
||||
std::to_string(leftover_density_events));
|
||||
#endif
|
||||
|
||||
// process both density and beta events before a cpu synchronization
|
||||
processDensityEvents(particles_per_bin, density_weight_factor);
|
||||
processDensityEvents();
|
||||
processEvents(events_of_cycle);
|
||||
|
||||
#if defined(debug_level1) || defined(debug_level2) || defined(debug_level3)
|
||||
@@ -240,7 +210,6 @@ void Simulation::start() {
|
||||
#endif
|
||||
|
||||
leftover_events_time_resolution -= events_of_cycle;
|
||||
leftover_density_events -= density_events_of_cycle;
|
||||
|
||||
reset = !(leftover_events_time_resolution > 0);
|
||||
|
||||
@@ -300,7 +269,6 @@ void Simulation::start() {
|
||||
}
|
||||
|
||||
leftover_events_time_resolution = beta_decay_events;
|
||||
leftover_density_events = particles_per_bin;
|
||||
|
||||
timer_->increaseTimestep(delta_t);
|
||||
timestep++;
|
||||
@@ -379,71 +347,43 @@ void Simulation::processEvents(int events) {
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::processDensityEvents(int particles_per_bin, const double weight_factor) {
|
||||
void Simulation::processDensityEvents() {
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Processing density events.");
|
||||
#endif
|
||||
// number of full grid traversions
|
||||
// number of full grid traversions (legacy variable)
|
||||
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
|
||||
// the expensive recalculateDensityField funtion being calculated for every
|
||||
// new injection event
|
||||
std::map<std::string, double> particleNumbers;
|
||||
for(auto& pair: tracked_species_) {
|
||||
particleNumbers[pair.first] = (pair.second->densityForDrawing()->particleNumber());
|
||||
}
|
||||
|
||||
while ((current_event < particles_per_bin) || (!queue_.empty())) {
|
||||
while ((!queue_.empty()) || (!storage_queue_[active_storage].empty())) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Current event: " + std::to_string(current_event));
|
||||
#endif
|
||||
|
||||
if (queue_.empty()) {
|
||||
std::vector<particle::Particle> new_particles;
|
||||
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Current density event: " + std::to_string(current_event));
|
||||
#endif
|
||||
|
||||
SimulationTimer::eventStartPoint(std::string("DensityInjection"));
|
||||
new_particles = determineInjectedDensityParticles(random_.get(),
|
||||
weight_factor, current_event, particleNumbers,
|
||||
all_bins_done);
|
||||
particle::Particle newParticle(storage_queue_[active_storage].back(),
|
||||
tracked_species_);
|
||||
storage_queue_[active_storage].pop_back();
|
||||
SimulationTimer::eventStopPoint(std::string("DensityInjection"));
|
||||
|
||||
#if defined debug_level3
|
||||
for(auto& particle : new_particles) {
|
||||
std::stringstream output_ss;
|
||||
output_ss << particle.specie()->name() << " with velocity (cart): ";
|
||||
output_ss << particle.velocity().cartesianEntries();
|
||||
output_ss << " and position (cart)";
|
||||
output_ss << particle.cartesianPosition().cartesianEntries();
|
||||
DEBUG_LEVEL_3(output_ss.str());
|
||||
}
|
||||
std::stringstream output_ss;
|
||||
output_ss << newParticle.specie()->name() << " with velocity (cart): ";
|
||||
output_ss << newParticle.velocity().cartesianEntries();
|
||||
output_ss << " and position (cart)";
|
||||
output_ss << newParticle.cartesianPosition().cartesianEntries();
|
||||
DEBUG_LEVEL_3(output_ss.str());
|
||||
#endif
|
||||
// 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(all_bins_done) {
|
||||
current_event += 1;
|
||||
for(auto& element : tracked_species_) {
|
||||
if(element.second->explicitlyStored()) {
|
||||
continue;
|
||||
}
|
||||
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_.push_back(newParticle);
|
||||
}
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Particles in queue: " +
|
||||
@@ -521,11 +461,11 @@ void Simulation::processUntilTermination(particle::Particle& particle) {
|
||||
ERROR(out.str());
|
||||
}
|
||||
#endif
|
||||
// particle terminated due to reaching time resolution alone -> needs
|
||||
// to be stored (if it's an electron)
|
||||
if(particle.specie()->explicitlyStored()) {
|
||||
storage_queue_[inactive_storage].push_back(particle.serialize());
|
||||
}
|
||||
|
||||
storage_queue_[inactive_storage].push_back(particle.serialize());
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(particle.specie()->name() + " pushed back into storage.");
|
||||
#endif
|
||||
|
||||
if(particle.specie()->deletionLogger()) {
|
||||
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
|
||||
@@ -692,75 +632,6 @@ interaction::InteractionOutput Simulation::interact(
|
||||
}
|
||||
}
|
||||
|
||||
// weight_factor has to be such that particleNumber * weight_factor = weight
|
||||
std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
||||
RandomNumbers* random, const double weight_factor, const int current,
|
||||
std::map<std::string, double>& particleNumbers, bool& all_bins_done) {
|
||||
|
||||
std::vector<particle::Particle> new_particles{};
|
||||
|
||||
if(!new_particles.empty()) {
|
||||
ERROR("In drawing particles from the density:"
|
||||
" the new particles vector is not empty at initialization");
|
||||
}
|
||||
|
||||
bool tmp_done = false;
|
||||
all_bins_done = true;
|
||||
|
||||
for(auto& pair: tracked_species_) {
|
||||
// Note: takes the next particle in the storage queue regardless if
|
||||
// that particle is a member of the current tracked_specie
|
||||
if(pair.second->explicitlyStored()) {
|
||||
// if the storage queue does not contain any more particles
|
||||
// no new particles can be drawn
|
||||
if(storage_queue_[active_storage].empty()) {
|
||||
all_bins_done = all_bins_done && true;
|
||||
continue;
|
||||
} else {
|
||||
all_bins_done = false;
|
||||
}
|
||||
// take the last particle from the storage queue and extract it
|
||||
particle::SerializedParticle new_sparticle =
|
||||
storage_queue_[active_storage].back();
|
||||
storage_queue_[active_storage].pop_back();
|
||||
particle::Particle new_particle(new_sparticle, tracked_species_);
|
||||
// "draw" the actual particle
|
||||
new_particles.push_back(new_particle);
|
||||
continue;
|
||||
}
|
||||
|
||||
tmp_done = pair.second->randomIndex()->visited_all();
|
||||
|
||||
if (particleNumbers[pair.first] == 0) {
|
||||
all_bins_done = all_bins_done && true;
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("No particles in density of species: " + pair.second->name());
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
#if defined debug_level3
|
||||
if (current == 0) {
|
||||
std::stringstream out;
|
||||
out << pair.second->name();
|
||||
out << "particle number from density: ";
|
||||
out << particleNumbers[pair.first];
|
||||
DEBUG_LEVEL_3(out.str());
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!tmp_done) {
|
||||
injector_->drawNewParticleFromDensityField(random->engine(),
|
||||
pair.second, new_particles, magnetic_field_,
|
||||
weight_factor);
|
||||
}
|
||||
|
||||
// if species is not done tmp_done && ... = false
|
||||
all_bins_done = all_bins_done && tmp_done;
|
||||
}
|
||||
return new_particles;
|
||||
}
|
||||
|
||||
//maybe put that into the poisson solver
|
||||
blitz::Array<double,3> Simulation::chargedensity() {
|
||||
#ifdef debug_level3
|
||||
|
||||
@@ -38,7 +38,6 @@ TrackedSpecie::TrackedSpecie(
|
||||
std::string name,
|
||||
double mass_kg,
|
||||
double charge_C,
|
||||
bool explicitly_stored,
|
||||
std::shared_ptr<Mover> mover,
|
||||
std::shared_ptr<Terminator> terminator,
|
||||
std::shared_ptr<Reflector> reflector,
|
||||
@@ -53,29 +52,11 @@ TrackedSpecie::TrackedSpecie(
|
||||
density_field_(density_field),
|
||||
deletion_logger_(std::shared_ptr<DeletionLogger>(nullptr)),
|
||||
current_collector_(std::shared_ptr<CurrentCollector>(nullptr)),
|
||||
velocity_distribution_(velocity_distribution),
|
||||
drift_velocity_(drift_velocity),
|
||||
density_for_drawing_(density_for_drawing),
|
||||
position_distribution_from_density_(
|
||||
std::make_shared<PositionDistributionFromDensity>(density_for_drawing)),
|
||||
velocity_distribution_from_density_(
|
||||
std::make_shared<VelocityDistributionFromDensityField>(
|
||||
density_for_drawing, mass_kg)),
|
||||
explicitly_stored_(explicitly_stored) {
|
||||
blitz::TinyVector<int, 5> 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();
|
||||
// include underflow bin in the energy direction only
|
||||
num_bins(4) = density_field->energyBinning()->numBins() + 1;
|
||||
|
||||
random_index_ = std::make_shared<RandomIndex> (RandomIndex(num_bins));
|
||||
}
|
||||
|
||||
RandomIndex* TrackedSpecie::randomIndex() {
|
||||
return random_index_.get();
|
||||
}
|
||||
density_for_drawing, mass_kg)) {}
|
||||
|
||||
DensityField* TrackedSpecie::densityField() {
|
||||
return density_field_.get();
|
||||
@@ -120,11 +101,6 @@ CurrentCollector* TrackedSpecie::currentCollector() {
|
||||
return current_collector_.get();
|
||||
}
|
||||
|
||||
PositionDistributionFromDensity*
|
||||
TrackedSpecie::positionDistributionFromDensity() {
|
||||
return position_distribution_from_density_.get();
|
||||
}
|
||||
|
||||
VelocityDistributionFromDensityField*
|
||||
TrackedSpecie::velocityDistributionFromDensityField() {
|
||||
return velocity_distribution_from_density_.get();
|
||||
@@ -149,10 +125,6 @@ void TrackedSpecie::currentCollector(
|
||||
current_collector_ = new_collector;
|
||||
}
|
||||
|
||||
bool TrackedSpecie::explicitlyStored() {
|
||||
return explicitly_stored_;
|
||||
}
|
||||
|
||||
BackgroundSpecie::BackgroundSpecie(
|
||||
ImplementedSpecies type,
|
||||
std::string name,
|
||||
|
||||
@@ -37,10 +37,6 @@ VelocityDistributionFromDensityField::VelocityDistributionFromDensityField(
|
||||
pitchAngleBinBorders_(density_field->pitchAngleBinning()->binBorders()),
|
||||
theta_distribution_(std::uniform_real_distribution<double>(0.,1.)),
|
||||
mass_kg_(mass_kg) {
|
||||
double maxAbsExponent = std::max(std::abs(std::log10(energyBinBorders_.front())),
|
||||
std::abs(std::log10(energyBinBorders_.back())));
|
||||
alpha_lower_limit = -300/maxAbsExponent;
|
||||
alpha_upper_limit = 300/maxAbsExponent;
|
||||
// necessary to include the underflow bin in the energy domain
|
||||
energyBinBorders_.insert(energyBinBorders_.begin(), 0);
|
||||
}
|
||||
@@ -154,211 +150,6 @@ CartesianVector VelocityDistributionFromDensityField::rollVelocity(
|
||||
|
||||
const double vMagnitude = kinematic::velocity(energy_eV, mass_kg_);
|
||||
|
||||
blitz::TinyVector<double, 3> v_perp =
|
||||
perpendicularNormalVector(cartesianB_values);
|
||||
|
||||
blitz::TinyVector<double, 3> 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<int, 5> 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<double, 3> zDirection(0,0,1);
|
||||
|
||||
const double vMagnitude = kinematic::velocity(energy_eV, mass_kg_);
|
||||
|
||||
// vector perpendicular to e_z
|
||||
blitz::TinyVector<double, 3> v_perp(1,0,0);
|
||||
|
||||
blitz::TinyVector<double, 3> 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<int, 5> index, std::mt19937* engine,
|
||||
const Coordinate& position,
|
||||
std::shared_ptr<MagneticField> 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 energy_eV;
|
||||
double alpha = 1;
|
||||
if(index(4) == -1) {
|
||||
// linear drawing inbetween E=0, N(0)=0 to E=Er and N(Er)=Nr
|
||||
energy_eV = energyBinBorders_[index(4) + 2]*
|
||||
std::sqrt(theta_distribution_(*engine));
|
||||
// #ifdef debug
|
||||
// std::stringstream out;
|
||||
// out << "underflow bin.\n\tdrawn energy: " << energy_eV;
|
||||
// out << "\n\tenergy value left: " << energyBinBorders_[index(4)+1];
|
||||
// out << "\n\tenergy value right: " << energyBinBorders_[index(4)+2];
|
||||
// DEBUG(out.str());
|
||||
// #endif
|
||||
} else {
|
||||
double nl = density_field_->particleNumber(index);
|
||||
double nr = density_field_->particleNumber(index +
|
||||
blitz::TinyVector<int, 5>(0,0,0,0,1));
|
||||
|
||||
// double alpha;
|
||||
// no reason for specific values, just to avoid these cases
|
||||
if(nl == 0) {
|
||||
alpha = 1;
|
||||
} else if (nr == 0) {
|
||||
alpha = -1;
|
||||
} else if (nr == 0 && nl == 0) {
|
||||
alpha = 0;
|
||||
} else {
|
||||
alpha = std::log(nr/nl)/std::log(energyBinBorders_[index(4) + 2]/
|
||||
energyBinBorders_[index(4) + 1]);
|
||||
}
|
||||
|
||||
// alpha = std::abs(alpha) > 100 ?(alpha/std::abs(alpha))*100 : alpha;
|
||||
alpha = std::min(std::max(alpha, alpha_lower_limit), alpha_upper_limit);
|
||||
|
||||
if(alpha == -1) {
|
||||
energy_eV = std::pow(energyBinBorders_[index(4) + 2]
|
||||
/ energyBinBorders_[index(4) + 1], theta_distribution_(*engine)) *
|
||||
energyBinBorders_[index(4) + 1];
|
||||
// energy_eV = (std::pow(2, theta_distribution_(*engine)) - 1)*energy_step
|
||||
// + energyBinBorders_[index(4) + 1];
|
||||
// #ifdef debug
|
||||
// std::stringstream out;
|
||||
// out << "alpha = -1\n\tdrawn energy: " << energy_eV;
|
||||
// out << "\n\tenergy value left: " << energyBinBorders_[index(4)+1];
|
||||
// out << "\n\tenergy value right: " << energyBinBorders_[index(4)+2];
|
||||
// DEBUG(out.str());
|
||||
// #endif
|
||||
} else {
|
||||
double xl_alphap1 = std::pow(energyBinBorders_[index(4) + 1], alpha + 1);
|
||||
double xr_alphap1 = std::pow(energyBinBorders_[index(4) + 2], alpha + 1);
|
||||
energy_eV = std::pow((xr_alphap1 - xl_alphap1)*
|
||||
theta_distribution_(*engine) + xl_alphap1, 1/(alpha + 1));
|
||||
// #ifdef debug
|
||||
// if(std::abs(alpha) > 100) {
|
||||
// std::stringstream out;
|
||||
// out << "alpha: " << alpha;
|
||||
// out << "\nxl_alphap1: " << xl_alphap1;
|
||||
// out << "\nxr_alphap1: " << xr_alphap1;
|
||||
// DEBUG(out.str());
|
||||
// }
|
||||
// #endif
|
||||
// #ifdef debug
|
||||
// std::stringstream out;
|
||||
// out << "alpha = "<< alpha << "\n\tdrawn energy: " << energy_eV;
|
||||
// out << "\n\tenergy value left: " << energyBinBorders_[index(4)+1];
|
||||
// out << "\n\tenergy value right: " << energyBinBorders_[index(4)+2];
|
||||
// DEBUG(out.str());
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
|
||||
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 << "\nalpha: " << alpha;
|
||||
out << "\ncurrent index: " << index;
|
||||
out << "\nNl: " << density_field_->particleNumber(index);
|
||||
out << "\nNl: " << density_field_->particleNumber(index +
|
||||
blitz::TinyVector<int, 5>(0,0,0,0,1));
|
||||
out << "\nEl: " << energyBinBorders_[index(4) + 1];
|
||||
out << "\nEr: " << energyBinBorders_[index(4) + 2];
|
||||
out << "\nEl^(alpha+1): " << std::pow(energyBinBorders_[index(4) + 1], alpha + 1);
|
||||
out << "\nEr^(alpha+1): " << std::pow(energyBinBorders_[index(4) + 2], alpha + 1);
|
||||
// out << "\nenergy values: " << energyValues;
|
||||
// out << "\npitch angle values: " << pitchAngleValues;
|
||||
out << "\nenergy bin borders: [ ";
|
||||
for(auto element : energyBinBorders_) {
|
||||
out << element << " ";
|
||||
}
|
||||
out << "]";
|
||||
|
||||
ERROR(out.str());
|
||||
}
|
||||
|
||||
// if(std::isinf(energy_eV)) {
|
||||
// std::stringstream out;
|
||||
// out << "pitchAngle: " << pitchAngle;
|
||||
// out << "\nenergy value: " << energy_eV;
|
||||
// out << "\ncurrent index: " << index;
|
||||
// out << "\nalpha: " << alpha;
|
||||
// out << "\nNl: " << density_field_->particleNumber(index);
|
||||
// out << "\nNl: " << density_field_->particleNumber(index +
|
||||
// blitz::TinyVector<int, 5>(0,0,0,0,1));
|
||||
// out << "\nEl: " << energyBinBorders_[index(4) + 1];
|
||||
// out << "\nEr: " << energyBinBorders_[index(4) + 2];
|
||||
// // out << "\nenergy values: " << energyValues;
|
||||
// // out << "\npitch angle values: " << pitchAngleValues;
|
||||
// out << "\nenergy bin borders: [ ";
|
||||
// for(auto element : energyBinBorders_) {
|
||||
// out << element << " ";
|
||||
// }
|
||||
// out << "]";
|
||||
|
||||
// ERROR(out.str());
|
||||
// }
|
||||
#endif
|
||||
|
||||
#ifdef debug_level2
|
||||
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<double, 3> 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<double, 3> v_perp =
|
||||
perpendicularNormalVector(cartesianB_values);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user