From 331e887f04f39efd2ca2e81432dd0959987cf9a3 Mon Sep 17 00:00:00 2001 From: Christian Sendlinger Date: Mon, 29 Jan 2024 11:21:07 +0100 Subject: [PATCH] Changed initializtion of potential-grid, included a variable for minimum cycles before first poisson solution --- include/simulation/geometry.h | 8 +++ simulation_config/test_poisson_parameter.json | 5 +- src/poisson_solver/poisson_solver.cpp | 53 ++++++++----------- src/simulation/geometry.cpp | 14 +++++ src/simulation/simulation.cpp | 8 ++- 5 files changed, 54 insertions(+), 34 deletions(-) diff --git a/include/simulation/geometry.h b/include/simulation/geometry.h index 59923f5..a5e639f 100755 --- a/include/simulation/geometry.h +++ b/include/simulation/geometry.h @@ -3,15 +3,23 @@ #include "simulation/coordinates.h" +enum class GeometryPositioning { + bottom, + top, + hull, + inside +}; class Geometry { public: virtual bool isInside(const Coordinate& position) const = 0; + virtual GeometryPositioning isWhere(const Coordinate& position) const = 0; }; class Cylinder : public Geometry { public: Cylinder(double radius, double height); bool isInside(const Coordinate& position) const; + GeometryPositioning isWhere(const Coordinate& position) const; private: const double radius_; diff --git a/simulation_config/test_poisson_parameter.json b/simulation_config/test_poisson_parameter.json index dc686dc..67c6166 100755 --- a/simulation_config/test_poisson_parameter.json +++ b/simulation_config/test_poisson_parameter.json @@ -16,7 +16,7 @@ } }, "Azimuthal": { - "NumberOfBins": 1 + "NumberOfBins": 4 } } }, @@ -590,7 +590,8 @@ }, "Simulation": { "SimulatedEvents": 1, - "EventStride": 1 + "EventStride": 1, + "PoissonOffset": 0 }, "Output": { "folder": "output", diff --git a/src/poisson_solver/poisson_solver.cpp b/src/poisson_solver/poisson_solver.cpp index b68e187..154aa99 100755 --- a/src/poisson_solver/poisson_solver.cpp +++ b/src/poisson_solver/poisson_solver.cpp @@ -33,22 +33,29 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary, num_cycles_(num_cycles) { // set inner values blitz::TinyVector stepsize = density_binning_.stepsize(); - for (int i = potential_.lbound(0); i <= potential_.ubound(0) - 1; ++i) { + for (int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) { for (int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) { - for (int k = potential_.lbound(2) + 1; k <= potential_.ubound(2) - 1; + for (int k = potential_.lbound(2); k <= potential_.ubound(2); ++k) { - potential_(i,j,k).type = BoundaryType::no_boundary; - potential_(i,j,k).value = 0.; - CylinderCoordinate position(blitz::TinyVector( i * stepsize(0), j * stepsize(1), k * stepsize(2))); -// does not make sense, either resize the potential array or include -// check which boundary it is and use the global boundary condition -// or throw an error, because otherwise there should be an error with the density binning - if (!geometry_->isInside(position)) { - //DEBUG_LEVEL_0("Binning is larger than the Geometry."); - potential_(i,j,k).type = BoundaryType::no_boundary; - potential_(i,j,k).value = 0.; + + switch(geometry_->isWhere(position)) { + case GeometryPositioning::bottom: + potential_(i,j,k) = {bottom_boundary_.type, bottom_boundary_.boundary_value}; + break; + case GeometryPositioning::top: + potential_(i,j,k) = {top_boundary_.type, top_boundary_.boundary_value}; + break; + case GeometryPositioning::hull: + potential_(i,j,k) = {hull_boundary_.type, hull_boundary_.boundary_value}; + break; + case GeometryPositioning::inside: + potential_(i,j,k) = {BoundaryType::no_boundary, 0.}; + break; + default: + ERROR("Something went terribly wrong. Position is nowhere."); + break; } for (auto& electrode : electrodes_) { if (electrode->isOnElectrode(position)) { @@ -59,25 +66,6 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary, } } } - - //does not yet make sense. Should be the boundaries for the boundary - // of the geometry, right now it's the boundary of the potential array - // set global boundary - PotentialGridPoint tempGridPoint{}; - tempGridPoint.type = bottom_boundary_.type; - tempGridPoint.value = bottom_boundary_.boundary_value; - potential_(blitz::Range::all(), blitz::Range::all(), potential_.lbound(2)) = - tempGridPoint; //hopefully by value and not by reference... - - tempGridPoint.type = top_boundary_.type; - tempGridPoint.value = top_boundary_.boundary_value; - potential_(blitz::Range::all(), blitz::Range::all(), potential_.ubound(2)) = - tempGridPoint; - - tempGridPoint.type = hull_boundary_.type; - tempGridPoint.value = hull_boundary_.boundary_value; - potential_(potential_.ubound(0), blitz::Range::all(), blitz::Range::all()) = - tempGridPoint; } void PoissonSolver::solverIteration( @@ -158,6 +146,9 @@ bool PoissonSolver::converged( for (int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) { for (int k = potential_.lbound(2) + 1; k <= potential_.ubound(2) - 1; ++k) { + if(potential_(i,j,k).type != BoundaryType::no_boundary) { + continue; + } if (i == 0) { // special calculation for r=0 //Note: the value \phi_{i,j+Nj/2,k} as the replacement of diff --git a/src/simulation/geometry.cpp b/src/simulation/geometry.cpp index 5616f4b..58e99fd 100755 --- a/src/simulation/geometry.cpp +++ b/src/simulation/geometry.cpp @@ -9,3 +9,17 @@ bool Cylinder::isInside(const Coordinate& position) const { return (cylinder_position(0) < radius_) && (cylinder_position(2) < height_) && (cylinder_position(2) > 0); } + +GeometryPositioning Cylinder::isWhere(const Coordinate& position) const { + const blitz::TinyVector cylinder_position = + position.cylinderEntries(); + if(cylinder_position(0) >= radius_) { + return GeometryPositioning::hull; + } else if (cylinder_position(2) <= 0) { + return GeometryPositioning::bottom; + } else if (cylinder_position(2) >= height_) { + return GeometryPositioning::top; + } else { + return GeometryPositioning::inside; + } +} diff --git a/src/simulation/simulation.cpp b/src/simulation/simulation.cpp index 9dc33bc..c638f32 100755 --- a/src/simulation/simulation.cpp +++ b/src/simulation/simulation.cpp @@ -95,6 +95,10 @@ 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); @@ -119,7 +123,9 @@ void Simulation::start() { SIM_INFO("Poisson step."); SimulationTimer::eventStartPoint(std::string("PoissonStep")); - poisson_solver_->solvePotential(chargedensity()); + if(num_cpu_syncs > poisson_offset) { + poisson_solver_->solvePotential(chargedensity()); + } SimulationTimer::eventStopPoint(std::string("PoissonStep")); electric_field_->updateDynamicField(poisson_solver_->staticElectricField());