106 lines
3.8 KiB
C++
Executable File
106 lines
3.8 KiB
C++
Executable File
#include "generators/vector_field_generator.h"
|
|
|
|
#include <functional>
|
|
#include "IO/hdf5_reader.h"
|
|
#include "generators/binning_generator.h"
|
|
#include "generators/function_generator.h"
|
|
#include "simulation/errors.h"
|
|
#include "simulation/homebase.h"
|
|
#include "simulation/jansson_additionals.h"
|
|
|
|
namespace generator {
|
|
|
|
std::string readAbsoluteFilename(json_t* object) {
|
|
std::string path_type = json_string(json_object_by_path(object, {"Type"}));
|
|
if (path_type == "RelativeToHomebase") {
|
|
std::string homebase = BUILD_HOMEBASE_STRING;
|
|
std::string relative_path_to_homebase =
|
|
json_string(json_object_by_path(object, {"RelativePath"}));
|
|
std::string filename =
|
|
json_string(json_object_by_path(object, {"Filename"}));
|
|
return homebase + "/" + relative_path_to_homebase + "/" + filename;
|
|
|
|
} else if (path_type == "AbsolutePath") {
|
|
std::string absolute_path =
|
|
json_string(json_object_by_path(object, {"AbsoluteFolderPath"}));
|
|
std::string filename =
|
|
json_string(json_object_by_path(object, {"Filename"}));
|
|
return absolute_path + "/" + filename;
|
|
} else {
|
|
ERROR("This path type is not supported: " + path_type);
|
|
return "";
|
|
}
|
|
}
|
|
|
|
blitz::Array<double, 2> readFromFile(json_t* object) {
|
|
std::string absolute_filename =
|
|
readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}));
|
|
std::string key = json_string(json_object_by_path(object, {"Key"}));
|
|
|
|
Hdf5Reader reader(absolute_filename);
|
|
return reader.readD2Double(key);
|
|
}
|
|
|
|
blitz::Array<double, 2> readComponentFromFile(json_t* object, int component) {
|
|
std::string absolute_filename =
|
|
readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}));
|
|
std::string key = json_string(
|
|
json_array_get(json_object_by_path(object, {"Keys"}), component));
|
|
|
|
Hdf5Reader reader(absolute_filename);
|
|
return reader.readD2Double(key);
|
|
}
|
|
|
|
std::shared_ptr<VectorField> buildVectorField(json_t* object) {
|
|
if (json_object_by_path(object, {"VectorFieldConstant"})) {
|
|
#ifdef debug_level2
|
|
DEBUG_LEVEL_2("Creating Vector field: VectorFieldConstant");
|
|
#endif
|
|
blitz::TinyVector<double, 3> constant = json_blitz_vector<3>(
|
|
json_object_by_path(object, {"VectorFieldConstant", "constant"}));
|
|
|
|
return std::shared_ptr<VectorField>(
|
|
new VectorFieldConstant(CylinderVector(constant)));
|
|
|
|
} else if (json_object_by_path(object, {"VectorFieldFunctionInZ"})) {
|
|
#ifdef debug_level2
|
|
DEBUG_LEVEL_2("Creating Vector field: VectorFieldFunctionInZ");
|
|
#endif
|
|
std::function<double(double, double, double)> z_function = function3D(
|
|
json_object_by_path(object, {"VectorFieldFunctionInZ", "zFunction"}));
|
|
return std::shared_ptr<VectorField>(new VectorFieldFunctionInZ(z_function));
|
|
|
|
} else if (json_object_by_path(object, {"VectorFieldFromArray"})) {
|
|
#ifdef debug_level2
|
|
DEBUG_LEVEL_2("Creating Vector field: VectorFieldFromArray");
|
|
#endif
|
|
|
|
blitz::Array<double, 2> v_radial = readComponentFromFile(
|
|
json_object_by_path(object,
|
|
{"VectorFieldFromArray", "ReadArrayFromFile"}),
|
|
0);
|
|
blitz::Array<double, 2> v_azimuthal = readComponentFromFile(
|
|
json_object_by_path(object,
|
|
{"VectorFieldFromArray", "ReadArrayFromFile"}),
|
|
1);
|
|
blitz::Array<double, 2> v_longitudinal = readComponentFromFile(
|
|
json_object_by_path(object,
|
|
{"VectorFieldFromArray", "ReadArrayFromFile"}),
|
|
2);
|
|
|
|
double radius = json_double(
|
|
json_object_by_path(object, {"VectorFieldFromArray", "Radius"}));
|
|
double length = json_double(
|
|
json_object_by_path(object, {"VectorFieldFromArray", "Length"}));
|
|
|
|
return std::make_shared<VectorFieldFromArray>(
|
|
v_radial, v_azimuthal, v_longitudinal, radius, length);
|
|
} else {
|
|
ERROR("This vector field is not implemented");
|
|
return nullptr;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
} // namespace generator
|