Kariba
Loading...
Searching...
No Matches
Particles.hpp
Go to the documentation of this file.
1#pragma once
2#include <cmath>
3#include <vector>
4
5namespace kariba {
6
8struct PlParams {
9 double s;
10 double n;
11};
12
14struct BknParams {
15 double s1;
16 double s2;
17 double brk;
18 double max;
19 double m;
21};
22
24struct ThParams {
25 double t;
26 double n;
27 double m;
28};
29
31struct KParams {
32 double t;
33 double k;
34};
35
38 double s;
39 double t;
40 double nth;
41 double npl;
42 double m;
43 double min;
44 double max;
45 double cutoff;
47};
48
51 double t;
52 double k;
53 double n;
54 double m;
55};
56
59 double s;
60 double n;
61 double m;
62 double max;
64};
65
68 double s1;
69 double s2;
70 double brk;
71 double max;
72 double m;
73 double n;
75};
76
80
81
82enum CutoffType { //trying something to make this easier to read,
83 // it will convert directly to int when used
86 Sech2 = 2
87
88};
89
90class Particles {
91 protected:
92 double mass_gr;
93 double mass_kev;
94
95 std::vector<double> p;
96 std::vector<double> ndens;
97 std::vector<double> gamma;
98 std::vector<double> gdens;
99 std::vector<double> pdensp2_diff_logp;
101 int cutoff_type = Exponential; // setting cutoff type for legacy bhjet without cutoff switch
102 public:
103 Particles(size_t size);
104 // cutoff adjustments:
105 int get_cutoff_type() const { return cutoff_type; }
106 virtual void set_cutoff_type(int t) { cutoff_type = t; }
107 static double cutoff_factor(double x, int type = Exponential);
108
109 virtual void set_mass(double m);
110 virtual void initialize_gdens();
111 virtual void initialize_pdens();
112 virtual void differentiate();
113
114 virtual const std::vector<double>& get_p() const { return p; }
115 virtual const std::vector<double>& get_pdens() const { return ndens; }
116 virtual const std::vector<double>& get_gamma() const { return gamma; }
117 virtual const std::vector<double>& get_gdens() const { return gdens; }
118 virtual const std::vector<double>& get_pdensp2_diff_logp() const { return pdensp2_diff_logp; }
119
120 virtual double count_particles();
121 virtual double count_particles_energy();
122 virtual double av_p();
123 virtual double av_gamma();
124 virtual double av_psq();
125 virtual double av_gammasq();
126
127 virtual void test_arrays();
128};
129
130//need this to be accessible by both mixed and powerlaw, so here goes:
131// this has three options for the behavior of the cutoff in the electron spectrum:
132// 1. the traditional exponential cutoff exp(e/ecut)
133// 2. this is from Comisso 2021, exp[(e/ecut)^2] - magnetic turbulence PIC sim
134// 3. also comisso 2021, sech[(e/ecut)^2]
135
136// in principle, meant to act like this: (in set_ndens or injection_mixed_int), in mixed.cpp or powerlaw.cpp:
137// C = cutoff_factor(p[i]/pmax_pl, cutoff_type); then ndens = npl * mom_int thing * C
138
139// Three cutoff types, with x = p/p_cut (momentum)
140//cutoff type 0 = exp(-x)
141// cutoff type 1 = exp(-x^2)
142
143// cutoff type 2 = sech(x)^2 = 1/cosh(x)^2
144// cosh(x) = ( e^x + e^-x ) / 2
145//
146
147inline double Particles::cutoff_factor(double x, int type)
148{
149 switch (type) {
150 case Exponential: // classic exponential cutoff
151 return std::exp(-x);
152 case SuperExponential:
153 return std::exp(-(x * x));
154 case Sech2: { // sech^2 cutoff
155 const double ax = std::fabs(x);
156 if (ax < 30.0) { //cosh(30) ~ 5e12
157 const double c = std::cosh(ax); //directly calculate sech(x)
158 return 1.0 / (c * c);
159 } // this is to avoid issues with cosh, maybe should replace this with taylor exp .
160 const double t = std::exp(-2.0 * ax); //approx
161 const double denom = 1.0 + t;
162 return 4.0 * t / (denom * denom);
163 }
164
165 default:
166 return std::exp(-x);
167 }
168}
169
170} // namespace kariba
Definition Particles.hpp:90
std::vector< double > gamma
array of particle kinetic energies for each momentum
Definition Particles.hpp:97
static double cutoff_factor(double x, int type=Exponential)
Definition Particles.hpp:147
virtual const std::vector< double > & get_gamma() const
Definition Particles.hpp:116
virtual void initialize_gdens()
Definition Particles.cpp:60
virtual void set_mass(double m)
Definition Particles.cpp:128
std::vector< double > gdens
array of number density per unit volume, per unit gamma
Definition Particles.hpp:98
virtual void test_arrays()
simple method to check arrays; only meant for debugging
Definition Particles.cpp:134
virtual double av_psq()
Definition Particles.cpp:45
std::vector< double > p
array of particle momenta
Definition Particles.hpp:95
std::vector< double > pdensp2_diff_logp
density for radiation calculation p^-2*dn/dp
Definition Particles.hpp:99
virtual const std::vector< double > & get_pdens() const
Definition Particles.hpp:115
int get_cutoff_type() const
Definition Particles.hpp:105
virtual double av_gamma()
Definition Particles.cpp:41
virtual void differentiate()
Definition Particles.cpp:92
double mass_gr
particle mass in grams
Definition Particles.hpp:92
double mass_kev
same as above but in keV, using electrons as "reference"
Definition Particles.hpp:93
std::vector< double > ndens
array of number density per unit volume, per unit momentum
Definition Particles.hpp:96
virtual const std::vector< double > & get_p() const
Definition Particles.hpp:114
virtual void initialize_pdens()
Same as above but the other way around.
Definition Particles.cpp:68
virtual void set_cutoff_type(int t)
Definition Particles.hpp:106
virtual double count_particles_energy()
Definition Particles.cpp:25
virtual const std::vector< double > & get_gdens() const
Definition Particles.hpp:117
int cutoff_type
Definition Particles.hpp:101
virtual double count_particles()
Simple numerical integrals /w trapeze method.
Definition Particles.cpp:17
virtual double av_p()
Definition Particles.cpp:33
virtual const std::vector< double > & get_pdensp2_diff_logp() const
Definition Particles.hpp:118
virtual double av_gammasq()
Definition Particles.cpp:54
Definition BBody.hpp:5
CutoffType
Definition Particles.hpp:82
@ SuperExponential
Definition Particles.hpp:85
@ Sech2
Definition Particles.hpp:86
@ Exponential
Definition Particles.hpp:84
Structure used for GSL integration.
Definition Particles.hpp:14
int cutoff_type
Definition Particles.hpp:20
double m
Definition Particles.hpp:19
double s2
Definition Particles.hpp:16
double brk
Definition Particles.hpp:17
double max
Definition Particles.hpp:18
double s1
Definition Particles.hpp:15
Structure used for GSL integration.
Definition Particles.hpp:67
double s1
Definition Particles.hpp:68
double n
Definition Particles.hpp:73
double s2
Definition Particles.hpp:69
int cutoff_type
Definition Particles.hpp:74
double brk
Definition Particles.hpp:70
double m
Definition Particles.hpp:72
double max
Definition Particles.hpp:71
Structure used for GSL integration.
Definition Particles.hpp:50
double m
Definition Particles.hpp:54
double k
Definition Particles.hpp:52
double n
Definition Particles.hpp:53
double t
Definition Particles.hpp:51
Structure used for GSL integration.
Definition Particles.hpp:37
double m
Definition Particles.hpp:42
double t
Definition Particles.hpp:39
double max
Definition Particles.hpp:44
double npl
Definition Particles.hpp:41
double min
Definition Particles.hpp:43
double nth
Definition Particles.hpp:40
double s
Definition Particles.hpp:38
double cutoff
Definition Particles.hpp:45
int cutoff_type
Definition Particles.hpp:46
Structure used for GSL integration.
Definition Particles.hpp:58
double max
Definition Particles.hpp:62
double s
Definition Particles.hpp:59
int cutoff_type
Definition Particles.hpp:63
double m
Definition Particles.hpp:61
double n
Definition Particles.hpp:60
Structure used for GSL integration.
Definition Particles.hpp:31
double k
Definition Particles.hpp:33
double t
Definition Particles.hpp:32
Structure used for GSL integration.
Definition Particles.hpp:8
double n
Definition Particles.hpp:10
double s
Definition Particles.hpp:9
Structure used for GSL integration.
Definition Particles.hpp:24
double m
Definition Particles.hpp:27
double n
Definition Particles.hpp:26
double t
Definition Particles.hpp:25