PySDM-examples 2.69__py3-none-any.whl → 2.71__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,7 @@
1
+ from functools import cached_property
2
+
1
3
  import numpy as np
4
+
2
5
  from PyMPDATA import Options, ScalarField, Solver, Stepper, VectorField
3
6
  from PyMPDATA.boundary_conditions import Extrapolated
4
7
 
@@ -19,41 +22,55 @@ class MPDATA_1D:
19
22
  self.dt = dt
20
23
  self.advector_of_t = advector_of_t
21
24
 
22
- grid = (nz,)
23
- options = Options(
25
+ self._grid = (nz,)
26
+ self._options = Options(
24
27
  n_iters=mpdata_settings["n_iters"],
25
28
  infinite_gauge=mpdata_settings["iga"],
26
29
  nonoscillatory=mpdata_settings["fct"],
27
30
  third_order_terms=mpdata_settings["tot"],
28
31
  )
29
- stepper = Stepper(options=options, grid=grid, non_unit_g_factor=True)
30
32
  bcs = (Extrapolated(),)
31
- zZ_scalar = arakawa_c.z_scalar_coord(grid) / nz
32
- g_factor = ScalarField(
33
+ zZ_scalar = arakawa_c.z_scalar_coord(self._grid) / nz
34
+ self._g_factor = ScalarField(
33
35
  data=g_factor_of_zZ(zZ_scalar),
34
- halo=options.n_halo,
36
+ halo=self._options.n_halo,
35
37
  boundary_conditions=bcs,
36
38
  )
37
- advector = VectorField(
39
+ self._advector = VectorField(
38
40
  data=(np.full(nz + 1, advector_of_t(0)),),
39
- halo=options.n_halo,
41
+ halo=self._options.n_halo,
40
42
  boundary_conditions=bcs,
41
43
  )
42
- self.advectee = ScalarField(
44
+ self._advectee = ScalarField(
43
45
  data=advectee_of_zZ_at_t0(zZ_scalar),
44
- halo=options.n_halo,
46
+ halo=self._options.n_halo,
45
47
  boundary_conditions=bcs,
46
48
  )
47
- self.solver = Solver(
48
- stepper=stepper,
49
- advectee=self.advectee,
50
- advector=advector,
51
- g_factor=g_factor,
49
+
50
+ @cached_property
51
+ def solver(self):
52
+ return Solver(
53
+ stepper=Stepper(
54
+ options=self._options, grid=self._grid, non_unit_g_factor=True
55
+ ),
56
+ advectee=self._advectee,
57
+ advector=self._advector,
58
+ g_factor=self._g_factor,
52
59
  )
53
60
 
61
+ @property
62
+ def solver_cached(self):
63
+ return "solver" in self.__dict__
64
+
65
+ @property
66
+ def advectee(self):
67
+ return (self.solver.advectee if self.solver_cached else self._advectee).get()
68
+
54
69
  @property
55
70
  def advector(self):
56
- return self.solver.advector.get_component(0)
71
+ return (
72
+ self.solver.advector if self.solver_cached else self._advector
73
+ ).get_component(0)
57
74
 
58
75
  def update_advector_field(self):
59
76
  self.__t += 0.5 * self.dt
@@ -61,5 +78,5 @@ class MPDATA_1D:
61
78
  np.testing.assert_array_less(np.abs(self.advector), 1)
62
79
  self.__t += 0.5 * self.dt
63
80
 
64
- def __call__(self):
81
+ def __call__(self, _):
65
82
  self.solver.advance(1)
@@ -46,7 +46,7 @@ class Simulation:
46
46
  z_above_reservoir = zZ * (settings.nz * settings.dz) + self.z0
47
47
  return z_above_reservoir
48
48
 
49
- self.mpdata = MPDATA_1D(
49
+ mpdata = MPDATA_1D(
50
50
  nz=settings.nz,
51
51
  dt=settings.dt,
52
52
  mpdata_settings=settings.mpdata_settings,
@@ -79,7 +79,7 @@ class Simulation:
79
79
  update_thd=settings.condensation_update_thd,
80
80
  )
81
81
  )
82
- self.builder.add_dynamic(EulerianAdvection(self.mpdata))
82
+ self.builder.add_dynamic(EulerianAdvection(mpdata))
83
83
 
84
84
  self.products = []
85
85
  if settings.precip:
@@ -257,10 +257,11 @@ class Simulation:
257
257
 
258
258
  self.save(0)
259
259
  for step in range(self.nt):
260
- self.mpdata.update_advector_field()
260
+ mpdata = self.particulator.dynamics["EulerianAdvection"].solvers
261
+ mpdata.update_advector_field()
261
262
  if "Displacement" in self.particulator.dynamics:
262
263
  self.particulator.dynamics["Displacement"].upload_courant_field(
263
- (self.mpdata.advector / self.g_factor_vec,)
264
+ (mpdata.advector / self.g_factor_vec,)
264
265
  )
265
266
  self.particulator.run(steps=1)
266
267
  self.save(step + 1)
@@ -348,10 +348,15 @@ class GUISettings:
348
348
  return widget.value
349
349
  raise NotImplementedError()
350
350
 
351
- def stream_function(self, xX, zZ, _):
351
+ @property
352
+ def stream_function(self):
352
353
  assert hasattr(self.__settings, "rhod_w_max")
353
354
  self.__settings.rhod_w_max = self.ui_rhod_w_max.value
354
- return self.__settings.stream_function(xX, zZ, _)
355
+
356
+ def fun(xX, zZ, _):
357
+ return self.__settings.stream_function(xX, zZ, _)
358
+
359
+ return fun
355
360
 
356
361
  @property
357
362
  def freezing_inp_spec(self):
@@ -1,4 +1,5 @@
1
1
  import inspect
2
+ from functools import cached_property
2
3
  from threading import Thread
3
4
 
4
5
  import numpy as np
@@ -24,13 +25,12 @@ class MPDATA_2D:
24
25
  dt,
25
26
  grid,
26
27
  size,
27
- displacement,
28
28
  n_iters=2,
29
29
  infinite_gauge=True,
30
30
  nonoscillatory=True,
31
31
  third_order_terms=False
32
32
  ):
33
- self.grid = grid
33
+ self._grid = grid
34
34
  self.size = size
35
35
  self.dt = dt
36
36
  self.stream_function = stream_function
@@ -39,96 +39,103 @@ class MPDATA_2D:
39
39
  )
40
40
  self.asynchronous = False
41
41
  self.thread: (Thread, None) = None
42
- self.displacement = displacement
43
42
  self.t = 0
43
+ self.advectees = advectees
44
44
 
45
- options = Options(
45
+ self._options = Options(
46
46
  n_iters=n_iters,
47
47
  infinite_gauge=infinite_gauge,
48
48
  nonoscillatory=nonoscillatory,
49
49
  third_order_terms=third_order_terms,
50
50
  )
51
+
52
+ self.g_factor = make_rhod(grid, rhod_of_zZ)
53
+ self.g_factor_vec = (
54
+ rhod_of_zZ(zZ=x_vec_coord(grid)[-1]),
55
+ rhod_of_zZ(zZ=z_vec_coord(grid)[-1]),
56
+ )
57
+
58
+ @cached_property
59
+ def mpdatas(self):
51
60
  disable_threads_if_needed = {}
52
61
  if not conf.JIT_FLAGS["parallel"]:
53
62
  disable_threads_if_needed["n_threads"] = 1
54
63
 
55
64
  stepper = Stepper(
56
- options=options,
57
- grid=self.grid,
65
+ options=self._options,
66
+ grid=self._grid,
58
67
  non_unit_g_factor=True,
59
68
  **disable_threads_if_needed
60
69
  )
61
70
 
62
71
  advector_impl = VectorField(
63
72
  (
64
- np.full((grid[0] + 1, grid[1]), np.nan),
65
- np.full((grid[0], grid[1] + 1), np.nan),
73
+ np.full((self._grid[0] + 1, self._grid[1]), np.nan),
74
+ np.full((self._grid[0], self._grid[1] + 1), np.nan),
66
75
  ),
67
- halo=options.n_halo,
76
+ halo=self._options.n_halo,
68
77
  boundary_conditions=(Periodic(), Periodic()),
69
78
  )
70
79
 
71
- g_factor = make_rhod(self.grid, rhod_of_zZ)
72
80
  g_factor_impl = ScalarField(
73
- g_factor.astype(dtype=options.dtype),
74
- halo=options.n_halo,
81
+ self.g_factor.astype(dtype=self._options.dtype),
82
+ halo=self._options.n_halo,
75
83
  boundary_conditions=(Periodic(), Periodic()),
76
84
  )
77
85
 
78
- self.g_factor_vec = (
79
- rhod_of_zZ(zZ=x_vec_coord(self.grid)[-1]),
80
- rhod_of_zZ(zZ=z_vec_coord(self.grid)[-1]),
81
- )
82
- self.mpdatas = {}
83
- for k, v in advectees.items():
86
+ mpdatas = {}
87
+ for k, v in self.advectees.items():
84
88
  advectee_impl = ScalarField(
85
- np.asarray(v, dtype=options.dtype),
86
- halo=options.n_halo,
89
+ np.asarray(v, dtype=self._options.dtype),
90
+ halo=self._options.n_halo,
87
91
  boundary_conditions=(Periodic(), Periodic()),
88
92
  )
89
- self.mpdatas[k] = Solver(
93
+ mpdatas[k] = Solver(
90
94
  stepper=stepper,
91
95
  advectee=advectee_impl,
92
96
  advector=advector_impl,
93
97
  g_factor=g_factor_impl,
94
98
  )
99
+ return mpdatas
95
100
 
96
- def __getitem__(self, item):
97
- return self.mpdatas[item]
101
+ def __getitem__(self, key: str):
102
+ if "mpdatas" in self.__dict__:
103
+ return self.mpdatas[key].advectee.get()
104
+ return self.advectees[key]
98
105
 
99
- def __call__(self):
106
+ def __call__(self, displacement):
100
107
  if self.asynchronous:
101
108
  self.thread = Thread(target=self.step, args=())
102
109
  self.thread.start()
103
110
  else:
104
- self.step()
111
+ self.step(displacement)
105
112
 
106
113
  def wait(self):
107
114
  if self.asynchronous:
108
115
  if self.thread is not None:
109
116
  self.thread.join()
110
117
 
111
- def refresh_advector(self):
118
+ def refresh_advector(self, displacement):
112
119
  for mpdata in self.mpdatas.values():
113
120
  advector = nondivergent_vector_field_2d(
114
- self.grid, self.size, self.dt, self.stream_function, t=self.t
121
+ self._grid, self.size, self.dt, self.stream_function, t=self.t
115
122
  )
116
- for d in range(len(self.grid)):
123
+ for d in range(len(self._grid)):
117
124
  np.testing.assert_array_less(np.abs(advector[d]), 1)
118
125
  mpdata.advector.get_component(d)[:] = advector[d]
119
- if self.displacement is not None:
120
- for d in range(len(self.grid)):
126
+ if displacement is not None:
127
+ for d in range(len(self._grid)):
121
128
  advector[d] /= self.g_factor_vec[d]
122
- self.displacement.upload_courant_field(advector)
129
+ displacement.upload_courant_field(advector)
123
130
  break # the advector field is shared
124
131
 
125
- def step(self):
132
+ def step(self, displacement):
126
133
  if not self.stream_function_time_dependent and self.t == 0:
127
- self.refresh_advector()
134
+ self.refresh_advector(displacement)
128
135
 
129
136
  self.t += 0.5 * self.dt
130
137
  if self.stream_function_time_dependent:
131
- self.refresh_advector()
138
+ self.refresh_advector(displacement)
132
139
  for mpdata in self.mpdatas.values():
133
140
  mpdata.advance(1)
134
141
  self.t += 0.5 * self.dt
@@ -66,13 +66,6 @@ class Simulation:
66
66
  **kwargs,
67
67
  )
68
68
  builder.add_dynamic(condensation)
69
- displacement = None
70
- if self.settings.processes["particle advection"]:
71
- displacement = Displacement(
72
- enable_sedimentation=self.settings.processes["sedimentation"],
73
- adaptive=self.settings.displacement_adaptive,
74
- rtol=self.settings.displacement_rtol,
75
- )
76
69
  if self.settings.processes["fluid advection"]:
77
70
  initial_profiles = {
78
71
  "th": self.settings.initial_dry_potential_temperature_profile,
@@ -92,7 +85,6 @@ class Simulation:
92
85
  dt=self.settings.dt,
93
86
  grid=self.settings.grid,
94
87
  size=self.settings.size,
95
- displacement=displacement,
96
88
  n_iters=self.settings.mpdata_iters,
97
89
  infinite_gauge=self.settings.mpdata_iga,
98
90
  nonoscillatory=self.settings.mpdata_fct,
@@ -100,7 +92,13 @@ class Simulation:
100
92
  )
101
93
  builder.add_dynamic(EulerianAdvection(solver))
102
94
  if self.settings.processes["particle advection"]:
103
- builder.add_dynamic(displacement)
95
+ builder.add_dynamic(
96
+ Displacement(
97
+ enable_sedimentation=self.settings.processes["sedimentation"],
98
+ adaptive=self.settings.displacement_adaptive,
99
+ rtol=self.settings.displacement_rtol,
100
+ )
101
+ )
104
102
  if (
105
103
  self.settings.processes["coalescence"]
106
104
  and self.settings.processes["breakup"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PySDM-examples
3
- Version: 2.69
3
+ Version: 2.71
4
4
  Summary: PySDM usage examples reproducing results from literature and depicting how to use PySDM from Python Jupyter notebooks
5
5
  Home-page: https://github.com/open-atmos/PySDM
6
6
  Author: https://github.com/open-atmos/PySDM/graphs/contributors
@@ -22,8 +22,8 @@ Requires-Dist: seaborn
22
22
  Requires-Dist: numdifftools
23
23
  Requires-Dist: vtk
24
24
  Provides-Extra: tests
25
- Requires-Dist: pytest ; extra == 'tests'
26
- Requires-Dist: nbconvert ; extra == 'tests'
25
+ Requires-Dist: pytest; extra == "tests"
26
+ Requires-Dist: nbconvert; extra == "tests"
27
27
 
28
28
  # PySDM-examples
29
29
 
@@ -97,10 +97,10 @@ PySDM_examples/Shima_et_al_2009/tutorial_example.py,sha256=GQp-sHFVHOXgETTTcme5p
97
97
  PySDM_examples/Shima_et_al_2009/tutorial_plotter.py,sha256=5gV9T0YnUFKuAL77ci0cmYMi6h9IvNi-X_J3_Nv6tIs,4191
98
98
  PySDM_examples/Shima_et_al_2009/tutorial_settings.py,sha256=nTe_rKAIPpXwnh52mDBrU4_We5lLu_1140jzXIlLY84,1176
99
99
  PySDM_examples/Shipway_and_Hill_2012/__init__.py,sha256=fVgTFoG-sHDYawCJhZdUrqqziLBiJKExw3_tAQeXQ5o,247
100
- PySDM_examples/Shipway_and_Hill_2012/mpdata_1d.py,sha256=GfbGXQFAVJ2rYnkhwKKESRLPDfJJeL0Qs1h1pZUjlWo,1907
100
+ PySDM_examples/Shipway_and_Hill_2012/mpdata_1d.py,sha256=8l7Zcv2PluBXYZO0qQ4j4_otLcLPtPWSGJJgzRfxEKs,2341
101
101
  PySDM_examples/Shipway_and_Hill_2012/plot.py,sha256=Q6lnGWE3oSDKV_F1qKUIihhbYABQ3S1A1qg7Q2rXwn4,3606
102
102
  PySDM_examples/Shipway_and_Hill_2012/settings.py,sha256=t6qypOnYniOJtkvlyeET8mY4zmF32qz0zs7ssdfoTOY,6458
103
- PySDM_examples/Shipway_and_Hill_2012/simulation.py,sha256=ixOWbDLpmOKrwGw4Pmpqo2ghB8gK41oSMi-d0QA_gNY,10275
103
+ PySDM_examples/Shipway_and_Hill_2012/simulation.py,sha256=E5c9kmC5qQ89ca_CQ3OY3qHLvRMrs7N5HLhov-K1tZo,10332
104
104
  PySDM_examples/Singer_Ward/__init__.py,sha256=wLus4IEzXkeOKCR3Dn2tM9PqNW9X7tjBiMymLvBow-c,31
105
105
  PySDM_examples/Singer_Ward/aerosol.py,sha256=H7TcvI94Wc-IvhTMFshFaJRJY3eUjihAlSdNxVKZzL0,5805
106
106
  PySDM_examples/Srivastava_1982/__init__.py,sha256=u7RxFGW08DIfwKU2yHpEQiiNlfz7F3GyYR4TV9LA7Ww,509
@@ -112,12 +112,12 @@ PySDM_examples/Szumowski_et_al_1998/__init__.py,sha256=L9UucV9lyb08Hkzs1zYI9cxmN
112
112
  PySDM_examples/Szumowski_et_al_1998/fields.py,sha256=tcR2MAB7azOLF955-ACHJU6v7aJxxpDXVdSIMQTbHEg,1584
113
113
  PySDM_examples/Szumowski_et_al_1998/gui.py,sha256=Vjt_ahdSl74NEjbZ-WxhK9eU3H2bqifjibPp6hy2DME,1309
114
114
  PySDM_examples/Szumowski_et_al_1998/gui_controller.py,sha256=AsP78e9bcGSP81kfDet_5fxpthlHsjDyJxHknvN2EgI,4283
115
- PySDM_examples/Szumowski_et_al_1998/gui_settings.py,sha256=3-Ox7GBHbEe30_znfry_UqAVU6ZTvJsCSRwMIw6_cJI,14400
115
+ PySDM_examples/Szumowski_et_al_1998/gui_settings.py,sha256=1V4ZXGn_vewInoc1jErS3WLapKR3acKus4NcTwsiFUA,14456
116
116
  PySDM_examples/Szumowski_et_al_1998/gui_viewer.py,sha256=JZFAfD9FXHS5msVYAzccoF5rhHlb6hdwY28Q6lAdJD4,13164
117
117
  PySDM_examples/Szumowski_et_al_1998/make_default_product_collection.py,sha256=m8qiUHsCaGSBo_b8MqhHtO4a-MBuhG42XHBn42Vy6Cw,4682
118
- PySDM_examples/Szumowski_et_al_1998/mpdata_2d.py,sha256=41F3D4Kx_Um01wqOlkDSu8gzbwy47OewK535PK-Ii54,4137
118
+ PySDM_examples/Szumowski_et_al_1998/mpdata_2d.py,sha256=Y3Qimm2hSDvtJxdc9mBoPCftMFSDTaOE7dSDd2lt_DU,4441
119
119
  PySDM_examples/Szumowski_et_al_1998/plots.py,sha256=fzeluxlLF9VbSMmcu2wvd9WPl3ApIuA0jouwOh6rJHA,7001
120
- PySDM_examples/Szumowski_et_al_1998/simulation.py,sha256=bEkYxTiP8S7MYzz2SlPLqeOGLiGibs4uaE7lTOBD8AA,9941
120
+ PySDM_examples/Szumowski_et_al_1998/simulation.py,sha256=ek2Jb4uTplCUl49dF6Sesi1S8neLtRjgxjfzxH9DDSw,9818
121
121
  PySDM_examples/Szumowski_et_al_1998/sounding.py,sha256=vk3KHRPrBbZpz6QCqj2RtWyEpl_N7jSMR-zoDWM_ZVQ,1440
122
122
  PySDM_examples/Szumowski_et_al_1998/storage.py,sha256=NaGoujCRLubSEbhLA0QZDaSkATpJuF09HCnGdWQzcxQ,2579
123
123
  PySDM_examples/Van_Hook_1968/__init__.py,sha256=nTGyMcf6D4l6Ib0hMwyx4es1nX5dpuPbM9AYEleaIPE,119
@@ -145,7 +145,7 @@ PySDM_examples/utils/read_vtk_1d.py,sha256=7_3sagEbX_FxqFuGkFWdwQapd1-9echFghU8T
145
145
  PySDM_examples/utils/widgets/__init__.py,sha256=U67WZ2YDcXSocMraI7pzcMxCfcxzXNqehDzoG6ogsh4,519
146
146
  PySDM_examples/utils/widgets/freezer.py,sha256=tFlZWShXUzA2X0cxgeE44N1g9kD33q3KQWZBqkgBP0A,407
147
147
  PySDM_examples/utils/widgets/progbar_updater.py,sha256=3uhG32QkAiSM3dTV7DoROJl7fAUNA6ZsJEIKSg3tdmk,267
148
- PySDM_examples-2.69.dist-info/METADATA,sha256=vBigxdGedbaPqaDWDkaQWk7Tz1LFUdqBHzfbSYnFBx8,40752
149
- PySDM_examples-2.69.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
150
- PySDM_examples-2.69.dist-info/top_level.txt,sha256=axw2inuuYKPWkQhzBYtkZJTPDlo5LrpGLOA0iSAf9v0,15
151
- PySDM_examples-2.69.dist-info/RECORD,,
148
+ PySDM_examples-2.71.dist-info/METADATA,sha256=41B6XS2U-7Rz9BIf1ZvhURcHT-Ie7qVoxpbCwoXEz5U,40750
149
+ PySDM_examples-2.71.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
150
+ PySDM_examples-2.71.dist-info/top_level.txt,sha256=axw2inuuYKPWkQhzBYtkZJTPDlo5LrpGLOA0iSAf9v0,15
151
+ PySDM_examples-2.71.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: bdist_wheel (0.44.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5