Added Electrodes to Poisson Solver

This commit is contained in:
2025-11-11 09:23:36 +01:00
parent 5d72083a25
commit 09dfddb6da
4 changed files with 1136 additions and 6 deletions
@@ -17,6 +17,7 @@ namespace generator {
json_t* object = json_object_by_path(
parameter.jsonFile(), {"PoissonSolver"});
//create geometry
if (json_object_by_path(object, {"BoundaryGeometry"})) {
geometry = buildGeometryIncludingRedirection(parameter,
@@ -24,6 +25,7 @@ namespace generator {
} else {
ERROR("Cannot find boundary geometry for poisson solver.");
}
//create binning
json_path path_binning = json_path_append({"PoissonSolver"},
{"PositionBinning"});
@@ -32,7 +34,37 @@ namespace generator {
auto boundaries = buildBoundaries(parameter, {"PoissonSolver", "Boundary"});
// build electrodes, might be good to put into own function
std::vector<std::shared_ptr<Electrode>> electrodes{};
const char* key;
json_t* value;
json_t* array = parameter.jsonObjectFromBase({"PoissonSolver", "Electrodes"});
json_object_foreach(array, key, value) {
std::string type = json_string(json_object_by_path(value, {"Type"}));
if(type == "RingElectrode") {
double zpos = json_read_length(json_object_by_path(value, {"zPosition"}));
double rInner = json_read_length(json_object_by_path(value, {"InnerRadius"}));
double rOuter = json_read_length(json_object_by_path(value, {"OuterRadius"}));
double potentialValue = json_double(json_object_by_path(value, {"Potential", "value"}));
#ifdef debug
std::stringstream out;
out << "Electrode " << std::string(key) << ":\n\t";
out << "z position: " << zpos << " m\n\t";
out << "inner radius: " << rInner << " m\n\t";
out << "outer radius: " << rOuter << " m\n\t";
out << "potential: " << potentialValue << " V";
DEBUG(out.str());
#endif
electrodes.push_back(
std::shared_ptr<RingElectrode>(
new RingElectrode(potentialValue, zpos, rInner, rOuter,
position_binning.stepsize())));
} else {
ERROR("Unknown or not implemented electrode type: " + type + ". Available options: \"RingElectrode\"");
}
}
double target_accuracy = parameter.doubleValue(
json_path_append({"PoissonSolver"}, {"TargetAccuracy"}));
+37 -5
View File
@@ -196,16 +196,18 @@ bool PoissonSolver::converged(
normalized_difference =
std::sqrt(cumulated_quadradic_difference / (nr * nz));
#ifdef debug
DEBUG_LEVEL_0("Poisson solver reached a normalized difference of: " +
std::to_string(normalized_difference));
std::stringstream out;
out << "Poisson solver reached a normalized difference of: ";
out << normalized_difference;
DEBUG_LEVEL_0(out.str());
#endif
double normalized_maximum =
maximum_difference*SI::eps0/(fabs(blitz::max(interpolated_density)) + 1e-12);
#ifdef debug_level1
#ifdef debug
std::ostringstream message;
message << "Maximum Difference normalized by order of magnitude: "
<< normalized_difference;
DEBUG_LEVEL_1(message.str());
<< normalized_maximum;
DEBUG(message.str());
#endif
return normalized_difference < target_accuracy_;
}
@@ -331,4 +333,34 @@ RearWall::RearWall(double potential): Electrode(potential) {};
bool RearWall::isOnElectrode(const Coordinate& position) {
return false;
}
RingElectrode::RingElectrode(double potential, const double zPosition,
const double innerRadius,
const double outerRadius,
const blitz::TinyVector<double, 2> stepsize):
Electrode(potential),
specs_(blitz::TinyVector<double, 3>(innerRadius, outerRadius, zPosition)),
stepsize_(stepsize) {}
bool RingElectrode::isOnElectrode(const Coordinate& pos) {
blitz::TinyVector<double, 3> pos_cyl = pos.cylinderEntries();
bool zdir = std::abs(pos_cyl(2) - specs_(2)) <= stepsize_(1)/2;
zdir = (specs_(2) - pos_cyl(2) == stepsize_(1)/2) ? false : zdir;
bool rInner = (pos_cyl(0) >= specs_(0));
bool rOuter = (pos_cyl(0) < specs_(1));
#ifdef debug
std::stringstream out;
out << "Position " << pos_cyl << ": \n\t";
out << "z-dir: " << ((zdir) ? "true" : "false") << "\n\t";
out << "rinner-dir: " << ((rInner) ? "true" : "false") << "\n\t";
out << "router-dir: " << ((rOuter) ? "true" : "false") << "\n\t";
out << "total: " << ((zdir && rInner && rOuter) ? "true" : "false") << "\n\t";
DEBUG(out.str());
#endif
return zdir && rInner && rOuter;
}