-
Notifications
You must be signed in to change notification settings - Fork 49
Seeding examples for 1D environment of S&H 2012 as well as 2D environment of M&G2007 #1396
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
base: main
Are you sure you want to change the base?
Changes from 16 commits
d5ef600
7c30823
49f7d18
9015069
5e6fdca
0a33e15
da5bb28
6524516
8c7da10
abac174
363debf
c3994cb
c0ec55e
a421ca8
f274579
d115df9
79c823e
57fde0f
736435a
487cd38
9ac7c1c
b19f0e0
8322e5e
8f4968d
e16f59d
a78e508
ffc2fef
5a8dd9a
c6453dd
04f4376
9757a17
080fdd1
630a252
ac1f6e9
2e7fde1
c84f844
02a9c22
0cf8992
6633a6c
206488d
7668e89
6c2674e
45f54f6
1089381
9eb1cfc
5bceccf
eb061e9
d36c065
9582c87
fbcec0d
fb95201
5862e33
f3b2d24
220a4ea
8df53d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
jtbuch marked this conversation as resolved.
Show resolved
Hide resolved
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plot time on the x-axis in last cell figures
jtbuch marked this conversation as resolved.
Show resolved
Hide resolved
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doing np.random.seed(123)
...
formulae= Formulae(seed= np.random.randint(1000)),seems misleading - would it be more readable to pass the |
Large diffs are not rendered by default.
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the same as the |
| 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 |
Uh oh!
There was an error while loading. Please reload this page.