55#include " grid.hxx"
66#include " rng.hxx"
77#include " particle.h"
8+ #include < psc.hxx>
89#include " pushp.hxx"
910#include " dim.hxx"
11+ #include " ../libpsc/psc_push_particles/inc_push.c"
1012
1113class ParticleGeneratorMaxwellian
1214{
@@ -50,6 +52,7 @@ template <typename PARTICLE_GENERATOR, typename PUSH_PARTICLES>
5052class InjectorBoundaryInflow
5153{
5254 static const int INJECT_DIM_IDX_ = 1 ;
55+ static const int MAX_NR_KINDS = PUSH_PARTICLES ::MAX_NR_KINDS ;
5356
5457public:
5558 using ParticleGenerator = PARTICLE_GENERATOR ;
@@ -76,6 +79,18 @@ public:
7679 const Grid_t& grid = mprts.grid ();
7780 auto injectors_by_patch = mprts.injector ();
7881
82+ PI <real_t > pi (grid);
83+ Real3 dxi = Real3{1 ., 1 ., 1 .} / Real3 (grid.domain .dx );
84+ real_t dq_kind[MAX_NR_KINDS ];
85+ auto & kinds = grid.kinds ;
86+ assert (kinds.size () <= MAX_NR_KINDS );
87+ for (int k = 0 ; k < kinds.size (); k++) {
88+ dq_kind[k] = .5f * grid.norm .eta * grid.dt * kinds[k].q / kinds[k].m ;
89+ }
90+ InterpolateEM_t ip;
91+ Current current (grid);
92+ auto accessor = mprts.accessor_ ();
93+
7994 for (int patch_idx = 0 ; patch_idx < grid.n_patches (); patch_idx++) {
8095 const auto & patch = grid.patches [patch_idx];
8196
@@ -84,6 +99,12 @@ public:
8499 }
85100
86101 auto && injector = injectors_by_patch[patch_idx];
102+ auto flds = mflds[patch_idx];
103+ auto prts = accessor[patch_idx];
104+ typename InterpolateEM_t::fields_t EM (flds.storage (), flds.ib ());
105+ typename Current::fields_t J (flds);
106+
107+ flds.storage ().view (_all, _all, _all, _s (JXI , JXI + 3 )) = real_t (0 );
87108
88109 Int3 ilo = patch.off ;
89110 Int3 ihi = ilo + grid.ldims ;
@@ -104,20 +125,52 @@ public:
104125 partice_generator.get (min_pos, grid.domain .dx );
105126
106127 Real3 v = advance.calc_v (prt.u );
128+ Real3 initial_x = prt.x ;
107129 advance.push_x (prt.x , v, 1.0 );
108130
109131 if (prt.x [INJECT_DIM_IDX_ ] < grid.domain .corner [INJECT_DIM_IDX_ ]) {
110132 continue ;
111133 }
112134
113135 injector (prt);
136+
137+ // Update currents
138+ // Taken from push_particles_1vb.hxx PushParticlesVb::push_mprts()
139+
140+ real_t initial_normalized_pos[3 ];
141+ for (int d = 0 ; d < 3 ; d++) {
142+ initial_normalized_pos[d] = prt.x [d] * dxi[d];
143+ }
144+ ip.set_coeffs (initial_normalized_pos);
145+
146+ // FIELD INTERPOLATION
147+ Real3 E = {ip.ex (EM ), ip.ey (EM ), ip.ez (EM )};
148+ Real3 H = {ip.hx (EM ), ip.hy (EM ), ip.hz (EM )};
149+
150+ int final_idx[3 ];
151+ real_t final_offset[3 ];
152+ real_t final_normalized_pos[3 ];
153+ pi.find_idx_off_pos_1st_rel (initial_x, final_idx, final_offset,
154+ final_normalized_pos, real_t (0 .));
155+
156+ // CURRENT DENSITY BETWEEN (n+.5)*dt and (n+1.5)*dt
157+ int lg[3 ];
158+ if (!Dim::InvarX::value) {
159+ lg[0 ] = ip.cx .g .l ;
160+ }
161+ if (!Dim::InvarY::value) {
162+ lg[1 ] = ip.cy .g .l ;
163+ }
164+ if (!Dim::InvarZ::value) {
165+ lg[2 ] = ip.cz .g .l ;
166+ }
167+ Real3 qni_wni = grid.kinds [prt.kind ].q * prt.w ;
168+ current.calc_j (J, initial_normalized_pos, final_normalized_pos,
169+ final_idx, lg, qni_wni, v);
114170 }
115171 }
116172 }
117173 }
118-
119- // TODO:
120- // 4. update current
121174 }
122175
123176private:
0 commit comments