updated version
This commit is contained in:
@@ -18,18 +18,20 @@
|
||||
#include "parameter.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>)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
TinyVector<double,3> electricfield(TinyVector<double,3>)
|
||||
TinyVector<double,3> Katrin::elField(TinyVector<double,3>)
|
||||
{
|
||||
return(0,0,0);
|
||||
}
|
||||
|
||||
double Katrin::tritiumDensity(TinyVector<double,3>)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -19,15 +19,15 @@
|
||||
#include "particle.h"
|
||||
#include "parameter.h"
|
||||
|
||||
class katrin: public Parameter
|
||||
class Katrin: public Parameter
|
||||
{
|
||||
public:
|
||||
katrin(){};
|
||||
virtual ~katrin(){};
|
||||
Katrin(){};
|
||||
virtual ~Katrin(){};
|
||||
|
||||
TinyVector<double,3> magneticfield(TinyVector<double,3>);
|
||||
TinyVector<double,3> electricfield(TinyVector<double,3>);
|
||||
double tritiumdichte(TinyVector<double,3>);
|
||||
TinyVector<double,3> magField(TinyVector<double,3>);
|
||||
TinyVector<double,3> elField(TinyVector<double,3>);
|
||||
double tritiumDensity(TinyVector<double,3>);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
//
|
||||
// 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 <math.h>
|
||||
@@ -23,13 +28,9 @@
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
//Simulation SIM;
|
||||
//SIM.init();
|
||||
Uniform<double> x;
|
||||
x.seed(141244);
|
||||
cout<<x.random()<<endl;
|
||||
|
||||
|
||||
Simulation SIM;
|
||||
SIM.init();
|
||||
SIM.inject();
|
||||
/*
|
||||
cout <<"___"<<endl;
|
||||
TinyVector<float,2> A;
|
||||
|
||||
+32
-39
@@ -22,45 +22,24 @@ public:
|
||||
|
||||
Parameter()
|
||||
{
|
||||
configFilePath = "parameters.cat";
|
||||
seed = (int)getVariable("seed");
|
||||
totalParticles = (long int)getVariable("totalParticles");
|
||||
dt = getVariable("dt");
|
||||
magFieldSetValue = getVariable("magFieldSetValue");
|
||||
seed = (int)value("seed");
|
||||
numTotalParticles = (long int)value("numTotalParticles");
|
||||
dt = value("dt");
|
||||
injectionMethod = (int)value("injectionMethod");
|
||||
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 temp;
|
||||
@@ -107,14 +86,28 @@ public:
|
||||
exit(1);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
protected:
|
||||
string configFilePath;
|
||||
|
||||
//Simulation specs
|
||||
int seed;
|
||||
long int totalParticles;
|
||||
long int numTotalParticles;
|
||||
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
|
||||
totalParticles 1000
|
||||
dt 5
|
||||
magFieldSetValue 2.5
|
||||
seed = 2342395328
|
||||
numTotalParticles = 1000
|
||||
dt = 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 "blitz/array.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.
|
||||
//
|
||||
// Notes: Energy being calculated using speed and mass
|
||||
|
||||
#ifndef particle_h
|
||||
#define particle_h
|
||||
@@ -20,29 +21,28 @@ typedef enum species{electron, positron, proton, tritium, tritium2, helium, deut
|
||||
|
||||
using namespace blitz;
|
||||
|
||||
class particle
|
||||
class Particle
|
||||
{
|
||||
private:
|
||||
double m,q,E;
|
||||
double m,q;
|
||||
TinyVector<double,3> x,v;
|
||||
species s;
|
||||
long int id;
|
||||
public:
|
||||
|
||||
virtual ~particle() { }
|
||||
particle(){}
|
||||
particle(double mass, double charge, double energy,TinyVector<double,3> loc, TinyVector<double,3> speed, double idnum, species spec)
|
||||
virtual ~Particle() { }
|
||||
Particle(){}
|
||||
Particle(double mass, double charge,TinyVector<double,3> loc, TinyVector<double,3> speed, double idnum, species spec)
|
||||
{
|
||||
m = mass;
|
||||
q = charge;
|
||||
E = energy;
|
||||
x = loc;
|
||||
v = speed;
|
||||
id = idnum;
|
||||
s = spec;
|
||||
}
|
||||
|
||||
//particle(Array<double, 1> props); //Create from Array
|
||||
//Particle(Array<double, 1> props); //Create from Array
|
||||
|
||||
double mass() { return(m); }
|
||||
double charge() { return(q); }
|
||||
@@ -55,8 +55,7 @@ public:
|
||||
TinyVector<double, 3> locSet(TinyVector<double, 3> xneu) { return x = xneu; };
|
||||
TinyVector<double, 3> speedSet(TinyVector<double, 3> vneu);
|
||||
|
||||
|
||||
|
||||
friend ostream& operator<<(ostream& os, const Particle& partOut);
|
||||
|
||||
/*
|
||||
void copyol(particle*);
|
||||
@@ -67,6 +66,9 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
class particle_info : public particle {
|
||||
|
||||
|
||||
@@ -20,27 +20,26 @@
|
||||
|
||||
void Simulation::init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Simulation::doit()
|
||||
{
|
||||
double totalcross, mfp;
|
||||
TinyVector <double,3> alterort, neuerort;
|
||||
while (injectedparticles < totalParticles)
|
||||
double sigmaTot, MFP;
|
||||
TinyVector <double,3> oldLoc, newLoc;
|
||||
while (numInjectedParticles < numTotalParticles)
|
||||
{
|
||||
if (teilchenliste.size() == 0 )
|
||||
if (particleQueue.size() == 0 )
|
||||
{
|
||||
inject();
|
||||
}
|
||||
for(teilcheniterator = teilchenliste.begin();
|
||||
teilcheniterator != teilchenliste.end();
|
||||
teilcheniterator++)
|
||||
for(particleQueueIt = particleQueue.begin();
|
||||
particleQueueIt != particleQueue.end();
|
||||
particleQueueIt++)
|
||||
{
|
||||
totalcross = calctotalcross(*teilcheniterator);
|
||||
mfp = 1/totalcross/KAT.tritiumdichte(teilcheniterator->ort());
|
||||
alterort = teilcheniterator->ort();
|
||||
move (*teilcheniterator, mfp);
|
||||
sigmaTot = calctotalcross(*particleQueueIt);
|
||||
MFP = 1/sigmaTot/KAT.tritiumDensity(particleQueueIt->loc());
|
||||
oldLoc = particleQueueIt->loc();
|
||||
move (*particleQueueIt, MFP);
|
||||
|
||||
//selectprocess(*teilcheniterator);
|
||||
//if (alterort(2) > 0.5)
|
||||
@@ -52,21 +51,55 @@ void Simulation::doit()
|
||||
|
||||
void Simulation::inject()
|
||||
{
|
||||
TinyVector<double,3> ort, geschwindigkeit;
|
||||
ort = 0,0,0;
|
||||
geschwindigkeit = 1,0,0;
|
||||
particle egon(9.109383e-28,1,ort, geschwindigkeit,injectedparticles,electron);
|
||||
injectedparticles++;
|
||||
TinyVector<double,3> loc, speed;
|
||||
double r,phi,z;
|
||||
TinyVector<double,3> speedDir;
|
||||
double Ekin,absSpeed;
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
|
||||
double calctotalcross(particle inputparticle)
|
||||
double calctotalcross(Particle inputparticle)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -32,32 +32,32 @@ public:
|
||||
~Simulation(){};
|
||||
Simulation()
|
||||
{
|
||||
injectedparticles = 0;
|
||||
numInjectedParticles = 0;
|
||||
rngUni.seed(seed);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
void init(void);
|
||||
|
||||
void doit(void);
|
||||
void inject();
|
||||
void move(particle inputparticle, double mfp);
|
||||
void move(Particle inputparticle, double mfp);
|
||||
void output(void);
|
||||
|
||||
|
||||
double calctotalcross(particle inputparticle){return 0;};
|
||||
double calctotalcross(Particle inputparticle){return 0;};
|
||||
|
||||
protected:
|
||||
katrin KAT;
|
||||
Katrin KAT;
|
||||
Uniform<double> rngUni;
|
||||
|
||||
|
||||
double zeit;
|
||||
int zeitschritt;
|
||||
double t;
|
||||
double id;
|
||||
|
||||
vector<particle> teilchenliste;
|
||||
int injectedparticles;
|
||||
vector<particle>::iterator teilcheniterator;
|
||||
vector<Particle> particleQueue;
|
||||
int numInjectedParticles;
|
||||
vector<Particle>::iterator particleQueueIt;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user