Restructuring of poisson solver offset;

inclusion of stride for poisson solver
This commit is contained in:
2024-03-28 15:57:04 +01:00
parent 26f730ca29
commit 52a580ac63
4 changed files with 60 additions and 39 deletions
+33 -26
View File
@@ -15,7 +15,9 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
CylinderBinning& density_binning,
std::vector<std::shared_ptr<Electrode>> electrodes,
double target_accuracy,
int num_cycles)
int num_cycles,
int solver_intervall,
int solver_offset)
: bottom_boundary_(bottom_boundary),
top_boundary_(top_boundary),
hull_boundary_(hull_boundary),
@@ -30,7 +32,9 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
density_binning.binIndexMax()(2)))),
electrodes_(electrodes),
target_accuracy_(target_accuracy),
num_cycles_(num_cycles) {
num_cycles_(num_cycles),
solver_intervall_(solver_intervall),
solver_offset_(solver_offset) {
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
for (int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) {
@@ -75,7 +79,29 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
blitz::Range(density_binning.binIndexMin()(2),
density_binning.binIndexMax()(2)));
zero_chargedensity = 0.;
solvePotential(zero_chargedensity);
solvePotential(zero_chargedensity, 0);
}
void PoissonSolver::solvePotential(
const blitz::Array<double, 3> charge_density, int cpu_sync) {
if ((cpu_sync % solver_intervall_ != 0) || ((cpu_sync <= solver_offset_)
&& (cpu_sync > 0))) {
return;
}
DEBUG_LEVEL_3("Interpolating chargedensity.");
blitz::Array<double, 3> interpolated_density =
interpolateDensityToPotentialGrid(charge_density);
int it = 1;
do {
solverIteration(interpolated_density);
if (it % 1000 == 0) {
DEBUG_LEVEL_3("Poisson solver, iteration: " + std::to_string(it));
if (converged(interpolated_density)) {
break;
};
}
++it;
} while (it < num_cycles_);
}
void PoissonSolver::solverIteration(
@@ -223,24 +249,6 @@ bool PoissonSolver::converged(
return normalized_difference < target_accuracy_;
}
void PoissonSolver::solvePotential(
const blitz::Array<double, 3> charge_density) {
DEBUG_LEVEL_3("Interpolating chargedensity.");
blitz::Array<double, 3> interpolated_density =
interpolateDensityToPotentialGrid(charge_density);
int it = 1;
do {
solverIteration(interpolated_density);
if (it % 1000 == 0) {
DEBUG_LEVEL_3("Poisson solver, iteration: " + std::to_string(it));
if (converged(interpolated_density)) {
break;
};
}
++it;
} while (it < num_cycles_);
}
blitz::Array<double, 3> PoissonSolver::potential() {
// there might be a better way to do this... (if one can do array.memberValue without
// explicitely looping)
@@ -346,6 +354,10 @@ std::shared_ptr<VectorField> PoissonSolver::staticElectricField() {
Eextent(0)*stepsize(0), Eextent(2)*stepsize(2)));
}
const CylinderBinning* PoissonSolver::densityBinning() {
return &density_binning_;
}
Electrode::Electrode(double potential): potential_(potential) {};
double Electrode::electrodePotential() {
@@ -360,9 +372,4 @@ RearWall::RearWall(double potential): Electrode(potential) {};
bool RearWall::isOnElectrode(const Coordinate& position) {
return false;
}
const CylinderBinning* PoissonSolver::densityBinning() {
return &density_binning_;
}
//PotentialGridPoint::PotentialGridPoint(BoundaryType _type, double _value): type(_type), value(_value) {};