Skip to content

Commit f7168d7

Browse files
RemiLehedpgrote
authored andcommitted
Update BackTransformed diagnostics to take into account arbitrary moving window velocity (BLAST-WarpX#5341)
In the `development` branch, the `BackTransformed` diagnostics assume that the moving window moves exactly at the speed of light. This PR generalizes the code for arbitrary moving window velocity. This PR does not add an automated test, but the upcoming PR BLAST-WarpX#5337 will add a test which features a moving window with a speed different than `c`. This is a follow-up of BLAST-WarpX#5226, which modified the transformation of the simulation box coordinates for arbitrary moving window velocity, but did not yet update the `BackTransformed` diagnostic code.
1 parent 3c46175 commit f7168d7

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

Docs/source/usage/faq.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ Several BTD quantities differ slightly from the lab frame domain described in th
7474
In the following discussion, we will use a subscript input (e.g. :math:`\Delta z_{\rm input}`) to denote properties of the lab frame domain.
7575

7676

77-
- The first back-transformed diagnostic (BTD) snapshot may not occur at :math:`t=0`. Rather, it occurs at :math:`t_0=\frac{z_{max}}c \beta(1+\beta)\gamma^2`. This is the first time when the boosted frame can complete the snapshot.
77+
- The first back-transformed diagnostic (BTD) snapshot may not occur at :math:`t=0`. Rather, it occurs at :math:`t_0=\frac{z_{max}}c \beta/(1 - \beta \beta_{mw})`, where :math:`\beta_{mw}` represents the speed of the moving window. This is the first time when the boosted frame can complete the snapshot.
7878
- The grid spacing of the BTD snapshot is different from the grid spacing indicated in the input script. It is given by :math:`\Delta z_{\rm grid,snapshot}=\frac{c\Delta t_{\rm boost}}{\gamma\beta}`. For a CFL-limited time step, :math:`\Delta z_{\rm grid,snapshot}\approx \frac{1+\beta}{\beta} \Delta z_{\rm input}\approx 2 \Delta z_{\rm input}`. Hence in many common use cases at large boost, it is expected that the BTD snapshot has a grid spacing twice what is expressed in the input script.
7979
- The effective length of the BTD snapshot may be longer than anticipated from the input script because the grid spacing is different. Additionally, the number of grid points in the BTD snapshot is a multiple of ``<BTD>.buffer_size`` whereas the number of grid cells specified in the input deck may not be.
80-
- The code may require longer than anticipated to complete a BTD snapshot. The code starts filling the :math:`i^{th}` snapshot around step :math:`j_{\rm BTD start}={\rm ceil}\left( i\gamma(1-\beta)\frac{\Delta t_{\rm snapshot}}{\Delta t_{\rm boost}}\right)`. The code then saves information for one BTD cell every time step in the boosted frame simulation. The :math:`i^{th}` snapshot is completed and saved :math:`n_{z,{\rm snapshot}}=n_{\rm buffers}\cdot ({\rm buffer\ size})` time steps after it begins, which is when the effective snapshot length is covered by the simulation.
80+
- The code may require longer than anticipated to complete a BTD snapshot. The code starts filling the :math:`i^{th}` snapshot around step :math:`j_{\rm BTD start}={\rm ceil}\left( i\gamma(1-\beta\beta_{mw})\frac{\Delta t_{\rm snapshot}}{\Delta t_{\rm boost}}\right)`. The code then saves information for one BTD cell every time step in the boosted frame simulation. The :math:`i^{th}` snapshot is completed and saved :math:`n_{z,{\rm snapshot}}=n_{\rm buffers}\cdot ({\rm buffer\ size})` time steps after it begins, which is when the effective snapshot length is covered by the simulation.
8181

8282
What kinds of RZ output do you support?
8383
---------------------------------------

Source/Diagnostics/BTDiagnostics.H

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ private:
161161
* in z-direction for both 2D and 3D simulations in the Cartesian frame of reference.
162162
*/
163163
int m_moving_window_dir;
164+
amrex::Real m_moving_window_beta;
164165

165166
/** Number of back-transformed snapshots in the lab-frame requested by the user */
166167
int m_num_snapshots_lab = std::numeric_limits<int>::lowest();

Source/Diagnostics/BTDiagnostics.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ void BTDiagnostics::DerivedInitData ()
6969
m_gamma_boost = WarpX::gamma_boost;
7070
m_beta_boost = std::sqrt( 1._rt - 1._rt/( m_gamma_boost * m_gamma_boost) );
7171
m_moving_window_dir = WarpX::moving_window_dir;
72+
m_moving_window_beta = WarpX::moving_window_v/PhysConst::c;
7273
// Currently, for BTD, all the data is averaged+coarsened to coarsest level
7374
// and then sliced+back-transformed+filled_to_buffer.
7475
// The number of levels to be output is nlev_output.
@@ -138,7 +139,7 @@ void BTDiagnostics::DerivedInitData ()
138139
const int lev = 0;
139140
const amrex::Real dt_boosted_frame = warpx.getdt(lev);
140141
const int moving_dir = WarpX::moving_window_dir;
141-
const amrex::Real Lz_lab = warpx.Geom(lev).ProbLength(moving_dir) / WarpX::gamma_boost / (1._rt+WarpX::beta_boost);
142+
const amrex::Real Lz_lab = warpx.Geom(lev).ProbLength(moving_dir) * WarpX::gamma_boost * (1._rt - WarpX::beta_boost*m_moving_window_beta);
142143
const int ref_ratio = 1;
143144
const amrex::Real dz_snapshot_grid = dz_lab(dt_boosted_frame, ref_ratio);
144145
// Need enough buffers so the snapshot length is longer than the lab frame length
@@ -149,22 +150,21 @@ void BTDiagnostics::DerivedInitData ()
149150
// the final snapshot starts filling when the
150151
// right edge of the moving window intersects the final snapshot
151152
// time of final snapshot : t_sn = t0 + i*dt_snapshot
152-
// where t0 is the time of first BTD snapshot, t0 = zmax / c * beta / (1-beta)
153+
// where t0 is the time of first BTD snapshot, t0 = zmax / c * beta / (1-beta*beta_mw)
153154
//
154155
// the right edge of the moving window at the time of the final snapshot
155156
// has space time coordinates
156-
// time t_intersect = t_sn, position z_intersect=zmax + c*t_sn
157+
// time t_intersect = t_sn, position z_intersect=zmax + v_mw*t_sn
157158
// the boosted time of this space time pair is
158159
// t_intersect_boost = gamma * (t_intersect - beta * z_intersect_boost/c)
159-
// = gamma * (t_sn * (1 - beta) - beta * zmax / c)
160-
// = gamma * (zmax*beta/c + i*dt_snapshot*(1-beta) - beta*zmax/c)
161-
// = gamma * i * dt_snapshot * (1-beta)
162-
// = i * dt_snapshot / gamma / (1+beta)
160+
// = gamma * (t_sn * (1 - beta*beta_mw) - beta * zmax / c)
161+
// = gamma * (zmax*beta/c + i*dt_snapshot*(1-beta*beta_mw) - beta*zmax/c)
162+
// = gamma * (1-beta*beta_mw) * i * dt_snapshot
163163
//
164164
// if j = final snapshot starting step, then we want to solve
165-
// j dt_boosted_frame >= t_intersect_boost = i * dt_snapshot / gamma / (1+beta)
166-
// j >= i / gamma / (1+beta) * dt_snapshot / dt_boosted_frame
167-
const int final_snapshot_starting_step = static_cast<int>(std::ceil(final_snapshot_iteration / WarpX::gamma_boost / (1._rt+WarpX::beta_boost) * m_dt_snapshots_lab / dt_boosted_frame));
165+
// j dt_boosted_frame >= t_intersect_boost = i * gamma * (1-beta*beta_mw) * dt_snapshot
166+
// j >= i * gamma * (1-beta*beta_mw) * dt_snapshot / dt_boosted_frame
167+
const int final_snapshot_starting_step = static_cast<int>(std::ceil(final_snapshot_iteration * WarpX::gamma_boost * (1._rt - WarpX::beta_boost*m_moving_window_beta) * m_dt_snapshots_lab / dt_boosted_frame));
168168
const int final_snapshot_fill_iteration = final_snapshot_starting_step + num_buffers * m_buffer_size - 1;
169169
const amrex::Real final_snapshot_fill_time = final_snapshot_fill_iteration * dt_boosted_frame;
170170
if (WarpX::compute_max_step_from_btd) {
@@ -256,7 +256,7 @@ BTDiagnostics::ReadParameters ()
256256
bool snapshot_interval_is_specified = utils::parser::queryWithParser(
257257
pp_diag_name, "dt_snapshots_lab", m_dt_snapshots_lab);
258258
if ( utils::parser::queryWithParser(pp_diag_name, "dz_snapshots_lab", m_dz_snapshots_lab) ) {
259-
m_dt_snapshots_lab = m_dz_snapshots_lab/PhysConst::c;
259+
m_dt_snapshots_lab = m_dz_snapshots_lab/WarpX::moving_window_v;
260260
snapshot_interval_is_specified = true;
261261
}
262262
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(snapshot_interval_is_specified,
@@ -338,13 +338,15 @@ BTDiagnostics::InitializeBufferData ( int i_buffer , int lev, bool restart)
338338
// When restarting boosted simulations, the code below needs to take
339339
// into account the fact that the position of the box at the beginning
340340
// of the simulation, is not the one that we had at t=0 (because of the moving window)
341-
const amrex::Real boosted_moving_window_v = (WarpX::moving_window_v - m_beta_boost*PhysConst::c)
342-
/ (1._rt - m_beta_boost * WarpX::moving_window_v/PhysConst::c);
341+
const amrex::Real boosted_moving_window_v = (m_moving_window_beta - m_beta_boost)
342+
/ (1._rt - m_beta_boost*m_moving_window_beta);
343343
// Lab-frame time for the i^th snapshot
344344
if (!restart) {
345-
const amrex::Real zmax_0 = warpx.Geom(lev).ProbHi(m_moving_window_dir);
345+
const amrex::Real zmax_boost = warpx.Geom(lev).ProbHi(m_moving_window_dir);
346346
m_t_lab.at(i_buffer) = m_intervals.GetBTDIteration(i_buffer) * m_dt_snapshots_lab
347-
+ m_gamma_boost*m_beta_boost*zmax_0/PhysConst::c;
347+
+ m_gamma_boost*m_beta_boost*zmax_boost/PhysConst::c;
348+
// Note: gamma_boost*beta_boost*zmax_boost is equal to
349+
// beta_boost*zmax_lab/(1-beta_boost*beta_moving_window)
348350
}
349351

350352
// Define buffer domain in boosted frame at level, lev, with user-defined lo and hi
@@ -403,9 +405,9 @@ BTDiagnostics::InitializeBufferData ( int i_buffer , int lev, bool restart)
403405
// Define buffer_domain in lab-frame for the i^th snapshot.
404406
// Replace z-dimension with lab-frame co-ordinates.
405407
const amrex::Real zmin_buffer_lab = ( diag_dom.lo(m_moving_window_dir) - boosted_moving_window_v * warpx.gett_new(0) )
406-
/ ( (1.0_rt + m_beta_boost) * m_gamma_boost);
408+
* (1.0_rt - m_beta_boost*m_moving_window_beta) * m_gamma_boost;
407409
const amrex::Real zmax_buffer_lab = ( diag_dom.hi(m_moving_window_dir) - boosted_moving_window_v * warpx.gett_new(0) )
408-
/ ( (1.0_rt + m_beta_boost) * m_gamma_boost);
410+
* (1.0_rt - m_beta_boost*m_moving_window_beta) * m_gamma_boost;
409411

410412
// Initialize buffer counter and z-positions of the i^th snapshot in
411413
// boosted-frame and lab-frame

0 commit comments

Comments
 (0)