-
Notifications
You must be signed in to change notification settings - Fork 0
/
DispReln.h
450 lines (386 loc) · 13.7 KB
/
DispReln.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
#ifndef DISPRELN_H
#define DISPRELN_H
#define __STDCPP_WANT_MATH_SPEC_FUNCS__ 1
#include <boost/math/constants/constants.hpp>
#include <cmath>
#include <complex>
#include <list>
#include <vector>
#include "ExpBessel.h"
namespace DispReln {
using Real = double;
using Complex = std::complex<double>;
std::complex<double> Z( std::complex<double> xi );
std::complex<double> AcousticDisp( std::complex<double> xi, double ZoverTau );
template<unsigned int> std::complex<double> Zeta( std::complex<double> xi );
template<unsigned int,unsigned int,unsigned int> double Gamma( double );
template<> double inline Gamma<1,0,0>( double alpha )
{
return ExpBessel<0>( alpha );
}
template<> double inline Gamma<2,1,0>( double alpha )
{
return ExpBessel<0>( alpha ) - ExpBessel<1>( alpha );
}
template<> double inline Gamma<3,0,0>( double alpha )
{
return ExpBessel<0>( alpha ) + alpha * ( ExpBessel<1>( alpha ) - ExpBessel<0>( alpha ) );
}
template<> double inline Gamma<3,1,1>( double alpha )
{
return 2.0*( ExpBessel<0>( alpha ) - ExpBessel<1>( alpha ) );
}
template<> double inline Gamma<4,1,0>( double alpha )
{
return ( 2.0*( 1.0 - alpha )*ExpBessel<0>( alpha ) - ( 1.0 - 2.0*alpha ) * ExpBessel<1>( alpha ) );
}
template<> double inline Gamma<5,1,1>( double alpha )
{
return 2.0 * ( ( 3.0 - 2.0*alpha )*ExpBessel<0>( alpha ) - 2.0*( 1.0 - alpha )*ExpBessel<1>( alpha ) );
}
// General Gamma<l,m,n> can be done if you have a generalized hypergeometric pFq
// evaluator.
template<unsigned int l,unsigned int m,unsigned int n> double Gamma( double alpha ) { throw std::logic_error( "Unimplemented!" );}
template<> std::complex<double> inline Zeta<0>( std::complex<double> xi )
{
return Z( xi );
}
template<> std::complex<double> inline Zeta<1>( std::complex<double> xi )
{
return 1.0 + xi*Z( xi );
}
template<> std::complex<double> inline Zeta<2>( std::complex<double> xi )
{
return xi*( 1.0 + xi*Z( xi ) );
}
template<unsigned int l> inline std::complex<double> Zeta( std::complex<double> xi )
{
if ( l % 2 == 0 )
return xi*Zeta<l-1>( xi );
else
return xi*Zeta<l-1>( xi ) + std::tgamma( ( l )/2.0 )/boost::math::double_constants::root_pi;
}
struct Species {
double Temperature; // Relative to a fiducial reference temperature.
double Density; // Relative to a fiducial reference density.
double Z; // Charge in units of the elemental charge (electrons have Z = -1)
double mass; // Relative to a fiducial mass.
double fprim; // a/L_n , positive for centrally peaked profiles
double tprim; // a/L_T , positive for centrally peaked profiles
double rho; // rho_s in terms of rho_ref
Species( double T_in, double Dens_in, double Z_in, double mass_in, double fprim_in, double tprim_in ) :
Temperature( T_in ), Density( Dens_in ), Z( Z_in ), mass( mass_in ), fprim( fprim_in ), tprim( tprim_in )
{
rho = ::sqrt( Temperature * mass )/Z;
}
// Copy constructor
Species( Species const& other ) :
Temperature( other.Temperature ), Density( other.Density ), Z( other.Z ), mass( other.mass ), fprim( other.fprim ),
tprim( other.tprim ), rho( other.rho )
{
rho = ::sqrt( Temperature * mass )/::abs( Z );
};
};
class ElectrostaticSlab {
public:
ElectrostaticSlab( std::list<Species> const & spec_list )
{
SpeciesList.clear();
for ( auto i : spec_list )
SpeciesList.emplace_back( i );
_kpar = 1.0; _kx=0; _ky=0;
recalculate();
}
ElectrostaticSlab( std::vector<Species> const & spec_list )
{
SpeciesList.clear();
for ( auto i : spec_list )
SpeciesList.emplace_back( i );
_kpar = 1.0; _kx=0; _ky=0;
recalculate();
}
ElectrostaticSlab( std::initializer_list<Species> const & spec_list )
{
SpeciesList.clear();
for ( auto i : spec_list )
SpeciesList.emplace_back( i );
_kpar = 1.0; _kx=0; _ky=0;
recalculate();
}
Complex operator()( Complex xi )
{
// _ky & _kx come normalized to rho_ref
// k_|| normalized to a;
Complex D( 0.0, 0.0 );
for ( auto x : SpeciesList )
{
if ( x.s.mass == 0.0 )
{
D += x.boltz;
continue;
}
Complex xi_s = x.vt*xi;
D += ( x.boltz )*( 1.0 + ( xi_s - x.om_star + 1.5*x.om_star_t )*Zeta<0>( xi_s )*Gamma<1,0,0>( x.alpha )
- x.om_star_t*( Zeta<0>( xi_s )*Gamma<3,0,0>( x.alpha ) + Zeta<2>( xi_s )*Gamma<1,0,0>( x.alpha ) ) );
// D += ( x.boltz )*( 1.0 + ( xi_s - x.om_star )*Zeta<0>( xi_s )*Gamma<1,0,0>( x.alpha ) );
}
return D;
}
void set_kpar( double kp ){_kpar = kp;recalculate();};
void set_kx( double kx ){_kx= kx;recalculate();};
void set_ky( double ky ){_ky= ky;recalculate();};
void set_beta( double /* beta */ ) {};
double get_kpar(){return _kpar;};
double get_kx(){return _kx;};
double get_ky(){return _ky;};
struct _species {
DispReln::Species s;
Real om_star,om_star_t,alpha;
Real vt,boltz;
_species( Species const& s_in ) : s( s_in ),om_star( 0.0 ),om_star_t( 0.0 ),alpha( 0.0 )
{
vt = ::sqrt( s_in.mass/s_in.Temperature );
boltz = s_in.Z*s_in.Z*s_in.Density / s_in.Temperature;
};
_species( _species const& _s_in ) : s( _s_in.s ), om_star( _s_in.om_star ), om_star_t( _s_in.om_star_t ), alpha( _s_in.alpha )
{
vt = ::sqrt( _s_in.s.mass/_s_in.s.Temperature );
boltz = _s_in.s.Z*_s_in.s.Z*_s_in.s.Density / _s_in.s.Temperature;
};
};
void recalculate()
{
for ( auto &x : SpeciesList )
{
x.s.rho = ::sqrt( x.s.Temperature * x.s.mass )/::abs( x.s.Z );
x.vt = ::sqrt( x.s.mass / x.s.Temperature );
x.boltz = x.s.Z * x.s.Z * x.s.Density / x.s.Temperature;
x.om_star = -1.0 * ( x.s.Z / ::abs ( x.s.Z ) )*0.5 * _ky * ( x.s.rho ) * x.s.fprim / _kpar;
x.om_star_t = -1.0 * ( x.s.Z / ::abs ( x.s.Z ) )*0.5 * _ky * ( x.s.rho ) * x.s.tprim / _kpar;
x.alpha = ( _ky*_ky + _kx*_kx )*( x.s.rho * x.s.rho )/2.0;
}
}
std::vector<_species> SpeciesList;
ElectrostaticSlab( ElectrostaticSlab const &other )
: SpeciesList( other.SpeciesList )
{
_kpar = other._kpar; _kx = other._kx; _ky = other._ky;
recalculate();
};
ElectrostaticSlab()
{
SpeciesList.clear();
_kpar = 0.0;
_ky = 0.0;
_kx = 0.0;
};
protected:
double _kpar,_kx,_ky;
};
class GKSlab {
public:
GKSlab( std::list<Species> const & spec_list, double beta )
{
SpeciesList.clear();
for ( auto i : spec_list )
SpeciesList.emplace_back( i );
_kpar = 1.0; _kx=0; _ky=0;
beta_ref = beta;
recalculate();
}
GKSlab( std::vector<Species> const & spec_list, double beta )
{
SpeciesList.clear();
for ( auto i : spec_list )
SpeciesList.emplace_back( i );
_kpar = 1.0; _kx=0; _ky=0;
beta_ref = beta;
recalculate();
}
GKSlab( std::initializer_list<Species> const & spec_list, double beta )
{
SpeciesList.clear();
for ( auto i : spec_list )
SpeciesList.emplace_back( i );
_kpar = 1.0; _kx=0; _ky=0;
beta_ref = beta;
recalculate();
}
Complex operator()( Complex xi )
{
// _ky & _kx come normalized to rho_ref
// k_|| normalized to a;
Complex A( 0.0, 0.0 ),B( 0.0, 0.0 ),C( 0.0, 0.0 ),D( 0.0,0.0 ),E( 0.0, 0.0 );
for ( auto x : SpeciesList )
{
Complex xi_s = x.vt*xi;
double om_kappa = x.om_star - 1.5*x.om_star_t;
double om_eta = x.om_star_t;
A += ( x.boltz )*( 1.0 + ( xi_s - om_kappa )*Zeta<0>( xi_s )*Gamma<1,0,0>( x.alpha ) - om_eta*( Zeta<0>( xi_s )*Gamma<3,0,0>( x.alpha ) + Zeta<2>( xi_s )*Gamma<1,0,0>( x.alpha ) ) );
B += ( x.boltz/x.vt ) * ( xi_s - ( xi_s - om_kappa )*Gamma<1,0,0>( x.alpha ) + om_eta*( Gamma<3,0,0>( x.alpha ) + 0.5*Gamma<1,0,0>( x.alpha ) ) );
C += ( x.s.Z * x.s.Density ) * ( ( xi_s - om_kappa )*Zeta<0>( xi_s )*Gamma<2,1,0>( x.alpha ) - om_eta*( Zeta<0>( xi_s )*Gamma<4,1,0>( x.alpha ) + Zeta<2>( xi_s )*Gamma<2,1,0>( x.alpha ) ) );
D += ( x.s.Temperature * x.s.Density ) * ( ( xi_s - om_kappa )*Zeta<0>( xi_s )*Gamma<3,1,1>( x.alpha ) - om_eta*( Zeta<0>( xi_s )*Gamma<5,1,1>( x.alpha ) + Zeta<2>( xi_s )*Gamma<3,1,1>( x.alpha ) ) );
E += ( x.s.Z/x.vt ) * ( ( xi_s - om_kappa )*Gamma<2,1,0>( x.alpha ) - om_eta*( Gamma<4,1,0>( x.alpha ) + 0.5*Gamma<2,1,0>( x.alpha ) ) );
/*
A += ( x.boltz )*( 1.0 + xi_s*Zeta<0>( xi_s )*Gamma<1,0,0>( x.alpha ) );
B += ( x.boltz/x.vt ) * ( xi_s - xi_s*Gamma<1,0,0>( x.alpha ) );
C += ( x.s.Z * x.s.Density ) * ( xi_s*Zeta<0>( xi_s )*Gamma<2,1,0>( x.alpha ) );
D += ( x.s.Temperature * x.s.Density ) * ( xi_s*Zeta<0>( xi_s )*Gamma<3,1,1>( x.alpha ) );
E += ( x.s.Z/x.vt ) * ( xi_s* Gamma<2,1,0>( x.alpha ) );
*/
}
return ( A*alpha_ref/( beta_ref ) - xi*A*B + B*B )*( 2.0*A/beta_ref - A*D + C*C) - (A*E + B*C)*(A*E + B*C);
}
void set_kpar( double kp ){_kpar = kp;recalculate();};
void set_kx( double kx ){_kx= kx;recalculate();};
void set_ky( double ky ){_ky= ky;recalculate();};
double get_kpar(){return _kpar;};
double get_kx(){return _kx;};
double get_ky(){return _ky;};
struct _species {
DispReln::Species s;
Real om_star,om_star_t,alpha;
Real vt,boltz;
_species( Species const& s_in ) : s( s_in ),om_star( 0.0 ),om_star_t( 0.0 ),alpha( 0.0 )
{
vt = ::sqrt( s_in.mass/s_in.Temperature );
boltz = s_in.Z*s_in.Z*s_in.Density / s_in.Temperature;
};
_species( _species const& _s_in ) : s( _s_in.s ), om_star( _s_in.om_star ), om_star_t( _s_in.om_star_t ), alpha( _s_in.alpha )
{
vt = ::sqrt( _s_in.s.mass/_s_in.s.Temperature );
boltz = _s_in.s.Z*_s_in.s.Z*_s_in.s.Density / _s_in.s.Temperature;
};
};
void recalculate()
{
alpha_ref = ( _ky*_ky + _kx*_kx )/2.0;
for ( auto &x : SpeciesList )
{
x.vt = ::sqrt( x.s.mass / x.s.Temperature );
x.s.rho = ::sqrt( x.s.Temperature * x.s.mass )/::abs( x.s.Z );
x.om_star = ( x.s.Z / ::abs ( x.s.Z ) )*0.5 * _ky * ( x.s.rho ) * x.s.fprim / _kpar;
x.om_star_t = ( x.s.Z / ::abs ( x.s.Z ) )*0.5 * _ky * ( x.s.rho ) * x.s.tprim / _kpar;
x.alpha = ( alpha_ref )*( x.s.rho * x.s.rho );
x.boltz = x.s.Z * x.s.Z * x.s.Density / x.s.Temperature;
}
}
std::vector<_species> SpeciesList;
GKSlab( GKSlab const &other )
: SpeciesList( other.SpeciesList )
{
_kpar = other._kpar; _kx = other._kx; _ky = other._ky;
beta_ref = other.beta_ref;
recalculate();
};
GKSlab()
{
SpeciesList.clear();
_kpar = 0.0;
_ky = 0.0;
_kx = 0.0;
beta_ref = 0.0;
};
double beta_ref;
void set_beta( double beta ) { beta_ref = beta;};
protected:
double _kpar,_kx,_ky;
double alpha_ref;
};
class EdgeSlab {
public:
EdgeSlab( std::list<Species> const & spec_list, double beta )
{
SpeciesList.clear();
for ( auto i : spec_list )
SpeciesList.emplace_back( i );
_kpar = 1.0; _kx=0; _ky=0;
beta_ref = beta;
recalculate();
}
EdgeSlab( std::vector<Species> const & spec_list, double beta )
{
SpeciesList.clear();
for ( auto i : spec_list )
SpeciesList.emplace_back( i );
_kpar = 1.0; _kx=0; _ky=0;
beta_ref = beta;
recalculate();
}
EdgeSlab( std::initializer_list<Species> const & spec_list, double beta )
{
SpeciesList.clear();
for ( auto i : spec_list )
SpeciesList.emplace_back( i );
_kpar = 1.0; _kx=0; _ky=0;
beta_ref = beta;
recalculate();
}
Complex operator()( Complex xi )
{
// _ky & _kx come normalized to rho_ref
// k_|| normalized to a;
Complex A( 0.0, 0.0 ),B( 0.0, 0.0 );
for ( auto x : SpeciesList )
{
Complex xi_s = x.vt*xi;
A += ( x.boltz )*( 1.0 + ( xi_s - x.om_star + 1.5*x.om_star_t )*Zeta<0>( xi_s )*Gamma<1,0,0>( x.alpha ) - x.om_star_t*( Zeta<0>( xi_s )*Gamma<3,0,0>( x.alpha ) + Zeta<2>( xi_s )*Gamma<1,0,0>( x.alpha ) ) );
B += ( x.boltz/x.vt ) * ( xi_s - ( xi_s - x.om_star + 1.5*x.om_star_t )*Gamma<1,0,0>( x.alpha ) + x.om_star_t*( Gamma<3,0,0>( x.alpha ) + 0.5*Gamma<1,0,0>( x.alpha ) ) );
}
return ( A*alpha_ref/( xi*xi*beta_ref ) - A*B + B*B );
}
void set_kpar( double kp ){_kpar = kp;recalculate();};
void set_kx( double kx ){_kx= kx;recalculate();};
void set_ky( double ky ){_ky= ky;recalculate();};
struct _species {
DispReln::Species s;
Real om_star,om_star_t,alpha;
Real vt,boltz;
_species( Species const& s_in ) : s( s_in ),om_star( 0.0 ),om_star_t( 0.0 ),alpha( 0.0 )
{
vt = ::sqrt( s_in.mass/s_in.Temperature );
boltz = s_in.Z*s_in.Z*s_in.Density / s_in.Temperature;
};
_species( _species const& _s_in ) : s( _s_in.s ), om_star( _s_in.om_star ), om_star_t( _s_in.om_star_t ), alpha( _s_in.alpha )
{
vt = ::sqrt( _s_in.s.mass/_s_in.s.Temperature );
boltz = _s_in.s.Z*_s_in.s.Z*_s_in.s.Density / _s_in.s.Temperature;
};
};
void recalculate()
{
alpha_ref = ( _ky*_ky + _kx*_kx )/2.0;
for ( auto &x : SpeciesList )
{
x.s.rho = ::sqrt( x.s.Temperature * x.s.mass )/::abs( x.s.Z );
x.om_star = ( x.s.Z / ::abs ( x.s.Z ) )*0.5 * _ky * x.s.rho * x.s.fprim / _kpar;
x.om_star_t = ( x.s.Z / ::abs ( x.s.Z ) )*0.5 * _ky * x.s.rho * x.s.tprim / _kpar;
x.alpha = alpha_ref*( x.s.rho * x.s.rho );
x.vt = ::sqrt( x.s.mass / x.s.Temperature );
x.boltz = x.s.Z * x.s.Z * x.s.Density / x.s.Temperature;
}
}
std::vector<_species> SpeciesList;
EdgeSlab( EdgeSlab const &other )
: SpeciesList( other.SpeciesList )
{
_kpar = other._kpar; _kx = other._kx; _ky = other._ky;
beta_ref = other.beta_ref;
recalculate();
};
EdgeSlab()
{
SpeciesList.clear();
_kpar = 0.0;
_ky = 0.0;
_kx = 0.0;
beta_ref = 0.0;
};
double beta_ref;
void set_beta( double beta ) { beta_ref = beta;};
protected:
double _kpar,_kx,_ky;
double alpha_ref;
};
}
#endif // DISPRELN_H