Changes in general code and added class energyhisto for
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user