paddle 1.1.0__tar.gz → 1.1.3__tar.gz
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-1.1.3/.bumpversion.cfg +12 -0
- paddle-1.1.3/.github/workflows/bump-and-tag.yaml +78 -0
- paddle-1.1.3/.github/workflows/cd.yml +55 -0
- paddle-1.1.3/.github/workflows/ci.yml +60 -0
- {paddle-1.1.0 → paddle-1.1.3}/.gitignore +0 -1
- paddle-1.1.3/.pre-commit-config.yaml +17 -0
- {paddle-1.1.0 → paddle-1.1.3}/PKG-INFO +6 -5
- {paddle-1.1.0 → paddle-1.1.3}/pyproject.toml +9 -6
- paddle-1.1.3/src/paddle/__init__.py +7 -0
- {paddle-1.1.0 → paddle-1.1.3}/src/paddle/crm.py +14 -14
- {paddle-1.1.0 → paddle-1.1.3}/src/paddle/evolve_kinetics.py +15 -11
- {paddle-1.1.0 → paddle-1.1.3}/src/paddle/find_init_params.py +14 -12
- {paddle-1.1.0 → paddle-1.1.3}/src/paddle/setup_profile.py +39 -40
- {paddle-1.1.0 → paddle-1.1.3}/src/paddle/write_profile.py +10 -8
- {paddle-1.1.0/src/paddle → paddle-1.1.3/tests}/data/saturn1d.yaml +1 -1
- {paddle-1.1.0 → paddle-1.1.3}/tests/test_saturn_adiabat.py +25 -21
- paddle-1.1.0/src/paddle/__init__.py +0 -6
- {paddle-1.1.0 → paddle-1.1.3}/README.md +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[bumpversion]
|
|
2
|
+
current_version = 1.1.3
|
|
3
|
+
commit = True
|
|
4
|
+
tag = True
|
|
5
|
+
|
|
6
|
+
[bumpversion:file:src/paddle/__init__.py]
|
|
7
|
+
search = __version__ = "{current_version}"
|
|
8
|
+
replace = __version__ = "{new_version}"
|
|
9
|
+
|
|
10
|
+
[bumpversion:file:pyproject.toml]
|
|
11
|
+
search = version = "{current_version}"
|
|
12
|
+
replace = version = "{new_version}"
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
name: Bump Version and Tag
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [closed]
|
|
6
|
+
branches: [main]
|
|
7
|
+
|
|
8
|
+
env:
|
|
9
|
+
PYTHON_VERSION: "3.11"
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
bump-version:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
permissions:
|
|
15
|
+
contents: write
|
|
16
|
+
pull-requests: write
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- name: Checkout repository
|
|
20
|
+
uses: actions/checkout@v4
|
|
21
|
+
with:
|
|
22
|
+
fetch-depth: 0
|
|
23
|
+
|
|
24
|
+
- name: Set up Python
|
|
25
|
+
uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: ${{ env.PYTHON_VERSION }}
|
|
28
|
+
|
|
29
|
+
- name: Configure Git
|
|
30
|
+
run: |
|
|
31
|
+
git config user.name "github-actions[bot]"
|
|
32
|
+
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
33
|
+
|
|
34
|
+
- name: Bump version and push tag
|
|
35
|
+
id: bump_version
|
|
36
|
+
uses: jasonamyers/github-bumpversion-action@v1.0.5
|
|
37
|
+
env:
|
|
38
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
39
|
+
|
|
40
|
+
- name: Push changes
|
|
41
|
+
uses: ad-m/github-push-action@master
|
|
42
|
+
with:
|
|
43
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
44
|
+
branch: ${{ github.ref }}
|
|
45
|
+
tags: true
|
|
46
|
+
|
|
47
|
+
- name: Generate Release Notes
|
|
48
|
+
uses: octokit/request-action@v2.x
|
|
49
|
+
id: get_release_notes
|
|
50
|
+
with:
|
|
51
|
+
route: POST /repos/${{ github.repository }}/releases/generate-notes
|
|
52
|
+
tag_name: v${{ steps.bump_version.outputs.new_ver }}
|
|
53
|
+
env:
|
|
54
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
55
|
+
|
|
56
|
+
- name: Create GitHub release
|
|
57
|
+
id: create_release
|
|
58
|
+
uses: actions/create-release@v1.1.4
|
|
59
|
+
env:
|
|
60
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
61
|
+
with:
|
|
62
|
+
tag_name: v${{ steps.bump_version.outputs.new_ver }}
|
|
63
|
+
release_name: Release v${{ steps.bump_version.outputs.new_ver }}
|
|
64
|
+
draft: false
|
|
65
|
+
prerelease: false
|
|
66
|
+
body: ${{ fromJson(steps.get_release_notes.outputs.data).body }}
|
|
67
|
+
|
|
68
|
+
- name: Post comment on PR with release notes
|
|
69
|
+
uses: actions/github-script@v7
|
|
70
|
+
with:
|
|
71
|
+
script: |
|
|
72
|
+
const notes = `${{ fromJson(steps.get_release_notes.outputs.data).body }}`;
|
|
73
|
+
github.rest.issues.createComment({
|
|
74
|
+
issue_number: context.payload.pull_request.number,
|
|
75
|
+
owner: context.repo.owner,
|
|
76
|
+
repo: context.repo.repo,
|
|
77
|
+
body: `🎉 Released v${{ steps.bump_version.outputs.new_ver }}!\n\n${notes}`
|
|
78
|
+
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
name: Deploy to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
tags: [v*]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build:
|
|
10
|
+
name: Build distribution artifacts
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout code
|
|
14
|
+
uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Setup Host Python
|
|
17
|
+
uses: actions/setup-python@v5
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.11"
|
|
20
|
+
cache: pip
|
|
21
|
+
|
|
22
|
+
- name: Install build backend
|
|
23
|
+
run: |
|
|
24
|
+
python -m pip install --upgrade pip
|
|
25
|
+
pip install build
|
|
26
|
+
|
|
27
|
+
- name: Build sdist and wheel
|
|
28
|
+
run: python -m build
|
|
29
|
+
|
|
30
|
+
- name: Upload artifacts
|
|
31
|
+
uses: actions/upload-artifact@v4
|
|
32
|
+
with:
|
|
33
|
+
name: dist
|
|
34
|
+
path: dist/*
|
|
35
|
+
|
|
36
|
+
publish-pypi:
|
|
37
|
+
name: Publish to PyPI
|
|
38
|
+
needs: build
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
permissions:
|
|
41
|
+
id-token: write
|
|
42
|
+
contents: read
|
|
43
|
+
steps:
|
|
44
|
+
- name: Download wheels
|
|
45
|
+
uses: actions/download-artifact@v4
|
|
46
|
+
with:
|
|
47
|
+
name: dist
|
|
48
|
+
path: dist
|
|
49
|
+
|
|
50
|
+
- name: Publish to PyPI
|
|
51
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
52
|
+
with:
|
|
53
|
+
user: __token__
|
|
54
|
+
password: ${{ secrets.PYPI_API_TOKEN }}
|
|
55
|
+
verbose: true
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
name: Continuous Integration
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches: [main]
|
|
6
|
+
|
|
7
|
+
push:
|
|
8
|
+
branches: [main]
|
|
9
|
+
tags: [v*]
|
|
10
|
+
|
|
11
|
+
env:
|
|
12
|
+
PYTHON_VERSION: "3.11"
|
|
13
|
+
BUILD_TYPE: Release
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
pre-commit:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- name: Check out code
|
|
20
|
+
uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- name: Set up Python
|
|
23
|
+
uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: ${{ env.PYTHON_VERSION }}
|
|
26
|
+
|
|
27
|
+
- name: Install style checkers
|
|
28
|
+
run: pip install --user cpplint cppcheck clang-format==20.1.4
|
|
29
|
+
|
|
30
|
+
- name: Cache pre-commit
|
|
31
|
+
uses: actions/cache@v3
|
|
32
|
+
with:
|
|
33
|
+
path: ~/.cache/pre-commit
|
|
34
|
+
key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
|
|
35
|
+
restore-keys: |
|
|
36
|
+
${{ runner.os }}-pre-commit-
|
|
37
|
+
|
|
38
|
+
- name: Run pre-commit
|
|
39
|
+
uses: pre-commit/action@v3.0.1
|
|
40
|
+
|
|
41
|
+
build-and-test:
|
|
42
|
+
needs: pre-commit
|
|
43
|
+
runs-on: ${{ matrix.os }}
|
|
44
|
+
strategy:
|
|
45
|
+
fail-fast: true
|
|
46
|
+
matrix:
|
|
47
|
+
os: [ubuntu-latest, macOS-latest]
|
|
48
|
+
steps:
|
|
49
|
+
- name: Check out code
|
|
50
|
+
uses: actions/checkout@v4
|
|
51
|
+
|
|
52
|
+
- name: Set up Python
|
|
53
|
+
uses: actions/setup-python@v5
|
|
54
|
+
with:
|
|
55
|
+
python-version: ${{ env.PYTHON_VERSION }}
|
|
56
|
+
cache: "pip"
|
|
57
|
+
|
|
58
|
+
- name: Install Python dependencies
|
|
59
|
+
run: |
|
|
60
|
+
pip install numpy pytest 'pyharp>=1.7.1' 'torch==2.7.1'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
3
|
+
rev: v4.0.1
|
|
4
|
+
hooks:
|
|
5
|
+
- id: requirements-txt-fixer
|
|
6
|
+
- id: trailing-whitespace
|
|
7
|
+
exclude: ^(data|patches)/.*$
|
|
8
|
+
- id: end-of-file-fixer
|
|
9
|
+
exclude: ^(data|patches)/.*$
|
|
10
|
+
- id: check-yaml
|
|
11
|
+
exclude: ^data/
|
|
12
|
+
|
|
13
|
+
- repo: https://github.com/psf/black
|
|
14
|
+
rev: 24.10.0 # Use the latest stable version
|
|
15
|
+
hooks:
|
|
16
|
+
- id: black
|
|
17
|
+
args: [--line-length=88]
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: paddle
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.3
|
|
4
4
|
Summary: Canoe's utility subroutines
|
|
5
|
-
Project-URL: Homepage, https://github.com/
|
|
6
|
-
Project-URL: Repository, https://github.com/
|
|
7
|
-
Project-URL: Issues, https://github.com/
|
|
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
|
+
Classifier: Intended Audience :: Developers
|
|
10
11
|
Classifier: Intended Audience :: Science/Research
|
|
11
12
|
Classifier: Programming Language :: Python
|
|
12
13
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
[build-system]
|
|
2
2
|
requires = ["hatchling>=1.25"]
|
|
3
3
|
build-backend = "hatchling.build"
|
|
4
|
-
#build-backend = "setuptools.build_meta"
|
|
5
4
|
|
|
6
5
|
[project]
|
|
7
6
|
name = "paddle"
|
|
8
|
-
version = "1.1.
|
|
7
|
+
version = "1.1.3"
|
|
9
8
|
description = "Canoe's utility subroutines"
|
|
10
9
|
readme = "README.md"
|
|
11
10
|
requires-python = ">=3.9"
|
|
12
|
-
authors = [
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Cheng Li", email = "chengcli@umich.edu" },
|
|
13
|
+
{ name = "Elijah Mullens", email = "eem85@cornell.edu" },
|
|
14
|
+
]
|
|
13
15
|
keywords = []
|
|
14
16
|
classifiers = [
|
|
15
17
|
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
16
19
|
"Intended Audience :: Science/Research",
|
|
17
20
|
"Programming Language :: Python",
|
|
18
21
|
"Programming Language :: Python :: 3",
|
|
@@ -39,9 +42,9 @@ dev = [
|
|
|
39
42
|
]
|
|
40
43
|
|
|
41
44
|
[project.urls]
|
|
42
|
-
Homepage = "https://github.com/
|
|
43
|
-
Repository = "https://github.com/
|
|
44
|
-
Issues = "https://github.com/
|
|
45
|
+
Homepage = "https://github.com/elijah-mullens/paddle"
|
|
46
|
+
Repository = "https://github.com/elijah-mullens/paddle"
|
|
47
|
+
Issues = "https://github.com/elijah-mullens/paddle/issues"
|
|
45
48
|
|
|
46
49
|
[project.scripts]
|
|
47
50
|
paddle = "paddle.__main__:main"
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
from .setup_profile import setup_profile
|
|
2
|
+
from .write_profile import write_profile
|
|
3
|
+
from .find_init_params import find_init_params
|
|
4
|
+
from .evolve_kinetics import evolve_kinetics
|
|
5
|
+
|
|
6
|
+
__all__ = ["setup_profile", "write_profile", "find_init_params", "evolve_kinetics"]
|
|
7
|
+
__version__ = "1.1.3"
|
|
@@ -4,20 +4,20 @@ import time
|
|
|
4
4
|
import kintera
|
|
5
5
|
import numpy as np
|
|
6
6
|
from snapy import (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
index,
|
|
8
|
+
MeshBlockOptions,
|
|
9
|
+
MeshBlock,
|
|
10
|
+
OutputOptions,
|
|
11
|
+
NetcdfOutput,
|
|
12
|
+
)
|
|
13
13
|
from kintera import (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
ThermoOptions,
|
|
15
|
+
ThermoX,
|
|
16
|
+
KineticsOptions,
|
|
17
|
+
Kinetics,
|
|
18
|
+
)
|
|
19
19
|
|
|
20
|
-
if __name__ ==
|
|
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
|
|
@@ -2,11 +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,
|
|
9
|
-
thermo_x: kintera.ThermoX
|
|
8
|
+
block: snapy.MeshBlock,
|
|
9
|
+
kinet: kintera.Kinetics,
|
|
10
|
+
thermo_x: kintera.ThermoX,
|
|
11
|
+
dt,
|
|
12
|
+
) -> torch.Tensor:
|
|
10
13
|
"""
|
|
11
14
|
Evolve the chemical kinetics for one time step using implicit method.
|
|
12
15
|
|
|
@@ -15,26 +18,27 @@ def evolve_kinetics(
|
|
|
15
18
|
block (snapy.MeshBlock): The mesh block containing the simulation data.
|
|
16
19
|
kinet (kintera.Kinetics): The kinetics module for chemical reactions.
|
|
17
20
|
thermo_x (kintera.ThermoX): The thermodynamics module for computing properties.
|
|
21
|
+
dt (float): The time step for evolution.
|
|
18
22
|
|
|
19
23
|
Returns:
|
|
20
24
|
torch.Tensor: The change in mass density due to chemical reactions.
|
|
21
25
|
"""
|
|
22
|
-
eos = block.
|
|
23
|
-
thermo_y =
|
|
26
|
+
eos = block.hydro.get_eos()
|
|
27
|
+
thermo_y = block.module("hydro.eos.thermo")
|
|
24
28
|
|
|
25
|
-
temp = eos.compute("W->T", (
|
|
26
|
-
pres =
|
|
27
|
-
xfrac = thermo_y.compute("Y->X", (
|
|
29
|
+
temp = eos.compute("W->T", (hydro_w,))
|
|
30
|
+
pres = hydro_w[snapy.index.ipr]
|
|
31
|
+
xfrac = thermo_y.compute("Y->X", (hydro_w[snapy.index.icy :],))
|
|
28
32
|
conc = thermo_x.compute("TPX->V", (temp, pres, xfrac))
|
|
29
33
|
cp_vol = thermo_x.compute("TV->cp", (temp, conc))
|
|
30
34
|
|
|
31
35
|
conc_kinet = kinet.options.narrow_copy(conc, thermo_y.options)
|
|
32
|
-
rate, rc_ddC, rc_ddT = kinet.
|
|
36
|
+
rate, rc_ddC, rc_ddT = kinet.forward_nogil(temp, pres, conc_kinet)
|
|
33
37
|
jac = kinet.jacobian(temp, conc_kinet, cp_vol, rate, rc_ddC, rc_ddT)
|
|
34
38
|
|
|
35
39
|
stoich = kinet.buffer("stoich")
|
|
36
40
|
del_conc = kintera.evolve_implicit(rate, stoich, jac, dt)
|
|
37
41
|
|
|
38
42
|
inv_mu = thermo_y.buffer("inv_mu")
|
|
39
|
-
del_rho = del_conc / inv_mu[1:].view(
|
|
40
|
-
return del_rho.permute(
|
|
43
|
+
del_rho = del_conc / inv_mu[1:].view(1, 1, 1, -1)
|
|
44
|
+
return del_rho.permute(3, 0, 1, 2)
|
|
@@ -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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
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
|
-
|
|
@@ -4,18 +4,19 @@ import torch
|
|
|
4
4
|
import snapy
|
|
5
5
|
import kintera
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
def integrate_neutral(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
141
|
-
|
|
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.
|
|
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(
|
|
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,8 +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])
|
|
280
|
-
|
|
281
|
-
# initialize hydro state
|
|
282
|
-
block.initialize({"hydro_w": w})
|
|
281
|
+
w[snapy.index.icy :, ..., i] = thermo_x.compute("X->Y", [xfrac])
|
|
283
282
|
return w
|
|
@@ -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.
|
|
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
|
|
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
|
-
|
|
56
|
-
|
|
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
|
|
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.
|
|
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.
|
|
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,45 +1,48 @@
|
|
|
1
1
|
from importlib import resources
|
|
2
2
|
from paddle import (
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
setup_profile,
|
|
4
|
+
write_profile,
|
|
5
|
+
find_init_params,
|
|
6
|
+
)
|
|
7
7
|
from snapy import (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
MeshBlockOptions,
|
|
9
|
+
MeshBlock,
|
|
10
|
+
)
|
|
11
11
|
from kintera import ThermoX
|
|
12
12
|
|
|
13
|
+
|
|
13
14
|
def setup_saturn_profile():
|
|
14
|
-
path = resources.files("paddle") / "data" / "saturn1d.yaml"
|
|
15
|
+
# path = resources.files("paddle") / "data" / "saturn1d.yaml"
|
|
16
|
+
path = "data" / "saturn1d.yaml"
|
|
15
17
|
print(f"Reading input file: {path}")
|
|
16
18
|
|
|
17
19
|
op_block = MeshBlockOptions.from_yaml(str(path))
|
|
18
20
|
block = MeshBlock(op_block)
|
|
19
21
|
|
|
20
22
|
param = {
|
|
21
|
-
"Ts": 600
|
|
22
|
-
"Ps": 100.
|
|
23
|
-
"Tmin": 85
|
|
23
|
+
"Ts": 600.0,
|
|
24
|
+
"Ps": 100.0e5,
|
|
25
|
+
"Tmin": 85.0,
|
|
24
26
|
"xH2O": 8.91e-3,
|
|
25
27
|
"xNH3": 3.52e-4,
|
|
26
28
|
"xH2S": 8.08e-5,
|
|
27
29
|
"grav": 10.44,
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
#method = "pseudo-adiabat"
|
|
31
|
-
#method = "moist-adiabat"
|
|
32
|
+
# method = "pseudo-adiabat"
|
|
33
|
+
# method = "moist-adiabat"
|
|
32
34
|
method = "dry-adiabat"
|
|
33
35
|
|
|
34
36
|
param = find_init_params(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
block,
|
|
38
|
+
param,
|
|
39
|
+
target_T=134.0,
|
|
40
|
+
target_P=1.0e5,
|
|
41
|
+
method=method,
|
|
42
|
+
max_iter=50,
|
|
43
|
+
ftol=1.0e-2,
|
|
44
|
+
verbose=True,
|
|
45
|
+
)
|
|
43
46
|
|
|
44
47
|
w = setup_profile(block, param, method=method)
|
|
45
48
|
|
|
@@ -50,5 +53,6 @@ def setup_saturn_profile():
|
|
|
50
53
|
write_profile("saturn_profile.txt", w, block)
|
|
51
54
|
return w
|
|
52
55
|
|
|
56
|
+
|
|
53
57
|
if __name__ == "__main__":
|
|
54
58
|
w = setup_saturn_profile()
|
|
File without changes
|