Warwick-Plasma / epoch

Particle-in-cell code for plasma physics simulations
https://epochpic.github.io
GNU General Public License v3.0
176 stars 56 forks source link

Noise in Plasma Density Profile #724

Open floresv299 opened 4 days ago

floresv299 commented 4 days ago

Hi all,

I'm initializing a 1d plasma slab with an exponential profile. This is a simple proton/electron plasma, that suppose to peak at 40*nc. I'm seeing a lot of fluctuations near the maximum density. I thought it might be numerical heating so I increased my ppc and grid resolution but it didn't fix the problem. I also noticed that the sum of the electron and proton densities do not sum up to zero. Is this normal ? Any help will be greatly appreciated ! Thank you

input (7).txt image

Status-Mirror commented 3 days ago

When a normal EPOCH simulation is loaded, the number density in each cell is taken from your input deck, and macro-particles are loaded to achieve that density. The macro-particles are positioned randomly throughout the cell, and the weights are set such that the sum of macro-particle weights divided by the cell volume is equal to the assigned number density.

However, EPOCH macro-particles have shapes which project out from their original cell. This is done to smooth the fields interpolated to the macro-particles to reduce simulation noise, but it has the added effect of distorting the initial number densities. Weights which are calculated on a cell-by-cell basis are projected to neighbouring cells, and because macro-particle position within a cell is random, there are random projections that don't balance out. The net effect is noise similar to what you show here. It would be improved by increasing the ppc, but it would always remain.

I'm a little more confused about your sums not adding to zero though. Is this an output from the 0000.sdf file?

Cheers, Stuart

TomGoffrey commented 3 days ago

Regarding the sums not cancelling (so presumably a net charge in the domain) - is this explained by each species having different projections into ghostcells, and thus having slightly different net contributions to the physical domain?

Status-Mirror commented 3 days ago

EPOCH loads the correct weight into each cell. The projections will smear this weight among neighbouring cells, but the total summed weight should still be correct - unless weight is being lost through the x_min or x_max boundaries. It does't appear that this is the case in the figure, but I've just spotted:

number_density = if((x gt slab_length) and (x lt start_ramp), 0, number_density(Electron))

in the input.deck. This line does nothing, as we cannot satisfy $x>5\mu m$ and $x < -1 \mu m$ at the same time. However, even ignoring this, the density should still be 0 on the boundaries.

My last thought is that maybe this is was taken at a different time-step, where macro-particles may have escaped the simulation window?

Edit: Maybe @floresv299 means that the total charge in a given cell isn't neutral? This would be explained by the random weight projections.

floresv299 commented 3 days ago

Hi all, thank you very much for your reply, this was very helpful. Yes, I do mean the total charge, here is a better graph. This is taken at 0000.sdf.

image

floresv299 commented 3 days ago

I can verify that this effect is improved by increasing the ppc, but it still remains. Just making sure I wasn't doing anything wrong. Thank you all again !

Status-Mirror commented 3 days ago

Hi @floresv299,

I've looked into it, and there are two reasons why the weights may not fully cancel out.

  1. You're using different numbers of particles per cell. The weights are set for each species to sum to the density*cell-volume at their position. If you have a uniform-density region with different macro-particle numbers, then when calculating [total cell weight]/[macro-particle count], machine precision effects are present, and the weight isn't exactly correct.
  2. This is your main issue. Macro-particles are positioned randomly in the cell, then the density function is applied to the current macro-particle position. This means that particles loaded at different points on your density ramp are dealing with different densities, and are assigned different weights. Because these positions are random within the cell, your summed macro-proton weight won't perfectly cancel your summed macro-electron weight - even if you use the same number of particles per cell.

In practice, this means there is a net charge on the grid. The way EPOCH's field solver works is that it assumes every cell is initially neutral. Any cell with a net charge is assumed to have an immobile background charge which perfectly cancels this out. Typically this is fine when a larger number of particles per cell is used, but it's something to be aware of if all your target particles move to a different $x$ position - a fake "ghost charge" will remain at the initial position.

In most cases, this isn't an issue. I think this problem would vanish completely if you recompile the code with -DPER_SPECIES_WEIGHT, following the compilation flag instructions. This fixes all macro-particles within a species to have the same weight, and doesn't calculate weights based on individual macro-particles. Density ramps are achieved by having fewer macro-particles in cells with lower density. There are compatability issues though with some physics packages, if you're interested in ionisation for example.

Hope this helps, Stuart