#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 specie, std::map>& tracked_species, std::map>& 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") { #ifdef debug_level2 DEBUG_LEVEL_2("Adding interactions: ElasticScattering"); #endif std::function cross_section = buildTotalCrossSection(json_object_by_path(value, {"CrossSection"})); std::shared_ptr scattering_angle_distribution = buildScatteringAngleDistribution( json_object_by_path(value, {"ScatteringAngleDistribution"})); std::string target_name = json_string(json_object_by_path(value, {"Target"})); #ifdef debug_level3 DEBUG_LEVEL_3("with target " + target_name); #endif std::shared_ptr target = findTarget(target_name, tracked_species, background_species); specie->addInteraction(std::shared_ptr( new interaction::ElasticScattering(cross_section, target, scattering_angle_distribution))); } else if (type == "FreeMovement") { #ifdef debug_level2 DEBUG_LEVEL_2("Adding interactions: FreeMovement"); #endif specie->addInteraction(std::shared_ptr( new interaction::FreeMovement())); } else if (type == "ElectronIonization") { #ifdef debug_level2 DEBUG_LEVEL_2("Adding interactions: Ionization"); #endif std::string target_name = json_string(json_object_by_path(value, {"Target"})); std::shared_ptr target = findTarget(target_name, tracked_species, background_species); std::string outgoing_electron_name = json_string(json_object_by_path(value, {"OutgoingElectron"})); std::shared_ptr electron = findTracked(outgoing_electron_name, tracked_species); std::string outgoing_ion_name = json_string(json_object_by_path(value, {"OutgoingIon"})); std::shared_ptr 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 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::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( cross_section, target, electron, ion, ionization_energy_distribution, scattering_angle_distribution, ionization_energy_eV)); } else if (ionization_model == "JanevDissToGround") { std::function 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::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( cross_section, target, electron, ion, ionization_energy_distribution, scattering_angle_distribution, ionization_energy_eV)); } else if (ionization_model == "JanevDissToFirstExcited") { std::function 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::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( cross_section, target, electron, ion, ionization_energy_distribution, scattering_angle_distribution, ionization_energy_eV)); } else if (ionization_model == "JanevAtomic") { std::function 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::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( 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") { #ifdef debug_level2 DEBUG_LEVEL_2("Adding interactions: Excitation"); #endif std::string target_name = json_string(json_object_by_path(value, {"Target"})); std::shared_ptr target = findTarget(target_name, tracked_species, background_species); std::string excitation_state = json_string(json_object_by_path(value, {"ExcitationState"})); std::function cross_section = buildExcitationCrossSection(excitation_state); double excitation_energy = buildExcitationEnergy(excitation_state); specie->addInteraction( std::shared_ptr(new interaction::Excitation( cross_section, target, excitation_energy))); } else if (type == "Clustering") { #ifdef debug_level2 DEBUG_LEVEL_2("Adding interactions: Clustering"); #endif std::string target_name = json_string(json_object_by_path(value, {"Target"})); std::shared_ptr target = findTarget(target_name, tracked_species, background_species); std::string product_name = json_string(json_object_by_path(value, {"Product"})); std::shared_ptr product = findTracked(product_name, tracked_species); std::function cross_section = buildTotalCrossSection(json_object_by_path(value, {"CrossSection"})); specie->addInteraction(std::shared_ptr( new interaction::ClusterFormation(cross_section, target, product))); } else if (type == "ChargeExchange") { #ifdef debug_level2 DEBUG_LEVEL_2("Adding interactions: ChargeExchange"); #endif std::string target_name = json_string(json_object_by_path(value, {"Target"})); std::shared_ptr target = findTarget(target_name, tracked_species, background_species); std::function cross_section = buildTotalCrossSection(json_object_by_path(value, {"CrossSection"})); specie->addInteraction(std::shared_ptr( new interaction::ChargeExchange(cross_section, target))); } else if (type == "Recombination") { #ifdef debug_level2 DEBUG_LEVEL_2("Adding interactions: Recombination"); #endif std::string target_name = json_string(json_object_by_path(value, {"Target"})); std::shared_ptr target = findTracked(target_name, tracked_species); std::function cross_section = buildTotalCrossSection(json_object_by_path(value, {"CrossSection"})); specie->addInteraction(std::shared_ptr( new interaction::Recombination(cross_section, target))); } else { ERROR("This interaction type is not implemented: " + type); } } } std::function 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 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 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 buildScatteringAngleDistribution( json_t* object) { if (json_object_by_path(object, {"Isotropic"})) { #ifdef debug_level2 DEBUG_LEVEL_2("Adding ScatteringAngleDistribution: Isotropic"); #endif return std::shared_ptr( new IsotropicAngleDistribution()); } else if (json_object_by_path(object, {"AngleDistributionFromFile"})) { #ifdef debug_level2 DEBUG_LEVEL_2( "Adding ScatteringAngleDistribution: AngleDistributionFromFile"); #endif std::string absolute_filepath = readAbsoluteFilename( json_object_by_path(object, {"AngleDistributionFromFile", "PathToH5"})); return std::make_shared(absolute_filepath); } else if (json_object_by_path(object, {"CompositeAngleDistribution"})) { #ifdef debug_level2 DEBUG_LEVEL_2( "Adding ScatteringAngleDistribution: CompositeAngleDistribution"); #endif 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 lower_distribution = buildScatteringAngleDistribution( json_object_by_path(object_composite, {"LowerDistribution"})); std::shared_ptr higher_distribution = buildScatteringAngleDistribution( json_object_by_path(object_composite, {"HigherDistribution"})); return std::make_shared( lower_distribution, higher_distribution, decider_energy); } else { ERROR("This scattering angle distribution is not implemented."); return nullptr; } } std::shared_ptr findTarget( std::string& target_name, std::map>& tracked_species, std::map>& 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 findTracked( std::string& target_name, std::map>& 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