Implemented pitch angle resolution.

Still includes (and uses) the non-pitch angle
resolved fields as well; have to be either removed
completely or refactored s.t. one of the two options
is chosen.
Pitch angle distribution has a hardcoded number of
bins for now, and exists in 'energy_binning.h'
This commit is contained in:
2024-10-28 15:00:19 +01:00
parent b4cbd8c44c
commit 5fc227e1b1
24 changed files with 1126 additions and 42 deletions
+59
View File
@@ -162,6 +162,36 @@ blitz::Array<double, 4> Hdf5Reader::readD4Double(std::string path) {
return data.copy();
}
blitz::Array<double, 5> Hdf5Reader::readD5Double(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 != 5) {
ERROR("The given dataset is not five-dimensional. It has dims: " + ndims);
}
H5Sget_simple_extent_dims(dataspace, dims, NULL);
blitz::Array<double, 5> data(dims[0], dims[1], dims[2], dims[3], dims[4]);
H5Dread(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
data.data());
H5Dclose(dataset);
H5Fclose(file);
return data.copy();
}
blitz::Array<long int, 4> Hdf5Reader::readD4LongInt(std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
@@ -192,6 +222,35 @@ blitz::Array<long int, 4> Hdf5Reader::readD4LongInt(std::string path) {
return data.copy();
}
blitz::Array<long int, 5> Hdf5Reader::readD5LongInt(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 != 5) {
ERROR("The given dataset is not five-dimensional. It has dims: " + ndims);
}
H5Sget_simple_extent_dims(dataspace, dims, NULL);
blitz::Array<long int, 5> data(dims[0], dims[1], dims[2], dims[3], dims[4]);
H5Dread(dataset, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL, H5P_DEFAULT,
data.data());
H5Dclose(dataset);
H5Fclose(file);
return data.copy();
}
// reads the engine stringstream with the correct size from the file, such that it should be able
// to be used for the initialization of the random engine without any further modification
+65
View File
@@ -165,6 +165,38 @@ void Hdf5Writer::write(const blitz::Array<double, 4>& data, std::string path) {
H5Fclose(file);
}
void Hdf5Writer::write(const blitz::Array<double, 5>& data, std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
blitz::TinyVector<int, 5> size = data.extent();
blitz::TinyVector<int, 5> start(0, 0, 0, 0, 0);
hid_t filespace =
H5Screate_simple(5, blitz::TinyVector<hsize_t, 5>(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);
@@ -198,6 +230,39 @@ void Hdf5Writer::write(const blitz::Array<long int, 4>& data,
H5Fclose(file);
}
void Hdf5Writer::write(const blitz::Array<long int, 5>& data,
std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
blitz::TinyVector<int, 5> size = data.extent();
blitz::TinyVector<int, 5> start(0, 0, 0, 0, 0);
hid_t filespace =
H5Screate_simple(5, blitz::TinyVector<hsize_t, 5>(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);
+37 -3
View File
@@ -35,9 +35,19 @@ void Restart::restart(std::map<std::string, std::shared_ptr<species::TrackedSpec
restartTimer(species.begin()->second.get());
for(const auto& pair: species) {
std::string path = pair.second->name() + "/DensityField/SimulationData/" +
restart_identifier_;
restartDrawingDensityField(pair.second->densityForDrawing(), path);
{
std::string path = pair.second->name() + "/DensityField/SimulationData/" +
restart_identifier_;
restartDrawingDensityField(pair.second->densityForDrawing(), path);
}
{
std::string path = pair.second->name() +
"/DensityFieldWithPitchAngle/SimulationData/" +
restart_identifier_;
restartDrawingDensityField(pair.second->dynamicDensityFieldWithPitchAngleForDrawing(),
path);
}
}
}
@@ -121,6 +131,30 @@ void Restart::restartDrawingDensityField(DynamicDensityField* field, std::string
return;
}
void Restart::restartDrawingDensityField(DynamicDensityFieldWithPitchAngle* field, std::string path) {
// restart TimeInBin field
{
std::string path_to_data = path + "/TimeInBin";
DEBUG_LEVEL_3(path_to_data);
blitz::Array<double, 5> time_in_bin = reader_.readD5Double(path_to_data);
field->restartTimeInBin(time_in_bin);
}
// restart deleted particles
{
std::string path_to_data = path + "/DeletedParticles";
DEBUG_LEVEL_3(path_to_data);
blitz::Array<long int, 5> deleted_particles = reader_.readD5LongInt(path_to_data);
field->restartDeletedParticlesArray(deleted_particles);
}
// set the density distribution and calculate the density
{
field->setDensityDistribution();
}
return;
}
// could be removed, but then the potential has to be calculated
// as in the normal simulation cycle
void Restart::restartPoissonSolver(PoissonSolver* solver) {
+107 -3
View File
@@ -46,6 +46,8 @@ void SimulationOutput::writeMetaData(
std::string specie_path = "/" + task.specie_name;
writeMetaData(species.at(task.specie_name)->dynamicDensityField(),
specie_path);
writeMetaData(species.at(task.specie_name)->dynamicDensityFieldWithPitchAngle(),
specie_path);
}
for (auto& task : tasks_current_collector_) {
@@ -60,6 +62,7 @@ void SimulationOutput::writeMetaData(
}
}
}
void SimulationOutput::writeSimulationData(
int cpu_sync,
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
@@ -70,6 +73,8 @@ void SimulationOutput::writeSimulationData(
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)->dynamicDensityFieldWithPitchAngle(),
specie_path, cpu_sync, task.overwrite_last);
writeSimulationData(species.at(task.specie_name)->dynamicDensityField(),
specie_path, cpu_sync, task.overwrite_last);
}
@@ -99,7 +104,7 @@ void SimulationOutput::writeSimulationData(
}
// if the rng intervall = 0 (no neg. intervalls allowed) -> no output,
// otherwise the intervall used the same as for the other output
// otherwise the intervall used the same as for the other outputs
if((task_rng_.intervall > 0) && (cpu_sync%task_rng_.intervall == 0)) {
writeRestartData(engine, cpu_sync, task_rng_.overwrite_last);
}
@@ -127,6 +132,28 @@ void SimulationOutput::writeSimulationData(DynamicDensityField* density_field,
writePhysicalTime(density_field, path);
}
void SimulationOutput::writeSimulationData(DynamicDensityFieldWithPitchAngle* 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 + "/DensityFieldWithPitchAngle/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,
@@ -188,8 +215,6 @@ void SimulationOutput::writeRestartData(std::mt19937* engine, int cpu_sync,
void SimulationOutput::writeRandomEngineState(std::mt19937* engine, std::string path) {
std::ostringstream engine_state;
engine_state << (*engine);
DEBUG_LEVEL_0(std::to_string(engine_state.str().size()));
DEBUG_LEVEL_0(std::to_string(sizeof(*engine)));
writer.writeRNG(engine_state.str(), path);
}
@@ -248,23 +273,55 @@ void SimulationOutput::writeSpectrum(DynamicDensityField* density_field,
writer.write(density_field->spectrumArray(), path + "/Spectrum");
}
void SimulationOutput::writeSpectrum(DynamicDensityFieldWithPitchAngle* 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::writeDensity(DynamicDensityFieldWithPitchAngle* 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::writeTimeInBin(DynamicDensityFieldWithPitchAngle* 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::writeDeletedParticles(DynamicDensityFieldWithPitchAngle* 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::writePhysicalTime(DynamicDensityFieldWithPitchAngle* density_field,
std::string path) {
writer.write(density_field->physicalTime(), path + "/PhysicalTime");
}
void SimulationOutput::writePotential(PoissonSolver* poisson_solver, std::string path) {
writer.write(poisson_solver->potential(), path + "/Potential");
}
@@ -285,6 +342,53 @@ void SimulationOutput::writeMetaData(DynamicDensityField* density_field,
writeNumBins(density_field, path_to_field);
}
void SimulationOutput::writeMetaData(DynamicDensityFieldWithPitchAngle* density_field,
std::string path) {
std::string path_to_field = path + "/DensityFieldWithPitchAngle";
// write bin volumes
{
std::string path_to_volume = path_to_field + "/BinVolumes";
writer.write(density_field->binVolumeArray(), path_to_volume);
}
// write bin borders
{
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> mu_bin_borders =
density_field->pitchAngleBinning()->binBorders();
writer.write(mu_bin_borders, path_to_bin_borders + "/pitchAngle");
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");
}
// write num bins
{
std::string path_to_num_bins = path_to_field + "/NumBins";
blitz::TinyVector<int, 4> num_bins = density_field->spectrumArray().extent();
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::writeMetaData(CurrentCollector* current_collector,
std::string path) {
std::string path_to_collector = path + "/CurrentCollector";