Skip to content

Commit cd1470a

Browse files
Merge branch '1.2.0rc' into pgen/BZjet
2 parents fe9694e + 429bc94 commit cd1470a

19 files changed

Lines changed: 64 additions & 62 deletions

File tree

pgens/accretion/pgen.hpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ namespace user {
4040
metric.template h_<1, 1>(x_Cd) * metric.beta1(x_Cd) *
4141
metric.beta1(x_Cd) };
4242
return HALF * (metric.template h_<1, 3>(x_Cd) * metric.beta1(x_Cd) +
43-
TWO * metric.spin() * g_00);
43+
TWO * metric.spin() * (g_00 + ONE));
44+
4445
}
4546

46-
Inline auto bx1(const coord_t<D>& x_Ph) const -> real_t { // at ( i , j + HALF )
47+
Inline auto bx1(const coord_t<D>& x_Ph) const
48+
-> real_t { // at ( i , j + HALF )
4749
coord_t<D> xi { ZERO }, x0m { ZERO }, x0p { ZERO };
4850
metric.template convert<Crd::Ph, Crd::Cd>(x_Ph, xi);
4951

@@ -61,7 +63,8 @@ namespace user {
6163
}
6264
}
6365

64-
Inline auto bx2(const coord_t<D>& x_Ph) const -> real_t { // at ( i + HALF , j )
66+
Inline auto bx2(const coord_t<D>& x_Ph) const
67+
-> real_t { // at ( i + HALF , j )
6568
coord_t<D> xi { ZERO }, x0m { ZERO }, x0p { ZERO };
6669
metric.template convert<Crd::Ph, Crd::Cd>(x_Ph, xi);
6770

@@ -79,7 +82,20 @@ namespace user {
7982
}
8083

8184
Inline auto bx3(const coord_t<D>& x_Ph) const -> real_t {
82-
return ZERO;
85+
coord_t<D> xi { ZERO }, x0m { ZERO }, x0p { ZERO };
86+
metric.template convert<Crd::Ph, Crd::Cd>(x_Ph, xi);
87+
88+
x0m[0] = xi[0];
89+
x0m[1] = xi[1] - HALF * m_eps;
90+
x0p[0] = xi[0];
91+
x0p[1] = xi[1] + HALF * m_eps;
92+
93+
real_t inv_sqrt_detH_ijP { ONE / metric.sqrt_det_h({ xi[0], xi[1] }) };
94+
if (cmp::AlmostZero(x_Ph[1])) {
95+
return ZERO;
96+
} else {
97+
return -(A_1(x0p) - A_1(x0m)) * inv_sqrt_detH_ijP / m_eps;
98+
}
8399
}
84100

85101
Inline auto dx1(const coord_t<D>& x_Ph) const -> real_t {
@@ -174,7 +190,7 @@ namespace user {
174190
return false;
175191
}
176192

177-
Inline auto operator()(const coord_t<M::Dim>& x_Ph) const -> real_t override {
193+
Inline auto operator()(const coord_t<M::Dim>& x_Ph) const -> real_t {
178194
auto fill = true;
179195
for (auto d = 0u; d < M::Dim; ++d) {
180196
fill &= x_Ph[d] > x_min[d] and x_Ph[d] < x_max[d] and sigma_crit(x_Ph);

pgens/reconnection/pgen.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace user {
2828
, center_x { center_x }
2929
, cs_y { cs_y } {}
3030

31-
Inline auto operator()(const coord_t<M::Dim>& x_Ph) const -> real_t override {
31+
Inline auto operator()(const coord_t<M::Dim>& x_Ph) const -> real_t {
3232
return ONE / SQR(math::cosh((x_Ph[1] - cs_y) / cs_width)) *
3333
(ONE - math::exp(-SQR((x_Ph[0] - center_x) / cs_width)));
3434
}

src/archetypes/energy_dist.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,6 @@ namespace arch {
4040

4141
EnergyDistribution(const M& metric) : metric { metric } {}
4242

43-
// Takes the physical coordinate of the particle and returns
44-
// the velocity in tetrad basis
45-
// last argument -- is the species index (1, ..., nspec)
46-
Inline virtual void operator()(const coord_t<D>&,
47-
vec_t<Dim::_3D>& v,
48-
spidx_t = 0) const {
49-
v[0] = ZERO;
50-
v[1] = ZERO;
51-
v[2] = ZERO;
52-
}
53-
5443
protected:
5544
const M metric;
5645
};
@@ -61,7 +50,8 @@ namespace arch {
6150

6251
Inline void operator()(const coord_t<M::Dim>&,
6352
vec_t<Dim::_3D>& v,
64-
spidx_t = 0) const override {
53+
spidx_t = 0) const {
54+
6555
v[0] = ZERO;
6656
v[1] = ZERO;
6757
v[2] = ZERO;
@@ -85,7 +75,7 @@ namespace arch {
8575

8676
Inline void operator()(const coord_t<M::Dim>&,
8777
vec_t<Dim::_3D>& v,
88-
spidx_t = 0) const override {
78+
spidx_t = 0) const {
8979
auto rand_gen = pool.get_state();
9080
auto rand_X1 = Random<real_t>(rand_gen);
9181
auto rand_gam = ONE;
@@ -241,7 +231,7 @@ namespace arch {
241231

242232
Inline void operator()(const coord_t<M::Dim>&,
243233
vec_t<Dim::_3D>& v,
244-
spidx_t sp = 0) const override {
234+
spidx_t sp = 0) const {
245235
SampleFromMaxwellian<S, M::CoordType == Coord::Cart>(v,
246236
pool,
247237
temperature,
@@ -293,7 +283,7 @@ namespace arch {
293283

294284
Inline void operator()(const coord_t<M::Dim>&,
295285
vec_t<Dim::_3D>& v,
296-
spidx_t sp = 0) const override {
286+
spidx_t sp = 0) const {
297287
SampleFromMaxwellian<S, M::CoordType == Coord::Cart>(
298288
v,
299289
pool,
@@ -367,7 +357,7 @@ namespace arch {
367357

368358
Inline void operator()(const coord_t<M::Dim>& x_Code,
369359
vec_t<Dim::_3D>& v,
370-
spidx_t = 0) const override {
360+
spidx_t = 0) const {
371361
if (cmp::AlmostZero(temperature)) {
372362
v[0] = ZERO;
373363
v[1] = ZERO;

src/archetypes/spatial_dist.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ namespace arch {
3232

3333
SpatialDistribution(const M& metric) : metric { metric } {}
3434

35-
Inline virtual auto operator()(const coord_t<M::Dim>&) const -> real_t {
36-
return ONE;
37-
}
38-
3935
protected:
4036
const M metric;
4137
};
@@ -44,7 +40,7 @@ namespace arch {
4440
struct Uniform : public SpatialDistribution<S, M> {
4541
Uniform(const M& metric) : SpatialDistribution<S, M> { metric } {}
4642

47-
Inline auto operator()(const coord_t<M::Dim>&) const -> real_t override {
43+
Inline auto operator()(const coord_t<M::Dim>&) const -> real_t {
4844
return ONE;
4945
}
5046
};
@@ -69,7 +65,7 @@ namespace arch {
6965
, target_density { target_density }
7066
, target_max_density { target_max_density } {}
7167

72-
Inline auto operator()(const coord_t<M::Dim>& x_Ph) const -> real_t override {
68+
Inline auto operator()(const coord_t<M::Dim>& x_Ph) const -> real_t {
7369
coord_t<M::Dim> x_Cd { ZERO };
7470
metric.template convert<Crd::Ph, Crd::Cd>(x_Ph, x_Cd);
7571
real_t dens { ZERO };

src/archetypes/tests/spatial_dist.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct RadialDist : public SpatialDistribution<S, M> {
7676

7777
RadialDist(const M& metric) : SpatialDistribution<S, M> { metric } {}
7878

79-
Inline auto operator()(const coord_t<M::Dim>& x_Code) const -> real_t override {
79+
auto operator()(const coord_t<M::Dim>& x_Code) const -> real_t {
8080
coord_t<M::Dim> x_Sph { ZERO };
8181
metric.template convert<Crd::Cd, Crd::Sph>(x_Code, x_Sph);
8282
auto r { ZERO };
@@ -123,4 +123,4 @@ auto main(int argc, char* argv[]) -> int {
123123
}
124124
Kokkos::finalize();
125125
return 0;
126-
}
126+
}

src/global/utils/error.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ namespace raise {
101101
const char* func,
102102
int line,
103103
const char* msg) {
104-
printf("\n%s:%d @ %s\nError: %s", file, line, func, msg);
104+
Kokkos::printf("\n%s:%d @ %s\nError: %s", file, line, func, msg);
105105
Kokkos::abort("kernel error");
106106
}
107107

108108
Inline void KernelNotImplementedError(const char* file, const char* func, int line) {
109-
printf("\n%s:%d @ %s\n", file, line, func);
109+
Kokkos::printf("\n%s:%d @ %s\n", file, line, func);
110110
Kokkos::abort("kernel not implemented");
111111
}
112112

src/kernels/tests/ampere_mink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void errorIf(bool condition, const std::string& message) {
2525

2626
Inline auto equal(real_t a, real_t b, const char* msg, real_t acc) -> bool {
2727
if (not(math::abs(a - b) < acc)) {
28-
printf("%.12e != %.12e [%.12e] %s\n", a, b, math::abs(a - b), msg);
28+
Kokkos::printf("%.12e != %.12e [%.12e] %s\n", a, b, math::abs(a - b), msg);
2929
return false;
3030
}
3131
return true;

src/kernels/tests/deposit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const real_t eps = std::is_same_v<real_t, double> ? (real_t)(1e-6)
3232

3333
Inline auto equal(real_t a, real_t b, const char* msg, real_t eps) -> bool {
3434
if ((a - b) >= eps * math::max(math::fabs(a), math::fabs(b))) {
35-
printf("%.12e != %.12e %s\n", a, b, msg);
36-
printf("%.12e >= %.12e %s\n",
35+
Kokkos::printf("%.12e != %.12e %s\n", a, b, msg);
36+
Kokkos::printf("%.12e >= %.12e %s\n",
3737
a - b,
3838
eps * math::max(math::fabs(a), math::fabs(b)),
3939
msg);

src/kernels/tests/faraday_mink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void errorIf(bool condition, const std::string& message) {
2525

2626
Inline auto equal(real_t a, real_t b, const char* msg, real_t acc) -> bool {
2727
if (not(math::abs(a - b) < acc)) {
28-
printf("%.12e != %.12e [%.12e] %s\n", a, b, math::abs(a - b), msg);
28+
Kokkos::printf("%.12e != %.12e [%.12e] %s\n", a, b, math::abs(a - b), msg);
2929
return false;
3030
}
3131
return true;

src/kernels/tests/flds_bc.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct DummyFieldsBCs {
4848

4949
Inline auto equal(real_t a, real_t b, const char* msg, real_t acc) -> bool {
5050
if (not(math::abs(a - b) < acc)) {
51-
printf("%.12e != %.12e [%.12e] %s\n", a, b, math::abs(a - b), msg);
51+
Kokkos::printf("%.12e != %.12e [%.12e] %s\n", a, b, math::abs(a - b), msg);
5252
return false;
5353
}
5454
return true;
@@ -118,19 +118,19 @@ void testFldsBCs(const std::vector<std::size_t>& res) {
118118
FOUR * math::abs(x + HALF - xg_edge) / dx_abs);
119119
const auto factor2 = math::tanh(FOUR * math::abs(x - xg_edge) / dx_abs);
120120
if (not cmp::AlmostEqual(flds(i1, em::ex1), TWO * (ONE - factor1))) {
121-
printf("%f != %f\n", flds(i1, em::ex1), TWO * (ONE - factor1));
121+
Kokkos::printf("%f != %f\n", flds(i1, em::ex1), TWO * (ONE - factor1));
122122
raise::KernelError(HERE, "incorrect ex1");
123123
}
124124
if (not cmp::AlmostEqual(flds(i1, em::ex2), THREE * (ONE - factor2))) {
125-
printf("%f != %f\n", flds(i1, em::ex2), THREE * (ONE - factor2));
125+
Kokkos::printf("%f != %f\n", flds(i1, em::ex2), THREE * (ONE - factor2));
126126
raise::KernelError(HERE, "incorrect ex2");
127127
}
128128
if (not cmp::AlmostEqual(flds(i1, em::bx2), FOUR * (ONE - factor1))) {
129-
printf("%f != %f\n", flds(i1, em::bx2), FOUR * (ONE - factor1));
129+
Kokkos::printf("%f != %f\n", flds(i1, em::bx2), FOUR * (ONE - factor1));
130130
raise::KernelError(HERE, "incorrect bx2");
131131
}
132132
if (not cmp::AlmostEqual(flds(i1, em::bx3), FIVE * (ONE - factor1))) {
133-
printf("%f != %f\n", flds(i1, em::bx3), FIVE * (ONE - factor1));
133+
Kokkos::printf("%f != %f\n", flds(i1, em::bx3), FIVE * (ONE - factor1));
134134
raise::KernelError(HERE, "incorrect bx3");
135135
}
136136
});
@@ -145,19 +145,19 @@ void testFldsBCs(const std::vector<std::size_t>& res) {
145145
FOUR * math::abs(x + HALF - xg_edge) / dx_abs);
146146
const auto factor2 = math::tanh(FOUR * math::abs(x - xg_edge) / dx_abs);
147147
if (not cmp::AlmostEqual(flds(i1, i2, em::ex1), TWO * (ONE - factor1))) {
148-
printf("%f != %f\n", flds(i1, i2, em::ex1), TWO * (ONE - factor1));
148+
Kokkos::printf("%f != %f\n", flds(i1, i2, em::ex1), TWO * (ONE - factor1));
149149
raise::KernelError(HERE, "incorrect ex1");
150150
}
151151
if (not cmp::AlmostEqual(flds(i1, i2, em::ex2), THREE * (ONE - factor2))) {
152-
printf("%f != %f\n", flds(i1, i2, em::ex2), THREE * (ONE - factor2));
152+
Kokkos::printf("%f != %f\n", flds(i1, i2, em::ex2), THREE * (ONE - factor2));
153153
raise::KernelError(HERE, "incorrect ex2");
154154
}
155155
if (not cmp::AlmostEqual(flds(i1, i2, em::bx2), FOUR * (ONE - factor1))) {
156-
printf("%f != %f\n", flds(i1, i2, em::bx2), FOUR * (ONE - factor1));
156+
Kokkos::printf("%f != %f\n", flds(i1, i2, em::bx2), FOUR * (ONE - factor1));
157157
raise::KernelError(HERE, "incorrect bx2");
158158
}
159159
if (not cmp::AlmostEqual(flds(i1, i2, em::bx3), FIVE * (ONE - factor1))) {
160-
printf("%f != %f\n", flds(i1, i2, em::bx3), FIVE * (ONE - factor1));
160+
Kokkos::printf("%f != %f\n", flds(i1, i2, em::bx3), FIVE * (ONE - factor1));
161161
raise::KernelError(HERE, "incorrect bx3");
162162
}
163163
});
@@ -173,22 +173,22 @@ void testFldsBCs(const std::vector<std::size_t>& res) {
173173
FOUR * math::abs(x + HALF - xg_edge) / dx_abs);
174174
const auto factor2 = math::tanh(FOUR * math::abs(x - xg_edge) / dx_abs);
175175
if (not cmp::AlmostEqual(flds(i1, i2, i3, em::ex1), TWO * (ONE - factor1))) {
176-
printf("%f != %f\n", flds(i1, i2, i3, em::ex1), TWO * (ONE - factor1));
176+
Kokkos::printf("%f != %f\n", flds(i1, i2, i3, em::ex1), TWO * (ONE - factor1));
177177
raise::KernelError(HERE, "incorrect ex1");
178178
}
179179
if (not cmp::AlmostEqual(flds(i1, i2, i3, em::ex2),
180180
THREE * (ONE - factor2))) {
181-
printf("%f != %f\n", flds(i1, i2, i3, em::ex2), THREE * (ONE - factor2));
181+
Kokkos::printf("%f != %f\n", flds(i1, i2, i3, em::ex2), THREE * (ONE - factor2));
182182
raise::KernelError(HERE, "incorrect ex2");
183183
}
184184
if (not cmp::AlmostEqual(flds(i1, i2, i3, em::bx2),
185185
FOUR * (ONE - factor1))) {
186-
printf("%f != %f\n", flds(i1, i2, i3, em::bx2), FOUR * (ONE - factor1));
186+
Kokkos::printf("%f != %f\n", flds(i1, i2, i3, em::bx2), FOUR * (ONE - factor1));
187187
raise::KernelError(HERE, "incorrect bx2");
188188
}
189189
if (not cmp::AlmostEqual(flds(i1, i2, i3, em::bx3),
190190
FIVE * (ONE - factor1))) {
191-
printf("%f != %f\n", flds(i1, i2, i3, em::bx3), FIVE * (ONE - factor1));
191+
Kokkos::printf("%f != %f\n", flds(i1, i2, i3, em::bx3), FIVE * (ONE - factor1));
192192
raise::KernelError(HERE, "incorrect bx3");
193193
}
194194
});

0 commit comments

Comments
 (0)