paddle 1.1.1__py3-none-any.whl → 1.1.3__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.
paddle/__init__.py CHANGED
@@ -3,8 +3,5 @@ from .write_profile import write_profile
3
3
  from .find_init_params import find_init_params
4
4
  from .evolve_kinetics import evolve_kinetics
5
5
 
6
- __all__ = ["setup_profile",
7
- "write_profile",
8
- "find_init_params",
9
- "evolve_kinetics"]
10
- __version__ = "1.1.1"
6
+ __all__ = ["setup_profile", "write_profile", "find_init_params", "evolve_kinetics"]
7
+ __version__ = "1.1.3"
paddle/crm.py CHANGED
@@ -4,20 +4,20 @@ import time
4
4
  import kintera
5
5
  import numpy as np
6
6
  from snapy import (
7
- index,
8
- MeshBlockOptions,
9
- MeshBlock,
10
- OutputOptions,
11
- NetcdfOutput,
12
- )
7
+ index,
8
+ MeshBlockOptions,
9
+ MeshBlock,
10
+ OutputOptions,
11
+ NetcdfOutput,
12
+ )
13
13
  from kintera import (
14
- ThermoOptions,
15
- ThermoX,
16
- KineticsOptions,
17
- Kinetics,
18
- )
14
+ ThermoOptions,
15
+ ThermoX,
16
+ KineticsOptions,
17
+ Kinetics,
18
+ )
19
19
 
20
- if __name__ == '__main__':
20
+ if __name__ == "__main__":
21
21
  # input file
22
22
  infile = "earth.yaml"
23
23
  device = "cpu"
@@ -46,7 +46,7 @@ if __name__ == '__main__':
46
46
 
47
47
  # set up initial condition
48
48
  w = setup_initial_condition(block, thermo_x)
49
- print("w = ", w[:,0,0,:])
49
+ print("w = ", w[:, 0, 0, :])
50
50
 
51
51
  # integration
52
52
  current_time = 0.0
@@ -70,7 +70,7 @@ if __name__ == '__main__':
70
70
  block.forward(dt, stage)
71
71
 
72
72
  # evolve kinetics
73
- u[index.icy:] += evolve_kinetics(block, kinet, thermo_x)
73
+ u[index.icy :] += evolve_kinetics(block, kinet, thermo_x)
74
74
 
75
75
  current_time += dt
76
76
  count += 1
paddle/evolve_kinetics.py CHANGED
@@ -2,12 +2,14 @@ import torch
2
2
  import snapy
3
3
  import kintera
4
4
 
5
+
5
6
  def evolve_kinetics(
6
7
  hydro_w: torch.Tensor,
7
- block: snapy.MeshBlock,
8
- kinet: kintera.Kinetics,
8
+ block: snapy.MeshBlock,
9
+ kinet: kintera.Kinetics,
9
10
  thermo_x: kintera.ThermoX,
10
- dt) -> torch.Tensor:
11
+ dt,
12
+ ) -> torch.Tensor:
11
13
  """
12
14
  Evolve the chemical kinetics for one time step using implicit method.
13
15
 
@@ -26,7 +28,7 @@ def evolve_kinetics(
26
28
 
27
29
  temp = eos.compute("W->T", (hydro_w,))
28
30
  pres = hydro_w[snapy.index.ipr]
29
- xfrac = thermo_y.compute("Y->X", (hydro_w[snapy.index.icy:],))
31
+ xfrac = thermo_y.compute("Y->X", (hydro_w[snapy.index.icy :],))
30
32
  conc = thermo_x.compute("TPX->V", (temp, pres, xfrac))
31
33
  cp_vol = thermo_x.compute("TV->cp", (temp, conc))
32
34
 
@@ -4,16 +4,18 @@ import numpy as np
4
4
 
5
5
  from .setup_profile import setup_profile
6
6
 
7
+
7
8
  def find_init_params(
8
- block: snapy.MeshBlock,
9
- param: dict[str, float],
10
- *,
11
- target_T: float=300.,
12
- target_P: float=1.e5,
13
- method: str="moist-adiabat",
14
- max_iter: int=50,
15
- ftol: float=1.e-2,
16
- verbose: bool=True):
9
+ block: snapy.MeshBlock,
10
+ param: dict[str, float],
11
+ *,
12
+ target_T: float = 300.0,
13
+ target_P: float = 1.0e5,
14
+ method: str = "moist-adiabat",
15
+ max_iter: int = 50,
16
+ ftol: float = 1.0e-2,
17
+ verbose: bool = True,
18
+ ):
17
19
  """Find initial parameters that yield desired T and P
18
20
 
19
21
  Args:
@@ -44,14 +46,15 @@ def find_init_params(
44
46
  temp = eos.compute("W->T", (w,)).squeeze()
45
47
 
46
48
  # calculate 1D pressure
47
- pres = w[snapy.index.ipr,...].squeeze()
49
+ pres = w[snapy.index.ipr, ...].squeeze()
48
50
 
49
51
  # temperature function
50
52
  t_func = interp1d(
51
53
  pres.log().cpu().numpy(),
52
54
  temp.log().cpu().numpy(),
53
55
  kind="linear",
54
- fill_value="extrapolate")
56
+ fill_value="extrapolate",
57
+ )
55
58
 
56
59
  temp1 = np.exp(t_func(np.log(target_P)))
57
60
  if verbose:
@@ -69,4 +72,3 @@ def find_init_params(
69
72
  count += 1
70
73
 
71
74
  raise RuntimeError("Failed to converge within the maximum number of iterations.")
72
-
paddle/setup_profile.py CHANGED
@@ -4,18 +4,19 @@ import torch
4
4
  import snapy
5
5
  import kintera
6
6
 
7
+
7
8
  def integrate_neutral(
8
- thermo_x: kintera.ThermoX,
9
- temp: torch.Tensor,
10
- pres: torch.Tensor,
11
- xfrac: torch.Tensor,
12
- grav: float,
13
- dz: float,
14
- max_iter: int = 100
15
- ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
9
+ thermo_x: kintera.ThermoX,
10
+ temp: torch.Tensor,
11
+ pres: torch.Tensor,
12
+ xfrac: torch.Tensor,
13
+ grav: float,
14
+ dz: float,
15
+ max_iter: int = 100,
16
+ ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
16
17
  """
17
18
  A neutral density profile assumes no cloud and:
18
-
19
+
19
20
  (1) dP/dz = -rho*g
20
21
  (2) d(rho)/dz = ...
21
22
 
@@ -68,15 +69,16 @@ def integrate_neutral(
68
69
 
69
70
  return temp2, pres2, xfrac2
70
71
 
72
+
71
73
  def integrate_dry_adiabat(
72
- thermo_x: kintera.ThermoX,
73
- temp: torch.Tensor,
74
- pres: torch.Tensor,
75
- xfrac: torch.Tensor,
76
- grav: float,
77
- dz: float,
78
- max_iter: int = 100
79
- ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
74
+ thermo_x: kintera.ThermoX,
75
+ temp: torch.Tensor,
76
+ pres: torch.Tensor,
77
+ xfrac: torch.Tensor,
78
+ grav: float,
79
+ dz: float,
80
+ max_iter: int = 100,
81
+ ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
80
82
  """
81
83
  A dry adiabatic profile assumes no cloud and:
82
84
 
@@ -84,12 +86,12 @@ def integrate_dry_adiabat(
84
86
  (2) dP/dz = -rho*g
85
87
 
86
88
  In discretized form:
87
-
89
+
88
90
  cp_bar = 0.5 * (cp(T_old) + cp(T_new))
89
91
  T_new = T_old - g/bar * dz
90
92
  rho_bar = 0.5 * (rho_old + rho_new)
91
93
  P_new = P_old - rho_bar * g * dz
92
-
94
+
93
95
  """
94
96
  conc1 = thermo_x.compute("TPX->V", [temp, pres, xfrac])
95
97
  cp1 = thermo_x.compute("TV->cp", [temp, conc1]) / conc1.sum(-1)
@@ -136,11 +138,10 @@ def integrate_dry_adiabat(
136
138
 
137
139
  return temp2, pres2, xfrac2
138
140
 
141
+
139
142
  def setup_profile(
140
- block: snapy.MeshBlock,
141
- param: dict[str, float] = {},
142
- method: str = "moist-adiabat"
143
- ) -> torch.Tensor:
143
+ block: snapy.MeshBlock, param: dict[str, float] = {}, method: str = "moist-adiabat"
144
+ ) -> torch.Tensor:
144
145
  """
145
146
  Set up an adiabatic initial condition for the mesh block.
146
147
 
@@ -175,16 +176,16 @@ def setup_profile(
175
176
  "moist-adiabat",
176
177
  "isothermal",
177
178
  "pseudo-adiabat",
178
- "neutral"
179
+ "neutral",
179
180
  ]
180
181
 
181
182
  if method not in valid_methods:
182
183
  raise ValueError(f"Invalid method '{method}'. Choose from {valid_methods}.")
183
184
 
184
- Ts = param.get("Ts", 300.)
185
- Ps = param.get("Ps", 1.e5)
185
+ Ts = param.get("Ts", 300.0)
186
+ Ps = param.get("Ps", 1.0e5)
186
187
  grav = param.get("grav", 9.8)
187
- Tmin = param.get("Tmin", 0.)
188
+ Tmin = param.get("Tmin", 0.0)
188
189
 
189
190
  # get handles to modules
190
191
  coord = block.module("hydro.coord")
@@ -204,8 +205,7 @@ def setup_profile(
204
205
  ny = len(thermo_y.options.species()) - 1
205
206
  nvar = 5 + ny
206
207
 
207
- w = torch.zeros((nvar, nc3, nc2, nc1),
208
- dtype=x1v.dtype, device=x1v.device)
208
+ w = torch.zeros((nvar, nc3, nc2, nc1), dtype=x1v.dtype, device=x1v.device)
209
209
 
210
210
  temp = Ts * torch.ones((nc3, nc2), dtype=w.dtype, device=w.device)
211
211
  pres = Ps * torch.ones((nc3, nc2), dtype=w.dtype, device=w.device)
@@ -216,7 +216,7 @@ def setup_profile(
216
216
  xfrac[..., index] = param.get(f"x{name}", 0.0)
217
217
 
218
218
  # dry air mole fraction
219
- xfrac[..., 0] = 1. - xfrac[..., 1:].sum(dim=-1)
219
+ xfrac[..., 0] = 1.0 - xfrac[..., 1:].sum(dim=-1)
220
220
 
221
221
  # start and end indices for the vertical direction
222
222
  # excluding ghost cells
@@ -227,7 +227,7 @@ def setup_profile(
227
227
  dz = coord.buffer("dx1f")[ifirst]
228
228
 
229
229
  # half a grid to cell center
230
- thermo_x.extrapolate_ad(temp, pres, xfrac, grav, dz / 2.);
230
+ thermo_x.extrapolate_ad(temp, pres, xfrac, grav, dz / 2.0)
231
231
 
232
232
  # adiabatic extrapolation
233
233
  if method == "isothermal":
@@ -245,17 +245,19 @@ def setup_profile(
245
245
  xfrac /= xfrac.sum(dim=-1, keepdim=True)
246
246
  conc = thermo_x.compute("TPX->V", [temp, pres, xfrac])
247
247
 
248
- w[snapy.index.ipr, ..., i] = pres;
248
+ w[snapy.index.ipr, ..., i] = pres
249
249
  w[snapy.index.idn, ..., i] = thermo_x.compute("V->D", [conc])
250
- w[snapy.index.icy:, ...,i] = thermo_x.compute("X->Y", [xfrac])
250
+ w[snapy.index.icy :, ..., i] = thermo_x.compute("X->Y", [xfrac])
251
251
 
252
252
  dz = coord.buffer("dx1f")[i]
253
253
  if method.split("-")[0] == "dry":
254
- temp, pres, xfrac = integrate_dry_adiabat(thermo_x, temp, pres, xfrac, grav, dz);
254
+ temp, pres, xfrac = integrate_dry_adiabat(
255
+ thermo_x, temp, pres, xfrac, grav, dz
256
+ )
255
257
  elif method.split("-")[0] == "neutral":
256
- temp, pres, xfrac = integrate_neutral(thermo_x, temp, pres, xfrac, grav, dz);
258
+ temp, pres, xfrac = integrate_neutral(thermo_x, temp, pres, xfrac, grav, dz)
257
259
  else:
258
- thermo_x.extrapolate_ad(temp, pres, xfrac, grav, dz);
260
+ thermo_x.extrapolate_ad(temp, pres, xfrac, grav, dz)
259
261
 
260
262
  if torch.any(temp < Tmin):
261
263
  i_isothermal = i + 1
@@ -276,5 +278,5 @@ def setup_profile(
276
278
  conc = thermo_x.compute("TPX->V", [temp, pres, xfrac])
277
279
  w[snapy.index.ipr, ..., i] = pres
278
280
  w[snapy.index.idn, ..., i] = thermo_x.compute("V->D", [conc])
279
- w[snapy.index.icy:, ..., i] = thermo_x.compute("X->Y", [xfrac])
281
+ w[snapy.index.icy :, ..., i] = thermo_x.compute("X->Y", [xfrac])
280
282
  return w
paddle/write_profile.py CHANGED
@@ -7,11 +7,12 @@ import torch
7
7
  import kintera
8
8
  import snapy
9
9
 
10
+
10
11
  def write_profile(
11
12
  filename: str,
12
13
  hydro_w: torch.Tensor,
13
14
  block: snapy.MeshBlock,
14
- ref_pressure: float = 1.e5,
15
+ ref_pressure: float = 1.0e5,
15
16
  comment: Optional[str] = None,
16
17
  ) -> None:
17
18
  """
@@ -46,27 +47,28 @@ def write_profile(
46
47
  raise ValueError("hydro_w must have shape (N, 1, 1, L).")
47
48
 
48
49
  # calculate a height grid
49
- pres = hydro_w[snapy.index.ipr,...].squeeze() / 1.e5 # Pa -> bar
50
+ pres = hydro_w[snapy.index.ipr, ...].squeeze() / 1.0e5 # Pa -> bar
50
51
  zlev_func = interp1d(
51
52
  pres.log().cpu().numpy(),
52
53
  coord.buffer("x1v").cpu().numpy(),
53
54
  kind="linear",
54
- fill_value="extrapolate")
55
- zref = zlev_func(np.log(ref_pressure / 1.e5))
56
- zlev = (coord.buffer("x1v") - zref) / 1.e3 # m -> km
55
+ fill_value="extrapolate",
56
+ )
57
+ zref = zlev_func(np.log(ref_pressure / 1.0e5))
58
+ zlev = (coord.buffer("x1v") - zref) / 1.0e3 # m -> km
57
59
 
58
60
  # calculate temperature
59
61
  temp = eos.compute("W->T", (hydro_w,)).squeeze()
60
62
 
61
63
  # calculate mole fractions
62
- xfrac = thermo_y.compute("Y->X", (hydro_w[snapy.index.icy:,...],)).squeeze()
64
+ xfrac = thermo_y.compute("Y->X", (hydro_w[snapy.index.icy :, ...],)).squeeze()
63
65
 
64
66
  # calculate heat capacity
65
- conc = thermo_x.compute("TPX->V", (temp, pres * 1.e5, xfrac))
67
+ conc = thermo_x.compute("TPX->V", (temp, pres * 1.0e5, xfrac))
66
68
  cpx = thermo_x.compute("TV->cp", (temp, conc)) / conc.sum(-1)
67
69
 
68
70
  # calculate entropy
69
- ens = thermo_x.compute("TPV->S", (temp, pres * 1.e5, conc)) / conc.sum(-1)
71
+ ens = thermo_x.compute("TPV->S", (temp, pres * 1.0e5, conc)) / conc.sum(-1)
70
72
 
71
73
  with open(filename, "w") as f:
72
74
  # write comments
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: paddle
3
- Version: 1.1.1
3
+ Version: 1.1.3
4
4
  Summary: Canoe's utility subroutines
5
- Project-URL: Homepage, https://github.com/chengcli/paddle
6
- Project-URL: Repository, https://github.com/chengcli/paddle
7
- Project-URL: Issues, https://github.com/chengcli/paddle/issues
8
- Author-email: Cheng Li <chengcli@umich.edu>
5
+ Project-URL: Homepage, https://github.com/elijah-mullens/paddle
6
+ Project-URL: Repository, https://github.com/elijah-mullens/paddle
7
+ Project-URL: Issues, https://github.com/elijah-mullens/paddle/issues
8
+ Author-email: Cheng Li <chengcli@umich.edu>, Elijah Mullens <eem85@cornell.edu>
9
9
  Classifier: Development Status :: 3 - Alpha
10
10
  Classifier: Intended Audience :: Developers
11
11
  Classifier: Intended Audience :: Science/Research
@@ -0,0 +1,10 @@
1
+ paddle/__init__.py,sha256=ET6AzrpqJmUJwj-U9TlCjybszSFCS_EMwAxRYP5ljj8,281
2
+ paddle/crm.py,sha256=HwOLAojR5LBcptqjAC9APEJiWpn8GhxPiAmvvIZ4mTM,1986
3
+ paddle/evolve_kinetics.py,sha256=OWt1-SiLTzaWUCIchwRnBHCjbtcgJIIxrlQ5Lk4iN8c,1541
4
+ paddle/find_init_params.py,sha256=dyRmo-LTwVohbPhSH5LV45jL_XeRmNEcuKPvafBklto,2516
5
+ paddle/setup_profile.py,sha256=MHxRvFyva8CR5_71QSfrLy9ml2rQnW6yy21ZXaVcTGU,8733
6
+ paddle/write_profile.py,sha256=HeBtGaFixGv8DnmJWPiQs-30RsdplSObhMA6ky6eVrg,3908
7
+ paddle-1.1.3.dist-info/METADATA,sha256=7TVy7Gm0xgfNpXc-7pWoXUQ72URw25owBJOyCoxVtd0,1394
8
+ paddle-1.1.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
+ paddle-1.1.3.dist-info/entry_points.txt,sha256=pDR96GW6ylBZrbFd-tRGthW8qTuYaSLjrEt1LFIEYto,48
10
+ paddle-1.1.3.dist-info/RECORD,,
paddle/data/saturn1d.yaml DELETED
@@ -1,88 +0,0 @@
1
- # Saturn Reference Atmosphere Model
2
- #
3
- # Solar abundances relative to H2, enrichments
4
- #
5
- # X_He = 0.195, 0.6955
6
- # X_CH4 = 5.50e-04, 9.4
7
- # X_H2O = 1.026e-03, 10.0
8
- # X_NH3 = 1.352e-04, 3.0
9
- # X_H2S = 3.10e-05, 3.0
10
- #
11
- # Converted to mole fractions
12
- #
13
- # X_H2O = 8.91e-03
14
- # X_NH3 = 3.52e-04
15
- # X_H2S = 8.08e-05
16
- #
17
- # Dry air composition
18
- #
19
- # 0.86838 * H2 + 0.11778 * He + 4.49e-03 * CH4
20
- # {H: 1.755, He: 0.118, C: 4.49e-03}
21
-
22
- reference-state:
23
- Tref: 0.
24
- Pref: 1.e5
25
-
26
- species:
27
- - name: dry
28
- composition: {H: 1.755, He: 0.118, C: 4.49e-03}
29
- cv_R: 2.5
30
-
31
- - name: H2O
32
- composition: {H: 2, O: 1}
33
- cv_R: 2.5
34
- u0_R: 0.
35
-
36
- - name: NH3
37
- composition: {H: 2, O: 1}
38
- cv_R: 2.5
39
- u0_R: 0.
40
-
41
- - name: H2S
42
- composition: {H: 2, S: 1}
43
- cv_R: 2.5
44
- u0_R: 0.
45
-
46
- - name: H2O(l)
47
- composition: {H: 2, O: 1}
48
- cv_R: 9.0
49
- u0_R: -3430.
50
-
51
- - name: NH3(s)
52
- composition: {H: 2, O: 1}
53
- cv_R: 9.0
54
- u0_R: -5520.
55
-
56
- - name: NH4SH(s)
57
- composition: {N: 1, H: 5, S: 1}
58
- cv_R: 9.0
59
- u0_R: -1.2e4
60
-
61
- geometry:
62
- type: cartesian
63
- bounds: {x1min: 0., x1max: 600.e3, x2min: -0.5, x2max: 0.5, x3min: -0.5, x3max: 0.5}
64
- cells: {nx1: 200, nx2: 1, nx3: 1, nghost: 0}
65
-
66
- dynamics:
67
- equation-of-state:
68
- type: moist-mixture
69
- max-iter: 20
70
- ftol: 1.e-6
71
-
72
- reactions:
73
- - equation: H2O => H2O(l)
74
- type: nucleation
75
- rate-constant: {formula: h2o_ideal}
76
-
77
- - equation: NH3 => NH3(s)
78
- type: nucleation
79
- rate-constant: {formula: nh3_ideal}
80
-
81
- - equation: NH3 + H2S <=> NH4SH(s)
82
- type: nucleation
83
- rate-constant: {formula: nh3_h2s_lewis}
84
-
85
- boundary-condition:
86
- external:
87
- x1-inner: reflecting
88
- x1-outer: reflecting
@@ -1,11 +0,0 @@
1
- paddle/__init__.py,sha256=7L9UltY-Uy_Xp_4lc3nhYMinleWBlN4fU-Yztxfw9ko,314
2
- paddle/crm.py,sha256=LXuvOINJE_d6skKu5wU--LVR2CLnI8N5FP5blatM04s,2034
3
- paddle/evolve_kinetics.py,sha256=ZuUc8eFDBUVhCFTbft__0vM0mmPolUpys1Nde8_MbwE,1539
4
- paddle/find_init_params.py,sha256=iEc-NyBlDlGY6k9wfjYqgqU9hMPklp_7YEjvMnEp57M,2525
5
- paddle/setup_profile.py,sha256=goyafLBjCVJhwe_Kk4GcrCceT-fcBpo_UHwFOqKOiY8,8834
6
- paddle/write_profile.py,sha256=3PECXsvGzvJvZfKMTdm49nNj61ZCgf488KoCL3ayB_s,3892
7
- paddle/data/saturn1d.yaml,sha256=07JvsjBGg004TdrhLZOjPZ3m0CYlEhB7fz98Iv1dEGE,1635
8
- paddle-1.1.1.dist-info/METADATA,sha256=qLhZzHLAxEgfL4aENwcZ8UYK1GamcuW0z1jzt-fy8FE,1340
9
- paddle-1.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
- paddle-1.1.1.dist-info/entry_points.txt,sha256=pDR96GW6ylBZrbFd-tRGthW8qTuYaSLjrEt1LFIEYto,48
11
- paddle-1.1.1.dist-info/RECORD,,
File without changes