rec counter/target E, move drift, el. gyro c move

This commit is contained in:
Jonas Kellerer
2021-04-16 10:53:16 +02:00
parent 9928388830
commit d1ca162676
29 changed files with 660 additions and 409 deletions
+34
View File
@@ -0,0 +1,34 @@
#include "T2Ie_recombination.h"
#include "janev_eT2I_recombination.h"
#include "kinematics.h"
#include "recombination_counter.h"
T2Ie_Recombination::T2Ie_Recombination(
Population_Base *ePopulation,
UniRNG *rngUni) :
TI_e_Precomputed_Interaction_Base(
ePopulation, rngUni, 2*mT_eV)
{
calc_values(); // need to call here, because, constructor can't call pure virtual function
}
double T2Ie_Recombination::get_microSigma_m2(
const double &E_eV)
{
// ion at rest
return Janev_eT2I_Recombination::get_TCS(E_eV);
}
InteractionOut T2Ie_Recombination::do_Interaction (
Particle *interPart)
{
InteractionOut res;
res.set_delete_current(true);
double E_eV = calc_E_eV_from_v_ms(
Population->roll_v_ms(interPart->get_x_m()), me_eV); // should be computed properly using chances.
Population->decrease_denisty(interPart->get_x_m(), E_eV);
GlobalCounter::num_T2I_recombinations += 1;
return res;
}
+9 -31
View File
@@ -1,39 +1,17 @@
//
// T2Ie_recombination.h
// mc_electron
//
// Created by Christian Reiling on 30.07.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#ifndef T2Ie_recombination_h
#define T2Ie_recombination_h
#ifndef T2IE_RECOMBINATION_H
#define T2IE_RECOMBINATION_H
#include "TI_kinetic_base.h"
#include "janev_eT2I_recombination.h"
class T2Ie_Recombination : public TI_e_Precomputed_Interaction_Base {
public:
T2Ie_Recombination(Population_Base *ePopulation, UniRNG *rngUni) : TI_e_Precomputed_Interaction_Base(ePopulation, rngUni, 2*mT_eV) {
calc_values(); // need to call here, because, constructor can't call pure virtual function
}
public:
T2Ie_Recombination(
Population_Base *ePopulation,
UniRNG *rngUni);
InteractionOut do_Interaction (Particle *interPart);
protected:
double get_microSigma_m2(const double &E_eV) {
return Janev_eT2I_Recombination::get_TCS(E_eV);
}
protected:
double get_microSigma_m2(const double &E_eV);
};
inline InteractionOut T2Ie_Recombination::do_Interaction (Particle *interPart) {
InteractionOut res;
res.set_delete_current(true);
double E_eV = calc_E_eV_from_v_ms(Population->roll_v_ms(interPart->get_x_m()), me_eV); // should be computed properly using chances.
Population->decrease_denisty(interPart->get_x_m(), E_eV);
return res;
}
#endif /* T2Ie_recombination_h */
#endif /* T2IE_RECOMBINATION_H */
+32
View File
@@ -0,0 +1,32 @@
#include "T3Ie_recombination.h"
#include "janev_eT3I_recombination.h"
#include "kinematics.h"
#include "recombination_counter.h"
T3Ie_Recombination::T3Ie_Recombination(
Population_Base *ePopulation,
UniRNG *rngUni) :
TI_e_Precomputed_Interaction_Base(
ePopulation, rngUni, 3*mT_eV)
{
calc_values(); // need to call here, because, constructor can't call pure virtual function
}
double T3Ie_Recombination::get_microSigma_m2(
const double &E_eV)
{
// ion at rest
return Janev_eT3I_Recombination::get_TCS(E_eV);
}
InteractionOut T3Ie_Recombination::do_Interaction (
Particle *interPart)
{
InteractionOut res;
res.set_delete_current(true);
double E_eV = calc_E_eV_from_v_ms(
Population->roll_v_ms(interPart->get_x_m()), me_eV); // should be computed properly using chances.
Population->decrease_denisty(interPart->get_x_m(), E_eV);
GlobalCounter::num_T3I_recombinations += 1;
return res;
}
+6 -28
View File
@@ -1,39 +1,17 @@
//
// T3Ie_recombination.h
// mc_electron
//
// Created by Christian Reiling on 29.07.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#ifndef T3Ie_recombination_h
#define T3Ie_recombination_h
#include "TI_kinetic_base.h"
#include "janev_eT3I_recombination.h"
class T3Ie_Recombination : public TI_e_Precomputed_Interaction_Base {
public:
T3Ie_Recombination(Population_Base *ePopulation, UniRNG *rngUni) : TI_e_Precomputed_Interaction_Base(ePopulation, rngUni, 3*mT_eV) {
calc_values(); // need to call here, because, constructor can't call pure virtual function
}
public:
T3Ie_Recombination(
Population_Base *ePopulation,
UniRNG *rngUni);
InteractionOut do_Interaction (Particle *interPart);
protected:
double get_microSigma_m2(const double &E_eV) {
return Janev_eT3I_Recombination::get_TCS(E_eV);
}
protected:
double get_microSigma_m2(const double &E_eV);
};
inline InteractionOut T3Ie_Recombination::do_Interaction (Particle *interPart) {
InteractionOut res;
res.set_delete_current(true);
double E_eV = calc_E_eV_from_v_ms(Population->roll_v_ms(interPart->get_x_m()), me_eV); // should be computed properly using chances.
Population->decrease_denisty(interPart->get_x_m(), E_eV);
return res;
}
#endif /* T3Ie_recombination_h */
+117
View File
@@ -0,0 +1,117 @@
#include "TI_kinetic_base.h"
#include "kinematics.h"
TI_e_Interaction_Base::TI_e_Interaction_Base(
Population_Base *Population,
UniRNG *rngUni, double m_eV) :
Interaction_Base(Population, rngUni)
{
m1_eV = Population->get_m_eV();
m2_eV = m_eV;
num_Ee_bins = Population->get_number_E_bins();
if (num_Ee_bins <= 1) {
throw MyException("Population is not kinetic, when expected kinetic.");
}
ve_mids = new double[num_Ee_bins];
Ee_mids = new double[num_Ee_bins];
for (int Ee_bin = 0; Ee_bin<num_Ee_bins; Ee_bin++) {
Ee_mids[Ee_bin] = Population->get_E_bin_mid_eV(Ee_bin);
ve_mids[Ee_bin] = calc_v_ms_from_E_eV(Ee_mids[Ee_bin], m1_eV);
}
}
double TI_e_Interaction_Base::get_macro_sigma_m(
const Particle &interPart)
{
return calc_macro_sigma_m(
interPart.get_E_eV(), interPart.get_x_m());
}
double TI_e_Interaction_Base::calc_macro_sigma_m(
const double &E_eV, const vec3 &loc_m)
{
Bins loc_bins = Population->get_loc_bin(loc_m);
double macro_sigma_m = 0;
for (int Ee_bin = 0; Ee_bin<num_Ee_bins; Ee_bin++) {
macro_sigma_m += calc_microSigma_m2(E_eV, Ee_bin)
* Population->get_density_m3(Ee_bin, loc_bins);
}
return macro_sigma_m;
}
double TI_e_Interaction_Base::calc_microSigma_m2(
const double &E2_eV, const int &Ee_bin)
{
//return get_microSigma_m2(Ee_mids[Ee_bin]); // No Integration... Only e- energy
double v1_ms = ve_mids[Ee_bin]; // electron velocity
double v2_ms = calc_v_ms_from_E_eV(E2_eV, m2_eV); // ion velocity
if (v1_ms > v2_ms*2000 ) { // 2000 represents 1% variation in energy
return get_microSigma_m2(Ee_mids[Ee_bin]);
} else {
auto integrand = [&](double theta) {
const double E_kin_incident =
kineticEnergyIncidentRelativistic(v1_ms, v2_ms, m1_eV, m2_eV, theta);
// frame where ion (m2_eV) is at rest
return get_microSigma_m2(E_kin_incident);
};
return integrate(integrand, pi/8., 7*pi/8., INT_N, simpson())/pi;
}
}
TI_e_Precomputed_Interaction_Base::TI_e_Precomputed_Interaction_Base(
Population_Base *Population,
UniRNG *rngUni,
double m_eV) :
TI_e_Interaction_Base(Population, rngUni, m_eV),
E_scale(INT_PRE_START, INT_PRE_END, INT_PRE_N)
{
precomputed_values = new double *[E_scale.get_number_bins()];
for (int EI_bin=0; EI_bin<E_scale.get_number_bins(); EI_bin++) {
precomputed_values[EI_bin] = new double[num_Ee_bins];
}
}
void TI_e_Precomputed_Interaction_Base::calc_values()
{
for (int EI_bin=0; EI_bin<E_scale.get_number_bins(); EI_bin++) {
for (int Ee_bin = 0; Ee_bin<num_Ee_bins; Ee_bin++) {
precomputed_values[EI_bin][Ee_bin] = calc_microSigma_m2(E_scale.get_bin_mid(EI_bin), Ee_bin);
}
}
}
double TI_e_Precomputed_Interaction_Base::get_macro_sigma_m(
const Particle &interPart)
{
vec3 loc_m = interPart.get_x_m();
double E_eV = interPart.get_E_eV();
if (E_scale.in_scale(E_eV)) {
return lookup_macro_sigma_m(E_eV, loc_m);
} else {
return calc_macro_sigma_m(E_eV, loc_m);
}
}
double TI_e_Precomputed_Interaction_Base::lookup_macro_sigma_m(
const double &E_eV, const vec3 &loc_m)
{
int EI_bin = E_scale.calc_index(E_eV);
double *microSigmas = precomputed_values[EI_bin];
Bins loc_bins = Population->get_loc_bin(loc_m);
double macro_sigma_m = 0;
for (int Ee_bin = 0; Ee_bin<num_Ee_bins; Ee_bin++) {
macro_sigma_m += microSigmas[Ee_bin]
* Population->get_density_m3(Ee_bin, loc_bins);
}
return macro_sigma_m;
}
+25 -106
View File
@@ -1,129 +1,48 @@
//
// TI_kinetic_base.h
// mc_electron
//
// Created by Christian Reiling on 18.11.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#ifndef TI_kinetic_base_h
#define TI_kinetic_base_h
#include "interaction_base.h"
class TI_e_Interaction_Base : public Interaction_Base { // Interactions of ions with kinetic e Populations
protected:
// Interactions of ions with kinetic e Populations
class TI_e_Interaction_Base : public Interaction_Base {
public:
TI_e_Interaction_Base(
Population_Base *Population,
UniRNG *rngUni,
double m_eV);
double get_macro_sigma_m(const Particle &interPart);
protected:
double calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m);
double calc_microSigma_m2(const double &E1_eV, const int &Ee_bin);
double m1_eV; // energy of kinetic particle for CS measurement : e-
double m2_eV; // energy of massic initial particle : TI
int num_Ee_bins; // number of Ee_bins in Populations
double *Ee_mids; // values for energy mids of Ee_bins in Populations
double *ve_mids; // corresponding v_values
public:
TI_e_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double m_eV) : Interaction_Base(Population, rngUni) {
m1_eV = Population->get_m_eV();
m2_eV = m_eV;
num_Ee_bins = Population->get_number_E_bins();
if (num_Ee_bins <= 1) {
throw MyException("Population is not kinetic, when expected kinetic.");
}
ve_mids = new double[num_Ee_bins];
Ee_mids = new double[num_Ee_bins];
for (int Ee_bin = 0; Ee_bin<num_Ee_bins; Ee_bin++) {
Ee_mids[Ee_bin] = Population->get_E_bin_mid_eV(Ee_bin);
ve_mids[Ee_bin] = calc_v_ms_from_E_eV(Ee_mids[Ee_bin], m1_eV);
}
}
double get_macro_sigma_m(const Particle &interPart);
protected:
double calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m);
double calc_microSigma_m2(const double &E1_eV, const int &Ee_bin);
private:
private:
virtual double get_microSigma_m2(const double &E_eV) = 0;
};
inline double TI_e_Interaction_Base::get_macro_sigma_m(const Particle &interPart) {
return calc_macro_sigma_m(interPart.get_E_eV(), interPart.get_x_m());
}
// Precompute Interactions of ions with kinetic e Populations
class TI_e_Precomputed_Interaction_Base : public TI_e_Interaction_Base {
public:
TI_e_Precomputed_Interaction_Base(
Population_Base *Population,
UniRNG *rngUni,
double m_eV);
inline double TI_e_Interaction_Base::calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m) {
Bins loc_bins = Population->get_loc_bin(loc_m);
double macro_sigma_m = 0;
for (int Ee_bin = 0; Ee_bin<num_Ee_bins; Ee_bin++) {
macro_sigma_m += calc_microSigma_m2(E_eV, Ee_bin) * Population->get_density_m3(Ee_bin, loc_bins);
}
return macro_sigma_m;
}
inline double TI_e_Interaction_Base::calc_microSigma_m2(const double &E2_eV, const int &Ee_bin) {
//return get_microSigma_m2(Ee_mids[Ee_bin]); // No Integration... Only e- energy
double v1_ms = ve_mids[Ee_bin];
double v2_ms = calc_v_ms_from_E_eV(E2_eV, m2_eV);
if (v1_ms > v2_ms*2000 ) { // 2000 represents 1% variation in energy
return get_microSigma_m2(Ee_mids[Ee_bin]);
} else {
auto integrand = [&](double theta) {
double E_eV = m1_eV/2 * (pow(v1_ms,2) + pow(v2_ms,2) - 2*v1_ms*v2_ms*cos(theta)) * pow(c_ms, -2);
return get_microSigma_m2(E_eV);
};
return integrate(integrand, pi/8., 7*pi/8., INT_N, simpson())/pi;
}
}
class TI_e_Precomputed_Interaction_Base : public TI_e_Interaction_Base { // Precompute Interactions of ions with kinetic e Populations
Log_Scale E_scale; // E_scale for Interpolation calculation
double **precomputed_values;
public:
TI_e_Precomputed_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double m_eV) : TI_e_Interaction_Base(Population, rngUni, m_eV), E_scale(INT_PRE_START, INT_PRE_END, INT_PRE_N) {
precomputed_values = new double *[E_scale.get_number_bins()];
for (int EI_bin=0; EI_bin<E_scale.get_number_bins(); EI_bin++) {
precomputed_values[EI_bin] = new double[num_Ee_bins];
}
}
void calc_values();
double get_macro_sigma_m(const Particle &interPart);
private:
private:
double lookup_macro_sigma_m(const double &E_eV, const vec3 &loc_m);
Log_Scale E_scale; // E_scale for Interpolation calculation
double **precomputed_values;
};
inline void TI_e_Precomputed_Interaction_Base::calc_values() {
for (int EI_bin=0; EI_bin<E_scale.get_number_bins(); EI_bin++) {
for (int Ee_bin = 0; Ee_bin<num_Ee_bins; Ee_bin++) {
precomputed_values[EI_bin][Ee_bin] = calc_microSigma_m2(E_scale.get_bin_mid(EI_bin), Ee_bin);
}
}
}
inline double TI_e_Precomputed_Interaction_Base::get_macro_sigma_m(const Particle &interPart) {
vec3 loc_m = interPart.get_x_m();
double E_eV = interPart.get_E_eV();
if (E_scale.in_scale(E_eV)) {
return lookup_macro_sigma_m(E_eV, loc_m);
} else {
return calc_macro_sigma_m(E_eV, loc_m);
}
}
inline double TI_e_Precomputed_Interaction_Base::lookup_macro_sigma_m(const double &E_eV, const vec3 &loc_m) {
int EI_bin = E_scale.calc_index(E_eV);
double *microSigmas = precomputed_values[EI_bin];
Bins loc_bins = Population->get_loc_bin(loc_m);
double macro_sigma_m = 0;
for (int Ee_bin = 0; Ee_bin<num_Ee_bins; Ee_bin++) {
macro_sigma_m += microSigmas[Ee_bin] * Population->get_density_m3(Ee_bin, loc_bins);
}
return macro_sigma_m;
}
#endif /* TI_kinetic_base_h */
+4 -2
View File
@@ -40,6 +40,7 @@ constant TritiumDecayEndpoint_eV = 18.574e3;
// WGTS
constant z_RW_m = -3;
constant z_rear_m = -1.57;
constant z_WGTS_start_m = 0;
constant z_WGTS_end_m = 10;
constant z_DPS_end_m = 13;
@@ -48,8 +49,9 @@ constant l_WGTS_m = z_WGTS_end_m - z_WGTS_start_m;
constant z_WGTS_mid_m = (z_WGTS_end_m+z_WGTS_start_m)/2;
// from Kuckert:2018aa
constant reduction_WGTS_front = 0.034;
constant reduction_WGTS_rear = 0.033;
constant reduction_WGTS_front = 0.02;
constant reduction_WGTS_rear = 0.02;
constant reduction_rear_wgts = 0.002;
constant reduction_tot_front = 5e-4;
constant reduction_tot_rear = 5e-4;
+30
View File
@@ -0,0 +1,30 @@
#include "eT2I_recombination.h"
#include "recombination_counter.h"
eT2I_Recombination::eT2I_Recombination(
Population_Base *T2IPopulation,
UniRNG *rngUni) :
e_thermal_Precomputed_Interaction_Base(
T2IPopulation, rngUni, me_eV)
{
calc_values(); // need to call here, because, constructor can't call pure virtual function
}
double eT2I_Recombination::get_microSigma_m2(
const double &E_eV)
{
return Janev_eT2I_Recombination::get_TCS(E_eV);
}
InteractionOut eT2I_Recombination::do_Interaction(
Particle *interPart)
{
InteractionOut res;
res.set_delete_current(true);
Population->decrease_denisty(interPart->get_x_m(), 0);
GlobalCounter::num_electron_recombinations += 1;
return res;
}
+4 -24
View File
@@ -1,11 +1,3 @@
//
// eT2I_recombination.h
// mc_electron
//
// Created by Christian Reiling on 18.06.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#ifndef eT2I_recombination_h
#define eT2I_recombination_h
@@ -15,24 +7,12 @@
class eT2I_Recombination : public e_thermal_Precomputed_Interaction_Base {
public:
eT2I_Recombination(Population_Base *T2IPopulation, UniRNG *rngUni) : e_thermal_Precomputed_Interaction_Base(T2IPopulation, rngUni, me_eV) {
calc_values(); // need to call here, because, constructor can't call pure virtual function
}
eT2I_Recombination(
Population_Base *T2IPopulation,
UniRNG *rngUni);
double get_microSigma_m2(const double &E_eV) {
return Janev_eT2I_Recombination::get_TCS(E_eV);
}
double get_microSigma_m2(const double &E_eV);
InteractionOut do_Interaction (Particle *interPart);
};
inline InteractionOut eT2I_Recombination::do_Interaction (Particle *interPart) {
InteractionOut res;
res.set_delete_current(true);
//std::cout<<"eT2I:\t"<<*interPart<<"\n";
//Population->decrease_denisty(interPart->get_x_m(), 0);
return res;
}
#endif /* eT2I_recombination_h */
+29
View File
@@ -0,0 +1,29 @@
#include "eT3I_recombination.h"
#include "janev_eT3I_recombination.h"
#include "recombination_counter.h"
eT3I_Recombination::eT3I_Recombination(
Population_Base *T3IPopulation,
UniRNG *rngUni) :
e_thermal_Precomputed_Interaction_Base(
T3IPopulation, rngUni, me_eV)
{
calc_values(); // need to call here, because, constructor can't call pure virtual function
}
double eT3I_Recombination::get_microSigma_m2(
const double &E_eV)
{
return Janev_eT3I_Recombination::get_TCS(E_eV);
}
InteractionOut eT3I_Recombination::do_Interaction (Particle *interPart) {
InteractionOut res;
res.set_delete_current(true);
Population->decrease_denisty(interPart->get_x_m(), 0);
GlobalCounter::num_electron_recombinations +=1;
return res;
}
+2 -22
View File
@@ -1,36 +1,16 @@
//
// eT3I_recombination.h
// mc_electron
//
// Created by Christian Reiling on 12.07.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#ifndef eT3I_recombination_h
#define eT3I_recombination_h
#include "e_thermal_base.h"
#include "janev_eT3I_recombination.h"
class eT3I_Recombination : public e_thermal_Precomputed_Interaction_Base {
public:
eT3I_Recombination(Population_Base *T3IPopulation, UniRNG *rngUni) : e_thermal_Precomputed_Interaction_Base(T3IPopulation, rngUni, me_eV) {
calc_values(); // need to call here, because, constructor can't call pure virtual function
}
eT3I_Recombination(Population_Base *T3IPopulation, UniRNG *rngUni);
double get_microSigma_m2(const double &E_eV) {return Janev_eT3I_Recombination::get_TCS(E_eV);}
double get_microSigma_m2(const double &E_eV);
InteractionOut do_Interaction (Particle *interPart);
};
inline InteractionOut eT3I_Recombination::do_Interaction (Particle *interPart) {
InteractionOut res;
res.set_delete_current(true);
//std::cout<<"eT3I:\t"<<*interPart<<"\n";
//Population->decrease_denisty(interPart->get_x_m(), 0);
return res;
}
#endif /* eT3I_recombination_h */
+1 -9
View File
@@ -1,11 +1,3 @@
//
// eT5I_recombination.h
// mc_electron
//
// Created by Christian Reiling on 16.09.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#ifndef eT5I_recombination_h
#define eT5I_recombination_h
@@ -30,7 +22,7 @@ inline InteractionOut eT5I_Recombination::do_Interaction (Particle *interPart) {
InteractionOut res;
//std::cout<<"eT5I:\t"<<*interPart<<"\n";
res.set_delete_current(true);
//Population->decrease_denisty(interPart->get_x_m(), 0);
Population->decrease_denisty(interPart->get_x_m(), 0);
return res;
}
+111
View File
@@ -0,0 +1,111 @@
#include "e_thermal_base.h"
#include "interaction_base.h"
#include "blitz/array.h"
#include "kinematics.h"
e_thermal_Interaction_Base::e_thermal_Interaction_Base(
Population_Base *Population,
UniRNG *rngUni,
double m_eV) :
Interaction_Base(Population, rngUni)
{
if (Population->get_number_E_bins() > 1) {
throw MyException("Population is not thermal, when expected thermal.");
}
m1_eV = m_eV;
v_therm = Population->get_thermal_v_ms(); // Typical Speed of "Thermal Blur"
E_limit = calc_E_eV_from_v_ms(v_therm * 2000, m1_eV); // 2000 represents 1% variation in energy
}
double e_thermal_Interaction_Base::get_macro_sigma_m(const Particle &interPart)
{
vec3 loc_m = interPart.get_x_m();
double v_ms = calc_vec3_abs(
interPart.get_v_ms() - Population->get_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur"
double E_eV = calc_E_eV_from_v_ms(v_ms, m1_eV); // Lab energy without thermal integration
return calc_macro_sigma_m(E_eV, loc_m);
}
double e_thermal_Interaction_Base::calc_macro_sigma_m(
const double &E_eV, const vec3 &loc_m)
{
return calc_microSigma_m2(E_eV)*Population->get_density_m3(loc_m);
}
double e_thermal_Interaction_Base::calc_microSigma_m2(const double &E_eV)
{
//return get_microSigma_m2(E_eV); //No Integration... Only e- energy
if (E_eV > E_limit) {
return get_microSigma_m2(E_eV);
} else {
const double v1_ms = calc_v_ms_from_E_eV(E_eV, m1_eV);
const double m2_eV = Population->get_m_eV();
// Integration over theta and v
auto integrand = [&](double v2_ms, double theta) {
// v2_ms: drift already taken care of in get macro sigma
const double E_incident = kineticEnergyIncidentRelativistic(
v1_ms, v2_ms, m1_eV, m2_eV, theta);
// frame where ion is at rest
return Population->get_v_pdf(v2_ms)*get_microSigma_m2(E_incident)/pi;
};
return double_simpson_integrate(integrand, 0., 3*v_therm, pi/8., 7./8.*pi, INT_N, INT_N); // 3*v_therm equals 99% of the integral
}
}
vec3 e_thermal_Interaction_Base::get_vOff_ms(
const Particle &interPart, const double &minE_eV)
{
vec3 v1_ms = interPart.get_v_ms();
vec3 v2_ms = Population->roll_v_ms(interPart.get_x_m());
vec3 v1Lab_ms = v1_ms - v2_ms;
double T_eV = calc_E_eV_from_v_ms(v1Lab_ms, m1_eV);
if (T_eV < minE_eV) {
T_eV = calc_E_eV_from_v_ms(v1_ms, m1_eV);
if (T_eV < minE_eV) {
std::stringstream ss;
ss<<"Interaction_Base::get_vOff_ms: T_eV < minE_eV.\nT_eV= "<< T_eV<<"\t minE_eV= "<<minE_eV<<"\n";
throw MyException (ss.str());
}
return vec3(0,0,0);
}
return v2_ms;
}
e_thermal_Precomputed_Interaction_Base::e_thermal_Precomputed_Interaction_Base(
Population_Base *Population, UniRNG *rngUni, double m_eV):
e_thermal_Interaction_Base(Population, rngUni, m_eV),
E_scale(INT_PRE_START, INT_PRE_END, INT_PRE_N)
{
precomputed_values = new double [E_scale.get_number_bins()];
}
void e_thermal_Precomputed_Interaction_Base::calc_values() {
for (int i=0; i<E_scale.get_number_bins(); i++) {
precomputed_values[i] = calc_microSigma_m2(E_scale.get_bin_mid(i));
}
}
double e_thermal_Precomputed_Interaction_Base::get_macro_sigma_m(
const Particle &interPart)
{
vec3 loc_m = interPart.get_x_m();
double v_ms = calc_vec3_abs(
interPart.get_v_ms() - Population->get_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur"
double E_eV = calc_E_eV_from_v_ms(v_ms, m1_eV); // Lab energy without thermal integration
if (E_scale.in_scale(E_eV)) {
return lookup_macro_sigma_m(E_eV, loc_m);
} else {
return calc_macro_sigma_m(E_eV, loc_m);
}
}
double e_thermal_Precomputed_Interaction_Base::lookup_macro_sigma_m(
const double &E_eV, const vec3 &loc_m)
{
int i = E_scale.calc_index(E_eV);
return precomputed_values[i] * Population->get_density_m3(loc_m);
}
+23 -99
View File
@@ -1,122 +1,46 @@
//
// e_thermal_base.h
// mc_electron
//
// Created by Christian Reiling on 18.11.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#ifndef e_thermal_base_h
#define e_thermal_base_h
#include "interaction_base.h"
// Interactions of electrons with thermal Populations
class e_thermal_Interaction_Base : public Interaction_Base {
class e_thermal_Interaction_Base : public Interaction_Base { // Interactions of electrons with thermal Populations
protected:
public:
e_thermal_Interaction_Base(
Population_Base *Population,
UniRNG *rngUni, double m_eV);
protected:
double m1_eV; // energy of kinetic particle in CS measurement : e-
double E_limit; // limit for integration calculation
double v_therm; // typical spped for thermal population
public:
e_thermal_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double m_eV) : Interaction_Base(Population, rngUni) {
if (Population->get_number_E_bins() > 1) {
throw MyException("Population is not thermal, when expected thermal.");
}
m1_eV = m_eV;
v_therm = Population->get_thermal_v_ms(); // Typical Speed of "Thermal Blur"
E_limit = calc_E_eV_from_v_ms(v_therm * 2000, m1_eV); // 2000 represents 1% variation in energy
}
double get_macro_sigma_m(const Particle &interPart);
protected:
double calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m);
double calc_microSigma_m2(const double &E_eV);
vec3 get_vOff_ms(const Particle &interPart, const double &minE_eV); // For derived class -> Roll energy loss
private:
double get_macro_sigma_m(const Particle &interPart);
private:
virtual double get_microSigma_m2(const double &E_eV) = 0;
};
inline double e_thermal_Interaction_Base::get_macro_sigma_m(const Particle &interPart) {
vec3 loc_m = interPart.get_x_m();
double v_ms = calc_vec3_abs(interPart.get_v_ms() - Population->get_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur"
double E_eV = calc_E_eV_from_v_ms(v_ms, m1_eV); // Lab energy without thermal integration
return calc_macro_sigma_m(E_eV, loc_m);
}
inline double e_thermal_Interaction_Base::calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m) {
return calc_microSigma_m2(E_eV)*Population->get_density_m3(loc_m);
}
inline double e_thermal_Interaction_Base::calc_microSigma_m2(const double &E_eV) {
//return get_microSigma_m2(E_eV); //No Integration... Only e- energy
if (E_eV > E_limit) {
return get_microSigma_m2(E_eV);
} else {
double v1_ms = calc_v_ms_from_E_eV(E_eV, m1_eV);
// Integration over theta and v
auto integrand = [&](double v2_ms, double theta) {
double E_eV = m1_eV/2 * (pow(v1_ms,2) + pow(v2_ms,2) - 2*v1_ms*v2_ms*cos(theta)) * pow(c_ms, -2);
return Population->get_v_pdf(v2_ms)*get_microSigma_m2(E_eV)/pi;
};
return double_simpson_integrate(integrand, 0., 3*v_therm, pi/8., 7.*pi/8., INT_N, INT_N); // 3*v_therm equals 99% of the integral
}
}
inline vec3 e_thermal_Interaction_Base::get_vOff_ms(const Particle &interPart, const double &minE_eV) {
vec3 v1_ms = interPart.get_v_ms();
vec3 v2_ms = Population->roll_v_ms(interPart.get_x_m());
vec3 v1Lab_ms = v1_ms - v2_ms;
double T_eV = calc_E_eV_from_v_ms(v1Lab_ms, m1_eV);
if (T_eV < minE_eV) {
T_eV = calc_E_eV_from_v_ms(v1_ms, m1_eV);
if (T_eV < minE_eV) {
std::stringstream ss;
ss<<"Interaction_Base::get_vOff_ms: T_eV < minE_eV.\nT_eV= "<< T_eV<<"\t minE_eV= "<<minE_eV<<"\n";
throw MyException (ss.str());
}
return vec3(0,0,0);
}
return v2_ms;
}
class e_thermal_Precomputed_Interaction_Base : public e_thermal_Interaction_Base { // + Using precomputed values
Log_Scale E_scale; // E_scale for Interpolation calculation
double *precomputed_values;
public:
e_thermal_Precomputed_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double m_eV) : e_thermal_Interaction_Base(Population, rngUni, m_eV), E_scale(INT_PRE_START, INT_PRE_END, INT_PRE_N) {
precomputed_values = new double [E_scale.get_number_bins()];
}
// Using precomputed values
class e_thermal_Precomputed_Interaction_Base : public e_thermal_Interaction_Base {
public:
e_thermal_Precomputed_Interaction_Base(
Population_Base *Population,
UniRNG *rngUni,
double m_eV);
void calc_values(); // must be called by derived class, can't call in this constructor, due to virtual pure
double get_macro_sigma_m(const Particle &interPart);
private:
private:
double lookup_macro_sigma_m(const double &E_eV, const vec3 &loc_m);
Log_Scale E_scale; // E_scale for Interpolation calculation
double *precomputed_values;
};
inline void e_thermal_Precomputed_Interaction_Base::calc_values() {
for (int i=0; i<E_scale.get_number_bins(); i++) {
precomputed_values[i] = calc_microSigma_m2(E_scale.get_bin_mid(i));
}
}
inline double e_thermal_Precomputed_Interaction_Base::get_macro_sigma_m(const Particle &interPart) {
vec3 loc_m = interPart.get_x_m();
double v_ms = calc_vec3_abs(interPart.get_v_ms() - Population->get_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur"
double E_eV = calc_E_eV_from_v_ms(v_ms, m1_eV); // Lab energy without thermal integration
if (E_scale.in_scale(E_eV)) {
return lookup_macro_sigma_m(E_eV, loc_m);
} else {
return calc_macro_sigma_m(E_eV, loc_m);
}
}
inline double e_thermal_Precomputed_Interaction_Base::lookup_macro_sigma_m(const double &E_eV, const vec3 &loc_m) {
int i = E_scale.calc_index(E_eV);
return precomputed_values[i] * Population->get_density_m3(loc_m);
}
#endif /* e_thermal_base_h */
+11 -12
View File
@@ -1,5 +1,5 @@
#include "electron_E_drift.h"
#include <cmath>
void E_Mover_E_Drift::do_E_calculus(Particle *movePart, const vec3 &oldLoc_m, const double &macro_sigma_m) {
if (macro_sigma_m <= 0) {
@@ -8,19 +8,18 @@ void E_Mover_E_Drift::do_E_calculus(Particle *movePart, const vec3 &oldLoc_m, co
double t_s = 1/macro_sigma_m/calc_vec3_abs(movePart->get_v_ms());
vec3 newLoc_m = movePart->get_x_m();
vec3 E_Vm = 0.5 * (Katrin_Fields::getElField_Vm(oldLoc_m) + Katrin_Fields::getElField_Vm(newLoc_m));
double B_T = calc_vec3_abs( 0.5 * (Katrin_Fields::getMagField_T(oldLoc_m) + Katrin_Fields::getMagField_T(newLoc_m)) );
double E_rad_Vm = calc_r_m(E_Vm);
double v_rad_ms = E_rad_Vm/B_T;
vec3 loc_offset_m = E_Vm;
if((loc_offset_m(0) == 0.) && (loc_offset_m(1) == 0.)){
loc_offset_m = 0.;
} else{
loc_offset_m(2) = 0.;
loc_offset_m = loc_offset_m/calc_vec3_abs(loc_offset_m) * v_rad_ms * t_s;
vec3 B_T = 0.5 * (Katrin_Fields::getMagField_T(oldLoc_m) + Katrin_Fields::getMagField_T(newLoc_m));
const double B_squared = static_cast<double>(blitz::dot(B_T, B_T));
vec3 v_drift;
if(B_squared == 0){
v_drift = vec3(0,0,0);
}
else{
v_drift = blitz::cross(E_Vm, B_T)/(B_squared);
}
movePart->set_x_m(newLoc_m + loc_offset_m);
movePart->set_x_m(newLoc_m + v_drift*t_s);
vec3 v_boost_ms = vec3(0,0, movePart->get_Z()*e_C/movePart->get_m_eV()*E_Vm[2] * t_s/c_ms/c_ms);
movePart->set_v_ms(movePart->get_v_ms() + v_boost_ms);
}
-8
View File
@@ -1,11 +1,3 @@
//
// janev_eT3I_recombination.h
// mc_electron
//
// Created by Christian Reiling on 12.07.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#ifndef janev_eT3I_recombination_h
#define janev_eT3I_recombination_h
+26
View File
@@ -71,5 +71,31 @@ inline double calc_phi(const vec3 &loc_m) {
}
}
inline double gamma(double v)
{
return 1./std::sqrt(1-std::pow(v/c_ms, 2));
}
inline double kineticEnergyIncidentRelativistic(double v1, double v2, double m1, double m2, double theta)
{
// relativistic transformation to a system where m2 is at rest
const double p1 = gamma(v1)*m1*v1/c_ms;
const double p2 = gamma(v2)*m2*v2/c_ms;
const double E1 = std::sqrt(std::pow(m1,2)+std::pow(p1,2));
const double E2 = std::sqrt(std::pow(m2,2)+std::pow(p2,2));
const double s =
std::pow(m1, 2) + std::pow(m2,2) + 2*E1*E2 - 2*p1*p2*std::cos(theta);
const double twoEam2 = s - std::pow(m1, 2) - std::pow(m2, 2);
const double E_incident = twoEam2/(2*m2);
const double E_kin_incident = E_incident - m1;
return E_kin_incident;
}
inline double kineticIncidentEnergySwitch(double E1, double m1, double m2)
{
// relativistic transformation to a system where m1 is at rest
const double E_kin_incident = (E1 + m1)*m2/m1 - m2;
return E_kin_incident;
}
#endif /* kinematics_h */
+8
View File
@@ -24,6 +24,14 @@ OBJS := particle_looper.o \
TIT2_elastic.o \
CurrentHistogram.o \
CurrentLogger.o \
e_thermal_base.o \
TI_kinetic_base.o \
eT2I_recombination.o \
eT3I_recombination.o \
T2Ie_recombination.o \
T3Ie_recombination.o \
postive_E_drift.o \
recombination_counter.o \
CXXFLAGS = $(X_OFLAGS) -I.. $(X_INC) -std=c++11
+8 -1
View File
@@ -1,4 +1,5 @@
#include "particle_looper.hpp"
#include "recombination_counter.h"
using namespace std;
@@ -48,6 +49,12 @@ void Particle_Looper::do_loops(int target_decays) {
log_output = part_loggers.find(species::tritium3I);
log_output->output();
log_output = part_loggers.find(species::tritiumI);
log_output->output();
log_output = part_loggers.find(species::tritium2I);
log_output->output();
pop_loggers.log();
}
@@ -88,7 +95,7 @@ void Particle_Looper::process_one(std::vector<Particle> *particle_queue) {
}
}
particle_queue->erase(particle_queue->begin() + i);
//std::cout << "Particle: " << i << " of " << particle_queue->size() << " particles\n";
}
+3 -1
View File
@@ -139,9 +139,11 @@ double Population_Container::get_density_m3(const int &E_bin, const Bins &loc_bi
int offset = offsets[data_bin];
double V_m3 = size_data_m3[loc_bins.r];
double n_m3 = cum_time_s/time_s/V_m3 - offset;
double n_m3 = cum_time_s/time_s/V_m3 - offset/V_m3;
if (n_m3<0) {
n_m3 = 0;
cum_times_s[data_bin] = 0;
offsets[data_bin] = 0;
}
return n_m3;
}
+33
View File
@@ -0,0 +1,33 @@
#include "postive_E_drift.h"
#include <cmath>
Positive_Mover_E_Drift::Positive_Mover_E_Drift(
species this_species,
Particle_Logger_Base *Logger,
Population_Base *Population) :
Positive_Mover_Drift(this_species, Logger, Population)
{};
void Positive_Mover_E_Drift::do_E_calculus(Particle *movePart, const vec3 &oldLoc_m, const double &macro_sigma_m) {
if (macro_sigma_m <= 0) {
return;
}
double t_s = 1/macro_sigma_m/calc_vec3_abs(movePart->get_v_ms());
vec3 newLoc_m = movePart->get_x_m();
vec3 E_Vm = 0.5 * (Katrin_Fields::getElField_Vm(oldLoc_m) + Katrin_Fields::getElField_Vm(newLoc_m));
vec3 B_T = 0.5 * (Katrin_Fields::getMagField_T(oldLoc_m) + Katrin_Fields::getMagField_T(newLoc_m));
const double B_squared = static_cast<double>(blitz::dot(B_T, B_T));
vec3 v_drift;
if(B_squared == 0){
v_drift = vec3(0,0,0);
}
else{
v_drift = blitz::cross(E_Vm, B_T)/(B_squared);
}
movePart->set_x_m(newLoc_m + v_drift*t_s);
vec3 v_boost_ms = vec3(0,0, movePart->get_Z()*e_C/movePart->get_m_eV()*E_Vm[2] * t_s/c_ms/c_ms);
movePart->set_v_ms(movePart->get_v_ms() + v_boost_ms);
}
+13 -43
View File
@@ -1,50 +1,20 @@
//
// postive_E_drift.h
// mc_electron
//
// Created by Christian Reiling on 05.10.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#ifndef postive_E_drift_h
#define postive_E_drift_h
#ifndef POSTIVE_E_DRIFT_H
#define POSTIVE_E_DRIFT_H
#include "postive_drift.h"
class Positive_Mover_E_Drift : public Positive_Mover_Drift {
public:
Positive_Mover_E_Drift(species this_species, Particle_Logger_Base *Logger, Population_Base *Population) : Positive_Mover_Drift(this_species, Logger, Population) {};
public:
Positive_Mover_E_Drift(
species this_species,
Particle_Logger_Base *Logger,
Population_Base *Population);
protected:
void do_E_calculus(Particle *movePart, const vec3 &oldLoc_m, const double &macro_sigma_m);
protected:
void do_E_calculus(
Particle *movePart,
const vec3 &oldLoc_m,
const double &macro_sigma_m);
};
inline void Positive_Mover_E_Drift::do_E_calculus(Particle *movePart, const vec3 &oldLoc_m, const double &macro_sigma_m) {
if (macro_sigma_m <= 0) {
return;
}
double t_s = 1/macro_sigma_m/calc_vec3_abs(movePart->get_v_ms());
vec3 newLoc_m = movePart->get_x_m();
vec3 E_Vm = 0.5 * (Katrin_Fields::getElField_Vm(oldLoc_m) + Katrin_Fields::getElField_Vm(newLoc_m));
double B_T = calc_vec3_abs( 0.5 * (Katrin_Fields::getMagField_T(oldLoc_m) + Katrin_Fields::getMagField_T(newLoc_m)) );
double E_rad_Vm = calc_r_m(E_Vm);
double v_rad_ms = E_rad_Vm/B_T;
vec3 loc_offset_m = E_Vm;
if((loc_offset_m(0) == 0.) && (loc_offset_m(1) == 0.)){
loc_offset_m = 0.;
} else{
loc_offset_m(2) = 0.;
loc_offset_m = loc_offset_m/calc_vec3_abs(loc_offset_m) * v_rad_ms * t_s;
}
movePart->set_x_m(newLoc_m + loc_offset_m);
vec3 v_boost_ms = vec3(0,0, movePart->get_Z()*e_C/movePart->get_m_eV()*E_Vm[2] * t_s/c_ms/c_ms);
movePart->set_v_ms(movePart->get_v_ms() + v_boost_ms);
}
#endif /* postive_E_drift_h */
#endif /* POSTIVE_E_DRIFT_H */
+6
View File
@@ -0,0 +1,6 @@
#include "recombination_counter.h"
long int GlobalCounter::num_electron_recombinations{0};
long int GlobalCounter::num_T3I_recombinations{0};
long int GlobalCounter::num_T2I_recombinations{0};
long int GlobalCounter::num_TI_recombinations{0};
+12
View File
@@ -0,0 +1,12 @@
#ifndef RECOMBINATION_COUNTER_H
#define RECOMBINATION_COUNTER_H
struct GlobalCounter {
static long int num_electron_recombinations;
static long int num_T3I_recombinations;
static long int num_T2I_recombinations;
static long int num_TI_recombinations;
};
#endif /* RECOMBINATION_COUNTER_H */
+27 -6
View File
@@ -9,6 +9,7 @@
#include "simulation.hpp"
#include <iomanip>
#include "recombination_counter.h"
using namespace std;
@@ -257,14 +258,34 @@ void Simulation::print_term_stats() {
global_stats.from_array(global_array);
if (mpi_rank == 0) {
std::cout<<"# "<<*itr<<"\n";
std::cout<<"n_total\t"<<global_stats.n_total<<"\n";
std::cout<<"n_rw\t"<<global_stats.n_rw<<"\n";
std::cout<<"n_dipole\t"<<global_stats.n_dipole<<"\n";
std::cout<<"n_radial\t"<<global_stats.n_radial<<"\n";
std::cout<<"n_max\t"<<global_stats.n_max<<"\n";
std::cout<<"n_energy\t"<<global_stats.n_energy<<"\n";
std::cout<<"n_total \t"<<global_stats.n_total<<"\n";
std::cout<<"n_rw \t"<<global_stats.n_rw<<"\n";
std::cout<<"n_dipole \t"<<global_stats.n_dipole<<"\n";
std::cout<<"n_radial \t"<<global_stats.n_radial<<"\n";
std::cout<<"n_max \t"<<global_stats.n_max<<"\n";
std::cout<<"n_energy \t"<<global_stats.n_energy<<"\n";
std::cout<<"n_reaction\t"<<global_stats.n_reaction<<"\n";
}
}
}
long int num_e_recombinations = 0;
MPI_Allreduce(&(GlobalCounter::num_electron_recombinations), &num_e_recombinations, 1, MPI_LONG, MPI_SUM, MPI_COMM_WORLD);
long int num_TI2_recombinations = 0;
MPI_Allreduce(&(GlobalCounter::num_T2I_recombinations), &num_TI2_recombinations, 1, MPI_LONG, MPI_SUM, MPI_COMM_WORLD);
long int num_TI3_recombinations = 0;
MPI_Allreduce(&(GlobalCounter::num_T3I_recombinations), &num_TI3_recombinations, 1, MPI_LONG, MPI_SUM, MPI_COMM_WORLD);
long int num_TI_recombinations = 0;
MPI_Allreduce(&(GlobalCounter::num_TI_recombinations), &num_TI_recombinations, 1, MPI_LONG, MPI_SUM, MPI_COMM_WORLD);
if(mpi_rank == 0){
std::cout << "# Recombinations\n";
std::cout << "n_rec_e- \t"<<num_e_recombinations<<"\n";
std::cout << "n_rec_T+ \t"<<num_TI_recombinations<<"\n";
std::cout << "n_rec_T2+ \t"<<num_TI2_recombinations<<"\n";
std::cout << "n_rec_T3+ \t"<<num_TI3_recombinations<<"\n";
}
}
+3 -3
View File
@@ -57,9 +57,9 @@ public:
const double T2_Population::wgtsT2MaxDensity_m3 = load_parameter("T2_MAXDENS");
inline void T2_Population::set_regimes() {
n_regimes = 4;
double reds[5] = {reduction_tot_rear, reduction_WGTS_rear, 1, reduction_WGTS_front, reduction_tot_front};
double zs[5] = {z_RW_m, z_WGTS_start_m, z_WGTS_mid_m, z_WGTS_end_m, z_DPS_end_m};
n_regimes = 5;
double reds[6] = {reduction_tot_rear, reduction_rear_wgts, reduction_WGTS_rear, 1, reduction_WGTS_front, reduction_tot_front};
double zs[6] = {z_RW_m, z_rear_m, z_WGTS_start_m, z_WGTS_mid_m, z_WGTS_end_m, z_DPS_end_m};
reduction_min = new double[n_regimes];
double reduction_max;
z_min_m = new double[n_regimes];
@@ -16,9 +16,13 @@ def makeBarPlotData(data, mins, maxs):
def plotAllDensityVsZ(filename, filename_output):
keys = ["/Populations/e-/e-", "/Populations/T+/T+", "/Populations/T2+/T2+", "/Populations/T3+/T3+"]
print("Get Density: e-")
density_e = getDensities(filename, keys[0])
print("Get Density: T+")
density_T = getDensities(filename, keys[1])
print("Get Density: T2+")
density_T2 = getDensities(filename, keys[2])
print("Get Density: T3+")
density_T3 = getDensities(filename, keys[3])
zmins = getZBinsMin(filename, keys[0])
@@ -140,15 +140,26 @@ def outputFilename(filename_bare, cpu_number, num_cpu):
return filename_bare +cpuString(cpu_number, num_cpu) + "_currents.h5"
def mergeOutputs(filename, num_cpu, specie_key):
print("Merging outputs")
first_filename = outputFilename(filename, 0, num_cpu)
print(first_filename)
print("get bin borders")
bin_borders_z = binBordersZ(first_filename, specie_key)
bin_borders_r = binBordersR(first_filename, specie_key)
bin_borders_E = binBordersE(first_filename, specie_key)
print("Data first")
print("N_pos_z")
N_pos_z = NPosZ(first_filename, specie_key)
print("N_neg_z")
N_neg_z = NNegZ(first_filename, specie_key)
print("N_pos_r")
N_pos_r = NPosR(first_filename, specie_key)
print("N_neg_r")
N_neg_r = NNegR(first_filename, specie_key)
for i in np.arange(1,num_cpu,1):
print("At cpu: " + str(i))
N_pos_z += NPosZ(outputFilename(filename, i, num_cpu), specie_key)
N_neg_z += NNegZ(outputFilename(filename, i, num_cpu), specie_key)
N_pos_r += NPosR(outputFilename(filename, i, num_cpu), specie_key)
@@ -156,17 +167,63 @@ def mergeOutputs(filename, num_cpu, specie_key):
f = h5py.File(filename+"currents_merged.h5", 'a')
key = specie_key+"/current_bin_borders/bin_borders_E"
print("Saving: " + key)
try:
del f[key]
except:
pass
dset = f.create_dataset(key,data=bin_borders_E)
key = specie_key+"/current_bin_borders/bin_borders_r"
print("Saving: " + key)
try:
del f[key]
except:
pass
dset = f.create_dataset(key,data=bin_borders_r)
key = specie_key+"/current_bin_borders/bin_borders_z"
print("Saving: " + key)
try:
del f[key]
except:
pass
dset = f.create_dataset(key,data=bin_borders_z)
key = specie_key+"/N_pos_z"
f.create_dataset(key,data=N_pos_z)
print("Saving: " + key)
try:
del f[key]
except:
pass
dset = f.create_dataset(key,data=N_pos_z)
key = specie_key+"/N_neg_z"
f.create_dataset(key,data=N_neg_z)
print("Saving: " + key)
try:
del f[key]
except:
pass
dset = f.create_dataset(key,data=N_neg_z)
key = specie_key+"/N_pos_r"
f.create_dataset(key,data=N_pos_r)
print("Saving: " + key)
try:
del f[key]
except:
pass
dset = f.create_dataset(key,data=N_pos_r)
key = specie_key+"/N_neg_r"
f.create_dataset(key,data=N_neg_r)
print("Saving: " + key)
try:
del f[key]
except:
pass
dset = f.create_dataset(key,data=N_neg_r)
f.close()
@@ -37,15 +37,30 @@ def getDensities(filename, key):
data_last = data[data[:,0] == last_output_time]
[zbins, rbins, phi_bins, E_bins] = getNumBins(filename, key)
zbins_min = getZBinsMin(filename, key)
zbins_max = getZBinsMax(filename, key)
rbins_min = getRBinsMin(filename, key)
rbins_max = getRBinsMax(filename, key)
phibins_min = getPhiBinsMin(filename, key)
phibins_max = getPhiBinsMax(filename, key)
print("Get Cum times")
cum_times = getCumTimes(filename, key)
densities = np.zeros((zbins, rbins, phi_bins, E_bins))
print("Calculate densities")
for iz in np.arange(0,zbins,1):
print("iz: " + str(iz))
for ir in np.arange(0,rbins,1):
for iphi in np.arange(0,phi_bins,1):
for iE in np.arange(0,E_bins,1):
densities[iz,ir,iphi,iE] = cum_times[iz, ir, iphi, iE]/(last_output_time*getVolume(filename, key, iz, ir, iphi))
z_bin_min = zbins_min[iz]
z_bin_max = zbins_max[iz]
r_bin_min = rbins_min[ir]
r_bin_max = rbins_max[ir]
phi_bin_min = phibins_min[iphi]
phi_bin_max = phibins_max[iphi]
densities[iz,ir,iphi,iE] = cum_times[iz, ir, iphi, iE]/(last_output_time*getVolume(z_bin_min, z_bin_max, r_bin_min, r_bin_max, phi_bin_min, phi_bin_max))
return densities
@@ -148,14 +163,7 @@ def getNumBins(filename, key):
return [zbins, rbins, phi_bins, E_bins]
def getVolume(filename, key, z_bin, r_bin, phi_bin):
z_min = getZBinsMin(filename, key)[z_bin]
z_max = getZBinsMax(filename, key)[z_bin]
r_min = getRBinsMin(filename, key)[r_bin]
r_max = getRBinsMax(filename, key)[r_bin]
phi_min = getPhiBinsMin(filename, key)[phi_bin]
phi_max = getPhiBinsMax(filename, key)[phi_bin]
def getVolume(z_min, z_max, r_min, r_max, phi_min, phi_max):
A = (r_max**2 - r_min**2)*(phi_max-phi_min)/2
h = z_max-z_min
return A*h