If interaction and timeres reached at same
time log only after interaction. Some debug stuff
This commit is contained in:
@@ -90,6 +90,11 @@ class Simulation {
|
|||||||
std::shared_ptr<CpuSynchronizer> cpu_synchronizer_;
|
std::shared_ptr<CpuSynchronizer> cpu_synchronizer_;
|
||||||
|
|
||||||
std::vector<particle::Particle> queue_;
|
std::vector<particle::Particle> queue_;
|
||||||
|
|
||||||
|
#ifdef debug
|
||||||
|
double phyLossAtWallIon = 0;
|
||||||
|
double createdDensity = 0;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SIMULATION_H */
|
#endif /* SIMULATION_H */
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ void BorisMover::move(particle::Particle* particle,
|
|||||||
old_mu = kinematic::cosPitchAngle(
|
old_mu = kinematic::cosPitchAngle(
|
||||||
B_old, particle->velocity().cartesianEntries(old_position_cart));
|
B_old, particle->velocity().cartesianEntries(old_position_cart));
|
||||||
}
|
}
|
||||||
|
new_mu = old_mu;
|
||||||
|
|
||||||
double timestep = 0;
|
double timestep = 0;
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ void BorisMover::move(particle::Particle* particle,
|
|||||||
bool changed_energy_bin = false;
|
bool changed_energy_bin = false;
|
||||||
bool left_simulation_domain = false;
|
bool left_simulation_domain = false;
|
||||||
bool changed_mu_bin = false;
|
bool changed_mu_bin = false;
|
||||||
bool died_in_bin = false;
|
bool died_in_bin = particle->specie()->terminator()->reachedMaxTimeAlive(particle);
|
||||||
|
|
||||||
while (
|
while (
|
||||||
!(changed_position_bin || changed_energy_bin || left_simulation_domain ||
|
!(changed_position_bin || changed_energy_bin || left_simulation_domain ||
|
||||||
@@ -130,6 +131,19 @@ void BorisMover::move(particle::Particle* particle,
|
|||||||
changed_energy_bin =
|
changed_energy_bin =
|
||||||
particle->specie()->dynamicDensityField()->changedEnergyBin(
|
particle->specie()->dynamicDensityField()->changedEnergyBin(
|
||||||
old_kinetic_energy, particle->kineticEnergy_eV());
|
old_kinetic_energy, particle->kineticEnergy_eV());
|
||||||
|
// #ifdef debug
|
||||||
|
// if(changed_energy_bin &&
|
||||||
|
// particle->specie()->type() == species::ImplementedSpecies::Tplus) {
|
||||||
|
// std::stringstream out;
|
||||||
|
// out << "Changed energy bin from: " << particle->specie()->dynamicDensityField()
|
||||||
|
// ->energyBinning()->bin(old_kinetic_energy);
|
||||||
|
// out << " (" << old_kinetic_energy << ") to: ";
|
||||||
|
// out << particle->specie()->dynamicDensityField()->energyBinning()
|
||||||
|
// ->bin(particle->kineticEnergy_eV());
|
||||||
|
// out << " (" << particle->kineticEnergy_eV() << ")\n";
|
||||||
|
// DEBUG(out.str());
|
||||||
|
// }
|
||||||
|
// #endif
|
||||||
|
|
||||||
left_simulation_domain =
|
left_simulation_domain =
|
||||||
particle->specie()->terminator()->leftSimulationDomain(particle);
|
particle->specie()->terminator()->leftSimulationDomain(particle);
|
||||||
@@ -147,15 +161,15 @@ void BorisMover::move(particle::Particle* particle,
|
|||||||
? delta_timeresolution*SimConstants::compare_epsilon
|
? delta_timeresolution*SimConstants::compare_epsilon
|
||||||
: (max_time_alive - timestep);
|
: (max_time_alive - timestep);
|
||||||
}
|
}
|
||||||
if(died_in_bin && !left_simulation_domain) {
|
if(died_in_bin && !left_simulation_domain
|
||||||
|
&& (leftover_time > SimConstants::compare_epsilon ||
|
||||||
|
changed_energy_bin || changed_mu_bin || changed_position_bin)) {
|
||||||
// use new values, since that is necessary if died_in_bin and a change in
|
// use new values, since that is necessary if died_in_bin and a change in
|
||||||
// bin can occur at the same time
|
// bin can occur at the same time
|
||||||
particle->specie()->dynamicDensityField()->logMovement(
|
particle->specie()->dynamicDensityField()->logMovement(
|
||||||
particle->cylinderPosition(), particle->kineticEnergy_eV(), new_mu,
|
particle->cylinderPosition(), particle->kineticEnergy_eV(), new_mu,
|
||||||
particle->weight());
|
particle->weight());
|
||||||
#ifdef debug
|
|
||||||
particle->deposited();
|
particle->deposited();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
// particle->resetTimeInBin();
|
// particle->resetTimeInBin();
|
||||||
particle->specie()->currentCollector()->collect(particle, old_position_cyl);
|
particle->specie()->currentCollector()->collect(particle, old_position_cyl);
|
||||||
|
|||||||
@@ -270,7 +270,21 @@ void Simulation::start() {
|
|||||||
SimulationTimer::eventStartPoint("Reset");
|
SimulationTimer::eventStartPoint("Reset");
|
||||||
if(reset) {
|
if(reset) {
|
||||||
SIM_INFO("Do resets and increase the timestep for timeresolution.");
|
SIM_INFO("Do resets and increase the timestep for timeresolution.");
|
||||||
|
#ifdef debug
|
||||||
|
std::stringstream out;
|
||||||
|
out << "Ions (T+) lost at wall (physical value): " << phyLossAtWallIon;
|
||||||
|
phyLossAtWallIon = 0.;
|
||||||
|
double total_tp = 0;
|
||||||
|
double total_tp_sync = 0.;
|
||||||
|
#endif
|
||||||
for(auto& pair : tracked_species_) {
|
for(auto& pair : tracked_species_) {
|
||||||
|
#ifdef debug
|
||||||
|
if(pair.second->type() == species::ImplementedSpecies::Tplus) {
|
||||||
|
total_tp = blitz::sum(pair.second->dynamicDensityField()->timeInBinArray());
|
||||||
|
total_tp_sync = blitz::sum(
|
||||||
|
pair.second->densityForDrawing()->timeInBinArray());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
pair.second->dynamicDensityField()->resetDynamicDensityField();
|
pair.second->dynamicDensityField()->resetDynamicDensityField();
|
||||||
|
|
||||||
pair.second->currentCollector()->resetCurrentCollector();
|
pair.second->currentCollector()->resetCurrentCollector();
|
||||||
@@ -280,6 +294,17 @@ void Simulation::start() {
|
|||||||
// the density from which new particles are drawn is only updated after a timestep
|
// the density from which new particles are drawn is only updated after a timestep
|
||||||
pair.second->positionDistributionFromDensity()->setMaximumDensity();
|
pair.second->positionDistributionFromDensity()->setMaximumDensity();
|
||||||
}
|
}
|
||||||
|
#ifdef debug
|
||||||
|
out << "\n\ttotal number in tp: " << total_tp;
|
||||||
|
out << "\n\tdiff to expected: " << (timesteps+1)*0.02 - total_tp;
|
||||||
|
out << "\n\ttotal number created: " << createdDensity;
|
||||||
|
out << "\n\tdiff to expected: " << (timesteps)*0.02/MpiCommunication::mpiSize()
|
||||||
|
- createdDensity;
|
||||||
|
out << "\n\ttotal number in density drawing field: " << total_tp_sync;
|
||||||
|
out << "\n\tdiff to in density: " << total_tp_sync - total_tp;
|
||||||
|
DEBUG(out.str());
|
||||||
|
createdDensity = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
leftover_events_time_resolution = beta_decay_events;
|
leftover_events_time_resolution = beta_decay_events;
|
||||||
leftover_density_events = particles_per_bin;
|
leftover_density_events = particles_per_bin;
|
||||||
@@ -473,7 +498,8 @@ void Simulation::processUntilTermination(
|
|||||||
if (particle.specie()->terminator()->reachedMaxTimeAlive(
|
if (particle.specie()->terminator()->reachedMaxTimeAlive(
|
||||||
&particle) &&
|
&particle) &&
|
||||||
!particle.specie()->terminator()->leftSimulationDomain(
|
!particle.specie()->terminator()->leftSimulationDomain(
|
||||||
&particle)) {
|
&particle) &&
|
||||||
|
particle.wasDeposited()) {
|
||||||
#ifdef debug_level3
|
#ifdef debug_level3
|
||||||
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name() +
|
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name() +
|
||||||
". Reached timeresolution.");
|
". Reached timeresolution.");
|
||||||
@@ -507,6 +533,9 @@ void Simulation::processUntilTermination(
|
|||||||
DeletionType::wall);
|
DeletionType::wall);
|
||||||
}
|
}
|
||||||
#ifdef debug
|
#ifdef debug
|
||||||
|
if(particle.specie()->type() == species::ImplementedSpecies::Tplus) {
|
||||||
|
phyLossAtWallIon += particle.weight();
|
||||||
|
}
|
||||||
if(particle.wasDeposited()) {
|
if(particle.wasDeposited()) {
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
out << "particle " << particle.specie()->name();
|
out << "particle " << particle.specie()->name();
|
||||||
@@ -539,6 +568,21 @@ void Simulation::processUntilTermination(
|
|||||||
// macroscopic_cross_sections_m);
|
// macroscopic_cross_sections_m);
|
||||||
SimulationTimer::eventStopPoint(std::string("Interaction"));
|
SimulationTimer::eventStopPoint(std::string("Interaction"));
|
||||||
|
|
||||||
|
// particle has reached time resolution, but was not deposited due to
|
||||||
|
// the interaction taking place at the same time.
|
||||||
|
// If the particle is not destroyed in the interaction put it into the mover
|
||||||
|
// in order to log the position. (Not ideal, but otherwise it would be a bit
|
||||||
|
// more effort to calculate the pitchangle here again...)
|
||||||
|
// should work, since the check for died in bin should immediatly happen (hopefully)
|
||||||
|
if(particle.specie()->terminator()->reachedMaxTimeAlive(&particle)
|
||||||
|
&& !particle.wasDeposited() && !output.deleteCurrentParticle()) {
|
||||||
|
particle.specie()->mover()->move(&particle, 1,
|
||||||
|
electric_field_.get(), magnetic_field_.get(), gravity_field_.get());
|
||||||
|
if(!particle.wasDeposited()) {
|
||||||
|
ERROR("particle was not deposited even though it should have been");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
particle.increaseInteractionCounter();
|
particle.increaseInteractionCounter();
|
||||||
|
|
||||||
for (auto& new_particle : output.newParticles()) {
|
for (auto& new_particle : output.newParticles()) {
|
||||||
@@ -700,6 +744,20 @@ std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
|||||||
injector_->drawNewParticleFromDensityField(random->engine(),
|
injector_->drawNewParticleFromDensityField(random->engine(),
|
||||||
pair.second, new_particles, magnetic_field_,
|
pair.second, new_particles, magnetic_field_,
|
||||||
weight_factor, injection_time);
|
weight_factor, injection_time);
|
||||||
|
#ifdef debug
|
||||||
|
if(!new_particles.empty()) {
|
||||||
|
if(new_particles.back().specie()->type() == species::ImplementedSpecies::Tplus
|
||||||
|
&& pair.second->type() == species::ImplementedSpecies::Tplus) {
|
||||||
|
// if(createdDensity + new_particles.back().weight() == createdDensity){
|
||||||
|
// std::stringstream out;
|
||||||
|
// out << "catastrophic cancellation!\ncreated density: " << createdDensity;
|
||||||
|
// out << "\n\tweight: " << new_particles.back().weight();
|
||||||
|
// DEBUG(out.str());
|
||||||
|
// }
|
||||||
|
createdDensity += new_particles.back().weight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// if species is not done tmp_done && ... = false
|
// if species is not done tmp_done && ... = false
|
||||||
|
|||||||
Reference in New Issue
Block a user