restructured fields for cpu sync;
no longer whole object in species but additional fields in the corresponding classes
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
|
||||
@@ -67,6 +67,15 @@ class CurrentCollector {
|
||||
blitz::Array<double, 3> r_negative_crossings;
|
||||
blitz::Array<double, 3> r_positive_crossings;
|
||||
|
||||
blitz::Array<double, 3> sync_z_negative_crossings;
|
||||
blitz::Array<double, 3> sync_z_positive_crossings;
|
||||
|
||||
blitz::Array<double, 3> sync_phi_negative_crossings;
|
||||
blitz::Array<double, 3> sync_phi_positive_crossings;
|
||||
|
||||
blitz::Array<double, 3> sync_r_negative_crossings;
|
||||
blitz::Array<double, 3> sync_r_positive_crossings;
|
||||
|
||||
blitz::Array<double, 3> collector_areas_r;
|
||||
blitz::Array<double, 3> collector_areas_phi;
|
||||
blitz::Array<double, 3> collector_areas_z;
|
||||
|
||||
@@ -80,6 +80,10 @@ class DynamicDensityField : public DensityField {
|
||||
|
||||
blitz::Array<double, 4> time_in_bin_s_;
|
||||
blitz::Array<long int, 4> deleted_particles_;
|
||||
|
||||
blitz::Array<double, 4> sync_time_in_bin_s_;
|
||||
blitz::Array<long int, 4> sync_deleted_particles_;
|
||||
|
||||
blitz::Array<double, 4> density_per_m3_;
|
||||
blitz::Array<double, 3> bin_volume_m3_;
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ class DeletionLogger {
|
||||
|
||||
private:
|
||||
std::map<DeletionType, long int> num_deletions;
|
||||
std::map<DeletionType, long int> sync_num_deletions;
|
||||
};
|
||||
|
||||
#endif /* LOGGER_H */
|
||||
|
||||
@@ -62,7 +62,6 @@ class TrackedSpecie : public Specie {
|
||||
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> 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<DeletionLogger> new_logger);
|
||||
|
||||
DeletionLogger* lastSyncDeletionLogger();
|
||||
void lastSyncDeletionLogger(std::shared_ptr<DeletionLogger> new_logger);
|
||||
|
||||
DynamicDensityField* densityForDrawing();
|
||||
|
||||
CurrentCollector* currentCollector();
|
||||
void currentCollector(std::shared_ptr<CurrentCollector> new_collector);
|
||||
|
||||
CurrentCollector* lastSyncCurrentCollector();
|
||||
void lastSyncCurrentCollector(
|
||||
std::shared_ptr<CurrentCollector> new_collector);
|
||||
|
||||
std::vector<std::shared_ptr<interaction::Interaction>> interactions();
|
||||
void addInteraction(std::shared_ptr<interaction::Interaction> interaction);
|
||||
|
||||
@@ -106,13 +97,6 @@ class TrackedSpecie : public Specie {
|
||||
std::shared_ptr<CurrentCollector> current_collector_;
|
||||
std::vector<std::shared_ptr<interaction::Interaction>> 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<DynamicDensityField> last_sync_density_field_;
|
||||
std::shared_ptr<DeletionLogger> last_sync_deletion_logger_;
|
||||
std::shared_ptr<CurrentCollector> last_sync_current_collector_;
|
||||
|
||||
std::shared_ptr<DynamicDensityField> density_for_drawing_;
|
||||
};
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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.;
|
||||
}
|
||||
@@ -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.;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user