From c57dd44ddeff09ef43b5a7238368da6ad76300fd Mon Sep 17 00:00:00 2001 From: csendlinger Date: Tue, 9 Sep 2025 10:42:17 +0200 Subject: [PATCH] Applied correction to cluster formation from karl_paper --- include/interactions/cluster_formation.h | 21 +++++++++++++++++- include/interactions/free_movement.h | 2 +- include/simulation/interaction.h | 2 +- src/generators/interaction_generator.cpp | 20 +++++++++++++++-- src/interactions/cluster_formation.cpp | 15 +++++++++++++ src/interactions/elastic_scattering.cpp | 3 ++- src/interactions/free_movement.cpp | 3 ++- src/interactions/recombination.cpp | 6 ++--- src/simulation/interaction.cpp | 28 ++++++------------------ 9 files changed, 69 insertions(+), 31 deletions(-) diff --git a/include/interactions/cluster_formation.h b/include/interactions/cluster_formation.h index 5303080..4f34cbc 100755 --- a/include/interactions/cluster_formation.h +++ b/include/interactions/cluster_formation.h @@ -10,6 +10,8 @@ class Specie; namespace interaction { +// class for (radiative) cluster formation interactions (A + B --> AB) 7 +// or (A + BC --> AB + C) class ClusterFormation : public Interaction { public: ClusterFormation(std::function cross_section, @@ -18,10 +20,27 @@ class ClusterFormation : public Interaction { InteractionOutput performInteraction(particle::Particle& particle, RandomNumbers* generator); - private: + protected: std::shared_ptr product_; }; +// class for tertiary association (A + B + B --> AB + B) +class ClusterFormationTertiary : public ClusterFormation { + public: +// Constructor: takes the function describing the cross section (dependent on the energy of the incident particle) +// and a shared_ptr to the Species that is the target in the interaction +// and a shared_ptr to the TrackedSpecie that is the product of the interaction + ClusterFormationTertiary(std::function cross_section, + std::shared_ptr target, + std::shared_ptr product); + +// due to only the rate coefficients being available the cross section is +// approximated as sigma = rate_coefficient * density / velocity +// (units of the tertiary rate coefficient m^6/s) + double microscopicCrossSection(double energy_eV, const Coordinate& position); +}; + + }; // namespace interaction #endif /* CLUSTER_FORMATION_H */ diff --git a/include/interactions/free_movement.h b/include/interactions/free_movement.h index d0c199e..01c481f 100755 --- a/include/interactions/free_movement.h +++ b/include/interactions/free_movement.h @@ -13,7 +13,7 @@ class FreeMovement : public Interaction { InteractionOutput performInteraction(particle::Particle& particle, RandomNumbers* generator); - double microscopicCrossSection(double energy_eV); + double microscopicCrossSection(double energy_eV, const Coordinate& position); double macroscopicCrossSection(particle::Particle& particle); double drawCollisionTime(particle::Particle& particle, RandomNumbers* generator); diff --git a/include/simulation/interaction.h b/include/simulation/interaction.h index 35239bf..9b5a800 100755 --- a/include/simulation/interaction.h +++ b/include/simulation/interaction.h @@ -30,7 +30,7 @@ class Interaction { Interaction(std::function cross_section, std::shared_ptr target); - virtual double microscopicCrossSection(double energy_eV); + virtual double microscopicCrossSection(double energy_eV, const Coordinate& position); virtual double macroscopicCrossSection(particle::Particle& particle); // return the time the given particle can travel in the laboratory frame diff --git a/src/generators/interaction_generator.cpp b/src/generators/interaction_generator.cpp index 1eb8ea6..d4cfbf5 100755 --- a/src/generators/interaction_generator.cpp +++ b/src/generators/interaction_generator.cpp @@ -224,10 +224,26 @@ void addInteractions( std::shared_ptr product = findTracked(product_name, tracked_species); + std::string clustering_type = + json_string(json_object_by_path(value, {"ClusteringType"})); + std::function cross_section = buildTotalCrossSection(json_object_by_path(value, {"CrossSection"})); - specie->addInteraction(std::shared_ptr( - new interaction::ClusterFormation(cross_section, target, product))); + + if(clustering_type == "radiative") { + specie->addInteraction(std::shared_ptr( + new interaction::ClusterFormation(cross_section, target, product))); + } else if (clustering_type == "tertiary") { + SIM_INFO("Warning: tertiary clustering has been chosen. Be warned " + "that the cross section function is scaled by the density " + "of the target specie at the position of the interaction " + "(cross section function assumed to have the units m^5)"); + specie->addInteraction(std::shared_ptr( + new interaction::ClusterFormationTertiary(cross_section, target, product))); + } else { + ERROR("ClusteringType " + clustering_type + + ": not known, choose either 'radiative' or 'tertiary'."); + } } else if (type == "ChargeExchange") { #ifdef debug_level2 DEBUG_LEVEL_2("Adding interactions: ChargeExchange"); diff --git a/src/interactions/cluster_formation.cpp b/src/interactions/cluster_formation.cpp index b99d7e8..bdd1fa9 100755 --- a/src/interactions/cluster_formation.cpp +++ b/src/interactions/cluster_formation.cpp @@ -5,6 +5,7 @@ #include "simulation/logger.h" #include "simulation/velocity_distribution.h" #include "constants/physical_constants.h" +#include "simulation/density_field.h" namespace interaction { @@ -49,4 +50,18 @@ InteractionOutput ClusterFormation::performInteraction( return output; } +ClusterFormationTertiary::ClusterFormationTertiary( + std::function cross_section, + std::shared_ptr target, + std::shared_ptr product) : + ClusterFormation(cross_section, target, product) {} + +double ClusterFormationTertiary::microscopicCrossSection(double energy_eV, + const Coordinate& position) { + // SIM_INFO("Tertiary cross section."); + const double rate_over_velocity = cross_section_(energy_eV); + auto density = target_->densityField()->density(position); + return rate_over_velocity * density; +} + } // namespace interaction diff --git a/src/interactions/elastic_scattering.cpp b/src/interactions/elastic_scattering.cpp index 1adc287..b8ae1ab 100755 --- a/src/interactions/elastic_scattering.cpp +++ b/src/interactions/elastic_scattering.cpp @@ -100,7 +100,8 @@ double ElasticScattering::drawCollisionTime(particle::Particle& particle, // out << "energy collision time: " << energy_eV; - const double crosssection = microscopicCrossSection(energy_eV); + const double crosssection = microscopicCrossSection(energy_eV, + particle.cylinderPosition()); // out << "\ncross section: " << crosssection; const double density = target_->densityField()->density(particle.cylinderPosition()); diff --git a/src/interactions/free_movement.cpp b/src/interactions/free_movement.cpp index 29a77e8..0b08b09 100755 --- a/src/interactions/free_movement.cpp +++ b/src/interactions/free_movement.cpp @@ -17,7 +17,8 @@ InteractionOutput FreeMovement::performInteraction(particle::Particle& particle, return InteractionOutput(); } -double FreeMovement::microscopicCrossSection(double energy_eV) { +double FreeMovement::microscopicCrossSection(double energy_eV, + const Coordinate& position) { // returns very small number return SimConstants::minimal_cross_section; } diff --git a/src/interactions/recombination.cpp b/src/interactions/recombination.cpp index 01af322..e7e6f25 100755 --- a/src/interactions/recombination.cpp +++ b/src/interactions/recombination.cpp @@ -158,9 +158,9 @@ double Recombination::macroscopicCrossSection(const Coordinate& position, //Simpson's rule const double integrated_microscopic_cross_section = (upper_bound - lower_bound)/6. * - (microscopicCrossSection(upper_bound) + - 4*microscopicCrossSection(intermediate_value) + - microscopicCrossSection(lower_bound)); + (microscopicCrossSection(upper_bound, position) + + 4*microscopicCrossSection(intermediate_value, position) + + microscopicCrossSection(lower_bound, position)); // assumption, that the differential density is constant within a cell return differential_density_value * integrated_microscopic_cross_section; } diff --git a/src/simulation/interaction.cpp b/src/simulation/interaction.cpp index 8456818..e9cfc55 100755 --- a/src/simulation/interaction.cpp +++ b/src/simulation/interaction.cpp @@ -53,16 +53,19 @@ double Interaction::macroscopicCrossSection(particle::Particle& particle) { UnitConversion::JouleToeV; const double density = target_->densityField()->density(x_particle); - const double cross_section = microscopicCrossSection(kinetic_energy_eV); + const double cross_section = microscopicCrossSection(kinetic_energy_eV, + particle.cylinderPosition()); return cross_section * density; }; -double Interaction::microscopicCrossSection(double energy_eV) { +double Interaction::microscopicCrossSection(double energy_eV, + const Coordinate& position) { return cross_section_(energy_eV); } // think i need to include the magnetic field for it to be really correct +// also sets the velocity of the interaction partner double Interaction::drawCollisionTime(particle::Particle& particle, RandomNumbers* generator) { CartesianVector particle_velocity = particle.velocity(); @@ -94,13 +97,6 @@ double Interaction::drawCollisionTime(particle::Particle& particle, const double relative_velocity = kinematic::norm(velocity_target_fixed); - // std::stringstream out; - // out << "particle "<< particle.specie()->name() <<" velocity: " - // << particle_velocity.cartesianEntries(); - // out << "\ntarget "<< target_->name() <<" velocity: " - // << target_velocity_.cartesianEntries(); - // out << "\nabsolute relative velocity: " << relative_velocity; - // check if the relative velocity is smaller than an epsilon compared to the larger // of the two present velocities (to avoid division by 0 if either is 0) probably // a better version possible @@ -115,15 +111,10 @@ double Interaction::drawCollisionTime(particle::Particle& particle, kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg())* UnitConversion::JouleToeV; - // out << "energy collision time: " << energy_eV; - - const double crosssection = microscopicCrossSection(energy_eV); - // out << "\ncross section: " << crosssection; + const double crosssection = microscopicCrossSection(energy_eV, + particle.cylinderPosition()); const double density = target_->densityField()->density(particle.cylinderPosition()); - // out << "\ninverse mfp: " << crosssection*density << ", sigma: " << crosssection; - // out << ", density: " << density; - const double random_number = generator->rollUniform(0.,1.); if (random_number == 0) { return std::numeric_limits::max(); @@ -132,12 +123,7 @@ double Interaction::drawCollisionTime(particle::Particle& particle, const double distance_target_fixed = - 1./(crosssection * density) * log(random_number); - // out << "\ndistance in target fixed frame: " << distance_target_fixed; - const double time = distance_target_fixed / relative_velocity; - // out << "\ntime before collision: " << time; - // if(density != 0) - // DEBUG_LEVEL_1(out.str()); return time; }