updated version
This commit is contained in:
@@ -18,18 +18,20 @@
|
|||||||
#include "parameter.h"
|
#include "parameter.h"
|
||||||
#include "katrin.h"
|
#include "katrin.h"
|
||||||
|
|
||||||
TinyVector<double,3> katrin::magneticfield(TinyVector<double,3>)
|
TinyVector<double,3> Katrin::magField(TinyVector<double,3>)
|
||||||
{
|
{
|
||||||
return(0,0,magFieldSetValue);
|
return(0,0,wgtsMagField);
|
||||||
}
|
}
|
||||||
|
|
||||||
double katrin::tritiumdichte(TinyVector<double,3>)
|
TinyVector<double,3> Katrin::elField(TinyVector<double,3>)
|
||||||
{
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TinyVector<double,3> electricfield(TinyVector<double,3>)
|
|
||||||
{
|
{
|
||||||
return(0,0,0);
|
return(0,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Katrin::tritiumDensity(TinyVector<double,3>)
|
||||||
|
{
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,15 +19,15 @@
|
|||||||
#include "particle.h"
|
#include "particle.h"
|
||||||
#include "parameter.h"
|
#include "parameter.h"
|
||||||
|
|
||||||
class katrin: public Parameter
|
class Katrin: public Parameter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
katrin(){};
|
Katrin(){};
|
||||||
virtual ~katrin(){};
|
virtual ~Katrin(){};
|
||||||
|
|
||||||
TinyVector<double,3> magneticfield(TinyVector<double,3>);
|
TinyVector<double,3> magField(TinyVector<double,3>);
|
||||||
TinyVector<double,3> electricfield(TinyVector<double,3>);
|
TinyVector<double,3> elField(TinyVector<double,3>);
|
||||||
double tritiumdichte(TinyVector<double,3>);
|
double tritiumDensity(TinyVector<double,3>);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
//
|
//
|
||||||
// Created by Christian Reiling on 13.09.18.
|
// Created by Christian Reiling on 13.09.18.
|
||||||
//
|
//
|
||||||
|
//Notes: SI-system
|
||||||
|
|
||||||
|
//Tasks:
|
||||||
|
// 1. Take in account tritium density for location distribution
|
||||||
|
// 2. Take in account tritium flow speed for speed distribution
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@@ -23,13 +28,9 @@
|
|||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
//Simulation SIM;
|
Simulation SIM;
|
||||||
//SIM.init();
|
SIM.init();
|
||||||
Uniform<double> x;
|
SIM.inject();
|
||||||
x.seed(141244);
|
|
||||||
cout<<x.random()<<endl;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
cout <<"___"<<endl;
|
cout <<"___"<<endl;
|
||||||
TinyVector<float,2> A;
|
TinyVector<float,2> A;
|
||||||
|
|||||||
+32
-39
@@ -22,45 +22,24 @@ public:
|
|||||||
|
|
||||||
Parameter()
|
Parameter()
|
||||||
{
|
{
|
||||||
configFilePath = "parameters.cat";
|
seed = (int)value("seed");
|
||||||
seed = (int)getVariable("seed");
|
numTotalParticles = (long int)value("numTotalParticles");
|
||||||
totalParticles = (long int)getVariable("totalParticles");
|
dt = value("dt");
|
||||||
dt = getVariable("dt");
|
injectionMethod = (int)value("injectionMethod");
|
||||||
magFieldSetValue = getVariable("magFieldSetValue");
|
deltaKinEnergy = value("deltaKinEnergy");
|
||||||
|
MBKinEnergy = value("MBKinEnergy");
|
||||||
|
|
||||||
|
wgtsMagField = value("wgtsMagField");
|
||||||
|
wgtsLength = value("wgtsLength");
|
||||||
|
wgtsDiameter = value("wgtsDiameter");
|
||||||
|
|
||||||
|
|
||||||
|
constPi = value("constPi");
|
||||||
|
constc = value("constc");
|
||||||
|
constme = value("constme");
|
||||||
|
constqe = value("constqe");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double getVariable(string varName) // Reads Parameter from config file
|
|
||||||
{
|
|
||||||
string varTemp;
|
|
||||||
double valueTemp;
|
|
||||||
ifstream configFile;
|
|
||||||
|
|
||||||
configFile.open (configFilePath);
|
|
||||||
if (!configFile)
|
|
||||||
{
|
|
||||||
cout<< configFilePath <<" not found " <<endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (configFile >> varTemp >> valueTemp)
|
|
||||||
{
|
|
||||||
if (varName.compare(varTemp)==0)
|
|
||||||
{
|
|
||||||
configFile.close();
|
|
||||||
return(valueTemp);
|
|
||||||
}
|
|
||||||
configFile.ignore(numeric_limits<streamsize>::max(), '\n'); // jump to end of line
|
|
||||||
}
|
|
||||||
configFile.close();
|
|
||||||
std::cout<< varName << " not found." <<std::endl;
|
|
||||||
exit(1);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
double value(char *str, char* ext = "cat") // Reads Parameter from config file
|
double value(char *str, char* ext = "cat") // Reads Parameter from config file
|
||||||
{
|
{
|
||||||
double temp;
|
double temp;
|
||||||
@@ -107,14 +86,28 @@ public:
|
|||||||
exit(1);
|
exit(1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
string configFilePath;
|
string configFilePath;
|
||||||
|
|
||||||
|
//Simulation specs
|
||||||
int seed;
|
int seed;
|
||||||
long int totalParticles;
|
long int numTotalParticles;
|
||||||
double dt;
|
double dt;
|
||||||
double magFieldSetValue;
|
int injectionMethod;
|
||||||
|
double deltaKinEnergy;
|
||||||
|
double MBKinEnergy;
|
||||||
|
|
||||||
|
//KATRIN Specs
|
||||||
|
double wgtsMagField;
|
||||||
|
double wgtsLength;
|
||||||
|
double wgtsDiameter;
|
||||||
|
|
||||||
|
// physical constants
|
||||||
|
double constPi;
|
||||||
|
double constc;
|
||||||
|
double constme;
|
||||||
|
double constqe;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,18 @@
|
|||||||
seed 2342395328
|
seed = 2342395328
|
||||||
totalParticles 1000
|
numTotalParticles = 1000
|
||||||
dt 5
|
dt = 5
|
||||||
magFieldSetValue 2.5
|
injectionMethod = 2
|
||||||
|
deltaKinEnergy = 10
|
||||||
|
MBKinEnergy = 10
|
||||||
|
|
||||||
|
|
||||||
|
wgtsMagField = 2.5
|
||||||
|
wgtsLength = 100
|
||||||
|
wgtsDiameter = 10
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
constPi = 3.14159265
|
||||||
|
constc = 299792458
|
||||||
|
constme = 9.10938356e-31 m
|
||||||
|
constqe = −1.6021766208e-19 C
|
||||||
|
|||||||
@@ -12,3 +12,11 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "blitz/array.h"
|
#include "blitz/array.h"
|
||||||
#include "blitz/tinyvec2.h"
|
#include "blitz/tinyvec2.h"
|
||||||
|
|
||||||
|
#include "particle.h"
|
||||||
|
|
||||||
|
ostream& operator<<(ostream& os, const Particle& partOut)
|
||||||
|
{
|
||||||
|
os << "(" << partOut.id<<","<<partOut.s<<","<<partOut.m << "," << partOut.q << ","<< partOut.x<<","<< partOut.v <<")";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
//
|
//
|
||||||
// Created by Christian Reiling on 13.09.18.
|
// Created by Christian Reiling on 13.09.18.
|
||||||
//
|
//
|
||||||
|
// Notes: Energy being calculated using speed and mass
|
||||||
|
|
||||||
#ifndef particle_h
|
#ifndef particle_h
|
||||||
#define particle_h
|
#define particle_h
|
||||||
@@ -20,29 +21,28 @@ typedef enum species{electron, positron, proton, tritium, tritium2, helium, deut
|
|||||||
|
|
||||||
using namespace blitz;
|
using namespace blitz;
|
||||||
|
|
||||||
class particle
|
class Particle
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
double m,q,E;
|
double m,q;
|
||||||
TinyVector<double,3> x,v;
|
TinyVector<double,3> x,v;
|
||||||
species s;
|
species s;
|
||||||
long int id;
|
long int id;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~particle() { }
|
virtual ~Particle() { }
|
||||||
particle(){}
|
Particle(){}
|
||||||
particle(double mass, double charge, double energy,TinyVector<double,3> loc, TinyVector<double,3> speed, double idnum, species spec)
|
Particle(double mass, double charge,TinyVector<double,3> loc, TinyVector<double,3> speed, double idnum, species spec)
|
||||||
{
|
{
|
||||||
m = mass;
|
m = mass;
|
||||||
q = charge;
|
q = charge;
|
||||||
E = energy;
|
|
||||||
x = loc;
|
x = loc;
|
||||||
v = speed;
|
v = speed;
|
||||||
id = idnum;
|
id = idnum;
|
||||||
s = spec;
|
s = spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
//particle(Array<double, 1> props); //Create from Array
|
//Particle(Array<double, 1> props); //Create from Array
|
||||||
|
|
||||||
double mass() { return(m); }
|
double mass() { return(m); }
|
||||||
double charge() { return(q); }
|
double charge() { return(q); }
|
||||||
@@ -55,8 +55,7 @@ public:
|
|||||||
TinyVector<double, 3> locSet(TinyVector<double, 3> xneu) { return x = xneu; };
|
TinyVector<double, 3> locSet(TinyVector<double, 3> xneu) { return x = xneu; };
|
||||||
TinyVector<double, 3> speedSet(TinyVector<double, 3> vneu);
|
TinyVector<double, 3> speedSet(TinyVector<double, 3> vneu);
|
||||||
|
|
||||||
|
friend ostream& operator<<(ostream& os, const Particle& partOut);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void copyol(particle*);
|
void copyol(particle*);
|
||||||
@@ -67,6 +66,9 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
class particle_info : public particle {
|
class particle_info : public particle {
|
||||||
|
|
||||||
|
|||||||
@@ -20,27 +20,26 @@
|
|||||||
|
|
||||||
void Simulation::init()
|
void Simulation::init()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Simulation::doit()
|
void Simulation::doit()
|
||||||
{
|
{
|
||||||
double totalcross, mfp;
|
double sigmaTot, MFP;
|
||||||
TinyVector <double,3> alterort, neuerort;
|
TinyVector <double,3> oldLoc, newLoc;
|
||||||
while (injectedparticles < totalParticles)
|
while (numInjectedParticles < numTotalParticles)
|
||||||
{
|
{
|
||||||
if (teilchenliste.size() == 0 )
|
if (particleQueue.size() == 0 )
|
||||||
{
|
{
|
||||||
inject();
|
inject();
|
||||||
}
|
}
|
||||||
for(teilcheniterator = teilchenliste.begin();
|
for(particleQueueIt = particleQueue.begin();
|
||||||
teilcheniterator != teilchenliste.end();
|
particleQueueIt != particleQueue.end();
|
||||||
teilcheniterator++)
|
particleQueueIt++)
|
||||||
{
|
{
|
||||||
totalcross = calctotalcross(*teilcheniterator);
|
sigmaTot = calctotalcross(*particleQueueIt);
|
||||||
mfp = 1/totalcross/KAT.tritiumdichte(teilcheniterator->ort());
|
MFP = 1/sigmaTot/KAT.tritiumDensity(particleQueueIt->loc());
|
||||||
alterort = teilcheniterator->ort();
|
oldLoc = particleQueueIt->loc();
|
||||||
move (*teilcheniterator, mfp);
|
move (*particleQueueIt, MFP);
|
||||||
|
|
||||||
//selectprocess(*teilcheniterator);
|
//selectprocess(*teilcheniterator);
|
||||||
//if (alterort(2) > 0.5)
|
//if (alterort(2) > 0.5)
|
||||||
@@ -52,21 +51,55 @@ void Simulation::doit()
|
|||||||
|
|
||||||
void Simulation::inject()
|
void Simulation::inject()
|
||||||
{
|
{
|
||||||
TinyVector<double,3> ort, geschwindigkeit;
|
TinyVector<double,3> loc, speed;
|
||||||
ort = 0,0,0;
|
double r,phi,z;
|
||||||
geschwindigkeit = 1,0,0;
|
TinyVector<double,3> speedDir;
|
||||||
particle egon(9.109383e-28,1,ort, geschwindigkeit,injectedparticles,electron);
|
double Ekin,absSpeed;
|
||||||
injectedparticles++;
|
|
||||||
|
|
||||||
|
r = rngUni.random()*wgtsDiameter;
|
||||||
|
phi = rngUni.random()*2*constPi;
|
||||||
|
z = rngUni.random()*wgtsLength;
|
||||||
|
loc = r*cos(phi),r*sin(phi),z;
|
||||||
|
// Add Code taking in account tritium density
|
||||||
|
|
||||||
|
speedDir = rngUni.random(),rngUni.random(),rngUni.random();
|
||||||
|
speedDir = 1./sqrt(dot(speedDir,speedDir))*speedDir;
|
||||||
|
// Add Code for corregtion of direction by tritium direction!!!
|
||||||
|
|
||||||
|
switch(injectionMethod)
|
||||||
|
{
|
||||||
|
case 1: // Fermi
|
||||||
|
Ekin = 1.; //Implement Later
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2: //Delta
|
||||||
|
Ekin = deltaKinEnergy;
|
||||||
|
break;
|
||||||
|
case 3: //Maxwell Boltzman
|
||||||
|
Ekin = 1.; //Implement Later
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
particleQueue.assign(1,Particle(constme,constqe,loc, speed,numInjectedParticles,electron));
|
||||||
|
numInjectedParticles++;
|
||||||
}
|
}
|
||||||
void Simulation::move(particle inputparticle, double mfp)
|
|
||||||
|
void Simulation::move(Particle inParticle, double length)
|
||||||
{
|
{
|
||||||
//Borispush
|
//Borispush
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double calctotalcross(particle inputparticle)
|
double calctotalcross(Particle inputparticle)
|
||||||
{
|
{
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,32 +32,32 @@ public:
|
|||||||
~Simulation(){};
|
~Simulation(){};
|
||||||
Simulation()
|
Simulation()
|
||||||
{
|
{
|
||||||
injectedparticles = 0;
|
numInjectedParticles = 0;
|
||||||
|
rngUni.seed(seed);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void init(void);
|
void init(void);
|
||||||
|
|
||||||
void doit(void);
|
void doit(void);
|
||||||
void inject();
|
void inject();
|
||||||
void move(particle inputparticle, double mfp);
|
void move(Particle inputparticle, double mfp);
|
||||||
void output(void);
|
void output(void);
|
||||||
|
|
||||||
|
|
||||||
double calctotalcross(particle inputparticle){return 0;};
|
double calctotalcross(Particle inputparticle){return 0;};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
katrin KAT;
|
Katrin KAT;
|
||||||
|
Uniform<double> rngUni;
|
||||||
|
|
||||||
|
double t;
|
||||||
double zeit;
|
|
||||||
int zeitschritt;
|
|
||||||
double id;
|
double id;
|
||||||
|
|
||||||
vector<particle> teilchenliste;
|
vector<Particle> particleQueue;
|
||||||
int injectedparticles;
|
int numInjectedParticles;
|
||||||
vector<particle>::iterator teilcheniterator;
|
vector<Particle>::iterator particleQueueIt;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user