Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ventilation coefficient (Pruppacher & Rasmussen 1979 & Froessling 1938) + Reynolds number attr + air dynamic viscosity formulae + unit tests (incl. drop size changes upon ventilation-in-parcel-below-cloud vs. no-ventilation) + refactor of env vars __getitem__ logic #1282

Merged
merged 15 commits into from
Mar 14, 2024

Conversation

kaitlyn-loftus
Copy link
Collaborator

@kaitlyn-loftus kaitlyn-loftus commented Feb 19, 2024

First attempt to add ventilation coefficient from Pruppacher & Rasmussen (1979)).

Added methods for air dynamic viscosity, particle Reynolds number, and air Schmidt number to support ventilation coefficient calculation.

Tried to add basic tests for dynamic viscosity and ventilation coefficient calculation but don't think I activated them...

@slayoo
Copy link
Member

slayoo commented Feb 19, 2024

@kaitlyn-loftus, thanks!!!

For all PRs, we run the CI workflow in several steps, on of the first featuring pylint check (https://pylint.readthedocs.io/). Here it complains a bit:

************* Module PySDM.physics.ventilation.pruppacher_rasmussen_1979
PySDM/physics/ventilation/pruppacher_rasmussen_1979.py:2:0: C0301: Line too long (110/100) (line-too-long)
PySDM/physics/ventilation/pruppacher_rasmussen_1979.py:3:0: C0301: Line too long (107/100) (line-too-long)
PySDM/physics/ventilation/pruppacher_rasmussen_1979.py:5:0: C0301: Line too long (182/100) (line-too-long)
PySDM/physics/ventilation/pruppacher_rasmussen_1979.py:69:0: C0301: Line too long (131/100) (line-too-long)
PySDM/physics/ventilation/pruppacher_rasmussen_1979.py:83:0: C0301: Line too long (122/100) (line-too-long)
PySDM/physics/ventilation/pruppacher_rasmussen_1979.py:17:4: C2401: Function name "calcηairEarth" contains a non-ASCII character, consider renaming it. (non-ascii-name)
PySDM/physics/ventilation/pruppacher_rasmussen_1979.py:37:42: C2401: Argument name "ηair" contains a non-ASCII character, consider renaming it. (non-ascii-name)
PySDM/physics/ventilation/pruppacher_rasmussen_1979.py:37:49: C2401: Argument name "ρair" contains a non-ASCII character, consider renaming it. (non-ascii-name)
PySDM/physics/ventilation/pruppacher_rasmussen_1979.py:53:15: C2401: Argument name "ηair" contains a non-ASCII character, consider renaming it. (non-ascii-name)
PySDM/physics/ventilation/pruppacher_rasmussen_1979.py:53:25: C2401: Argument name "ρair" contains a non-ASCII character, consider renaming it. (non-ascii-name)
PySDM/physics/ventilation/pruppacher_rasmussen_1979.py:121:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return)
************* Module tests.smoke_tests.no_env.pruppacher_rasmussen_1979.test_dynvisvT
tests/smoke_tests/no_env/pruppacher_rasmussen_1979/test_dynvisvT.py:28:0: C2401: Function name "test_ηvT_figA5" contains a non-ASCII character, consider renaming it. (non-ascii-name)
tests/smoke_tests/no_env/pruppacher_rasmussen_1979/test_dynvisvT.py:28:23: C2401: Argument name "η" contains a non-ASCII character, consider renaming it. (non-ascii-name)
tests/smoke_tests/no_env/pruppacher_rasmussen_1979/test_dynvisvT.py:30:4: C2401: Variable name "η_test" contains a non-ASCII character, consider renaming it. (non-ascii-name)

For this reason, most of the tests were not run.
To check how to execute pylint locally, see: https://github.com/open-atmos/python-dev-hints/wiki/Pylint-FAQ

The smoke_tests folder is meant for tests that cannot be called "unit tests" for they involve executing multiple units of code. Here, I'd say you've implemented exactly what unit test should look like, so I'd suggest moving the new tests into PySDM/tests/unit_tests/physics. Any '.py file the begins with test_ will be included in the test run, there is no need to activate it.

To run the unit tests locally, executing pytest tests/unit_tests should be enough.

Thanks again!

@slayoo
Copy link
Member

slayoo commented Feb 19, 2024

Thank you!
The new test was executed and passed! (part of thenojit_and_codecov job which runs with Numba JIT turned off):
https://github.com/open-atmos/PySDM/actions/runs/7966038711/job/21746648231?pr=1282#step:4:808

@kaitlyn-loftus
Copy link
Collaborator Author

Great!! Thanks for explaining. I originally ran the pylint tests before staging the new files, so none of them got checked 😅

@slayoo
Copy link
Member

slayoo commented Feb 20, 2024

Thinking out loud, a next step here could be to add a new super-particle attribute: Reynolds number.
The calculation of it would go to backends which would call the newly introduced formula.
Then, within condensation/evaporation dynamic, this attribute would be available in case Formulae was instantiated with a non-neglect ventilation specified... please give me a few days to come up with a draft code - will push it into this PR's branch when ready.

@slayoo
Copy link
Member

slayoo commented Feb 28, 2024

@kaitlyn-loftus, in the above commit 9c2269f, there are some refactors towards making the ventilation coefficient being used inside condensation/evaporation solver. Added also more unit tests and a simpler "classic" formula from Froessling 1938 for reference. Please have a look if the changes look OK? Next step on my side: use the ventilation coefficient in the condensation solver - stay tuned, thanks

@kaitlyn-loftus
Copy link
Collaborator Author

kaitlyn-loftus commented Feb 28, 2024

@slayoo these changes look good. Thanks for fixing the air density to include the water vapor contribution; I had meant to flag that as a todo. The only potential issue I see is how the ventilation_coefficient method in PySDM/physics/ventilation/pruppacher_rasmussen_1979.py would handle sqrt_re_times_cbrt_sc=const.PRUPPACHER_RASMUSSEN_1979_XTHRES. This looks to me like it would give NaN (unless there is some clever handling elsewhere in the code).

@slayoo
Copy link
Member

slayoo commented Feb 28, 2024

The only potential issue I see is how the ventilation_coefficient method in PySDM/physics/ventilation/pruppacher_rasmussen_1979.py would handle sqrt_re_times_cbrt_sc=const.PRUPPACHER_RASMUSSEN_1979_XTHRES. This looks to me like it would give NaN (unless there is some clever handling elsewhere in the code).

Very valid point! Thanks, @kaitlyn-loftus
Here's a fix with a new test added checking behavior at the threshold value: 4917da4

@kaitlyn-loftus
Copy link
Collaborator Author

I think this will still give 0 at the threshold, instead of ~1.02. Is np.heaviside friendly with the CPU and GPU accelerators?

@slayoo
Copy link
Member

slayoo commented Feb 29, 2024

I think this will still give 0 at the threshold, instead of ~1.02. Is np.heaviside friendly with the CPU and GPU accelerators?

Thanks, @kaitlyn-loftus !
Hopefully fixed in f886fec

We don't have yet any tests covering GPU for this, so let's address GPU compatibility when we will get there...
Added an assert for the value (which seems to be around 1.2)

@slayoo
Copy link
Member

slayoo commented Mar 8, 2024

@kaitlyn-loftus just a quick update: here's a fresh PR introducing a refactor of the CPU condensation logic which is meant to make the introduction of the ventilation factor there much simpler - #1291

@slayoo slayoo force-pushed the add-ventilation-coeff-PR79 branch from f886fec to 0e365a7 Compare March 11, 2024 13:30
@slayoo
Copy link
Member

slayoo commented Mar 13, 2024

@kaitlyn-loftus, the a40ca41 commit above contains draft of code for actually using the ventilation coeffs in condensation integrator. This includes a basic test depicting that evaporation of a single droplet in subsaturated env proceeds faster if ventilation if taken into account: https://github.com/open-atmos/PySDM/blob/a40ca41377ecb8e57f68d83cf81e605071511147/tests/unit_tests/dynamics/condensation/test_ventilation.py

Stay tuned for updated GPU code.

@slayoo
Copy link
Member

slayoo commented Mar 14, 2024

@kaitlyn-loftus, CI green! :)
Please have a look, happy to merge soon and start working on 1D and 2D examples featuring ventilation!
(also, this will be super important for the isotope fractionation developments)

@slayoo slayoo changed the title add ventilation coefficient from Pruppacher & Rasmussen (1979) add ventilation coefficient (Pruppacher & Rasmussen 1979 & Froessling 1938) + Reynolds number attr + air dynamic viscosity formulae + unit & parcel test + refactor of env vars __getitem__ logic Mar 14, 2024
@slayoo slayoo changed the title add ventilation coefficient (Pruppacher & Rasmussen 1979 & Froessling 1938) + Reynolds number attr + air dynamic viscosity formulae + unit & parcel test + refactor of env vars __getitem__ logic add ventilation coefficient (Pruppacher & Rasmussen 1979 & Froessling 1938) + Reynolds number attr + air dynamic viscosity formulae + unit tests (incl. drop size changes upon ventilation-in-parcel-below-cloud vs. no-ventilation) + refactor of env vars __getitem__ logic Mar 14, 2024
@kaitlyn-loftus kaitlyn-loftus marked this pull request as ready for review March 14, 2024 13:58
@kaitlyn-loftus
Copy link
Collaborator Author

great news!

@slayoo
Copy link
Member

slayoo commented Mar 14, 2024

OK, I'm merging then, and will follow right away with a new release.
Thank you @kaitlyn-loftus!!!

@slayoo slayoo added this pull request to the merge queue Mar 14, 2024
Merged via the queue into open-atmos:main with commit dc052ac Mar 14, 2024
107 checks passed
bhiogade pushed a commit to bhiogade/PySDM that referenced this pull request Mar 22, 2024
… 1938) + Reynolds number attr + air dynamic viscosity formulae + unit tests (incl. drop size changes upon ventilation-in-parcel-below-cloud vs. no-ventilation) + refactor of env vars __getitem__ logic (open-atmos#1282)

Co-authored-by: Sylwester Arabas <sylwester.arabas@agh.edu.pl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants