diff --git a/include/poisson_solver/poisson_solver.h b/include/poisson_solver/poisson_solver.h index e5d966e..d00829e 100755 --- a/include/poisson_solver/poisson_solver.h +++ b/include/poisson_solver/poisson_solver.h @@ -59,7 +59,7 @@ class PoissonSolver { void solvePotential(const blitz::Array charge_density); blitz::Array potential(); - // std::shared_ptr staticElectricField(); + std::shared_ptr staticElectricField(); private: GlobalBoundary bottom_boundary_; @@ -74,7 +74,7 @@ class PoissonSolver { // the potential is located on the grid corners (such that // it is defined on r=0) (note that the density_binning is taken // to be defined in the cell centers) - blitz::Array potential_; + blitz::Array potential_; //unit V blitz::Array interpolateDensityToPotentialGrid( const blitz::Array charge_density); diff --git a/src/poisson_solver/poisson_solver.cpp b/src/poisson_solver/poisson_solver.cpp index 2b3a85f..1595cf3 100755 --- a/src/poisson_solver/poisson_solver.cpp +++ b/src/poisson_solver/poisson_solver.cpp @@ -2,6 +2,7 @@ #include "simulation/errors.h" #include "simulation/geometry.h" #include "simulation/position_binning.h" +#include "constants/physical_constants.h" #include "simulation/vector_field.h" #include #include @@ -84,7 +85,6 @@ void PoissonSolver::solverIteration( 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 - const double unit_factor = 1.; // todo: change this factor to the correct value for SI for (int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) { for (int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) { @@ -108,7 +108,7 @@ void PoissonSolver::solverIteration( ((4 / dr_sq) * potential_(i + 1, j, k).value + (1 / dz_sq) * (potential_(i, j, k + 1).value + potential_(i, j, k - 1).value) + - 4 * M_PI * interpolated_density(i, j, k) * unit_factor); + interpolated_density(i, j, k)/SI::eps0); } else { const int jp1 = j + 1 > potential_.ubound(1) @@ -129,7 +129,7 @@ void PoissonSolver::solverIteration( (potential_(i, jp1, k).value + potential_(i, jm1, k).value) + (1 / dz_sq) * (potential_(i, j, k + 1).value + potential_(i, j, k - 1).value) + - 4 * M_PI * interpolated_density(i, j, k) * unit_factor); + interpolated_density(i, j, k)/SI::eps0); } } } @@ -161,7 +161,7 @@ bool PoissonSolver::converged( ((4 / dr_sq) * potential_(i + 1, j, k).value + (1 / dz_sq) * (potential_(i, j, k + 1).value + potential_(i, j, k - 1).value) + - 4 * M_PI * interpolated_density(i, j, k) * unit_factor) - + interpolated_density(i, j, k)/SI::eps0) - potential_(i, j, k).value; cumulated_quadradic_difference += std::pow(difference, 2); @@ -184,7 +184,7 @@ bool PoissonSolver::converged( (potential_(i, jp1, k).value + potential_(i, jm1, k).value) + (1 / dz_sq) * (potential_(i, j, k + 1).value + potential_(i, j, k - 1).value) + - 4 * M_PI * interpolated_density(i, j, k) * unit_factor) - + interpolated_density(i, j, k)/SI::eps0) - potential_(i, j, k).value; cumulated_quadradic_difference += std::pow(difference, 2); } @@ -301,9 +301,39 @@ blitz::Array PoissonSolver::interpolateDensityToPotentialGrid(const b return interpolatedDensity; } -// std::shared_ptr staticElectricField() { -// } +//TODO: -interpolation to the correct position in the gridpoint +// (probably already during the calculation of the values +// otherwise need to adjust the size of the E-arrays +// since e.g. Ez exists for all r Values in potential_ +std::shared_ptr PoissonSolver::staticElectricField() { + blitz::TinyVector stepsize = density_binning_->stepsize(); + blitz::TinyVector Eextent = potential_.extent() - + blitz::TinyVector(1,0,1); + blitz::Array Er(potential_.lbound(), Eextent); + blitz::Array Ephi(potential_.lbound(), Eextent); + blitz::Array Ez(potential_.lbound(), Eextent); + + Ephi = 0.; + + for(int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) { + int jp = (j+1 > potential_.ubound(1)) ? potential_.lbound(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)); + } + } + } + } + + return std::shared_ptr(new VectorFieldConstant(CylinderVector(blitz::TinyVector(0,0,0)))); +} Electrode::Electrode(double potential): potential_(potential) {}; @@ -322,12 +352,7 @@ bool RearWall::isOnElectrode(const Coordinate& position) { //PotentialGridPoint::PotentialGridPoint(BoundaryType _type, double _value): type(_type), value(_value) {}; -//TODO: write (or find): -// - interpolateDensityToPotentialGrid() <- need to understand how the potential grid -// is intended to differ from the density one -// - Electrode class -// - Rearwall class -// - constructor for Potentialgridpoint and probs for GlobalBoundary +//TODO: // look for a function that calculates the E-Field from the potential (if it doesn't exist, one has to be written) -// Note: ubound() might not be an actual function in blitz, the correct one might be ubound() -// change the update formula to SI units +// get the "main" code to also output the potential if specified(for testing purposes) +// same for the electric field \ No newline at end of file