Decoupled the number of events simulated from
the timestep; Bug with density drawing present (if CPU syncs don't line up with the timestep)
This commit is contained in:
@@ -28,7 +28,7 @@ struct InjectorInfo {
|
|||||||
public:
|
public:
|
||||||
std::shared_ptr<species::TrackedSpecie> created_specie;
|
std::shared_ptr<species::TrackedSpecie> created_specie;
|
||||||
std::shared_ptr<VelocityDistribution> creation_velocity_distribution;
|
std::shared_ptr<VelocityDistribution> creation_velocity_distribution;
|
||||||
int multiplicity;
|
// int multiplicity;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Injector {
|
class Injector {
|
||||||
@@ -39,7 +39,8 @@ class Injector {
|
|||||||
std::shared_ptr<DriftVelocity> mother_drift_velocity);
|
std::shared_ptr<DriftVelocity> mother_drift_velocity);
|
||||||
|
|
||||||
std::vector<particle::Particle> rollNewParticles(std::mt19937* engine,
|
std::vector<particle::Particle> rollNewParticles(std::mt19937* engine,
|
||||||
const double current_time);
|
const double current_time,
|
||||||
|
const double beta_particle_weight);
|
||||||
|
|
||||||
// draw new particles from the DynamicDensityField of the provided specie
|
// draw new particles from the DynamicDensityField of the provided specie
|
||||||
// the new particles are then appened to the vector queue
|
// the new particles are then appened to the vector queue
|
||||||
|
|||||||
@@ -36,11 +36,13 @@ class Simulation {
|
|||||||
void finalize();
|
void finalize();
|
||||||
// cpu_syncs only included for debug purposes, e.g. only drawing decay particles
|
// cpu_syncs only included for debug purposes, e.g. only drawing decay particles
|
||||||
// at the 0th timestep
|
// at the 0th timestep
|
||||||
void processEvents(int events, int density_events, int cpu_syncs);
|
void processEvents(int events, int density_events, int cpu_syncs,
|
||||||
|
const double beta_particle_weight);
|
||||||
void processUntilTermination(particle::Particle& particle);
|
void processUntilTermination(particle::Particle& particle);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<particle::Particle> determineInjectedParticles(RandomNumbers* random);
|
std::vector<particle::Particle> determineInjectedParticles(RandomNumbers* random,
|
||||||
|
const double beta_particle_weight);
|
||||||
std::vector<particle::Particle>
|
std::vector<particle::Particle>
|
||||||
determineInjectedDensityParticles(RandomNumbers* random,
|
determineInjectedDensityParticles(RandomNumbers* random,
|
||||||
const int numberParticlesToDraw, const int current,
|
const int numberParticlesToDraw, const int current,
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ std::shared_ptr<Injector> buildInjector(
|
|||||||
json_path_append(path_to_injector, {"CreatedSpecies", std::string(key),
|
json_path_append(path_to_injector, {"CreatedSpecies", std::string(key),
|
||||||
"CreationVelocityDistribution"}));
|
"CreationVelocityDistribution"}));
|
||||||
|
|
||||||
info.multiplicity = json_int(json_object_by_path(value, {"Multiplicity"}), 1);
|
// info.multiplicity = json_int(json_object_by_path(value, {"Multiplicity"}), 1);
|
||||||
ASSERT_POSITIVE(&info.multiplicity, "The multiplicity has to be positive. " +
|
// ASSERT_POSITIVE(&info.multiplicity, "The multiplicity has to be positive. " +
|
||||||
specie_name + " multiplicity: " + std::to_string(info.multiplicity));
|
// specie_name + " multiplicity: " + std::to_string(info.multiplicity));
|
||||||
injector_infos.push_back(info);
|
injector_infos.push_back(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,9 +40,13 @@ particle::Particle Injector::rollNewParticle(
|
|||||||
velocity,
|
velocity,
|
||||||
mother_drift_velocity_->driftVelocity(position).cartesianEntries());
|
mother_drift_velocity_->driftVelocity(position).cartesianEntries());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined debug_level3
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
out << created_specie->name() << " created at time: " << time_birth << "s.";
|
out << created_specie->name() << " created at time: " << time_birth << "s.";
|
||||||
DEBUG_LEVEL_3(out.str());
|
DEBUG_LEVEL_3(out.str());
|
||||||
|
#endif
|
||||||
|
|
||||||
return particle::Particle(created_specie, position,
|
return particle::Particle(created_specie, position,
|
||||||
CartesianVector(velocity), time_birth, weight);
|
CartesianVector(velocity), time_birth, weight);
|
||||||
}
|
}
|
||||||
@@ -53,26 +57,28 @@ void Injector::initInjectionTimeDistribution(double delta_t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<particle::Particle> Injector::rollNewParticles(
|
std::vector<particle::Particle> Injector::rollNewParticles(
|
||||||
std::mt19937* engine, const double current_time) {
|
std::mt19937* engine, const double current_time,
|
||||||
|
const double beta_particle_weight) {
|
||||||
// pull drawing from the position distribution into the "multiplicity" loop?
|
// pull drawing from the position distribution into the "multiplicity" loop?
|
||||||
// (would improve resolution stuff in space as well as just in velocity direction
|
// (would improve resolution stuff in space as well as just in velocity direction
|
||||||
// especially for slow particles, i.e. ions)
|
// especially for slow particles, i.e. ions)
|
||||||
CylinderCoordinate position = position_distribution_->rollPosition(engine);
|
|
||||||
DEBUG_LEVEL_3("Injected z position: " +
|
|
||||||
std::to_string(position.cylinderEntries()(2)));
|
|
||||||
std::vector<particle::Particle> new_particles;
|
std::vector<particle::Particle> new_particles;
|
||||||
|
|
||||||
const double time_birth = current_time - injection_time_distribution_(*engine);
|
const double time_birth = current_time - injection_time_distribution_(*engine);
|
||||||
|
|
||||||
for (auto& injector_info : injector_infos_) {
|
for (auto& injector_info : injector_infos_) {
|
||||||
const double weight = 1./injector_info.multiplicity;
|
|
||||||
|
CylinderCoordinate position = position_distribution_->rollPosition(engine);
|
||||||
|
DEBUG_LEVEL_3("Injected z position: " +
|
||||||
|
std::to_string(position.cylinderEntries()(2)));
|
||||||
|
|
||||||
for (int i = 0; i < injector_info.multiplicity; i++) {
|
// for (int i = 0; i < injector_info.multiplicity; i++) {
|
||||||
new_particles.push_back(
|
new_particles.push_back(
|
||||||
rollNewParticle(engine, position, injector_info.created_specie,
|
rollNewParticle(engine, position, injector_info.created_specie,
|
||||||
injector_info.creation_velocity_distribution,
|
injector_info.creation_velocity_distribution,
|
||||||
time_birth, weight));
|
time_birth, beta_particle_weight));
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
return new_particles;
|
return new_particles;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,47 +109,55 @@ void Simulation::finalize() {
|
|||||||
void Simulation::start() {
|
void Simulation::start() {
|
||||||
SIM_INFO("Starting Simulation.");
|
SIM_INFO("Starting Simulation.");
|
||||||
|
|
||||||
|
// stride wrt the number of beta decay events per CPU
|
||||||
const int event_stride =
|
const int event_stride =
|
||||||
parameter_.intValue(json_path({"Simulation", "EventStride"}), 1);
|
parameter_.intValue(json_path({"Simulation", "EventStride"}), 1);
|
||||||
// const int total_simulated_events =
|
// const int total_simulated_events =
|
||||||
// parameter_.intValue(json_path({"Simulation", "SimulatedEvents"}), 1);
|
// parameter_.intValue(json_path({"Simulation", "SimulatedEvents"}), 1);
|
||||||
|
|
||||||
|
// number of timesteps to be simulated
|
||||||
const int number_timesteps = parameter_.intValue(json_path({"Simulation",
|
const int number_timesteps = parameter_.intValue(json_path({"Simulation",
|
||||||
"NumberTimesteps"}), 1);
|
"NumberTimesteps"}), 1);
|
||||||
|
|
||||||
|
// number of physical beta events defining the timescale by
|
||||||
|
// time_resolution_events/Activity
|
||||||
const int time_resolution_events =
|
const int time_resolution_events =
|
||||||
parameter_.intValue(json_path({"Simulation", "TimeResolutionEvents"}),
|
parameter_.intValue(json_path({"Simulation", "TimeResolutionEvents"}),
|
||||||
MpiCommunication::mpiSize());
|
MpiCommunication::mpiSize());
|
||||||
|
|
||||||
|
// number of beta decay events per timestep and CPU (will get normalized s.t.
|
||||||
|
// the physical number of particles is correct)
|
||||||
|
const int beta_decay_events =
|
||||||
|
parameter_.intValue(json_path{"Simulation", "BetaDecayEventsPerCPU"}, 1);
|
||||||
|
|
||||||
|
// weight of a particle created through beta decay wrt a physical particle
|
||||||
|
const double beta_particle_weight = time_resolution_events/
|
||||||
|
static_cast<double>(beta_decay_events*MpiCommunication::mpiSize());
|
||||||
|
|
||||||
|
// number of density events per timestep and CPU
|
||||||
const int density_events =
|
const int density_events =
|
||||||
parameter_.intValue(json_path({"Simulation", "DensityEventsPerCPU"}), 0);
|
parameter_.intValue(json_path({"Simulation", "DensityEventsPerCPU"}), 0);
|
||||||
DEBUG_LEVEL_0("Density events per cpu: " + std::to_string(density_events));
|
DEBUG_LEVEL_0("Density events per cpu: " + std::to_string(density_events));
|
||||||
|
|
||||||
// if(total_simulated_events % MpiCommunication::mpiSize() != 0) {
|
|
||||||
// ERROR("total simulated events are not divisible by the number of mpi procs");
|
|
||||||
// }
|
|
||||||
// if(time_resolution_events % MpiCommunication::mpiSize() != 0) {
|
|
||||||
// ERROR("time resolution events are not divisible by the number of mpi procs");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// SIM_INFO("Total simulated events: " + std::to_string(total_simulated_events));
|
|
||||||
SIM_INFO("Number of Timesteps: " + std::to_string(number_timesteps));
|
SIM_INFO("Number of Timesteps: " + std::to_string(number_timesteps));
|
||||||
SIM_INFO("Simulated events before cpu sync: " + std::to_string(event_stride));
|
SIM_INFO("Simulated events before cpu sync: " + std::to_string(event_stride));
|
||||||
// const int events_this_cpu = eventsThisCpu(total_simulated_events);
|
// const int time_resolution_this_cpu = eventsThisCpu(time_resolution_events);
|
||||||
const int time_resolution_this_cpu = eventsThisCpu(time_resolution_events);
|
|
||||||
|
|
||||||
if(time_resolution_events % MpiCommunication::mpiSize() != 0) {
|
// if(time_resolution_events % MpiCommunication::mpiSize() != 0) {
|
||||||
if(time_resolution_events % MpiCommunication::mpiSize() <= MpiCommunication::mpiRank() &&
|
// if(time_resolution_events % MpiCommunication::mpiSize() <= MpiCommunication::mpiRank() &&
|
||||||
time_resolution_this_cpu % event_stride == 0) {
|
// time_resolution_this_cpu % event_stride == 0) {
|
||||||
ERROR("Code will not terminate! The event stride: " + std::to_string(event_stride) +
|
// ERROR("Code will not terminate! The event stride: " + std::to_string(event_stride) +
|
||||||
", the number of CPUs: " + std::to_string(MpiCommunication::mpiSize()) +
|
// ", the number of CPUs: " + std::to_string(MpiCommunication::mpiSize()) +
|
||||||
" and the number of events per timestep: " + std::to_string(time_resolution_events) +
|
// " and the number of events per timestep: " + std::to_string(time_resolution_events) +
|
||||||
" create at least one CPU for which the number of CPU syncs for one timestep " +
|
// " create at least one CPU for which the number of CPU syncs for one timestep " +
|
||||||
" differs from the rest of the CPUs.");
|
// " differs from the rest of the CPUs.");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
SIM_INFO("Events per cpu (approx.) per timestep: " +
|
// SIM_INFO("Events per cpu (approx.) per timestep: " +
|
||||||
std::to_string(time_resolution_this_cpu));
|
// std::to_string(time_resolution_this_cpu));
|
||||||
// int leftover_events = events_this_cpu;
|
// int leftover_events = events_this_cpu;
|
||||||
int leftover_events_time_resolution = time_resolution_this_cpu;
|
int leftover_events_time_resolution = beta_decay_events;
|
||||||
|
|
||||||
const double delta_t = time_resolution_events*injector_->timePassed();
|
const double delta_t = time_resolution_events*injector_->timePassed();
|
||||||
|
|
||||||
@@ -189,17 +197,21 @@ void Simulation::start() {
|
|||||||
out << "Timeinterval: " << timer_->time() << "s.";
|
out << "Timeinterval: " << timer_->time() << "s.";
|
||||||
DEBUG_LEVEL_3(out.str());
|
DEBUG_LEVEL_3(out.str());
|
||||||
|
|
||||||
int events_of_cylcle = eventsOfCycle(event_stride, leftover_events_time_resolution);
|
int events_of_cycle = eventsOfCycle(event_stride, leftover_events_time_resolution);
|
||||||
SIM_INFO("Leftover timesteps this CPU: " + std::to_string(number_timesteps - timesteps));
|
|
||||||
|
SIM_INFO("Leftover timesteps this CPU: " +
|
||||||
|
std::to_string(number_timesteps - timesteps));
|
||||||
SIM_INFO("Leftover events this timestep this CPU: " +
|
SIM_INFO("Leftover events this timestep this CPU: " +
|
||||||
std::to_string(leftover_events_time_resolution));
|
std::to_string(leftover_events_time_resolution));
|
||||||
processEvents(events_of_cylcle, density_events, num_cpu_syncs);
|
|
||||||
|
processEvents(events_of_cycle, density_events, num_cpu_syncs,
|
||||||
|
beta_particle_weight);
|
||||||
|
|
||||||
DEBUG_LEVEL_1("Leftover timesteps: " + std::to_string(number_timesteps - timesteps));
|
DEBUG_LEVEL_1("Leftover timesteps: " + std::to_string(number_timesteps - timesteps));
|
||||||
DEBUG_LEVEL_1("Leftover events this timestep: " +
|
DEBUG_LEVEL_1("Leftover events this timestep: " +
|
||||||
std::to_string(leftover_events_time_resolution));
|
std::to_string(leftover_events_time_resolution));
|
||||||
// leftover_events -= events_of_cylcle;
|
// leftover_events -= events_of_cylcle;
|
||||||
leftover_events_time_resolution -= events_of_cylcle;
|
leftover_events_time_resolution -= events_of_cycle;
|
||||||
|
|
||||||
// Problem: proc 0: simuliert erst 2 dann 1
|
// Problem: proc 0: simuliert erst 2 dann 1
|
||||||
// proc 1: simuliert nur 2
|
// proc 1: simuliert nur 2
|
||||||
@@ -227,7 +239,6 @@ void Simulation::start() {
|
|||||||
SimulationTimer::eventStartPoint(std::string("PoissonStep"));
|
SimulationTimer::eventStartPoint(std::string("PoissonStep"));
|
||||||
poisson_solver_->solvePotential(chargedensity(), reset);
|
poisson_solver_->solvePotential(chargedensity(), reset);
|
||||||
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
|
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
|
||||||
|
|
||||||
SimulationTimer::eventStopPoint(std::string("PoissonStep"));
|
SimulationTimer::eventStopPoint(std::string("PoissonStep"));
|
||||||
|
|
||||||
SIM_INFO("Perform output.");
|
SIM_INFO("Perform output.");
|
||||||
@@ -250,7 +261,7 @@ void Simulation::start() {
|
|||||||
// the density from which new particles are drawn is only updated after a timestep
|
// the density from which new particles are drawn is only updated after a timestep
|
||||||
pair.second->positionDistributionFromDensity()->setMaximumDensity();
|
pair.second->positionDistributionFromDensity()->setMaximumDensity();
|
||||||
}
|
}
|
||||||
leftover_events_time_resolution = time_resolution_this_cpu;
|
leftover_events_time_resolution = beta_decay_events;
|
||||||
timesteps++;
|
timesteps++;
|
||||||
}
|
}
|
||||||
SimulationTimer::eventStopPoint("Reset");
|
SimulationTimer::eventStopPoint("Reset");
|
||||||
@@ -261,7 +272,8 @@ int particleNumberFromQueue(int queue_length, RandomNumbers* random) {
|
|||||||
return random->rollUniform(0, queue_length);
|
return random->rollUniform(0, queue_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Simulation::processEvents(int events, int density_events, int cpu_syncs) {
|
void Simulation::processEvents(int events, int density_events, int cpu_syncs,
|
||||||
|
const double beta_particle_weight) {
|
||||||
DEBUG_LEVEL_0("Processing events.");
|
DEBUG_LEVEL_0("Processing events.");
|
||||||
int current_event = 0;
|
int current_event = 0;
|
||||||
int current_density_event = 0;
|
int current_density_event = 0;
|
||||||
@@ -284,7 +296,8 @@ void Simulation::processEvents(int events, int density_events, int cpu_syncs) {
|
|||||||
current_event += 1;
|
current_event += 1;
|
||||||
DEBUG_LEVEL_2("Inject particles to queue.");
|
DEBUG_LEVEL_2("Inject particles to queue.");
|
||||||
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
|
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
|
||||||
new_particles = determineInjectedParticles(random_.get());
|
new_particles = determineInjectedParticles(random_.get(),
|
||||||
|
beta_particle_weight);
|
||||||
// construction of stringstream can take up a lot of computation time
|
// construction of stringstream can take up a lot of computation time
|
||||||
// even if the debug output performs nothing therefore use the if defined
|
// even if the debug output performs nothing therefore use the if defined
|
||||||
// preprocessor directive
|
// preprocessor directive
|
||||||
@@ -305,11 +318,11 @@ void Simulation::processEvents(int events, int density_events, int cpu_syncs) {
|
|||||||
DEBUG_LEVEL_2("Current density event: " +
|
DEBUG_LEVEL_2("Current density event: " +
|
||||||
std::to_string(current_density_event));
|
std::to_string(current_density_event));
|
||||||
//maybe use a different event name?
|
//maybe use a different event name?
|
||||||
SimulationTimer::eventStartPoint(std::string("DensityParticleInjection"));
|
SimulationTimer::eventStartPoint(std::string("DensityInjection"));
|
||||||
new_particles = determineInjectedDensityParticles(random_.get(), density_events,
|
new_particles = determineInjectedDensityParticles(random_.get(), density_events,
|
||||||
current_density_event,
|
current_density_event,
|
||||||
particleNumbers);
|
particleNumbers);
|
||||||
SimulationTimer::eventStopPoint(std::string("DensityParticleInjection"));
|
SimulationTimer::eventStopPoint(std::string("DensityInjection"));
|
||||||
#if defined debug_level3
|
#if defined debug_level3
|
||||||
for(auto& particle : new_particles) {
|
for(auto& particle : new_particles) {
|
||||||
std::stringstream output_ss;
|
std::stringstream output_ss;
|
||||||
@@ -497,8 +510,9 @@ interaction::InteractionOutput Simulation::interact(
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<particle::Particle> Simulation::determineInjectedParticles(
|
std::vector<particle::Particle> Simulation::determineInjectedParticles(
|
||||||
RandomNumbers* random) {
|
RandomNumbers* random, const double beta_particle_weight) {
|
||||||
return injector_->rollNewParticles(random->engine(), timer_->time());
|
return injector_->rollNewParticles(random->engine(), timer_->time(),
|
||||||
|
beta_particle_weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
||||||
|
|||||||
Reference in New Issue
Block a user