Changes to Interaction Processor, making possible to add infinite Interactions for all kind of Particles
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// interaction_species.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 27.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "interaction_species.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
InteractionOut ParticleInteractions::do_Interaction(Particle *interPart) const {
|
||||
double macroSigma_m2 = get_macroSigma_m2(*interPart);
|
||||
if (macroSigma_m2 == 0) {
|
||||
stringstream ss;
|
||||
ss<<"ParticleInteractions::do_Interaction: Interaction Cross Section = 0 for particle of Species "<<get_Species()<<".\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
double currentStackedSigma = 0;
|
||||
double targetStackedSigma = rngUni->random() * macroSigma_m2;
|
||||
InteractionsVec::const_iterator Itr = Interactions.cbegin();
|
||||
do {
|
||||
currentStackedSigma += (*Itr)->get_macroSigma_m2(*interPart);
|
||||
Itr++;
|
||||
} while(currentStackedSigma < targetStackedSigma);
|
||||
Itr--;
|
||||
return ((*Itr)->do_Interaction(interPart));
|
||||
}
|
||||
|
||||
double ParticleInteractions::get_macroSigma_m2(const Particle &interPart) const {
|
||||
double macroSigma_m2 = 0;
|
||||
if (empty()) {
|
||||
cout<<"Warning: No Interaction for Particle of Type "<<get_Species()<<"\n";
|
||||
} else {
|
||||
for (InteractionsVec::const_iterator Itr = Interactions.begin();Itr!=Interactions.end();Itr++) {
|
||||
macroSigma_m2 += (*Itr)->get_macroSigma_m2(interPart);
|
||||
}
|
||||
}
|
||||
return(macroSigma_m2);
|
||||
}
|
||||
|
||||
void ParticleInteractions::add_Interaction(Interaction* addInteraction) {
|
||||
if (Interactions.size()>0) {
|
||||
for (InteractionsVec::iterator Itr = Interactions.begin();Itr!=Interactions.end();Itr++) {
|
||||
if ( typeid(addInteraction) == typeid(Itr)) {
|
||||
stringstream ss;
|
||||
ss<<"ParticleInteractions::add_Interaction: Interactions already exists.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (addInteraction->get_Species() != get_Species()) {
|
||||
stringstream ss;
|
||||
ss<<"ParticleInteractions::add_Interaction: Species of adding Interaction missmatches this ParticleInteractions species: \nThis Species:\t"<<get_Species()<<"\nadding Species:\t"<<addInteraction->get_Species()<<"\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
Interactions.push_back(addInteraction);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user