open-atmos / PySDM

Pythonic particle-based (super-droplet) warm-rain/aqueous-chemistry cloud microphysics package with box, parcel & 1D/2D prescribed-flow examples in Python, Julia and Matlab
https://open-atmos.github.io/PySDM/
GNU General Public License v3.0
56 stars 30 forks source link

Assert error on n_in_dv in spectral sampling #1395

Open claresinger opened 2 days ago

claresinger commented 2 days ago

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
slayoo commented 2 days ago

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)