PySDM icon indicating copy to clipboard operation
PySDM copied to clipboard

Assert error on n_in_dv in spectral sampling

Open claresinger opened this issue 1 year ago • 1 comments

Depending on the parameter values of the aerosol distribution, sometimes I need to lower significant to 5 or even 4. I haven't noticed a pattern for which values cause an error (e.g. sometimes N_a = 50 is fine sometimes it leads to error).

https://github.com/claresinger/PySDM/blob/e7840a3d3e18cd26df04f361504096769051fae2/examples/PySDM_examples/Singer_Ward/parcel.py#L58

https://github.com/claresinger/PySDM/blob/e7840a3d3e18cd26df04f361504096769051fae2/examples/PySDM_examples/Singer_Ward/aerosol.py#L53

I get errors like

AssertionError: 
Items are not equal to 5 significant digits:
 ACTUAL: 49998999.99999998
 DESIRED: 49999999.99999999

claresinger avatar Sep 30 '24 18:09 claresinger

So, the assert tells us that after performing sampling, the total aerosol number concentration differs from the analytical one by ca. 0.002%, which is clearly a small difference given that we only sample within a finite cdf range:
https://github.com/open-atmos/PySDM/blob/163b6d9b805cacfd9adc02023d776bff8f42dae9/PySDM/initialisation/sampling/spectral_sampling.py#L11

Increasing the number of super-droplets or altering the above range could help here (via the optional size_range argument to ConstantMultiplicity ctor)

slayoo avatar Sep 30 '24 21:09 slayoo

closing as this is rather a feature than a bug, and both the assert and the error make sense

slayoo avatar Nov 24 '24 23:11 slayoo