Added constants.h: declaring global variables there and passign to parameters, particles. Included Elastic Scattering
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// constants.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 08.10.18.
|
||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef constants_h
|
||||
#define constants_h
|
||||
|
||||
class Constants
|
||||
{
|
||||
public:
|
||||
virtual ~Constants(){};
|
||||
Constants() {};
|
||||
|
||||
protected:
|
||||
const double pi = 3.1415;
|
||||
const double c_nat = 1.;
|
||||
const double c_ms = 299792458;
|
||||
const double me_eV = 0.511e6;
|
||||
const double qe_e = 1;
|
||||
const double re_m = 2.817940322719e-15;
|
||||
const double e_C = 1.602176462e-19;
|
||||
const double ZT2 = 2.;
|
||||
const double mT2_eV = 5.61886404234e9;
|
||||
|
||||
// Conversion Functions
|
||||
double v_ms(double Ekin_eV) {
|
||||
double gamma = 1. + Ekin_eV/me_eV;
|
||||
double beta = sqrt(1 - pow(gamma,-2));
|
||||
return(beta * c_ms);
|
||||
|
||||
}
|
||||
double Ekin_eV(double speedAbs_ms) {
|
||||
double beta = speedAbs_ms/c_ms;
|
||||
double gamma = pow(1 - pow(beta,2),-0.5);
|
||||
return ( (gamma-1) * me_eV * pow(c_nat,2) );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -8,7 +8,15 @@
|
||||
|
||||
#include "simulation.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define Debug( x ) std::cout << x << std::endl;
|
||||
#else
|
||||
#define Debug( x )
|
||||
#endif
|
||||
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
Debug("Debug Mode is on.")
|
||||
Simulation Sim;
|
||||
Sim.init();
|
||||
Sim.doit();
|
||||
|
||||
@@ -12,8 +12,9 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
class Parameter
|
||||
class Parameter: protected Constants
|
||||
{
|
||||
public:
|
||||
virtual ~Parameter(){};
|
||||
@@ -33,14 +34,6 @@ public:
|
||||
wgtsRadius_m = value("wgtsRadius_m");
|
||||
wgtsTritiumDensity_m3 = value("wgtsTritiumDensity_m3");
|
||||
}
|
||||
// Natural Constants
|
||||
const double pi = 3.1415;
|
||||
const double c_nat = 1.;
|
||||
const double c_ms = 299792458;
|
||||
const double me_eV = 0.511e6;
|
||||
const double qe_e = 1;
|
||||
const double re_m = 2.817940322719e-15;
|
||||
|
||||
|
||||
private:
|
||||
double value(std::string strin, char* ext = (char*)("cat")) {
|
||||
@@ -105,19 +98,7 @@ protected:
|
||||
double wgtsLength_m;
|
||||
double wgtsRadius_m;
|
||||
double wgtsTritiumDensity_m3;
|
||||
|
||||
// Help Functions
|
||||
double v_ms(double Ekin_eV) {
|
||||
double gamma = 1. + Ekin_eV/me_eV;
|
||||
double beta = sqrt(1 - pow(gamma,-2));
|
||||
return(beta * c_ms);
|
||||
}
|
||||
double Ekin_eV(double speedAbs_ms) {
|
||||
double beta = speedAbs_ms/c_ms;
|
||||
double gamma = pow(1 - pow(beta,2),-0.5);
|
||||
return ( (gamma-1) * me_eV * pow(c_nat,2) );
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
seed = 2342395328
|
||||
numTotalParticles = 100
|
||||
dt_s = 0.00000001
|
||||
injectionMethod = 2
|
||||
numTotalParticles = 1
|
||||
dt_s = 0.0000000001
|
||||
injectionMethod = 1
|
||||
deltaKinEnergy_eV = 100
|
||||
MBKinEnergy_eV = 100
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
|
||||
#include "particle.h"
|
||||
|
||||
|
||||
|
||||
// Overload <<
|
||||
std::ostream& operator<<(std::ostream& os, const species& SpecOut) {
|
||||
switch (SpecOut) {
|
||||
case electron:
|
||||
@@ -41,7 +44,6 @@ std::ostream& operator<<(std::ostream& os, const species& SpecOut) {
|
||||
}
|
||||
return (os);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Particle& partOut) {
|
||||
os
|
||||
<< partOut.Id << ";"
|
||||
@@ -57,3 +59,122 @@ std::ostream& operator<<(std::ostream& os, const Particle& partOut) {
|
||||
<< partOut.v_ms[2] << ";";
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Private Functions
|
||||
double Particle::r_m() {
|
||||
return ( sqrt( pow(x_m[0],2) + pow(x_m[1],2) ) );
|
||||
}
|
||||
|
||||
double Particle::vAbs_ms() {
|
||||
return ( sqrt( pow(v_ms[0],2) + pow(v_ms[1],2) + pow(v_ms[2],2)) );
|
||||
}
|
||||
|
||||
double Particle::beta() {
|
||||
return ( vAbs_ms()/c_ms );
|
||||
}
|
||||
|
||||
double Particle::gamma() {
|
||||
return ( pow(1- pow(beta(),2),-0.5));
|
||||
}
|
||||
|
||||
double Particle::Ekin_eV() {
|
||||
return ( (gamma()-1) * m_eV);
|
||||
}
|
||||
|
||||
double Particle::tau() {
|
||||
return (Ekin_eV()/me_eV) ;
|
||||
}
|
||||
|
||||
double Particle::eta() {
|
||||
double etac = (Ekin_eV() < 50e3)? 1.198 : 1.13+3.76*pow(ZT2/(137*beta()),2);
|
||||
return (etac * 1.7e-5 * pow(ZT2,2./3.) /( tau()*(tau()+2) ));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
double Particle::borisFly_m(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s) {
|
||||
double distance_m;
|
||||
x_m += dt_s/2 * v_ms;
|
||||
distance_m = dt_s/2 * vAbs_ms();
|
||||
this->changeSpeedBoris(E_Vm , B_T , dt_s);
|
||||
x_m += dt_s/2 * v_ms;
|
||||
distance_m += dt_s/2 * vAbs_ms();
|
||||
return(distance_m);
|
||||
}
|
||||
|
||||
void Particle::changeSpeedBoris(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s) {
|
||||
{
|
||||
blitz::TinyVector<double, 3> vMinus_ms, vPlus_ms, vPrime_ms, t, s;
|
||||
double q_C = -1*q_e * e_C;
|
||||
double m_kg = m_eV*e_C/c_ms/c_ms;
|
||||
|
||||
t = q_C*dt_s/(2*m_kg) * B_T;
|
||||
s = (2*t)/(1+dot(t,t));
|
||||
vMinus_ms = v_ms + (q_C*E_Vm*dt_s)/(2*m_kg);
|
||||
vPrime_ms = vMinus_ms + cross(vMinus_ms,t);
|
||||
vPlus_ms = vMinus_ms + cross(vPrime_ms,s);
|
||||
v_ms = vPlus_ms + q_C/m_kg*E_Vm*0.5*dt_s;
|
||||
}
|
||||
}
|
||||
|
||||
double Particle::getSigmaTot() {
|
||||
return(getSigmaEla());
|
||||
}
|
||||
|
||||
double Particle::getSigmaEla() {
|
||||
double nenner = pi*ZT2*(ZT2+1)*re_m*re_m * (1-pow(beta(),2));
|
||||
double zaehler = eta() * (eta()+1)*pow(beta(),4);
|
||||
return(nenner/zaehler);
|
||||
}
|
||||
|
||||
void Particle::doElaScat(ranlib::Uniform<double> *rngUni) {
|
||||
// Do Ela Scattering without Tritium Movement
|
||||
double const1 = 2*pi/getSigmaEla()*ZT2*(ZT2+1)*re_m*re_m*(1- pow(beta(),2) )* pow(beta(),-4);
|
||||
double theta = acos( pow( rngUni->random()/const1-pow(2*eta(),-1) , -1 ) +1+2*eta());
|
||||
|
||||
double phi = rngUni->random() * 2 * pi;
|
||||
double vAbsNew_ms = sqrt( pow(vAbs_ms(),2)*(1-4*m_eV*mT2_eV*pow(m_eV+mT2_eV,-2)*cos(theta)*cos(theta)) );
|
||||
|
||||
// Change of direction following Plante and Cucinotta
|
||||
double theta0 = acos(v_ms[2]/vAbs_ms());
|
||||
double phi0 = atan2(v_ms[1],v_ms[0]);
|
||||
|
||||
double A3 = sin(theta)*cos(phi);
|
||||
double A4 =A3*cos(theta0) + cos(theta)*sin(theta0);
|
||||
double A5 = sin(theta)*sin(phi);
|
||||
double A11 = A4*cos(phi0) - A5*sin(phi0);
|
||||
double A21 = A4*sin(phi0) + A5*cos(phi0);
|
||||
double theta1 = acos( cos(theta0)*cos(theta)-A3*sin(theta0) );
|
||||
|
||||
|
||||
// Get right phi1, maybe more elegant way later.
|
||||
double phi1c [4];
|
||||
double phi1 = -1;
|
||||
phi1c[0] = acos( A11/sin(theta1));
|
||||
phi1c[1] = 2*pi - phi1c[0];
|
||||
phi1c[2] = asin (A21/sin(theta1));
|
||||
phi1c[3] = pi - phi1c[2];
|
||||
phi1c[2] = (phi1c[2] > 0) ? phi1c[2] : 2*pi + phi1c[2];
|
||||
for (int i=0;i<3;i++) {
|
||||
for (int j=i+1;j<4;j++) {
|
||||
if (phi1c[i]-phi1c[j] < 0.0001) {
|
||||
phi1 = phi1c[i];
|
||||
goto endloops;
|
||||
}
|
||||
}
|
||||
}
|
||||
endloops:
|
||||
if (phi1 == -1) {
|
||||
std::cerr<<"Particle::doElaScat: phi1 not found."<<std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> vnew_ms;
|
||||
vnew_ms = sin(theta1)*cos(phi1) , sin(theta1)*sin(phi1) , cos(theta1) ;
|
||||
vnew_ms = vAbsNew_ms * vnew_ms;
|
||||
setSpeed_ms(vnew_ms);
|
||||
}
|
||||
|
||||
+34
-111
@@ -16,11 +16,15 @@
|
||||
#include <fstream>
|
||||
#include "blitz/array.h"
|
||||
#include "blitz/tinyvec2.h"
|
||||
#include <random/uniform.h>
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
typedef enum species{electron, positron, proton, tritium, tritium2, helium, deuterium, DT}species;
|
||||
std::ostream& operator<<(std::ostream& os, const species& SpecOut);
|
||||
|
||||
class Particle
|
||||
|
||||
class Particle: private Constants
|
||||
{
|
||||
private:
|
||||
double m_eV;
|
||||
@@ -30,6 +34,15 @@ private:
|
||||
species s;
|
||||
unsigned long int Id;
|
||||
unsigned long int parentId;
|
||||
|
||||
double r_m();
|
||||
double vAbs_ms();
|
||||
double beta();
|
||||
double gamma();
|
||||
double Ekin_eV();
|
||||
double tau();
|
||||
double eta();
|
||||
|
||||
public:
|
||||
|
||||
virtual ~Particle() { }
|
||||
@@ -43,125 +56,35 @@ public:
|
||||
s = spec;
|
||||
}
|
||||
|
||||
//Particle(Array<double, 1> props); //Create from Array
|
||||
|
||||
// Get Properties Methods
|
||||
double getMass_eV() {
|
||||
return(m_eV);
|
||||
}
|
||||
|
||||
double getCharge_e() {
|
||||
return(q_e);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> getLoc_m() {
|
||||
return(x_m);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> getSpeed_ms() {
|
||||
return(v_ms);
|
||||
}
|
||||
|
||||
double getId() {
|
||||
return(Id);
|
||||
}
|
||||
|
||||
double getParentId() {
|
||||
return(parentId);
|
||||
}
|
||||
|
||||
double getRadius_m() {
|
||||
return (sqrt( pow(x_m[0],2) + pow(x_m[1],2) ));
|
||||
}
|
||||
|
||||
double getSpeedAbs_ms() {
|
||||
return (sqrt( pow(v_ms[0],2) + pow(v_ms[1],2) + pow(v_ms[2],2)));
|
||||
}
|
||||
|
||||
double getKinEnergy_eV() {
|
||||
// Implement Constants here, else Particle::Parameters
|
||||
const double c_ms = 299792458;
|
||||
const double me_eV = 0.511e6;
|
||||
double SpeedAbs_ms = sqrt( pow(v_ms[0],2) + pow(v_ms[1],2) + pow(v_ms[2],2) );
|
||||
double beta = SpeedAbs_ms/c_ms;
|
||||
double gamma = pow(1- pow(beta,2),-0.5);
|
||||
return ( (gamma-1) * me_eV);
|
||||
}
|
||||
double getMass_eV() { return(m_eV); }
|
||||
double getCharge_e() { return(q_e); }
|
||||
blitz::TinyVector<double,3> getLoc_m() { return(x_m); }
|
||||
blitz::TinyVector<double,3> getSpeed_ms() { return(v_ms); }
|
||||
double getId() { return(Id); }
|
||||
double getParentId() { return(parentId); }
|
||||
double getRadius_m() { return ( r_m() ); }
|
||||
double getSpeedAbs_ms() { return (vAbs_ms() ); }
|
||||
double getKinEnergy_eV() { return (Ekin_eV() ); }
|
||||
|
||||
// Set Properties Methods
|
||||
void setLoc_m(blitz::TinyVector<double, 3> xnew_m) {x_m = xnew_m; };
|
||||
void setSpeed_ms(blitz::TinyVector<double, 3> vnew_ms) {v_ms = vnew_ms; };
|
||||
|
||||
// Boris Push
|
||||
double borisFly_m(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s);
|
||||
void changeLocFly(double dt_s);
|
||||
void changeSpeedBoris(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s);
|
||||
|
||||
// Cross Sections
|
||||
double getSigmaTot();
|
||||
double getSigmaEla();
|
||||
void doElaScat(ranlib::Uniform<double> *rngUni);
|
||||
|
||||
|
||||
// Write Methods
|
||||
friend std::ostream& operator<<(std::ostream& os, const Particle& partOut);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// Some Code, maybe required later
|
||||
/*
|
||||
blitz::TinyVector<double,3> locChange(blitz::TinyVector<double, 3> dx, int i, blitz::TinyVector<double, 3> xmin, blitz::TinyVector<double, 3> nx, blitz::TinyVector<double, 3> dvdt);
|
||||
blitz::TinyVector<double,3> speedChange(blitz::TinyVector<double, 3> dv, int i);
|
||||
|
||||
void copyol(particle*);
|
||||
Array<double,1> prop(Array<double,1>);
|
||||
virtual Array<double,1> array(); // ********************** warum virtual???? ******************************
|
||||
//void copyol(particle);
|
||||
*/
|
||||
/*
|
||||
class particle_info : public particle {
|
||||
|
||||
private:
|
||||
TinyVector<double,3> x0,p0;
|
||||
double id;
|
||||
double mue0;
|
||||
|
||||
public:
|
||||
particle_info(TinyVector<double,3> anfangsort, TinyVector<double,3> anfangsimpuls, double nummer, double anfangswinkel ):particle()
|
||||
{
|
||||
x0 = anfangsort;
|
||||
p0 = anfangsimpuls;
|
||||
mue0 = anfangswinkel;
|
||||
id = nummer;
|
||||
}
|
||||
|
||||
particle_info() { }
|
||||
~particle_info() { }
|
||||
|
||||
|
||||
TinyVector<double,3> anfangsort() { return(x0); }
|
||||
TinyVector<double,3> anfangsimpuls() { return(p0); }
|
||||
double nummer() { return(id); }
|
||||
double anfangswinkel() { return(mue0); }
|
||||
// virtual void copyol(particle_info*);
|
||||
|
||||
Array<double,1> array () // *********************** auslagern in .cpp **************************
|
||||
{
|
||||
Array<double,1> teilchenprop;
|
||||
TinyVector<int,1> temp;
|
||||
temp=8;
|
||||
teilchenprop.resize(temp);
|
||||
|
||||
x0 = this->anfangsort();
|
||||
p0 = this->anfangsimpuls();
|
||||
id = this->nummer();
|
||||
mue0 = this->anfangswinkel();
|
||||
|
||||
teilchenprop(0) = x0(0);
|
||||
teilchenprop(1) = x0(1);
|
||||
teilchenprop(2) = x0(2);
|
||||
teilchenprop(3) = p0(0);
|
||||
teilchenprop(4) = p0(1);
|
||||
teilchenprop(5) = p0(2);
|
||||
teilchenprop(6) = id;
|
||||
teilchenprop(7) = mue0;
|
||||
|
||||
return(teilchenprop);
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
// Other Functions
|
||||
|
||||
#endif
|
||||
|
||||
+57
-125
@@ -13,64 +13,34 @@ void Simulation::init() {
|
||||
}
|
||||
|
||||
void Simulation::doit() {
|
||||
double energy_eV,sigTot_m2, density_m3,MFP_m;
|
||||
blitz::TinyVector <double,3> oldLoc_m, newLoc_m;
|
||||
blitz::TinyVector <double,3> loc_m;
|
||||
bool insideFlag;
|
||||
|
||||
while (numInjectedParticles < numTotalParticles) {
|
||||
if (particleQueue.size() < 1) {
|
||||
particleQueue.assign(1,inject());
|
||||
while ( (numInjectedParticles < numTotalParticles) || (particleQue.size() > 0) ) {
|
||||
if (particleQue.size() < 1) {
|
||||
particleQue.push_back(inject());
|
||||
numInjectedParticles++;
|
||||
}
|
||||
|
||||
particleQueueIt = particleQueue.begin();
|
||||
while (particleQueueIt != particleQueue.end()) {
|
||||
step = 0;
|
||||
while (true) {
|
||||
energy_eV = particleQueueIt->getKinEnergy_eV();
|
||||
sigTot_m2 = sigmaTot_m2(energy_eV);
|
||||
density_m3 = Kat.getTritiumDensity(particleQueueIt->getLoc_m());
|
||||
MFP_m = 1/ ( density_m3 * sigTot_m2);
|
||||
oldLoc_m = particleQueueIt->getLoc_m();
|
||||
newLoc_m = move(*particleQueueIt ,MFP_m);
|
||||
if (movedOutside(newLoc_m)) {
|
||||
// Reflexion oder Absorbtion? Erstmal Reflexion
|
||||
newLoc_m = moveToLocOfDeath(*particleQueueIt);
|
||||
particleQueueIt->setLoc_m(newLoc_m);
|
||||
|
||||
writeToLogger(*particleQueueIt);
|
||||
goto particleDied;
|
||||
}
|
||||
|
||||
particleQueueIt->setLoc_m(newLoc_m);
|
||||
writeToLogger(*particleQueueIt);
|
||||
|
||||
|
||||
/*
|
||||
switch (getprocess()) {
|
||||
case "ElasticScattering":
|
||||
break;
|
||||
case "Ionization":
|
||||
break;
|
||||
case "Recombination";
|
||||
|
||||
partQueue.erase(partQueue.begin());
|
||||
continue;
|
||||
break;
|
||||
default:
|
||||
cerr<<"getprocess() returned unknown event"<<endl;
|
||||
break;
|
||||
}
|
||||
*/
|
||||
insideFlag = move(&particleQue.front());
|
||||
if (insideFlag) {
|
||||
switch (getInteraction(particleQue.front())) {
|
||||
case 0: // Elastic Scattering
|
||||
particleQue.front().doElaScat(&rngUni);
|
||||
break;
|
||||
case 1: // Ionization
|
||||
//particleQue.push_back();
|
||||
break;
|
||||
case 2: // Recombination
|
||||
particleQue.pop_front();
|
||||
break;
|
||||
default:
|
||||
std::cerr<<"getprocess() returned unknown event"<<std::endl;
|
||||
break;
|
||||
}
|
||||
particleDied:
|
||||
particleQueueIt++;
|
||||
|
||||
}else {
|
||||
particleQue.pop_front();
|
||||
}
|
||||
|
||||
writeToFile(&particleLogger);
|
||||
particleLogger.clear();
|
||||
|
||||
particleQueue = newParticles;
|
||||
newParticles.clear();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -93,15 +63,14 @@ Particle Simulation::inject() {
|
||||
// Add Code for corregtion of direction by tritium direction!!!
|
||||
|
||||
switch(injectionMethod) {
|
||||
case 1: // Fermi
|
||||
Ekin_eV = 1.; //Implement Later
|
||||
case 0: // Fermi
|
||||
Ekin_eV = 100.; //Implement Later
|
||||
break;
|
||||
|
||||
case 2: //Delta
|
||||
case 1: //Delta
|
||||
Ekin_eV = deltaKinEnergy_eV;
|
||||
break;
|
||||
case 3: //Maxwell Boltzman
|
||||
Ekin_eV = 1.; //Implement Later
|
||||
case 2: //Maxwell Boltzman
|
||||
Ekin_eV = 100.; //Implement Later
|
||||
break;
|
||||
default:
|
||||
std::cerr<<"Invalid Injection Method./n";
|
||||
@@ -112,59 +81,47 @@ Particle Simulation::inject() {
|
||||
absSpeed_ms = v_ms(Ekin_eV);
|
||||
speed_ms = absSpeed_ms * speedDir;
|
||||
|
||||
|
||||
return (Particle(me_eV,qe_e,loc_m, speed_ms,numInjectedParticles,NULL,electron));
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> Simulation::move(Particle inputParticle,double distance_m) {
|
||||
//Pseudocode, lineare bewegung
|
||||
blitz::TinyVector<double,3> oldLoc_m = inputParticle.getLoc_m();
|
||||
blitz::TinyVector<double,3> v_ms =inputParticle.getSpeed_ms();
|
||||
blitz::TinyVector<double,3> SpeedDir = pow(dot(v_ms,v_ms),-0.5)*v_ms;
|
||||
return( oldLoc_m + SpeedDir*distance_m);
|
||||
bool Simulation::move(Particle *inputParticle) {
|
||||
blitz::TinyVector<double,3> loc_m = inputParticle->getLoc_m();
|
||||
double density_m3 = Kat.getTritiumDensity(loc_m);
|
||||
blitz::TinyVector<double,3> E_Vm = Kat.getElField(loc_m);
|
||||
blitz::TinyVector<double,3> B_T = Kat.getMagField(loc_m);
|
||||
|
||||
double sigTot_m2 = inputParticle->getSigmaTot();
|
||||
double MFP_m = 1/(density_m3 * sigTot_m2);
|
||||
|
||||
double distance = 0.;
|
||||
while (distance < MFP_m) {
|
||||
distance += inputParticle->borisFly_m(E_Vm , B_T , dt_s);
|
||||
// Log Movment here!!!
|
||||
//std::cout<<*inputParticle<<std::endl;
|
||||
if (movedOutside(inputParticle->getLoc_m())) {
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool Simulation::movedOutside(blitz::TinyVector<double,3> loc_m) {
|
||||
double r_m = sqrt( pow(loc_m(0),2) + pow(loc_m(1),2) );
|
||||
return ( ! (loc_m[2]>0 && loc_m[2] < wgtsLength_m && r_m < wgtsRadius_m ) );
|
||||
return ( ! (loc_m[2]>0 && loc_m[2]<wgtsLength_m && r_m<wgtsRadius_m ) );
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> Simulation::moveToLocOfDeath(Particle inputParticle) {
|
||||
|
||||
// Führe methode 1 step für move ein, die einen einzelnen Schritt in move ausführt und benutze diese, bis an Rand
|
||||
double stepsize = inputParticle.getSpeedAbs_ms()*dt_s;
|
||||
blitz::TinyVector<double,3> loc_m = inputParticle.getLoc_m();
|
||||
blitz::TinyVector<double,2> rVec_m;
|
||||
double r_m;
|
||||
|
||||
// Include saftey calc for too small stepsize
|
||||
|
||||
int countfordebug = 0;
|
||||
while (!movedOutside(loc_m) ) {
|
||||
loc_m = move (inputParticle,stepsize);
|
||||
inputParticle.setLoc_m(loc_m);
|
||||
countfordebug++;
|
||||
}
|
||||
|
||||
if (loc_m(2) < 0) {
|
||||
loc_m(2) = 0;
|
||||
} else if (loc_m(2) > wgtsLength_m) {
|
||||
loc_m(2) = wgtsLength_m;
|
||||
}
|
||||
|
||||
r_m = sqrt(pow(loc_m(0),2)+pow(loc_m(1),2));
|
||||
if (r_m > wgtsRadius_m) {
|
||||
loc_m(0) = wgtsRadius_m/r_m * loc_m(0);
|
||||
loc_m(1) = wgtsRadius_m/r_m * (loc_m(1));
|
||||
}
|
||||
return (loc_m);
|
||||
int Simulation::getInteraction(Particle inputParticle) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
// Logging Methods
|
||||
void Simulation::writeToLogger(Particle inputParticle) {
|
||||
std::string textLine;
|
||||
|
||||
|
||||
|
||||
particleLogger.push_back(textLine);
|
||||
}
|
||||
@@ -180,35 +137,10 @@ void Simulation::writeToFile(std::vector<Particle> *particleLogger) {
|
||||
}
|
||||
outFile.close();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
// Cross Sections
|
||||
double Simulation::sigmaTot_m2(double Ekin_eV) {
|
||||
return(sigmaEla_m2(Ekin_eV));
|
||||
}
|
||||
|
||||
double Simulation::sigmaEla_m2(double Ekin_eV) {
|
||||
// From Plante and S Uehara et al 1998
|
||||
double Z, tau, beta, etac, eta, nenner, zaehler;
|
||||
Z = 1.;
|
||||
tau = Ekin_eV/me_eV;
|
||||
beta = v_ms(Ekin_eV)/c_ms;
|
||||
etac = (Ekin_eV < 50e3)? 1.198 : 1.13+3.76*pow(Z/(137*beta),2); //beta im nenner oder zähler?
|
||||
eta = etac * 1.7e-5 * pow(Z,2./3.) /( tau*(tau+2) );
|
||||
nenner = pi*Z*(Z+1)*re_m*re_m * (1-pow(beta,2));
|
||||
zaehler = eta * (eta+1)*pow(beta,4);
|
||||
return(nenner/zaehler);
|
||||
}
|
||||
|
||||
double Simulation::dSigmaEladOmega_m2 (double Ekin_eV, double Theta_rad, double Phi_rad) {
|
||||
// From Plante and S Uehara et al 1998
|
||||
double Z, tau, beta, etac, eta, nenner, zaehler;
|
||||
Z = 1.;
|
||||
tau = Ekin_eV/me_eV;
|
||||
beta = v_ms(Ekin_eV)/c_ms;
|
||||
etac = (Ekin_eV < 50e3)? 1.198 : 1.13+3.76*pow(Z/(137*beta),2); //beta im nenner oder zähler?
|
||||
eta = etac * 1.7e-5 * pow(Z,2./3.) /( tau*(tau+2) );
|
||||
nenner = Z*(Z+1)*re_m*re_m * (1-pow(beta,2));
|
||||
zaehler = pow(1.-cos(Theta_rad)+2*eta,2) * pow(beta,4);
|
||||
return(nenner/zaehler);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "blitz/array.h"
|
||||
@@ -30,8 +30,6 @@ public:
|
||||
Simulation() {
|
||||
numInjectedParticles = 0;
|
||||
rngUni.seed(seed);
|
||||
particleLogger.clear();
|
||||
outputName = "TestRun";
|
||||
|
||||
|
||||
// Check OutFile already existing? -no-> Create Outfile_1
|
||||
@@ -49,9 +47,17 @@ protected:
|
||||
Katrin Kat;
|
||||
ranlib::Uniform<double> rngUni;
|
||||
int numInjectedParticles;
|
||||
std::vector<Particle> particleQueue, newParticles;
|
||||
std::vector<Particle>::iterator particleQueueIt;
|
||||
std::deque<Particle> particleQue;
|
||||
|
||||
// Simulation Methods
|
||||
Particle inject();
|
||||
bool move(Particle *inputParticle);
|
||||
bool movedOutside(blitz::TinyVector<double,3> loc_m);
|
||||
|
||||
int getInteraction(Particle inPutParticle);
|
||||
|
||||
|
||||
/*
|
||||
// Logging Objects
|
||||
int step;
|
||||
std::string outputName;
|
||||
@@ -59,22 +65,13 @@ protected:
|
||||
std::vector<Particle>::iterator particleLoggerIt;
|
||||
std::ofstream outFile;
|
||||
|
||||
// Simulation Methods
|
||||
Particle inject();
|
||||
blitz::TinyVector<double,3> move(Particle inputParticle,double distance_m);
|
||||
bool movedOutside(blitz::TinyVector<double,3> loc_m);
|
||||
blitz::TinyVector<double,3> moveToLocOfDeath(Particle inputParticle);
|
||||
|
||||
// Logging Methods
|
||||
void writeToLogger(Particle inputParticle);
|
||||
void writeToFile(std::vector<Particle> *particleLogger);
|
||||
|
||||
// Cross Sections
|
||||
double sigmaTot_m2(double Ekin_eV);
|
||||
double sigmaEla_m2(double Ekin_eV);
|
||||
double dSigmaEladOmega_m2 (double Ekin_eV, double Theta_rad, double Phi_rad);
|
||||
|
||||
*/
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user