Skip to content

Commit

Permalink
Merge branch 'main' into improved_energy_distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell authored Apr 19, 2024
2 parents 73eef16 + f99fbc1 commit eafb359
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 37 deletions.
48 changes: 15 additions & 33 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
Expand All @@ -14,30 +6,20 @@ on:

jobs:
deploy:

runs-on: ubuntu-latest

permissions:
id-token: write
steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools build wheel twine
- name: Build package
run: python -m build

- name: Check build
run: twine check dist/*

- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
13 changes: 9 additions & 4 deletions src/openmc_plasma_source/tokamak_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def tokamak_source(
angles: Tuple[float, float] = (0, 2 * np.pi),
sample_size: int = 1000,
fuel: dict = {"D": 0.5, "T": 0.5},
sample_seed: int = 122807528840384100672342137672332424406,
) -> list[openmc.IndependentSource]:
"""Creates a list of openmc.IndependentSource objects representing a tokamak plasma.
Expand Down Expand Up @@ -69,6 +70,9 @@ def tokamak_source(
(cm)
angles (iterable of floats): the start and stop angles of the ring in
radians
sample_seed int: the seed passed to numpy.random when sampling source
location. Numpy recommend a large int value. Defaults to
122807528840384100672342137672332424406
sample_size (int, optional): number of neutron sources. Defaults
to 1000.
fuel (dict): Isotopes as keys and atom fractions as values
Expand Down Expand Up @@ -116,9 +120,10 @@ def tokamak_source(
(neutron source density) and .RZ (coordinates)
"""
# create a sample of (a, alpha) coordinates
a = np.random.random(sample_size) * minor_radius
alpha = np.random.random(sample_size) * 2 * np.pi

rng = np.random.default_rng(self.sample_seed)
a = rng.random(self.sample_size) * self.minor_radius
alpha = rng.random(self.sample_size) * 2 * np.pi

# compute densities, temperatures
densities = tokamak_ion_density(
mode=mode,
Expand Down Expand Up @@ -277,7 +282,7 @@ def tokamak_ion_temperature(
+ (ion_temperature_pedestal - ion_temperature_separatrix)
* (major_radius - r)
/ (major_radius - pedestal_radius)
),
)
)
return temperature

Expand Down

0 comments on commit eafb359

Please sign in to comment.