Version 2, position dependent E/B, kinetic ions, boris mover, terminator
This commit is contained in:
Executable
+99
@@ -0,0 +1,99 @@
|
||||
#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 == "AbsolutPath") {
|
||||
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, 3> 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.readD3Double(key);
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> 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, {"PathToH5"}), component));
|
||||
|
||||
Hdf5Reader reader(absolute_filename);
|
||||
return reader.readD3Double(key);
|
||||
}
|
||||
|
||||
std::shared_ptr<VectorField> buildVectorField(json_t* object) {
|
||||
if (json_object_by_path(object, {"VectorFieldConstant"})) {
|
||||
DEBUG_LEVEL_2("Creating Vector field: VectorFieldConstant");
|
||||
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"})) {
|
||||
DEBUG_LEVEL_2("Creating Vector field: VectorFieldFunctionInZ");
|
||||
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"})) {
|
||||
DEBUG_LEVEL_2("Creating Vector field: VectorFieldFromArray");
|
||||
|
||||
blitz::Array<double, 3> v_radial = readComponentFromFile(
|
||||
json_object_by_path(object,
|
||||
{"VectorFieldFromArray", "ReadArrayFromFile"}),
|
||||
0);
|
||||
blitz::Array<double, 3> v_azimuthal = readComponentFromFile(
|
||||
json_object_by_path(object,
|
||||
{"VectorFieldFromArray", "ReadArrayFromFile"}),
|
||||
1);
|
||||
blitz::Array<double, 3> 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
|
||||
Reference in New Issue
Block a user