included generator files for the poisson solver
Adjusted binning in poisson_solver.* to fit with the generator
This commit is contained in:
@@ -11,7 +11,7 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
|
||||
GlobalBoundary top_boundary,
|
||||
GlobalBoundary hull_boundary,
|
||||
std::shared_ptr<Geometry> geometry,
|
||||
std::shared_ptr<CylinderBinning> density_binning,
|
||||
CylinderBinning& density_binning,
|
||||
std::vector<std::shared_ptr<Electrode>> electrodes,
|
||||
double target_accuracy,
|
||||
int num_cycles)
|
||||
@@ -21,17 +21,17 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
|
||||
geometry_(geometry),
|
||||
density_binning_(density_binning),
|
||||
potential_(blitz::Array<PotentialGridPoint, 3>(
|
||||
blitz::Range(density_binning->binIndexMin()(0),
|
||||
density_binning->binIndexMax()(0)+1),
|
||||
blitz::Range(density_binning->binIndexMin()(1),
|
||||
density_binning->binIndexMax()(1)), // the azimuthal direction is periodic
|
||||
blitz::Range(density_binning->binIndexMin()(2),
|
||||
density_binning->binIndexMax()(2)+1))),
|
||||
blitz::Range(density_binning.binIndexMin()(0),
|
||||
density_binning.binIndexMax()(0)+1),
|
||||
blitz::Range(density_binning.binIndexMin()(1),
|
||||
density_binning.binIndexMax()(1)), // the azimuthal direction is periodic
|
||||
blitz::Range(density_binning.binIndexMin()(2),
|
||||
density_binning.binIndexMax()(2)+1))),
|
||||
electrodes_(electrodes),
|
||||
target_accuracy_(target_accuracy),
|
||||
num_cycles_(num_cycles) {
|
||||
// set inner values
|
||||
blitz::TinyVector<double, 3> stepsize = density_binning_->stepsize();
|
||||
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
|
||||
for (int i = potential_.lbound(0); i <= potential_.ubound(0) - 1; ++i) {
|
||||
for (int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
|
||||
for (int k = potential_.lbound(2) + 1; k <= potential_.ubound(2) - 1;
|
||||
@@ -81,7 +81,7 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
|
||||
|
||||
void PoissonSolver::solverIteration(
|
||||
const blitz::Array<double, 3>& interpolated_density) {
|
||||
blitz::TinyVector<double, 3> stepsize = density_binning_->stepsize();
|
||||
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
|
||||
const double dr_sq = std::pow(stepsize(0), 2); // shorthand
|
||||
const double dth_sq = std::pow(stepsize(1), 2); // shorthand
|
||||
const double dz_sq = std::pow(stepsize(2), 2); // shorthand
|
||||
@@ -140,7 +140,7 @@ void PoissonSolver::solverIteration(
|
||||
//boundray, prbably needs to be added (or the "electrodes" removed)
|
||||
bool PoissonSolver::converged(
|
||||
const blitz::Array<double, 3>& interpolated_density) {
|
||||
blitz::TinyVector<double, 3> stepsize = density_binning_->stepsize();
|
||||
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
|
||||
const double dr_sq = std::pow(stepsize(0), 2); // shorthand
|
||||
const double dth_sq = std::pow(stepsize(1), 2); // shorthand
|
||||
const double dz_sq = std::pow(stepsize(2), 2); // shorthand
|
||||
@@ -238,7 +238,7 @@ blitz::Array<double, 3> PoissonSolver::interpolateDensityToPotentialGrid(const b
|
||||
|| (potential_.extent(2) - 1 != density.extent(2))) {
|
||||
ERROR("Extent of the cylinder binning and the provided chargedensity do not match.");
|
||||
}
|
||||
//probably include a check for the loweubound of the provided chargedensity
|
||||
//probably include a check for the lowerbound of the provided chargedensity
|
||||
//coincides with the one of the potential (and by that extent the cylinder binning)
|
||||
|
||||
// adapted from the external poisson solver (SDS: \\lsdf02.urz.uni-heidelberg.de\SD19H002\karl\src\tools\analysis_jkellerer)
|
||||
@@ -248,13 +248,10 @@ blitz::Array<double, 3> PoissonSolver::interpolateDensityToPotentialGrid(const b
|
||||
//center values
|
||||
for(int i = potential_.lbound(0)+1; i <= potential_.ubound(0)-1; ++i) {
|
||||
for(int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
|
||||
int jm = (j - 1) < potential_.lbound(1) ? potential_.ubound(1) : j-1;
|
||||
for(int k = potential_.lbound(2)+1; k <= potential_.ubound(2)-1; ++k) {
|
||||
interpolatedDensity(i, j, k) = (
|
||||
density(i-1, j , k-1) + density(i, j , k-1) +
|
||||
density(i-1, jm, k-1) + density(i, jm, k-1) +
|
||||
density(i-1, j , k ) + density(i, j , k ) +
|
||||
density(i-1, jm, k ) + density(i, jm, k ) )/8.;
|
||||
density(i-1, j , k ) + density(i, j , k ))/4.;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -278,24 +275,21 @@ blitz::Array<double, 3> PoissonSolver::interpolateDensityToPotentialGrid(const b
|
||||
fixedIndex = potential_.ubound(2);
|
||||
for(int i = potential_.lbound(0)+1; i <= potential_.ubound(0)-1; ++i) {
|
||||
for(int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
|
||||
int jm = (j - 1) < potential_.lbound(1) ? potential_.ubound(1) : j-1;
|
||||
interpolatedDensity(i, j, fixedIndex) = (
|
||||
density(i-1, j , fixedIndex-1) +
|
||||
density(i , j , fixedIndex-1) +
|
||||
density(i-1, jm, fixedIndex-1) +
|
||||
density(i , jm, fixedIndex-1) )/4.;
|
||||
density(i , j , fixedIndex-1) )/4.;
|
||||
}
|
||||
}
|
||||
|
||||
//value where the axis and the open boundary meet
|
||||
for(int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
|
||||
interpolatedDensity(potential_.lbound(0), blitz::Range::all(), fixedIndex) += (
|
||||
density(potential_.lbound(0), j , fixedIndex-1))/(potential_.extent(1));
|
||||
interpolatedDensity(potential_.lbound(0), blitz::Range::all(), fixedIndex) +=
|
||||
(density(potential_.lbound(0), j , fixedIndex-1))/(potential_.extent(1));
|
||||
}
|
||||
|
||||
//for r=r_max and k=k_min do not use an interpolation, since there's assumed
|
||||
//to be an absorbing, metallic wall, which leads to those values being 0 always
|
||||
//however(!) right now i would be possible that the global boundary at those
|
||||
//however(!) right now. it would be possible that the global boundary at those
|
||||
//positions is not a metallic(i.e. dirichlet) boundary --> would need to include
|
||||
//a check for the type of boundary and adjust the interpolation accordingly
|
||||
return interpolatedDensity;
|
||||
@@ -307,7 +301,7 @@ blitz::Array<double, 3> PoissonSolver::interpolateDensityToPotentialGrid(const b
|
||||
// otherwise need to adjust the size of the E-arrays
|
||||
// since e.g. Ez exists for all r Values in potential_
|
||||
std::shared_ptr<VectorField> PoissonSolver::staticElectricField() {
|
||||
blitz::TinyVector<double, 3> stepsize = density_binning_->stepsize();
|
||||
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
|
||||
blitz::TinyVector<int,3> Eextent = potential_.extent() -
|
||||
blitz::TinyVector<int,3>(1,0,1);
|
||||
blitz::Array<double, 3> Er(potential_.lbound(), Eextent);
|
||||
@@ -315,24 +309,54 @@ std::shared_ptr<VectorField> PoissonSolver::staticElectricField() {
|
||||
blitz::Array<double, 3> Ez(potential_.lbound(), Eextent);
|
||||
|
||||
Ephi = 0.;
|
||||
|
||||
//do calculation of E from the potential and interpolation to
|
||||
//cell center at the same time
|
||||
for(int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
|
||||
int jp = (j+1 > potential_.ubound(1)) ? potential_.lbound(1) : j+1;
|
||||
int jm = (j-1 < potential_.lbound(1)) ? potential_.ubound(1) : j-1;
|
||||
for(int i = potential_.lbound(0); i < potential_.ubound(0); ++i) {
|
||||
for(int k = potential_.lbound(2); k < potential_.ubound(2); ++k) {
|
||||
Er(i,j,k) = (potential_(i+1,j,k).value -
|
||||
potential_(i,j,k).value)/stepsize(0);
|
||||
Ez(i,j,k) = (potential_(i,j,k+1).value -
|
||||
potential_(i,j,k).value)/stepsize(2);
|
||||
if(i > 0) {
|
||||
Ephi(i,j,k) = (potential_(i,jp,k).value -
|
||||
potential_(i,j,k).value) / (i*stepsize(0) * stepsize(1));
|
||||
Er(i,j,k) = (potential_(i+1,j,k ).value -
|
||||
potential_(i ,j,k ).value +
|
||||
potential_(i+1,j,k+1).value -
|
||||
potential_(i ,j,k+1).value)
|
||||
/(2*stepsize(0));
|
||||
|
||||
Ez(i,j,k) = (potential_(i ,j,k+1).value -
|
||||
potential_(i ,j,k ).value +
|
||||
potential_(i+1,j,k+1).value -
|
||||
potential_(i+1,j,k ).value)
|
||||
/(2*stepsize(2));
|
||||
|
||||
if(i==potential_.lbound(0)) {
|
||||
Ephi(i,j,k) = (
|
||||
potential_(i+1,jp,k ).value -
|
||||
potential_(i+1,jm,k ).value +
|
||||
potential_(i+1,jp,k+1).value -
|
||||
potential_(i+1,jm,k+1).value)
|
||||
/((i+1)*stepsize(0)*stepsize(2))/4.;
|
||||
} else {
|
||||
Ephi(i,j,k) = (
|
||||
(potential_(i ,jp,k ).value -
|
||||
potential_(i ,jm,k ).value +
|
||||
potential_(i ,jp,k+1).value -
|
||||
potential_(i ,jm,k+1).value)
|
||||
/(i*stepsize(0)) +
|
||||
(potential_(i+1,jp,k ).value -
|
||||
potential_(i+1,jm,k ).value +
|
||||
potential_(i+1,jp,k+1).value -
|
||||
potential_(i+1,jm,k+1).value)
|
||||
/((i+1)*stepsize(0))
|
||||
)/(4.*stepsize(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::shared_ptr<VectorField>(new VectorFieldConstant(CylinderVector(blitz::TinyVector<double, 3>(0,0,0))));
|
||||
// if the VectorField object uses the E-field
|
||||
//at the correct position is not certain
|
||||
return std::shared_ptr<VectorField>(
|
||||
new VectorFieldFromArray(Er, Ephi, Ez,
|
||||
Eextent(0)*stepsize(0), Eextent(2)*stepsize(2)));
|
||||
}
|
||||
|
||||
Electrode::Electrode(double potential): potential_(potential) {};
|
||||
@@ -355,4 +379,5 @@ bool RearWall::isOnElectrode(const Coordinate& position) {
|
||||
//TODO:
|
||||
// look for a function that calculates the E-Field from the potential (if it doesn't exist, one has to be written)
|
||||
// get the "main" code to also output the potential if specified(for testing purposes)
|
||||
// same for the electric field
|
||||
// same for the electric field
|
||||
// make sure .lbound(0) always makes sense as a replacement of r=0
|
||||
Reference in New Issue
Block a user