-
Notifications
You must be signed in to change notification settings - Fork 36
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
Seeding example for 1D environment of S&H 2012 #1396
Open
jtbuch
wants to merge
12
commits into
open-atmos:main
Choose a base branch
from
jtbuch:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d5ef600
updated with sampling for X direction
jtbuch 7c30823
updated pre-commit hook
jtbuch 49f7d18
pruned branches following pylint
jtbuch 9015069
Merge branch 'open-atmos:main' into main
jtbuch 5e6fdca
spatial sampling for 2D flows
jtbuch 0a33e15
seeding example for 1D
jtbuch da5bb28
added new files for 1D seeding example
jtbuch 6524516
renamed file
jtbuch 8c7da10
merging latest version
jtbuch abac174
Merge branch 'open-atmos:main' into main
jtbuch 363debf
Merge branch 'main' of https://github.com/jtbuch/PySDM
jtbuch c3994cb
couple of minor fixes based on Clares comments
jtbuch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7,467 changes: 7,467 additions & 0 deletions
7,467
examples/PySDM_examples/seeding/SH2012_seeding.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
""" | ||
Single-column time-varying-updraft framework with moisture advection handled by | ||
[PyMPDATA](http://github.com/open-atmos/PyMPDATA/) | ||
""" | ||
|
||
import numpy as np | ||
|
||
from PySDM.environments.impl.moist import Moist | ||
|
||
from PySDM.impl import arakawa_c | ||
from PySDM.initialisation.equilibrate_wet_radii import equilibrate_wet_radii | ||
from PySDM.environments.impl import register_environment | ||
|
||
|
||
@register_environment() | ||
class Kinematic1D(Moist): | ||
def __init__(self, *, dt, mesh, thd_of_z, rhod_of_z, z0=0): | ||
super().__init__(dt, mesh, []) | ||
self.thd0 = thd_of_z(z0 + mesh.dz * arakawa_c.z_scalar_coord(mesh.grid)) | ||
self.rhod = rhod_of_z(z0 + mesh.dz * arakawa_c.z_scalar_coord(mesh.grid)) | ||
self.formulae = None | ||
|
||
def register(self, builder): | ||
super().register(builder) | ||
self.formulae = builder.particulator.formulae | ||
rhod = builder.particulator.Storage.from_ndarray(self.rhod) | ||
self._values["current"]["rhod"] = rhod | ||
self._tmp["rhod"] = rhod | ||
|
||
def get_water_vapour_mixing_ratio(self) -> np.ndarray: | ||
return self.particulator.dynamics["EulerianAdvection"].solvers.advectee | ||
|
||
def get_thd(self) -> np.ndarray: | ||
return self.thd0 | ||
|
||
def init_attributes( | ||
self, | ||
*, | ||
spatial_discretisation, | ||
spectral_discretisation, | ||
kappa, | ||
n_sd, | ||
z_part=None, | ||
collisions_only=False | ||
): | ||
super().sync() | ||
self.notify() | ||
|
||
attributes = {} | ||
with np.errstate(all="raise"): | ||
positions = spatial_discretisation.sample( | ||
backend=self.particulator.backend, | ||
grid=self.mesh.grid, | ||
n_sd=n_sd, | ||
z_part=z_part, | ||
) | ||
( | ||
attributes["cell id"], | ||
attributes["cell origin"], | ||
attributes["position in cell"], | ||
) = self.mesh.cellular_attributes(positions) | ||
|
||
if collisions_only: | ||
v_wet, n_per_kg = spectral_discretisation.sample( | ||
backend=self.particulator.backend, n_sd=n_sd | ||
) | ||
attributes["volume"] = v_wet | ||
else: | ||
r_dry, n_per_kg = spectral_discretisation.sample( | ||
backend=self.particulator.backend, n_sd=n_sd | ||
) | ||
attributes["dry volume"] = self.formulae.trivia.volume(radius=r_dry) | ||
attributes["kappa times dry volume"] = attributes["dry volume"] * kappa | ||
r_wet = equilibrate_wet_radii( | ||
r_dry=r_dry, | ||
environment=self, | ||
cell_id=attributes["cell id"], | ||
kappa_times_dry_volume=attributes["kappa times dry volume"], | ||
) | ||
attributes["volume"] = self.formulae.trivia.volume(radius=r_wet) | ||
|
||
rhod = self["rhod"].to_ndarray() | ||
cell_id = attributes["cell id"] | ||
domain_volume = np.prod(np.array(self.mesh.size)) | ||
|
||
attributes["multiplicity"] = n_per_kg * rhod[cell_id] * domain_volume | ||
|
||
return attributes | ||
|
||
@property | ||
def dv(self): | ||
return self.mesh.dv |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the cell origin and position in cell? where are these used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PySDM/PySDM/attributes/numerics/position_in_cell.py
Line 2 in b8a0d71
PySDM/PySDM/attributes/numerics/cell_origin.py
Line 2 in b8a0d71
These are used to define and track positions of particles in the domain (only used for >0D environments, so do not apply in the case of parcel env)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will use the
particulator.environment
argument to call the seeding function with default arguments when seeding in the parcel environment