Skip to content

Commit 17c6acf

Browse files
authored
Merge pull request #360 from JamesMcClung/pr/cleanup-inc-push
Cleanup inc_push.c
2 parents 953ac87 + a0678c9 commit 17c6acf

2 files changed

Lines changed: 19 additions & 50 deletions

File tree

src/libpsc/psc_push_particles/inc_push.c

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,12 @@
55

66
#include "pushp.hxx"
77

8-
template <typename real_t>
9-
class PI
8+
template <typename real_t, typename Real3 = Vec3<real_t>>
9+
void find_idx_pos_1st_rel(Real3 final_pos, Real3 dxi, Int3& final_index,
10+
Real3& final_pos_normalized, real_t shift)
1011
{
11-
public:
12-
using Real3 = Vec3<real_t>;
13-
14-
PI(const Grid_t& grid) : dxi_{Real3{1., 1., 1.} / Real3(grid.domain.dx)} {}
15-
16-
// ----------------------------------------------------------------------
17-
// find_idx_off_1st_rel
18-
19-
void find_idx_off_1st_rel(real_t xi[3], int lg[3], real_t og[3], real_t shift)
20-
{
21-
for (int d = 0; d < 3; d++) {
22-
real_t pos = xi[d] * dxi_[d] + shift;
23-
lg[d] = fint(pos);
24-
og[d] = pos - lg[d];
25-
}
12+
for (int d = 0; d < 3; d++) {
13+
final_pos_normalized[d] = final_pos[d] * dxi[d] + shift;
14+
final_index[d] = fint(final_pos_normalized[d]);
2615
}
27-
28-
// ----------------------------------------------------------------------
29-
// find_idx_off_pos_1st_rel
30-
31-
void find_idx_off_pos_1st_rel(real_t xi[3], int lg[3], real_t og[3],
32-
real_t pos[3], real_t shift)
33-
{
34-
for (int d = 0; d < 3; d++) {
35-
pos[d] = xi[d] * dxi_[d] + shift;
36-
lg[d] = fint(pos[d]);
37-
og[d] = pos[d] - lg[d];
38-
}
39-
}
40-
41-
private:
42-
Real3 dxi_;
43-
};
16+
}

src/libpsc/psc_push_particles/push_particles_1vb.hxx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ struct PushParticlesVb
2424
static void push_mprts(Mparticles& mprts, MfieldsState& mflds)
2525
{
2626
const auto& grid = mprts.grid();
27-
PI<real_t> pi(grid);
2827
Real3 dxi = Real3{1., 1., 1.} / Real3(grid.domain.dx);
2928
real_t dq_kind[MAX_NR_KINDS];
3029
auto& kinds = grid.kinds;
@@ -46,13 +45,8 @@ struct PushParticlesVb
4645
flds.storage().view(_all, _all, _all, _s(JXI, JXI + 3)) = real_t(0);
4746

4847
for (auto prt : prts) {
49-
Real3& x = prt.x();
50-
51-
real_t xm[3];
52-
for (int d = 0; d < 3; d++) {
53-
xm[d] = x[d] * dxi[d];
54-
}
55-
ip.set_coeffs(xm);
48+
Real3 initial_pos_normalized = prt.x() * dxi;
49+
ip.set_coeffs(initial_pos_normalized);
5650

5751
// FIELD INTERPOLATION
5852
Real3 E = {ip.ex(EM), ip.ey(EM), ip.ez(EM)};
@@ -64,11 +58,12 @@ struct PushParticlesVb
6458

6559
// x^(n+0.5), p^(n+1.0) -> x^(n+1.5), p^(n+1.0)
6660
auto v = advance.calc_v(prt.u());
67-
advance.push_x(x, v);
61+
advance.push_x(prt.x(), v);
6862

69-
int lf[3];
70-
real_t of[3], xp[3];
71-
pi.find_idx_off_pos_1st_rel(x, lf, of, xp, real_t(0.));
63+
Int3 final_index;
64+
Real3 final_pos_normalized;
65+
find_idx_pos_1st_rel(prt.x(), dxi, final_index, final_pos_normalized,
66+
real_t(0.));
7267

7368
// CURRENT DENSITY BETWEEN (n+.5)*dt and (n+1.5)*dt
7469
int lg[3];
@@ -81,7 +76,8 @@ struct PushParticlesVb
8176
if (!Dim::InvarZ::value) {
8277
lg[2] = ip.cz.g.l;
8378
}
84-
current.calc_j(J, xm, xp, lf, lg, prt.qni_wni(), v);
79+
current.calc_j(J, initial_pos_normalized, final_pos_normalized,
80+
final_index, lg, prt.qni_wni(), v);
8581
}
8682
}
8783
}
@@ -112,14 +108,14 @@ struct PushParticlesVb
112108
// field interpolation
113109
real_t* x = prt.x;
114110

115-
real_t xm[3];
111+
real_t initial_pos_normalized[3];
116112
for (int d = 0; d < 3; d++) {
117-
xm[d] = x[d] * dxi[d];
113+
initial_pos_normalized[d] = x[d] * dxi[d];
118114
}
119115

120116
// FIELD INTERPOLATION
121117

122-
ip.set_coeffs(xm);
118+
ip.set_coeffs(initial_pos_normalized);
123119
// FIXME, we're not using EM instead flds_em
124120
real_t E[3] = {ip.ex(EM), ip.ey(EM), ip.ez(EM)};
125121
real_t H[3] = {ip.hx(EM), ip.hy(EM), ip.hz(EM)};

0 commit comments

Comments
 (0)