Resampling
Resampling is beta. Parameter names, defaults and the numerical behaviour may still change. Before using results in production, compare the case against a run without resampling.
What resampling does
A simulation resolves a region with a fixed number of test particles per real particle, given by the statistical weight (see NREAL). Where the density is low, that wastes particles on nearly empty space; where the density is high, too many particles end up in one cell and the run slows down. Resampling adjusts the number of test particles per cell during the run: particles in sparse cells are split, particles in dense cells are merged. The total weight per cell is preserved, so density, current and fluxes stay the same - only the statistical resolution changes.
It is a numerical tool, not an additional physical model. Cross sections, transport and collisions are not affected.
Switching it on
- RVM
- Python
RESAMPLE_METHOD = 4; # 4 = balanced, the default
RESAMPLE_SCALE = 150; # target particles per cell at peak density
sim = PICMC.Sim(
RESAMPLE_METHOD = 4, # 4 = balanced, the default
RESAMPLE_SCALE = 150 # target particles per cell at peak density
)
RESAMPLE_SCALE is the switch. If the line is missing - or commented out - resampling is off,
even if RESAMPLE_METHOD is set to something else. Parameter files created with initpicmc
contain both lines, so freshly created cases resample by default; existing cases keep running
unchanged.
In a Python case the same switches are keyword arguments of Sim, for example
Sim(RESAMPLE_METHOD = 4, RESAMPLE_SCALE = 150, …); leaving RESAMPLE_SCALE out disables
resampling there as well. See Driving a case from Python.
At startup the weights are harmonised once before the first time step; the log prints
Initial per-particle weight harmonization.... While resampling is active it is
RESAMPLE_SCALE, not NREAL_<species>, that sets the starting weights: they are derived from
P0_<species> and the cell volume, and the log warns if NREAL_<species> was also given.
P0_<species> is therefore required for every species in the species lists.
Warning: because the starting weights come from P0, a wrong initial pressure or density
immediately leads to a wrong particle count per cell. Check the number/ plots of the first
few output times before interpreting anything else.
Profiles
| Value | Name | Conserves | Cost |
|---|---|---|---|
| 0 | off | - | - |
| 1 | fast | number only | lowest |
| 2 | numberT | number and temperature | low |
| 3 | energyT | energy | moderate |
| 4 | balanced | charge, momentum and energy in every event | moderate (default) |
| 5 | accurate | as 4, plus higher moments | highest |
Start with 4. Profile 1 is noticeably cheaper but the temperature develops a visible bias; it is acceptable for a quick look at a density profile, not for energy-sensitive work such as sputter yields or dissociation rates.
Tuning
| Key | Default | Meaning |
|---|---|---|
RESAMPLE_SCALE | - | target particles per cell at peak density; missing or commented out means off |
RESAMPLE_INTERVAL | 100 | time steps between full harmonisations |
RESAMPLE_DENSITY_SCALING | 0 | 0: same target everywhere; 1: target follows the density, fewer particles in thin regions |
RESAMPLE_DENSITY_THRESHOLD | 1e12 | below this density in [1/m³] nothing is resampled |
RESAMPLE_NP_MIN | 4 | cells whose average particle number is below this are left alone |
RESAMPLE_GOAL_MIN | 20 | lower bound of the target in sparse cells |
RESAMPLE_LOCAL_ELECTRONS | 8 | step interval of the cheaper per-species pass, electrons |
RESAMPLE_LOCAL_IONS | 100 | same, ions |
RESAMPLE_LOCAL_NEUTRALS | 1000 | same, neutrals |
RESAMPLE_SCALE is read as an integer, so give it as a whole number.
Practical loop: set RESAMPLE_SCALE, leave the remaining keys at their defaults, run a few
hundred cycles and look at number/ and number_goal/. The particle count should settle in
a band around the target. If the band is too wide, reduce RESAMPLE_INTERVAL; if the run
became slower instead of faster, the target is too high for the available memory.
Cells are only touched when they leave a dead band around the target: split below roughly 0.67 times the target, merged above roughly 1.5 times. Small fluctuations therefore cost nothing.
Warning: RESAMPLE_GOAL_MIN must stay above the number of constraints of the selected
profile, otherwise dense cells are never merged. The build refuses a configuration that
violates this.
Cut cells are handled separately: their target ramps down below one percent cell volume fraction, so thin slivers along curved walls do not attract particles.
What to check afterwards
- Density, current and absorption must agree with a run without resampling within the statistical scatter.
- The total kinetic energy should be conserved. A growing or sinking trend means the target is far too small.
- The particle count per cell should settle, not oscillate. Oscillation means
RESAMPLE_INTERVALis too long compared to how fast the density changes. - The electron energy distribution should keep its tail - compare histograms with a non-resampled run.
Limitations
- Weights differ within a cell after resampling. Anything that averages over single particles must weight by the particle weight instead of counting particles equally.
- Checkpoints contain the weights, so a run can be continued. After a restart the harmonisation runs once, which re-establishes the target particle count immediately; the density stays the same.
- Changing
RESAMPLE_SCALEbetween two runs of the same case changes the statistical resolution, not the physics - but it does change the noise level of all plots. - Beta: not yet validated for every gas mixture. Report suspicious behaviour.