Fixed MB-Generator. Slight changes
This commit is contained in:
@@ -87,3 +87,20 @@ blitz::TinyVector<double,3> Constants::getRandDir(ranlib::Uniform<double> *rngUn
|
|||||||
dir = sin(Theta_rad)*cos(Phi_rad) , sin(Theta_rad)*sin(Phi_rad) , cos(Theta_rad);
|
dir = sin(Theta_rad)*cos(Phi_rad) , sin(Theta_rad)*sin(Phi_rad) , cos(Theta_rad);
|
||||||
return(dir);
|
return(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Random Generators
|
||||||
|
|
||||||
|
double Constants::getRandEnergyMaxwell(double Temp_K,double mass_eV,ranlib::NormalUnit<double> *rngNormal) {
|
||||||
|
double C, beta, N1,N2,N3;
|
||||||
|
C = kb_eVK*Temp_K/mass_eV;
|
||||||
|
beta = 0;
|
||||||
|
N1 = rngNormal->random();
|
||||||
|
N2 = rngNormal->random();
|
||||||
|
N3 = rngNormal->random();
|
||||||
|
beta = sqrt(C*(N1*N1 + N2*N2 + N3*N3));
|
||||||
|
|
||||||
|
return((calcGammaFromBeta(beta)-1)*mass_eV);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,10 @@ public:
|
|||||||
// Help Functions
|
// Help Functions
|
||||||
blitz::TinyVector<double,3> zeroVec();
|
blitz::TinyVector<double,3> zeroVec();
|
||||||
blitz::TinyVector<double,3> getRandDir(ranlib::Uniform<double> *rngUni);
|
blitz::TinyVector<double,3> getRandDir(ranlib::Uniform<double> *rngUni);
|
||||||
|
|
||||||
|
// Random Generators
|
||||||
|
double getRandEnergyMaxwell(double Temp_K,double mass_eV,ranlib::NormalUnit<double> *rngNormal);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ double Katrin::getTritiumDensity(blitz::TinyVector<double,3> loc_m) {
|
|||||||
return(wgtsT2Density_m3);
|
return(wgtsT2Density_m3);
|
||||||
}
|
}
|
||||||
|
|
||||||
Particle Katrin::getT2AverScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal) {
|
Particle Katrin::getT2AverScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni) {
|
||||||
blitz::TinyVector<double,3> speed_ms;
|
blitz::TinyVector<double,3> speed_ms;
|
||||||
// Get Linear Flow
|
// Get Linear Flow
|
||||||
double sign = (loc_m[2] < wgtsLength_m/2.) ? -1 : 1;
|
double sign = (loc_m[2] < wgtsLength_m/2.) ? -1 : 1;
|
||||||
@@ -40,13 +40,13 @@ Particle Katrin::getT2AverScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Un
|
|||||||
}
|
}
|
||||||
|
|
||||||
Particle Katrin::getT2ScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal) {
|
Particle Katrin::getT2ScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal) {
|
||||||
Particle ScatPart = getT2AverScatPart(loc_m, rngUni, rngNormal);
|
Particle ScatPart = getT2AverScatPart(loc_m, rngUni);
|
||||||
blitz::TinyVector<double,3> speed_ms, flowOffset_ms, tempOffset_ms;
|
blitz::TinyVector<double,3> speed_ms, flowOffset_ms, tempOffset_ms;
|
||||||
// Get Linear Flow
|
// Get Linear Flow
|
||||||
flowOffset_ms = ScatPart.getSpeed_ms();
|
flowOffset_ms = ScatPart.getSpeed_ms();
|
||||||
|
|
||||||
// Get Temperature Motion
|
// Get Temperature Motion
|
||||||
double tempOffsetABS_ms = rngNormal->random()*sqrt(kb_eVK*wgtsTemp_K/mT2_eV)*c_ms;
|
double tempOffsetABS_ms = calcV_msFromEkin_eV(getRandEnergyMaxwell(wgtsTemp_K,mT2_eV,rngNormal), mT2_eV);
|
||||||
tempOffset_ms = getRandDir(rngUni)*tempOffsetABS_ms;
|
tempOffset_ms = getRandDir(rngUni)*tempOffsetABS_ms;
|
||||||
|
|
||||||
speed_ms = flowOffset_ms + tempOffset_ms;
|
speed_ms = flowOffset_ms + tempOffset_ms;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public:
|
|||||||
blitz::TinyVector<double,3> getElField(blitz::TinyVector<double,3> loc_m);
|
blitz::TinyVector<double,3> getElField(blitz::TinyVector<double,3> loc_m);
|
||||||
double getTritiumDensity(blitz::TinyVector<double,3> loc_m);
|
double getTritiumDensity(blitz::TinyVector<double,3> loc_m);
|
||||||
|
|
||||||
Particle getT2AverScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
|
Particle getT2AverScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni);
|
||||||
Particle getT2ScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
|
Particle getT2ScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ TARGETS = mcelectron
|
|||||||
all: $(TARGETS)
|
all: $(TARGETS)
|
||||||
|
|
||||||
mcelectron: main.o katrin.o simulation.o particle.o interaction.o tests.o constants.o
|
mcelectron: main.o katrin.o simulation.o particle.o interaction.o tests.o constants.o
|
||||||
$(CXX) -std=c++17 -o $@ $^ $(LDFLAGS) $(LOADLIBES)
|
$(CXX) -o $@ $^ $(LDFLAGS) $(LOADLIBES)
|
||||||
|
|
||||||
%.o : %.cpp
|
%.o : %.cpp
|
||||||
$(CXX) -std=c++17 -Wno-write-strings -c $< $(CXXFLAGS) -o $@
|
$(CXX) -Wno-write-strings -c $< $(CXXFLAGS) -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm *.o mcelectron
|
rm *.o mcelectron
|
||||||
|
|||||||
@@ -64,12 +64,12 @@ std::ostream& operator<<(std::ostream& os, const Particle& partOut) {
|
|||||||
|
|
||||||
// Default Constructor
|
// Default Constructor
|
||||||
Particle::Particle() {
|
Particle::Particle() {
|
||||||
m_eV = NULL;
|
m_eV = NAN;
|
||||||
Z = NULL;
|
Z = NAN;
|
||||||
x_m = zeroVec();
|
x_m = zeroVec();
|
||||||
v_ms = zeroVec();
|
v_ms = zeroVec();
|
||||||
Id = NULL;
|
Id = NAN;
|
||||||
parentId = NULL;
|
parentId = NAN;
|
||||||
s = undef;
|
s = undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,8 +78,8 @@ Particle::Particle(double mass_eV, double charge_e, blitz::TinyVector<double,3>
|
|||||||
Z = charge_e;
|
Z = charge_e;
|
||||||
x_m = zeroVec();
|
x_m = zeroVec();
|
||||||
v_ms = speed_ms;
|
v_ms = speed_ms;
|
||||||
Id = NULL;
|
Id = NAN;
|
||||||
parentId = NULL;
|
parentId = NAN;
|
||||||
s = undef;
|
s = undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,15 +24,16 @@ void Simulation::doit() {
|
|||||||
std::cout<<numInjectedParticles<<"/"<<numTotalParticles<<std::endl;
|
std::cout<<numInjectedParticles<<"/"<<numTotalParticles<<std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ScatT2 = Kat.getT2AverScatPart(particleQue.front().getLoc_m(), &rngUni, &rngNormal);
|
ScatT2 = Kat.getT2AverScatPart(particleQue.front().getLoc_m(), &rngUni);
|
||||||
IntereT2 = Interaction(&particleQue.front(),&ScatT2);
|
IntereT2 = Interaction(&particleQue.front(),&ScatT2);
|
||||||
//Replace with vector containing all Interactions and adapt functions and put particle pointers into Particle class
|
//Replace with vector containing all Interactions and adapt functions and put particle pointers into Particle class
|
||||||
|
|
||||||
MFP_m = getMFP_m(IntereT2);
|
MFP_m = getMFP_m(IntereT2);
|
||||||
moveParticle(&particleQue.front(),MFP_m); // If moved outside set v = 0,0,0;
|
moveParticle(&particleQue.front(),MFP_m); // If moved outside set v = 0,0,0;
|
||||||
|
|
||||||
switch (getInteraction(particleQue.front())) {
|
switch (getInteraction(particleQue.front())) {
|
||||||
case 0: //Moved Outside
|
case 0: //Moved Outside
|
||||||
|
break;
|
||||||
case 1: // Elastic Scattering
|
case 1: // Elastic Scattering
|
||||||
ScatT2 = Kat.getT2ScatPart(particleQue.front().getLoc_m(), &rngUni, &rngNormal);
|
ScatT2 = Kat.getT2ScatPart(particleQue.front().getLoc_m(), &rngUni, &rngNormal);
|
||||||
IntereT2 = Interaction(&particleQue.front(),&ScatT2);
|
IntereT2 = Interaction(&particleQue.front(),&ScatT2);
|
||||||
@@ -76,7 +77,7 @@ Particle Simulation::inject() {
|
|||||||
Ekin_eV = deltaKinEnergy_eV;
|
Ekin_eV = deltaKinEnergy_eV;
|
||||||
break;
|
break;
|
||||||
case 2: //Maxwell Boltzman
|
case 2: //Maxwell Boltzman
|
||||||
Ekin_eV = getEnergyBoltzmann_eV();
|
Ekin_eV = getRandEnergyMaxwell(MBTemp_K,me_eV, &rngNormal);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
std::cerr<<"Invalid Injection Method./n";
|
std::cerr<<"Invalid Injection Method./n";
|
||||||
@@ -113,12 +114,7 @@ double Simulation::FermiFunction(double Z, double Ekin_eV) {
|
|||||||
double eta =Z/beta/137.;
|
double eta =Z/beta/137.;
|
||||||
return( 2*pi*eta/(1-exp(-2*pi*eta)) );
|
return( 2*pi*eta/(1-exp(-2*pi*eta)) );
|
||||||
}
|
}
|
||||||
double Simulation::getEnergyBoltzmann_eV() {
|
|
||||||
double N = rngNormal.random();
|
|
||||||
double beta = N*sqrt(kb_eVK*MBTemp_K/me_eV);
|
|
||||||
double gamma = 1/sqrt(1-pow(beta,2));
|
|
||||||
return((gamma-1)*me_eV);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Moving
|
// Moving
|
||||||
void Simulation::moveParticle(Particle *movePart, double MFP_m) {
|
void Simulation::moveParticle(Particle *movePart, double MFP_m) {
|
||||||
@@ -160,9 +156,7 @@ int Simulation::getInteraction(Particle interPart) {
|
|||||||
if (interPart.getKinEnergy_eV()==0) {
|
if (interPart.getKinEnergy_eV()==0) {
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
return(0);
|
||||||
|
|
||||||
return(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Termination
|
// Termination
|
||||||
@@ -175,7 +169,7 @@ bool Simulation::checkTermination(Particle termPart) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EKin_eV<ETemp_eV) {
|
if (EKin_eV<=ETemp_eV) {
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ protected:
|
|||||||
double getBetaDecayEnergyRejection_eV();
|
double getBetaDecayEnergyRejection_eV();
|
||||||
double EnergyDistributionBetaDecay(double Ekin_eV);
|
double EnergyDistributionBetaDecay(double Ekin_eV);
|
||||||
double FermiFunction(double Z, double Ekin_eV);
|
double FermiFunction(double Z, double Ekin_eV);
|
||||||
double getEnergyBoltzmann_eV();
|
|
||||||
|
|
||||||
// Moving
|
// Moving
|
||||||
void moveParticle(Particle *movePart, double MFP_m);
|
void moveParticle(Particle *movePart, double MFP_m);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ void TestSimulation::maxwellBoltzmann(int numDecays, std::string outputFilePath)
|
|||||||
std::ofstream outFile;
|
std::ofstream outFile;
|
||||||
outFile.open (outputFilePath);
|
outFile.open (outputFilePath);
|
||||||
for (int i = 0;i<numDecays;i++) {
|
for (int i = 0;i<numDecays;i++) {
|
||||||
outFile << getEnergyBoltzmann_eV() <<std::endl;
|
//outFile << getEnergyBoltzmann_eV() <<std::endl;
|
||||||
}
|
}
|
||||||
outFile.close();
|
outFile.close();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user