From b3b914f0b4b49b6472f6dac61bbc602141e1abd3 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 20 Sep 2018 18:43:32 +0200 Subject: [PATCH] Changes in general code and added class energyhisto for --- docs/masters/creiling/LateX/thesis.bib | 48 +++++++ src/mc_electron/energyhisto.cpp | 41 ++++++ src/mc_electron/energyhisto.h | 59 +++++++++ src/mc_electron/katrin.cpp | 28 ++-- src/mc_electron/katrin.h | 12 +- src/mc_electron/main.cpp | 38 ++---- src/mc_electron/parameter.h | 71 +++++----- src/mc_electron/parameters.cat | 13 +- src/mc_electron/particle.cpp | 51 +++++-- src/mc_electron/particle.h | 176 ++++++++++++++----------- src/mc_electron/simulation.cpp | 146 +++++++++++++------- src/mc_electron/simulation.h | 35 ++--- 12 files changed, 473 insertions(+), 245 deletions(-) create mode 100644 docs/masters/creiling/LateX/thesis.bib create mode 100644 src/mc_electron/energyhisto.cpp create mode 100644 src/mc_electron/energyhisto.h diff --git a/docs/masters/creiling/LateX/thesis.bib b/docs/masters/creiling/LateX/thesis.bib new file mode 100644 index 0000000..74ced08 --- /dev/null +++ b/docs/masters/creiling/LateX/thesis.bib @@ -0,0 +1,48 @@ +%% This BibTeX bibliography file was created using BibDesk. +%% http://bibdesk.sourceforge.net/ + + +%% Created for Christian Reiling at 2018-09-18 10:29:48 +0200 + + +%% Saved with string encoding Unicode (UTF-8) + + + +@inbook{Plante_MCSIRT, + Author = {Plante, Ianik and Cucinotta, Francis}, + Booktitle = {Application of Monte Carlo Methods in Biology, Medicine and Other Fields of Science}, + Chapter = {18}, + Date-Added = {2018-09-18 08:23:27 +0000}, + Date-Modified = {2018-09-18 08:25:43 +0000}, + Isbn = {978-953-307-427-6}, + Month = {07}, + Pages = {315-356}, + Title = {Monte-Carlo Simulation of Ionizing Radiation Tracks}, + Year = {2011}} + +@techreport{KATRIN_design, + Author = {{KATRIN Collaboration} and {KATRIN Collaboration}}, + Date-Added = {2018-09-18 08:18:39 +0000}, + Date-Modified = {2018-09-18 08:24:07 +0000}, + Institution = {{Forschungszentrum, Karlsruhe}}, + Issn = {0947-8620}, + Language = {english}, + Note = {51.54.01; LK 01; Auch: NPI ASCR Rez EXP-01/2005; MS-KP-0501}, + Pagetotal = {245}, + Series = {Wissenschaftliche Berichte. FZKA}, + Title = {KATRIN design report 2004}, + Volume = {7090}, + Year = {2005}} + +@book{Alireza_MCMPT, + Address = {Boca Raton}, + Author = {Haghighat, Alireza [VerfasserIn]}, + Bestand = {Karlsruher Institut f{\"u}r Technologie (KIT) - KIT-Bibliothek <90> [Signatur: 2017 A 7474]; Hochschule Mannheim, Hochschulbibliothek <953> [Signatur: C I 1601]; Oberwolfach, Mathematisches Forschungsinstitut Oberwolfach [Signatur: M/Haghighat, A];}, + Date-Added = {2018-09-18 08:14:54 +0000}, + Date-Modified = {2018-09-18 08:29:48 +0000}, + Isbn = {978-1-4665-9253-7}, + Publisher = {CRC Press Taylor & Francis Group}, + Size = {xviii, 273 Seiten : Illustrationen}, + Title = {Monte Carlo methods for particle transport}, + Year = {[2015]}} diff --git a/src/mc_electron/energyhisto.cpp b/src/mc_electron/energyhisto.cpp new file mode 100644 index 0000000..b7830f0 --- /dev/null +++ b/src/mc_electron/energyhisto.cpp @@ -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 = "< maxEBin) { + return(numberEBins + 1); + } else { + return(floor((E-minEBin)/EBinWidth)); + } +} + + + + + diff --git a/src/mc_electron/energyhisto.h b/src/mc_electron/energyhisto.h new file mode 100644 index 0000000..7ac0c69 --- /dev/null +++ b/src/mc_electron/energyhisto.h @@ -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 +#include +#include +#include +#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 ZBinBoarders, EBinBoarders; + + blitz::Array data; +}; + +#endif diff --git a/src/mc_electron/katrin.cpp b/src/mc_electron/katrin.cpp index a3a573c..2b4be57 100644 --- a/src/mc_electron/katrin.cpp +++ b/src/mc_electron/katrin.cpp @@ -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 -#include -#include -#include -#include -#include "blitz/array.h" -#include "blitz/tinyvec2.h" -#include -#include "particle.h" -#include "parameter.h" #include "katrin.h" -TinyVector Katrin::magField(TinyVector position) -{ - TinyVector tmp(0.,0.,wgtsMagField); +blitz::TinyVector Katrin::magField(blitz::TinyVector position) { + blitz::TinyVector tmp(0.,0.,wgtsMagField); return (tmp); } -TinyVector Katrin::elField(TinyVector position) -{ - TinyVector tmp(0.,0.,0.); +blitz::TinyVector Katrin::elField(blitz::TinyVector position) { + blitz::TinyVector tmp(0.,0.,0.); return (tmp); } -double Katrin::tritiumDensity(TinyVector position) -{ +double Katrin::tritiumDensity(blitz::TinyVector position) { return(0); } diff --git a/src/mc_electron/katrin.h b/src/mc_electron/katrin.h index b107664..8cb8bfa 100644 --- a/src/mc_electron/katrin.h +++ b/src/mc_electron/katrin.h @@ -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 magField(TinyVector); - TinyVector elField(TinyVector); - double tritiumDensity(TinyVector); + blitz::TinyVector magField(blitz::TinyVector); + blitz::TinyVector elField(blitz::TinyVector); + double tritiumDensity(blitz::TinyVector); }; diff --git a/src/mc_electron/main.cpp b/src/mc_electron/main.cpp index 024ddfa..f412b19 100644 --- a/src/mc_electron/main.cpp +++ b/src/mc_electron/main.cpp @@ -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 -#include -#include -#include -#include -#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 <<"___"< A; - A = 1,0; - cout << TinyVector(1,0)< #include -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 " < -#include -#include -#include -#include -#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<<","< #include @@ -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 x,v; + blitz::TinyVector x,v; species s; long int id; public: virtual ~Particle() { } Particle(){} - Particle(double mass, double charge,TinyVector loc, TinyVector speed, double idnum, species spec) - { + Particle(double mass, double charge,blitz::TinyVector loc, blitz::TinyVector speed, double idnum, species spec) { m = mass; q = charge; x = loc; @@ -41,27 +40,53 @@ public: id = idnum; s = spec; } - + //Particle(Array props); //Create from Array - double mass() { return(m); } - double charge() { return(q); } - TinyVector loc() { return(x); } - TinyVector speed() { return(v); } - double number() { return(id);} + double mass() { + return(m); + } - TinyVector locChange(TinyVector dx, int i, TinyVector xmin, TinyVector nx, TinyVector dvdt); - TinyVector speedChange(TinyVector dv, int i); - TinyVector locSet(TinyVector xneu) { return x = xneu; }; - TinyVector speedSet(TinyVector vneu); + double charge() { + return(q); + } - friend ostream& operator<<(ostream& os, const Particle& partOut); + blitz::TinyVector loc() { + return(x); + } + + blitz::TinyVector 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 locChange(blitz::TinyVector dx, int i, blitz::TinyVector xmin, blitz::TinyVector nx, blitz::TinyVector dvdt); + blitz::TinyVector speedChange(blitz::TinyVector dv, int i); + void setLoc(blitz::TinyVector xnew) {x = xnew; }; + void setSpeed(blitz::TinyVector vnew) {v = vnew; }; + + friend std::ostream& operator<<(std::ostream& os, const Particle& partOut); /* - void copyol(particle*); - Array prop(Array); - virtual Array array(); // ********************** warum virtual???? ****************************** - //void copyol(particle); + void copyol(particle*); + Array prop(Array); + virtual Array array(); // ********************** warum virtual???? ****************************** + //void copyol(particle); */ }; @@ -70,55 +95,56 @@ public: /* -class particle_info : public particle { + class particle_info : public particle { + + private: + TinyVector x0,p0; + double id; + double mue0; + + public: + particle_info(TinyVector anfangsort, TinyVector anfangsimpuls, double nummer, double anfangswinkel ):particle() + { + x0 = anfangsort; + p0 = anfangsimpuls; + mue0 = anfangswinkel; + id = nummer; + } + + particle_info() { } + ~particle_info() { } + + + TinyVector anfangsort() { return(x0); } + TinyVector anfangsimpuls() { return(p0); } + double nummer() { return(id); } + double anfangswinkel() { return(mue0); } + // virtual void copyol(particle_info*); + + Array array () // *********************** auslagern in .cpp ************************** + { + Array teilchenprop; + TinyVector 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 x0,p0; - double id; - double mue0; - -public: - particle_info(TinyVector anfangsort, TinyVector anfangsimpuls, double nummer, double anfangswinkel ):particle() - { - x0 = anfangsort; - p0 = anfangsimpuls; - mue0 = anfangswinkel; - id = nummer; - } - - particle_info() { } - ~particle_info() { } - - - TinyVector anfangsort() { return(x0); } - TinyVector anfangsimpuls() { return(p0); } - double nummer() { return(id); } - double anfangswinkel() { return(mue0); } - // virtual void copyol(particle_info*); - - Array array () // *********************** auslagern in .cpp ************************** - { - Array teilchenprop; - TinyVector 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 diff --git a/src/mc_electron/simulation.cpp b/src/mc_electron/simulation.cpp index 6cbb4e4..dbd8a2b 100644 --- a/src/mc_electron/simulation.cpp +++ b/src/mc_electron/simulation.cpp @@ -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 -#include -#include -#include -#include -#include "blitz/array.h" -#include "blitz/tinyvec2.h" - -#include -#include "particle.h" -#include "parameter.h" #include "simulation.h" -void Simulation::init() -{ +void Simulation::init() { + } -void Simulation::doit() -{ - double sigmaTot, MFP; - TinyVector 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 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: " < loc, speed; +void Simulation::inject() { + blitz::TinyVector loc, speed; double r,phi,z; - TinyVector speedDir; + blitz::TinyVector 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.size()-1) { + std::cerr<<"queueNum outside of size"< 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"< loc = particleQueue[queueNum].loc(); + double r = particleQueue[queueNum].radius(); + return (!(loc[2]>0 && loc[2] 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); } diff --git a/src/mc_electron/simulation.h b/src/mc_electron/simulation.h index f878a2d..ae12c11 100644 --- a/src/mc_electron/simulation.h +++ b/src/mc_electron/simulation.h @@ -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 -#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 oldLoc, int queueNum=0); + + + double calcMFP(); + protected: Katrin KAT; - Uniform rngUni; + ranlib::Uniform rngUni; double t; double id; - vector particleQueue; + std::vector particleQueue; int numInjectedParticles; - vector::iterator particleQueueIt; + std::vector::iterator particleQueueIt; }; #endif