Version 2, position dependent E/B, kinetic ions, boris mover, terminator

This commit is contained in:
Jonas Kellerer
2022-10-21 10:09:19 +02:00
parent acc55cf003
commit 83fd2e5d7e
869 changed files with 1033204 additions and 3634436 deletions
+102
View File
@@ -0,0 +1,102 @@
#include "IO/hdf5_reader.h"
#include <hdf5.h>
#include <hdf5_hl.h>
#include "simulation/errors.h"
Hdf5Reader::Hdf5Reader(std::string directory, std::string filename)
: absolute_filename_((directory + "/" + filename + ".h5").c_str()) {}
Hdf5Reader::Hdf5Reader(std::string absolute_filename)
: absolute_filename_(absolute_filename) {}
blitz::Array<double, 3> Hdf5Reader::readD3Double(std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset;
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
hid_t dataspace = H5Dget_space(dataset);
if (dataset < 0) {
ERROR("The given dataset could not be opened");
}
// turn error report back onby hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
const int ndims = H5Sget_simple_extent_ndims(dataspace);
hsize_t dims[ndims];
if (ndims != 3) {
ERROR("The given dataset is not threedimensional. It has dims: " + ndims);
}
H5Sget_simple_extent_dims(dataspace, dims, NULL);
blitz::Array<double, 3> data(dims[0], dims[1], dims[2]);
H5Dread(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
data.data());
H5Dclose(dataset);
H5Fclose(file);
return data.copy();
}
blitz::Array<double, 2> Hdf5Reader::readD2Double(std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset;
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
hid_t dataspace = H5Dget_space(dataset);
if (dataset < 0) {
ERROR("The given dataset could not be opened");
}
// turn error report back onby hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
const int ndims = H5Sget_simple_extent_ndims(dataspace);
hsize_t dims[ndims];
if (ndims != 2) {
ERROR("The given dataset is not two dimensional. It has dims: " + ndims);
}
H5Sget_simple_extent_dims(dataspace, dims, NULL);
blitz::Array<double, 2> data(dims[0], dims[1]);
H5Dread(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
data.data());
H5Sclose(dataspace);
H5Dclose(dataset);
H5Fclose(file);
return data.copy();
}
blitz::Array<double, 1> Hdf5Reader::readD1Double(std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
// H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
hid_t dataspace = H5Dget_space(dataset);
if (dataset < 0) {
ERROR("The given dataset could not be opened");
}
// turn error report back onby hdf5 because of check H5Dopen2
// H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
const int ndims = H5Sget_simple_extent_ndims(dataspace);
hsize_t dims[ndims];
if (ndims != 1) {
ERROR("The given dataset is not one dimensional. It has dims: " + ndims);
}
H5Sget_simple_extent_dims(dataspace, dims, NULL);
blitz::Array<double, 1> data(dims[0]);
H5Dread(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
data.data());
H5Sclose(dataspace);
H5Dclose(dataset);
H5Fclose(file);
return data.copy();
}
+408
View File
@@ -0,0 +1,408 @@
#include "IO/hdf5_writer.h"
#include <hdf5.h>
#include <hdf5_hl.h>
#include <sys/stat.h>
#include <iostream>
#include "simulation/mpi_communication.h"
Hdf5Writer::Hdf5Writer(std::string directory, std::string filename)
: absolute_filename_((directory + "/" + filename + ".h5").c_str()) {
createFolder(directory);
createFile(absolute_filename_);
}
void Hdf5Writer::createFolder(std::string directory) {
mkdir(directory.c_str(), 0755);
}
void Hdf5Writer::createFile(std::string absolute_filename) {
if (MpiCommunication::mpi_rank == 0) {
hid_t file = H5Fcreate(absolute_filename.c_str(), H5F_ACC_TRUNC,
H5P_DEFAULT, H5P_DEFAULT);
}
}
void Hdf5Writer::write(const blitz::Array<double, 1>& data, std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
blitz::TinyVector<int, 1> size = data.extent();
int start = 0;
hid_t filespace =
H5Screate_simple(1, blitz::TinyVector<hsize_t, 1>(size).data(), NULL);
hid_t memoryspace =
H5Screate_simple(1, blitz::TinyVector<hsize_t, 1>(size).data(), NULL);
// select a part of the disc space
H5Sselect_hyperslab(filespace, H5S_SELECT_SET,
blitz::TinyVector<hsize_t, 1>(start).data(), NULL,
blitz::TinyVector<hsize_t, 1>(size).data(), NULL);
// select a part of the memory space, in this case all
H5Sselect_hyperslab(
memoryspace, H5S_SELECT_SET,
blitz::TinyVector<hsize_t, 1>(blitz::TinyVector<int, 1>(0)).data(), NULL,
blitz::TinyVector<hsize_t, 1>(size).data(), NULL);
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
H5Pset_create_intermediate_group(lcpl, 1);
// turn of error report by hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset;
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
if (dataset < 0) {
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_DOUBLE, filespace, lcpl,
H5P_DEFAULT, H5P_DEFAULT);
}
// turn error report back onby hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
data.data());
H5Dclose(dataset);
H5Pclose(lcpl);
H5Sclose(filespace);
H5Sclose(memoryspace);
H5Fclose(file);
}
void Hdf5Writer::write(const blitz::Array<double, 2>& data, std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
blitz::TinyVector<int, 2> size = data.extent();
blitz::TinyVector<int, 2> start(0, 0);
hid_t filespace =
H5Screate_simple(2, blitz::TinyVector<hsize_t, 2>(size).data(), NULL);
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
H5Pset_create_intermediate_group(lcpl, 1);
// turn of error report by hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset;
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
if (dataset < 0) {
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_DOUBLE, filespace, lcpl,
H5P_DEFAULT, H5P_DEFAULT);
}
// turn error report back onby hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
data.data());
H5Dclose(dataset);
H5Pclose(lcpl);
H5Sclose(filespace);
H5Fclose(file);
}
void Hdf5Writer::write(const blitz::Array<double, 3>& data, std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
blitz::TinyVector<int, 3> size = data.extent();
blitz::TinyVector<int, 3> start(0, 0, 0);
hid_t filespace =
H5Screate_simple(3, blitz::TinyVector<hsize_t, 3>(size).data(), NULL);
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
H5Pset_create_intermediate_group(lcpl, 1);
// turn of error report by hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset;
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
if (dataset < 0) {
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_DOUBLE, filespace, lcpl,
H5P_DEFAULT, H5P_DEFAULT);
}
// turn error report back onby hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
data.data());
H5Dclose(dataset);
H5Pclose(lcpl);
H5Sclose(filespace);
H5Fclose(file);
}
void Hdf5Writer::write(const blitz::Array<double, 4>& data, std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
blitz::TinyVector<int, 4> size = data.extent();
blitz::TinyVector<int, 4> start(0, 0, 0, 0);
hid_t filespace =
H5Screate_simple(4, blitz::TinyVector<hsize_t, 4>(size).data(), NULL);
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
H5Pset_create_intermediate_group(lcpl, 1);
// turn of error report by hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset;
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
if (dataset < 0) {
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_DOUBLE, filespace, lcpl,
H5P_DEFAULT, H5P_DEFAULT);
}
// turn error report back onby hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, filespace, H5P_DEFAULT,
data.data());
H5Dclose(dataset);
H5Pclose(lcpl);
H5Sclose(filespace);
H5Fclose(file);
}
void Hdf5Writer::write(const blitz::Array<long int, 4>& data,
std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
blitz::TinyVector<int, 4> size = data.extent();
blitz::TinyVector<int, 4> start(0, 0, 0, 0);
hid_t filespace =
H5Screate_simple(4, blitz::TinyVector<hsize_t, 4>(size).data(), NULL);
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
H5Pset_create_intermediate_group(lcpl, 1);
// turn of error report by hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset;
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
if (dataset < 0) {
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_LONG, filespace, lcpl,
H5P_DEFAULT, H5P_DEFAULT);
}
// turn error report back onby hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
H5Dwrite(dataset, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL, H5P_DEFAULT,
data.data());
H5Dclose(dataset);
H5Pclose(lcpl);
H5Sclose(filespace);
H5Fclose(file);
}
void Hdf5Writer::write(const blitz::TinyVector<double, 3>& data,
std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
int size = 3;
int start = 0;
hid_t filespace =
H5Screate_simple(1, blitz::TinyVector<hsize_t, 1>(size).data(), NULL);
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
H5Pset_create_intermediate_group(lcpl, 1);
// turn of error report by hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset;
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
if (dataset < 0) {
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_DOUBLE, filespace, lcpl,
H5P_DEFAULT, H5P_DEFAULT);
}
// turn error report back onby hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
data.data());
H5Dclose(dataset);
H5Pclose(lcpl);
H5Sclose(filespace);
H5Fclose(file);
}
void Hdf5Writer::write(const blitz::TinyVector<int, 3>& data,
std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
int size = 3;
int start = 0;
hid_t filespace =
H5Screate_simple(1, blitz::TinyVector<hsize_t, 1>(size).data(), NULL);
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
H5Pset_create_intermediate_group(lcpl, 1);
// turn of error report by hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset;
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
if (dataset < 0) {
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_INT, filespace, lcpl,
H5P_DEFAULT, H5P_DEFAULT);
}
// turn error report back onby hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data.data());
H5Dclose(dataset);
H5Pclose(lcpl);
H5Sclose(filespace);
H5Fclose(file);
}
void Hdf5Writer::write(const std::vector<double>& data, std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
int size = data.size();
int start = 0;
hid_t filespace =
H5Screate_simple(1, blitz::TinyVector<hsize_t, 1>(size).data(), NULL);
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
H5Pset_create_intermediate_group(lcpl, 1);
// turn of error report by hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset;
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
if (dataset < 0) {
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_DOUBLE, filespace, lcpl,
H5P_DEFAULT, H5P_DEFAULT);
}
// turn error report back onby hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
data.data());
H5Dclose(dataset);
H5Pclose(lcpl);
H5Sclose(filespace);
H5Fclose(file);
}
void Hdf5Writer::write(int data, std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
hsize_t scalar = 1;
hid_t filespace = H5Screate_simple(1, &scalar, NULL);
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
H5Pset_create_intermediate_group(lcpl, 1);
// turn of error report by hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset;
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
if (dataset < 0) {
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_INT, filespace, lcpl,
H5P_DEFAULT, H5P_DEFAULT);
}
// turn error report back onby hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data);
H5Dclose(dataset);
H5Pclose(lcpl);
H5Sclose(filespace);
H5Fclose(file);
}
void Hdf5Writer::write(long int data, std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
hsize_t scalar = 1;
hid_t filespace = H5Screate_simple(1, &scalar, NULL);
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
H5Pset_create_intermediate_group(lcpl, 1);
// turn of error report by hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset;
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
if (dataset < 0) {
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_LONG, filespace, lcpl,
H5P_DEFAULT, H5P_DEFAULT);
}
// turn error report back onby hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
H5Dwrite(dataset, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data);
H5Dclose(dataset);
H5Pclose(lcpl);
H5Sclose(filespace);
H5Fclose(file);
}
void Hdf5Writer::write(double data, std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
hsize_t scalar = 1;
hid_t filespace = H5Screate_simple(1, &scalar, NULL);
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
H5Pset_create_intermediate_group(lcpl, 1);
// turn of error report by hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset;
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
if (dataset < 0) {
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_DOUBLE, filespace, lcpl,
H5P_DEFAULT, H5P_DEFAULT);
}
// turn error report back onby hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data);
H5Dclose(dataset);
H5Pclose(lcpl);
H5Sclose(filespace);
H5Fclose(file);
}
void Hdf5Writer::write(const std::string& data, std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
hsize_t scalar = 1;
hid_t filespace = H5Screate_simple(1, &scalar, NULL);
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
H5Pset_create_intermediate_group(lcpl, 1);
hid_t dtype;
dtype = H5Tcreate(H5T_STRING, data.size());
// turn of error report by hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset;
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
if (dataset < 0) {
dataset = H5Dcreate2(file, path.c_str(), dtype, filespace, lcpl,
H5P_DEFAULT, H5P_DEFAULT);
}
// turn error report back onby hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
H5Dwrite(dataset, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, data.c_str());
H5Dclose(dataset);
H5Pclose(lcpl);
H5Sclose(filespace);
H5Fclose(file);
}
+267
View File
@@ -0,0 +1,267 @@
#include "IO/simulation_output.h"
#include "IO/hdf5_writer.h"
#include "generators/species_generator.h"
#include "simulation/current_collector.h"
#include "simulation/density_field.h"
#include "simulation/logger.h"
#include "simulation/mpi_communication.h"
#include "simulation/species.h"
SimulationOutput::SimulationOutput(const std::string& output_folder,
const std::string& output_filename)
: writer(Hdf5Writer(output_folder, output_filename)) {}
void SimulationOutput::addDensityFieldOutput(OutputTask task) {
tasks_density_fields_.push_back(task);
}
void SimulationOutput::addCurrentBorderOutput(OutputTask task) {
tasks_current_collector_.push_back(task);
}
void SimulationOutput::addDeletionLoggerOutput(OutputTask task) {
tasks_deletion_logger_.push_back(task);
}
void SimulationOutput::writeMetaData(
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species) {
if (MpiCommunication::mpi_rank == 0) {
for (auto& pair : species) {
writeMetaData(pair.second.get());
}
for (auto& task : tasks_density_fields_) {
std::string specie_path = "/" + task.specie_name;
writeMetaData(species.at(task.specie_name)->dynamicDensityField(),
specie_path);
}
for (auto& task : tasks_current_collector_) {
std::string specie_path = "/" + task.specie_name;
writeMetaData(species.at(task.specie_name)->currentCollector(),
specie_path);
}
}
}
void SimulationOutput::writeSimulationData(
int cpu_sync,
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species) {
if (MpiCommunication::mpi_rank == 0) {
DEBUG_LEVEL_2("Write density field data.");
for (auto& task : tasks_density_fields_) {
if (cpu_sync % task.intervall == 0) {
std::string specie_path = "/" + task.specie_name;
writeSimulationData(species.at(task.specie_name)->dynamicDensityField(),
specie_path, cpu_sync, task.overwrite_last);
}
}
DEBUG_LEVEL_2("Write current collector data.");
for (auto& task : tasks_current_collector_) {
if (cpu_sync % task.intervall == 0) {
std::string specie_path = "/" + task.specie_name;
writeSimulationData(species.at(task.specie_name)->currentCollector(),
specie_path, cpu_sync, task.overwrite_last);
}
}
DEBUG_LEVEL_2("Write deletion logger data.");
for (auto& task : tasks_deletion_logger_) {
if (cpu_sync % task.intervall == 0) {
std::string specie_path = "/" + task.specie_name;
writeSimulationData(species.at(task.specie_name)->deletionLogger(),
specie_path, cpu_sync, task.overwrite_last);
}
}
}
}
void SimulationOutput::writeSimulationData(DynamicDensityField* density_field,
std::string species_path,
int cpu_sync,
bool overwrite_last) {
std::string sync_path = "SyncPeriod_" + std::to_string(cpu_sync);
if (overwrite_last) {
sync_path = "LastSyncPeriod";
}
std::string path = species_path + "/DensityField/SimulationData/" + sync_path;
DEBUG_LEVEL_3("Write spectrum.");
writeSpectrum(density_field, path);
DEBUG_LEVEL_3("Write density.");
writeDensity(density_field, path);
DEBUG_LEVEL_3("Write time in bin.");
writeTimeInBin(density_field, path);
DEBUG_LEVEL_3("Write deleted particles.");
writeDeletedParticles(density_field, path);
DEBUG_LEVEL_3("Write physical time.");
writePhysicalTime(density_field, path);
}
void SimulationOutput::writeSimulationData(CurrentCollector* current_collector,
std::string species_path,
int cpu_sync,
bool overwrite_last) {
std::string sync_path = "SyncPeriod_" + std::to_string(cpu_sync);
if (overwrite_last) {
sync_path = "LastSyncPeriod";
}
std::string path =
species_path + "/CurrentCollector/SimulationData/" + sync_path;
DEBUG_LEVEL_3("Write current crossings.");
writeCurrentCrossings(current_collector, path);
DEBUG_LEVEL_3("Write current.");
writeCurrent(current_collector, path);
DEBUG_LEVEL_3("Write physical time.");
writePhysicalTime(current_collector, path);
}
void SimulationOutput::writeSimulationData(DeletionLogger* logger,
std::string species_path,
int cpu_sync,
bool overwrite_last) {
std::string sync_path = "SyncPeriod_" + std::to_string(cpu_sync);
if (overwrite_last) {
sync_path = "LastSyncPeriod";
}
std::string path = species_path + "/DeletionLogger/" + sync_path;
DEBUG_LEVEL_3("Write number of deletions.");
writeNumDeletions(logger, path);
}
void SimulationOutput::writeNumDeletions(DeletionLogger* logger,
std::string path) {
std::string path_to_deletions = path + "/NumDeletions";
auto deletions = logger->numDeletions();
for (auto& pair : deletions) {
if (pair.first == DeletionType::wall) {
writer.write(pair.second, path_to_deletions + "/Wall");
} else if (pair.first == DeletionType::recombination) {
writer.write(pair.second, path_to_deletions + "/Recombination");
} else if (pair.first == DeletionType::max_interactions) {
writer.write(pair.second, path_to_deletions + "/MaxInteractions");
} else if (pair.first == DeletionType::max_time_alive) {
writer.write(pair.second, path_to_deletions + "/MaxTimeAlive");
}
}
}
void SimulationOutput::writeCurrentCrossings(
CurrentCollector* current_collector,
std::string path) {
writer.write(current_collector->positiveCrossingsInR(),
path + "/PositiveCrossingsInR");
writer.write(current_collector->negativeCrossingsInR(),
path + "/NegativeCrossingsInR");
writer.write(current_collector->positiveCrossingsInPhi(),
path + "/PositiveCrossingsInPhi");
writer.write(current_collector->negativeCrossingsInPhi(),
path + "/NegativeCrossingsInPhi");
writer.write(current_collector->positiveCrossingsInZ(),
path + "/PositiveCrossingsInZ");
writer.write(current_collector->negativeCrossingsInZ(),
path + "/NegativeCrossingsInZ");
}
void SimulationOutput::writeCurrent(CurrentCollector* current_collector,
std::string path) {
writer.write(current_collector->currentInR(), path + "/CurrentInR");
writer.write(current_collector->currentInPhi(), path + "/CurrentInPhi");
writer.write(current_collector->currentInZ(), path + "/CurrentInZ");
}
void SimulationOutput::writePhysicalTime(CurrentCollector* current_collector,
std::string path) {
writer.write(current_collector->physicalTime(), path + "/PhysicalTime");
}
void SimulationOutput::writeSpectrum(DynamicDensityField* density_field,
std::string path) {
writer.write(density_field->spectrumArray(), path + "/Spectrum");
}
void SimulationOutput::writeDensity(DynamicDensityField* density_field,
std::string path) {
writer.write(density_field->densityArray(), path + "/Density");
}
void SimulationOutput::writeTimeInBin(DynamicDensityField* density_field,
std::string path) {
writer.write(density_field->timeInBinArray(), path + "/TimeInBin");
}
void SimulationOutput::writeDeletedParticles(DynamicDensityField* density_field,
std::string path) {
writer.write(density_field->deletedParticlesArray(),
path + "/DeletedParticles");
}
void SimulationOutput::writePhysicalTime(DynamicDensityField* density_field,
std::string path) {
writer.write(density_field->physicalTime(), path + "/PhysicalTime");
}
void SimulationOutput::writeMetaData(species::TrackedSpecie* specie) {
std::string specie_path = "/" + specie->name();
writer.write(specie->mass_kg(), specie_path + "/Mass");
writer.write(specie->charge_C(), specie_path + "/Charge");
}
void SimulationOutput::writeMetaData(DynamicDensityField* density_field,
std::string path) {
std::string path_to_field = path + "/DensityField";
writeBinVolumes(density_field, path_to_field);
writeBinBorders(density_field, path_to_field);
writeNumBins(density_field, path_to_field);
}
void SimulationOutput::writeMetaData(CurrentCollector* current_collector,
std::string path) {
std::string path_to_collector = path + "/CurrentCollector";
writeCollectorAreas(current_collector, path_to_collector);
}
void SimulationOutput::writeCollectorAreas(CurrentCollector* current_collector,
std::string path) {
writer.write(current_collector->areaInR(), path + "/AreaInR");
writer.write(current_collector->areaInPhi(), path + "/AreaInPhi");
writer.write(current_collector->areaInZ(), path + "/AreaInZ");
}
void SimulationOutput::writeBinVolumes(DynamicDensityField* density_field,
std::string path_to_field) {
std::string path_to_volume = path_to_field + "/BinVolumes";
writer.write(density_field->binVolumeArray(), path_to_volume);
}
void SimulationOutput::writeNumBins(DynamicDensityField* density_field,
std::string path_to_field) {
std::string path_to_num_bins = path_to_field + "/NumBins";
blitz::TinyVector<double, 4> num_bins = density_field->spectrumArray().size();
writer.write(num_bins(0), path_to_num_bins + "/energy");
writer.write(num_bins(1), path_to_num_bins + "/radial");
writer.write(num_bins(2), path_to_num_bins + "/azimuthal");
writer.write(num_bins(3), path_to_num_bins + "/longitudinal");
}
void SimulationOutput::writeBinBorders(DynamicDensityField* density_field,
std::string path_to_field) {
std::string path_to_bin_borders = path_to_field + "/BinBorders";
std::vector<double> energy_bin_borders =
density_field->energyBinning()->binBorders();
writer.write(energy_bin_borders, path_to_bin_borders + "/energy");
std::vector<double> radial_bin_borders =
density_field->positionBinning()->radial_binning.binBorders();
writer.write(radial_bin_borders, path_to_bin_borders + "/radial");
std::vector<double> azimuth_bin_borders =
density_field->positionBinning()->azimuth_binning.binBorders();
writer.write(azimuth_bin_borders, path_to_bin_borders + "/azimuth");
std::vector<double> longitudinal_bin_borders =
density_field->positionBinning()->longitudinal_binning.binBorders();
writer.write(longitudinal_bin_borders, path_to_bin_borders + "/longitudinal");
}