Files
karl/src/generators/simulation_output_generator.cpp
T
csendlinger c33629cb88 Added new reading routines (engine state,
4d double, 4d int); fixed error in RestartInfo
output; added the maximum length of the engine
state string into sim_constants.h
2024-08-27 14:46:48 +02:00

182 lines
6.0 KiB
C++
Executable File

#include "generators/simulation_output_generator.h"
#include "IO/simulation_output.h"
#include "simulation/jansson_additionals.h"
#include "simulation/species.h"
namespace generator {
std::shared_ptr<SimulationOutput> buildSimulationOutput(
json_t* object,
const std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
tracked_species) {
std::string output_folder =
json_string(json_object_by_path(object, {"folder"}));
std::string filename = json_string(json_object_by_path(object, {"filename"}));
auto output = std::make_shared<SimulationOutput>(output_folder, filename);
// DensityFields
{
int intervall =
json_int(json_object_by_path(object, {"DensityFields", "Intervall"}));
if (intervall == 0 &&
json_string(json_object_by_path(
object, {"DensityFields", "Intervall"})) == "EachSync") {
intervall = 1;
}
ASSERT_POSITIVE(&intervall,
"The intervall for density field output must be positive");
bool overwrite_last = json_bool(
json_object_by_path(object, {"DensityFields", "OverwriteLast"}));
json_t* species = json_object_by_path(object, {"DensityFields", "Species"});
if (json_is_array(species)) {
size_t index;
json_t* value;
json_array_foreach(species, index, value) {
std::string specie_alias = json_string(value);
OutputTask task = {specie_alias, overwrite_last, intervall};
output->addDensityFieldOutput(task);
}
} else {
std::string all = json_string(species);
if (all == "all") {
for (const auto& pairs : tracked_species) {
OutputTask task = {pairs.first, overwrite_last, intervall};
output->addDensityFieldOutput(task);
}
} else {
ERROR("DensityFields: Species to be outputted have to be "
"given as an array or using the keyword \"all\".");
}
}
}
// CurrentBorders
{
int intervall =
json_int(json_object_by_path(object, {"CurrentBorders", "Intervall"}));
if (intervall == 0 &&
json_string(json_object_by_path(
object, {"CurrentBorders", "Intervall"})) == "EachSync") {
intervall = 1;
}
ASSERT_POSITIVE(&intervall,
"The intervall for current border output must be positive");
bool overwrite_last = json_bool(
json_object_by_path(object, {"CurrentBorders", "OverwriteLast"}));
json_t* species =
json_object_by_path(object, {"CurrentBorders", "Species"});
if (json_is_array(species)) {
size_t index;
json_t* value;
json_array_foreach(species, index, value) {
std::string specie_alias = json_string(value);
OutputTask task = {specie_alias, overwrite_last, intervall};
output->addCurrentBorderOutput(task);
}
} else {
std::string all = json_string(species);
if (all == "all") {
for (const auto& pairs : tracked_species) {
OutputTask task = {pairs.first, overwrite_last, intervall};
output->addCurrentBorderOutput(task);
}
} else {
ERROR("CurrentBorders: Species to be outputted have to be "
"given as an array or using the keyword \"all\".");
}
}
}
// DeletionLogger
{
int intervall =
json_int(json_object_by_path(object, {"DeletionLogger", "Intervall"}));
if (intervall == 0 &&
json_string(json_object_by_path(
object, {"DeletionLogger", "Intervall"})) == "EachSync") {
intervall = 1;
}
ASSERT_POSITIVE(
&intervall,
"The intervall for deletion logger output must be positive");
bool overwrite_last = json_bool(
json_object_by_path(object, {"DeletionLogger", "OverwriteLast"}));
json_t* species =
json_object_by_path(object, {"DeletionLogger", "Species"});
if (json_is_array(species)) {
size_t index;
json_t* value;
json_array_foreach(species, index, value) {
std::string specie_alias = json_string(value);
OutputTask task = {specie_alias, overwrite_last, intervall};
output->addDeletionLoggerOutput(task);
}
} else {
std::string all = json_string(species);
if (all == "all") {
for (const auto& pairs : tracked_species) {
OutputTask task = {pairs.first, overwrite_last, intervall};
output->addDeletionLoggerOutput(task);
}
} else {
ERROR("DeletionLogger: Species to be outputted have to be "
"given as an array or using the keyword \"all\".");
}
}
}
// PoissonSolver
{
int intervall =
json_int(json_object_by_path(object, {"PoissonSolver", "Intervall"}));
if (intervall == 0 &&
json_string(json_object_by_path(
object, {"PoissonSolver", "Intervall"})) == "EachSync") {
intervall = 1;
}
ASSERT_POSITIVE(&intervall,
"The intervall for the poisson solver output must be positive");
bool overwrite_last = json_bool(
json_object_by_path(object, {"PoissonSolver", "OverwriteLast"}));
OutputTask task = {"PoissonSolver", overwrite_last, intervall};
output->setPotentialOutput(task);
}
// RestartInfo
{
int intervall =
json_int(json_object_by_path(object, {"RestartInfo", "Intervall"}), -1);
// DEBUG_LEVEL_2("Try value of Intervall as string");
if (intervall == -1 && json_string(json_object_by_path(
object, {"RestartInfo", "Intervall"})) == "EachSync") {
intervall = 1;
} else if (intervall == -1) {
intervall = 0;
}
ASSERT_NOTNEGATIVE(&intervall, "The intervall for RestartInfo has to be either 0"
",if no output is required or positive otherwise");
DEBUG_LEVEL_3("Restart Interval: " + std::to_string(intervall));
bool overwrite_last = json_bool(
json_object_by_path(object, {"RestartInfo", "OverwriteLast"}));
OutputTask task = {"RestartInfo", overwrite_last, intervall};
output->setRestartInfoOutput(task);
}
return output;
}
}; // namespace generator