Added counting of physical losses at a wall
to deletion logger
This commit is contained in:
@@ -3,8 +3,9 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "simulation/coordinates.h"
|
#include "simulation/particle.h"
|
||||||
|
|
||||||
|
// to count numerical particle deletions
|
||||||
enum class DeletionType {
|
enum class DeletionType {
|
||||||
wall,
|
wall,
|
||||||
recombination,
|
recombination,
|
||||||
@@ -13,13 +14,23 @@ enum class DeletionType {
|
|||||||
cluster_formation
|
cluster_formation
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// to count physical particle deletion
|
||||||
|
enum class PhysicalDeletionType {
|
||||||
|
wall
|
||||||
|
};
|
||||||
|
class Coordinate;
|
||||||
|
|
||||||
class DeletionLogger {
|
class DeletionLogger {
|
||||||
public:
|
public:
|
||||||
DeletionLogger(std::vector<DeletionType> used_types);
|
DeletionLogger(std::vector<DeletionType> used_types,
|
||||||
|
std::vector<PhysicalDeletionType> used_phys_types);
|
||||||
// why a coordinate as a parameter -> not used in implementation
|
// why a coordinate as a parameter -> not used in implementation
|
||||||
virtual void logDeletion(const Coordinate& coordinate, DeletionType type);
|
virtual void logDeletion(const Coordinate& coordinate, DeletionType type);
|
||||||
|
virtual void logDeletion(const particle::Particle& particle,
|
||||||
|
PhysicalDeletionType type);
|
||||||
|
|
||||||
std::map<DeletionType, long int> numDeletions() const;
|
std::map<DeletionType, long int> numDeletions() const;
|
||||||
|
std::map<PhysicalDeletionType, double> numPhysDeletions() const;
|
||||||
void numDeletions(long int new_value, DeletionType type);
|
void numDeletions(long int new_value, DeletionType type);
|
||||||
long int numDeletions(DeletionType type) const;
|
long int numDeletions(DeletionType type) const;
|
||||||
|
|
||||||
@@ -30,6 +41,10 @@ class DeletionLogger {
|
|||||||
private:
|
private:
|
||||||
std::map<DeletionType, long int> num_deletions;
|
std::map<DeletionType, long int> num_deletions;
|
||||||
std::map<DeletionType, long int> sync_num_deletions;
|
std::map<DeletionType, long int> sync_num_deletions;
|
||||||
|
|
||||||
|
std::map<PhysicalDeletionType, double> num_phys_deletions;
|
||||||
|
std::map<PhysicalDeletionType, double> sync_num_phys_deletions;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* LOGGER_H */
|
#endif /* LOGGER_H */
|
||||||
|
|||||||
@@ -244,6 +244,13 @@ void SimulationOutput::writeNumDeletions(DeletionLogger* logger,
|
|||||||
writer.write(pair.second, path_to_deletions + "/ClusterFormation");
|
writer.write(pair.second, path_to_deletions + "/ClusterFormation");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto physDeletions = logger->numPhysDeletions();
|
||||||
|
for (auto& pair : physDeletions) {
|
||||||
|
if (pair.first == PhysicalDeletionType::wall) {
|
||||||
|
writer.write(pair.second, path_to_deletions + "/Wall(physical)");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulationOutput::writeCurrentCrossings(
|
void SimulationOutput::writeCurrentCrossings(
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ namespace generator {
|
|||||||
|
|
||||||
std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
|
std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
|
||||||
std::vector<DeletionType> used_types;
|
std::vector<DeletionType> used_types;
|
||||||
|
std::vector<PhysicalDeletionType> used_phys_types;
|
||||||
|
|
||||||
json_t* type = json_object_by_path(object, {"Type"});
|
json_t* type = json_object_by_path(object, {"Type"});
|
||||||
if (json_is_array(type)) {
|
if (json_is_array(type)) {
|
||||||
@@ -24,7 +25,9 @@ std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
|
|||||||
used_types.push_back(DeletionType::max_time_alive);
|
used_types.push_back(DeletionType::max_time_alive);
|
||||||
} else if (type_alias == "cluster_formation") {
|
} else if (type_alias == "cluster_formation") {
|
||||||
used_types.push_back(DeletionType::cluster_formation);
|
used_types.push_back(DeletionType::cluster_formation);
|
||||||
} else {
|
} else if (type_alias == "wall_physical") {
|
||||||
|
used_phys_types.push_back(PhysicalDeletionType::wall);
|
||||||
|
}else {
|
||||||
ERROR("This deletion type " + type_alias + " is not known.");
|
ERROR("This deletion type " + type_alias + " is not known.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,10 +38,11 @@ std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
|
|||||||
used_types.push_back(DeletionType::max_interactions);
|
used_types.push_back(DeletionType::max_interactions);
|
||||||
used_types.push_back(DeletionType::max_time_alive);
|
used_types.push_back(DeletionType::max_time_alive);
|
||||||
used_types.push_back(DeletionType::cluster_formation);
|
used_types.push_back(DeletionType::cluster_formation);
|
||||||
|
used_phys_types.push_back(PhysicalDeletionType::wall);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_shared<DeletionLogger>(used_types);
|
return std::make_shared<DeletionLogger>(used_types, used_phys_types);
|
||||||
}
|
}
|
||||||
std::shared_ptr<DeletionLogger> buildDeletionLogger(
|
std::shared_ptr<DeletionLogger> buildDeletionLogger(
|
||||||
Parameter& parameter,
|
Parameter& parameter,
|
||||||
|
|||||||
@@ -145,6 +145,15 @@ void CpuSynchronizer::synchronize(DeletionLogger* logger) {
|
|||||||
pair.second = last_sync_num_deletion;
|
pair.second = last_sync_num_deletion;
|
||||||
logger->sync_num_deletions[pair.first] = last_sync_num_deletion;
|
logger->sync_num_deletions[pair.first] = last_sync_num_deletion;
|
||||||
}
|
}
|
||||||
|
for (auto& pair : logger->num_phys_deletions) {
|
||||||
|
double num_deletion = pair.second;
|
||||||
|
double last_sync_num_deletion = logger->sync_num_phys_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;
|
||||||
|
logger->sync_num_phys_deletions[pair.first] = last_sync_num_deletion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
#include "simulation/logger.h"
|
#include "simulation/logger.h"
|
||||||
|
#include "simulation/coordinates.h"
|
||||||
|
|
||||||
DeletionLogger::DeletionLogger(std::vector<DeletionType> used_types) {
|
DeletionLogger::DeletionLogger(std::vector<DeletionType> used_types,
|
||||||
|
std::vector<PhysicalDeletionType> used_phys_types) {
|
||||||
for (auto& type : used_types) {
|
for (auto& type : used_types) {
|
||||||
num_deletions[type] = 0;
|
num_deletions[type] = 0;
|
||||||
sync_num_deletions[type] = 0;
|
sync_num_deletions[type] = 0;
|
||||||
}
|
}
|
||||||
|
for (auto& type: used_phys_types) {
|
||||||
|
num_phys_deletions[type] = 0.;
|
||||||
|
sync_num_phys_deletions[type] = 0.;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeletionLogger::logDeletion(const Coordinate& coordinate,
|
void DeletionLogger::logDeletion(const Coordinate& coordinate,
|
||||||
@@ -14,10 +20,21 @@ void DeletionLogger::logDeletion(const Coordinate& coordinate,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeletionLogger::logDeletion(const particle::Particle& particle,
|
||||||
|
PhysicalDeletionType type) {
|
||||||
|
if (num_phys_deletions.count(type) > 0) {
|
||||||
|
num_phys_deletions.at(type) += particle.weight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::map<DeletionType, long int> DeletionLogger::numDeletions() const {
|
std::map<DeletionType, long int> DeletionLogger::numDeletions() const {
|
||||||
return num_deletions;
|
return num_deletions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<PhysicalDeletionType, double> DeletionLogger::numPhysDeletions() const {
|
||||||
|
return num_phys_deletions;
|
||||||
|
}
|
||||||
|
|
||||||
void DeletionLogger::numDeletions(long int new_value, DeletionType type) {
|
void DeletionLogger::numDeletions(long int new_value, DeletionType type) {
|
||||||
if (num_deletions.count(type)) {
|
if (num_deletions.count(type)) {
|
||||||
num_deletions.at(type) = new_value;
|
num_deletions.at(type) = new_value;
|
||||||
@@ -39,4 +56,10 @@ void DeletionLogger::resetDeletionLogger() {
|
|||||||
for (auto& pair : sync_num_deletions) {
|
for (auto& pair : sync_num_deletions) {
|
||||||
pair.second = 0;
|
pair.second = 0;
|
||||||
}
|
}
|
||||||
|
for(auto& pair : num_phys_deletions) {
|
||||||
|
pair.second = 0;
|
||||||
|
}
|
||||||
|
for (auto& pair : sync_num_phys_deletions) {
|
||||||
|
pair.second = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -530,6 +530,8 @@ void Simulation::processUntilTermination(
|
|||||||
if (particle.specie()->deletionLogger()) {
|
if (particle.specie()->deletionLogger()) {
|
||||||
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
|
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
|
||||||
DeletionType::wall);
|
DeletionType::wall);
|
||||||
|
particle.specie()->deletionLogger()->logDeletion(particle,
|
||||||
|
PhysicalDeletionType::wall);
|
||||||
}
|
}
|
||||||
#ifdef debug
|
#ifdef debug
|
||||||
if(particle.specie()->type() == species::ImplementedSpecies::Tplus) {
|
if(particle.specie()->type() == species::ImplementedSpecies::Tplus) {
|
||||||
|
|||||||
Reference in New Issue
Block a user