Files
karl/include/poisson_solver/poisson_solver.h
T

89 lines
2.3 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 {
//PotentialGridPoint(BoundaryType _type, double _value);
BoundaryType type;
double value;
};
struct GlobalBoundary {
double boundary_value;
BoundaryType type;
};
class Electrode {
public:
Electrode(double potential);
virtual bool isOnElectrode(const Coordinate& position) = 0;
double electrodePotential();
protected:
const double potential_;
};
class RearWall : public Electrode {
public:
RearWall(double potential);
bool isOnElectrode(const Coordinate& position);
};
class PoissonSolver {
public:
PoissonSolver(GlobalBoundary bottom_boundary,
GlobalBoundary top_boundary,
GlobalBoundary hull_boundary,
std::shared_ptr<Geometry> geometry,
std::shared_ptr<CylinderBinning> density_binning,
std::vector<std::shared_ptr<Electrode>> electrodes,
double target_accuracy,
int num_cycles);
void solvePotential(const blitz::Array<double, 3> charge_density);
blitz::Array<double, 3> potential();
std::shared_ptr<VectorField> staticElectricField();
private:
GlobalBoundary bottom_boundary_;
GlobalBoundary top_boundary_;
GlobalBoundary hull_boundary_;
std::shared_ptr<Geometry> geometry_;
std::vector<std::shared_ptr<Electrode>> electrodes_;
std::shared_ptr<CylinderBinning> density_binning_;
double target_accuracy_;
int num_cycles_;
// 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_; //unit V
blitz::Array<double, 3> interpolateDensityToPotentialGrid(
const blitz::Array<double, 3> charge_density);
void solverIteration(const blitz::Array<double, 3>& interpolated_density);
bool converged(const blitz::Array<double, 3>& interpolated_density);
};
// Electrodes can only be dirichlet boundary conditions
#endif /* POISSON_SOLVER_H */