Files

111 lines
3.0 KiB
C++
Executable File

#ifndef POISSON_SOLVER_H
#define POISSON_SOLVER_H
#include "blitz/array.h"
#include "simulation/vector_field.h"
#include <memory>
// for now put the electric field calculation into
// the poisson solver
class Geometry;
class CylinderBinning;
enum class BoundaryType {
no_boundary,
dirichlet,
neumann_to_top,
neumann_to_bottom,
neumann_to_hull
};
struct PotentialGridPoint {
BoundaryType type;
double value;
};
struct GlobalBoundary {
double boundary_value;
BoundaryType type;
};
// only useful at the initialization of the PoissonSolver...
// (or if at later times a time dependent value is desired)
class Electrode {
public:
Electrode(double potential);
virtual bool isOnElectrode(const Coordinate& position) = 0;
virtual double electrodePotential();
protected:
const double potential_;
};
class RearWall : public Electrode {
public:
RearWall(double potential);
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
class PoissonSolver {
public:
PoissonSolver(GlobalBoundary bottom_boundary,
GlobalBoundary top_boundary,
GlobalBoundary hull_boundary,
std::shared_ptr<Geometry> geometry,
CylinderBinning& density_binning,
std::vector<std::shared_ptr<Electrode>> electrodes,
double target_accuracy,
int num_cycles,
bool do_solver);
void solvePotential(const blitz::Array<double, 2> charge_density);
blitz::Array<double, 2> potential();
std::shared_ptr<VectorField> staticElectricField();
const CylinderBinning* densityBinning();
void setPotential(blitz::Array<double, 2>& potential);
private:
GlobalBoundary bottom_boundary_;
GlobalBoundary top_boundary_;
GlobalBoundary hull_boundary_;
std::shared_ptr<Geometry> geometry_;
std::vector<std::shared_ptr<Electrode>> electrodes_;
const CylinderBinning density_binning_;
const double target_accuracy_;
const int num_cycles_;
const bool do_solver_;
// density binning defined on the cell centers, potential defined
// such that it exists on the cell edges so that the azimuthal
// position is the same as the one of the density binning
blitz::Array<PotentialGridPoint, 2> potential_; //unit V
blitz::Array<double, 2> interpolateDensityToPotentialGrid(
const blitz::Array<double, 2> charge_density);
void solverIteration(const blitz::Array<double, 2>& interpolated_density);
bool converged(const blitz::Array<double, 2>& interpolated_density);
};
// Electrodes can only be dirichlet boundary conditions
#endif /* POISSON_SOLVER_H */