#include "generators/poisson_solver_generator.h" #include "poisson_solver/poisson_solver.h" #include "generators/geometry_generator.h" #include "generators/binning_generator.h" #include #include "simulation/errors.h" namespace generator { std::shared_ptr buildPoissonSolver( Parameter& parameter) { DEBUG_LEVEL_2("Generating Poisson solver."); std::shared_ptr geometry; json_t* object = json_object_by_path( parameter.jsonFile(), {"PoissonSolver"}); //create geometry if (json_object_by_path(object, {"BoundaryGeometry"})) { geometry = buildGeometryIncludingRedirection(parameter, json_path_append({"PoissonSolver"}, {"BoundaryGeometry"})); } else { ERROR("Cannot find boundary geometry for poisson solver."); } //create binning json_path path_binning = json_path_append({"PoissonSolver"}, {"PositionBinning"}); CylinderBinning position_binning = buildPositionBinningIncludingRedirection(parameter, path_binning); auto boundaries = buildBoundaries(parameter, {"PoissonSolver", "Boundary"}); int solver_intervall = json_int(json_object_by_path(object, {"Intervall"})); if (solver_intervall == 0 && json_string(json_object_by_path( object, {"Intervall"})) == "EachSync") { solver_intervall = 1; } ASSERT_POSITIVE(&solver_intervall, "The intervall for poisson solver stride must be positive" " or 'EachSync'"); int solver_offset = json_int(json_object_by_path(object, {"Offset"})); ASSERT_NOTNEGATIVE(&solver_offset, "The offset for poisson solver has to be non-negative"); std::vector> electrodes{}; double target_accuracy = parameter.doubleValue( json_path_append({"PoissonSolver"}, {"TargetAccuracy"})); int num_cycles = parameter.intValue(json_path_append({"PoissonSolver"}, {"NumCycles"})); bool do_solver = parameter.boolValue(json_path_append({"PoissonSolver"}, {"DoSolver"}), true); return std::shared_ptr(new PoissonSolver(boundaries.at("Bottom"), boundaries.at("Top"), boundaries.at("Hull"), geometry, position_binning, electrodes, target_accuracy, num_cycles, solver_intervall, solver_offset, do_solver)); } std::map buildBoundaries(Parameter& parameter, const json_path& path_to_boundaries) { DEBUG_LEVEL_3("Creating Boundaries."); std::map boundary_map { {"Bottom", {0., BoundaryType::dirichlet}}, {"Top", {0., BoundaryType::dirichlet}}, {"Hull", {0., BoundaryType::dirichlet}}}; const std::map neumann_location_map { {"Bottom", BoundaryType::neumann_to_bottom}, {"Top", BoundaryType::neumann_to_top}, {"Hull", BoundaryType::neumann_to_hull}}; const char* key; json_t* value; json_object_foreach(parameter.jsonObjectFromBase(path_to_boundaries), key, value) { DEBUG_LEVEL_3("Creating " + std::string(key) + ": "); if(!(boundary_map.find(std::string(key)) == boundary_map.end())) { double boundary_value = json_double(json_object_by_path(value, {"value"})); std::string boundary_type = json_string(json_object_by_path(value, {"type"})); if (boundary_type == "dirichlet") { boundary_map[std::string(key)].type = BoundaryType::dirichlet; boundary_map[std::string(key)].boundary_value = boundary_value; } else if (boundary_type == "neumann") { boundary_map[std::string(key)].type = neumann_location_map.at(std::string(key)); boundary_map[std::string(key)].boundary_value = boundary_value; } else { SIM_INFO("Unknown boundary type:" + boundary_type + ". Using default boundary (dirichtlet, value 0)"); continue; } DEBUG_LEVEL_3("with type: " + boundary_type); DEBUG_LEVEL_3("with value: " + std::to_string(boundary_value)); } else { SIM_INFO(std::string(key) + ": unknown location. Is ignored."); } } return boundary_map; } };