From f510d0a39a392c080c27d2025fc2e5f07c2d3247 Mon Sep 17 00:00:00 2001 From: csendlinger Date: Wed, 28 May 2025 15:27:00 +0200 Subject: [PATCH] preprocessor now filters debug output --- makefile | 4 +- src/IO/hdf5_reader.cpp | 13 +++- src/IO/hdf5_writer.cpp | 6 ++ src/IO/restart.cpp | 14 ++++ src/IO/simulation_output.cpp | 32 ++++++++- src/generators/binning_generator.cpp | 33 +++++++++ .../current_collector_generator.cpp | 2 + src/generators/density_field_generator.cpp | 4 ++ src/generators/drift_velocity_generator.cpp | 8 +++ src/generators/electric_field_generator.cpp | 6 ++ ...energy_distribution_function_generator.cpp | 10 +++ src/generators/function_generator.cpp | 20 ++++++ src/generators/geometry_generator.cpp | 8 +++ src/generators/gravity_field_generator.cpp | 2 + src/generators/injector_generator.cpp | 6 ++ src/generators/interaction_generator.cpp | 22 ++++++ src/generators/logger_generator.cpp | 2 + src/generators/magnetic_field_generator.cpp | 2 + src/generators/mover_generator.cpp | 4 ++ src/generators/poisson_solver_generator.cpp | 8 +++ src/generators/reflector_generator.cpp | 4 ++ src/generators/restart_generator.cpp | 6 ++ .../simulation_output_generator.cpp | 2 + src/generators/species_generator.cpp | 40 +++++++++++ src/generators/terminator_generator.cpp | 4 ++ src/generators/vector_field_generator.cpp | 6 ++ ...locity_distribution_function_generator.cpp | 4 ++ .../velocity_distribution_generator.cpp | 4 ++ src/interactions/charge_exchange.cpp | 2 + src/interactions/cluster_formation.cpp | 2 + src/interactions/elastic_scattering.cpp | 2 + src/interactions/excitation.cpp | 2 + src/interactions/free_movement.cpp | 2 + src/interactions/ionization.cpp | 2 + src/interactions/recombination.cpp | 2 + src/poisson_solver/poisson_solver.cpp | 15 +++- src/simulation/density_field.cpp | 8 ++- src/simulation/injector.cpp | 6 +- src/simulation/simulation.cpp | 70 +++++++++++++++++-- 39 files changed, 375 insertions(+), 14 deletions(-) diff --git a/makefile b/makefile index de823c7..3c1d61c 100755 --- a/makefile +++ b/makefile @@ -47,8 +47,10 @@ LIBS += $(HDF5P_LIBRARIES) CXXFLAGS += $(JANSSON_INCLUDES) LIBS += $(JANSSON_LIBRARIES) + +CXXFLAGS += -g ifeq ($(DO_DEBUGGING),true) - CXXFLAGS += -ftemplate-depth-30 -g -DBZ_DEBUG + CXXFLAGS += -ftemplate-depth-30 -DBZ_DEBUG CXXFLAGS += -Ddebug CXXFLAGS += -Ddebug_level$(DEBUG_LEVEL) endif diff --git a/src/IO/hdf5_reader.cpp b/src/IO/hdf5_reader.cpp index 28de3dd..83e22b5 100755 --- a/src/IO/hdf5_reader.cpp +++ b/src/IO/hdf5_reader.cpp @@ -277,23 +277,24 @@ std::stringstream Hdf5Reader::readEngineString(std::string path) { std::to_string(SimConstants::engine_string_length_max) + ", size of string: " + std::to_string(size)); } +#ifdef debug_level3 DEBUG_LEVEL_3("RestartInfo: " + std::to_string(H5Tdetect_class(dtype, H5T_STRING))); +#endif const int ndims = H5Sget_simple_extent_ndims(dataspace); hsize_t dims[ndims]; if (ndims != 1) { ERROR("The given dataset is not one dimensional. It has dims: " + ndims); } +#ifdef debug_level3 DEBUG_LEVEL_3(std::to_string(ndims)); DEBUG_LEVEL_3("RestartInfo: " + std::to_string(size)); +#endif H5Sget_simple_extent_dims(dataspace, dims, NULL); char data[SimConstants::engine_string_length_max]; H5Dread(dataset, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data); - - std::stringstream temp; - temp << data; H5Tclose(dtype); H5Sclose(dataspace); @@ -314,15 +315,21 @@ std::stringstream Hdf5Reader::readEngineString(std::string path) { size_t length; H5Dread(dataset, H5T_NATIVE_HSIZE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &length); +#ifdef debug_level3 DEBUG_LEVEL_3("RestartInfo: read length from file: " + std::to_string(length)); +#endif H5Sclose(dataspace); H5Dclose(dataset); H5Fclose(file); +#ifdef debug_level3 + std::stringstream temp; + temp << data; out << temp.str().substr(0, length); DEBUG_LEVEL_3(std::to_string(out.str().size())); +#endif return out; } \ No newline at end of file diff --git a/src/IO/hdf5_writer.cpp b/src/IO/hdf5_writer.cpp index fbdb225..daf4977 100755 --- a/src/IO/hdf5_writer.cpp +++ b/src/IO/hdf5_writer.cpp @@ -542,12 +542,16 @@ void Hdf5Writer::writeRNG(const std::string& data, std::string path_base) { for(int i = 0; i < MpiCommunication::mpiSize(); ++i) { std::string path = path_base + std::to_string(i); +#ifdef debug_level3 DEBUG_LEVEL_3(path); +#endif hid_t dataset_string = H5Dcreate2(file, (path + "/string").c_str(), dtype, filespace, lcpl, H5P_DEFAULT, H5P_DEFAULT); // this sadly seems to be the option that takes the least amount of effort. // H5Lexits() would be an option but (!) each group would need to be checked for existance first, which sucks if(dataset_string < 0) { +#ifdef debug_level3 DEBUG_LEVEL_3("Dataset could not be created"); +#endif dataset_string = H5Dopen2(file, (path + "/string").c_str(), H5P_DEFAULT); if(dataset_string < 0) { ERROR("Dataset for string can neither be created nor opened"); @@ -556,7 +560,9 @@ void Hdf5Writer::writeRNG(const std::string& data, std::string path_base) { hid_t dataset_length = H5Dcreate2(file, (path + "/length").c_str(), H5T_NATIVE_HSIZE, filespace, lcpl, H5P_DEFAULT, H5P_DEFAULT); if(dataset_length < 0) { +#ifdef debug_level3 DEBUG_LEVEL_3("Dataset could not be created"); +#endif dataset_length = H5Dopen2(file, (path + "/length").c_str(), H5P_DEFAULT); if(dataset_length < 0) { ERROR("Dataset for length can neither be created nor opened"); diff --git a/src/IO/restart.cpp b/src/IO/restart.cpp index 06f6083..51c19e8 100644 --- a/src/IO/restart.cpp +++ b/src/IO/restart.cpp @@ -27,12 +27,18 @@ void Restart::restart(std::mapsecond.get()); for(const auto& pair: species) { @@ -68,7 +74,9 @@ void Restart::restartTimer(species::TrackedSpecie* reference_specie) { { std::string path = reference_specie->name() + "/DensityField/SimulationData/" + restart_identifier_ + "/PhysicalTime"; +#ifdef debug_level3 DEBUG_LEVEL_3(path); +#endif // probably add a function in the reader to read a single double value instead of // an 1d array of doubles blitz::Array restart_time = reader_.readD1Double(path); @@ -84,7 +92,9 @@ void Restart::restartTimer(species::TrackedSpecie* reference_specie) { { std::string path = reference_specie->name() + "/CurrentCollector/SimulationData/" + restart_identifier_ + "/PhysicalTime"; +#ifdef debug_level3 DEBUG_LEVEL_3(path); +#endif // probably add a function in the reader to read a single double value instead of // a 1d array of doubles blitz::Array time_resolution = reader_.readD1Double(path); @@ -103,7 +113,9 @@ void Restart::restartDrawingDensityField(DynamicDensityField* field, std::string // restart TimeInBin field { std::string path_to_data = path + "/TimeInBin"; +#ifdef debug_level3 DEBUG_LEVEL_3(path_to_data); +#endif blitz::Array time_in_bin = reader_.readD5Double(path_to_data); field->restartTimeInBin(time_in_bin); } @@ -124,7 +136,9 @@ void Restart::restartDrawingDensityField(DynamicDensityField* field, std::string void Restart::restartPoissonSolver(PoissonSolver* solver) { std::string path = "PoissonSolver/SimulationData/" + restart_identifier_ + "/Potential/"; +#ifdef debug_level3 DEBUG_LEVEL_3(path); +#endif blitz::Array potential = reader_.readD3Double(path); solver->setPotential(potential); } \ No newline at end of file diff --git a/src/IO/simulation_output.cpp b/src/IO/simulation_output.cpp index 553f5b4..19f4b99 100755 --- a/src/IO/simulation_output.cpp +++ b/src/IO/simulation_output.cpp @@ -72,7 +72,11 @@ void SimulationOutput::writeSimulationData( PoissonSolver* poisson_solver, std::mt19937* engine) { 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; @@ -80,7 +84,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; @@ -88,7 +94,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; @@ -96,7 +104,9 @@ void SimulationOutput::writeSimulationData( specie_path, cpu_sync, task.overwrite_last); } } +#ifdef debug_level2 DEBUG_LEVEL_2("Write PoissonSolver data."); +#endif if (cpu_sync % task_potential_.intervall == 0) { std::string poisson_path = "/" + task_potential_.specie_name; writeSimulationData(poisson_solver, poisson_path, cpu_sync, @@ -121,15 +131,23 @@ 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); // DEBUG_LEVEL_3("Write deleted particles."); // writeDeletedParticles(density_field, path); +#ifdef debug_level3 DEBUG_LEVEL_3("Write physical time."); +#endif writePhysicalTime(density_field, path); } @@ -143,11 +161,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); } @@ -160,7 +184,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); } @@ -173,7 +199,9 @@ void SimulationOutput::writeSimulationData(PoissonSolver* poisson_solver, sync_path = "/LastSyncPeriod"; } std::string path = poisson_path + "/SimulationData" + sync_path; +#ifdef debug_level3 DEBUG_LEVEL_3("Write potential."); +#endif writePotential(poisson_solver, path); } @@ -185,10 +213,12 @@ void SimulationOutput::writeRestartData(std::mt19937* engine, int cpu_sync, if (overwrite_last) { path_base = "/RestartInfo/LastSyncPeriod/CPU_"; } +#ifdef debug_level3 DEBUG_LEVEL_3(path_base); DEBUG_LEVEL_3("Write restart info."); +#endif writeRandomEngineState(engine, path_base); - DEBUG_LEVEL_3("Done"); + // DEBUG_LEVEL_3("Done"); } void SimulationOutput::writeRandomEngineState(std::mt19937* engine, std::string path) { diff --git a/src/generators/binning_generator.cpp b/src/generators/binning_generator.cpp index 82acaca..14806d9 100755 --- a/src/generators/binning_generator.cpp +++ b/src/generators/binning_generator.cpp @@ -10,7 +10,9 @@ namespace generator { CylinderBinning buildPositionBinning(json_t* object) { if (json_object_by_path(object, {"CylinderBinning"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating position binning: cylinder binning."); +#endif object = json_object_by_path(object, {"CylinderBinning"}); json_t* radial = json_object_by_path(object, {"Radial"}); @@ -36,6 +38,7 @@ CylinderBinning buildPositionBinning(json_t* object) { json_read_length(json_object_by_path(longitudinal, {"MaxLength"}), "m"); ASSERT_POSITIVE(&max_length, "Radius must be positive"); +#ifdef debug_level3 DEBUG_LEVEL_3("with number of bins radial: " + std::to_string(number_of_bins_radial)); DEBUG_LEVEL_3("with number of bins azimuthal: " + @@ -44,6 +47,7 @@ CylinderBinning buildPositionBinning(json_t* object) { std::to_string(number_of_bins_longitudinal)); DEBUG_LEVEL_3("with radius: " + std::to_string(max_radius) + " m"); DEBUG_LEVEL_3("with height: " + std::to_string(max_length) + " m"); +#endif return CylinderBinning(number_of_bins_radial, max_radius, number_of_bins_azimuthal, @@ -59,14 +63,18 @@ CylinderBinning buildPositionBinningIncludingRedirection( json_path& path_to_binning) { if (parameter.jsonObjectFromBase( json_path_append(path_to_binning, {"CreateSameAs"}))) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating position binning: CreateSameAs."); +#endif json_path path_to_same = json_path_get(parameter.jsonObjectFromBase( json_path_append(path_to_binning, {"CreateSameAs"}))); std::stringstream path; for (auto& p : path_to_same) { path << p << " "; } +#ifdef debug_level3 DEBUG_LEVEL_3("From path: " + path.str()); +#endif return buildPositionBinningIncludingRedirection(parameter, path_to_same); } else { return buildPositionBinning(parameter.jsonObjectFromBase(path_to_binning)); @@ -76,7 +84,9 @@ CylinderBinning buildPositionBinningIncludingRedirection( EnergyBinning buildEnergyBinning(json_t* object) { std::string energy_type = json_string(json_object_by_path(object, {"Type"})); if (energy_type == "Logarithmic") { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating energy binning: logarithmic."); +#endif int number_of_bins = json_int(json_object_by_path(object, {"NumberOfBins"})); ASSERT_POSITIVE(&number_of_bins, "Number of Bins must be positive"); @@ -87,9 +97,11 @@ EnergyBinning buildEnergyBinning(json_t* object) { json_read_energy(json_object_by_path(object, {"MaxEnergy"}), "eV"); ASSERT_POSITIVE(&max_energy, "Max Energy must be positive"); +#ifdef debug_level3 DEBUG_LEVEL_3("with number of bins: " + std::to_string(number_of_bins)); DEBUG_LEVEL_3("with min energy: " + std::to_string(min_energy)); DEBUG_LEVEL_3("with max energy: " + std::to_string(max_energy)); +#endif return EnergyBinning(min_energy, max_energy, number_of_bins); @@ -104,14 +116,22 @@ EnergyBinning buildEnergyBinningIncludingRedirection( json_path& path_to_binning) { if (parameter.jsonObjectFromBase( json_path_append(path_to_binning, {"CreateSameAs"}))) { + +#ifdef debug_level2 DEBUG_LEVEL_2("Creating energy binning: CreateSameAs."); +#endif + json_path path_to_same = json_path_get(parameter.jsonObjectFromBase( json_path_append(path_to_binning, {"CreateSameAs"}))); + +#ifdef debug_level3 std::stringstream path; for (auto& p : path_to_same) { path << p << " "; } DEBUG_LEVEL_3("From path: " + path.str()); +#endif + return buildEnergyBinningIncludingRedirection(parameter, path_to_same); } else { return buildEnergyBinning(parameter.jsonObjectFromBase(path_to_binning)); @@ -121,12 +141,18 @@ EnergyBinning buildEnergyBinningIncludingRedirection( PitchAngleBinning buildPitchAngleBinning(json_t* object) { std::string pitch_angle_type = json_string(json_object_by_path(object, {"Type"})); if (pitch_angle_type == "Linear") { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating pitch angle binning: linear."); +#endif + int number_of_bins = json_int(json_object_by_path(object, {"NumberOfBins"})); ASSERT_POSITIVE(&number_of_bins, "Number of Bins must be positive"); +#ifdef debug_level3 DEBUG_LEVEL_3("with number of bins: " + std::to_string(number_of_bins)); +#endif + return PitchAngleBinning(number_of_bins); } else { @@ -140,14 +166,21 @@ PitchAngleBinning buildPitchAngleBinningIncludingRedirection( json_path& path_to_binning) { if (parameter.jsonObjectFromBase( json_path_append(path_to_binning, {"CreateSameAs"}))) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating energy binning: CreateSameAs."); +#endif + json_path path_to_same = json_path_get(parameter.jsonObjectFromBase( json_path_append(path_to_binning, {"CreateSameAs"}))); + +#ifdef debug_level3 std::stringstream path; for (auto& p : path_to_same) { path << p << " "; } DEBUG_LEVEL_3("From path: " + path.str()); +#endif + return buildPitchAngleBinningIncludingRedirection(parameter, path_to_same); } else { return buildPitchAngleBinning(parameter.jsonObjectFromBase(path_to_binning)); diff --git a/src/generators/current_collector_generator.cpp b/src/generators/current_collector_generator.cpp index 08db4c1..1d9dcf9 100755 --- a/src/generators/current_collector_generator.cpp +++ b/src/generators/current_collector_generator.cpp @@ -9,7 +9,9 @@ std::shared_ptr buildCurrentCollector( Parameter& parameter, const json_path& path_to_collector, std::shared_ptr& timer) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating current collector."); +#endif json_path path_binning = json_path_append(path_to_collector, {"PositionBinning"}); CylinderBinning position_binning = diff --git a/src/generators/density_field_generator.cpp b/src/generators/density_field_generator.cpp index f510e22..609aa37 100755 --- a/src/generators/density_field_generator.cpp +++ b/src/generators/density_field_generator.cpp @@ -10,7 +10,9 @@ namespace generator { std::shared_ptr buildConstantDensityField( json_t* object) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating constant density field."); +#endif json_path path = {"ScalarField"}; std::shared_ptr field = buildScalarField(json_object_by_path(object, path)); @@ -22,7 +24,9 @@ std::shared_ptr buildDynamicDensityField( const json_path& path_to_field, std::shared_ptr& timer) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating dynamic density field with pitch angle."); +#endif json_path path_binning = json_path_append(path_to_field, {"PositionBinning"}); CylinderBinning position_binning = buildPositionBinningIncludingRedirection(parameter, path_binning); diff --git a/src/generators/drift_velocity_generator.cpp b/src/generators/drift_velocity_generator.cpp index 9937448..9f99eb4 100755 --- a/src/generators/drift_velocity_generator.cpp +++ b/src/generators/drift_velocity_generator.cpp @@ -9,14 +9,18 @@ std::shared_ptr buildDriftVelocity( const json_path& path_to_drift_velocity) { if (parameter.jsonObjectFromBase( json_path_append(path_to_drift_velocity, {"VectorField"}))) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating drift velocity: Vector field."); +#endif std::shared_ptr field = buildVectorField(parameter.jsonObjectFromBase( json_path_append(path_to_drift_velocity, {"VectorField"}))); return std::shared_ptr(new DriftVelocity(field)); } else if (parameter.jsonObjectFromBase( json_path_append(path_to_drift_velocity, {"null"}))) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating drift velocity: null."); +#endif return nullptr; } else { ERROR("No drift velocity given."); @@ -29,14 +33,18 @@ std::shared_ptr buildDriftVelocityIncludingRedirection( std::stringstream cpath; if (parameter.jsonObjectFromBase( json_path_append(path_to_drift_velocity, {"CreateSameAs"}))) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating drift velocity: CreateSameAs."); +#endif json_path path_to_same = json_path_get(parameter.jsonObjectFromBase( json_path_append(path_to_drift_velocity, {"CreateSameAs"}))); +#ifdef debug_level3 std::stringstream path; for (auto& p : path_to_same) { path << p << " "; } DEBUG_LEVEL_3("From path: " + path.str()); +#endif return buildDriftVelocityIncludingRedirection(parameter, path_to_same); } else { return buildDriftVelocity(parameter, path_to_drift_velocity); diff --git a/src/generators/electric_field_generator.cpp b/src/generators/electric_field_generator.cpp index 143ba33..ad2f901 100755 --- a/src/generators/electric_field_generator.cpp +++ b/src/generators/electric_field_generator.cpp @@ -6,12 +6,16 @@ namespace generator { std::shared_ptr electricField(json_t* object) { +#ifdef debug_level2 DEBUG_LEVEL_2("Generating electric field."); +#endif std::shared_ptr background; std::shared_ptr dynamic; if (json_object_by_path(object, {"Background"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Generating background electric field."); +#endif background = buildVectorField( json_object_by_path(object, {"Background", "VectorField"})); } else { @@ -19,7 +23,9 @@ std::shared_ptr electricField(json_t* object) { } if (json_object_by_path(object, {"Dynamic"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Generating dynamic electric field."); +#endif dynamic = buildVectorField( json_object_by_path(object, {"Dynamic", "VectorField"})); } else { diff --git a/src/generators/energy_distribution_function_generator.cpp b/src/generators/energy_distribution_function_generator.cpp index 05e5059..5cec708 100755 --- a/src/generators/energy_distribution_function_generator.cpp +++ b/src/generators/energy_distribution_function_generator.cpp @@ -11,21 +11,31 @@ std::shared_ptr buildEnergyDistributionFunction( json_t* object = parameter.jsonObjectFromBase(path_to_function); if (json_object_by_path(object, {"TritiumBetaDecay"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating energy distribution function: tritium beta decay."); +#endif return std::shared_ptr(new TritiumBetaDecay()); } else if (json_object_by_path(object, {"MaxwellBoltzmann"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating energy distribution function: Maxwell Boltzmann."); +#endif double temperature_K = json_double(json_object_by_path( object, {"MaxwellBoltzmann", "Temperature", "value"})); +#ifdef debug_level3 DEBUG_LEVEL_3("with temperature: " + std::to_string(temperature_K) + " K"); +#endif return std::shared_ptr( new MaxwellBoltzmann(temperature_K)); } else if (json_object_by_path(object, {"Constant"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating energy distribution function: Constant."); +#endif double constant_eV = json_double( json_object_by_path(object, {"Constant", "constant", "value"})); +#ifdef debug_level3 DEBUG_LEVEL_3("with constant: " + std::to_string(constant_eV) + " eV"); +#endif return std::shared_ptr( new Constant(constant_eV)); } diff --git a/src/generators/function_generator.cpp b/src/generators/function_generator.cpp index b9c494f..ccb09da 100755 --- a/src/generators/function_generator.cpp +++ b/src/generators/function_generator.cpp @@ -11,14 +11,20 @@ namespace generator { std::function function1D(json_t* object) { if (json_object_by_path(object, {"Constant"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating function1d: constant."); +#endif double constant = json_double(json_object_by_path(object, {"Constant", "constant"})); +#ifdef debug_level3 DEBUG_LEVEL_3("with constant: " + std::to_string(constant)); +#endif return D1ToD1::Constant(constant); } else if (json_object_by_path(object, {"PiecewiseLinear"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating function1d: PiecewiseLinear."); +#endif std::vector x_values = json_vector( json_object_by_path(object, {"PiecewiseLinear", {"xValues"}})); std::vector y_values = json_vector( @@ -31,11 +37,15 @@ std::function function1D(json_t* object) { return D1ToD1::PiecewiseLinear(x_values, y_values); } else if (json_object_by_path(object, {"PiecewiseLinearFromFile"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating function1d: PiecewiseLinear from file."); +#endif std::string absolute_filename = readAbsoluteFilename( json_object_by_path(object, {"PiecewiseLinearFromFile", "PathToH5"})); +#ifdef debug_level3 DEBUG_LEVEL_3("with filename: " + absolute_filename); +#endif Hdf5Reader reader(absolute_filename); std::string x_values_key = json_string( @@ -53,7 +63,9 @@ std::function function1D(json_t* object) { double prefactor = json_double(json_object_by_path( object, {"PiecewiseLinearFromFile", {"prefactor"}})); +#ifdef debug_level3 DEBUG_LEVEL_3("with prefactor: " + std::to_string(prefactor)); +#endif for (int i = 0; i < y_values.size(); ++i) { y_values[i] = y_values[i] * prefactor; @@ -61,7 +73,9 @@ std::function function1D(json_t* object) { return D1ToD1::PiecewiseLinear(x_values, y_values); } else if (json_object_by_path(object, {"Product"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating function1d: Product."); +#endif json_t* function_array = json_object_by_path(object, {"Product"}); std::vector> functions; size_t index; @@ -72,7 +86,9 @@ std::function function1D(json_t* object) { return D1ToD1::Product(functions); } else if (json_object_by_path(object, {"Exponential"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating function1d: Exponential."); +#endif double prefactor = json_double(json_object_by_path( object, {"Exponential", {"prefactor"}})); double scale = json_double(json_object_by_path( @@ -86,12 +102,16 @@ std::function function1D(json_t* object) { std::function function3D(json_t* object) { if (json_object_by_path(object, {"Constant3D"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating function3d: Constant3D."); +#endif double constant = json_double(json_object_by_path(object, {"Constant3D", "constant"})); return D3ToD1::Constant(constant); } else if (json_object_by_path(object, {"Product"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating function3d: Product."); +#endif std::function fi = function1D(json_object_by_path(object, {"Product", "fi"})); std::function fj = diff --git a/src/generators/geometry_generator.cpp b/src/generators/geometry_generator.cpp index ddbc21f..40d7531 100755 --- a/src/generators/geometry_generator.cpp +++ b/src/generators/geometry_generator.cpp @@ -7,7 +7,9 @@ std::shared_ptr buildGeometry(Parameter& parameter, const json_path& path_to_geometry) { if (parameter.jsonObjectFromBase( json_path_append(path_to_geometry, {"Cylinder"}))) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating geometry: cylinder."); +#endif double radius = json_read_length(parameter.jsonObjectFromBase(json_path_append( path_to_geometry, {"Cylinder", "Radius"})), @@ -16,8 +18,10 @@ std::shared_ptr buildGeometry(Parameter& parameter, json_read_length(parameter.jsonObjectFromBase(json_path_append( path_to_geometry, {"Cylinder", "Height"})), "m"); +#ifdef debug_level3 DEBUG_LEVEL_3("with radius: " + std::to_string(radius) + " m"); DEBUG_LEVEL_3("with height: " + std::to_string(height) + " m"); +#endif return std::shared_ptr(new Cylinder(radius, height)); } else { ERROR("This geometry is not implemented."); @@ -29,14 +33,18 @@ std::shared_ptr buildGeometryIncludingRedirection( Parameter& parameter, const json_path& path_to_geometry) { if (parameter.jsonObjectFromBase( json_path_append(path_to_geometry, {"CreateSameAs"}))) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating geometry: CreateSameAs."); +#endif json_path path_to_same = json_path_get(parameter.jsonObjectFromBase( json_path_append(path_to_geometry, {"CreateSameAs"}))); std::stringstream path; for (auto& p : path_to_same) { path << p << " "; } +#ifdef debug_level3 DEBUG_LEVEL_3("From path: " + path.str()); +#endif return buildGeometryIncludingRedirection(parameter, path_to_same); } else { return buildGeometry(parameter, path_to_geometry); diff --git a/src/generators/gravity_field_generator.cpp b/src/generators/gravity_field_generator.cpp index e505a70..ea8af19 100644 --- a/src/generators/gravity_field_generator.cpp +++ b/src/generators/gravity_field_generator.cpp @@ -5,7 +5,9 @@ namespace generator { std::shared_ptr gravityField(json_t* object) { +#ifdef debug_level2 DEBUG_LEVEL_2("Generating gravity field."); +#endif return std::shared_ptr(new GravityField( buildVectorField(json_object_by_path(object, {"VectorField"})))); } diff --git a/src/generators/injector_generator.cpp b/src/generators/injector_generator.cpp index c957368..3c0bb80 100755 --- a/src/generators/injector_generator.cpp +++ b/src/generators/injector_generator.cpp @@ -25,7 +25,9 @@ std::shared_ptr buildInjector( json_object_foreach(array, key, value) { std::string specie_name = json_string(json_object_by_path(value, {"TrackedSpecieName"})); +#ifdef debug_level3 DEBUG_LEVEL_3("Injected specie: " + specie_name); +#endif InjectorInfo info; info.created_specie = tracked_species[specie_name]; @@ -41,7 +43,9 @@ std::shared_ptr buildInjector( } // EventPositionDistribution +#ifdef debug_level2 DEBUG_LEVEL_2("Creating event distribution."); +#endif std::shared_ptr field = buildScalarField(json_object_by_path( object, {"EventPositionDistribution", "ScalarField"})); @@ -80,7 +84,9 @@ std::shared_ptr buildInjector( position_limit_phi, position_limit_z)); // MotherDriftVelocity +#ifdef debug_level2 DEBUG_LEVEL_2("Creating mother drift velocity."); +#endif std::shared_ptr drift_velocity = buildDriftVelocity( parameter, json_path_append(path_to_injector, {"MotherDriftVelocity"})); diff --git a/src/generators/interaction_generator.cpp b/src/generators/interaction_generator.cpp index 0fe0af3..1eb8ea6 100755 --- a/src/generators/interaction_generator.cpp +++ b/src/generators/interaction_generator.cpp @@ -33,7 +33,9 @@ void addInteractions( std::string type = json_string(json_object_by_path(value, {"Type"})); if (type == "ElasticScattering") { +#ifdef debug_level2 DEBUG_LEVEL_2("Adding interactions: ElasticScattering"); +#endif std::function cross_section = buildTotalCrossSection(json_object_by_path(value, {"CrossSection"})); @@ -43,7 +45,9 @@ void addInteractions( std::string target_name = json_string(json_object_by_path(value, {"Target"})); +#ifdef debug_level3 DEBUG_LEVEL_3("with target " + target_name); +#endif std::shared_ptr target = findTarget(target_name, tracked_species, background_species); @@ -53,11 +57,15 @@ void addInteractions( scattering_angle_distribution))); } else if (type == "FreeMovement") { +#ifdef debug_level2 DEBUG_LEVEL_2("Adding interactions: FreeMovement"); +#endif specie->addInteraction(std::shared_ptr( new interaction::FreeMovement())); } else if (type == "ElectronIonization") { +#ifdef debug_level2 DEBUG_LEVEL_2("Adding interactions: Ionization"); +#endif std::string target_name = json_string(json_object_by_path(value, {"Target"})); std::shared_ptr target = @@ -183,7 +191,9 @@ void addInteractions( ERROR("This ionization model is not implemented: " + ionization_model); } } else if (type == "Excitation") { +#ifdef debug_level2 DEBUG_LEVEL_2("Adding interactions: Excitation"); +#endif std::string target_name = json_string(json_object_by_path(value, {"Target"})); std::shared_ptr target = @@ -201,7 +211,9 @@ void addInteractions( cross_section, target, excitation_energy))); } else if (type == "Clustering") { +#ifdef debug_level2 DEBUG_LEVEL_2("Adding interactions: Clustering"); +#endif std::string target_name = json_string(json_object_by_path(value, {"Target"})); std::shared_ptr target = @@ -217,7 +229,9 @@ void addInteractions( specie->addInteraction(std::shared_ptr( new interaction::ClusterFormation(cross_section, target, product))); } else if (type == "ChargeExchange") { +#ifdef debug_level2 DEBUG_LEVEL_2("Adding interactions: ChargeExchange"); +#endif std::string target_name = json_string(json_object_by_path(value, {"Target"})); std::shared_ptr target = @@ -228,7 +242,9 @@ void addInteractions( specie->addInteraction(std::shared_ptr( new interaction::ChargeExchange(cross_section, target))); } else if (type == "Recombination") { +#ifdef debug_level2 DEBUG_LEVEL_2("Adding interactions: Recombination"); +#endif std::string target_name = json_string(json_object_by_path(value, {"Target"})); std::shared_ptr target = @@ -471,18 +487,24 @@ std::function build2DCrossSection(json_t* object) { std::shared_ptr buildScatteringAngleDistribution( json_t* object) { if (json_object_by_path(object, {"Isotropic"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Adding ScatteringAngleDistribution: Isotropic"); +#endif return std::shared_ptr( new IsotropicAngleDistribution()); } else if (json_object_by_path(object, {"AngleDistributionFromFile"})) { +#ifdef debug_level2 DEBUG_LEVEL_2( "Adding ScatteringAngleDistribution: AngleDistributionFromFile"); +#endif std::string absolute_filepath = readAbsoluteFilename( json_object_by_path(object, {"AngleDistributionFromFile", "PathToH5"})); return std::make_shared(absolute_filepath); } else if (json_object_by_path(object, {"CompositeAngleDistribution"})) { +#ifdef debug_level2 DEBUG_LEVEL_2( "Adding ScatteringAngleDistribution: CompositeAngleDistribution"); +#endif json_t* object_composite = json_object_by_path(object, {"CompositeAngleDistribution"}); const double decider_energy = json_read_energy( diff --git a/src/generators/logger_generator.cpp b/src/generators/logger_generator.cpp index c480074..2280a6a 100755 --- a/src/generators/logger_generator.cpp +++ b/src/generators/logger_generator.cpp @@ -43,7 +43,9 @@ std::shared_ptr buildDeletionLogger(json_t* object) { std::shared_ptr buildDeletionLogger( Parameter& parameter, const json_path& path_to_loggers) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating deletion logger."); +#endif json_path path_logger = json_path_append(path_to_loggers, {"Deletion"}); json_t* object = parameter.jsonObjectFromBase(path_logger); diff --git a/src/generators/magnetic_field_generator.cpp b/src/generators/magnetic_field_generator.cpp index 3e54f2a..84120d0 100755 --- a/src/generators/magnetic_field_generator.cpp +++ b/src/generators/magnetic_field_generator.cpp @@ -5,7 +5,9 @@ namespace generator { std::shared_ptr magneticField(json_t* object) { +#ifdef debug_level2 DEBUG_LEVEL_2("Generating magnetic field."); +#endif return std::shared_ptr(new MagneticField( buildVectorField(json_object_by_path(object, {"VectorField"})), buildVectorField(json_object_by_path(object, {"GradientField"})))); diff --git a/src/generators/mover_generator.cpp b/src/generators/mover_generator.cpp index d05c0ba..068cc44 100755 --- a/src/generators/mover_generator.cpp +++ b/src/generators/mover_generator.cpp @@ -7,13 +7,17 @@ std::shared_ptr buildMover(Parameter& parameter, const json_path& path_to_mover) { if (parameter.jsonObjectFromBase( json_path_append(path_to_mover, {"Boris"}))) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating mover: Boris."); +#endif double max_timestep_length = parameter.doubleValue(json_path_append( path_to_mover, {"Boris", "MaximalTimestepLength", "value"})); return std::shared_ptr(new BorisMover(max_timestep_length)); } else if (parameter.jsonObjectFromBase( json_path_append(path_to_mover, {"Drift"}))) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating mover: Drift."); +#endif double maximal_moved_distance = json_read_length(parameter.jsonObjectFromBase(json_path_append( path_to_mover, {"Drift", "MaximalMovedDistance"}))); diff --git a/src/generators/poisson_solver_generator.cpp b/src/generators/poisson_solver_generator.cpp index 41c3b0d..549f619 100644 --- a/src/generators/poisson_solver_generator.cpp +++ b/src/generators/poisson_solver_generator.cpp @@ -10,7 +10,9 @@ namespace generator { std::shared_ptr buildPoissonSolver( Parameter& parameter) { +#ifdef debug_level2 DEBUG_LEVEL_2("Generating Poisson solver."); +#endif std::shared_ptr geometry; json_t* object = json_object_by_path( @@ -48,7 +50,9 @@ namespace generator { std::map buildBoundaries(Parameter& parameter, const json_path& path_to_boundaries) { +#ifdef debug_level3 DEBUG_LEVEL_3("Creating Boundaries."); +#endif std::map boundary_map { {"Bottom", {0., BoundaryType::dirichlet}}, {"Top", {0., BoundaryType::dirichlet}}, @@ -63,7 +67,9 @@ namespace generator { json_t* value; json_object_foreach(parameter.jsonObjectFromBase(path_to_boundaries), key, value) { +#ifdef debug_level3 DEBUG_LEVEL_3("Creating " + std::string(key) + ": "); +#endif if(!(boundary_map.find(std::string(key)) == boundary_map.end())) { double boundary_value = json_double(json_object_by_path(value, {"value"})); @@ -82,8 +88,10 @@ namespace generator { ". Using default boundary (dirichtlet, value 0)"); continue; } +#ifdef debug_level3 DEBUG_LEVEL_3("with type: " + boundary_type); DEBUG_LEVEL_3("with value: " + std::to_string(boundary_value)); +#endif } else { SIM_INFO(std::string(key) + ": unknown location. Is ignored."); diff --git a/src/generators/reflector_generator.cpp b/src/generators/reflector_generator.cpp index e1720ff..3a71867 100755 --- a/src/generators/reflector_generator.cpp +++ b/src/generators/reflector_generator.cpp @@ -8,7 +8,9 @@ std::shared_ptr buildReflector(Parameter& parameter, const json_path& path_to_reflector) { if (parameter.jsonObjectFromBase( json_path_append(path_to_reflector, {"ReflectorDPS"}))) { +#ifdef debug_level2 DEBUG_LEVEL_2("Create reflector: ReflectorDPS"); +#endif double position_z = json_read_length( parameter.jsonObjectFromBase(json_path_append( path_to_reflector, {"ReflectorDPS", "position_z"})), @@ -16,7 +18,9 @@ std::shared_ptr buildReflector(Parameter& parameter, return std::shared_ptr(new ReflectorDPS(position_z)); } else if (parameter.jsonObjectFromBase( json_path_append(path_to_reflector, {"NoReflector"}))) { +#ifdef debug_level2 DEBUG_LEVEL_2("Create reflector: NoReflector"); +#endif return std::shared_ptr(new NoReflector()); } else { ERROR("This reflector is not implemented."); diff --git a/src/generators/restart_generator.cpp b/src/generators/restart_generator.cpp index 5f6e97a..1a098e5 100644 --- a/src/generators/restart_generator.cpp +++ b/src/generators/restart_generator.cpp @@ -7,13 +7,17 @@ namespace generator { DEBUG_LEVEL_3("Build Restart."); bool do_restart = json_bool(json_object_by_path(object, {"Do"})); if (!do_restart) { +#ifdef debug DEBUG_LEVEL_0("No Restart desired."); +#endif return Restart(false, "", ""); } std::string filepath = readAbsoluteFilename(json_object_by_path(object, {"PathToH5"})) + ".h5"; +#ifdef debug_level3 DEBUG_LEVEL_3("Restart: file path:" + filepath); +#endif std::string identifier; int sync_period = json_int(json_object_by_path(object, {"SyncPeriod"})); @@ -27,7 +31,9 @@ namespace generator { identifier = "SyncPeriod_" + std::to_string(sync_period); } +#ifdef debug_level3 DEBUG_LEVEL_3("Restart: SyncPeriod to be started from: " + identifier); +#endif return Restart(do_restart, filepath, identifier); } diff --git a/src/generators/simulation_output_generator.cpp b/src/generators/simulation_output_generator.cpp index 979d7e5..79b6b69 100755 --- a/src/generators/simulation_output_generator.cpp +++ b/src/generators/simulation_output_generator.cpp @@ -166,7 +166,9 @@ std::shared_ptr buildSimulationOutput( } ASSERT_NOTNEGATIVE(&intervall, "The intervall for RestartInfo has to be either 0" ",if no output is required or positive otherwise"); +#ifdef debug_level3 DEBUG_LEVEL_3("Restart output interval: " + std::to_string(intervall)); +#endif bool overwrite_last = json_bool( json_object_by_path(object, {"RestartInfo", "OverwriteLast"})); diff --git a/src/generators/species_generator.cpp b/src/generators/species_generator.cpp index 6b98995..5a1afc3 100755 --- a/src/generators/species_generator.cpp +++ b/src/generators/species_generator.cpp @@ -107,13 +107,17 @@ std::shared_ptr SpeciesBuilder::lastSyncTimer() { } void SpeciesBuilder::initTimer() { +#ifdef debug_level2 DEBUG_LEVEL_2("Init timer."); +#endif timer_ = std::shared_ptr(new Timer()); last_sync_timer_ = std::shared_ptr(new Timer()); } void SpeciesBuilder::initBackgroundSpecies(Parameter& parameter) { +#ifdef debug_level2 DEBUG_LEVEL_2("Init background species info."); +#endif const char* key; json_t* value; json_object_foreach(parameter.jsonObjectFromBase({"Species", "Background"}), @@ -126,7 +130,9 @@ void SpeciesBuilder::initBackgroundSpecies(Parameter& parameter) { } void SpeciesBuilder::initTrackedSpecies(Parameter& parameter) { +#ifdef debug_level2 DEBUG_LEVEL_2("Init tracked species info."); +#endif const char* key; json_t* value; json_object_foreach(parameter.jsonObjectFromBase({"Species", "Tracked"}), key, @@ -139,11 +145,15 @@ void SpeciesBuilder::initTrackedSpecies(Parameter& parameter) { } void SpeciesBuilder::fillBackgroundSpecieType(Parameter& parameter) { +#ifdef debug_level2 DEBUG_LEVEL_2("Fill background species type."); +#endif for (auto& b : background_species_info) { std::string type = json_string(parameter.jsonObjectFromBase( json_path_append(b.second.path_in_json, {"ParticleType"}))); +#ifdef debug_level3 DEBUG_LEVEL_3("Type: " + type); +#endif if (SpeciesAlias::isAlias(type)) { b.second.type = SpeciesAlias::alias(type); } else { @@ -153,11 +163,15 @@ void SpeciesBuilder::fillBackgroundSpecieType(Parameter& parameter) { } void SpeciesBuilder::fillTrackedSpecieType(Parameter& parameter) { +#ifdef debug_level2 DEBUG_LEVEL_2("Fill tracked species type."); +#endif for (auto& b : tracked_species_info) { std::string type = json_string(parameter.jsonObjectFromBase( json_path_append(b.second.path_in_json, {"ParticleType"}))); +#ifdef debug_level3 DEBUG_LEVEL_3("Type: " + type); +#endif if (SpeciesAlias::isAlias(type)) { b.second.type = SpeciesAlias::alias(type); } else { @@ -167,7 +181,9 @@ void SpeciesBuilder::fillTrackedSpecieType(Parameter& parameter) { } void SpeciesBuilder::fillBackgroundDensity(Parameter& parameter) { +#ifdef debug_level2 DEBUG_LEVEL_2("Fill background density."); +#endif for (auto& b : background_species_info) { b.second.density = buildConstantDensityField(parameter.jsonObjectFromBase( json_path_append(b.second.path_in_json, {"ConstantDensityField"}))); @@ -175,7 +191,9 @@ void SpeciesBuilder::fillBackgroundDensity(Parameter& parameter) { } void SpeciesBuilder::fillVelocityDistribution(Parameter& parameter) { +#ifdef debug_level2 DEBUG_LEVEL_2("Fill velocity distributions."); +#endif for (auto& b : background_species_info) { b.second.velocity_distribution = buildVelocityDistribution( parameter, @@ -189,7 +207,9 @@ void SpeciesBuilder::fillVelocityDistribution(Parameter& parameter) { } void SpeciesBuilder::fillDriftVelocity(Parameter& parameter) { +#ifdef debug_level2 DEBUG_LEVEL_2("Fill drift velocity."); +#endif for (auto& b : background_species_info) { b.second.drift_velocity = buildDriftVelocityIncludingRedirection( parameter, json_path_append(b.second.path_in_json, {"DriftVelocity"})); @@ -201,7 +221,9 @@ void SpeciesBuilder::fillDriftVelocity(Parameter& parameter) { } void SpeciesBuilder::fillMass() { +#ifdef debug_level2 DEBUG_LEVEL_2("Fill masses."); +#endif for (auto& b : background_species_info) { b.second.mass_kg = SpeciesMasses::mass(b.second.type); } @@ -211,7 +233,9 @@ void SpeciesBuilder::fillMass() { } void SpeciesBuilder::fillCharge() { +#ifdef debug_level2 DEBUG_LEVEL_2("Fill charges."); +#endif for (auto& b : background_species_info) { b.second.charge_C = SpeciesCharges::charge(b.second.type); } @@ -221,7 +245,9 @@ void SpeciesBuilder::fillCharge() { } void SpeciesBuilder::fillMover(Parameter& parameter) { +#ifdef debug_level2 DEBUG_LEVEL_2("Fill movers."); +#endif for (auto& b : tracked_species_info) { if ((b.second.mover == nullptr)) { b.second.mover = buildMover( @@ -231,7 +257,9 @@ void SpeciesBuilder::fillMover(Parameter& parameter) { } void SpeciesBuilder::fillTerminator(Parameter& parameter) { +#ifdef debug_level2 DEBUG_LEVEL_2("Fill terminators."); +#endif for (auto& b : tracked_species_info) { if ((b.second.terminator == nullptr)) { b.second.terminator = buildTerminator( @@ -241,7 +269,9 @@ void SpeciesBuilder::fillTerminator(Parameter& parameter) { } void SpeciesBuilder::fillReflector(Parameter& parameter) { +#ifdef debug_level2 DEBUG_LEVEL_2("Fill reflectors."); +#endif for (auto& b : tracked_species_info) { if ((b.second.reflector == nullptr)) { b.second.reflector = buildReflector( @@ -252,7 +282,9 @@ void SpeciesBuilder::fillReflector(Parameter& parameter) { // TBD: Fill and create dynamic density fields with pitch angle distribution void SpeciesBuilder::fillTrackedDensity(Parameter& parameter) { +#ifdef debug_level2 DEBUG_LEVEL_2("Fill tracked density."); +#endif for (auto& b : tracked_species_info) { b.second.density_field = buildDynamicDensityField( parameter, @@ -270,7 +302,9 @@ void SpeciesBuilder::fillTrackedDensity(Parameter& parameter) { } void SpeciesBuilder::buildSpecies() { +#ifdef debug_level2 DEBUG_LEVEL_2("Build species from info."); +#endif for (auto& b : background_species_info) { background_species[b.first] = std::shared_ptr( new species::BackgroundSpecie( @@ -290,7 +324,9 @@ void SpeciesBuilder::buildSpecies() { } void SpeciesBuilder::fillCurrentCollector(Parameter& parameter) { +#ifdef debug_level2 DEBUG_LEVEL_2("Fill current collectors."); +#endif for (auto& b : tracked_species) { auto current_collector = buildCurrentCollector( parameter, @@ -302,7 +338,9 @@ void SpeciesBuilder::fillCurrentCollector(Parameter& parameter) { } void SpeciesBuilder::fillLoggers(Parameter& parameter) { +#ifdef debug_level2 DEBUG_LEVEL_2("Fill loggers."); +#endif for (auto& b : tracked_species) { auto deletion_logger = buildDeletionLogger( parameter, @@ -313,7 +351,9 @@ void SpeciesBuilder::fillLoggers(Parameter& parameter) { } void SpeciesBuilder::fillInteractions(Parameter& parameter) { +#ifdef debug_level2 DEBUG_LEVEL_2("Fill interactions."); +#endif for (auto& b : tracked_species) { json_path path = tracked_species_info[b.first].path_in_json; path = json_path_append(path, {"Interactions"}); diff --git a/src/generators/terminator_generator.cpp b/src/generators/terminator_generator.cpp index d5f362a..d845a00 100755 --- a/src/generators/terminator_generator.cpp +++ b/src/generators/terminator_generator.cpp @@ -7,13 +7,17 @@ namespace generator { std::shared_ptr buildTerminator( Parameter& parameter, const json_path& path_to_terminator) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating terminator."); +#endif long int max_interactions = static_cast(parameter.doubleValue( json_path_append(path_to_terminator, {"MaximumInteractions"}))); double max_time_alive = parameter.doubleValue( json_path_append(path_to_terminator, {"MaxTimeAlive", "value"})); +#ifdef debug_level3 DEBUG_LEVEL_3("with max interactions: " + std::to_string(max_interactions)); DEBUG_LEVEL_3("with max time alive: " + std::to_string(max_time_alive)); +#endif std::shared_ptr geometry = buildGeometryIncludingRedirection( parameter, json_path_append(path_to_terminator, {"BoundaryGeometry"})); diff --git a/src/generators/vector_field_generator.cpp b/src/generators/vector_field_generator.cpp index 8d03fe7..b4dc8a1 100755 --- a/src/generators/vector_field_generator.cpp +++ b/src/generators/vector_field_generator.cpp @@ -53,7 +53,9 @@ blitz::Array readComponentFromFile(json_t* object, int component) { std::shared_ptr buildVectorField(json_t* object) { if (json_object_by_path(object, {"VectorFieldConstant"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating Vector field: VectorFieldConstant"); +#endif blitz::TinyVector constant = json_blitz_vector<3>( json_object_by_path(object, {"VectorFieldConstant", "constant"})); @@ -61,13 +63,17 @@ std::shared_ptr buildVectorField(json_t* object) { new VectorFieldConstant(CylinderVector(constant))); } else if (json_object_by_path(object, {"VectorFieldFunctionInZ"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating Vector field: VectorFieldFunctionInZ"); +#endif std::function z_function = function3D( json_object_by_path(object, {"VectorFieldFunctionInZ", "zFunction"})); return std::shared_ptr(new VectorFieldFunctionInZ(z_function)); } else if (json_object_by_path(object, {"VectorFieldFromArray"})) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating Vector field: VectorFieldFromArray"); +#endif blitz::Array v_radial = readComponentFromFile( json_object_by_path(object, diff --git a/src/generators/velocity_distribution_function_generator.cpp b/src/generators/velocity_distribution_function_generator.cpp index 96cfc8c..5b78dee 100755 --- a/src/generators/velocity_distribution_function_generator.cpp +++ b/src/generators/velocity_distribution_function_generator.cpp @@ -11,8 +11,10 @@ std::shared_ptr buildVelocityDistributionFunction( const json_path& path_to_distribution) { if (parameter.jsonObjectFromBase( json_path_append(path_to_distribution, {"IsotropicDistribution"}))) { +#ifdef debug_level2 DEBUG_LEVEL_2( "Creating velocity distribution function: IsotropicDistribution"); +#endif std::shared_ptr fE = buildEnergyDistributionFunction( parameter, json_path_append(path_to_distribution, @@ -26,8 +28,10 @@ std::shared_ptr buildVelocityDistributionFunction( } else if (parameter.jsonObjectFromBase(json_path_append( path_to_distribution, {"DirectedDistribution"}))) { +#ifdef debug_level2 DEBUG_LEVEL_2( "Creating velocity distribution function: DirectedDistribution"); +#endif std::shared_ptr fE = buildEnergyDistributionFunction( parameter, json_path_append(path_to_distribution, diff --git a/src/generators/velocity_distribution_generator.cpp b/src/generators/velocity_distribution_generator.cpp index e731296..effc801 100755 --- a/src/generators/velocity_distribution_generator.cpp +++ b/src/generators/velocity_distribution_generator.cpp @@ -10,8 +10,10 @@ std::shared_ptr buildVelocityDistribution( const json_path& path_to_distribution) { if (parameter.jsonObjectFromBase(json_path_append( path_to_distribution, {"VelocityDistributionFromFunction"}))) { +#ifdef debug_level2 DEBUG_LEVEL_2( "Creating velocity distribution: VelocityDistributionFromFunction"); +#endif std::shared_ptr v = buildVelocityDistributionFunction( parameter, json_path_append(path_to_distribution, @@ -21,7 +23,9 @@ std::shared_ptr buildVelocityDistribution( new VelocityDistributionFromFunction(v)); } else if (parameter.jsonObjectFromBase( json_path_append(path_to_distribution, {"null"}))) { +#ifdef debug_level2 DEBUG_LEVEL_2("Creating velocity distribution: null"); +#endif return nullptr; } else { ERROR("This velocity distribution is not implemented."); diff --git a/src/interactions/charge_exchange.cpp b/src/interactions/charge_exchange.cpp index 2a1a4c0..0cac026 100755 --- a/src/interactions/charge_exchange.cpp +++ b/src/interactions/charge_exchange.cpp @@ -13,7 +13,9 @@ ChargeExchange::ChargeExchange(std::function 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(); // const blitz::TinyVector v_target = diff --git a/src/interactions/cluster_formation.cpp b/src/interactions/cluster_formation.cpp index e8d8d82..714a7a3 100755 --- a/src/interactions/cluster_formation.cpp +++ b/src/interactions/cluster_formation.cpp @@ -17,7 +17,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 v_target = // target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() + diff --git a/src/interactions/elastic_scattering.cpp b/src/interactions/elastic_scattering.cpp index b87df68..183e23d 100755 --- a/src/interactions/elastic_scattering.cpp +++ b/src/interactions/elastic_scattering.cpp @@ -18,7 +18,9 @@ ElasticScattering::ElasticScattering( InteractionOutput ElasticScattering::performInteraction( particle::Particle& particle, RandomNumbers* generator) { +#ifdef debug_level3 DEBUG_LEVEL_3("Perform elastic scattering."); +#endif const blitz::TinyVector v_impact = particle.velocity().cartesianEntries(); // const auto x_impact = particle.position(); diff --git a/src/interactions/excitation.cpp b/src/interactions/excitation.cpp index a0c8123..150d8a3 100755 --- a/src/interactions/excitation.cpp +++ b/src/interactions/excitation.cpp @@ -18,7 +18,9 @@ Excitation::Excitation(std::function cross_section, InteractionOutput Excitation::performInteraction(particle::Particle& particle, RandomNumbers* generator) { +#ifdef debug_level3 DEBUG_LEVEL_3("Perform excitation."); +#endif const blitz::TinyVector v_impact = particle.velocity().cartesianEntries(); const blitz::TinyVector n_impact = diff --git a/src/interactions/free_movement.cpp b/src/interactions/free_movement.cpp index 2147e65..29a77e8 100755 --- a/src/interactions/free_movement.cpp +++ b/src/interactions/free_movement.cpp @@ -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(); } diff --git a/src/interactions/ionization.cpp b/src/interactions/ionization.cpp index 9c8457b..48db467 100755 --- a/src/interactions/ionization.cpp +++ b/src/interactions/ionization.cpp @@ -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 v_impact = particle.velocity().cartesianEntries(); diff --git a/src/interactions/recombination.cpp b/src/interactions/recombination.cpp index 61da545..af12a0f 100755 --- a/src/interactions/recombination.cpp +++ b/src/interactions/recombination.cpp @@ -17,7 +17,9 @@ Recombination::Recombination(std::function cross_section, InteractionOutput Recombination::performInteraction( particle::Particle& particle, RandomNumbers* generator) { +#ifdef debug_level3 DEBUG_LEVEL_3("Perform recombination."); +#endif // std::vector macroscopic_bin_cross_sections_m; // const int number_energy_bins = recombination_target_->dynamicDensityField() diff --git a/src/poisson_solver/poisson_solver.cpp b/src/poisson_solver/poisson_solver.cpp index ce553a7..3bc09ce 100755 --- a/src/poisson_solver/poisson_solver.cpp +++ b/src/poisson_solver/poisson_solver.cpp @@ -85,14 +85,18 @@ void PoissonSolver::solvePotential( if (!(do_solver_) || !(solve)) { return; } +#ifdef debug_level3 DEBUG_LEVEL_3("Interpolating chargedensity."); +#endif blitz::Array interpolated_density = interpolateDensityToPotentialGrid(charge_density); int it = 1; do { solverIteration(interpolated_density); if (it % 1000 == 0) { +#ifdef debug_level3 DEBUG_LEVEL_3("Poisson solver, iteration: " + std::to_string(it)); +#endif if (converged(interpolated_density)) { break; }; @@ -235,14 +239,18 @@ bool PoissonSolver::converged( normalized_difference = std::sqrt(cumulated_quadradic_difference / (nr * nth * nz)); +#ifdef debug DEBUG_LEVEL_0("Poisson solver reached a normalized difference of: " + std::to_string(normalized_difference)); +#endif double normalized_maximum = maximum_difference*SI::eps0/(fabs(blitz::max(interpolated_density)) + 1e-12); +#ifdef debug_level1 std::ostringstream message; message << "Maximum Difference normalized by order of magnitude: " << normalized_difference; - DEBUG_LEVEL_0(message.str()); + DEBUG_LEVEL_1(message.str()); +#endif return normalized_difference < target_accuracy_; } @@ -250,7 +258,9 @@ blitz::Array PoissonSolver::potential() { // there might be a better way to do this... (if one can do array.memberValue without // explicitely looping) blitz::Array potentialValues(potential_.lbound(), potential_.extent()); +#ifdef debug_level3 DEBUG_LEVEL_3("Extracting potential values"); +#endif for(int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) { for(int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) { for(int k = potential_.lbound(2); k <= potential_.ubound(2); ++k) { @@ -293,9 +303,10 @@ blitz::Array PoissonSolver::interpolateDensityToPotentialGrid( //might not work that way (if not needs a loop) interpolatedDensity(fixedIndex, blitz::Range::all(), blitz::Range::all()) /= potential_.extent(1); - +#ifdef debug_level3 DEBUG_LEVEL_3("Max Value in interpolated density array: " + std::to_string(blitz::max(interpolatedDensity))); +#endif //for r=r_max, k=k_min and k=k_max do not use an interpolation, //since no boundary cell needs the information about its density value return interpolatedDensity; diff --git a/src/simulation/density_field.cpp b/src/simulation/density_field.cpp index d7a0d42..6d6b2ca 100755 --- a/src/simulation/density_field.cpp +++ b/src/simulation/density_field.cpp @@ -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 DynamicDensityField::densityArray() { +#ifdef debug_level3 DEBUG_LEVEL_3("recalc Density array"); +#endif recalculateDensityArray(); blitz::TinyVector lowerbound(density_per_m3_.lbound(0), @@ -237,7 +241,7 @@ blitz::Array DynamicDensityField::densityArray() { blitz::Array 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 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; } diff --git a/src/simulation/injector.cpp b/src/simulation/injector.cpp index f4648b9..2bc4531 100755 --- a/src/simulation/injector.cpp +++ b/src/simulation/injector.cpp @@ -71,8 +71,10 @@ std::vector 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(0,0,0)); diff --git a/src/simulation/simulation.cpp b/src/simulation/simulation.cpp index f674196..642f6f4 100755 --- a/src/simulation/simulation.cpp +++ b/src/simulation/simulation.cpp @@ -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(); +#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 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 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 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 Simulation::determineInjectedDensityParticles( //maybe put that into the poisson solver blitz::Array 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 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 init = firstTracked-> dynamicDensityField()->densityArray(); blitz::Array 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; }