Aktuelle Stand
This commit is contained in:
@@ -9,33 +9,28 @@
|
||||
#include "energyhisto.h"
|
||||
|
||||
|
||||
void Energyhisto::addContent(double z1, double z2, double Energy) {
|
||||
int zLowBin = std::min(getZBin(z1),getZBin(z2));
|
||||
int zUpBin = std::max(getZBin(z1),getZBin(z2));
|
||||
int EBin = getEBin(Energy);
|
||||
void Energyhisto::addContent(double z1_m, double z2_m, double Energy_eV) {
|
||||
int zLowBin = std::min(getZBin(z1_m),getZBin(z2_m));
|
||||
int zUpBin = std::max(getZBin(z1_m),getZBin(z2_m));
|
||||
int EBin = getEBin(Energy_eV);
|
||||
data(blitz::Range(zLowBin,zUpBin),EBin) += 1;
|
||||
}
|
||||
|
||||
int Energyhisto::getZBin(double z) {
|
||||
if (z<0 || z>wgtsLength) {
|
||||
std::cerr<<"Energyhisto::getZBin: z = "<<z<<" outside out dimensions \n";
|
||||
int Energyhisto::getZBin(double z_m) {
|
||||
if (z_m<0 || z_m>wgtsLength_m) {
|
||||
std::cerr<<"Energyhisto::getZBin: z = "<<z_m<<" outside out dimensions \n";
|
||||
exit(1);
|
||||
}
|
||||
return(floor(z/ZBinWidth));
|
||||
return(floor(z_m/ZBinWidth));
|
||||
}
|
||||
|
||||
|
||||
int Energyhisto::getEBin(double E) {
|
||||
if (E<minEBin) {
|
||||
int Energyhisto::getEBin(double E_eV) {
|
||||
if (E_eV<minEBin) {
|
||||
return (0);
|
||||
} else if (E > maxEBin) {
|
||||
} else if (E_eV > maxEBin) {
|
||||
return(numberEBins + 1);
|
||||
} else {
|
||||
return(floor((E-minEBin)/EBinWidth));
|
||||
return(floor((E_eV-minEBin)/EBinWidth));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -27,31 +27,31 @@ public:
|
||||
data.resize(numberZBins,numberEBins+2); // Under and Overflow Bins
|
||||
data = 0;
|
||||
|
||||
ZBinWidth = wgtsLength/numberZBins;
|
||||
ZBinWidth = wgtsLength_m/numberZBins;
|
||||
EBinWidth = (maxEBin-minEBin)/numberEBins;
|
||||
|
||||
ZBinBoarders.resize(numberZBins+1);
|
||||
ZBinBoarders_m.resize(numberZBins+1);
|
||||
for (int i=0;i<numberZBins+1;i++) {
|
||||
ZBinBoarders[i] = ZBinWidth*i; //More fancy with blitz functions?
|
||||
ZBinBoarders_m[i] = ZBinWidth*i; //More fancy with blitz functions?
|
||||
}
|
||||
|
||||
EBinBoarders.resize(numberEBins+3);
|
||||
EBinBoarders_eV.resize(numberEBins+3);
|
||||
for (int i=0;i<numberEBins+1;i++) {
|
||||
EBinBoarders[i+1] = minEBin + i*EBinWidth; //More fancy with blitz functions?
|
||||
EBinBoarders_eV[i+1] = minEBin + i*EBinWidth; //More fancy with blitz functions?
|
||||
}
|
||||
};
|
||||
|
||||
int getZBin(double z);
|
||||
int getZBin(double z_m);
|
||||
|
||||
int getEBin(double E);
|
||||
int getEBin(double E_eV);
|
||||
|
||||
void addContent(double zLow, double zUp, double Energy);
|
||||
void addContent(double zLow_m, double zUp_m, double Energy_eV);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
double ZBinWidth, EBinWidth;
|
||||
blitz::Array <double,1> ZBinBoarders, EBinBoarders;
|
||||
blitz::Array <double,1> ZBinBoarders_m, EBinBoarders_eV;
|
||||
|
||||
blitz::Array<int,2> data;
|
||||
};
|
||||
|
||||
+12
-10
@@ -9,19 +9,21 @@
|
||||
|
||||
#include "katrin.h"
|
||||
|
||||
blitz::TinyVector<double,3> Katrin::getMagField(blitz::TinyVector<double,3> position) {
|
||||
blitz::TinyVector<double,3> tmp(0.,0.,wgtsMagField);
|
||||
return (tmp);
|
||||
|
||||
|
||||
blitz::TinyVector<double,3> Katrin::getMagField(blitz::TinyVector<double,3> loc_m) {
|
||||
blitz::TinyVector<double,3> MagField_T;
|
||||
MagField_T = 0,0,wgtsMagField_T;
|
||||
return(MagField_T);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> Katrin::getElField(blitz::TinyVector<double,3> position) {
|
||||
blitz::TinyVector<double, 3> tmp(0.,0.,0.);
|
||||
return (tmp);
|
||||
blitz::TinyVector<double,3> Katrin::getElField(blitz::TinyVector<double,3> loc_m) {
|
||||
blitz::TinyVector<double,3> ElField_Vm;
|
||||
ElField_Vm = 0,0,0;
|
||||
return (ElField_Vm);
|
||||
}
|
||||
|
||||
double Katrin::tritiumDensity(blitz::TinyVector<double,3> position) {
|
||||
return(0);
|
||||
double Katrin::getTritiumDensity(blitz::TinyVector<double,3> loc_m) {
|
||||
return(wgtsTritiumDensity_m3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -25,10 +25,10 @@ public:
|
||||
Katrin(){};
|
||||
virtual ~Katrin(){};
|
||||
|
||||
blitz::TinyVector<double,3> getMagField(blitz::TinyVector<double,3>);
|
||||
blitz::TinyVector<double,3> getElField(blitz::TinyVector<double,3>);
|
||||
double tritiumDensity(blitz::TinyVector<double,3>);
|
||||
|
||||
blitz::TinyVector<double,3> getMagField(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);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,11 +6,10 @@
|
||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#include "simulation.h"
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
Simulation SIM;
|
||||
SIM.init();
|
||||
SIM.doit();
|
||||
Simulation Sim;
|
||||
Sim.init();
|
||||
Sim.doit();
|
||||
}
|
||||
|
||||
+39
-35
@@ -16,32 +16,33 @@
|
||||
class Parameter
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~Parameter(){};
|
||||
|
||||
Parameter() {
|
||||
// Simulation Specs
|
||||
seed = (int)value("seed");
|
||||
numTotalParticles = (long int)value("numTotalParticles");
|
||||
dt = value("dt");
|
||||
dt_s = value("dt_s");
|
||||
injectionMethod = (int)value("injectionMethod");
|
||||
deltaKinEnergy = value("deltaKinEnergy");
|
||||
MBKinEnergy = value("MBKinEnergy");
|
||||
numberZBins = (int)value ("numberZBins");
|
||||
minEBin = value ("minEBin");
|
||||
maxEBin = value ("maxEBin");
|
||||
numberEBins = (int)value ("numberEBins");
|
||||
deltaKinEnergy_eV = value("deltaKinEnergy_eV");
|
||||
MBKinEnergy_eV = value("MBKinEnergy_eV");
|
||||
|
||||
wgtsMagField = value("wgtsMagField");
|
||||
wgtsLength = value("wgtsLength");
|
||||
wgtsDiameter = value("wgtsDiameter");
|
||||
|
||||
|
||||
constPi = value("constPi");
|
||||
constc = value("constc");
|
||||
constme = value("constme");
|
||||
constqe = value("constqe");
|
||||
// Katrin Specs
|
||||
wgtsMagField_T = value("wgtsMagField_T");
|
||||
wgtsLength_m = value("wgtsLength_m");
|
||||
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")) {
|
||||
char* str = strdup(strin.c_str());
|
||||
double temp;
|
||||
@@ -90,30 +91,33 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string configFilePath;
|
||||
|
||||
//Simulation specs
|
||||
//Simulation Specs
|
||||
int seed;
|
||||
long int numTotalParticles;
|
||||
double dt;
|
||||
double dt_s;
|
||||
int injectionMethod;
|
||||
double deltaKinEnergy;
|
||||
double MBKinEnergy;
|
||||
int numberZBins;
|
||||
double minEBin;
|
||||
double maxEBin;
|
||||
int numberEBins;
|
||||
double deltaKinEnergy_eV;
|
||||
double MBKinEnergy_eV;
|
||||
|
||||
|
||||
//KATRIN Specs
|
||||
double wgtsMagField;
|
||||
double wgtsLength;
|
||||
double wgtsDiameter;
|
||||
double wgtsMagField_T;
|
||||
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) );
|
||||
}
|
||||
|
||||
// physical constants
|
||||
double constPi;
|
||||
double constc;
|
||||
double constme;
|
||||
double constqe;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
seed = 2342395328
|
||||
numTotalParticles = 10
|
||||
dt = 0.00001
|
||||
numTotalParticles = 100
|
||||
dt_s = 0.00000001
|
||||
injectionMethod = 2
|
||||
deltaKinEnergy = 10
|
||||
MBKinEnergy = 4.14e-22 J
|
||||
deltaKinEnergy_eV = 100
|
||||
MBKinEnergy_eV = 100
|
||||
|
||||
numberZBins = 10
|
||||
minEBin = 0
|
||||
@@ -11,13 +11,10 @@ maxEBin = 10
|
||||
numberEBins = 10
|
||||
|
||||
|
||||
wgtsMagField = 2.5
|
||||
wgtsLength = 10
|
||||
wgtsDiameter = 10
|
||||
wgtsMagField_T = 2.5
|
||||
wgtsLength_m = 10
|
||||
wgtsRadius_m = 0.045
|
||||
wgtsTritiumDensity_m3 = 5e21
|
||||
wgtsTemp_K = 27.
|
||||
|
||||
|
||||
|
||||
constPi = 3.14159265
|
||||
constc = 299792458
|
||||
constme = 9.10938356e-31 m
|
||||
constqe = −1.6021766208e-19 C
|
||||
|
||||
@@ -43,8 +43,17 @@ std::ostream& operator<<(std::ostream& os, const species& SpecOut) {
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Particle& partOut) {
|
||||
os << "(" << partOut.id<<","<<partOut.s<<","<<partOut.m << "," << partOut.q << ","<< partOut.x<<","<< partOut.v <<")";
|
||||
os
|
||||
<< partOut.Id << ";"
|
||||
<<partOut.parentId << ";"
|
||||
<<partOut.s << ";"
|
||||
<<partOut.m_eV << ";"
|
||||
<< partOut.q_e << ";"
|
||||
<< partOut.x_m[0] << ";"
|
||||
<< partOut.x_m[1] << ";"
|
||||
<< partOut.x_m[2] << ";"
|
||||
<< partOut.v_ms[0] << ";"
|
||||
<< partOut.v_ms[1] << ";"
|
||||
<< partOut.v_ms[2] << ";";
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+48
-36
@@ -20,85 +20,95 @@
|
||||
typedef enum species{electron, positron, proton, tritium, tritium2, helium, deuterium, DT}species;
|
||||
std::ostream& operator<<(std::ostream& os, const species& SpecOut);
|
||||
|
||||
|
||||
class Particle
|
||||
{
|
||||
private:
|
||||
double m,q;
|
||||
blitz::TinyVector<double,3> x,v;
|
||||
double m_eV;
|
||||
double q_e;
|
||||
blitz::TinyVector<double,3> x_m;
|
||||
blitz::TinyVector<double,3> v_ms;
|
||||
species s;
|
||||
long int id, parentId;
|
||||
unsigned long int Id;
|
||||
unsigned long int parentId;
|
||||
public:
|
||||
|
||||
virtual ~Particle() { }
|
||||
Particle(){}
|
||||
Particle(double mass, double charge,blitz::TinyVector<double,3> loc, blitz::TinyVector<double,3> speed, double idnum, double parentIdnum, species spec) {
|
||||
m = mass;
|
||||
q = charge;
|
||||
x = loc;
|
||||
v = speed;
|
||||
id = idnum;
|
||||
Particle(double mass_eV, double charge_e,blitz::TinyVector<double,3> loc_m, blitz::TinyVector<double,3> speed_ms, double idnum, double parentIdnum, species spec) {
|
||||
m_eV = mass_eV;
|
||||
q_e = charge_e;
|
||||
x_m = loc_m;
|
||||
v_ms = speed_ms;
|
||||
Id = idnum;
|
||||
parentId = parentIdnum;
|
||||
s = spec;
|
||||
}
|
||||
|
||||
//Particle(Array<double, 1> props); //Create from Array
|
||||
|
||||
double getMass() {
|
||||
return(m);
|
||||
// Get Properties Methods
|
||||
double getMass_eV() {
|
||||
return(m_eV);
|
||||
}
|
||||
|
||||
double getCharge() {
|
||||
return(q);
|
||||
double getCharge_e() {
|
||||
return(q_e);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> getLoc() {
|
||||
return(x);
|
||||
blitz::TinyVector<double,3> getLoc_m() {
|
||||
return(x_m);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> getSpeed() {
|
||||
return(v);
|
||||
blitz::TinyVector<double,3> getSpeed_ms() {
|
||||
return(v_ms);
|
||||
}
|
||||
|
||||
double getId() {
|
||||
return(id);
|
||||
return(Id);
|
||||
}
|
||||
|
||||
double getParentId() {
|
||||
return(parentId);
|
||||
}
|
||||
|
||||
double getRadius() {
|
||||
return (sqrt( pow(x[0],2) + pow(x[1],2) ));
|
||||
double getRadius_m() {
|
||||
return (sqrt( pow(x_m[0],2) + pow(x_m[1],2) ));
|
||||
}
|
||||
|
||||
double getSpeedAbs() {
|
||||
return (sqrt( pow(v[0],2) + pow(v[1],2) + pow(v[2],2)));
|
||||
double getSpeedAbs_ms() {
|
||||
return (sqrt( pow(v_ms[0],2) + pow(v_ms[1],2) + pow(v_ms[2],2)));
|
||||
}
|
||||
|
||||
double getEnergy(); // muss noch implementiert werden
|
||||
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);
|
||||
}
|
||||
|
||||
// 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; };
|
||||
|
||||
void setLoc(blitz::TinyVector<double, 3> xnew) {x = xnew; };
|
||||
void setSpeed(blitz::TinyVector<double, 3> vnew) {v = vnew; };
|
||||
// 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);
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const Particle& partOut);
|
||||
|
||||
/*
|
||||
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 {
|
||||
|
||||
@@ -152,4 +162,6 @@ public:
|
||||
};
|
||||
*/
|
||||
|
||||
// Other Functions
|
||||
|
||||
#endif
|
||||
|
||||
+157
-94
@@ -7,76 +7,85 @@
|
||||
//
|
||||
|
||||
#include "simulation.h"
|
||||
|
||||
//
|
||||
void Simulation::init() {
|
||||
|
||||
}
|
||||
|
||||
void Simulation::doit() {
|
||||
double MFP;
|
||||
blitz::TinyVector <double,3> oldLoc, newLoc;
|
||||
// Iterator nicht mit push_back möglich
|
||||
// Laufe vorderstes Teilchen bis zum Tod durch, entferne es dann aus der Liste
|
||||
double energy_eV,sigTot_m2, density_m3,MFP_m;
|
||||
blitz::TinyVector <double,3> oldLoc_m, newLoc_m;
|
||||
|
||||
while (numInjectedParticles < numTotalParticles) {
|
||||
inject();
|
||||
|
||||
while (particleQueue.size()>0) {
|
||||
// Run Code for first particle in Queue
|
||||
|
||||
MFP = calcMFP();
|
||||
oldLoc = particleQueue[0].getLoc();
|
||||
|
||||
std::cout << "Before move: " <<particleQueue[0]<<std::endl;
|
||||
|
||||
move (MFP,0);
|
||||
|
||||
|
||||
std::cout << "After move: " <<particleQueue[0]<<std::endl;
|
||||
|
||||
|
||||
if (movedOutside(0)) {
|
||||
moveToLocOfDeath(oldLoc,0);
|
||||
// updateDensity(oldLoc, partQueue[0].getEnergy());
|
||||
std::cout << "Death position: " <<particleQueue[0]<<std::endl;
|
||||
particleQueue.erase(particleQueue.begin());
|
||||
continue;
|
||||
} else {
|
||||
//newLoc = partQueue[0];
|
||||
//updateDensity(oldLoc,newLoc,partQueue[0].getEnergy());
|
||||
}
|
||||
/*
|
||||
switch (getprocess()) {
|
||||
case "ElasticScattering":
|
||||
break;
|
||||
case "Ionization":
|
||||
break;
|
||||
case "Recombination";
|
||||
|
||||
partQueue.erase(partQueue.begin());
|
||||
continue
|
||||
break;
|
||||
default:
|
||||
cerr<<"getprocess() returned unknown event"<<endl;
|
||||
break;
|
||||
}
|
||||
*/
|
||||
//particleQueue.erase(particleQueue.begin());
|
||||
if (particleQueue.size() < 1) {
|
||||
particleQueue.assign(1,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;
|
||||
}
|
||||
*/
|
||||
}
|
||||
particleDied:
|
||||
particleQueueIt++;
|
||||
}
|
||||
|
||||
writeToFile(&particleLogger);
|
||||
particleLogger.clear();
|
||||
|
||||
particleQueue = newParticles;
|
||||
newParticles.clear();
|
||||
}
|
||||
};
|
||||
|
||||
void Simulation::inject() {
|
||||
blitz::TinyVector<double,3> loc, speed;
|
||||
double r,phi,z;
|
||||
|
||||
// Simulation Methods
|
||||
Particle Simulation::inject() {
|
||||
blitz::TinyVector<double,3> loc_m, speed_ms;
|
||||
double r_m,phi_rad,z_m;
|
||||
blitz::TinyVector<double,3> speedDir;
|
||||
double Ekin,absSpeed;
|
||||
double Ekin_eV,absSpeed_ms;
|
||||
|
||||
r = rngUni.random()*wgtsDiameter;
|
||||
phi = rngUni.random()*2*constPi;
|
||||
z = rngUni.random()*wgtsLength;
|
||||
loc = r*cos(phi),r*sin(phi),z;
|
||||
r_m = rngUni.random()*wgtsRadius_m;
|
||||
phi_rad = rngUni.random()*2*pi;
|
||||
z_m = rngUni.random()*wgtsLength_m;
|
||||
loc_m = r_m*cos(phi_rad),r_m*sin(phi_rad),z_m;
|
||||
// Add Code taking in account tritium density
|
||||
|
||||
speedDir = rngUni.random(),rngUni.random(),rngUni.random();
|
||||
@@ -85,67 +94,121 @@ void Simulation::inject() {
|
||||
|
||||
switch(injectionMethod) {
|
||||
case 1: // Fermi
|
||||
Ekin = 1.; //Implement Later
|
||||
Ekin_eV = 1.; //Implement Later
|
||||
break;
|
||||
|
||||
case 2: //Delta
|
||||
Ekin = deltaKinEnergy;
|
||||
Ekin_eV = deltaKinEnergy_eV;
|
||||
break;
|
||||
case 3: //Maxwell Boltzman
|
||||
Ekin = 1.; //Implement Later
|
||||
Ekin_eV = 1.; //Implement Later
|
||||
break;
|
||||
default:
|
||||
std::cerr<<"Invalid Injection Method./n";
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
|
||||
absSpeed = sqrt( pow(constc,2) - ( pow(constme,2)*pow(constc,6) ) / pow( Ekin + constme*pow(constc,2) , 2 ) );
|
||||
speed = absSpeed * speedDir;
|
||||
|
||||
absSpeed_ms = v_ms(Ekin_eV);
|
||||
speed_ms = absSpeed_ms * speedDir;
|
||||
|
||||
|
||||
particleQueue.assign(1,Particle(constme,constqe,loc, speed,numInjectedParticles,NULL,electron));
|
||||
numInjectedParticles++;
|
||||
return (Particle(me_eV,qe_e,loc_m, speed_ms,numInjectedParticles,NULL,electron));
|
||||
}
|
||||
|
||||
void Simulation::move(double MFP,int queueNum) {
|
||||
if (queueNum > particleQueue.size()-1) {
|
||||
std::cerr<<"queueNum outside of size"<<std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> Simulation::move(Particle inputParticle,double distance_m) {
|
||||
//Pseudocode, lineare bewegung
|
||||
blitz::TinyVector<double,3> SpeedDir;
|
||||
SpeedDir = 1./sqrt(dot(particleQueue[queueNum].getSpeed(),particleQueue[queueNum].getSpeed()))*particleQueue[queueNum].getSpeed();
|
||||
particleQueue[queueNum].setLoc(particleQueue[queueNum].getLoc() + SpeedDir*MFP);
|
||||
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::movedOutside(int queueNum) {
|
||||
if (queueNum > particleQueue.size()-1) {
|
||||
std::cerr<<"queueNum outside of size"<<std::endl;
|
||||
exit(1);
|
||||
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 ) );
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> loc = particleQueue[queueNum].getLoc();
|
||||
double r = particleQueue[queueNum].getRadius();
|
||||
return (!(loc[2]>0 && loc[2]<wgtsLength && r<(wgtsDiameter/2) ));
|
||||
}
|
||||
|
||||
void Simulation::moveToLocOfDeath(blitz::TinyVector<double,3> oldLoc, int queueNum) {
|
||||
double stepsize = particleQueue[queueNum].getSpeedAbs()*dt;
|
||||
particleQueue[queueNum].setLoc(oldLoc);
|
||||
while (!movedOutside(queueNum) ) {
|
||||
move (stepsize,queueNum);
|
||||
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));
|
||||
}
|
||||
if (particleQueue[queueNum].getLoc()(2)<0) {
|
||||
particleQueue[queueNum].getLoc()(2) = 0;
|
||||
} else if (particleQueue[queueNum].getLoc()(2)>wgtsLength) {
|
||||
particleQueue[queueNum].getLoc()(2) = wgtsLength;
|
||||
return (loc_m);
|
||||
}
|
||||
|
||||
|
||||
// Logging Methods
|
||||
void Simulation::writeToLogger(Particle inputParticle) {
|
||||
std::string textLine;
|
||||
|
||||
|
||||
particleLogger.push_back(textLine);
|
||||
}
|
||||
|
||||
|
||||
void Simulation::writeToFile(std::vector<Particle> *particleLogger) {
|
||||
// Write all electrons to one file, just append them, ID for identification
|
||||
// Writing after every particle is very time intense.... Buffer and write only once every...
|
||||
|
||||
outFile.open (outputName,std::ios::app);
|
||||
for (particleLoggerIt = particleLogger->begin() ; particleLoggerIt != particleLogger->end() ; particleLoggerIt++) {
|
||||
outFile << *particleLoggerIt<<std::endl;
|
||||
}
|
||||
// Runde Position auf Rand
|
||||
outFile.close();
|
||||
}
|
||||
|
||||
|
||||
double Simulation::calcMFP() {
|
||||
return(1);
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "parameter.h"
|
||||
#include "katrin.h"
|
||||
#include "particle.h"
|
||||
#include "energyhisto.h"
|
||||
|
||||
|
||||
class Simulation: public Parameter
|
||||
@@ -31,33 +30,51 @@ public:
|
||||
Simulation() {
|
||||
numInjectedParticles = 0;
|
||||
rngUni.seed(seed);
|
||||
particleLogger.clear();
|
||||
outputName = "TestRun";
|
||||
|
||||
|
||||
// Check OutFile already existing? -no-> Create Outfile_1
|
||||
// -yes-> Create Outfile_i+1
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
void init(void);
|
||||
void doit(void);
|
||||
void inject();
|
||||
void output(void);
|
||||
|
||||
|
||||
void move(double MFP,int queueNum=0);
|
||||
bool movedOutside(int queueNum=0);
|
||||
void moveToLocOfDeath(blitz::TinyVector<double,3> oldLoc, int queueNum=0);
|
||||
|
||||
double calcMFP();
|
||||
|
||||
protected:
|
||||
Katrin KAT;
|
||||
// Simulation Objects
|
||||
Katrin Kat;
|
||||
ranlib::Uniform<double> rngUni;
|
||||
|
||||
double t;
|
||||
double id;
|
||||
|
||||
std::vector<Particle> particleQueue;
|
||||
int numInjectedParticles;
|
||||
std::vector<Particle> particleQueue, newParticles;
|
||||
std::vector<Particle>::iterator particleQueueIt;
|
||||
|
||||
// Logging Objects
|
||||
int step;
|
||||
std::string outputName;
|
||||
std::vector<std::string> particleLogger;
|
||||
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