Skip to content

Commit 20a7954

Browse files
authored
Rigid injection: Center field scaling around the v push (#5389)
In the rigid injection, the fields where scale by the fraction of time spent between `n*dt` and `(n+1)*dt` to the right of the injection plane. However, to be consistent with the leap-frog velocity update, this needs to be between `(n-1/2)*dt` and `(n+1/2)*dt` instead. As a side-effect of this PR, saving and re-setting `u` and `optical_depth` to their original value is not needed anymore since the scaling factor for E and B is 0 for particles to the left of the plane.
1 parent 057d403 commit 20a7954

File tree

6 files changed

+106
-137
lines changed

6 files changed

+106
-137
lines changed
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
{
22
"lev=0": {
33
"Bx": 0.0,
4-
"By": 514.5044890273722,
4+
"By": 473.98537926589177,
55
"Bz": 0.0,
6-
"Ex": 154245109024.33972,
6+
"Ex": 142097845843.78326,
77
"Ey": 0.0,
88
"Ez": 0.0,
9-
"jx": 1161126105.5594487,
9+
"jx": 1260205974.7220135,
1010
"jy": 0.0,
1111
"jz": 0.0
1212
},
1313
"electrons": {
1414
"particle_position_x": 0.0,
1515
"particle_position_y": 0.0,
16-
"particle_position_z": 13607.569953355982,
17-
"particle_momentum_x": 3.095483353687591e-19,
16+
"particle_position_z": 13607.572916093213,
17+
"particle_momentum_x": 3.2646797960476606e-19,
1818
"particle_momentum_y": 0.0,
19-
"particle_momentum_z": 1.5419514460764825e-16,
19+
"particle_momentum_z": 1.541338620507345e-16,
2020
"particle_weight": 1349823909946836.0
2121
},
2222
"positrons": {
2323
"particle_position_x": 0.0,
2424
"particle_position_y": 0.0,
25-
"particle_position_z": 13607.569953355982,
26-
"particle_momentum_x": 3.095483353687591e-19,
25+
"particle_position_z": 13607.572916093213,
26+
"particle_momentum_x": 3.2646797960476606e-19,
2727
"particle_momentum_y": 0.0,
28-
"particle_momentum_z": 1.5419514460764825e-16,
28+
"particle_momentum_z": 1.541338620507345e-16,
2929
"particle_weight": 1349823909946836.0
3030
}
3131
}
Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
{
22
"lev=0": {
3-
"Bx": 1118808.3686978193,
4-
"By": 3248970.5506422943,
5-
"Bz": 280612.7921641442,
6-
"Ex": 975536649649286.1,
7-
"Ey": 402861835403418.1,
8-
"Ez": 159049265640492.28,
9-
"jx": 2.9996888133195436e+16,
10-
"jy": 8.866654944519546e+16,
11-
"jz": 3.164008885453435e+17,
12-
"rho": 1059988299.6088305
13-
},
14-
"ions": {
15-
"particle_momentum_x": 1.6150513873065298e-18,
16-
"particle_momentum_y": 2.233426695677123e-18,
17-
"particle_momentum_z": 4.279249529993671e-13,
18-
"particle_position_x": 1.4883816864183497,
19-
"particle_position_y": 16.452386504127254,
20-
"particle_weight": 1.234867369440658e+18
3+
"Bx": 1118808.3708538802,
4+
"By": 3248949.0437452313,
5+
"Bz": 280612.7768961371,
6+
"Ex": 975530336896144.1,
7+
"Ey": 402861838033488.6,
8+
"Ez": 159049784131625.12,
9+
"jx": 2.9997142632475216e+16,
10+
"jy": 8.866655055001146e+16,
11+
"jz": 3.163953981093208e+17,
12+
"rho": 1059970922.1974506
2113
},
2214
"electrons": {
23-
"particle_momentum_x": 7.058167362825288e-19,
24-
"particle_momentum_y": 2.204239326446281e-18,
25-
"particle_momentum_z": 2.530521998715408e-16,
26-
"particle_position_x": 1.5006581263609764,
27-
"particle_position_y": 16.454388313398017,
15+
"particle_momentum_x": 7.058252826278211e-19,
16+
"particle_momentum_y": 2.204239315713169e-18,
17+
"particle_momentum_z": 2.530521235191952e-16,
18+
"particle_position_x": 1.5006579649318788,
19+
"particle_position_y": 16.454388304724286,
2820
"particle_weight": 1.234867020725368e+18
2921
},
3022
"beam": {
31-
"particle_momentum_x": 6.869222298759882e-19,
32-
"particle_momentum_y": 4.374719809060106e-19,
33-
"particle_momentum_z": 6.4523206583503136e-18,
34-
"particle_position_x": 0.001290816359726098,
35-
"particle_position_y": 0.3586691102823157,
23+
"particle_momentum_x": 6.88879318082965e-19,
24+
"particle_momentum_y": 4.37466174746362e-19,
25+
"particle_momentum_z": 6.4299296650127095e-18,
26+
"particle_position_x": 0.0012936414423443238,
27+
"particle_position_y": 0.3587414953163842,
3628
"particle_weight": 3120754537230.3823
29+
},
30+
"ions": {
31+
"particle_momentum_x": 1.6150618501530563e-18,
32+
"particle_momentum_y": 2.2334266731098355e-18,
33+
"particle_momentum_z": 4.279249530957972e-13,
34+
"particle_position_x": 1.488381686539698,
35+
"particle_position_y": 16.4523865041322,
36+
"particle_weight": 1.234867369440658e+18
3737
}
3838
}
Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
{
22
"lev=0": {
3-
"Bx": 1086729.9718613266,
4-
"By": 2886554.482275311,
5-
"Bz": 264259.55093734514,
6-
"Ex": 867387781289915.2,
7-
"Ey": 392666724461952.5,
8-
"Ez": 146897592531660.03,
9-
"jx": 2.702866174672266e+16,
10-
"jy": 8.615938361747776e+16,
11-
"jz": 2.7329155817806224e+17,
12-
"rho": 915945723.7934376
3+
"Bx": 1086729.9879225595,
4+
"By": 2886531.8361456757,
5+
"Bz": 264259.55266959703,
6+
"Ex": 867381192933999.0,
7+
"Ey": 392666738858258.7,
8+
"Ez": 146898030091111.84,
9+
"jx": 2.702892158065604e+16,
10+
"jy": 8.615938867870698e+16,
11+
"jz": 2.7328506574305683e+17,
12+
"rho": 915924567.6956444
13+
},
14+
"beam": {
15+
"particle_momentum_x": 7.006049777955171e-19,
16+
"particle_momentum_y": 4.374916846096741e-19,
17+
"particle_momentum_z": 6.173292885825711e-18,
18+
"particle_position_x": 0.0016046573777589298,
19+
"particle_position_y": 0.35899824939059793,
20+
"particle_weight": 3120754537230.3823
1321
},
1422
"ions": {
15-
"particle_momentum_x": 1.4394902513923003e-18,
16-
"particle_momentum_y": 1.5967629157922875e-18,
17-
"particle_momentum_z": 4.287340658051679e-13,
18-
"particle_position_x": 1.4911814217142487,
19-
"particle_position_y": 16.521964978771,
23+
"particle_momentum_x": 1.4395010524514718e-18,
24+
"particle_momentum_y": 1.596762923413923e-18,
25+
"particle_momentum_z": 4.2873406589510426e-13,
26+
"particle_position_x": 1.4911814218338595,
27+
"particle_position_y": 16.52196497877563,
2028
"particle_weight": 1.2372405194129536e+18
2129
},
2230
"electrons": {
23-
"particle_momentum_x": 6.240933687389075e-19,
24-
"particle_momentum_y": 1.5790611427694247e-18,
25-
"particle_momentum_z": 2.5064357834741096e-16,
26-
"particle_position_x": 1.501413766926399,
27-
"particle_position_y": 16.523781713952324,
31+
"particle_momentum_x": 6.241019323257125e-19,
32+
"particle_momentum_y": 1.5790611706036782e-18,
33+
"particle_momentum_z": 2.5064350576384073e-16,
34+
"particle_position_x": 1.501413593465263,
35+
"particle_position_y": 16.52378170448397,
2836
"particle_weight": 1.2372401466086835e+18
29-
},
30-
"beam": {
31-
"particle_momentum_x": 7.000932845220306e-19,
32-
"particle_momentum_y": 4.374936866729326e-19,
33-
"particle_momentum_z": 6.194468548032543e-18,
34-
"particle_position_x": 0.0016030835496557787,
35-
"particle_position_y": 0.3589262705964349,
36-
"particle_weight": 3120754537230.3823
3737
}
3838
}
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
{
22
"lev=0": {
3-
"Bx": 4818955.480797943,
4-
"By": 1752.8025638791275,
5-
"Bz": 14516.212782554387,
6-
"Ex": 2366115503598.9224,
7-
"Ey": 1446112025635674.2,
8-
"Ez": 21864189507357.867,
9-
"jx": 1996366349775593.5,
10-
"jy": 5.312583827155926e+16,
11-
"jz": 2.0491352624508764e+16,
12-
"rho": 68443961.71852128
3+
"Bx": 4818955.485307051,
4+
"By": 1752.8020185365554,
5+
"Bz": 14516.212849649737,
6+
"Ex": 2366115529014.2324,
7+
"Ey": 1446112026998942.5,
8+
"Ez": 21864189485739.55,
9+
"jx": 1996366372981548.5,
10+
"jy": 5.312583836344946e+16,
11+
"jz": 2.049135259966133e+16,
12+
"rho": 68443961.64027263
13+
},
14+
"beam": {
15+
"particle_momentum_x": 3.535736052190267e-19,
16+
"particle_momentum_y": 4.363217976210739e-19,
17+
"particle_momentum_z": 5.658515465395611e-17,
18+
"particle_position_x": 0.008314855161869274,
19+
"particle_position_y": 1.170433573157185,
20+
"particle_weight": 62415090744.60765
1321
},
1422
"electrons": {
15-
"particle_momentum_x": 2.2135945391319113e-23,
16-
"particle_momentum_y": 2.8224559499558413e-22,
17-
"particle_momentum_z": 5.260626010214114e-22,
18-
"particle_position_x": 0.010800577787628052,
19-
"particle_position_y": 0.2111506062831815,
23+
"particle_momentum_x": 2.213594541883545e-23,
24+
"particle_momentum_y": 2.8224559261549207e-22,
25+
"particle_momentum_z": 5.260626007410037e-22,
26+
"particle_position_x": 0.010800577787636243,
27+
"particle_position_y": 0.2111506062831794,
2028
"particle_weight": 4.121554826246186e+16
2129
},
2230
"ions": {
23-
"particle_momentum_x": 6.248472277246885e-23,
24-
"particle_momentum_y": 4.449097689427654e-22,
25-
"particle_momentum_z": 5.768168724998047e-22,
31+
"particle_momentum_x": 6.24847229412907e-23,
32+
"particle_momentum_y": 4.449097671673176e-22,
33+
"particle_momentum_z": 5.768168722032957e-22,
2634
"particle_position_x": 0.010800001678510512,
2735
"particle_position_y": 0.21114947608115425,
2836
"particle_weight": 4.121554826246186e+16
29-
},
30-
"beam": {
31-
"particle_momentum_x": 3.5357456351701565e-19,
32-
"particle_momentum_y": 4.363391839372122e-19,
33-
"particle_momentum_z": 5.658606416951653e-17,
34-
"particle_position_x": 0.008314723025211468,
35-
"particle_position_y": 1.1704335743854242,
36-
"particle_weight": 62415090744.60765
3737
}
3838
}

Source/Particles/Gather/ScaleFields.H

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,21 @@ struct ScaleFields
4747
// This only approximates what should be happening. The particles
4848
// should by advanced a fraction of a time step instead.
4949
// Scaling the fields is much easier and may be good enough.
50-
const amrex::Real dtscale = 1._rt - (m_z_plane_previous - zp)/(m_vz_ave_boosted + m_v_boost)/m_dt;
51-
if (0._rt < dtscale && dtscale < 1._rt)
50+
51+
// The scaling factor corresponds to the fraction of time that
52+
// the particles spends to the right of the injection plane,
53+
// between (n-1/2)*dt and (n+1/2)*dt, which is the interval
54+
// over which the velocity is updated, in the leap-frog velocity push.
55+
// (Note that here, `zp` is the particle position at time n*dt)
56+
amrex::Real dtscale = 0.5_rt - (m_z_plane_previous - zp)/(m_vz_ave_boosted + m_v_boost)/m_dt;
57+
// If the particle stays to the left of the plane during the
58+
// whole push, simply set the scaling factor to 0, and thus
59+
// the velocity push leaves the velocity unchanged.
60+
if (dtscale < 0._rt) {
61+
dtscale = 0;
62+
}
63+
// Scale the fields.
64+
if (dtscale < 1._rt)
5265
{
5366
Exp *= dtscale;
5467
Eyp *= dtscale;

Source/Particles/RigidInjectedParticleContainer.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,6 @@ RigidInjectedParticleContainer::PushPX (WarpXParIter& pti,
176176

177177
// Save the position, momentum and optical depth, making copies
178178
amrex::Gpu::DeviceVector<ParticleReal> xp_save, yp_save, zp_save;
179-
amrex::Gpu::DeviceVector<ParticleReal> uxp_save, uyp_save, uzp_save;
180-
#ifdef WARPX_QED
181-
amrex::Gpu::DeviceVector<ParticleReal> optical_depth_save;
182-
#endif
183179

184180
const auto GetPosition = GetParticlePosition<PIdx>(pti, offset);
185181
auto SetPosition = SetParticlePosition<PIdx>(pti, offset);
@@ -188,54 +184,24 @@ RigidInjectedParticleContainer::PushPX (WarpXParIter& pti,
188184
amrex::ParticleReal* const AMREX_RESTRICT uy = uyp.dataPtr() + offset;
189185
amrex::ParticleReal* const AMREX_RESTRICT uz = uzp.dataPtr() + offset;
190186

191-
#ifdef WARPX_QED
192-
const bool loc_has_quantum_sync = has_quantum_sync();
193-
amrex::ParticleReal* AMREX_RESTRICT p_optical_depth = nullptr;
194-
amrex::ParticleReal* AMREX_RESTRICT p_optical_depth_save = nullptr;
195-
#endif
196-
197187
if (!done_injecting_lev)
198188
{
199189
// If the old values are not already saved, create copies here.
200190
xp_save.resize(np_to_push);
201191
yp_save.resize(np_to_push);
202192
zp_save.resize(np_to_push);
203193

204-
uxp_save.resize(np_to_push);
205-
uyp_save.resize(np_to_push);
206-
uzp_save.resize(np_to_push);
207-
208194
amrex::ParticleReal* const AMREX_RESTRICT xp_save_ptr = xp_save.dataPtr();
209195
amrex::ParticleReal* const AMREX_RESTRICT yp_save_ptr = yp_save.dataPtr();
210196
amrex::ParticleReal* const AMREX_RESTRICT zp_save_ptr = zp_save.dataPtr();
211197

212-
amrex::ParticleReal* const AMREX_RESTRICT uxp_save_ptr = uxp_save.dataPtr();
213-
amrex::ParticleReal* const AMREX_RESTRICT uyp_save_ptr = uyp_save.dataPtr();
214-
amrex::ParticleReal* const AMREX_RESTRICT uzp_save_ptr = uzp_save.dataPtr();
215-
216-
#ifdef WARPX_QED
217-
if(loc_has_quantum_sync){
218-
p_optical_depth = pti.GetAttribs(particle_comps["opticalDepthQSR"]).dataPtr()
219-
+ offset;
220-
optical_depth_save.resize(np_to_push);
221-
p_optical_depth_save = optical_depth_save.dataPtr();
222-
}
223-
#endif
224-
225198
amrex::ParallelFor( np_to_push,
226199
[=] AMREX_GPU_DEVICE (long i) {
227200
amrex::ParticleReal xp, yp, zp;
228201
GetPosition(i, xp, yp, zp);
229202
xp_save_ptr[i] = xp;
230203
yp_save_ptr[i] = yp;
231204
zp_save_ptr[i] = zp;
232-
uxp_save_ptr[i] = ux[i];
233-
uyp_save_ptr[i] = uy[i];
234-
uzp_save_ptr[i] = uz[i];
235-
#ifdef WARPX_QED
236-
if(loc_has_quantum_sync){
237-
p_optical_depth_save[i] = p_optical_depth[i];}
238-
#endif
239205
});
240206
}
241207

@@ -252,9 +218,6 @@ RigidInjectedParticleContainer::PushPX (WarpXParIter& pti,
252218
amrex::ParticleReal* AMREX_RESTRICT x_save = xp_save.dataPtr();
253219
amrex::ParticleReal* AMREX_RESTRICT y_save = yp_save.dataPtr();
254220
amrex::ParticleReal* AMREX_RESTRICT z_save = zp_save.dataPtr();
255-
amrex::ParticleReal* AMREX_RESTRICT ux_save = uxp_save.dataPtr();
256-
amrex::ParticleReal* AMREX_RESTRICT uy_save = uyp_save.dataPtr();
257-
amrex::ParticleReal* AMREX_RESTRICT uz_save = uzp_save.dataPtr();
258221

259222
// Undo the push for particles not injected yet.
260223
// The zp are advanced a fixed amount.
@@ -267,9 +230,6 @@ RigidInjectedParticleContainer::PushPX (WarpXParIter& pti,
267230
amrex::ParticleReal xp, yp, zp;
268231
GetPosition(i, xp, yp, zp);
269232
if (zp <= z_plane_lev) {
270-
ux[i] = ux_save[i];
271-
uy[i] = uy_save[i];
272-
uz[i] = uz_save[i];
273233
xp = x_save[i];
274234
yp = y_save[i];
275235
if (rigid) {
@@ -281,10 +241,6 @@ RigidInjectedParticleContainer::PushPX (WarpXParIter& pti,
281241
zp = z_save[i] + dt*uz[i]*gi;
282242
}
283243
SetPosition(i, xp, yp, zp);
284-
#ifdef WARPX_QED
285-
if(loc_has_quantum_sync){
286-
p_optical_depth[i] = p_optical_depth_save[i];}
287-
#endif
288244
}
289245
});
290246
}

0 commit comments

Comments
 (0)