Added Electrodes to Poisson Solver
This commit is contained in:
@@ -29,11 +29,14 @@ struct GlobalBoundary {
|
|||||||
BoundaryType type;
|
BoundaryType type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// only useful at the initialization of the PoissonSolver...
|
||||||
|
// (or if at later times a time dependent value is desired)
|
||||||
class Electrode {
|
class Electrode {
|
||||||
public:
|
public:
|
||||||
Electrode(double potential);
|
Electrode(double potential);
|
||||||
virtual bool isOnElectrode(const Coordinate& position) = 0;
|
virtual bool isOnElectrode(const Coordinate& position) = 0;
|
||||||
double electrodePotential();
|
virtual double electrodePotential();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const double potential_;
|
const double potential_;
|
||||||
@@ -45,6 +48,20 @@ class RearWall : public Electrode {
|
|||||||
bool isOnElectrode(const Coordinate& position);
|
bool isOnElectrode(const Coordinate& position);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class RingElectrode : public Electrode {
|
||||||
|
public:
|
||||||
|
RingElectrode(double potential, const double zPosition,
|
||||||
|
const double innerRadius,
|
||||||
|
const double outerRadius,
|
||||||
|
const blitz::TinyVector<double, 2> stepsize);
|
||||||
|
bool isOnElectrode(const Coordinate& position);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// stores (rinner, router, zpos) in this order
|
||||||
|
blitz::TinyVector<double,3> specs_;
|
||||||
|
blitz::TinyVector<double,2> stepsize_;
|
||||||
|
};
|
||||||
|
|
||||||
// for (r,z) axially density
|
// for (r,z) axially density
|
||||||
class PoissonSolver {
|
class PoissonSolver {
|
||||||
public:
|
public:
|
||||||
|
|||||||
Executable
+1049
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,7 @@ namespace generator {
|
|||||||
|
|
||||||
json_t* object = json_object_by_path(
|
json_t* object = json_object_by_path(
|
||||||
parameter.jsonFile(), {"PoissonSolver"});
|
parameter.jsonFile(), {"PoissonSolver"});
|
||||||
|
|
||||||
//create geometry
|
//create geometry
|
||||||
if (json_object_by_path(object, {"BoundaryGeometry"})) {
|
if (json_object_by_path(object, {"BoundaryGeometry"})) {
|
||||||
geometry = buildGeometryIncludingRedirection(parameter,
|
geometry = buildGeometryIncludingRedirection(parameter,
|
||||||
@@ -24,6 +25,7 @@ namespace generator {
|
|||||||
} else {
|
} else {
|
||||||
ERROR("Cannot find boundary geometry for poisson solver.");
|
ERROR("Cannot find boundary geometry for poisson solver.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//create binning
|
//create binning
|
||||||
json_path path_binning = json_path_append({"PoissonSolver"},
|
json_path path_binning = json_path_append({"PoissonSolver"},
|
||||||
{"PositionBinning"});
|
{"PositionBinning"});
|
||||||
@@ -32,7 +34,37 @@ namespace generator {
|
|||||||
|
|
||||||
auto boundaries = buildBoundaries(parameter, {"PoissonSolver", "Boundary"});
|
auto boundaries = buildBoundaries(parameter, {"PoissonSolver", "Boundary"});
|
||||||
|
|
||||||
|
// build electrodes, might be good to put into own function
|
||||||
std::vector<std::shared_ptr<Electrode>> electrodes{};
|
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(
|
double target_accuracy = parameter.doubleValue(
|
||||||
json_path_append({"PoissonSolver"}, {"TargetAccuracy"}));
|
json_path_append({"PoissonSolver"}, {"TargetAccuracy"}));
|
||||||
|
|||||||
@@ -196,16 +196,18 @@ bool PoissonSolver::converged(
|
|||||||
normalized_difference =
|
normalized_difference =
|
||||||
std::sqrt(cumulated_quadradic_difference / (nr * nz));
|
std::sqrt(cumulated_quadradic_difference / (nr * nz));
|
||||||
#ifdef debug
|
#ifdef debug
|
||||||
DEBUG_LEVEL_0("Poisson solver reached a normalized difference of: " +
|
std::stringstream out;
|
||||||
std::to_string(normalized_difference));
|
out << "Poisson solver reached a normalized difference of: ";
|
||||||
|
out << normalized_difference;
|
||||||
|
DEBUG_LEVEL_0(out.str());
|
||||||
#endif
|
#endif
|
||||||
double normalized_maximum =
|
double normalized_maximum =
|
||||||
maximum_difference*SI::eps0/(fabs(blitz::max(interpolated_density)) + 1e-12);
|
maximum_difference*SI::eps0/(fabs(blitz::max(interpolated_density)) + 1e-12);
|
||||||
#ifdef debug_level1
|
#ifdef debug
|
||||||
std::ostringstream message;
|
std::ostringstream message;
|
||||||
message << "Maximum Difference normalized by order of magnitude: "
|
message << "Maximum Difference normalized by order of magnitude: "
|
||||||
<< normalized_difference;
|
<< normalized_maximum;
|
||||||
DEBUG_LEVEL_1(message.str());
|
DEBUG(message.str());
|
||||||
#endif
|
#endif
|
||||||
return normalized_difference < target_accuracy_;
|
return normalized_difference < target_accuracy_;
|
||||||
}
|
}
|
||||||
@@ -332,3 +334,33 @@ bool RearWall::isOnElectrode(const Coordinate& position) {
|
|||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user