preprocessor now filters debug output

This commit is contained in:
2025-05-28 15:27:00 +02:00
parent e2167fb75b
commit f510d0a39a
39 changed files with 375 additions and 14 deletions
+7 -1
View File
@@ -186,12 +186,14 @@ bool DynamicDensityField::changedPitchAngleBin(double old_mu,
const int old_bin = pitch_angle_binning_.bin(old_mu);
const int new_bin = pitch_angle_binning_.bin(new_mu);
#ifdef debug_level3
if(!(old_bin == new_bin)) {
DEBUG_LEVEL_3("old mu: " + std::to_string(old_mu));
DEBUG_LEVEL_3("old bin: " + std::to_string(old_bin));
DEBUG_LEVEL_3("new mu: " + std::to_string(new_mu));
DEBUG_LEVEL_3("new bin: " + std::to_string(new_bin));
}
#endif
return !(old_bin == new_bin);
}
@@ -225,7 +227,9 @@ void DynamicDensityField::logMovement(const Coordinate& position,
// }
blitz::Array<double, 3> DynamicDensityField::densityArray() {
#ifdef debug_level3
DEBUG_LEVEL_3("recalc Density array");
#endif
recalculateDensityArray();
blitz::TinyVector<int,3> lowerbound(density_per_m3_.lbound(0),
@@ -237,7 +241,7 @@ blitz::Array<double, 3> DynamicDensityField::densityArray() {
blitz::Array<double, 3> density(lowerbound, extent);
blitz::fourthIndex iE;
DEBUG_LEVEL_3("density sum");
// DEBUG_LEVEL_3("density sum");
density = blitz::sum(density_per_m3_, iE);
return density.copy();
}
@@ -303,7 +307,9 @@ void DynamicDensityField::recalculateDensityArray() {
double DynamicDensityField::particleNumber() {
blitz::Array<double, 3> density = densityArray();
double particleNumber = blitz::sum(density * bin_volume_m3_);
#ifdef debug_level3
DEBUG_LEVEL_3("particle number: " + std::to_string(particleNumber));
#endif
return particleNumber;
}
+4 -2
View File
@@ -71,8 +71,10 @@ std::vector<particle::Particle> Injector::rollNewParticles(
for (auto& injector_info : injector_infos_) {
CylinderCoordinate position = position_distribution_->rollPosition(engine);
#ifdef debug_level3
DEBUG_LEVEL_3("Injected z position: " +
std::to_string(position.cylinderEntries()(2)));
#endif
// for (int i = 0; i < injector_info.multiplicity; i++) {
new_particles.push_back(
@@ -102,12 +104,12 @@ void Injector::drawNewParticleFromDensityField(std::mt19937* engine,
CylinderCoordinate position =
specie->positionDistributionFromDensity()->drawPosition(engine,
index(0), index(1), index(2));
#ifdef debug_level3
DEBUG_LEVEL_3("Injected z position: " +
std::to_string(position.cylinderEntries()(2)));
DEBUG_LEVEL_3("Injected r position: " +
std::to_string(position.cylinderEntries()(0)));
#endif
// draw the velocity
CartesianVector velocity(blitz::TinyVector<double, 3>(0,0,0));
+66 -4
View File
@@ -48,30 +48,42 @@ void Simulation::init(Parameter& parameter) {
electric_field_ = generator::electricField(parameter);
gravity_field_ = generator::gravityField(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);
for(auto& tracked_specie : tracked_species_) {
tracked_specie.second->randomIndex()->reshuffle(random_->engine());
}
#ifdef debug
DEBUG_LEVEL_0("Init poisson solver.");
#endif
poisson_solver_ = generator::buildPoissonSolver(parameter);
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
#ifdef debug
DEBUG_LEVEL_0("Init cpu synchronizer.");
#endif
cpu_synchronizer_ = std::make_shared<CpuSynchronizer>();
#ifdef debug_level3
DEBUG_LEVEL_3("Init done.");
#endif
Restart restarter = generator::buildRestart(parameter);
restarter.restart(tracked_species_, poisson_solver_.get(), random_.get());
@@ -82,11 +94,15 @@ void Simulation::init(Parameter& parameter) {
// writing the metadata
MPI_Barrier(MPI_COMM_WORLD);
#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_, poisson_solver_);
}
@@ -151,7 +167,9 @@ void Simulation::start() {
const double density_weight_factor =
1./(MpiCommunication::mpiSize()*particles_per_bin);
#ifdef debug
DEBUG_LEVEL_0("Number of particles per bin per CPU: " + std::to_string(particles_per_bin));
#endif
SIM_INFO("Number of Timesteps: " + std::to_string(number_timesteps));
SIM_INFO("Simulated events before cpu sync: " + std::to_string(event_stride));
@@ -197,9 +215,11 @@ void Simulation::start() {
int density_events_of_cycle =
eventsOfCycle(density_stride, leftover_density_events);
#ifdef debug_level1
DEBUG_LEVEL_1("Events of cycle: " + std::to_string(events_of_cycle));
DEBUG_LEVEL_1("Density Events of cycle: " +
std::to_string(density_events_of_cycle));
#endif
SIM_INFO("Processing timestep: " + std::to_string(timesteps));
SIM_INFO("Leftover events this timestep this CPU: " +
@@ -211,9 +231,11 @@ void Simulation::start() {
processDensityEvents(particles_per_bin, density_weight_factor);
processEvents(events_of_cycle, beta_particle_weight);
#ifdef debug_level1
DEBUG_LEVEL_1("Processing timestep: " + std::to_string(timesteps));
DEBUG_LEVEL_1("Leftover events this timestep: " +
std::to_string(leftover_events_time_resolution));
#endif
leftover_events_time_resolution -= events_of_cycle;
leftover_density_events -= density_events_of_cycle;
@@ -274,18 +296,24 @@ int particleNumberFromQueue(int queue_length, RandomNumbers* random) {
}
void Simulation::processEvents(int events, const double beta_particle_weight) {
#ifdef debug
DEBUG_LEVEL_0("Processing events.");
#endif
int current_event = 0;
while ((current_event < events) || (!queue_.empty())) {
#ifdef debug_level2
DEBUG_LEVEL_2("Current event: " + std::to_string(current_event));
#endif
if (queue_.empty()) {
std::vector<particle::Particle> new_particles;
current_event += 1;
#ifdef debug_level2
DEBUG_LEVEL_2("Inject particles to queue.");
#endif
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
new_particles = determineInjectedParticles(random_.get(),
beta_particle_weight);
@@ -304,13 +332,17 @@ void Simulation::processEvents(int events, const double beta_particle_weight) {
#endif
SimulationTimer::eventStopPoint(std::string("ParticleInjection"));
#ifdef debug_level2
DEBUG_LEVEL_2("Injected particles to queue.");
#endif
queue_.insert(queue_.end(), new_particles.begin(),
new_particles.end());
}
#ifdef debug_level2
DEBUG_LEVEL_2("Particles in queue: " +
std::to_string(queue_.size()));
#endif
const int particle_number =
particleNumberFromQueue(queue_.size(), random_.get());
@@ -324,7 +356,9 @@ void Simulation::processEvents(int events, const double beta_particle_weight) {
}
void Simulation::processDensityEvents(int particles_per_bin, const double weight_factor) {
#ifdef debug
DEBUG_LEVEL_0("Processing density events.");
#endif
// number of full grid traversions
int current_event = 0;
// set to true if all grids of all species have been visited
@@ -340,12 +374,16 @@ void Simulation::processDensityEvents(int particles_per_bin, const double weight
}
while ((current_event < particles_per_bin) || (!queue_.empty())) {
#ifdef debug_level2
DEBUG_LEVEL_2("Current event: " + std::to_string(current_event));
#endif
if (queue_.empty()) {
std::vector<particle::Particle> new_particles;
#ifdef debug_level2
DEBUG_LEVEL_2("Current density event: " + std::to_string(current_event));
#endif
SimulationTimer::eventStartPoint(std::string("DensityInjection"));
new_particles = determineInjectedDensityParticles(random_.get(),
@@ -381,8 +419,10 @@ void Simulation::processDensityEvents(int particles_per_bin, const double weight
}
}
#ifdef debug_level2
DEBUG_LEVEL_2("Particles in queue: " +
std::to_string(queue_.size()));
std::to_string(queue_.size()));
#endif
const int particle_number =
particleNumberFromQueue(queue_.size(), random_.get());
@@ -397,8 +437,10 @@ void Simulation::processDensityEvents(int particles_per_bin, const double weight
void Simulation::processUntilTermination(
particle::Particle& particle) {
#ifdef debug_level3
DEBUG_LEVEL_3("Process particle until termination");
DEBUG_LEVEL_3("Weight of the particle: " + std::to_string(particle.weight()));
#endif
while (particle.specie()->terminator()->isAlive(&particle)) {
auto old_position = particle.position();
double old_energy = particle.kineticEnergy_eV();
@@ -419,7 +461,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);
@@ -428,8 +472,10 @@ void Simulation::processUntilTermination(
if (particle.specie()->terminator()->reachedMaxTimeAlive(
&particle)) {
#ifdef debug_level3
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name() +
". Reached timeresolution.");
#endif
if(particle.specie()->deletionLogger()) {
particle.specie()->deletionLogger()->logDeletion(particle.position(),
DeletionType::max_time_alive);
@@ -438,12 +484,12 @@ void Simulation::processUntilTermination(
} else if (particle.specie()->terminator()->leftSimulationDomain(
&particle)) {
#if defined debug_level3
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name()
DEBUG_LEVEL_1("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());
// ERROR(output_ss.str());
#endif
if (particle.specie()->deletionLogger()) {
particle.specie()->deletionLogger()->logDeletion(particle.position(),
@@ -457,12 +503,12 @@ 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()));
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();
@@ -481,13 +527,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);
@@ -611,7 +661,9 @@ std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
if (particleNumbers[pair.first] == 0) {
all_bins_done = all_bins_done && true;
#ifdef debug_level3
DEBUG_LEVEL_3("No particles in density of species: " + pair.second->name());
#endif
continue;
}
@@ -639,26 +691,36 @@ std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
//maybe put that into the poisson solver
blitz::Array<double,3> Simulation::chargedensity() {
#ifdef debug_level3
DEBUG_LEVEL_3("Initialize chargedensity Array");
#endif
//not great but the size and bounds of the density arrays are needed...
std::shared_ptr<species::TrackedSpecie> firstTracked =
tracked_species_.begin()->second;
#ifdef debug_level3
DEBUG_LEVEL_3("shared pointer extracted, key: "
+ tracked_species_.begin()->first);
#endif
if(!firstTracked)
ERROR("Extracted pointer is null.");
blitz::Array<double,3> init = firstTracked->
dynamicDensityField()->densityArray();
blitz::Array<double, 3> chargeden(init.lbound(), init.extent());
chargeden = 0.;
#ifdef debug_level3
DEBUG_LEVEL_3("Collect chargedensity");
#endif
for (auto& pair : tracked_species_) {
chargeden += pair.second->charge_C() * pair.second->dynamicDensityField()->
densityArray();
}
#ifdef debug_level3
DEBUG_LEVEL_3("Maximum value in the chargedensity: " +
std::to_string(blitz::max(chargeden)));
#endif
return chargeden;
}