Poisson step and resets only after time resolution

This commit is contained in:
2024-05-15 09:12:43 +02:00
parent 77fa8d175a
commit fcbff96f17
4 changed files with 29 additions and 44 deletions
+3 -7
View File
@@ -55,12 +55,10 @@ class PoissonSolver {
std::vector<std::shared_ptr<Electrode>> electrodes,
double target_accuracy,
int num_cycles,
int solver_intervall,
int solver_offset,
bool reset_after_solving);
bool do_solver);
void solvePotential(const blitz::Array<double, 3> charge_density,
int cpu_sync, bool& reset);
const bool solve);
blitz::Array<double, 3> potential();
std::shared_ptr<VectorField> staticElectricField();
const CylinderBinning* densityBinning();
@@ -74,9 +72,7 @@ class PoissonSolver {
const CylinderBinning density_binning_;
const double target_accuracy_;
const int num_cycles_;
const int solver_intervall_;
const int solver_offset_;
const bool reset_after_solving_;
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
+3 -18
View File
@@ -30,20 +30,6 @@ 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(
@@ -52,13 +38,12 @@ namespace generator {
int num_cycles = parameter.intValue(json_path_append({"PoissonSolver"},
{"NumCycles"}));
bool reset_after_solving = parameter.boolValue(
json_path_append({"PoissonSolver"}, {"ResetAfterSolving"}), false);
bool do_solver = parameter.boolValue(
json_path_append({"PoissonSolver"}, {"DoSolver"}), false);
return std::shared_ptr<PoissonSolver>(new PoissonSolver(boundaries.at("Bottom"),
boundaries.at("Top"), boundaries.at("Hull"), geometry, position_binning,
electrodes, target_accuracy, num_cycles, solver_intervall, solver_offset,
reset_after_solving));
electrodes, target_accuracy, num_cycles, do_solver));
}
std::map<std::string, GlobalBoundary> buildBoundaries(Parameter& parameter,
+5 -14
View File
@@ -16,9 +16,7 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
std::vector<std::shared_ptr<Electrode>> electrodes,
double target_accuracy,
int num_cycles,
int solver_intervall,
int solver_offset,
bool reset_after_solving)
bool do_solver)
: bottom_boundary_(bottom_boundary),
top_boundary_(top_boundary),
hull_boundary_(hull_boundary),
@@ -34,9 +32,7 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
electrodes_(electrodes),
target_accuracy_(target_accuracy),
num_cycles_(num_cycles),
solver_intervall_(solver_intervall),
solver_offset_(solver_offset),
reset_after_solving_(reset_after_solving) {
do_solver_(do_solver) {
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
for (int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) {
@@ -81,16 +77,12 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
blitz::Range(density_binning.binIndexMin()(2),
density_binning.binIndexMax()(2)));
zero_chargedensity = 0.;
bool reset;
solvePotential(zero_chargedensity, 0, reset);
solvePotential(zero_chargedensity, true);
}
void PoissonSolver::solvePotential(
const blitz::Array<double, 3> charge_density, int cpu_sync,
bool& reset) {
if ((cpu_sync % solver_intervall_ != 0) || ((cpu_sync <= solver_offset_)
&& (cpu_sync > 0))) {
reset = false;
const blitz::Array<double, 3> charge_density, const bool solve) {
if (!(do_solver_) && !(solve)) {
return;
}
DEBUG_LEVEL_3("Interpolating chargedensity.");
@@ -107,7 +99,6 @@ void PoissonSolver::solvePotential(
}
++it;
} while (it < num_cycles_);
reset = reset_after_solving_;
}
void PoissonSolver::solverIteration(
+18 -5
View File
@@ -110,18 +110,24 @@ void Simulation::start() {
const int time_resolution_this_cpu = eventsThisCpu(time_resolution_events);
SIM_INFO("Events per cpu (approx.): " + std::to_string(events_this_cpu));
int leftover_events = events_this_cpu;
int leftover_events_time_resolution = time_resolution_this_cpu;
const double delta_t = time_resolution_events*injector_->timePassed();
int num_cpu_syncs = 0;
bool reset = false;
bool reset = true;
std::vector<particle::Particle> backup_queue;
backup_queue.reserve(100); // probably should be a more sensible value
// bring some order into the reset checks
while (leftover_events > 0) {
timer_->increaseTimestep(time_resolution_events*injector_->timePassed());
if(reset)
timer_->increaseTimestep(delta_t);
std::stringstream out;
out << "Timeinterval: " << timer_->time() << "s.";
out << "\n size of particle: " << sizeof(particle::Particle);
DEBUG_LEVEL_3(out.str());
int events_of_cylcle = eventsOfCycle(event_stride, time_resolution_this_cpu);
int events_of_cylcle = eventsOfCycle(event_stride, leftover_events_time_resolution);
SIM_INFO("Leftover events on first cpu: " +
std::to_string(leftover_events));
processEvents(events_of_cylcle, backup_queue, time_resolution_events);
@@ -129,6 +135,9 @@ void Simulation::start() {
DEBUG_LEVEL_1("Leftover events: " + std::to_string(leftover_events));
leftover_events -= events_of_cylcle;
leftover_events_time_resolution -= events_of_cylcle;
reset = !(leftover_events_time_resolution > 0);
SIM_INFO("Cpu sync.");
SimulationTimer::eventStartPoint(std::string("CpuSync"));
@@ -138,7 +147,7 @@ void Simulation::start() {
SIM_INFO("Poisson step.");
SimulationTimer::eventStartPoint(std::string("PoissonStep"));
poisson_solver_->solvePotential(chargedensity(), num_cpu_syncs, reset);
poisson_solver_->solvePotential(chargedensity(), reset);
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
SimulationTimer::eventStopPoint(std::string("PoissonStep"));
@@ -161,6 +170,10 @@ void Simulation::start() {
pair.second->lastSyncDeletionLogger()->resetDeletionLogger();
}
}
if ((leftover_events > 0) && reset) {
leftover_events_time_resolution = time_resolution_this_cpu;
}
}
}
@@ -175,7 +188,7 @@ void Simulation::processEvents(int events,
std::vector<particle::Particle> particle_queue;
particle_queue.reserve(100);
DEBUG_LEVEL_3("Move backup to processing queue.");
// highly inefficient in case that #cpu_syncs/time_res >> 1
// highly inefficient in case that #cpu_syncs/time_res >> 1, i.e. backup queue is large
particle_queue.insert(particle_queue.end(), backup_queue.begin(),
backup_queue.end());
// clean backup_queue after moving the elements to the particle queue