minor corrections, beginning of electric field calc
This commit is contained in:
@@ -59,7 +59,7 @@ class PoissonSolver {
|
||||
|
||||
void solvePotential(const blitz::Array<double, 3> charge_density);
|
||||
blitz::Array<double, 3> potential();
|
||||
// std::shared_ptr<VectorField> staticElectricField();
|
||||
std::shared_ptr<VectorField> 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<PotentialGridPoint, 3> potential_;
|
||||
blitz::Array<PotentialGridPoint, 3> potential_; //unit V
|
||||
|
||||
blitz::Array<double, 3> interpolateDensityToPotentialGrid(
|
||||
const blitz::Array<double, 3> charge_density);
|
||||
|
||||
@@ -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 <memory>
|
||||
#include <string>
|
||||
@@ -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<double, 3> PoissonSolver::interpolateDensityToPotentialGrid(const b
|
||||
return interpolatedDensity;
|
||||
}
|
||||
|
||||
// std::shared_ptr<VectorField> 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<VectorField> PoissonSolver::staticElectricField() {
|
||||
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);
|
||||
blitz::Array<double, 3> Ephi(potential_.lbound(), Eextent);
|
||||
blitz::Array<double, 3> 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<VectorField>(new VectorFieldConstant(CylinderVector(blitz::TinyVector<double, 3>(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
|
||||
Reference in New Issue
Block a user