Skip to content

new particle_shape_and_density #1539

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions PySDM/formulae.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def __init__( # pylint: disable=too-many-locals
optical_albedo: str = "Null",
optical_depth: str = "Null",
particle_shape_and_density: str = "LiquidSpheres",
liquid_particle_shape: str = "LiquidSpheres",
ice_particle_shape: str = "IceSpheres",
terminal_velocity: str = "GunnKinzer1949",
air_dynamic_viscosity: str = "ZografosEtAl1987",
bulk_phase_partitioning: str = "Null",
Expand Down
3 changes: 0 additions & 3 deletions PySDM/physics/particle_shape_and_density/liquid_spheres.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,3 @@ def volume_to_mass(const, volume):
def radius_to_mass(const, radius):
return const.rho_w * const.PI_4_3 * np.power(radius, const.THREE)

@staticmethod
def reynolds_number(_, radius, velocity_wrt_air, dynamic_viscosity, density):
return 2 * radius * velocity_wrt_air * density / dynamic_viscosity
5 changes: 5 additions & 0 deletions PySDM/physics/particle_shape_ice/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
particle shape and density relationships for ice particles
"""

from .ice_spheres import IceSpheres
12 changes: 12 additions & 0 deletions PySDM/physics/particle_shape_ice/columnar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
columnar particles with constant density of ice
"""

class Columnar:
def __init__(self, const, _):
self.mass_density = const.rho_i

@staticmethod
def supports_mixed_phase(_=None):
return True

63 changes: 63 additions & 0 deletions PySDM/physics/particle_shape_ice/ice_spheres.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
spherical particles with constant density of ice
"""
from PySDM.physics.trivia import Trivia

class IceSpheres:
def __init__(self, const, _):
pass

@staticmethod
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that supports_mixed_phase within IceSpheres does not really convey much - should always be True

def supports_mixed_phase(_=None):
return True

@staticmethod
def mass_to_volume(const, mass):
return (
Trivia.volume_of_density_mass(const, const.rho_i, mass)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this will not work with the current implementation of Formulae. Everything in the physics folder is expected to take form of one-liners without calls to other than NumPy math functions. It will choke both in the GPU backend (where Trivia. will not work in C code), but likely also in Numba CPU backend for it does not allow non-Numba class accessors.

)

@staticmethod
def volume_to_mass(const, volume):
return (
Trivia.mass_of_density_volume(const.rho_i, volume)
)

@staticmethod
def volume_to_radius(const, volume):
return (
Trivia.radius(const, volume)
)

@staticmethod
def radius_to_volume(const, radius):
return (
Trivia.sphere_radius_to_volume(const, radius)
)

@staticmethod
def radius_to_mass(const, radius, mass_density):
return (
Trivia.sphere_radius_to_volume(const, radius) * const.rho_i
)

@staticmethod
def radius_to_area(const, radius):
return(
Trivia.area(const, radius)
)

@staticmethod
def mass_to_capacity(const, mass):
return(
Trivia.sphere_mass_to_radius(const, mass, const.rho_i,)
)

@staticmethod
def maximum_diameter(const, mass):
return(
Trivia.sphere_mass_to_radius(const, mass, const.rho_i) * 2
)



6 changes: 6 additions & 0 deletions PySDM/physics/particle_shape_liquid/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
particle shape and density relationships for liquid particles
"""

from .liquid_spheres import LiquidSpheres
from .porous_spheroids import PorousSpheroid
56 changes: 56 additions & 0 deletions PySDM/physics/particle_shape_liquid/liquid_spheres.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
spherical particles with constant density of ice
"""
from PySDM.physics.trivia import Trivia

class LiquidSpheres:
def __init__(self, const, _):
pass

@staticmethod
def mass_to_volume(const, mass):
return (
Trivia.volume_of_density_mass(const, const.rho_w, mass)
)

@staticmethod
def volume_to_mass(const, volume):
return (
Trivia.mass_of_density_volume(const.rho_w, volume)
)

@staticmethod
def volume_to_radius(const, volume):
return (
Trivia.radius(const, volume)
)

@staticmethod
def radius_to_volume(const, radius):
return (
Trivia.sphere_radius_to_volume(const, radius)
)

@staticmethod
def radius_to_mass(const, radius, mass_density):
return (
Trivia.sphere_radius_to_volume(const, radius) * const.rho_w
)

@staticmethod
def radius_to_area(const, radius):
return (
Trivia.area(const, radius)
)

@staticmethod
def mass_to_capacity(const, mass):
return (
Trivia.sphere_mass_to_radius(const, mass, const.rho_w, )
)

@staticmethod
def maximum_diameter(const, mass):
return (
Trivia.sphere_mass_to_radius(const, mass, const.rho_w) * 2
)
10 changes: 10 additions & 0 deletions PySDM/physics/particle_shape_liquid/porous_spheroids.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
for mixed-phase microphysics as in
[Shima et al. 2020](https://doi.org/10.5194/gmd-13-4107-2020)
"""


class PorousSpheroid: # pylint: disable=too-few-public-methods
@staticmethod
def supports_mixed_phase(_=None):
return True
21 changes: 18 additions & 3 deletions PySDM/physics/trivia.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,36 @@ def __init__(self, _):
pass

@staticmethod
def volume_of_density_mass(rho, m):
return m / rho
def volume_of_density_mass(rho, mass):
return mass / rho

@staticmethod
def mass_of_density_volume(rho, volume):
return volume * rho

# TODO: change name to sphere_volume_to_radius
@staticmethod
def radius(const, volume):
return np.power(volume / const.PI_4_3, const.ONE_THIRD)

# TODO: change name to sphere_radius_to_area
@staticmethod
def area(const, radius):
return const.PI * const.FOUR * np.power(radius, const.TWO)

@staticmethod
def volume(const, radius):
def sphere_radius_to_volume(const, radius):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good point!

return const.PI_4_3 * np.power(radius, const.THREE)

@staticmethod
def sphere_radius_to_mass(const, radius, density):
return const.PI_4_3 * np.power(radius, const.THREE) * density

@staticmethod
def sphere_mass_to_radius(const, mass, density):
return const.PI_4_3 * np.power(radius, const.THREE) * density

# TODO: remove this. There is already sphere_radius_to_area
@staticmethod
def sphere_surface(const, diameter):
return const.PI * diameter**2
Expand Down
Loading