Basic changes for time resolution.
Input from json still suboptimal.
This commit is contained in:
@@ -133,9 +133,10 @@ void CpuSynchronizer::synchronize(
|
||||
tracked_species) {
|
||||
MPI_Barrier(MPI_COMM_WORLD);
|
||||
auto it = tracked_species.begin();
|
||||
DEBUG_LEVEL_3("Timer Synchronization.");
|
||||
synchronize(it->second->dynamicDensityField()->timer_.get(),
|
||||
it->second->lastSyncDensityField()->timer_.get());
|
||||
// drops due to time being a global variable now
|
||||
//DEBUG_LEVEL_3("Timer Synchronization.");
|
||||
//synchronize(it->second->dynamicDensityField()->timer_.get(),
|
||||
// it->second->lastSyncDensityField()->timer_.get());
|
||||
|
||||
for (auto& pair : tracked_species) {
|
||||
// DEBUG_LEVEL_3("dynden Synchronization.");
|
||||
|
||||
@@ -206,7 +206,7 @@ double DynamicDensityField::physicalTime() const {
|
||||
}
|
||||
|
||||
void DynamicDensityField::resetDynamicDensityField() {
|
||||
timer_->resetTime(); // reductive since shared between species
|
||||
//timer_->resetTime(); // time stays global
|
||||
time_in_bin_s_ = 0.;
|
||||
deleted_particles_ = 0.;
|
||||
density_per_m3_ = 0.;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "simulation/particle.h"
|
||||
#include "simulation/species.h"
|
||||
#include "simulation/velocity_distribution.h"
|
||||
#include <sstream>
|
||||
|
||||
Injector::Injector(
|
||||
std::vector<InjectorInfo>& injector_info,
|
||||
@@ -26,7 +27,8 @@ particle::Particle Injector::rollNewParticle(
|
||||
std::mt19937* engine,
|
||||
const Coordinate& position,
|
||||
std::shared_ptr<species::TrackedSpecie> created_specie,
|
||||
std::shared_ptr<VelocityDistribution> creation_velocity_distribution) {
|
||||
std::shared_ptr<VelocityDistribution> creation_velocity_distribution,
|
||||
const double time_birth) {
|
||||
blitz::TinyVector<double, 3> velocity =
|
||||
creation_velocity_distribution->rollVelocity(position, engine)
|
||||
.cartesianEntries();
|
||||
@@ -35,20 +37,29 @@ particle::Particle Injector::rollNewParticle(
|
||||
velocity,
|
||||
mother_drift_velocity_->driftVelocity(position).cartesianEntries());
|
||||
}
|
||||
std::stringstream out;
|
||||
out << created_specie->name() << " created at time: " << time_birth << "s.";
|
||||
DEBUG_LEVEL_3(out.str());
|
||||
return particle::Particle(created_specie, position,
|
||||
CartesianVector(velocity));
|
||||
CartesianVector(velocity), time_birth);
|
||||
}
|
||||
|
||||
std::vector<particle::Particle> Injector::rollNewParticles(
|
||||
std::mt19937* engine) {
|
||||
std::mt19937* engine, const double current_time,
|
||||
const int time_resolution_events) {
|
||||
CylinderCoordinate position = position_distribution_->rollPosition(engine);
|
||||
DEBUG_LEVEL_3("Injected z position: " +
|
||||
std::to_string(position.cylinderEntries()(2)));
|
||||
std::vector<particle::Particle> new_particles;
|
||||
const double delta_t = time_resolution_events*timePassed();
|
||||
std::uniform_real_distribution<> injection_time(current_time - delta_t,
|
||||
current_time);
|
||||
const double time_birth = injection_time(*engine);
|
||||
for (auto& injector_info : injector_infos_) {
|
||||
new_particles.push_back(
|
||||
rollNewParticle(engine, position, injector_info.created_specie,
|
||||
injector_info.creation_velocity_distribution));
|
||||
injector_info.creation_velocity_distribution,
|
||||
time_birth));
|
||||
}
|
||||
return new_particles;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,13 @@ Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
||||
|
||||
Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
||||
const Coordinate& position,
|
||||
const Vector& velocity)
|
||||
const Vector& velocity,
|
||||
const double time_birth)
|
||||
: specie_(specie),
|
||||
position_(position),
|
||||
velocity_(velocity, position),
|
||||
id_(this->last_id_),
|
||||
time_alive_s_(0.),
|
||||
time_alive_s_(time_birth),
|
||||
time_in_bin_s_(0.),
|
||||
interaction_counter_(0) {
|
||||
last_id_++;
|
||||
|
||||
@@ -99,19 +99,33 @@ void Simulation::start() {
|
||||
parameter_.intValue(json_path({"Simulation", "EventStride"}), 1);
|
||||
const int total_simulated_events =
|
||||
parameter_.intValue(json_path({"Simulation", "SimulatedEvents"}), 1);
|
||||
const int time_resolution_events =
|
||||
parameter_.intValue(json_path({"Simulation", "TimeResolutionEvents"}),
|
||||
total_simulated_events);
|
||||
|
||||
SIM_INFO("Total simulated events: " + std::to_string(total_simulated_events));
|
||||
SIM_INFO("Simulated events before cpu sync: " + std::to_string(event_stride));
|
||||
const int events_this_cpu = eventsThisCpu(total_simulated_events);
|
||||
// maybe better as class memeber...
|
||||
const int time_resolution_this_cpu = eventsThisCpu(time_resolution_events);
|
||||
SIM_INFO("Events per cpu (approx.): " + std::to_string(events_this_cpu));
|
||||
int leftover_events = events_this_cpu;
|
||||
|
||||
int num_cpu_syncs = 0;
|
||||
bool reset = false;
|
||||
std::vector<particle::Particle> backup_queue;
|
||||
backup_queue.reserve(100); // probably should be a more sensible value
|
||||
while (leftover_events > 0) {
|
||||
int events_of_cylcle = eventsOfCycle(event_stride, leftover_events);
|
||||
timer_->increaseTimestep(time_resolution_events*injector_->timePassed());
|
||||
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, time_resolution_this_cpu);
|
||||
SIM_INFO("Leftover events on first cpu: " +
|
||||
std::to_string(leftover_events));
|
||||
processEvents(events_of_cylcle);
|
||||
processEvents(events_of_cylcle, backup_queue, time_resolution_events);
|
||||
DEBUG_LEVEL_3("Size of backup queue: " + std::to_string(backup_queue.size()));
|
||||
|
||||
DEBUG_LEVEL_1("Leftover events: " + std::to_string(leftover_events));
|
||||
leftover_events -= events_of_cylcle;
|
||||
@@ -154,10 +168,19 @@ int particleNumberFromQueue(int queue_length, RandomNumbers* random) {
|
||||
return random->rollUniform(0, queue_length);
|
||||
}
|
||||
|
||||
void Simulation::processEvents(int events) {
|
||||
void Simulation::processEvents(int events,
|
||||
std::vector<particle::Particle>& backup_queue,
|
||||
const int time_resolution_events) {
|
||||
DEBUG_LEVEL_0("Processing events.");
|
||||
std::vector<particle::Particle> particle_queue;
|
||||
particle_queue.reserve(100);
|
||||
DEBUG_LEVEL_3("Move backup to processing queue.");
|
||||
// highly inefficient in case that #cpu_syncs/time_res >> 1
|
||||
particle_queue.insert(particle_queue.end(), backup_queue.begin(),
|
||||
backup_queue.end());
|
||||
// clean backup_queue after moving the elements to the particle queue
|
||||
backup_queue.erase(backup_queue.begin(), backup_queue.end());
|
||||
DEBUG_LEVEL_3("Size processing queue: " + std::to_string(particle_queue.size()));
|
||||
int current_event = 0;
|
||||
while ((current_event < events) || (!particle_queue.empty())) {
|
||||
DEBUG_LEVEL_2("Current event: " + std::to_string(current_event));
|
||||
@@ -167,7 +190,7 @@ void Simulation::processEvents(int events) {
|
||||
DEBUG_LEVEL_2("Inject particles to queue.");
|
||||
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
|
||||
std::vector<particle::Particle> new_particles =
|
||||
determineInjectedParticles(random_.get());
|
||||
determineInjectedParticles(random_.get(), time_resolution_events);
|
||||
#if defined debug_level3
|
||||
for(auto& particle : new_particles) {
|
||||
std::stringstream output_ss;
|
||||
@@ -193,13 +216,14 @@ void Simulation::processEvents(int events) {
|
||||
particle::Particle particle = particle_queue.at(particle_number);
|
||||
particle_queue.erase(particle_queue.begin() + particle_number);
|
||||
|
||||
processUntilTermination(particle, particle_queue);
|
||||
processUntilTermination(particle, particle_queue, backup_queue);
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::processUntilTermination(
|
||||
particle::Particle& particle,
|
||||
std::vector<particle::Particle>& particle_queue) {
|
||||
std::vector<particle::Particle>& particle_queue,
|
||||
std::vector<particle::Particle>& backup_queue) {
|
||||
DEBUG_LEVEL_3("Process particle until termination");
|
||||
while (particle.specie()->terminator()->isAlive(&particle)) {
|
||||
auto old_position = particle.position();
|
||||
@@ -226,12 +250,9 @@ void Simulation::processUntilTermination(
|
||||
|
||||
if (particle.specie()->terminator()->reachedMaxTimeAlive(
|
||||
&particle)) {
|
||||
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name()
|
||||
+". Reached max time alive.");
|
||||
if (particle.specie()->deletionLogger()) {
|
||||
particle.specie()->deletionLogger()->logDeletion(
|
||||
particle.position(), DeletionType::max_time_alive);
|
||||
}
|
||||
DEBUG_LEVEL_3("Move particle " + particle.specie()->name()
|
||||
+" to backup queue.");
|
||||
backup_queue.push_back(particle);
|
||||
break;
|
||||
} else if (particle.specie()->terminator()->leftSimulationDomain(
|
||||
&particle)) {
|
||||
@@ -339,9 +360,10 @@ interaction::InteractionOutput Simulation::interact(
|
||||
}
|
||||
|
||||
std::vector<particle::Particle> Simulation::determineInjectedParticles(
|
||||
RandomNumbers* random) {
|
||||
timer_->increaseTimestep(injector_->timePassed());
|
||||
return injector_->rollNewParticles(random->engine());
|
||||
RandomNumbers* random, const int time_resolution_events) {
|
||||
// timer_->increaseTimestep(injector_->timePassed());
|
||||
return injector_->rollNewParticles(random->engine(),
|
||||
timer_->time(), time_resolution_events);
|
||||
}
|
||||
|
||||
//maybe put that into the poisson solver
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "simulation/errors.h"
|
||||
#include "simulation/geometry.h"
|
||||
#include "simulation/density_field.h"
|
||||
|
||||
Terminator::Terminator(long int max_interactions,
|
||||
double max_time_alive,
|
||||
@@ -31,7 +32,8 @@ bool Terminator::reachedMaxInteractions(
|
||||
return particle->interactionCounter() > max_interactions_;
|
||||
}
|
||||
bool Terminator::reachedMaxTimeAlive(const particle::Particle* particle) const {
|
||||
return particle->timeAlive() > max_time_alive_;
|
||||
return particle->timeAlive() > particle->specie()->dynamicDensityField()
|
||||
->physicalTime();
|
||||
}
|
||||
|
||||
bool Terminator::leftSimulationDomain(
|
||||
|
||||
Reference in New Issue
Block a user