Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
differentialFlux.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <array>
3#include <cmath>
4
5typedef double Real;
6constexpr static int productionNumAccEnergies = 60;
7constexpr static int productionNumTemperatures = 60;
8constexpr static int productionNumParticleEnergies = 100;
9constexpr static Real productionMinAccEnergy = 0.1; // keV
10constexpr static Real productionMaxAccEnergy = 100.; // keV
11constexpr static Real productionMinTemperature = 0.1; // keV
12constexpr static Real productionMaxTemperature = 100.; // keV
13
14static const Real kB = 1.380649e-23;
15static const Real CHARGE = 1.602176634e-19;
16static const Real MASS_ELECTRON = 9.1093837015e-31;
17
18std::array< Real, productionNumParticleEnergies+1 > particle_energy;
19std::array< Real, productionNumParticleEnergies > differentialFlux;
20
21
22int main(int argc, char** argv) {
23
24 if(argc < 3) {
25 std::cerr << "Syntax: differentialFlux <Density (1/m³)> <Temperature (K)>" << std::endl;
26 return 1;
27 }
28 Real rhon = atof(argv[1]);
29 Real T = atof(argv[2]);
30
31 // Energies of particles that sample the production array
32 // are logspace-distributed from 10^-1 to 10^2.3 keV
33 for(int e=0; e<productionNumParticleEnergies; e++) {
34 particle_energy[e] = pow(10.0, -1.+e*(2.3+1.)/(productionNumParticleEnergies-1));
35 }
37
38 Real tempenergy = kB * T / CHARGE / 1000;
39 Real accenergy = productionMinAccEnergy;
40 std::cerr << "# Temperature of " << T << " K == Thermal energy of " << tempenergy << " keV" << std::endl;
41
42 for(int p=0; p<productionNumParticleEnergies; p++) {
43 // TODO: Kappa distribution here? Now only going for maxwellian
44 Real energyparam = (particle_energy[p]-accenergy)/tempenergy;
45
46 if(particle_energy[p] > accenergy) {
47 Real deltaE = (particle_energy[p+1] - particle_energy[p])* 1e3*CHARGE; // dE in J
48
49 differentialFlux[p] = sqrt(1. / (2. * M_PI * MASS_ELECTRON))
50 * particle_energy[p] / tempenergy / sqrt(tempenergy * 1e3 *CHARGE)
51 * deltaE * exp(-energyparam);
52 } else {
53 differentialFlux[p] = 0;
54 }
55 }
56
57 std::cout << "#Energy (keV)\tFlux (1/m²/s)" << std::endl;
58 for(int p=0; p<productionNumParticleEnergies; p++) {
59 std::cout << particle_energy[p] << "\t" << rhon*differentialFlux[p] << std::endl;
60 }
61
62 return 0;
63}
sqrt(1.0+vA *vA/(c *c))) % Ion-acoustic wave cS
float Real
Definition definitions.h:41
static constexpr int productionNumTemperatures
static constexpr int productionNumParticleEnergies
static constexpr Real productionMinTemperature
static const Real MASS_ELECTRON
static constexpr Real productionMaxAccEnergy
static const Real kB
std::array< Real, productionNumParticleEnergies+1 > particle_energy
static constexpr int productionNumAccEnergies
static constexpr Real productionMaxTemperature
static const Real CHARGE
std::array< Real, productionNumParticleEnergies > differentialFlux
static constexpr Real productionMinAccEnergy
int main()