Skip to content

Commit 8a4e0d8

Browse files
add test for curvature emission kernel
1 parent 271afa4 commit 8a4e0d8

2 files changed

Lines changed: 113 additions & 3 deletions

File tree

src/kernels/QED_process.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ namespace kernel::QED{
6060
}
6161

6262
void operator()(index_t p) const{
63-
if(tag(p) != ParticleTag::alive){
64-
if(tag(p) != ParticleTag::dead){
63+
if(sepc.tag(p) != ParticleTag::alive){
64+
if(spec.tag(p) != ParticleTag::dead){
6565
raise::KernelError(HERE, "Invalid particle tag in pusher");
6666
}
6767
return;
@@ -79,7 +79,7 @@ namespace kernel::QED{
7979
auto rand_gen = random_pool.get_state();
8080

8181
spec_ph.ux1(n_ph + i) = SIGN(spec.ux1(p)) * ONE;
82-
spec_ph.pld(n_ph + i) = inverseCDF(CDF(zeta) * Random<real_t>(rand_gen))
82+
spec_ph.pld(n_ph + i, 0) = inverseCDF(CDF(zeta) * Random<real_t>(rand_gen))
8383
* CUBE(pp / gamma_emit) / rho;
8484
spec_ph.i1(n_ph + i) = spec.i1(p);
8585
spec_ph.dx1(n_ph + i) = spec.dx1(p);

src/kernels/tests/QED_process.cpp

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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

Comments
 (0)