Added option for initial weights in the injector

This commit is contained in:
2024-07-31 10:35:14 +02:00
parent 961f1a2a8e
commit 4301c4453b
7 changed files with 36 additions and 12 deletions
+3 -1
View File
@@ -26,6 +26,7 @@ struct InjectorInfo {
public:
std::shared_ptr<species::TrackedSpecie> created_specie;
std::shared_ptr<VelocityDistribution> creation_velocity_distribution;
int multiplicity;
};
class Injector {
@@ -51,7 +52,8 @@ class Injector {
const Coordinate& position,
std::shared_ptr<species::TrackedSpecie> created_specie,
std::shared_ptr<VelocityDistribution> creation_velocity_distribution,
const double time_birth);
const double time_birth,
const double weight);
};
#endif /* INJECTOR_H */
+6 -1
View File
@@ -15,7 +15,8 @@ class Particle {
Particle(std::shared_ptr<species::TrackedSpecie> specie,
const Coordinate& position,
const Vector& velocity,
const double time_birth);
const double time_birth,
const double weight);
void position(const Coordinate& new_position);
CartesianCoordinate position() const;
@@ -49,7 +50,11 @@ class Particle {
long int ID() const;
double weight() const;
private:
double weight_;
CartesianVector velocity_;
CartesianCoordinate position_;
+3
View File
@@ -33,6 +33,9 @@ std::shared_ptr<Injector> buildInjector(
parameter,
json_path_append(path_to_injector, {"CreatedSpecies", std::string(key),
"CreationVelocityDistribution"}));
// missing a check if the value is positive
info.multiplicity = json_int(json_object_by_path(value, {"Multiplicity"}), 1);
injector_infos.push_back(info);
}
+3 -1
View File
@@ -30,8 +30,10 @@ InteractionOutput ClusterFormation::performInteraction(
const blitz::TinyVector<double, 3> v_cluster =
kinematic::velocity(energy_eV, product_->mass_kg()) *
v_target / kinematic::norm(v_target);
// product inherits weight of the main particle (not the target, which is
// assumed to be just a density, i.e. has no weight of its own)
particle::Particle cluster(product_, x_impact, CartesianVector(v_cluster),
particle.timeAlive());
particle.timeAlive(), particle.weight());
InteractionOutput output;
output.add(cluster);
+4 -2
View File
@@ -95,12 +95,14 @@ InteractionOutput ElectronIonization::performInteraction(
const double time_birth = particle.timeAlive();
const double weight_parent = particle.weight();
InteractionOutput output;
output.add(
particle::Particle(electron_, x_impact, CartesianVector(v_ejected),
time_birth));
time_birth, weight_parent));
output.add(particle::Particle(ion_, x_impact, CartesianVector(v_target),
time_birth));
time_birth, weight_parent));
return output;
}
+8 -4
View File
@@ -28,7 +28,8 @@ particle::Particle Injector::rollNewParticle(
const Coordinate& position,
std::shared_ptr<species::TrackedSpecie> created_specie,
std::shared_ptr<VelocityDistribution> creation_velocity_distribution,
const double time_birth) {
const double time_birth,
const double weight) {
blitz::TinyVector<double, 3> velocity =
creation_velocity_distribution->rollVelocity(position, engine)
.cartesianEntries();
@@ -41,7 +42,7 @@ particle::Particle Injector::rollNewParticle(
out << created_specie->name() << " created at time: " << time_birth << "s.";
DEBUG_LEVEL_3(out.str());
return particle::Particle(created_specie, position,
CartesianVector(velocity), time_birth);
CartesianVector(velocity), time_birth, weight);
}
std::vector<particle::Particle> Injector::rollNewParticles(
@@ -56,10 +57,13 @@ std::vector<particle::Particle> Injector::rollNewParticles(
current_time);
const double time_birth = injection_time(*engine);
for (auto& injector_info : injector_infos_) {
new_particles.push_back(
const double weight = 1./injector_info.multiplicity;
for (int i = 0; i < injector_info.multiplicity; i++) {
new_particles.push_back(
rollNewParticle(engine, position, injector_info.created_specie,
injector_info.creation_velocity_distribution,
time_birth));
time_birth, weight));
}
}
return new_particles;
}
+9 -3
View File
@@ -21,14 +21,16 @@ Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
const Coordinate& position,
const Vector& velocity,
const double time_birth)
const double time_birth,
const double weight)
: specie_(specie),
position_(position),
velocity_(velocity, position),
id_(this->last_id_),
time_alive_s_(time_birth),
time_in_bin_s_(0.),
interaction_counter_(0) {
interaction_counter_(0),
weight_(weight) {
last_id_++;
}
@@ -100,7 +102,7 @@ double Particle::timeAlive() const {
}
void Particle::increaseTimeInBin(double time_s) {
time_in_bin_s_ += time_s;
time_in_bin_s_ += time_s*weight_;
}
void Particle::resetTimeInBin() {
@@ -115,4 +117,8 @@ long int Particle::ID() const {
return id_;
}
double Particle::weight() const {
return weight_;
}
} // namespace particle