restructured fields for cpu sync;

no longer whole object in species but additional
fields in the corresponding classes
This commit is contained in:
2024-08-13 15:00:13 +02:00
parent 9dda12b60a
commit 2e5923ab6f
12 changed files with 93 additions and 106 deletions
+1 -18
View File
@@ -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<DeletionLogger>(*deletion_logger));
}
}
+31 -38
View File
@@ -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());
}
}
+16 -1
View File
@@ -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<double, 3> 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.;
}
+20
View File
@@ -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<double>(
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<long int>(
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<long int>(
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<double>(
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.;
}
////////////////////////////////////////////////////////////////////////////////
+4
View File
@@ -3,6 +3,7 @@
DeletionLogger::DeletionLogger(std::vector<DeletionType> 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;
}
}
+4 -3
View File
@@ -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)) {
+1 -25
View File
@@ -42,7 +42,7 @@ TrackedSpecie::TrackedSpecie(
std::shared_ptr<DynamicDensityField> density_field,
std::shared_ptr<VelocityDistribution> velocity_distribution,
std::shared_ptr<DriftVelocity> drift_velocity,
std::shared_ptr<DynamicDensityField> last_sync_density_field,
// std::shared_ptr<DynamicDensityField> last_sync_density_field,
std::shared_ptr<DynamicDensityField> density_for_drawing)
: Specie(type, name, mass_kg, charge_C),
mover_(mover),
@@ -53,9 +53,6 @@ TrackedSpecie::TrackedSpecie(
current_collector_(std::shared_ptr<CurrentCollector>(nullptr)),
velocity_distribution_(velocity_distribution),
drift_velocity_(drift_velocity),
last_sync_density_field_(last_sync_density_field),
last_sync_deletion_logger_(std::shared_ptr<DeletionLogger>(nullptr)),
last_sync_current_collector_(std::shared_ptr<CurrentCollector>(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<std::shared_ptr<interaction::Interaction>>
TrackedSpecie::interactions() {
return interactions_;
@@ -123,20 +108,11 @@ void TrackedSpecie::deletionLogger(std::shared_ptr<DeletionLogger> new_logger) {
deletion_logger_ = new_logger;
}
void TrackedSpecie::lastSyncDeletionLogger(std::shared_ptr<DeletionLogger> new_logger) {
last_sync_deletion_logger_ = new_logger;
}
void TrackedSpecie::currentCollector(
std::shared_ptr<CurrentCollector> new_collector) {
current_collector_ = new_collector;
}
void TrackedSpecie::lastSyncCurrentCollector(
std::shared_ptr<CurrentCollector> new_collector) {
last_sync_current_collector_ = new_collector;
}
BackgroundSpecie::BackgroundSpecie(
ImplementedSpecies type,
std::string name,