Injection stride on a per injected species basis
This commit is contained in:
+53
-21
@@ -58,30 +58,61 @@ void Injector::initInjectionTimeDistribution(double delta_t) {
|
||||
}
|
||||
|
||||
std::vector<particle::Particle> Injector::rollNewParticles(
|
||||
std::mt19937* engine, const double current_time,
|
||||
const double beta_particle_weight) {
|
||||
std::mt19937* engine, const int timestep) {
|
||||
|
||||
std::vector<particle::Particle> new_particles;
|
||||
|
||||
const double time_birth = injection_time_distribution_(*engine);
|
||||
|
||||
for (auto& injector_info : injector_infos_) {
|
||||
|
||||
CylinderCoordinate position = position_distribution_->rollPosition(engine);
|
||||
if((timestep % injector_info.injection_stride) == injector_info.injection_group) {
|
||||
CylinderCoordinate position = position_distribution_->rollPosition(engine);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Injected z position: " +
|
||||
std::to_string(position.cylinderEntries()(2)));
|
||||
DEBUG_LEVEL_3("Injected z position: " +
|
||||
std::to_string(position.cylinderEntries()(2)));
|
||||
#endif
|
||||
|
||||
new_particles.push_back(
|
||||
rollNewParticle(engine, position, injector_info.created_specie,
|
||||
injector_info.creation_velocity_distribution,
|
||||
time_birth, beta_particle_weight));
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0(std::to_string(MpiCommunication::mpi_rank) + ": injection "
|
||||
+ injector_info.created_specie->name() + " at "
|
||||
"timestep " + std::to_string(timestep));
|
||||
#endif
|
||||
new_particles.push_back(
|
||||
rollNewParticle(engine, position, injector_info.created_specie,
|
||||
injector_info.creation_velocity_distribution,
|
||||
time_birth, injector_info.weight));
|
||||
}
|
||||
}
|
||||
return new_particles;
|
||||
}
|
||||
|
||||
void Injector::setWeights(const double physical_number, const int numerical_number) {
|
||||
#ifdef debug
|
||||
std::stringstream out;
|
||||
out << "Weights:\n";
|
||||
#endif
|
||||
int groupsize;
|
||||
|
||||
for(auto& injector_info : injector_infos_) {
|
||||
groupsize = MpiCommunication::mpi_size / injector_info.injection_stride;
|
||||
if((MpiCommunication::mpi_size - groupsize * injector_info.injection_stride)
|
||||
> injector_info.injection_group) {
|
||||
groupsize += 1;
|
||||
}
|
||||
injector_info.weight = physical_number / static_cast<double>(numerical_number *
|
||||
groupsize);
|
||||
#ifdef debug
|
||||
out << "\t" << injector_info.created_specie->name();
|
||||
out << ": " << injector_info.weight;
|
||||
out << " (group: " << injector_info.injection_group;
|
||||
out << ", size: " << groupsize;
|
||||
out << ")\n";
|
||||
#endif
|
||||
}
|
||||
#ifdef debug
|
||||
DEBUG(out.str());
|
||||
#endif
|
||||
}
|
||||
|
||||
void Injector::drawNewParticleFromDensityField(std::mt19937* engine,
|
||||
std::shared_ptr<species::TrackedSpecie> specie,
|
||||
std::vector<particle::Particle>& queue,
|
||||
@@ -92,6 +123,11 @@ void Injector::drawNewParticleFromDensityField(std::mt19937* engine,
|
||||
const double num_part_in_bin = specie->densityForDrawing()->particleNumber(index);
|
||||
|
||||
if(num_part_in_bin == 0) {
|
||||
#if defined(debug_level2) || defined(debug_level3)
|
||||
std::stringstream out;
|
||||
out << "index: "<< index <<" has no particles";
|
||||
// DEBUG_LEVEL_2(out.str());
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -99,12 +135,6 @@ void Injector::drawNewParticleFromDensityField(std::mt19937* engine,
|
||||
CylinderCoordinate position =
|
||||
specie->positionDistributionFromDensity()->drawPosition(engine,
|
||||
index(0), index(1), index(2));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Injected z position: " +
|
||||
std::to_string(position.cylinderEntries()(2)));
|
||||
DEBUG_LEVEL_3("Injected r position: " +
|
||||
std::to_string(position.cylinderEntries()(0)));
|
||||
#endif
|
||||
// draw the velocity
|
||||
CartesianVector velocity(blitz::TinyVector<double, 3>(0,0,0));
|
||||
|
||||
@@ -119,13 +149,15 @@ void Injector::drawNewParticleFromDensityField(std::mt19937* engine,
|
||||
drawVelocity(index, engine, position, magnetic_field);
|
||||
}
|
||||
|
||||
#ifdef debug_level2
|
||||
#if defined(debug_level2) || defined(debug_level3)
|
||||
std::stringstream out;
|
||||
out << "drawn index: " << index;
|
||||
out << specie->name() << ":\n";
|
||||
out << "\ndrawn index: " << index;
|
||||
out << "\nnumber of particles (" << specie->name() << ") at index: " << num_part_in_bin;
|
||||
out << "\ndrawn position: " << position.cylinderEntries();
|
||||
out << "\ndrawn velocity: " << velocity.cartesianEntries();
|
||||
DEBUG_LEVEL_2(out.str());
|
||||
if(num_part_in_bin > 0)
|
||||
DEBUG_LEVEL_2(out.str());
|
||||
#endif
|
||||
|
||||
particle::Particle drawn_particle(specie, position,
|
||||
|
||||
Reference in New Issue
Block a user