Basic changes for time resolution.
Input from json still suboptimal.
This commit is contained in:
@@ -35,7 +35,9 @@ class Injector {
|
|||||||
std::shared_ptr<EventPositionDistribution> position_distribution,
|
std::shared_ptr<EventPositionDistribution> position_distribution,
|
||||||
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 int time_resolution_events);
|
||||||
double timePassed() const;
|
double timePassed() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -48,7 +50,8 @@ class Injector {
|
|||||||
std::mt19937* engine,
|
std::mt19937* engine,
|
||||||
const Coordinate& position,
|
const Coordinate& position,
|
||||||
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,
|
||||||
|
const double time_birth);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* INJECTOR_H */
|
#endif /* INJECTOR_H */
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ class Particle {
|
|||||||
// Vector* velocity);
|
// Vector* velocity);
|
||||||
Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
||||||
const Coordinate& position,
|
const Coordinate& position,
|
||||||
const Vector& velocity);
|
const Vector& velocity,
|
||||||
|
const double time_birth);
|
||||||
|
|
||||||
void position(const Coordinate& new_position);
|
void position(const Coordinate& new_position);
|
||||||
CartesianCoordinate position() const;
|
CartesianCoordinate position() const;
|
||||||
|
|||||||
@@ -34,13 +34,15 @@ class Simulation {
|
|||||||
void init(Parameter& parameter);
|
void init(Parameter& parameter);
|
||||||
void start();
|
void start();
|
||||||
void finalize();
|
void finalize();
|
||||||
void processEvents(int events);
|
void processEvents(int events, std::vector<particle::Particle>& backup_queue,
|
||||||
|
const int time_resolution_events);
|
||||||
void processUntilTermination(particle::Particle& particle,
|
void processUntilTermination(particle::Particle& particle,
|
||||||
std::vector<particle::Particle>& particle_queue);
|
std::vector<particle::Particle>& particle_queue,
|
||||||
|
std::vector<particle::Particle>& backup_queue);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<particle::Particle> determineInjectedParticles(
|
std::vector<particle::Particle> determineInjectedParticles(
|
||||||
RandomNumbers* random);
|
RandomNumbers* random, const int time_resolution_events);
|
||||||
|
|
||||||
double meanFreePath(particle::Particle& particle, RandomNumbers* random);
|
double meanFreePath(particle::Particle& particle, RandomNumbers* random);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "simulation/particle.h"
|
#include "simulation/particle.h"
|
||||||
|
|
||||||
class Geometry;
|
class Geometry;
|
||||||
|
class DynamicDensityField;
|
||||||
class Terminator {
|
class Terminator {
|
||||||
public:
|
public:
|
||||||
Terminator(long int max_interactions,
|
Terminator(long int max_interactions,
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ InteractionOutput ClusterFormation::performInteraction(
|
|||||||
const blitz::TinyVector<double, 3> v_cluster =
|
const blitz::TinyVector<double, 3> v_cluster =
|
||||||
kinematic::velocity(energy_eV, product_->mass_kg()) *
|
kinematic::velocity(energy_eV, product_->mass_kg()) *
|
||||||
v_target / kinematic::norm(v_target);
|
v_target / kinematic::norm(v_target);
|
||||||
particle::Particle cluster(product_, x_impact, CartesianVector(v_cluster));
|
particle::Particle cluster(product_, x_impact, CartesianVector(v_cluster),
|
||||||
|
particle.timeAlive());
|
||||||
|
|
||||||
InteractionOutput output;
|
InteractionOutput output;
|
||||||
output.add(cluster);
|
output.add(cluster);
|
||||||
|
|||||||
@@ -93,10 +93,14 @@ InteractionOutput ElectronIonization::performInteraction(
|
|||||||
|
|
||||||
particle.velocity(v_impact_new);
|
particle.velocity(v_impact_new);
|
||||||
|
|
||||||
|
|
||||||
|
const double time_birth = particle.timeAlive();
|
||||||
InteractionOutput output;
|
InteractionOutput output;
|
||||||
output.add(
|
output.add(
|
||||||
particle::Particle(electron_, x_impact, CartesianVector(v_ejected)));
|
particle::Particle(electron_, x_impact, CartesianVector(v_ejected),
|
||||||
output.add(particle::Particle(ion_, x_impact, CartesianVector(v_target)));
|
time_birth));
|
||||||
|
output.add(particle::Particle(ion_, x_impact, CartesianVector(v_target),
|
||||||
|
time_birth));
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,9 +133,10 @@ void CpuSynchronizer::synchronize(
|
|||||||
tracked_species) {
|
tracked_species) {
|
||||||
MPI_Barrier(MPI_COMM_WORLD);
|
MPI_Barrier(MPI_COMM_WORLD);
|
||||||
auto it = tracked_species.begin();
|
auto it = tracked_species.begin();
|
||||||
DEBUG_LEVEL_3("Timer Synchronization.");
|
// drops due to time being a global variable now
|
||||||
synchronize(it->second->dynamicDensityField()->timer_.get(),
|
//DEBUG_LEVEL_3("Timer Synchronization.");
|
||||||
it->second->lastSyncDensityField()->timer_.get());
|
//synchronize(it->second->dynamicDensityField()->timer_.get(),
|
||||||
|
// it->second->lastSyncDensityField()->timer_.get());
|
||||||
|
|
||||||
for (auto& pair : tracked_species) {
|
for (auto& pair : tracked_species) {
|
||||||
// DEBUG_LEVEL_3("dynden Synchronization.");
|
// DEBUG_LEVEL_3("dynden Synchronization.");
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ double DynamicDensityField::physicalTime() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DynamicDensityField::resetDynamicDensityField() {
|
void DynamicDensityField::resetDynamicDensityField() {
|
||||||
timer_->resetTime(); // reductive since shared between species
|
//timer_->resetTime(); // time stays global
|
||||||
time_in_bin_s_ = 0.;
|
time_in_bin_s_ = 0.;
|
||||||
deleted_particles_ = 0.;
|
deleted_particles_ = 0.;
|
||||||
density_per_m3_ = 0.;
|
density_per_m3_ = 0.;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "simulation/particle.h"
|
#include "simulation/particle.h"
|
||||||
#include "simulation/species.h"
|
#include "simulation/species.h"
|
||||||
#include "simulation/velocity_distribution.h"
|
#include "simulation/velocity_distribution.h"
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
Injector::Injector(
|
Injector::Injector(
|
||||||
std::vector<InjectorInfo>& injector_info,
|
std::vector<InjectorInfo>& injector_info,
|
||||||
@@ -26,7 +27,8 @@ particle::Particle Injector::rollNewParticle(
|
|||||||
std::mt19937* engine,
|
std::mt19937* engine,
|
||||||
const Coordinate& position,
|
const Coordinate& position,
|
||||||
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,
|
||||||
|
const double time_birth) {
|
||||||
blitz::TinyVector<double, 3> velocity =
|
blitz::TinyVector<double, 3> velocity =
|
||||||
creation_velocity_distribution->rollVelocity(position, engine)
|
creation_velocity_distribution->rollVelocity(position, engine)
|
||||||
.cartesianEntries();
|
.cartesianEntries();
|
||||||
@@ -35,20 +37,29 @@ particle::Particle Injector::rollNewParticle(
|
|||||||
velocity,
|
velocity,
|
||||||
mother_drift_velocity_->driftVelocity(position).cartesianEntries());
|
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,
|
return particle::Particle(created_specie, position,
|
||||||
CartesianVector(velocity));
|
CartesianVector(velocity), time_birth);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<particle::Particle> Injector::rollNewParticles(
|
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);
|
CylinderCoordinate position = position_distribution_->rollPosition(engine);
|
||||||
DEBUG_LEVEL_3("Injected z position: " +
|
DEBUG_LEVEL_3("Injected z position: " +
|
||||||
std::to_string(position.cylinderEntries()(2)));
|
std::to_string(position.cylinderEntries()(2)));
|
||||||
std::vector<particle::Particle> new_particles;
|
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_) {
|
for (auto& injector_info : injector_infos_) {
|
||||||
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));
|
||||||
}
|
}
|
||||||
return new_particles;
|
return new_particles;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,12 +20,13 @@ Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
|||||||
|
|
||||||
Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
||||||
const Coordinate& position,
|
const Coordinate& position,
|
||||||
const Vector& velocity)
|
const Vector& velocity,
|
||||||
|
const double time_birth)
|
||||||
: specie_(specie),
|
: specie_(specie),
|
||||||
position_(position),
|
position_(position),
|
||||||
velocity_(velocity, position),
|
velocity_(velocity, position),
|
||||||
id_(this->last_id_),
|
id_(this->last_id_),
|
||||||
time_alive_s_(0.),
|
time_alive_s_(time_birth),
|
||||||
time_in_bin_s_(0.),
|
time_in_bin_s_(0.),
|
||||||
interaction_counter_(0) {
|
interaction_counter_(0) {
|
||||||
last_id_++;
|
last_id_++;
|
||||||
|
|||||||
@@ -99,19 +99,33 @@ void Simulation::start() {
|
|||||||
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);
|
||||||
|
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("Total simulated events: " + std::to_string(total_simulated_events));
|
||||||
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 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));
|
SIM_INFO("Events per cpu (approx.): " + std::to_string(events_this_cpu));
|
||||||
int leftover_events = events_this_cpu;
|
int leftover_events = events_this_cpu;
|
||||||
|
|
||||||
int num_cpu_syncs = 0;
|
int num_cpu_syncs = 0;
|
||||||
bool reset = false;
|
bool reset = false;
|
||||||
|
std::vector<particle::Particle> backup_queue;
|
||||||
|
backup_queue.reserve(100); // probably should be a more sensible value
|
||||||
while (leftover_events > 0) {
|
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: " +
|
SIM_INFO("Leftover events on first cpu: " +
|
||||||
std::to_string(leftover_events));
|
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));
|
DEBUG_LEVEL_1("Leftover events: " + std::to_string(leftover_events));
|
||||||
leftover_events -= events_of_cylcle;
|
leftover_events -= events_of_cylcle;
|
||||||
@@ -154,10 +168,19 @@ int particleNumberFromQueue(int queue_length, RandomNumbers* random) {
|
|||||||
return random->rollUniform(0, queue_length);
|
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.");
|
DEBUG_LEVEL_0("Processing events.");
|
||||||
std::vector<particle::Particle> particle_queue;
|
std::vector<particle::Particle> particle_queue;
|
||||||
particle_queue.reserve(100);
|
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;
|
int current_event = 0;
|
||||||
while ((current_event < events) || (!particle_queue.empty())) {
|
while ((current_event < events) || (!particle_queue.empty())) {
|
||||||
DEBUG_LEVEL_2("Current event: " + std::to_string(current_event));
|
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.");
|
DEBUG_LEVEL_2("Inject particles to queue.");
|
||||||
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
|
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
|
||||||
std::vector<particle::Particle> new_particles =
|
std::vector<particle::Particle> new_particles =
|
||||||
determineInjectedParticles(random_.get());
|
determineInjectedParticles(random_.get(), time_resolution_events);
|
||||||
#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;
|
||||||
@@ -193,13 +216,14 @@ void Simulation::processEvents(int events) {
|
|||||||
particle::Particle particle = particle_queue.at(particle_number);
|
particle::Particle particle = particle_queue.at(particle_number);
|
||||||
particle_queue.erase(particle_queue.begin() + particle_number);
|
particle_queue.erase(particle_queue.begin() + particle_number);
|
||||||
|
|
||||||
processUntilTermination(particle, particle_queue);
|
processUntilTermination(particle, particle_queue, backup_queue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Simulation::processUntilTermination(
|
void Simulation::processUntilTermination(
|
||||||
particle::Particle& particle,
|
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");
|
DEBUG_LEVEL_3("Process particle until termination");
|
||||||
while (particle.specie()->terminator()->isAlive(&particle)) {
|
while (particle.specie()->terminator()->isAlive(&particle)) {
|
||||||
auto old_position = particle.position();
|
auto old_position = particle.position();
|
||||||
@@ -226,12 +250,9 @@ void Simulation::processUntilTermination(
|
|||||||
|
|
||||||
if (particle.specie()->terminator()->reachedMaxTimeAlive(
|
if (particle.specie()->terminator()->reachedMaxTimeAlive(
|
||||||
&particle)) {
|
&particle)) {
|
||||||
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name()
|
DEBUG_LEVEL_3("Move particle " + particle.specie()->name()
|
||||||
+". Reached max time alive.");
|
+" to backup queue.");
|
||||||
if (particle.specie()->deletionLogger()) {
|
backup_queue.push_back(particle);
|
||||||
particle.specie()->deletionLogger()->logDeletion(
|
|
||||||
particle.position(), DeletionType::max_time_alive);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
} else if (particle.specie()->terminator()->leftSimulationDomain(
|
} else if (particle.specie()->terminator()->leftSimulationDomain(
|
||||||
&particle)) {
|
&particle)) {
|
||||||
@@ -339,9 +360,10 @@ interaction::InteractionOutput Simulation::interact(
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<particle::Particle> Simulation::determineInjectedParticles(
|
std::vector<particle::Particle> Simulation::determineInjectedParticles(
|
||||||
RandomNumbers* random) {
|
RandomNumbers* random, const int time_resolution_events) {
|
||||||
timer_->increaseTimestep(injector_->timePassed());
|
// timer_->increaseTimestep(injector_->timePassed());
|
||||||
return injector_->rollNewParticles(random->engine());
|
return injector_->rollNewParticles(random->engine(),
|
||||||
|
timer_->time(), time_resolution_events);
|
||||||
}
|
}
|
||||||
|
|
||||||
//maybe put that into the poisson solver
|
//maybe put that into the poisson solver
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "simulation/errors.h"
|
#include "simulation/errors.h"
|
||||||
#include "simulation/geometry.h"
|
#include "simulation/geometry.h"
|
||||||
|
#include "simulation/density_field.h"
|
||||||
|
|
||||||
Terminator::Terminator(long int max_interactions,
|
Terminator::Terminator(long int max_interactions,
|
||||||
double max_time_alive,
|
double max_time_alive,
|
||||||
@@ -31,7 +32,8 @@ bool Terminator::reachedMaxInteractions(
|
|||||||
return particle->interactionCounter() > max_interactions_;
|
return particle->interactionCounter() > max_interactions_;
|
||||||
}
|
}
|
||||||
bool Terminator::reachedMaxTimeAlive(const particle::Particle* particle) const {
|
bool Terminator::reachedMaxTimeAlive(const particle::Particle* particle) const {
|
||||||
return particle->timeAlive() > max_time_alive_;
|
return particle->timeAlive() > particle->specie()->dynamicDensityField()
|
||||||
|
->physicalTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Terminator::leftSimulationDomain(
|
bool Terminator::leftSimulationDomain(
|
||||||
|
|||||||
Reference in New Issue
Block a user