Skip to content

Commit

Permalink
Avoid interpolating from guard cells in BTD (#5342)
Browse files Browse the repository at this point in the history
BTD diagnostics sometimes show artifacts at the edge of the range of
collected data. (See for instance the red curve below.)

My understanding is that this happens because the BTD collection planes
use data from the guard cells outside of the simulation domain, when
interpolating fields that are then used for the Lorentz back-transform.
The guard cell data may not be physically correct (e.g. it may not have
the right cancellation between `E` and `B`), and could thus cause this
artifact.

This PR avoids this issue by prevents the collection planes to collect
data when it is half a cell from the edge of the simulation domain.

See the example below, taken from
#5337 (plot of the laser field,
from the BTD diagnostic)
![Figure
40](https://github.com/user-attachments/assets/e4549856-4182-4a87-aa26-2d3bc6ac8e2c)
The BTD diagnostics values are identical with this PR, except for the
problematic point appearing at the edge of the domain.
  • Loading branch information
RemiLehe authored Oct 11, 2024
1 parent 1794629 commit 3cda2c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"lev=0": {
"Bx": 3.719030475087696e-05,
"By": 0.004843257051761486,
"Bz": 5.522765606391185e-06,
"Ex": 1461264.5033270014,
"Ey": 11205.64142004876,
"Ez": 282020.7784731542,
"jx": 16437877.898892798,
"jy": 2492340.3149980744,
"jz": 215102423.57036853,
"rho": 0.7246235591902171
},
"beam": {
"particle_momentum_x": 2.2080215038948936e-16,
"particle_momentum_x": 2.2080215038948934e-16,
"particle_momentum_y": 2.18711072170811e-16,
"particle_momentum_z": 2.730924530737497e-15,
"particle_position_x": 0.0260823588888081,
"particle_momentum_z": 2.730924530737456e-15,
"particle_position_x": 0.026082358888808558,
"particle_position_y": 0.5049438607316916,
"particle_weight": 62415.090744607645
},
"lev=0": {
"Bx": 3.721807007218884e-05,
"By": 0.004860056238272468,
"Bz": 5.5335765596325185e-06,
"Ex": 1466447.517373168,
"Ey": 11214.10223280318,
"Ez": 283216.0961218869,
"jx": 16437877.898892513,
"jy": 2492340.3149980404,
"jz": 215102423.57036877,
"rho": 0.7246235591902177
}
}
7 changes: 5 additions & 2 deletions Source/Diagnostics/BTDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,12 +999,15 @@ BTDiagnostics::GetZSliceInDomainFlag (const int i_buffer, const int lev)
{
auto & warpx = WarpX::GetInstance();
const amrex::RealBox& boost_domain = warpx.Geom(lev).ProbDomain();
const amrex::Real boost_cellsize = warpx.Geom(lev).CellSize(m_moving_window_dir);
const amrex::Real buffer_zmin_lab = m_snapshot_domain_lab[i_buffer].lo( m_moving_window_dir );
const amrex::Real buffer_zmax_lab = m_snapshot_domain_lab[i_buffer].hi( m_moving_window_dir );

// Exclude 0.5*boost_cellsize from the edge, to avoid that the interpolation to
// cell centers uses data from the guard cells.
const bool slice_not_in_domain =
( m_current_z_boost[i_buffer] <= boost_domain.lo(m_moving_window_dir) ) ||
( m_current_z_boost[i_buffer] >= boost_domain.hi(m_moving_window_dir) ) ||
( m_current_z_boost[i_buffer] <= boost_domain.lo(m_moving_window_dir) + 0.5_rt*boost_cellsize) ||
( m_current_z_boost[i_buffer] >= boost_domain.hi(m_moving_window_dir) - 0.5_rt*boost_cellsize) ||
( m_current_z_lab[i_buffer] <= buffer_zmin_lab ) ||
( m_current_z_lab[i_buffer] >= buffer_zmax_lab );

Expand Down

0 comments on commit 3cda2c1

Please sign in to comment.