Moved drawing from density to seperate classes
This commit is contained in:
@@ -33,6 +33,8 @@
|
||||
#include "generators/gravity_field_generator.h"
|
||||
#include "generators/restart_generator.h"
|
||||
|
||||
#include "simulation/event_position_distribution.h"
|
||||
|
||||
#include "tools/simulation_time.h"
|
||||
|
||||
Simulation::Simulation(std::string parameter_filename)
|
||||
@@ -185,7 +187,6 @@ void Simulation::start() {
|
||||
while (timesteps < number_timesteps) {
|
||||
std::stringstream out;
|
||||
out << "Timeinterval: " << timer_->time() << "s.";
|
||||
// out << "\n size of particle: " << sizeof(particle::Particle);
|
||||
DEBUG_LEVEL_3(out.str());
|
||||
|
||||
int events_of_cylcle = eventsOfCycle(event_stride, leftover_events_time_resolution);
|
||||
@@ -235,25 +236,24 @@ void Simulation::start() {
|
||||
random_->engine());
|
||||
SimulationTimer::eventStopPoint(std::string("Output"));
|
||||
|
||||
SimulationTimer::eventStartPoint("Reset");
|
||||
if(reset) {
|
||||
SIM_INFO("Do resets and increase the timestep for timeresolution.");
|
||||
timer_->increaseTimestep(delta_t);
|
||||
for(auto& pair : tracked_species_) {
|
||||
pair.second->dynamicDensityField()->resetDynamicDensityField();
|
||||
// pair.second->dynamicDensityFieldWithPitchAngle()->resetDynamicDensityField();
|
||||
|
||||
// questionable if they need to be reset:
|
||||
// + time res in current
|
||||
// - ions very slow -> very unlikely that an ion crosses a boundary
|
||||
pair.second->currentCollector()->resetCurrentCollector();
|
||||
|
||||
// do not need to be reset, since the time resolution considers the same
|
||||
// set of particles
|
||||
pair.second->deletionLogger()->resetDeletionLogger();
|
||||
|
||||
// the density from which new particles are drawn is only updated after a timestep
|
||||
pair.second->positionDistributionFromDensity()->setMaximumDensity();
|
||||
}
|
||||
leftover_events_time_resolution = time_resolution_this_cpu;
|
||||
timesteps++;
|
||||
}
|
||||
SimulationTimer::eventStopPoint("Reset");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,14 +281,13 @@ void Simulation::processEvents(int events, int density_events, int cpu_syncs) {
|
||||
if (queue_.empty()) {
|
||||
std::vector<particle::Particle> new_particles;
|
||||
if(current_density_event == density_events) {
|
||||
// if(cpu_syncs > 0) {
|
||||
// DEBUG_LEVEL_3("Break while loop.");
|
||||
// break;
|
||||
// }
|
||||
current_event += 1;
|
||||
DEBUG_LEVEL_2("Inject particles to queue.");
|
||||
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
|
||||
new_particles = determineInjectedParticles(random_.get());
|
||||
// construction of stringstream can take up a lot of computation time
|
||||
// even if the debug output performs nothing therefore use the if defined
|
||||
// preprocessor directive
|
||||
#if defined debug_level3
|
||||
for(auto& particle : new_particles) {
|
||||
std::stringstream output_ss;
|
||||
@@ -390,12 +389,14 @@ void Simulation::processUntilTermination(
|
||||
break;
|
||||
} else if (particle.specie()->terminator()->leftSimulationDomain(
|
||||
&particle)) {
|
||||
#if defined debug_level3
|
||||
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name()
|
||||
+ ". Left simulation domain.");
|
||||
std::stringstream output_ss;
|
||||
output_ss << "Position (cyl): " << particle.position().cylinderEntries();
|
||||
output_ss << " (cart): " << particle.position().cartesianEntries();
|
||||
DEBUG_LEVEL_3(output_ss.str());
|
||||
#endif
|
||||
if (particle.specie()->deletionLogger()) {
|
||||
particle.specie()->deletionLogger()->logDeletion(particle.position(),
|
||||
DeletionType::wall);
|
||||
@@ -413,10 +414,12 @@ void Simulation::processUntilTermination(
|
||||
std::to_string(particle.interactionCounter()));
|
||||
DEBUG_LEVEL_3("Ekin before interact: " +
|
||||
std::to_string(particle.kineticEnergy_eV()));
|
||||
#if defined debug_level3
|
||||
std::stringstream output_ss;
|
||||
output_ss << "Position (cyl): " << particle.position().cylinderEntries();
|
||||
// output_ss << "\n (cart): " << particle.position().cartesianEntries();
|
||||
DEBUG_LEVEL_3(output_ss.str());
|
||||
#endif
|
||||
|
||||
SimulationTimer::eventStartPoint(std::string("Interaction"));
|
||||
interaction::InteractionOutput output = interact(particle, random_.get(),
|
||||
@@ -479,6 +482,7 @@ interaction::InteractionOutput Simulation::interact(
|
||||
|
||||
if (total_macroscopic_cross_section_m <= 0.) {
|
||||
// do nothing
|
||||
SIM_INFO("total mcs <= 0");
|
||||
return interaction::InteractionOutput();
|
||||
} else {
|
||||
std::discrete_distribution<int> interaction_decider(
|
||||
@@ -494,7 +498,6 @@ interaction::InteractionOutput Simulation::interact(
|
||||
|
||||
std::vector<particle::Particle> Simulation::determineInjectedParticles(
|
||||
RandomNumbers* random) {
|
||||
// timer_->increaseTimestep(injector_->timePassed());
|
||||
return injector_->rollNewParticles(random->engine(), timer_->time());
|
||||
}
|
||||
|
||||
@@ -502,15 +505,21 @@ std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
||||
RandomNumbers* random, const int numberParticlesToDraw, const int current,
|
||||
std::map<std::string, double>& particleNumbers) {
|
||||
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");
|
||||
ERROR("In drawing particles from the density:"
|
||||
" the new particles vector is not empty at initialization");
|
||||
}
|
||||
|
||||
const double injection_time = timer_->time() - timer_->getDeltaT();
|
||||
|
||||
for(auto& pair: tracked_species_) {
|
||||
if (particleNumbers[pair.first] == 0) {
|
||||
DEBUG_LEVEL_3("No particles in density of species: " + pair.second->name());
|
||||
continue;
|
||||
}
|
||||
|
||||
#if defined debug_level3
|
||||
if (current == 0) {
|
||||
std::stringstream out;
|
||||
out << pair.second->name();
|
||||
@@ -518,12 +527,14 @@ std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
||||
out << particleNumbers[pair.first];
|
||||
DEBUG_LEVEL_3(out.str());
|
||||
}
|
||||
injector_->rollNewParticleFromDensityField(random->engine(),
|
||||
pair.second,
|
||||
new_particles,
|
||||
magnetic_field_,
|
||||
particleNumbers[pair.first]/numberParticlesToDraw/MpiCommunication::mpiSize(),
|
||||
injection_time);
|
||||
#endif
|
||||
|
||||
double weight = particleNumbers[pair.first]/numberParticlesToDraw
|
||||
/MpiCommunication::mpiSize();
|
||||
|
||||
injector_->drawNewParticleFromDensityField(random->engine(),
|
||||
pair.second, new_particles, magnetic_field_,
|
||||
weight, injection_time);
|
||||
}
|
||||
return new_particles;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user