diff --git a/include/simulation/cpu_synchronizer.h b/include/simulation/cpu_synchronizer.h index 0930d71..885bcad 100755 --- a/include/simulation/cpu_synchronizer.h +++ b/include/simulation/cpu_synchronizer.h @@ -24,13 +24,10 @@ class CpuSynchronizer { tracked_species, bool reset); void synchronize(DynamicDensityField* field, - DynamicDensityField* last_sync_field, DynamicDensityField* density_for_drawing, bool reset); - void synchronize(CurrentCollector* collector, - CurrentCollector* last_sync_collector); - void synchronize(DeletionLogger* logger, - DeletionLogger* last_sync_logger); + void synchronize(CurrentCollector* collector); + void synchronize(DeletionLogger* logger); void synchronize(Timer* timer, Timer* last_sync_timer); diff --git a/include/simulation/current_collector.h b/include/simulation/current_collector.h index 35386e2..066767d 100755 --- a/include/simulation/current_collector.h +++ b/include/simulation/current_collector.h @@ -67,6 +67,15 @@ class CurrentCollector { blitz::Array r_negative_crossings; blitz::Array r_positive_crossings; + blitz::Array sync_z_negative_crossings; + blitz::Array sync_z_positive_crossings; + + blitz::Array sync_phi_negative_crossings; + blitz::Array sync_phi_positive_crossings; + + blitz::Array sync_r_negative_crossings; + blitz::Array sync_r_positive_crossings; + blitz::Array collector_areas_r; blitz::Array collector_areas_phi; blitz::Array collector_areas_z; diff --git a/include/simulation/density_field.h b/include/simulation/density_field.h index 5859366..e111fcc 100755 --- a/include/simulation/density_field.h +++ b/include/simulation/density_field.h @@ -80,6 +80,10 @@ class DynamicDensityField : public DensityField { blitz::Array time_in_bin_s_; blitz::Array deleted_particles_; + + blitz::Array sync_time_in_bin_s_; + blitz::Array sync_deleted_particles_; + blitz::Array density_per_m3_; blitz::Array bin_volume_m3_; diff --git a/include/simulation/logger.h b/include/simulation/logger.h index 4ef5c88..0f7e708 100755 --- a/include/simulation/logger.h +++ b/include/simulation/logger.h @@ -29,6 +29,7 @@ class DeletionLogger { private: std::map num_deletions; + std::map sync_num_deletions; }; #endif /* LOGGER_H */ diff --git a/include/simulation/species.h b/include/simulation/species.h index b21c331..01111ae 100755 --- a/include/simulation/species.h +++ b/include/simulation/species.h @@ -62,7 +62,6 @@ class TrackedSpecie : public Specie { std::shared_ptr density_field, std::shared_ptr velocity_distribution, std::shared_ptr drift_velocity, - std::shared_ptr last_sync_density_field, std::shared_ptr density_for_drawing); DensityField* densityField(); @@ -70,7 +69,6 @@ class TrackedSpecie : public Specie { DriftVelocity* driftVelocity(); DynamicDensityField* dynamicDensityField(); - DynamicDensityField* lastSyncDensityField(); Mover* mover(); Terminator* terminator(); Reflector* reflector(); @@ -78,18 +76,11 @@ class TrackedSpecie : public Specie { DeletionLogger* deletionLogger(); void deletionLogger(std::shared_ptr new_logger); - DeletionLogger* lastSyncDeletionLogger(); - void lastSyncDeletionLogger(std::shared_ptr new_logger); - DynamicDensityField* densityForDrawing(); CurrentCollector* currentCollector(); void currentCollector(std::shared_ptr new_collector); - CurrentCollector* lastSyncCurrentCollector(); - void lastSyncCurrentCollector( - std::shared_ptr new_collector); - std::vector> interactions(); void addInteraction(std::shared_ptr interaction); @@ -106,13 +97,6 @@ class TrackedSpecie : public Specie { std::shared_ptr current_collector_; std::vector> interactions_; - // fields to store the date of the last synchronization - // (after a synchronization the last_sync field and the non-last_sync field - // contain the same data) - std::shared_ptr last_sync_density_field_; - std::shared_ptr last_sync_deletion_logger_; - std::shared_ptr last_sync_current_collector_; - std::shared_ptr density_for_drawing_; }; diff --git a/src/generators/species_generator.cpp b/src/generators/species_generator.cpp index 21ed5fc..ac62209 100755 --- a/src/generators/species_generator.cpp +++ b/src/generators/species_generator.cpp @@ -265,12 +265,6 @@ void SpeciesBuilder::fillTrackedDensity(Parameter& parameter) { json_path_append(b.second.path_in_json, {"DensityField", "DynamicDensityField"}), timer_); - - b.second.last_sync_density_field = buildDynamicDensityField( - parameter, - json_path_append(b.second.path_in_json, - {"DensityField", "DynamicDensityField"}), - last_sync_timer_); } } @@ -290,8 +284,7 @@ void SpeciesBuilder::buildSpecies() { b.second.type, b.second.name, b.second.mass_kg, b.second.charge_C, b.second.mover, b.second.terminator, b.second.reflector, b.second.density_field, b.second.velocity_distribution, - b.second.drift_velocity, b.second.last_sync_density_field, - b.second.density_drawing_field)); + b.second.drift_velocity, b.second.density_drawing_field)); } } @@ -303,15 +296,7 @@ void SpeciesBuilder::fillCurrentCollector(Parameter& parameter) { json_path_append(tracked_species_info.at(b.first).path_in_json, {"CurrentCollector"}), timer_); - // has to be recreated, if it would be copied the timer_ pointer would - // point to the same object -> could not get updated during synchronization - auto last_sync_current_collector = buildCurrentCollector( - parameter, - json_path_append(tracked_species_info.at(b.first).path_in_json, - {"CurrentCollector"}), - last_sync_timer_); b.second->currentCollector(current_collector); - b.second->lastSyncCurrentCollector(last_sync_current_collector); } } @@ -323,8 +308,6 @@ void SpeciesBuilder::fillLoggers(Parameter& parameter) { json_path_append(tracked_species_info.at(b.first).path_in_json, {"Loggers"})); b.second->deletionLogger(deletion_logger); - b.second->lastSyncDeletionLogger( - std::make_shared(*deletion_logger)); } } diff --git a/src/simulation/cpu_synchronizer.cpp b/src/simulation/cpu_synchronizer.cpp index 84f8613..f832fc2 100755 --- a/src/simulation/cpu_synchronizer.cpp +++ b/src/simulation/cpu_synchronizer.cpp @@ -65,72 +65,68 @@ void CpuSynchronizer::synchronize(Timer* timer, Timer* last_sync_timer) { } void CpuSynchronizer::synchronize(DynamicDensityField* field, - DynamicDensityField* last_sync_field, DynamicDensityField* density_for_drawing, bool reset) { - if (field && last_sync_field) { - if(field == last_sync_field) { - ERROR("The way last_sync_field is created does not work as intended."); - } - sumToAll(field->time_in_bin_s_, last_sync_field->time_in_bin_s_); - field->time_in_bin_s_ = last_sync_field->time_in_bin_s_; + if (field) { + // if(field == last_sync_field) { + // ERROR("The way last_sync_field is created does not work as intended."); + // } + sumToAll(field->time_in_bin_s_, field->sync_time_in_bin_s_); + field->time_in_bin_s_ = field->sync_time_in_bin_s_; - sumToAll(field->deleted_particles_, last_sync_field->deleted_particles_); - field->deleted_particles_ = last_sync_field->deleted_particles_; + sumToAll(field->deleted_particles_, field->sync_deleted_particles_); + field->deleted_particles_ = field->sync_deleted_particles_; if (reset) { - density_for_drawing->time_in_bin_s_ = last_sync_field->time_in_bin_s_; - density_for_drawing->deleted_particles_ = - last_sync_field->deleted_particles_; + density_for_drawing->time_in_bin_s_ = field->time_in_bin_s_; + density_for_drawing->deleted_particles_ = field->deleted_particles_; } } } -void CpuSynchronizer::synchronize(CurrentCollector* collector, - CurrentCollector* last_sync_collector) { - if (collector && last_sync_collector) { +void CpuSynchronizer::synchronize(CurrentCollector* collector) { + if (collector) { sumToAll(collector->z_negative_crossings, - last_sync_collector->z_negative_crossings); + collector->sync_z_negative_crossings); collector->z_negative_crossings = - last_sync_collector->z_negative_crossings; + collector->sync_z_negative_crossings; sumToAll(collector->z_positive_crossings, - last_sync_collector->z_positive_crossings); + collector->sync_z_positive_crossings); collector->z_positive_crossings = - last_sync_collector->z_positive_crossings; + collector->sync_z_positive_crossings; sumToAll(collector->phi_negative_crossings, - last_sync_collector->phi_negative_crossings); + collector->sync_phi_negative_crossings); collector->phi_negative_crossings = - last_sync_collector->phi_negative_crossings; + collector->sync_phi_negative_crossings; sumToAll(collector->phi_positive_crossings, - last_sync_collector->phi_positive_crossings); + collector->sync_phi_positive_crossings); collector->phi_positive_crossings = - last_sync_collector->phi_positive_crossings; + collector->sync_phi_positive_crossings; sumToAll(collector->r_negative_crossings, - last_sync_collector->r_negative_crossings); + collector->sync_r_negative_crossings); collector->r_negative_crossings = - last_sync_collector->r_negative_crossings; + collector->sync_r_negative_crossings; sumToAll(collector->r_positive_crossings, - last_sync_collector->r_positive_crossings); + collector->sync_r_positive_crossings); collector->r_positive_crossings = - last_sync_collector->r_positive_crossings; + collector->sync_r_positive_crossings; } } -void CpuSynchronizer::synchronize(DeletionLogger* logger, - DeletionLogger* last_sync_logger) { - if (logger && last_sync_logger) { +void CpuSynchronizer::synchronize(DeletionLogger* logger) { + if (logger) { for (auto& pair : logger->num_deletions) { long int num_deletion = pair.second; - long int last_sync_num_deletion = last_sync_logger->num_deletions[pair.first]; + long int last_sync_num_deletion = logger->sync_num_deletions[pair.first]; sumToAll(num_deletion, last_sync_num_deletion); // last_sync_num_deletion now contains the total number of deletions // across all cpus -> update the values in the objects pair.second = last_sync_num_deletion; - last_sync_logger->num_deletions[pair.first] = last_sync_num_deletion; + logger->sync_num_deletions[pair.first] = last_sync_num_deletion; } } } @@ -147,14 +143,11 @@ void CpuSynchronizer::synchronize( for (auto& pair : tracked_species) { // DEBUG_LEVEL_3("dynden Synchronization."); - synchronize(pair.second->dynamicDensityField(), - pair.second->lastSyncDensityField(), + synchronize(pair.second->dynamicDensityField(), pair.second->densityForDrawing(), reset); // DEBUG_LEVEL_3("cc Synchronization."); - synchronize(pair.second->currentCollector(), - pair.second->lastSyncCurrentCollector()); + synchronize(pair.second->currentCollector()); // DEBUG_LEVEL_3("dellogger Synchronization."); - synchronize(pair.second->deletionLogger(), - pair.second->lastSyncDeletionLogger()); + synchronize(pair.second->deletionLogger()); } } \ No newline at end of file diff --git a/src/simulation/current_collector.cpp b/src/simulation/current_collector.cpp index 7ffe918..5ab4531 100755 --- a/src/simulation/current_collector.cpp +++ b/src/simulation/current_collector.cpp @@ -12,7 +12,13 @@ CurrentCollector::CurrentCollector(const CylinderBinning& position_binning, collector_areas_r(createAreaRadial(position_binning)), phi_negative_crossings(createCrossingsAzimuthal(position_binning)), phi_positive_crossings(createCrossingsAzimuthal(position_binning)), - collector_areas_phi(createAreaAzimuthal(position_binning)) {} + collector_areas_phi(createAreaAzimuthal(position_binning)), + sync_z_negative_crossings(createCrossingsLongitudinal(position_binning)), + sync_z_positive_crossings(createCrossingsLongitudinal(position_binning)), + sync_r_negative_crossings(createCrossingsRadial(position_binning)), + sync_r_positive_crossings(createCrossingsRadial(position_binning)), + sync_phi_negative_crossings(createCrossingsAzimuthal(position_binning)), + sync_phi_positive_crossings(createCrossingsAzimuthal(position_binning)) {} blitz::Array CurrentCollector::createAreaLongitudinal( const CylinderBinning& position_binning) { @@ -250,4 +256,13 @@ void CurrentCollector::resetCurrentCollector() { r_negative_crossings = 0.; r_positive_crossings = 0.; + + sync_z_negative_crossings = 0.; + sync_z_positive_crossings = 0.; + + sync_phi_negative_crossings = 0.; + sync_phi_positive_crossings = 0.; + + sync_r_negative_crossings = 0.; + sync_r_positive_crossings = 0.; } \ No newline at end of file diff --git a/src/simulation/density_field.cpp b/src/simulation/density_field.cpp index 23f3214..b60b989 100755 --- a/src/simulation/density_field.cpp +++ b/src/simulation/density_field.cpp @@ -54,6 +54,15 @@ DynamicDensityField::DynamicDensityField( position_binning.longitudinal_binning.binIndexMax()), blitz::Range(energy_binning.binIndexMin(), energy_binning.binIndexMax()))), + sync_time_in_bin_s_(initiate4DArray( + blitz::Range(position_binning.radial_binning.binIndexMin(), + position_binning.radial_binning.binIndexMax()), + blitz::Range(position_binning.azimuth_binning.binIndexMin(), + position_binning.azimuth_binning.binIndexMax()), + blitz::Range(position_binning.longitudinal_binning.binIndexMin(), + position_binning.longitudinal_binning.binIndexMax()), + blitz::Range(energy_binning.binIndexMin(), + energy_binning.binIndexMax()))), deleted_particles_(initiate4DArray( blitz::Range(position_binning.radial_binning.binIndexMin(), position_binning.radial_binning.binIndexMax()), @@ -63,6 +72,15 @@ DynamicDensityField::DynamicDensityField( position_binning.longitudinal_binning.binIndexMax()), blitz::Range(energy_binning.binIndexMin(), energy_binning.binIndexMax()))), + sync_deleted_particles_(initiate4DArray( + blitz::Range(position_binning.radial_binning.binIndexMin(), + position_binning.radial_binning.binIndexMax()), + blitz::Range(position_binning.azimuth_binning.binIndexMin(), + position_binning.azimuth_binning.binIndexMax()), + blitz::Range(position_binning.longitudinal_binning.binIndexMin(), + position_binning.longitudinal_binning.binIndexMax()), + blitz::Range(energy_binning.binIndexMin(), + energy_binning.binIndexMax()))), density_per_m3_(initiate4DArray( blitz::Range(position_binning.radial_binning.binIndexMin(), position_binning.radial_binning.binIndexMax()), @@ -302,6 +320,8 @@ void DynamicDensityField::resetDynamicDensityField() { time_in_bin_s_ = 0.; deleted_particles_ = 0.; density_per_m3_ = 0.; + sync_time_in_bin_s_ = 0.; + sync_deleted_particles_ = 0.; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/simulation/logger.cpp b/src/simulation/logger.cpp index 58490bd..347cf1c 100755 --- a/src/simulation/logger.cpp +++ b/src/simulation/logger.cpp @@ -3,6 +3,7 @@ DeletionLogger::DeletionLogger(std::vector used_types) { for (auto& type : used_types) { num_deletions[type] = 0; + sync_num_deletions[type] = 0; } } @@ -35,4 +36,7 @@ void DeletionLogger::resetDeletionLogger() { for(auto& pair : num_deletions) { pair.second = 0; } + for (auto& pair : sync_num_deletions) { + pair.second = 0; + } } diff --git a/src/simulation/simulation.cpp b/src/simulation/simulation.cpp index 51b6f29..77f2703 100755 --- a/src/simulation/simulation.cpp +++ b/src/simulation/simulation.cpp @@ -164,18 +164,15 @@ void Simulation::start() { timer_->increaseTimestep(delta_t); for(auto& pair : tracked_species_) { pair.second->dynamicDensityField()->resetDynamicDensityField(); - pair.second->lastSyncDensityField()->resetDynamicDensityField(); // questionable if they need to be reset: // + time res in current // - ions very slow -> very unlikely that an ion crosses a boundary pair.second->currentCollector()->resetCurrentCollector(); - pair.second->lastSyncCurrentCollector()->resetCurrentCollector(); // do not need to be reset, since the time resolution considers the same // set of particles // pair.second->deletionLogger()->resetDeletionLogger(); - // pair.second->lastSyncDeletionLogger()->resetDeletionLogger(); } leftover_events_time_resolution = time_resolution_this_cpu; } @@ -277,6 +274,10 @@ void Simulation::processUntilTermination( &particle)) { DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name() + ". Reached timeresolution."); + if(particle.specie()->deletionLogger()) { + particle.specie()->deletionLogger()->logDeletion(particle.position(), + DeletionType::max_time_alive); + } break; } else if (particle.specie()->terminator()->leftSimulationDomain( &particle)) { diff --git a/src/simulation/species.cpp b/src/simulation/species.cpp index c8dd8f4..76a878f 100755 --- a/src/simulation/species.cpp +++ b/src/simulation/species.cpp @@ -42,7 +42,7 @@ TrackedSpecie::TrackedSpecie( std::shared_ptr density_field, std::shared_ptr velocity_distribution, std::shared_ptr drift_velocity, - std::shared_ptr last_sync_density_field, + // std::shared_ptr last_sync_density_field, std::shared_ptr density_for_drawing) : Specie(type, name, mass_kg, charge_C), mover_(mover), @@ -53,9 +53,6 @@ TrackedSpecie::TrackedSpecie( current_collector_(std::shared_ptr(nullptr)), velocity_distribution_(velocity_distribution), drift_velocity_(drift_velocity), - last_sync_density_field_(last_sync_density_field), - last_sync_deletion_logger_(std::shared_ptr(nullptr)), - last_sync_current_collector_(std::shared_ptr(nullptr)), density_for_drawing_(density_for_drawing) {} DensityField* TrackedSpecie::densityField() { @@ -73,10 +70,6 @@ DynamicDensityField* TrackedSpecie::dynamicDensityField() { return density_field_.get(); } -DynamicDensityField* TrackedSpecie::lastSyncDensityField() { - return last_sync_density_field_.get(); -} - DynamicDensityField* TrackedSpecie::densityForDrawing() { return density_for_drawing_.get(); } @@ -97,18 +90,10 @@ DeletionLogger* TrackedSpecie::deletionLogger() { return deletion_logger_.get(); } -DeletionLogger* TrackedSpecie::lastSyncDeletionLogger() { - return last_sync_deletion_logger_.get(); -} - CurrentCollector* TrackedSpecie::currentCollector() { return current_collector_.get(); } -CurrentCollector* TrackedSpecie::lastSyncCurrentCollector() { - return last_sync_current_collector_.get(); -} - std::vector> TrackedSpecie::interactions() { return interactions_; @@ -123,20 +108,11 @@ void TrackedSpecie::deletionLogger(std::shared_ptr new_logger) { deletion_logger_ = new_logger; } -void TrackedSpecie::lastSyncDeletionLogger(std::shared_ptr new_logger) { - last_sync_deletion_logger_ = new_logger; -} - void TrackedSpecie::currentCollector( std::shared_ptr new_collector) { current_collector_ = new_collector; } -void TrackedSpecie::lastSyncCurrentCollector( - std::shared_ptr new_collector) { - last_sync_current_collector_ = new_collector; -} - BackgroundSpecie::BackgroundSpecie( ImplementedSpecies type, std::string name,