1+ #include " kernels/QED_process.hpp"
2+
3+ #include " global.h"
4+ #include " enums.h"
5+ #include " utils/numeric.h"
6+
7+ #include " arch/kokkos_aliases.h"
8+
9+ #include " framework/containers/particles.h"
10+
11+ #include < Kokkos_Core.hpp>
12+
13+ #include < iostream>
14+ #include < fstream>
15+ #include < vector>
16+
17+ using namespace ntt ;
18+
19+ class init_particles {
20+ public:
21+ init_particles (Particles<Dim::_1D, Coord::Cart>& spec_, const real_t gamma_)
22+ : spec(spec_), gamma(gamma_) {}
23+
24+ const real_t u0 = math::sqrt(SQR(gamma) - ONE);
25+ void operator ()(index_t p) const {
26+ spec.ux1 (p) = u0;
27+ spec.ux2 (p) = 0.0 ;
28+ spec.ux3 (p) = 0.0 ;
29+ spec.weight (p) = 1.0 ;
30+ spec.i1 (p) = 0 ;
31+ spec.dx1 (p) = 0.0 ;
32+ spec.tag (p) = ParticleTag::alive;
33+ }
34+
35+ private:
36+ Particles<Dim::_1D, Coord::Cart>& spec;
37+ const real_t gamma;
38+ };
39+
40+
41+ auto main (int argc, char * argv[]) -> int {
42+ Kokkos::initialize (argc, argv);
43+
44+ try {
45+ Particles<Dim::_1D, Coord::Cart> electron (1 , " e-" , 1.0 , -1.0 , 100 , PrtlPusher::Boris, false , Cooling::None, 0 );
46+ Particles<Dim::_1D, Coord::Cart> photon (2 , " photon" , 0.0 , 0.0 , 1e8 , PrtlPusher::Boris, false , Cooling::None, 1 );
47+ using namespace kernel ::QED;
48+ const real_t e_min { 2.0 };
49+ const real_t gamma_emit { 1e4 };
50+ const real_t gamma_rad { 6.7e5 };
51+ const real_t gamma_pc { 7.2e7 };
52+ const real_t coeff { SQR (THREE / TWO) * constant::SQRT3 / constant::SQRT2 / constant::PI
53+ * math::sqrt (gamma_pc) * SQR (SQR (gamma_emit / gamma_rad) * gamma_emit) };
54+ const real_t rho { 1.0 };
55+ random_number_pool_t random_pool;
56+
57+ const real_t gamma { 1e6 };
58+
59+ init_particles init (electron, gamma);
60+ Kokkos::parallel_for (" InitParticles" , electron.npart (), init);
61+
62+ CurvatureEmission_kernel<Dim::_1D, Coord::Cart> curvature_emission (electron, photon, e_min, coeff, gamma_emit, rho, random_pool);
63+
64+ Kokkos::parallel_for (" CurvatureEmission" , electron.npart (), curvature_emission);
65+
66+ const size_t num_bins = 100 ;
67+ array_t <int *> energy_bins { " energy_bins" , num_bins };
68+ const real_t e_ph = CUBE (gamma / gamma_emit) / rho;
69+ const real_t min = math::log10 (e_min / e_ph);
70+ const real_t max = 1.0 ;
71+ const real_t dx = (max - min) / num_bins;
72+
73+
74+ Kokkos::parallel_for (" GenerateEnergyBins" , photon.npart (), KOKKOS_LAMBDA (index_t i) {
75+ if (photon.tag (i) != ParticleTag::alive) {
76+ return ;
77+ }
78+ const real_t en = math::log10 (spec.pld (i, 0 ) / e_ph);
79+ const index_t bin = (en - min) / dx;
80+ if (bin < 0 || bin >= num_bins) {
81+ printf (" bin %d out of range\n " , bin);
82+ return ;
83+ }
84+ energy_bins (bin) += 1 ;
85+ });
86+
87+ auto energy_bins_h = Kokkos::create_mirror_view (energy_bins);
88+ Kokkos::deep_copy (energy_bins_h, energy_bins);
89+
90+ auto bin_centers = std::vector<real_t >(num_bins);
91+ for (size_t i = 0 ; i < num_bins; ++i) {
92+ bin_centers[i] = math::pow (10.0 , min + (i + 0.5 ) * dx);
93+ }
94+
95+ std::fstream file;
96+ file.open (" energy_bins.dat" , std::ios::out);
97+ for (size_t i = 0 ; i < num_bins; ++i) {
98+ file << bin_centers[i] << " " << energy_bins_h (i) << std::endl;
99+ }
100+ file.close ();
101+
102+
103+ } catch (std::exception& e) {
104+ std::cerr << e.what () << std::endl;
105+ }
106+
107+ Kokkos::finalize ();
108+
109+ return 0 ;
110+ }
0 commit comments