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

Incorrect initial density profile #279

Open jgriffmc opened 3 years ago

jgriffmc commented 3 years ago

Hello, I have been seeing unusual behavior that could be a potential bug.

Summary

The initial density profile outputted from a subset in the first save appears to be incorrect and scaled down by ~5% or ~17% depending on the grid resolution.

Steps to reproduce

I am attaching two input decks with two different grid resolutions that yield different results, both of which yield scaled versions of the intended density profile. 80 nm resolution: input_80nm.txt 160 nm resolution: input_160nm.txt

I ran EPOCH 3D on the 4.18-devel branch with 40 cores x 1 node.

What is the current bug behavior?

The number density of the first save is less than expected by a factor of ~5% or 17%, depending on the grid resolution.

What is the expected correct behavior?

The number density of the first save should be 1e20 cm-3 in the outer region and 4e18 cm-3 in the inner region.

Relevant logs and/or screenshots

This picture plots the ion density as a function of y position. I used the "xy_shrunk" subset which takes a longitudinal cross section and averaged between -2 and 2 microns in the x direction. DensityProfileBug_ResolutionComparison_v2

Best, Jesse

TomGoffrey commented 3 years ago

Just to check - this is the first snapshot produced, at t=0?

jgriffmc commented 3 years ago

Yes, that's right.

jgriffmc commented 3 years ago

DensityProfileBug_ResolutionComparison_v3

I just tested at a higher resolution of 40 nm (20 CPW) and the density is the same as for 80 nm resolution (10 CPW).

TomGoffrey commented 3 years ago

Seems to relate to the subset. The actual (non-subset) number density looks reasonable when I output and plot a slice through the middle.

I'm wondering if something is going awry with the use of +/- dz to select the subset in z. If I plot the 3 slices from that subset I get the correct profile in the middle slice, but the first and last slices are out by approx factor of 2. Setting the size of the subset to +/- 1 micron, and things seem better again.

jgriffmc commented 3 years ago

Interesting, thanks for checking it out. It's reassuring to hear that the issue appears to be the subset and not the particle loading.

Until I hear of a bug fix, your workaround seems reasonable. Thanks for your help!

TomGoffrey commented 3 years ago

I'm guessing you just want a slice of the data at z=0? If so I'd probably just ignore the first and last slices in your current snapshot and use the the remaining one.

Seems like there's always something off about the first and last slices. If I extend to +/- 2dz I get 5 slices . Suspect what's happening is the code is counting particles in the regions between +/-2dz (i.e. 4 cells), but placing them on a grid of 5 cells, and dividing the totals by dz.

I'd rather hoped that using +/-1.5 dz would work. The outer slices are better but still slightly off.

It's possible @keithbennett knows a better way to select a slice, but he's not at work until next week. It's likely he'll also be able to explain better what you're seeing

jgriffmc commented 3 years ago

Yes, I just want a slice at z=0. I have been using the middle slice from my snapshot which is what the previous plots were from and is scaled relative to the input deck. I had thought that you meant extending the z limit to +/- 1 micron recovered the correct the density for the middle slice at z=0. Is that what you meant?

TomGoffrey commented 3 years ago

Hmm, you're right, even the middle slice looks a little low, when compared to the middle slice of the full data set. Sorry, wasn't checking carefully enough. Seems like going to +/-2*dz is a bit better. The middle of a +/- 1 micron subset looks better again.

I'll have to look around at how the grids are defined for the subset. I'm not sure why the middle slices of two subsets centred on zero are different.

jgriffmc commented 3 years ago

Ok. I just did a sanity check on the middle slice of the full data set and got the right profile. It's also interesting that changing the grid resolution affects this at all.