Changed initializtion of potential-grid, included

a variable for minimum cycles before first poisson solution
This commit is contained in:
2024-01-29 11:21:07 +01:00
parent 3a802d8f8d
commit 331e887f04
5 changed files with 54 additions and 34 deletions
+8
View File
@@ -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_;
@@ -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",
+22 -31
View File
@@ -33,22 +33,29 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
num_cycles_(num_cycles) {
// set inner values
blitz::TinyVector<double, 3> 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<double, 3>(
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
+14
View File
@@ -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<double, 3> 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;
}
}
+7 -1
View File
@@ -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());