Files
karl/src/generators/drift_velocity_generator.cpp
T
2024-03-15 15:49:40 +01:00

45 lines
1.7 KiB
C++
Executable File

#include "generators/drift_velocity_generator.h"
#include "generators/vector_field_generator.h"
#include "simulation/errors.h"
namespace generator {
std::shared_ptr<DriftVelocity> buildDriftVelocity(
Parameter& parameter,
const json_path& path_to_drift_velocity) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_drift_velocity, {"VectorField"}))) {
DEBUG_LEVEL_2("Creating drift velocity: Vector field.");
std::shared_ptr<VectorField> field =
buildVectorField(parameter.jsonObjectFromBase(
json_path_append(path_to_drift_velocity, {"VectorField"})));
return std::shared_ptr<DriftVelocity>(new DriftVelocity(field));
} else if (parameter.jsonObjectFromBase(
json_path_append(path_to_drift_velocity, {"null"}))) {
DEBUG_LEVEL_2("Creating drift velocity: null.");
return nullptr;
} else {
ERROR("No drift velocity given.");
return nullptr;
}
}
std::shared_ptr<DriftVelocity> buildDriftVelocityIncludingRedirection(
Parameter& parameter, const json_path& path_to_drift_velocity) {
std::stringstream cpath;
if (parameter.jsonObjectFromBase(
json_path_append(path_to_drift_velocity, {"CreateSameAs"}))) {
DEBUG_LEVEL_2("Creating drift velocity: CreateSameAs.");
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
json_path_append(path_to_drift_velocity, {"CreateSameAs"})));
std::stringstream path;
for (auto& p : path_to_same) {
path << p << " ";
}
DEBUG_LEVEL_3("From path: " + path.str());
return buildDriftVelocityIncludingRedirection(parameter, path_to_same);
} else {
return buildDriftVelocity(parameter, path_to_drift_velocity);
}
}
}; // namespace generator