Author SHA1 Message Date
csendlinger 2f68d8e3b1 Added more deletionLogger elements (for debugging) 2025-06-16 09:44:51 +02:00
csendlinger 9d170336b8 changes from double to float to check if
error is indeed cancellation error
2025-06-11 11:03:23 +02:00
15 changed files with 114 additions and 15 deletions
+1
View File
@@ -15,6 +15,7 @@ class Hdf5Writer {
void write(const blitz::Array<double, 3>& data, std::string path); void write(const blitz::Array<double, 3>& data, std::string path);
void write(const blitz::Array<double, 4>& data, std::string path); void write(const blitz::Array<double, 4>& data, std::string path);
void write(const blitz::Array<double, 5>& data, std::string path); void write(const blitz::Array<double, 5>& data, std::string path);
void write(const blitz::Array<float, 5>& data, std::string path);
void write(const blitz::Array<long int, 4>& data, std::string path); void write(const blitz::Array<long int, 4>& data, std::string path);
void write(const blitz::Array<long int, 5>& data, std::string path); void write(const blitz::Array<long int, 5>& data, std::string path);
void write(const blitz::TinyVector<double, 3>& data, std::string path); void write(const blitz::TinyVector<double, 3>& data, std::string path);
+2
View File
@@ -36,6 +36,8 @@ class CpuSynchronizer {
*/ */
void sumToAll(blitz::Array<double, 4>& array, void sumToAll(blitz::Array<double, 4>& array,
blitz::Array<double, 4>& last_sync_array); blitz::Array<double, 4>& last_sync_array);
void sumToAll(blitz::Array<float, 5>& array,
blitz::Array<float, 5>& last_sync_array);
void sumToAll(blitz::Array<double, 5>& array, void sumToAll(blitz::Array<double, 5>& array,
blitz::Array<double, 5>& last_sync_array); blitz::Array<double, 5>& last_sync_array);
void sumToAll(blitz::Array<double, 3>& array, void sumToAll(blitz::Array<double, 3>& array,
+4 -4
View File
@@ -57,7 +57,7 @@ class DynamicDensityField : public DensityField {
blitz::Array<double, 3> densityArray(); blitz::Array<double, 3> densityArray();
blitz::Array<double, 4> spectrumArray(); blitz::Array<double, 4> spectrumArray();
blitz::Array<double, 5> timeInBinArray() const; blitz::Array<float, 5> timeInBinArray() const;
// blitz::Array<long int, 5> deletedParticlesArray() const; // blitz::Array<long int, 5> deletedParticlesArray() const;
blitz::Array<double, 3> binVolumeArray() const; blitz::Array<double, 3> binVolumeArray() const;
@@ -68,7 +68,7 @@ class DynamicDensityField : public DensityField {
// return an array of the time in bin at the Coordinate position and the energy // return an array of the time in bin at the Coordinate position and the energy
// energy_eV (only pitch angle direction left); over and underflow bin are removed // energy_eV (only pitch angle direction left); over and underflow bin are removed
blitz::Array<double, 1> sliceTimeInBinArray(const Coordinate& position, blitz::Array<float, 1> sliceTimeInBinArray(const Coordinate& position,
double energy_eV) const; double energy_eV) const;
const EnergyBinning* energyBinning() const; const EnergyBinning* energyBinning() const;
@@ -94,10 +94,10 @@ class DynamicDensityField : public DensityField {
// time in bin now contains the physical particle number per bin // time in bin now contains the physical particle number per bin
// (not renamed, since that would require many, many changes due to // (not renamed, since that would require many, many changes due to
// renaming of the functions) // renaming of the functions)
blitz::Array<double, 5> time_in_bin_s_; blitz::Array<float, 5> time_in_bin_s_;
// blitz::Array<long int, 5> deleted_particles_; // blitz::Array<long int, 5> deleted_particles_;
blitz::Array<double, 5> sync_time_in_bin_s_; blitz::Array<float, 5> sync_time_in_bin_s_;
// blitz::Array<long int, 5> sync_deleted_particles_; // blitz::Array<long int, 5> sync_deleted_particles_;
blitz::Array<double, 4> density_per_m3_; blitz::Array<double, 4> density_per_m3_;
+6 -1
View File
@@ -10,7 +10,12 @@ enum class DeletionType {
recombination, recombination,
max_interactions, max_interactions,
max_time_alive, max_time_alive,
cluster_formation cluster_formation,
creation_beta,
creation_density,
creation_interaction,
creation_above_2keV,
loss_above_2keV
}; };
class DeletionLogger { class DeletionLogger {
+32
View File
@@ -197,6 +197,38 @@ void Hdf5Writer::write(const blitz::Array<double, 5>& data, std::string path) {
H5Fclose(file); H5Fclose(file);
} }
void Hdf5Writer::write(const blitz::Array<float, 5>& data, std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
blitz::TinyVector<int, 5> size = data.extent();
blitz::TinyVector<int, 5> start(0, 0, 0, 0, 0);
hid_t filespace =
H5Screate_simple(5, blitz::TinyVector<hsize_t, 5>(size).data(), NULL);
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
H5Pset_create_intermediate_group(lcpl, 1);
// turn of error report by hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset;
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
if (dataset < 0) {
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_FLOAT, filespace, lcpl,
H5P_DEFAULT, H5P_DEFAULT);
}
// turn error report back onby hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, filespace, H5P_DEFAULT,
data.data());
H5Dclose(dataset);
H5Pclose(lcpl);
H5Sclose(filespace);
H5Fclose(file);
}
void Hdf5Writer::write(const blitz::Array<long int, 4>& data, void Hdf5Writer::write(const blitz::Array<long int, 4>& data,
std::string path) { std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT); hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
+10
View File
@@ -242,6 +242,16 @@ void SimulationOutput::writeNumDeletions(DeletionLogger* logger,
writer.write(pair.second, path_to_deletions + "/MaxTimeAlive"); writer.write(pair.second, path_to_deletions + "/MaxTimeAlive");
} else if (pair.first == DeletionType::cluster_formation) { } else if (pair.first == DeletionType::cluster_formation) {
writer.write(pair.second, path_to_deletions + "/ClusterFormation"); writer.write(pair.second, path_to_deletions + "/ClusterFormation");
} else if (pair.first == DeletionType::creation_beta) {
writer.write(pair.second, path_to_deletions + "/CreationBeta");
} else if (pair.first == DeletionType::creation_density) {
writer.write(pair.second, path_to_deletions + "/CreationDensity");
} else if (pair.first == DeletionType::creation_interaction) {
writer.write(pair.second, path_to_deletions + "/CreationInteraction");
} else if (pair.first == DeletionType::creation_above_2keV) {
writer.write(pair.second, path_to_deletions + "/CreationAbove2keV");
} else if (pair.first == DeletionType::loss_above_2keV) {
writer.write(pair.second, path_to_deletions + "/LossAbove2keV");
} }
} }
} }
+7
View File
@@ -35,6 +35,13 @@ std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
used_types.push_back(DeletionType::max_interactions); used_types.push_back(DeletionType::max_interactions);
used_types.push_back(DeletionType::max_time_alive); used_types.push_back(DeletionType::max_time_alive);
used_types.push_back(DeletionType::cluster_formation); used_types.push_back(DeletionType::cluster_formation);
// Debugging types, not yet able to be specified on their own, just
// in when "all" is used
used_types.push_back(DeletionType::creation_beta);
used_types.push_back(DeletionType::creation_density);
used_types.push_back(DeletionType::creation_interaction);
used_types.push_back(DeletionType::creation_above_2keV);
used_types.push_back(DeletionType::loss_above_2keV);
} }
} }
+2
View File
@@ -46,6 +46,8 @@ InteractionOutput ClusterFormation::performInteraction(
x_impact, DeletionType::cluster_formation); x_impact, DeletionType::cluster_formation);
} }
product_->deletionLogger()->logDeletion(x_impact, DeletionType::creation_interaction);
return output; return output;
} }
+5
View File
@@ -8,6 +8,7 @@
#include "simulation/kinematic.h" #include "simulation/kinematic.h"
#include "simulation/particle.h" #include "simulation/particle.h"
#include "simulation/velocity_distribution.h" #include "simulation/velocity_distribution.h"
#include "simulation/logger.h"
namespace interaction { namespace interaction {
@@ -117,6 +118,10 @@ InteractionOutput ElectronIonization::performInteraction(
output.add(particle::Particle(ion_, x_impact, CartesianVector(v_target), output.add(particle::Particle(ion_, x_impact, CartesianVector(v_target),
time_birth, weight_parent)); time_birth, weight_parent));
ion_->deletionLogger()->logDeletion(x_impact, DeletionType::creation_interaction);
electron_->deletionLogger()
->logDeletion(x_impact, DeletionType::creation_interaction);
return output; return output;
} }
+10
View File
@@ -27,6 +27,16 @@ void CpuSynchronizer::sumToAll(blitz::Array<double, 5>& array,
last_sync_array += delta; last_sync_array += delta;
} }
void CpuSynchronizer::sumToAll(blitz::Array<float, 5>& array,
blitz::Array<float, 5>& last_sync_array) {
int size = array.size();
blitz::Array<float, 5> delta(array.extent());
delta = array - last_sync_array;
MPI_Allreduce(MPI_IN_PLACE, delta.data(), size, MPI_FLOAT,
MPI_SUM, MPI_COMM_WORLD);
last_sync_array += delta;
}
void CpuSynchronizer::sumToAll(blitz::Array<long int, 4>& array, void CpuSynchronizer::sumToAll(blitz::Array<long int, 4>& array,
blitz::Array<long int, 4>& last_sync_array) { blitz::Array<long int, 4>& last_sync_array) {
int size = array.size(); int size = array.size();
+5 -5
View File
@@ -61,7 +61,7 @@ DynamicDensityField::DynamicDensityField(
energy_binning_(energy_binning), energy_binning_(energy_binning),
pitch_angle_binning_(pitch_angle_binning), pitch_angle_binning_(pitch_angle_binning),
timer_(timer), timer_(timer),
time_in_bin_s_(initiate5DArray<double>( time_in_bin_s_(initiate5DArray<float>(
blitz::Range(position_binning.radial_binning.binIndexMin(), blitz::Range(position_binning.radial_binning.binIndexMin(),
position_binning.radial_binning.binIndexMax()), position_binning.radial_binning.binIndexMax()),
blitz::Range(position_binning.azimuth_binning.binIndexMin(), blitz::Range(position_binning.azimuth_binning.binIndexMin(),
@@ -72,7 +72,7 @@ DynamicDensityField::DynamicDensityField(
pitch_angle_binning.binIndexMax()), pitch_angle_binning.binIndexMax()),
blitz::Range(energy_binning.binIndexMin(), blitz::Range(energy_binning.binIndexMin(),
energy_binning.binIndexMax()))), energy_binning.binIndexMax()))),
sync_time_in_bin_s_(initiate5DArray<double>( sync_time_in_bin_s_(initiate5DArray<float>(
blitz::Range(position_binning.radial_binning.binIndexMin(), blitz::Range(position_binning.radial_binning.binIndexMin(),
position_binning.radial_binning.binIndexMax()), position_binning.radial_binning.binIndexMax()),
blitz::Range(position_binning.azimuth_binning.binIndexMin(), blitz::Range(position_binning.azimuth_binning.binIndexMin(),
@@ -209,7 +209,7 @@ void DynamicDensityField::logMovement(const Coordinate& position,
const int pitch_angle_bin = pitch_angle_binning_.bin(pitch_angle); const int pitch_angle_bin = pitch_angle_binning_.bin(pitch_angle);
time_in_bin_s_(position_bin(0), position_bin(1), position_bin(2), time_in_bin_s_(position_bin(0), position_bin(1), position_bin(2),
pitch_angle_bin, energy_bin) += weight; pitch_angle_bin, energy_bin) += static_cast<float>(weight);
} }
// void DynamicDensityField::logDeletion(const Coordinate& position, // void DynamicDensityField::logDeletion(const Coordinate& position,
@@ -251,7 +251,7 @@ blitz::Array<double, 4> DynamicDensityField::spectrumArray() {
return density_per_m3_; return density_per_m3_;
} }
blitz::Array<double, 5> DynamicDensityField::timeInBinArray() const { blitz::Array<float, 5> DynamicDensityField::timeInBinArray() const {
return time_in_bin_s_; return time_in_bin_s_;
} }
@@ -327,7 +327,7 @@ blitz::Array<double, 1> DynamicDensityField::
energy_binning_.binIndexMax()-1)).copy(); energy_binning_.binIndexMax()-1)).copy();
} }
blitz::Array<double, 1> DynamicDensityField:: blitz::Array<float, 1> DynamicDensityField::
sliceTimeInBinArray(const Coordinate& position, double energy_eV) const { sliceTimeInBinArray(const Coordinate& position, double energy_eV) const {
blitz::TinyVector<int, 3> position_bin = blitz::TinyVector<int, 3> position_bin =
position_binning_.bin(position.cylinderEntries()); position_binning_.bin(position.cylinderEntries());
+13 -1
View File
@@ -10,6 +10,8 @@
#include "simulation/velocity_distribution.h" #include "simulation/velocity_distribution.h"
#include "simulation/electromagnetic_field.h" #include "simulation/electromagnetic_field.h"
#include "simulation/random_numbers.h" #include "simulation/random_numbers.h"
#include "simulation/logger.h"
#include "constants/physical_constants.h"
#include <sstream> #include <sstream>
Injector::Injector( Injector::Injector(
@@ -48,6 +50,12 @@ particle::Particle Injector::rollNewParticle(
DEBUG_LEVEL_3(out.str()); DEBUG_LEVEL_3(out.str());
#endif #endif
created_specie->deletionLogger()->logDeletion(position, DeletionType::creation_beta);
if(kinematic::kineticEnergy(velocity, created_specie->mass_kg())
*UnitConversion::JouleToeV > 2000) {
created_specie->deletionLogger()->logDeletion(position, DeletionType::creation_above_2keV);
}
return particle::Particle(created_specie, position, return particle::Particle(created_specie, position,
CartesianVector(velocity), time_birth, weight); CartesianVector(velocity), time_birth, weight);
} }
@@ -135,7 +143,11 @@ void Injector::drawNewParticleFromDensityField(std::mt19937* engine,
particle::Particle drawn_particle(specie, position, particle::Particle drawn_particle(specie, position,
velocity, injection_time, weight_factor*num_part_in_bin); velocity, injection_time, weight_factor*num_part_in_bin);
// debugging
specie->deletionLogger()->logDeletion(position, DeletionType::creation_density);
if(drawn_particle.kineticEnergy_eV() > 2000) {
specie->deletionLogger()->logDeletion(position, DeletionType::creation_above_2keV);
}
queue.push_back(drawn_particle); queue.push_back(drawn_particle);
} }
+1 -1
View File
@@ -40,7 +40,7 @@ void RandomIndex::reshuffle(std::mt19937* engine) {
} }
bool RandomIndex::visited_all() { bool RandomIndex::visited_all() {
return current_index_in_vector_ == total_bin_number_ - 1; return current_index_in_vector_ == total_bin_number_;
} }
// return the next index in the shuffled index vector. Returns the last // return the next index in the shuffled index vector. Returns the last
+13
View File
@@ -229,6 +229,7 @@ void Simulation::start() {
// process both density and beta events before a cpu synchronization // process both density and beta events before a cpu synchronization
processDensityEvents(particles_per_bin, density_weight_factor); processDensityEvents(particles_per_bin, density_weight_factor);
if(num_cpu_syncs == 0)
processEvents(events_of_cycle, beta_particle_weight); processEvents(events_of_cycle, beta_particle_weight);
#ifdef debug_level1 #ifdef debug_level1
@@ -479,6 +480,10 @@ void Simulation::processUntilTermination(
if(particle.specie()->deletionLogger()) { if(particle.specie()->deletionLogger()) {
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(), particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
DeletionType::max_time_alive); DeletionType::max_time_alive);
if(particle.kineticEnergy_eV() > 2000) {
particle.specie()->deletionLogger()->logDeletion(particle.cartesianPosition(),
DeletionType::loss_above_2keV);
}
#ifdef debug #ifdef debug
if(!particle.wasDeposited()) { if(!particle.wasDeposited()) {
std::stringstream out; std::stringstream out;
@@ -503,6 +508,10 @@ void Simulation::processUntilTermination(
if (particle.specie()->deletionLogger()) { if (particle.specie()->deletionLogger()) {
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(), particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
DeletionType::wall); DeletionType::wall);
if(particle.kineticEnergy_eV() > 2000) {
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
DeletionType::loss_above_2keV);
}
} }
#ifdef debug #ifdef debug
if(particle.wasDeposited()) { if(particle.wasDeposited()) {
@@ -558,6 +567,10 @@ void Simulation::processUntilTermination(
if (particle.specie()->deletionLogger()) { if (particle.specie()->deletionLogger()) {
particle.specie()->deletionLogger()->logDeletion( particle.specie()->deletionLogger()->logDeletion(
particle.cylinderPosition(), DeletionType::max_interactions); particle.cylinderPosition(), DeletionType::max_interactions);
if(particle.kineticEnergy_eV() > 2000) {
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
DeletionType::loss_above_2keV);
}
} }
break; break;
} }
+2 -2
View File
@@ -67,7 +67,7 @@ CartesianVector VelocityDistributionFromDensityField::rollVelocity(
// draw pitch angle from DynamicDensityField // draw pitch angle from DynamicDensityField
blitz::Array<double, 1> pitchAngleValues = density_field_-> blitz::Array<float, 1> pitchAngleValues = density_field_->
sliceTimeInBinArray(position, energy_eV); sliceTimeInBinArray(position, energy_eV);
std::piecewise_constant_distribution<double> pitchAngle_dist( std::piecewise_constant_distribution<double> pitchAngle_dist(
@@ -113,7 +113,7 @@ CartesianVector VelocityDistributionFromDensityField::rollVelocity(
// draw pitch angle from DynamicDensityField // draw pitch angle from DynamicDensityField
blitz::Array<double, 1> pitchAngleValues = density_field_-> blitz::Array<float, 1> pitchAngleValues = density_field_->
sliceTimeInBinArray(position, energy_eV); sliceTimeInBinArray(position, energy_eV);
std::piecewise_constant_distribution<double> pitchAngle_dist( std::piecewise_constant_distribution<double> pitchAngle_dist(