Implemented pitch angle resolution.

Still includes (and uses) the non-pitch angle
resolved fields as well; have to be either removed
completely or refactored s.t. one of the two options
is chosen.
Pitch angle distribution has a hardcoded number of
bins for now, and exists in 'energy_binning.h'
This commit is contained in:
2024-10-28 15:00:19 +01:00
parent b4cbd8c44c
commit 5fc227e1b1
24 changed files with 1126 additions and 42 deletions
+62 -19
View File
@@ -109,21 +109,44 @@ void Simulation::start() {
const int event_stride =
parameter_.intValue(json_path({"Simulation", "EventStride"}), 1);
const int total_simulated_events =
parameter_.intValue(json_path({"Simulation", "SimulatedEvents"}), 1);
// const int total_simulated_events =
// parameter_.intValue(json_path({"Simulation", "SimulatedEvents"}), 1);
const int number_timesteps = parameter_.intValue(json_path({"Simulation",
"NumberTimesteps"}), 1);
const int time_resolution_events =
parameter_.intValue(json_path({"Simulation", "TimeResolutionEvents"}),
total_simulated_events);
MpiCommunication::mpiSize());
const int density_events =
parameter_.intValue(json_path({"Simulation", "DensityEventsPerCPU"}), 0);
DEBUG_LEVEL_0("Density events per cpu: " + std::to_string(density_events));
SIM_INFO("Total simulated events: " + std::to_string(total_simulated_events));
// if(total_simulated_events % MpiCommunication::mpiSize() != 0) {
// ERROR("total simulated events are not divisible by the number of mpi procs");
// }
// if(time_resolution_events % MpiCommunication::mpiSize() != 0) {
// ERROR("time resolution events are not divisible by the number of mpi procs");
// }
// SIM_INFO("Total simulated events: " + std::to_string(total_simulated_events));
SIM_INFO("Number of Timesteps: " + std::to_string(number_timesteps));
SIM_INFO("Simulated events before cpu sync: " + std::to_string(event_stride));
const int events_this_cpu = eventsThisCpu(total_simulated_events);
// const int events_this_cpu = eventsThisCpu(total_simulated_events);
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;
if(time_resolution_events % MpiCommunication::mpiSize() != 0) {
if(time_resolution_events % MpiCommunication::mpiSize() <= MpiCommunication::mpiRank() &&
time_resolution_this_cpu % event_stride == 0) {
ERROR("Code will not terminate! The event stride: " + std::to_string(event_stride) +
", the number of CPUs: " + std::to_string(MpiCommunication::mpiSize()) +
" and the number of events per timestep: " + std::to_string(time_resolution_events) +
" create at least one CPU for which the number of CPU syncs for one timestep " +
" differs from the rest of the CPUs.");
}
}
SIM_INFO("Events per cpu (approx.) per timestep: " +
std::to_string(time_resolution_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();
@@ -154,25 +177,34 @@ void Simulation::start() {
int num_cpu_syncs = 0;
bool reset = true;
int timesteps = 0;
queue_.reserve(100);
timer_->increaseTimestep(delta_t);
while (leftover_events > 0) {
while (timesteps < number_timesteps) {
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, leftover_events_time_resolution);
SIM_INFO("Leftover events on first cpu: " +
std::to_string(leftover_events));
SIM_INFO("Leftover timesteps this CPU: " + std::to_string(number_timesteps - timesteps));
SIM_INFO("Leftover events this timestep this CPU: " +
std::to_string(leftover_events_time_resolution));
processEvents(events_of_cylcle, density_events, num_cpu_syncs);
DEBUG_LEVEL_1("Leftover events: " + std::to_string(leftover_events));
leftover_events -= events_of_cylcle;
DEBUG_LEVEL_1("Leftover timesteps: " + std::to_string(number_timesteps - timesteps));
DEBUG_LEVEL_1("Leftover events this timestep: " +
std::to_string(leftover_events_time_resolution));
// leftover_events -= events_of_cylcle;
leftover_events_time_resolution -= events_of_cylcle;
// Problem: proc 0: simuliert erst 2 dann 1
// proc 1: simuliert nur 2
// timestep besteht aus (2+1) + 2, aber die jetzt wird es noch zu
// 2 + 2, 1 + 2, in den syncs, das führt dazu, dass jede sync von proc 1
// als timestep gezählt wird, während proc 0 nur jede 2. sync eine timestep ist
reset = !(leftover_events_time_resolution > 0);
SIM_INFO("Cpu sync.");
@@ -208,6 +240,7 @@ void Simulation::start() {
timer_->increaseTimestep(delta_t);
for(auto& pair : tracked_species_) {
pair.second->dynamicDensityField()->resetDynamicDensityField();
pair.second->dynamicDensityFieldWithPitchAngle()->resetDynamicDensityField();
// questionable if they need to be reset:
// + time res in current
@@ -219,6 +252,7 @@ void Simulation::start() {
// pair.second->deletionLogger()->resetDeletionLogger();
}
leftover_events_time_resolution = time_resolution_this_cpu;
timesteps++;
}
}
}
@@ -263,7 +297,8 @@ void Simulation::processEvents(int events, int density_events, int cpu_syncs) {
std::to_string(current_density_event));
//maybe use a different event name?
SimulationTimer::eventStartPoint(std::string("DensityParticleInjection"));
new_particles = determineInjectedDensityParticles(random_.get(), density_events, current_density_event);
new_particles = determineInjectedDensityParticles(random_.get(), density_events,
current_density_event);
SimulationTimer::eventStopPoint(std::string("DensityParticleInjection"));
#if defined debug_level3
for(auto& particle : new_particles) {
@@ -456,19 +491,27 @@ std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
// which does not change except after a timestep, but think the rejection method is
// much more time consuming anyways... might optimize in the future
// particle number of the denstiy, i.e. the integral over the density
const double particleNumberDensity =
const double particleNumberFromDensity =
pair.second->densityForDrawing()->particleNumber();
if (particleNumberDensity == 0) {
const double particleNumberFromDensity_ =
pair.second->dynamicDensityFieldWithPitchAngleForDrawing()->particleNumber();
if (particleNumberFromDensity == 0) {
DEBUG_LEVEL_3("No particles in density of species: " + pair.second->name());
continue;
}
if (current == 0) {
DEBUG_LEVEL_0("particle number " + pair.second->name() + ": " + std::to_string(particleNumberDensity));
if (current == 0 || true) {
std::stringstream out;
out << pair.second->name();
out << "difference: ";
out << std::fabs(particleNumberFromDensity_ - particleNumberFromDensity)/particleNumberFromDensity;
DEBUG_LEVEL_0(out.str());
}
injector_->rollNewParticleFromDensityField(random->engine(),
pair.second,
new_particles,
particleNumberDensity/numberParticlesToDraw/MpiCommunication::mpiSize(),
new_particles,
magnetic_field_,
particleNumberFromDensity/numberParticlesToDraw/MpiCommunication::mpiSize(),
injection_time);
}
return new_particles;