Restructuring of poisson solver offset;
inclusion of stride for poisson solver
This commit is contained in:
@@ -54,9 +54,12 @@ class PoissonSolver {
|
||||
CylinderBinning& density_binning,
|
||||
std::vector<std::shared_ptr<Electrode>> electrodes,
|
||||
double target_accuracy,
|
||||
int num_cycles);
|
||||
int num_cycles,
|
||||
int solver_intervall,
|
||||
int solver_offset);
|
||||
|
||||
void solvePotential(const blitz::Array<double, 3> charge_density);
|
||||
void solvePotential(const blitz::Array<double, 3> charge_density,
|
||||
int cpu_sync);
|
||||
blitz::Array<double, 3> potential();
|
||||
std::shared_ptr<VectorField> staticElectricField();
|
||||
const CylinderBinning* densityBinning();
|
||||
@@ -68,8 +71,10 @@ class PoissonSolver {
|
||||
std::shared_ptr<Geometry> geometry_;
|
||||
std::vector<std::shared_ptr<Electrode>> electrodes_;
|
||||
const CylinderBinning density_binning_;
|
||||
double target_accuracy_;
|
||||
int num_cycles_;
|
||||
const double target_accuracy_;
|
||||
const int num_cycles_;
|
||||
const int solver_intervall_;
|
||||
const int solver_offset_;
|
||||
|
||||
// density binning defined on the cell centers, potential defined
|
||||
// such that it exists on the cell edges so that the azimuthal
|
||||
|
||||
@@ -30,6 +30,20 @@ namespace generator {
|
||||
|
||||
auto boundaries = buildBoundaries(parameter, {"PoissonSolver", "Boundary"});
|
||||
|
||||
int solver_intervall = json_int(json_object_by_path(object, {"Intervall"}));
|
||||
if (solver_intervall == 0 &&
|
||||
json_string(json_object_by_path(
|
||||
object, {"Intervall"})) == "EachSync") {
|
||||
solver_intervall = 1;
|
||||
}
|
||||
ASSERT_POSITIVE(&solver_intervall,
|
||||
"The intervall for poisson solver stride must be positive"
|
||||
" or 'EachSync'");
|
||||
|
||||
int solver_offset = json_int(json_object_by_path(object, {"Offset"}));
|
||||
ASSERT_NOTNEGATIVE(&solver_offset,
|
||||
"The offset for poisson solver has to be non-negative");
|
||||
|
||||
std::vector<std::shared_ptr<Electrode>> electrodes{};
|
||||
|
||||
double target_accuracy = parameter.doubleValue(
|
||||
@@ -40,7 +54,7 @@ namespace generator {
|
||||
|
||||
return std::shared_ptr<PoissonSolver>(new PoissonSolver(boundaries.at("Bottom"),
|
||||
boundaries.at("Top"), boundaries.at("Hull"), geometry, position_binning,
|
||||
electrodes, target_accuracy, num_cycles));
|
||||
electrodes, target_accuracy, num_cycles, solver_intervall, solver_offset));
|
||||
}
|
||||
|
||||
std::map<std::string, GlobalBoundary> buildBoundaries(Parameter& parameter,
|
||||
|
||||
@@ -15,7 +15,9 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
|
||||
CylinderBinning& density_binning,
|
||||
std::vector<std::shared_ptr<Electrode>> electrodes,
|
||||
double target_accuracy,
|
||||
int num_cycles)
|
||||
int num_cycles,
|
||||
int solver_intervall,
|
||||
int solver_offset)
|
||||
: bottom_boundary_(bottom_boundary),
|
||||
top_boundary_(top_boundary),
|
||||
hull_boundary_(hull_boundary),
|
||||
@@ -30,7 +32,9 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
|
||||
density_binning.binIndexMax()(2)))),
|
||||
electrodes_(electrodes),
|
||||
target_accuracy_(target_accuracy),
|
||||
num_cycles_(num_cycles) {
|
||||
num_cycles_(num_cycles),
|
||||
solver_intervall_(solver_intervall),
|
||||
solver_offset_(solver_offset) {
|
||||
|
||||
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
|
||||
for (int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) {
|
||||
@@ -75,7 +79,29 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
|
||||
blitz::Range(density_binning.binIndexMin()(2),
|
||||
density_binning.binIndexMax()(2)));
|
||||
zero_chargedensity = 0.;
|
||||
solvePotential(zero_chargedensity);
|
||||
solvePotential(zero_chargedensity, 0);
|
||||
}
|
||||
|
||||
void PoissonSolver::solvePotential(
|
||||
const blitz::Array<double, 3> charge_density, int cpu_sync) {
|
||||
if ((cpu_sync % solver_intervall_ != 0) || ((cpu_sync <= solver_offset_)
|
||||
&& (cpu_sync > 0))) {
|
||||
return;
|
||||
}
|
||||
DEBUG_LEVEL_3("Interpolating chargedensity.");
|
||||
blitz::Array<double, 3> interpolated_density =
|
||||
interpolateDensityToPotentialGrid(charge_density);
|
||||
int it = 1;
|
||||
do {
|
||||
solverIteration(interpolated_density);
|
||||
if (it % 1000 == 0) {
|
||||
DEBUG_LEVEL_3("Poisson solver, iteration: " + std::to_string(it));
|
||||
if (converged(interpolated_density)) {
|
||||
break;
|
||||
};
|
||||
}
|
||||
++it;
|
||||
} while (it < num_cycles_);
|
||||
}
|
||||
|
||||
void PoissonSolver::solverIteration(
|
||||
@@ -223,24 +249,6 @@ bool PoissonSolver::converged(
|
||||
return normalized_difference < target_accuracy_;
|
||||
}
|
||||
|
||||
void PoissonSolver::solvePotential(
|
||||
const blitz::Array<double, 3> charge_density) {
|
||||
DEBUG_LEVEL_3("Interpolating chargedensity.");
|
||||
blitz::Array<double, 3> interpolated_density =
|
||||
interpolateDensityToPotentialGrid(charge_density);
|
||||
int it = 1;
|
||||
do {
|
||||
solverIteration(interpolated_density);
|
||||
if (it % 1000 == 0) {
|
||||
DEBUG_LEVEL_3("Poisson solver, iteration: " + std::to_string(it));
|
||||
if (converged(interpolated_density)) {
|
||||
break;
|
||||
};
|
||||
}
|
||||
++it;
|
||||
} while (it < num_cycles_);
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> PoissonSolver::potential() {
|
||||
// there might be a better way to do this... (if one can do array.memberValue without
|
||||
// explicitely looping)
|
||||
@@ -346,6 +354,10 @@ std::shared_ptr<VectorField> PoissonSolver::staticElectricField() {
|
||||
Eextent(0)*stepsize(0), Eextent(2)*stepsize(2)));
|
||||
}
|
||||
|
||||
const CylinderBinning* PoissonSolver::densityBinning() {
|
||||
return &density_binning_;
|
||||
}
|
||||
|
||||
Electrode::Electrode(double potential): potential_(potential) {};
|
||||
|
||||
double Electrode::electrodePotential() {
|
||||
@@ -360,9 +372,4 @@ RearWall::RearWall(double potential): Electrode(potential) {};
|
||||
bool RearWall::isOnElectrode(const Coordinate& position) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const CylinderBinning* PoissonSolver::densityBinning() {
|
||||
return &density_binning_;
|
||||
}
|
||||
//PotentialGridPoint::PotentialGridPoint(BoundaryType _type, double _value): type(_type), value(_value) {};
|
||||
|
||||
@@ -97,10 +97,6 @@ void Simulation::start() {
|
||||
parameter_.intValue(json_path({"Simulation", "EventStride"}), 1);
|
||||
const int total_simulated_events =
|
||||
parameter_.intValue(json_path({"Simulation", "SimulatedEvents"}), 1);
|
||||
// Minimum number of cpu syncs before the potential is done the first time
|
||||
// afterwards the potential is recalculated every cpu sync (maybe change to a stride)
|
||||
const int poisson_offset =
|
||||
parameter_.intValue(json_path({"Simulation", "PoissonOffset"}), 0);
|
||||
SIM_INFO("Total simulated events: " + std::to_string(total_simulated_events));
|
||||
SIM_INFO("Simulated events before cpu sync: " + std::to_string(event_stride));
|
||||
const int events_this_cpu = eventsThisCpu(total_simulated_events);
|
||||
@@ -125,10 +121,9 @@ void Simulation::start() {
|
||||
|
||||
SIM_INFO("Poisson step.");
|
||||
SimulationTimer::eventStartPoint(std::string("PoissonStep"));
|
||||
if(num_cpu_syncs > poisson_offset) {
|
||||
poisson_solver_->solvePotential(chargedensity());
|
||||
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
|
||||
}
|
||||
poisson_solver_->solvePotential(chargedensity(), num_cpu_syncs);
|
||||
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
|
||||
|
||||
SimulationTimer::eventStopPoint(std::string("PoissonStep"));
|
||||
|
||||
SIM_INFO("Perform output.");
|
||||
|
||||
Reference in New Issue
Block a user