Files
karl/include/IO/simulation_output.h
2024-12-04 17:15:04 +01:00

163 lines
7.3 KiB
C++
Executable File

#ifndef SIMULATION_OUTPUT_H
#define SIMULATION_OUTPUT_H
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "IO/hdf5_writer.h"
// defined in "simulation/density_field.h"
class DynamicDensityField;
//class CurrentBorder;
// defined in "simulation/parameter.h"
class Parameter;
// defined in "simulation/current_collector.h"
class CurrentCollector;
// defined in "simulation/logger.h"
class DeletionLogger;
// defined in "simulation/species.h"
namespace species {
class TrackedSpecie;
enum class ImplementedSpecies;
}; // namespace species
// structure to store information about output types
struct OutputTask {
// name of the particle species that output should be performed for
std::string specie_name;
// if true earlier output is overwritten
bool overwrite_last;
// how many cpu synchronization steps are inbetween two output steps
int intervall;
// selector if each or only first cpu should write can be added here
};
// class to handle output from the simulation
class SimulationOutput {
public:
// Constructor: takes the name of the output directory and
// the name of the output file (".h5" appended by default)
// directory is created if it does not exist
SimulationOutput(const std::string& output_folder,
const std::string& output_filename);
// add OutputTask for the output of the (dynamic) density field
void addDensityFieldOutput(OutputTask task);
// add OutputTask for the output of the current collector
void addCurrentBorderOutput(OutputTask task);
// add OutputTask for the output of the deletion logger
void addDeletionLoggerOutput(OutputTask task);
// write data that is initialized once at the beginning of the simulation
// for all TrackedSpecies (mass (kg), charge (C), bin volumes, bin borders, number of bins
// bin areas)
void writeMetaData(
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species);
// write data that changes during the simulation, output intervalls are defined
// wrt the number of cpu synchronization steps cpu_sync
void writeSimulationData(
int cpu_sync,
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species);
private:
std::vector<OutputTask> tasks_density_fields_;
std::vector<OutputTask> tasks_current_collector_;
std::vector<OutputTask> tasks_deletion_logger_;
Hdf5Writer writer;
// function for writing simulated data in the dynamic density field
// takes the path to the hdf group of the specie the dynamic density field is defined for
// takes the number of cpu synchronization steps that have been performed
// takes whether earlier output should be overwritten
void writeSimulationData(DynamicDensityField* density_field,
std::string species_path,
int cpu_sync,
bool overwrite_last);
// write the 4d density array of the dynamic density field
// in the hdf group defined by string (has to be a total hdf path)
void writeSpectrum(DynamicDensityField* density_field, std::string path);
// write the 3d density array of the dynamic density field
// in the hdf group defined by string (has to be a total hdf path)
void writeDensity(DynamicDensityField* density_field, std::string path);
// write the 4d time in bin array (i.e. the raw data) of the dynamic density field
// in the hdf group defined by string (has to be a total hdf path)
void writeTimeInBin(DynamicDensityField* density_field, std::string path);
// write the 4d density array of the deleted particles array
// in the hdf group defined by string (has to be a total hdf path)
void writeDeletedParticles(DynamicDensityField* density_field,
std::string path);
// write the time of the Timer member object
// in the hdf group defined by string (has to be a total hdf path)
void writePhysicalTime(DynamicDensityField* density_field, std::string path);
// function for writing simulated data in the current collector
// takes the path to the hdf group of the specie the dynamic density field is defined for
// takes the number of cpu synchronization steps that have been performed
// takes whether earlier output should be overwritten
void writeSimulationData(CurrentCollector* current_collector,
std::string species_path,
int cpu_sync,
bool overwrite_last);
// write all positive and negative crossing arrays (i.e. raw data)
// in the hdf group defined by string (has to be a total hdf path)
void writeCurrentCrossings(CurrentCollector* current_collector,
std::string path);
// write all physical particle current arrays (i.e. raw data)
// in the hdf group defined by string (has to be a total hdf path)
void writeCurrent(CurrentCollector* current_collector, std::string path);
// write the time of the Timer member object
// in the hdf group defined by string (has to be a total hdf path)
void writePhysicalTime(CurrentCollector* current_collector, std::string path);
// function for writing simulated data in the deletion logger
// takes the path to the hdf group of the specie the dynamic density field is defined for
// takes the number of cpu synchronization steps that have been performed
// takes whether earlier output should be overwritten
void writeSimulationData(DeletionLogger* logger,
std::string species_path,
int cpu_sync,
bool overwrite_last);
// write the deletion trakced by the DeletionLogger
// in the hdf group defined by string (has to be a total hdf path)
void writeNumDeletions(DeletionLogger* logger, std::string path);
// write the not simulated aspects of the TrackedSpecie
// (mass (kg), charge (C))
// in the hdf group defined by string (has to be a total hdf path)
void writeMetaData(species::TrackedSpecie* specie);
// write the not simulated aspects of the DynamicDensityField
// (bin volumes, bin borders)
// in the hdf group defined by string (has to be a total hdf path)
void writeMetaData(DynamicDensityField* density_field, std::string path);
// write the not simulated aspects of the CurrentCollector
// (bin areas)
// in the hdf group defined by string (has to be a total hdf path)
void writeMetaData(CurrentCollector* current_collector, std::string path);
// void writeParameterFile(Parameter* parameter);
// write the areas of the bins used by the current collector
// in the hdf group defined by string (has to be a total hdf path)
void writeCollectorAreas(CurrentCollector* current_collector,
std::string path);
// write the volumes of the bins used by the dynamic density field
// in the hdf group defined by string (has to be a total hdf path)
void writeBinVolumes(DynamicDensityField* density_field,
std::string path_to_field);
// write the number of bins used by the dynamic density field
// in the hdf group defined by string (has to be a total hdf path)
void writeNumBins(DynamicDensityField* density_field,
std::string path_to_field);
// write the borders of the bins used by the dynamic density field
// in the hdf group defined by string (has to be a total hdf path)
void writeBinBorders(DynamicDensityField* density_field,
std::string path_to_field);
};
#endif /* SIMULATION_OUTPUT_H */