Skip to content

Commit

Permalink
Merge pull request #83 from fusion-energy/next_openmc_release_rem
Browse files Browse the repository at this point in the history
Next openMC release
  • Loading branch information
shimwell authored Jun 29, 2023
2 parents 0917dc9 + 3e69d9d commit d10f0c2
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jobs:
# test:
build:
docker:
- image: openmc/openmc:v0.13.3
- image: openmc/openmc:develop
steps:
- checkout
- run:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
testing:
runs-on: ubuntu-latest
container:
image: openmc/openmc:v0.13.3
image: openmc/openmc:develop
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Install
run: |
Expand Down
3 changes: 2 additions & 1 deletion examples/ring_source_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import openmc
from openmc_plasma_source import FusionRingSource
import math

my_source = FusionRingSource(
radius=700,
angles=(0.0, 6.28318530718), # 360deg source
angles=(0.0, 2 * math.pi), # 360deg source
temperature=20000.0,
)

Expand Down
30 changes: 21 additions & 9 deletions openmc_plasma_source/fuel_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,32 @@
for a given fusion fuel type.
"""

from param import Parameterized, Number


class Fuel(Parameterized):
# mean energy, eV
mean_energy = Number(None, bounds=(0, None), inclusive_bounds=(False, False))

# mass of the reactants, AMU
mass_of_reactants = Number(None, bounds=(0, None), inclusive_bounds=(False, False))

class Fuel:
def __init__(self, mean_energy, mass_of_reactants):
self.mean_energy = mean_energy
self.mass_of_reactants = mass_of_reactants

@property
def mean_energy(self):
return self._mean_energy

@mean_energy.setter
def mean_energy(self, value):
if value <= 0:
raise (ValueError("mean_energy needs to be strictly positive"))
self._mean_energy = value

@property
def mass_of_reactants(self):
return self._mass_of_reactants

@mass_of_reactants.setter
def mass_of_reactants(self, value):
if value <= 0:
raise (ValueError("mass_of_reactants needs to be strictly positive"))
self._mass_of_reactants = value


fuel_types = {
"DD": Fuel(mean_energy=2450000.0, mass_of_reactants=4),
Expand Down
46 changes: 39 additions & 7 deletions openmc_plasma_source/point_source.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import openmc
from typing import Tuple
from param import Parameterized, Number, NumericTuple, ListSelector

from .fuel_types import fuel_types


class FusionPointSource(openmc.Source, Parameterized):
class FusionPointSource(openmc.IndependentSource):
"""An openmc.Source object with some presets to make it more convenient
for fusion simulations using a point source. All attributes can be changed
after initialization if required. Default isotropic point source at the
Expand All @@ -18,13 +17,9 @@ class FusionPointSource(openmc.Source, Parameterized):
fuel_type (str): The fusion fuel mix. Either 'DT' or 'DD'.
"""

coordinate = NumericTuple(None, length=3)
temperature = Number(None, bounds=(0, None)) # temperature in eV
fuel_type = ListSelector(fuel_types.keys())

def __init__(
self,
coordinate: Tuple[float, float, float] = (0, 0, 0),
coordinate: Tuple[float, float, float] = (0.0, 0.0, 0.0),
temperature: float = 20000.0,
fuel: str = "DT",
):
Expand All @@ -45,3 +40,40 @@ def __init__(
m_rat=self.fuel.mass_of_reactants,
kt=self.temperature,
)

@property
def coordinate(self):
return self._coordinate

@coordinate.setter
def coordinate(self, value):
if (
isinstance(value, tuple)
and len(value) == 3
and all(isinstance(x, (int, float)) for x in value)
):
self._coordinate = value
else:
raise ValueError("coordinate must be a tuple of three floats.")

@property
def temperature(self):
return self._temperature

@temperature.setter
def temperature(self, value):
if isinstance(value, (int, float)) and value > 0:
self._temperature = value
else:
raise ValueError("Temperature must be strictly positive float.")

@property
def fuel_type(self):
return self._fuel_type

@fuel_type.setter
def fuel_type(self, value):
if value in fuel_types:
self._fuel_type = value
else:
raise KeyError("Invalid fuel type")
73 changes: 65 additions & 8 deletions openmc_plasma_source/ring_source.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import openmc
import numpy as np
from typing import Tuple
from param import Parameterized, Number, Range, ListSelector

from .fuel_types import fuel_types


class FusionRingSource(openmc.Source, Parameterized):
class FusionRingSource(openmc.IndependentSource):
"""An openmc.Source object with some presets to make it more convenient
for fusion simulations using a ring source. All attributes can be changed
after initialization if required. Default isotropic ring source with a Muir
Expand All @@ -20,12 +19,6 @@ class FusionRingSource(openmc.Source, Parameterized):
fuel_type (str): The fusion fuel mix. Either 'DT' or 'DD'.
"""

radius = Number(None, bounds=(0, None), inclusive_bounds=(False, False))
angles = Range((0, 2 * np.pi))
z_placement = Number()
temperature = Number(bounds=(0, None))
fuel_type = ListSelector(fuel_types.keys())

def __init__(
self,
radius: float,
Expand Down Expand Up @@ -58,3 +51,67 @@ def __init__(
m_rat=self.fuel.mass_of_reactants,
kt=self.temperature,
)

@property
def radius(self):
return self._radius

@radius.setter
def radius(self, value):
if isinstance(value, (int, float)) and value > 0:
self._radius = value
else:
raise ValueError("Radius must be a float strictly greater than 0.")

@property
def angles(self):
return self._angles

@angles.setter
def angles(self, value):
if (
isinstance(value, tuple)
and len(value) == 2
and all(
isinstance(angle, (int, float)) and -2 * np.pi <= angle <= 2 * np.pi
for angle in value
)
):
self._angles = value
else:
raise ValueError(
"Angles must be a tuple of floats between zero and 2 * np.pi"
)

@property
def z_placement(self):
return self._z_placement

@z_placement.setter
def z_placement(self, value):
if isinstance(value, (int, float)):
self._z_placement = value
else:
raise TypeError("Z placement must be a float.")

@property
def temperature(self):
return self._temperature

@temperature.setter
def temperature(self, value):
if isinstance(value, (int, float)) and value > 0:
self._temperature = value
else:
raise ValueError("Temperature must be a float strictly greater than 0.")

@property
def fuel_type(self):
return self._fuel_type

@fuel_type.setter
def fuel_type(self, value):
if value in fuel_types.keys():
self._fuel_type = value
else:
raise KeyError("Invalid fuel type.")
Loading

0 comments on commit d10f0c2

Please sign in to comment.