poisson solver boundary in .json

This commit is contained in:
2024-03-27 10:12:09 +01:00
parent 1b273c8e04
commit b54a5805d7
3 changed files with 60 additions and 20 deletions
+52 -16
View File
@@ -27,20 +27,8 @@ namespace generator {
{"PositionBinning"});
CylinderBinning position_binning =
buildPositionBinningIncludingRedirection(parameter, path_binning);
//create top, bottom and hull boundary
// for now put them as fixed and not read from json file
// needs to be changed! (probably needs an own generator or smth)
GlobalBoundary bottom_boundary;
bottom_boundary.type = BoundaryType::dirichlet;
bottom_boundary.boundary_value = 0.;
GlobalBoundary top_boundary;
top_boundary.type = BoundaryType::neumann_to_top;
top_boundary.boundary_value = 0.;
GlobalBoundary hull_boundary;
hull_boundary.type = BoundaryType::dirichlet;
hull_boundary.boundary_value = 0.;
auto boundaries = buildBoundaries(parameter, {"PoissonSolver", "Boundary"});
std::vector<std::shared_ptr<Electrode>> electrodes{};
@@ -50,9 +38,57 @@ namespace generator {
int num_cycles = parameter.intValue(json_path_append({"PoissonSolver"},
{"NumCycles"}));
return std::shared_ptr<PoissonSolver>(new PoissonSolver(bottom_boundary,
top_boundary, hull_boundary, geometry, position_binning, electrodes,
target_accuracy, num_cycles));
return std::shared_ptr<PoissonSolver>(new PoissonSolver(boundaries.at("Bottom"),
boundaries.at("Top"), boundaries.at("Hull"), geometry, position_binning,
electrodes, target_accuracy, num_cycles));
}
std::map<std::string, GlobalBoundary> buildBoundaries(Parameter& parameter,
const json_path& path_to_boundaries) {
DEBUG_LEVEL_3("Creating Boundaries.");
std::map<std::string, GlobalBoundary> boundary_map {
{"Bottom", {0., BoundaryType::dirichlet}},
{"Top", {0., BoundaryType::dirichlet}},
{"Hull", {0., BoundaryType::dirichlet}}};
const std::map<std::string, BoundaryType> 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;
}
};