debug statements in preprocessor clause

This commit is contained in:
2025-06-04 09:39:50 +02:00
parent 90d19b0cb7
commit 2439f4fca9
11 changed files with 83 additions and 3 deletions
+24
View File
@@ -51,7 +51,9 @@ void SimulationOutput::writeSimulationData(
int cpu_sync,
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species) {
if (MpiCommunication::mpi_rank == 0) {
#ifdef debug_level2
DEBUG_LEVEL_2("Write density field data.");
#endif
for (auto& task : tasks_density_fields_) {
if (cpu_sync % task.intervall == 0) {
std::string specie_path = "/" + task.specie_name;
@@ -59,7 +61,9 @@ void SimulationOutput::writeSimulationData(
specie_path, cpu_sync, task.overwrite_last);
}
}
#ifdef debug_level2
DEBUG_LEVEL_2("Write current collector data.");
#endif
for (auto& task : tasks_current_collector_) {
if (cpu_sync % task.intervall == 0) {
std::string specie_path = "/" + task.specie_name;
@@ -67,7 +71,9 @@ void SimulationOutput::writeSimulationData(
specie_path, cpu_sync, task.overwrite_last);
}
}
#ifdef debug_level2
DEBUG_LEVEL_2("Write deletion logger data.");
#endif
for (auto& task : tasks_deletion_logger_) {
if (cpu_sync % task.intervall == 0) {
std::string specie_path = "/" + task.specie_name;
@@ -88,15 +94,25 @@ void SimulationOutput::writeSimulationData(DynamicDensityField* density_field,
}
std::string path = species_path + "/DensityField/SimulationData/" + sync_path;
#ifdef debug_level3
DEBUG_LEVEL_3("Write spectrum.");
#endif
writeSpectrum(density_field, path);
#ifdef debug_level3
DEBUG_LEVEL_3("Write density.");
#endif
writeDensity(density_field, path);
#ifdef debug_level3
DEBUG_LEVEL_3("Write time in bin.");
#endif
writeTimeInBin(density_field, path);
#ifdef debug_level3
DEBUG_LEVEL_3("Write deleted particles.");
#endif
writeDeletedParticles(density_field, path);
#ifdef debug_level3
DEBUG_LEVEL_3("Write physical time.");
#endif
writePhysicalTime(density_field, path);
}
@@ -110,11 +126,17 @@ void SimulationOutput::writeSimulationData(CurrentCollector* current_collector,
}
std::string path =
species_path + "/CurrentCollector/SimulationData/" + sync_path;
#ifdef debug_level3
DEBUG_LEVEL_3("Write current crossings.");
#endif
writeCurrentCrossings(current_collector, path);
#ifdef debug_level3
DEBUG_LEVEL_3("Write current.");
#endif
writeCurrent(current_collector, path);
#ifdef debug_level3
DEBUG_LEVEL_3("Write physical time.");
#endif
writePhysicalTime(current_collector, path);
}
@@ -127,7 +149,9 @@ void SimulationOutput::writeSimulationData(DeletionLogger* logger,
sync_path = "LastSyncPeriod";
}
std::string path = species_path + "/DeletionLogger/" + sync_path;
#ifdef debug_level3
DEBUG_LEVEL_3("Write number of deletions.");
#endif
writeNumDeletions(logger, path);
}
+2
View File
@@ -13,7 +13,9 @@ ChargeExchange::ChargeExchange(std::function<double(double)> cross_section,
InteractionOutput ChargeExchange::performInteraction(
particle::Particle& particle,
RandomNumbers* generator) {
#ifdef debug_level3
DEBUG_LEVEL_3("Perform charge exchange.");
#endif
const auto x_impact = particle.position();
// draw velocity of the target specie
+2
View File
@@ -18,7 +18,9 @@ ClusterFormation::ClusterFormation(
InteractionOutput ClusterFormation::performInteraction(
particle::Particle& particle,
RandomNumbers* generator) {
#ifdef debug_level3
DEBUG_LEVEL_3("Perform cluster formation.");
#endif
const auto x_impact = particle.position();
const blitz::TinyVector<double, 3> v_target =
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
+2
View File
@@ -18,7 +18,9 @@ ElasticScattering::ElasticScattering(
InteractionOutput ElasticScattering::performInteraction(
particle::Particle& particle,
RandomNumbers* generator) {
#ifdef debug_level3
DEBUG_LEVEL_3("Perform elastic scattering.");
#endif
// get the information of the incident particle
const blitz::TinyVector<double, 3> v_impact =
particle.velocity().cartesianEntries();
+2
View File
@@ -18,7 +18,9 @@ Excitation::Excitation(std::function<double(double)> cross_section,
InteractionOutput Excitation::performInteraction(particle::Particle& particle,
RandomNumbers* generator) {
#ifdef debug_level3
DEBUG_LEVEL_3("Perform excitation.");
#endif
const blitz::TinyVector<double, 3> v_impact =
particle.velocity().cartesianEntries();
const blitz::TinyVector<double, 3> n_impact =
+2
View File
@@ -10,7 +10,9 @@ FreeMovement::FreeMovement()
InteractionOutput FreeMovement::performInteraction(particle::Particle& particle,
RandomNumbers* generator) {
#ifdef debug_level3
DEBUG_LEVEL_3("Perform free movement.");
#endif
// do nothing
return InteractionOutput();
}
+2
View File
@@ -29,7 +29,9 @@ ElectronIonization::ElectronIonization(
InteractionOutput ElectronIonization::performInteraction(
particle::Particle& particle,
RandomNumbers* generator) {
#ifdef debug_level3
DEBUG_LEVEL_3("Perform ionization.");
#endif
const blitz::TinyVector<double, 3> v_impact =
particle.velocity().cartesianEntries();
+2
View File
@@ -16,7 +16,9 @@ Recombination::Recombination(std::function<double(double)> cross_section,
InteractionOutput Recombination::performInteraction(
particle::Particle& particle,
RandomNumbers* generator) {
#ifdef debug_level3
DEBUG_LEVEL_3("Perform recombination.");
#endif
std::vector<double> macroscopic_bin_cross_sections_m;
const int number_energy_bins = recombination_target_->dynamicDensityField()
+1 -1
View File
@@ -133,7 +133,7 @@ void CpuSynchronizer::synchronize(
tracked_species) {
MPI_Barrier(MPI_COMM_WORLD);
auto it = tracked_species.begin();
DEBUG_LEVEL_3("Timer Synchronization.");
// DEBUG_LEVEL_3("Timer Synchronization.");
synchronize(it->second->dynamicDensityField()->timer_.get(),
it->second->lastSyncDensityField()->timer_.get());
+2
View File
@@ -45,8 +45,10 @@ std::vector<particle::Particle> Injector::rollNewParticles(
// particles are assumed to be created by a decay process
// therefore the resulting particles all start out at the same position
CylinderCoordinate position = position_distribution_->rollPosition(engine);
#ifdef debug_level3
DEBUG_LEVEL_3("Injected z position: " +
std::to_string(position.cylinderEntries()(2)));
#endif
std::vector<particle::Particle> new_particles;
// draw the velocity of all particles to be injected an append them to the new_particles vector
for (auto& injector_info : injector_infos_) {
+42 -2
View File
@@ -38,29 +38,43 @@ void Simulation::init(Parameter& parameter) {
magnetic_field_ = generator::magneticField(parameter);
electric_field_ = generator::electricField(parameter);
#ifdef debug
DEBUG_LEVEL_0("Creating species.");
#endif
generator::SpeciesBuilder builder(parameter);
tracked_species_ = builder.trackedSpecies();
background_species_ = builder.backgroundSpecies();
timer_ = builder.timer();
#ifdef debug
DEBUG_LEVEL_0("Creating injector.");
#endif
injector_ = generator::buildInjector(tracked_species_, background_species_,
parameter);
#ifdef debug
DEBUG_LEVEL_0("Init random numbers.");
#endif
random_ = generator::buildRandomNumbers(parameter);
#ifdef debug
DEBUG_LEVEL_0("Init output.");
#endif
output_ = generator::buildSimulationOutput(
parameter.jsonObjectFromBase({"Output"}), tracked_species_);
#ifdef debug
DEBUG_LEVEL_0("Output meta data.");
#endif
output_->writeMetaData(tracked_species_);
#ifdef debug
DEBUG_LEVEL_0("Init cpu synchronizer.");
#endif
cpu_synchronizer_ = std::make_shared<CpuSynchronizer>();
#ifdef debug_level3
DEBUG_LEVEL_3("Init done.");
#endif
}
int eventsThisCpu(int events_all_cpus) {
@@ -105,7 +119,7 @@ void Simulation::start() {
if((events_this_cpu % event_stride == 0) &&
(total_simulated_events % MpiCommunication::mpiSize()
<= MpiCommunication::mpiRank())) {
DEBUG_LEVEL_3("empty loop");
// DEBUG_LEVEL_3("empty loop");
empty_loop = true;
}
}
@@ -114,7 +128,7 @@ void Simulation::start() {
// special case of unbalanced cpu load, with a part of the cpus having one cycle
// that has no events, while the rest of the cpus have a single event (questionable if needed)
if(leftover_events == 0 && empty_loop) {
DEBUG_LEVEL_3("empty loop looped");
// DEBUG_LEVEL_3("empty loop looped");
empty_loop = false;
}
@@ -123,7 +137,9 @@ void Simulation::start() {
std::to_string(leftover_events));
processEvents(evenst_of_cycle);
#ifdef debug_level1
DEBUG_LEVEL_1("Leftover events: " + std::to_string(leftover_events));
#endif
leftover_events -= evenst_of_cycle;
SIM_INFO("Cpu sync.");
@@ -148,27 +164,37 @@ int particleNumberFromQueue(int queue_length, RandomNumbers* random) {
}
void Simulation::processEvents(int events) {
#ifdef debug
DEBUG_LEVEL_0("Processing events.");
#endif
std::vector<particle::Particle> particle_queue;
particle_queue.reserve(100);
int current_event = 0;
while ((current_event < events) || (!particle_queue.empty())) {
#ifdef debug_level2
DEBUG_LEVEL_2("Current event: " + std::to_string(current_event));
#endif
// if the particle queue is empty a new beta decay event is started
if (particle_queue.empty()) {
current_event += 1;
#ifdef debug_level2
DEBUG_LEVEL_2("Inject particles to queue.");
#endif
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
// draw new beta decay particles
std::vector<particle::Particle> new_particles =
determineInjectedParticles(random_.get());
SimulationTimer::eventStopPoint(std::string("ParticleInjection"));
#ifdef debug_level2
DEBUG_LEVEL_2("Injected particles to queue.");
#endif
particle_queue.insert(particle_queue.end(), new_particles.begin(),
new_particles.end());
}
#ifdef debug_level2
DEBUG_LEVEL_2("Particles in queue: " + std::to_string(particle_queue.size()));
#endif
// choose a random particle from the particle queue to be processed
const int particle_number =
particleNumberFromQueue(particle_queue.size(), random_.get());
@@ -185,7 +211,9 @@ void Simulation::processEvents(int events) {
void Simulation::processUntilTermination(
particle::Particle& particle,
std::vector<particle::Particle>& particle_queue) {
#ifdef debug_level3
DEBUG_LEVEL_3("Process particle until termination");
#endif
while (particle.specie()->terminator()->isAlive(&particle)) {
auto old_position = particle.position();
double old_energy = particle.kineticEnergy_eV();
@@ -205,7 +233,9 @@ void Simulation::processUntilTermination(
bool was_reflected = false;
if (particle.specie()->reflector()->needsReflectionBackToDomain(
&particle)) {
#ifdef debug_level3
DEBUG_LEVEL_3("Reflect particle.");
#endif
old_position = particle.position();
particle.specie()->reflector()->reflectBackToDomain(&particle);
particle.specie()->currentCollector()->collect(&particle, old_position);
@@ -214,7 +244,9 @@ void Simulation::processUntilTermination(
if (particle.specie()->terminator()->reachedMaxTimeAlive(
&particle)) {
#ifdef debug_level3
DEBUG_LEVEL_3("Terminate particle. Reached max time alive.");
#endif
if (particle.specie()->deletionLogger()) {
particle.specie()->deletionLogger()->logDeletion(
particle.position(), DeletionType::max_time_alive);
@@ -222,11 +254,13 @@ void Simulation::processUntilTermination(
break;
} else if (particle.specie()->terminator()->leftSimulationDomain(
&particle)) {
#ifdef debug_level3
DEBUG_LEVEL_3("Terminate particle. 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);
@@ -239,6 +273,7 @@ void Simulation::processUntilTermination(
!(particle.specie()->dynamicDensityField()->changedEnergyBin(
old_energy, particle.kineticEnergy_eV())) &&
!was_reflected) {
#ifdef debug_level3
DEBUG_LEVEL_3("Perform interaction.");
DEBUG_LEVEL_3("Number of Interactions: " +
std::to_string(particle.interactionCounter()));
@@ -247,6 +282,7 @@ void Simulation::processUntilTermination(
std::stringstream output_ss;
output_ss << "Position (cyl): " << particle.position().cylinderEntries();
DEBUG_LEVEL_3(output_ss.str());
#endif
SimulationTimer::eventStartPoint(std::string("Interaction"));
interaction::InteractionOutput output = interact(particle, random_.get(),
@@ -260,13 +296,17 @@ void Simulation::processUntilTermination(
}
if (output.deleteCurrentParticle()) {
#ifdef debug_level3
DEBUG_LEVEL_3(particle.specie()->name() + " removed due to interaction.");
#endif
break;
}
if (particle.specie()->terminator()->reachedMaxInteractions(&particle)) {
#ifdef debug_level3
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name()
+ ". Reached max interactions.");
#endif
if (particle.specie()->deletionLogger()) {
particle.specie()->deletionLogger()->logDeletion(
particle.position(), DeletionType::max_interactions);