Files
karl/src/generators/interaction_generator.cpp
T
2024-03-15 15:49:40 +01:00

534 lines
24 KiB
C++
Executable File

#include "generators/interaction_generator.h"
#include "constants/ionization_constants.h"
#include "generators/function_generator.h"
#include "generators/vector_field_generator.h"
#include "interactions/charge_exchange.h"
#include "interactions/cluster_formation.h"
#include "interactions/cross_sections.h"
#include "interactions/elastic_scattering.h"
#include "interactions/excitation.h"
#include "interactions/free_movement.h"
#include "interactions/ionization.h"
#include "interactions/recombination.h"
#include "simulation/errors.h"
#include "simulation/homebase.h"
#include "simulation/scattering_angle_distribution.h"
#include "simulation/species.h"
namespace generator {
void addInteractions(
std::shared_ptr<species::TrackedSpecie> specie,
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
tracked_species,
std::map<std::string, std::shared_ptr<species::BackgroundSpecie>>&
background_species,
Parameter& parameter,
json_path& path_to_interactions) {
const char* key;
json_t* value;
json_t* array = parameter.jsonObjectFromBase(path_to_interactions);
json_object_foreach(array, key, value) {
std::string type = json_string(json_object_by_path(value, {"Type"}));
if (type == "ElasticScattering") {
DEBUG_LEVEL_2("Adding interactions: ElasticScattering");
std::function<double(double)> cross_section =
buildTotalCrossSection(json_object_by_path(value, {"CrossSection"}));
std::shared_ptr<ScatteringAngleDistribution>
scattering_angle_distribution = buildScatteringAngleDistribution(
json_object_by_path(value, {"ScatteringAngleDistribution"}));
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
DEBUG_LEVEL_3("with target " + target_name);
std::shared_ptr<species::Specie> target =
findTarget(target_name, tracked_species, background_species);
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
new interaction::ElasticScattering(cross_section, target,
scattering_angle_distribution)));
} else if (type == "FreeMovement") {
DEBUG_LEVEL_2("Adding interactions: FreeMovement");
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
new interaction::FreeMovement()));
} else if (type == "ElectronIonization") {
DEBUG_LEVEL_2("Adding interactions: Ionization");
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
std::shared_ptr<species::Specie> target =
findTarget(target_name, tracked_species, background_species);
std::string outgoing_electron_name =
json_string(json_object_by_path(value, {"OutgoingElectron"}));
std::shared_ptr<species::TrackedSpecie> electron =
findTracked(outgoing_electron_name, tracked_species);
std::string outgoing_ion_name =
json_string(json_object_by_path(value, {"OutgoingIon"}));
std::shared_ptr<species::TrackedSpecie> ion =
findTracked(outgoing_ion_name, tracked_species);
std::string ionization_model =
json_string(json_object_by_path(value, {"IonizationModel"}));
if (ionization_model == "JanevNonDiss") {
std::function<double(double)> cross_section =
interaction::totalCrossSection::eT2_ionization_janev_non_diss();
const double ionization_energy_eV =
ionization::ionization_energy_janev_non_diss;
auto ionization_energy_distribution =
std::make_shared<interaction::IonizationEnergyDistribution>(
interaction::d2CrossSection::eT2_ionization_bed(),
ionization_energy_eV);
auto scattering_angle_distribution = std::make_shared<
interaction::IonizationScatteringAngleDistribution>();
if (electron->type() != species::ImplementedSpecies::electron) {
ERROR(
"The JanevNonDiss needs electron species as outgoing electrons.");
}
if (ion->type() != species::ImplementedSpecies::T2plus) {
std::cout << ion->name() << std::endl;
ERROR("The JanevNonDiss needs T2+ species as outgoing ions.");
}
specie->addInteraction(
std::make_shared<interaction::ElectronIonization>(
cross_section, target, electron, ion,
ionization_energy_distribution, scattering_angle_distribution,
ionization_energy_eV));
} else if (ionization_model == "JanevDissToGround") {
std::function<double(double)> cross_section =
interaction::totalCrossSection::eT2_ionization_janev_diss_ground();
const double ionization_energy_eV =
ionization::ionization_energy_janev_diss_ground;
auto ionization_energy_distribution =
std::make_shared<interaction::IonizationEnergyDistribution>(
interaction::d2CrossSection::eT2_ionization_bed(),
ionization_energy_eV);
auto scattering_angle_distribution = std::make_shared<
interaction::IonizationScatteringAngleDistribution>();
if (electron->type() != species::ImplementedSpecies::electron) {
ERROR(
"The JanevDissToGround needs electron species as outgoing "
"electrons.");
}
if (ion->type() != species::ImplementedSpecies::Tplus) {
ERROR("The JanevDissToGround needs T+ species as outgoing ions.");
}
specie->addInteraction(
std::make_shared<interaction::ElectronIonization>(
cross_section, target, electron, ion,
ionization_energy_distribution, scattering_angle_distribution,
ionization_energy_eV));
} else if (ionization_model == "JanevDissToFirstExcited") {
std::function<double(double)> cross_section =
interaction::totalCrossSection::eT2_ionization_janev_diss_first();
const double ionization_energy_eV =
ionization::ionization_energy_janev_diss_first;
auto ionization_energy_distribution =
std::make_shared<interaction::IonizationEnergyDistribution>(
interaction::d2CrossSection::eT2_ionization_bed(),
ionization_energy_eV);
auto scattering_angle_distribution = std::make_shared<
interaction::IonizationScatteringAngleDistribution>();
if (electron->type() != species::ImplementedSpecies::electron) {
ERROR(
"The JanevDissToFirstExcited needs electron species as outgoing "
"electrons.");
}
if (ion->type() != species::ImplementedSpecies::Tplus) {
ERROR(
"The JanevDissToFirstExcited needs T+ species as outgoing "
"ions.");
}
specie->addInteraction(
std::make_shared<interaction::ElectronIonization>(
cross_section, target, electron, ion,
ionization_energy_distribution, scattering_angle_distribution,
ionization_energy_eV));
} else if (ionization_model == "JanevAtomic") {
std::function<double(double)> cross_section =
interaction::totalCrossSection::eT_ionization_from_ground_janev();
const double ionization_energy_eV =
ionization::ionization_energy_janev_atomic;
auto ionization_energy_distribution =
std::make_shared<interaction::IonizationEnergyDistribution>(
interaction::d2CrossSection::eT_ionization_bed(),
ionization_energy_eV);
auto scattering_angle_distribution = std::make_shared<
interaction::IonizationScatteringAngleDistribution>();
if (electron->type() != species::ImplementedSpecies::electron) {
ERROR("The JanevAtomic needs electron species as outgoing electrons.");
}
if (ion->type() != species::ImplementedSpecies::Tplus) {
ERROR("The JanevAtomic nees T+ species as outgoing ions.");
}
specie->addInteraction(
std::make_shared<interaction::ElectronIonization>(
cross_section, target, electron, ion,
ionization_energy_distribution, scattering_angle_distribution,
ionization_energy_eV));
} else {
ERROR("This ionization model is not implemented: " + ionization_model);
}
} else if (type == "Excitation") {
DEBUG_LEVEL_2("Adding interactions: Excitation");
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
std::shared_ptr<species::Specie> target =
findTarget(target_name, tracked_species, background_species);
std::string excitation_state =
json_string(json_object_by_path(value, {"ExcitationState"}));
std::function<double(double)> cross_section =
buildExcitationCrossSection(excitation_state);
double excitation_energy = buildExcitationEnergy(excitation_state);
specie->addInteraction(
std::shared_ptr<interaction::Interaction>(new interaction::Excitation(
cross_section, target, excitation_energy)));
} else if (type == "Clustering") {
DEBUG_LEVEL_2("Adding interactions: Clustering");
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
std::shared_ptr<species::Specie> target =
findTarget(target_name, tracked_species, background_species);
std::string product_name =
json_string(json_object_by_path(value, {"Product"}));
std::shared_ptr<species::TrackedSpecie> product =
findTracked(product_name, tracked_species);
std::function<double(double)> cross_section =
buildTotalCrossSection(json_object_by_path(value, {"CrossSection"}));
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
new interaction::ClusterFormation(cross_section, target, product)));
} else if (type == "ChargeExchange") {
DEBUG_LEVEL_2("Adding interactions: ChargeExchange");
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
std::shared_ptr<species::Specie> target =
findTarget(target_name, tracked_species, background_species);
std::function<double(double)> cross_section =
buildTotalCrossSection(json_object_by_path(value, {"CrossSection"}));
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
new interaction::ChargeExchange(cross_section, target)));
} else if (type == "Recombination") {
DEBUG_LEVEL_2("Adding interactions: Recombination");
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
std::shared_ptr<species::TrackedSpecie> target =
findTracked(target_name, tracked_species);
std::function<double(double)> cross_section =
buildTotalCrossSection(json_object_by_path(value, {"CrossSection"}));
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
new interaction::Recombination(cross_section, target)));
}
else {
ERROR("This interaction type is not implemented: " + type);
}
}
}
std::function<double(double)> buildTotalCrossSection(json_t* object) {
if (json_object_by_path(object, {"PredefinedFunction"})) {
std::string function_name =
json_string(json_object_by_path(object, {"PredefinedFunction"}));
if (function_name == "eT2_elastic_scattering_constant") {
return interaction::totalCrossSection::eT2_elastic_scattering_constant();
} else if (function_name == "eT2_elastic_scattering") {
return interaction::totalCrossSection::eT2_elastic_scattering();
} else if (function_name == "eT2_elastic_scattering") {
return interaction::totalCrossSection::eT2_elastic_scattering();
} else if (function_name == "TpT2_elastic_scattering_tabata") {
return interaction::totalCrossSection::TpT2_elastic_scattering_tabata();
} else if (function_name == "T3pT2_elastic_scattering_tabata") {
return interaction::totalCrossSection::T3pT2_elastic_scattering_tabata();
} else if (function_name == "eT2_ionization_janev_diss_ground") {
return interaction::totalCrossSection::eT2_ionization_janev_diss_ground();
} else if (function_name == "eT2_ionization_janev_diss_first") {
return interaction::totalCrossSection::eT2_ionization_janev_diss_first();
} else if (function_name == "TpT2_clustering_radiative_ascendion_pasil") {
return interaction::totalCrossSection::
TpT2_clustering_radiative_ascendion_pasil();
} else if (function_name == "TpT2_clustering_tertiary_ascendion_pasil") {
return interaction::totalCrossSection::
TpT2_clustering_tertiary_ascendion_pasil();
} else if (function_name == "T2pT2_clustering_janev") {
return interaction::totalCrossSection::T2pT2_clustering_janev();
} else if (function_name == "T2pT2_charge_exchange_janev") {
return interaction::totalCrossSection::T2pT2_charge_exchange_janev();
} else if (function_name == "eT2p_recombination_janev") {
return interaction::totalCrossSection::eT2p_recombination_janev();
} else if (function_name == "eT3p_recombination_janev") {
return interaction::totalCrossSection::eT3p_recombination_janev();
} else if (function_name == "eT_elastic_scattering") {
return interaction::totalCrossSection::eT_elastic_scattering();
} else if (function_name == "TpT_elastic_scattering_schultz") {
return interaction::totalCrossSection::TpT_elastic_scattering_schultz();
} else if (function_name == "eT_ionization_from_ground_janev") {
return interaction::totalCrossSection::eT_ionization_from_ground_janev();
} else if (function_name == "TpT_clustering_tertiary_janev") {
// needs to be changed to account for the temperature, probs smth like excitation
return interaction::totalCrossSection::TpT_clustering_tertiary_janev(80.);
} else if (function_name == "eTp_recombination_kotelnikov") {
return interaction::totalCrossSection::eTp_recombination_kotelnikov();
} else if (function_name == "TpT_charge_exchange_janev") {
return interaction::totalCrossSection::TpT_charge_exchange_janev();
}
else {
ERROR("This predefined function does not exist: " + function_name);
return nullptr;
}
} else if (json_object_by_path(object, {"1dFunction"})) {
return function1D(json_object_by_path(object, {"1dFunction"}));
} else if (json_object_by_path(object, {"ExcitationFunction"})) {
std::string excitation_state = json_string(
json_object_by_path(object, {"ExcitationFunction", "ExcitationState"}));
return buildExcitationCrossSection(excitation_state);
} else {
ERROR("This type of cross section is not implemented.");
return nullptr;
}
}
double buildExcitationEnergy(std::string excitation_state) {
if (excitation_state == "janev_singlet_B1") {
return 12.754;
} else if (excitation_state == "janev_singlet_B1prime") {
return 14.85;
} else if (excitation_state == "janev_singlet_B1primeprime") {
return 15.47;
} else if (excitation_state == "janev_singlet_C1") {
return 13.29;
} else if (excitation_state == "janev_singlet_D1") {
return 14.996;
} else if (excitation_state == "janev_singlet_D1prime") {
return 15.555;
} else if (excitation_state == "janev_singlet_symmetry_forbidden_EF1") {
return 13.13;
} else if (excitation_state == "janev_singlet_symmetry_forbidden_HHb") {
return 14.98;
} else if (excitation_state == "janev_singlet_symmetry_forbidden_GK1") {
return 14.816;
} else if (excitation_state == "janev_singlet_symmetry_forbidden_I1") {
return 14.824;
} else if (excitation_state == "janev_triplet_A3") {
return 11.71;
} else if (excitation_state == "janev_triplet_B3") {
return 7.93;
} else if (excitation_state == "janev_triplet_C3") {
return 11.71;
} else if (excitation_state == "janev_triplet_E3") {
return 13.0;
} else if (excitation_state == "janev_triplet_D3") {
return 13.6;
} else if (excitation_state == "janev_vibrational_first") {
return 0.516;
} else if (excitation_state == "janev_vibrational_second") {
return 1.003;
} else if (excitation_state == "england_rotational_j0_to_j2") {
return 0.0439;
} else if (excitation_state == "england_rotational_j1_to_j3") {
return 0.0727;
} else if (excitation_state == "janev_atomic_n2") {
return 10.2;
} else if (excitation_state == "janev_atomic_n3") {
return 12.09;
} else if (excitation_state == "janev_atomic_n4") {
return 12.75;
} else if (excitation_state == "janev_atomic_n5") {
return 13.06;
} else {
ERROR(
"This type of cross section ExcitationState: " + excitation_state +
" is not implemented in buildExcitationEnergy.");
return 0.;
}
}
std::function<double(double)> buildExcitationCrossSection(
std::string excitation_state) {
if (excitation_state == "janev_singlet_B1") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state("B1");
} else if (excitation_state == "janev_singlet_B1prime") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state("B1prime");
} else if (excitation_state == "janev_singlet_B1primeprime") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state("B1primeprime");
} else if (excitation_state == "janev_singlet_C1") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state("C1");
} else if (excitation_state == "janev_singlet_D1") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state("D1");
} else if (excitation_state == "janev_singlet_D1prime") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state("D1prime");
} else if (excitation_state == "janev_singlet_symmetry_forbidden_EF1") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state_symmetry_forbidden(
"EF1");
} else if (excitation_state == "janev_singlet_symmetry_forbidden_HHb") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state_symmetry_forbidden(
"HHb");
} else if (excitation_state == "janev_singlet_symmetry_forbidden_GK1") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state_symmetry_forbidden(
"GK1");
} else if (excitation_state == "janev_singlet_symmetry_forbidden_I1") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state_symmetry_forbidden(
"I1");
} else if (excitation_state == "janev_triplet_A3") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_triplet_ground_state("A3");
} else if (excitation_state == "janev_triplet_B3") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_triplet_ground_state("B3");
} else if (excitation_state == "janev_triplet_C3") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_triplet_ground_state("C3");
} else if (excitation_state == "janev_triplet_E3") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_triplet_ground_state("E3");
} else if (excitation_state == "janev_triplet_D3") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_triplet_ground_state("D3");
} else if (excitation_state == "janev_vibrational_first") {
return interaction::totalCrossSection::
eT2_excitation_vibrational_janev_first();
} else if (excitation_state == "janev_vibrational_second") {
return interaction::totalCrossSection::
eT2_excitation_vibrational_janev_second();
} else if (excitation_state == "england_rotational_j0_to_j2") {
return interaction::totalCrossSection::
eT2_excitation_rotational_j0_to_j2_england();
} else if (excitation_state == "england_rotational_j1_to_j3") {
return interaction::totalCrossSection::
eT2_excitation_rotational_j1_to_j3_england();
} else if (excitation_state == "janev_atomic_n2") {
return interaction::totalCrossSection::
eT_excitation_electric_from_ground_janev("n2");
} else if (excitation_state == "janev_atomic_n3") {
return interaction::totalCrossSection::
eT_excitation_electric_from_ground_janev("n3");
} else if (excitation_state == "janev_atomic_n4") {
return interaction::totalCrossSection::
eT_excitation_electric_from_ground_janev("n4");
} else if (excitation_state == "janev_atomic_n5") {
return interaction::totalCrossSection::
eT_excitation_electric_from_ground_janev("n5");
} else {
ERROR(
"This type of cross section ExcitationState is not implemented in "
"buildExcitationCrossSection: " + excitation_state);
return nullptr;
}
}
//exists why?
std::function<double(double, double)> build2DCrossSection(json_t* object) {
if (json_object_by_path(object, {"PredefinedFunction"})) {
std::string function_name =
json_string(json_object_by_path(object, {"PredefinedFunction"}));
if (function_name == "eT2_ionization_bed") {
return interaction::d2CrossSection::eT2_ionization_bed();
} else if (function_name == "eT_ionization_bed") {
return interaction::d2CrossSection::eT_ionization_bed();
} else {
ERROR("This predefined function does not exist");
return nullptr;
}
} else {
ERROR("This type of cross section is not implemented.");
return nullptr;
}
}
std::shared_ptr<ScatteringAngleDistribution> buildScatteringAngleDistribution(
json_t* object) {
if (json_object_by_path(object, {"Isotropic"})) {
DEBUG_LEVEL_2("Adding ScatteringAngleDistribution: Isotropic");
return std::shared_ptr<ScatteringAngleDistribution>(
new IsotropicAngleDistribution());
} else if (json_object_by_path(object, {"AngleDistributionFromFile"})) {
DEBUG_LEVEL_2(
"Adding ScatteringAngleDistribution: AngleDistributionFromFile");
std::string absolute_filepath = readAbsoluteFilename(
json_object_by_path(object, {"AngleDistributionFromFile", "PathToH5"}));
return std::make_shared<AngleDistributionFromFile>(absolute_filepath);
} else if (json_object_by_path(object, {"CompositeAngleDistribution"})) {
DEBUG_LEVEL_2(
"Adding ScatteringAngleDistribution: CompositeAngleDistribution");
json_t* object_composite =
json_object_by_path(object, {"CompositeAngleDistribution"});
const double decider_energy = json_read_energy(
json_object_by_path(object_composite, {"DeciderEnergy"}));
std::shared_ptr<ScatteringAngleDistribution> lower_distribution =
buildScatteringAngleDistribution(
json_object_by_path(object_composite, {"LowerDistribution"}));
std::shared_ptr<ScatteringAngleDistribution> higher_distribution =
buildScatteringAngleDistribution(
json_object_by_path(object_composite, {"HigherDistribution"}));
return std::make_shared<CompositeAngleDistribution>(
lower_distribution, higher_distribution, decider_energy);
} else {
ERROR("This scattering angle distribution is not implemented.");
return nullptr;
}
}
std::shared_ptr<species::Specie> findTarget(
std::string& target_name,
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
tracked_species,
std::map<std::string, std::shared_ptr<species::BackgroundSpecie>>&
background_species) {
if (background_species.count(target_name)) {
return background_species.at(target_name);
} else if (tracked_species.count(target_name)) {
return tracked_species.at(target_name);
} else {
ERROR("The specified target " + target_name + " does not exist.");
return nullptr;
}
};
std::shared_ptr<species::TrackedSpecie> findTracked(
std::string& target_name,
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
tracked_species) {
if (tracked_species.count(target_name)) {
return tracked_species.at(target_name);
} else {
ERROR("The specified target " + target_name + " does not exist.");
return nullptr;
}
}
}; // namespace generator