Changes in general code and added class energyhisto for
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// energyhisto.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 20.09.18.
|
||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#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);
|
||||
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";
|
||||
exit(1);
|
||||
}
|
||||
return(floor(z/ZBinWidth));
|
||||
}
|
||||
|
||||
|
||||
int Energyhisto::getEBin(double E) {
|
||||
if (E<minEBin) {
|
||||
return (0);
|
||||
} else if (E > maxEBin) {
|
||||
return(numberEBins + 1);
|
||||
} else {
|
||||
return(floor((E-minEBin)/EBinWidth));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// energyhisto.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 20.09.18.
|
||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef energyhisto_h
|
||||
#define energyhisto_h
|
||||
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "blitz/array.h"
|
||||
#include "blitz/tinyvec2.h"
|
||||
|
||||
#include "parameter.h"
|
||||
|
||||
|
||||
class Energyhisto: public Parameter
|
||||
{
|
||||
public:
|
||||
virtual ~Energyhisto(){};
|
||||
Energyhisto(){
|
||||
data.resize(numberZBins,numberEBins+2); // Under and Overflow Bins
|
||||
data = 0;
|
||||
|
||||
ZBinWidth = wgtsLength/numberZBins;
|
||||
EBinWidth = (maxEBin-minEBin)/numberEBins;
|
||||
|
||||
ZBinBoarders.resize(numberZBins+1);
|
||||
for (int i=0;i<numberZBins+1;i++) {
|
||||
ZBinBoarders[i] = ZBinWidth*i; //More fancy with blitz functions?
|
||||
}
|
||||
|
||||
EBinBoarders.resize(numberEBins+3);
|
||||
for (int i=0;i<numberEBins+1;i++) {
|
||||
EBinBoarders[i+1] = minEBin + i*EBinWidth; //More fancy with blitz functions?
|
||||
}
|
||||
};
|
||||
|
||||
int getZBin(double z);
|
||||
|
||||
int getEBin(double E);
|
||||
|
||||
void addContent(double zLow, double zUp, double Energy);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
double ZBinWidth, EBinWidth;
|
||||
blitz::Array <double,1> ZBinBoarders, EBinBoarders;
|
||||
|
||||
blitz::Array<int,2> data;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,37 +1,25 @@
|
||||
//
|
||||
// katrin.cpp
|
||||
//
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.09.18.
|
||||
// Created by Christian Reiling on 20.09.18.
|
||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "blitz/array.h"
|
||||
#include "blitz/tinyvec2.h"
|
||||
|
||||
#include <math.h>
|
||||
#include "particle.h"
|
||||
#include "parameter.h"
|
||||
#include "katrin.h"
|
||||
|
||||
TinyVector<double,3> Katrin::magField(TinyVector<double,3> position)
|
||||
{
|
||||
TinyVector<double,3> tmp(0.,0.,wgtsMagField);
|
||||
blitz::TinyVector<double,3> Katrin::magField(blitz::TinyVector<double,3> position) {
|
||||
blitz::TinyVector<double,3> tmp(0.,0.,wgtsMagField);
|
||||
return (tmp);
|
||||
}
|
||||
|
||||
TinyVector<double,3> Katrin::elField(TinyVector<double,3> position)
|
||||
{
|
||||
TinyVector<double, 3> tmp(0.,0.,0.);
|
||||
blitz::TinyVector<double,3> Katrin::elField(blitz::TinyVector<double,3> position) {
|
||||
blitz::TinyVector<double, 3> tmp(0.,0.,0.);
|
||||
return (tmp);
|
||||
}
|
||||
|
||||
double Katrin::tritiumDensity(TinyVector<double,3> position)
|
||||
{
|
||||
double Katrin::tritiumDensity(blitz::TinyVector<double,3> position) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
//
|
||||
// katrin.h
|
||||
//
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.09.18.
|
||||
// Created by Christian Reiling on 20.09.18.
|
||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef katrin_h
|
||||
@@ -16,7 +17,6 @@
|
||||
#include "blitz/array.h"
|
||||
#include "blitz/tinyvec2.h"
|
||||
|
||||
#include "particle.h"
|
||||
#include "parameter.h"
|
||||
|
||||
class Katrin: public Parameter
|
||||
@@ -25,9 +25,9 @@ public:
|
||||
Katrin(){};
|
||||
virtual ~Katrin(){};
|
||||
|
||||
TinyVector<double,3> magField(TinyVector<double,3>);
|
||||
TinyVector<double,3> elField(TinyVector<double,3>);
|
||||
double tritiumDensity(TinyVector<double,3>);
|
||||
blitz::TinyVector<double,3> magField(blitz::TinyVector<double,3>);
|
||||
blitz::TinyVector<double,3> elField(blitz::TinyVector<double,3>);
|
||||
double tritiumDensity(blitz::TinyVector<double,3>);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,41 +1,21 @@
|
||||
//
|
||||
// main.cpp
|
||||
//
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.09.18.
|
||||
// Created by Christian Reiling on 20.09.18.
|
||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||
//
|
||||
//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>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "blitz/array.h"
|
||||
#include "blitz/tinyvec2.h"
|
||||
|
||||
|
||||
#include "parameter.h"
|
||||
#include "simulation.h"
|
||||
#include "particle.h"
|
||||
#include "katrin.h"
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, const char * argv[]) {
|
||||
char poub[]="poub=/Users/ChristianReiling/Documents/Masterarbeit/katrin-plasma/src/mc_electron";
|
||||
char pname[]="pname=parameters";
|
||||
putenv(poub);
|
||||
putenv(pname);
|
||||
|
||||
Simulation SIM;
|
||||
SIM.init();
|
||||
SIM.inject();
|
||||
/*
|
||||
cout <<"___"<<endl;
|
||||
TinyVector<float,2> A;
|
||||
A = 1,0;
|
||||
cout << TinyVector<float,2>(1,0)<<endl;
|
||||
cout<<"___"<<endl;
|
||||
*/
|
||||
SIM.doit();
|
||||
}
|
||||
|
||||
+39
-32
@@ -1,8 +1,9 @@
|
||||
//
|
||||
// parameter.h
|
||||
//
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.09.18.
|
||||
// Created by Christian Reiling on 20.09.18.
|
||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef parameter_h
|
||||
@@ -11,23 +12,24 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
using namespace blitz;
|
||||
|
||||
class Parameter
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
virtual ~Parameter(){};
|
||||
|
||||
Parameter()
|
||||
{
|
||||
Parameter() {
|
||||
seed = (int)value("seed");
|
||||
numTotalParticles = (long int)value("numTotalParticles");
|
||||
dt = value("dt");
|
||||
numTotalParticles = (long int)value("numTotalParticles");
|
||||
dt = value("dt");
|
||||
injectionMethod = (int)value("injectionMethod");
|
||||
deltaKinEnergy = value("deltaKinEnergy");
|
||||
MBKinEnergy = value("MBKinEnergy");
|
||||
numberZBins = (int)value ("numberZBins");
|
||||
minEBin = value ("minEBin");
|
||||
maxEBin = value ("maxEBin");
|
||||
numberEBins = (int)value ("numberEBins");
|
||||
|
||||
wgtsMagField = value("wgtsMagField");
|
||||
wgtsLength = value("wgtsLength");
|
||||
@@ -40,66 +42,70 @@ public:
|
||||
constqe = value("constqe");
|
||||
}
|
||||
|
||||
double value(char *str, char* ext = "cat") // Reads Parameter from config file
|
||||
{
|
||||
double value(std::string strin, char* ext = (char*)("cat")) {
|
||||
char* str = strdup(strin.c_str());
|
||||
double temp;
|
||||
char dummy[256];
|
||||
char fname[256],*pname;
|
||||
char dummy[256];
|
||||
char fname[256],*pname;
|
||||
FILE *fcat;
|
||||
|
||||
if (getenv("poub") == NULL)
|
||||
{
|
||||
fprintf(stderr,"Environment variable %s not defined.\n","poub");
|
||||
std::cerr<<"Parameter::value: Environment variable poub not defined.\n";
|
||||
exit(1);
|
||||
}
|
||||
strcpy(fname, getenv("poub"));
|
||||
strcpy(fname, getenv("poub"));
|
||||
pname = getenv("pname");
|
||||
if (pname == NULL)
|
||||
{
|
||||
fprintf(stderr,"Environment variable %s not defined.\n","pname");
|
||||
std::cerr<<"Parameter::value: Environment variable pname not defined.\n";
|
||||
exit(1);
|
||||
}
|
||||
if (!ext)
|
||||
{
|
||||
ext = "cat";
|
||||
ext = (char*)("cat");
|
||||
}
|
||||
sprintf(fname,"%s/%s.%s",getenv("poub"),getenv("pname"), ext);
|
||||
if (!(fcat = fopen(fname, "r")))
|
||||
{
|
||||
fprintf(stderr,"value: cannot open file %s\n",fname);
|
||||
sprintf(fname,"%s/%s.%s",getenv("poub"),getenv("pname"), ext);
|
||||
if (!(fcat = fopen(fname, "r")))
|
||||
{
|
||||
std::cerr<<"Parameter::value: Can not open file " <<fname<<".\n";
|
||||
exit(1);
|
||||
}
|
||||
while (!feof(fcat))
|
||||
{
|
||||
}
|
||||
while (!feof(fcat))
|
||||
{
|
||||
// fscanf(fcat, "'%s%*[^']'%F%*[^']",dummy,&temp); 1
|
||||
fscanf(fcat, "%s = %lf", dummy, &temp);
|
||||
// if (strncmp(dummy, str,strlen(str)) == 0) {
|
||||
if (strcmp(dummy, str) == 0)
|
||||
{
|
||||
fclose(fcat);
|
||||
return(temp);
|
||||
fclose(fcat);
|
||||
return(temp);
|
||||
}
|
||||
}
|
||||
fclose(fcat);
|
||||
fprintf(stderr,"variable %s not found\n",str);
|
||||
|
||||
exit(1);
|
||||
return 0;
|
||||
std::cerr<<"Parameter::value: Variable "<<str<<" not found.\n";
|
||||
exit(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
string configFilePath;
|
||||
std::string configFilePath;
|
||||
|
||||
//Simulation specs
|
||||
int seed;
|
||||
long int numTotalParticles;
|
||||
double dt;
|
||||
double dt;
|
||||
int injectionMethod;
|
||||
double deltaKinEnergy;
|
||||
double MBKinEnergy;
|
||||
int numberZBins;
|
||||
double minEBin;
|
||||
double maxEBin;
|
||||
int numberEBins;
|
||||
|
||||
//KATRIN Specs
|
||||
double wgtsMagField;
|
||||
double wgtsMagField;
|
||||
double wgtsLength;
|
||||
double wgtsDiameter;
|
||||
|
||||
@@ -111,4 +117,5 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
seed = 2342395328
|
||||
numTotalParticles = 1000
|
||||
dt = 5
|
||||
numTotalParticles = 10
|
||||
dt = 0.00001
|
||||
injectionMethod = 2
|
||||
deltaKinEnergy = 10
|
||||
MBKinEnergy = 10
|
||||
MBKinEnergy = 4.14e-22 J
|
||||
|
||||
numberZBins = 10
|
||||
minEBin = 0
|
||||
maxEBin = 10
|
||||
numberEBins = 10
|
||||
|
||||
|
||||
wgtsMagField = 2.5
|
||||
wgtsLength = 100
|
||||
wgtsLength = 10
|
||||
wgtsDiameter = 10
|
||||
|
||||
|
||||
|
||||
@@ -1,22 +1,51 @@
|
||||
//
|
||||
// particle.cpp
|
||||
//
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.09.18.
|
||||
// Created by Christian Reiling on 20.09.18.
|
||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "blitz/array.h"
|
||||
#include "blitz/tinyvec2.h"
|
||||
|
||||
#include "particle.h"
|
||||
|
||||
ostream& operator<<(ostream& os, const Particle& partOut)
|
||||
{
|
||||
std::ostream& operator<<(std::ostream& os, const species& SpecOut) {
|
||||
switch (SpecOut) {
|
||||
case electron:
|
||||
os<<"e-";
|
||||
break;
|
||||
case positron:
|
||||
os<<"e+";
|
||||
break;
|
||||
case proton:
|
||||
os<<"p";
|
||||
break;
|
||||
case tritium:
|
||||
os<<"T3";
|
||||
break;
|
||||
case tritium2:
|
||||
os<<"T_2";
|
||||
break;
|
||||
case helium:
|
||||
os<<"He3";
|
||||
break;
|
||||
case deuterium:
|
||||
os<<"D2";
|
||||
break;
|
||||
case DT:
|
||||
os<<"DT";
|
||||
break;
|
||||
default:
|
||||
std::cerr<<"unknown species";
|
||||
exit(1);
|
||||
}
|
||||
return (os);
|
||||
}
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Particle& partOut) {
|
||||
os << "(" << partOut.id<<","<<partOut.s<<","<<partOut.m << "," << partOut.q << ","<< partOut.x<<","<< partOut.v <<")";
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+101
-75
@@ -1,13 +1,13 @@
|
||||
//
|
||||
// particle.h
|
||||
//
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.09.18.
|
||||
// Created by Christian Reiling on 20.09.18.
|
||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||
//
|
||||
// Notes: Energy being calculated using speed and mass
|
||||
|
||||
#ifndef particle_h
|
||||
#define particle_h
|
||||
#ifndef particle_hpp
|
||||
#define particle_hpp
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
@@ -17,23 +17,22 @@
|
||||
#include "blitz/array.h"
|
||||
#include "blitz/tinyvec2.h"
|
||||
|
||||
typedef enum species{electron, positron, proton, tritium, tritium2, helium, deuterium, dt}species;
|
||||
typedef enum species{electron, positron, proton, tritium, tritium2, helium, deuterium, DT}species;
|
||||
std::ostream& operator<<(std::ostream& os, const species& SpecOut);
|
||||
|
||||
using namespace blitz;
|
||||
|
||||
class Particle
|
||||
{
|
||||
private:
|
||||
double m,q;
|
||||
TinyVector<double,3> x,v;
|
||||
blitz::TinyVector<double,3> x,v;
|
||||
species s;
|
||||
long int id;
|
||||
public:
|
||||
|
||||
virtual ~Particle() { }
|
||||
Particle(){}
|
||||
Particle(double mass, double charge,TinyVector<double,3> loc, TinyVector<double,3> speed, double idnum, species spec)
|
||||
{
|
||||
Particle(double mass, double charge,blitz::TinyVector<double,3> loc, blitz::TinyVector<double,3> speed, double idnum, species spec) {
|
||||
m = mass;
|
||||
q = charge;
|
||||
x = loc;
|
||||
@@ -41,27 +40,53 @@ public:
|
||||
id = idnum;
|
||||
s = spec;
|
||||
}
|
||||
|
||||
|
||||
//Particle(Array<double, 1> props); //Create from Array
|
||||
|
||||
double mass() { return(m); }
|
||||
double charge() { return(q); }
|
||||
TinyVector<double,3> loc() { return(x); }
|
||||
TinyVector<double,3> speed() { return(v); }
|
||||
double number() { return(id);}
|
||||
double mass() {
|
||||
return(m);
|
||||
}
|
||||
|
||||
TinyVector<double,3> locChange(TinyVector<double, 3> dx, int i, TinyVector<double, 3> xmin, TinyVector<double, 3> nx, TinyVector<double, 3> dvdt);
|
||||
TinyVector<double,3> speedChange(TinyVector<double, 3> dv, int i);
|
||||
TinyVector<double, 3> locSet(TinyVector<double, 3> xneu) { return x = xneu; };
|
||||
TinyVector<double, 3> speedSet(TinyVector<double, 3> vneu);
|
||||
double charge() {
|
||||
return(q);
|
||||
}
|
||||
|
||||
friend ostream& operator<<(ostream& os, const Particle& partOut);
|
||||
blitz::TinyVector<double,3> loc() {
|
||||
return(x);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> speed() {
|
||||
return(v);
|
||||
}
|
||||
|
||||
double number() {
|
||||
return(id);
|
||||
}
|
||||
|
||||
double radius() {
|
||||
return (sqrt( pow(x[0],2) + pow(x[1],2) ));
|
||||
}
|
||||
|
||||
double speedAbs() {
|
||||
return (sqrt( pow(v[0],2) + pow(v[1],2) + pow(v[2],2)));
|
||||
}
|
||||
|
||||
double energy(); // muss noch implementiert werden
|
||||
|
||||
|
||||
|
||||
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 setLoc(blitz::TinyVector<double, 3> xnew) {x = xnew; };
|
||||
void setSpeed(blitz::TinyVector<double, 3> vnew) {v = vnew; };
|
||||
|
||||
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);
|
||||
void copyol(particle*);
|
||||
Array<double,1> prop(Array<double,1>);
|
||||
virtual Array<double,1> array(); // ********************** warum virtual???? ******************************
|
||||
//void copyol(particle);
|
||||
*/
|
||||
};
|
||||
|
||||
@@ -70,55 +95,56 @@ public:
|
||||
|
||||
|
||||
/*
|
||||
class particle_info : public 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);
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
*/
|
||||
#endif
|
||||
|
||||
@@ -1,61 +1,78 @@
|
||||
//
|
||||
// simulation.cpp
|
||||
// mc_electron
|
||||
//
|
||||
//
|
||||
// Created by Christian Reiling on 13.09.18.
|
||||
// Created by Christian Reiling on 20.09.18.
|
||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "blitz/array.h"
|
||||
#include "blitz/tinyvec2.h"
|
||||
|
||||
#include <math.h>
|
||||
#include "particle.h"
|
||||
#include "parameter.h"
|
||||
#include "simulation.h"
|
||||
|
||||
void Simulation::init()
|
||||
{
|
||||
void Simulation::init() {
|
||||
|
||||
}
|
||||
|
||||
void Simulation::doit()
|
||||
{
|
||||
double sigmaTot, MFP;
|
||||
TinyVector <double,3> oldLoc, newLoc;
|
||||
while (numInjectedParticles < numTotalParticles)
|
||||
{
|
||||
if (particleQueue.size() == 0 )
|
||||
{
|
||||
inject();
|
||||
}
|
||||
for(particleQueueIt = particleQueue.begin();
|
||||
particleQueueIt != particleQueue.end();
|
||||
particleQueueIt++)
|
||||
{
|
||||
sigmaTot = calctotalcross(*particleQueueIt);
|
||||
MFP = 1/sigmaTot/KAT.tritiumDensity(particleQueueIt->loc());
|
||||
oldLoc = particleQueueIt->loc();
|
||||
move (*particleQueueIt, MFP);
|
||||
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
|
||||
|
||||
while (numInjectedParticles < numTotalParticles) {
|
||||
inject();
|
||||
|
||||
while (particleQueue.size()>0) {
|
||||
// Run Code for first particle in Queue
|
||||
|
||||
//selectprocess(*teilcheniterator);
|
||||
//if (alterort(2) > 0.5)
|
||||
MFP = calcMFP();
|
||||
oldLoc = particleQueue[0].loc();
|
||||
|
||||
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].energy());
|
||||
std::cout << "Death position: " <<particleQueue[0]<<std::endl;
|
||||
particleQueue.erase(particleQueue.begin());
|
||||
continue;
|
||||
} else {
|
||||
//newLoc = partQueue[0];
|
||||
//updateDensity(oldLoc,newLoc,partQueue[0].energy());
|
||||
}
|
||||
/*
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void Simulation::inject()
|
||||
{
|
||||
TinyVector<double,3> loc, speed;
|
||||
void Simulation::inject() {
|
||||
blitz::TinyVector<double,3> loc, speed;
|
||||
double r,phi,z;
|
||||
TinyVector<double,3> speedDir;
|
||||
blitz::TinyVector<double,3> speedDir;
|
||||
double Ekin,absSpeed;
|
||||
|
||||
|
||||
r = rngUni.random()*wgtsDiameter;
|
||||
phi = rngUni.random()*2*constPi;
|
||||
z = rngUni.random()*wgtsLength;
|
||||
@@ -66,8 +83,7 @@ void Simulation::inject()
|
||||
speedDir = 1./sqrt(dot(speedDir,speedDir))*speedDir;
|
||||
// Add Code for corregtion of direction by tritium direction!!!
|
||||
|
||||
switch(injectionMethod)
|
||||
{
|
||||
switch(injectionMethod) {
|
||||
case 1: // Fermi
|
||||
Ekin = 1.; //Implement Later
|
||||
break;
|
||||
@@ -79,7 +95,7 @@ void Simulation::inject()
|
||||
Ekin = 1.; //Implement Later
|
||||
break;
|
||||
default:
|
||||
cerr<<"Invalid Injection Method./n";
|
||||
std::cerr<<"Invalid Injection Method./n";
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
@@ -89,18 +105,46 @@ void Simulation::inject()
|
||||
|
||||
|
||||
particleQueue.assign(1,Particle(constme,constqe,loc, speed,numInjectedParticles,electron));
|
||||
cout<<particleQueue[0]<<endl;
|
||||
numInjectedParticles++;
|
||||
}
|
||||
|
||||
void Simulation::move(Particle inParticle, double length)
|
||||
{
|
||||
//Borispush
|
||||
void Simulation::move(double MFP,int queueNum) {
|
||||
if (queueNum > particleQueue.size()-1) {
|
||||
std::cerr<<"queueNum outside of size"<<std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//Pseudocode, lineare bewegung
|
||||
blitz::TinyVector<double,3> SpeedDir;
|
||||
SpeedDir = 1./sqrt(dot(particleQueue[queueNum].speed(),particleQueue[queueNum].speed()))*particleQueue[queueNum].speed();
|
||||
particleQueue[queueNum].setLoc(particleQueue[queueNum].loc() + SpeedDir*MFP);
|
||||
}
|
||||
|
||||
bool Simulation::movedOutside(int queueNum) {
|
||||
if (queueNum > particleQueue.size()-1) {
|
||||
std::cerr<<"queueNum outside of size"<<std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> loc = particleQueue[queueNum].loc();
|
||||
double r = particleQueue[queueNum].radius();
|
||||
return (!(loc[2]>0 && loc[2]<wgtsLength && r<(wgtsDiameter/2) ));
|
||||
}
|
||||
|
||||
void Simulation::moveToLocOfDeath(blitz::TinyVector<double,3> oldLoc, int queueNum) {
|
||||
double stepsize = particleQueue[queueNum].speedAbs()*dt;
|
||||
particleQueue[queueNum].setLoc(oldLoc);
|
||||
while (!movedOutside(queueNum) ) {
|
||||
move (stepsize,queueNum);
|
||||
}
|
||||
if (particleQueue[queueNum].loc()(2)<0) {
|
||||
particleQueue[queueNum].loc()(2) = 0;
|
||||
} else if (particleQueue[queueNum].loc()(2)>wgtsLength) {
|
||||
particleQueue[queueNum].loc()(2) = wgtsLength;
|
||||
}
|
||||
// Runde Position auf Rand
|
||||
}
|
||||
|
||||
double calctotalcross(Particle inputparticle)
|
||||
{
|
||||
return (0);
|
||||
double Simulation::calcMFP() {
|
||||
return(1);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
//
|
||||
// simulation.h
|
||||
//
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.09.18.
|
||||
// Created by Christian Reiling on 20.09.18.
|
||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef simulation_h
|
||||
@@ -17,47 +18,47 @@
|
||||
#include "blitz/tinyvec2.h"
|
||||
#include <random/uniform.h>
|
||||
|
||||
#include "particle.h"
|
||||
#include "parameter.h"
|
||||
#include "katrin.h"
|
||||
|
||||
using namespace blitz;
|
||||
using namespace std;
|
||||
using namespace ranlib;
|
||||
#include "particle.h"
|
||||
#include "energyhisto.h"
|
||||
|
||||
|
||||
class Simulation: public Parameter
|
||||
{
|
||||
public:
|
||||
~Simulation(){};
|
||||
Simulation()
|
||||
{
|
||||
Simulation() {
|
||||
numInjectedParticles = 0;
|
||||
rngUni.seed(seed);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
void init(void);
|
||||
void doit(void);
|
||||
void inject();
|
||||
void move(Particle inputparticle, double mfp);
|
||||
void output(void);
|
||||
|
||||
|
||||
double calctotalcross(Particle inputparticle){return 0;};
|
||||
|
||||
|
||||
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;
|
||||
Uniform<double> rngUni;
|
||||
ranlib::Uniform<double> rngUni;
|
||||
|
||||
double t;
|
||||
double id;
|
||||
|
||||
vector<Particle> particleQueue;
|
||||
std::vector<Particle> particleQueue;
|
||||
int numInjectedParticles;
|
||||
vector<Particle>::iterator particleQueueIt;
|
||||
std::vector<Particle>::iterator particleQueueIt;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user