159 lines
5.2 KiB
C++
Executable File
159 lines
5.2 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);
|
|
}
|
|
|
|
return output;
|
|
}
|
|
|
|
}; // namespace generator
|