Skip to content

Commit

Permalink
Merge pull request #25 from fusion-energy/develop
Browse files Browse the repository at this point in the history
Release 0.2.2
  • Loading branch information
RemDelaporteMathurin authored Sep 29, 2021
2 parents a03cc9b + 76e56d1 commit 52bd93d
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 17 deletions.
3 changes: 1 addition & 2 deletions examples/ring_source_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

my_source = FusionRingSource(
radius = 700,
start_angle =0.,
stop_angle = 6.28318530718,
angles =(0., 6.28318530718), # 360deg source
temperature = 20000.,
)

Expand Down
6 changes: 4 additions & 2 deletions openmc_plasma_source/plotting/plot_tokamak_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def scatter_tokamak_source(source, quantity=None, **kwargs):

quantity_to_attribute = {
"ion_temperature": source.temperatures,
"neutron_source_density": source.strengths
"neutron_source_density": source.neutron_source_density,
"strength": source.strengths,
}
if quantity in quantity_to_attribute:
colours = quantity_to_attribute[quantity]
Expand Down Expand Up @@ -52,7 +53,8 @@ def plot_tokamak_source_3D(source, quantity=None, angles=[0, 1/2*np.pi], colorba

quantity_to_attribute = {
"ion_temperature": source.temperatures,
"neutron_source_density": source.strengths
"neutron_source_density": source.neutron_source_density,
"strength": source.strengths,
}
if quantity in quantity_to_attribute:
values = quantity_to_attribute[quantity]
Expand Down
9 changes: 4 additions & 5 deletions openmc_plasma_source/ring_source.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import openmc
import numpy as np


class FusionRingSource(openmc.Source):
Expand All @@ -10,16 +11,14 @@ class FusionRingSource(openmc.Source):
Args:
radius: the inner radius of the ring source
start_angle: the start angle of the ring in radians,
stop_angle: the end angle of the ring in radians,
angles (iterable of floats): the start and stop angles of the ring in radians,
z_placement: Location of the ring source (m). Defaults to 0.
temperature: the temperature to use in the Muir distribution in eV,
"""
def __init__(
self,
radius,
start_angle: float =0.,
stop_angle: float = 6.28318530718,
angles=(0, 2*np.pi),
z_placement=0,
temperature: float = 20000.,
fuel='DT'
Expand All @@ -30,7 +29,7 @@ def __init__(
# performed after the super init as these are Source attributes
radius = openmc.stats.Discrete([radius], [1])
z_values = openmc.stats.Discrete([z_placement], [1])
angle = openmc.stats.Uniform(a=start_angle, b=stop_angle)
angle = openmc.stats.Uniform(a=angles[0], b=angles[1])
self.space = openmc.stats.CylindricalIndependent(
r=radius,
phi=angle,
Expand Down
17 changes: 11 additions & 6 deletions openmc_plasma_source/tokamak_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class TokamakSource():
shafranov_factor (float): Shafranov factor (referred in [1] as esh)
also known as outward radial displacement of magnetic surfaces
(m)
angles (iterable of floats): the start and stop angles of the ring in
radians
sample_size (int, optional): number of neutron sources. Defaults
to 1000.
"""
Expand All @@ -61,6 +63,7 @@ def __init__(
ion_temperature_separatrix,
pedestal_radius,
shafranov_factor,
angles=(0, 2*np.pi),
sample_size=1000
) -> None:
self.major_radius = major_radius
Expand All @@ -84,6 +87,8 @@ def __init__(

self.sample_size = sample_size

self.angles = angles

self.sample_sources()
self.sources = self.make_openmc_sources()

Expand Down Expand Up @@ -180,10 +185,12 @@ def sample_sources(self):
# convert coordinates
self.densities = self.ion_density(a)
self.temperatures = self.ion_temperature(a)
self.strengths = strength(self.densities, self.temperatures)
self.neutron_source_density = neutron_source_density(
self.densities, self.temperatures)
self.strengths = self.neutron_source_density/sum(self.neutron_source_density)
self.RZ = self.convert_a_alpha_to_R_Z(a, alpha)

def make_openmc_sources(self, angles=(0., 2*np.pi)):
def make_openmc_sources(self):
"""Creates a list of OpenMC Sources() objects. The created sources are
ring sources based on the .RZ coordinates between two angles. The
energy of the sources are Muir energy spectra with ion temperatures
Expand All @@ -207,7 +214,7 @@ def make_openmc_sources(self, angles=(0., 2*np.pi)):
# extract the RZ values accordingly
radius = openmc.stats.Discrete([self.RZ[0][i]], [1])
z_values = openmc.stats.Discrete([self.RZ[1][i]], [1])
angle = openmc.stats.Uniform(a=angles[0], b=angles[1])
angle = openmc.stats.Uniform(a=self.angles[0], b=self.angles[1])

# create a ring source
my_source.space = openmc.stats.CylindricalIndependent(
Expand All @@ -226,7 +233,7 @@ def make_openmc_sources(self, angles=(0., 2*np.pi)):
return sources


def strength(ion_density, ion_temperature):
def neutron_source_density(ion_density, ion_temperature):
"""Computes the neutron source density given ion density and ion
temperature.
Expand Down Expand Up @@ -266,5 +273,3 @@ def DT_xs(ion_temperature):
val = c[0]/(U**(5/6)*ion_temperature**(2/3))
val *= np.exp(-c[1]*(U/ion_temperature)**(1/3))
return val


52 changes: 50 additions & 2 deletions tests/test_tokamak_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from openmc import Source

import pytest


def test_creation():
my_source = TokamakSource(
Expand All @@ -22,7 +24,53 @@ def test_creation():
triangularity=0.270,
ion_temperature_beta=6
)
my_source.sample_sources()
my_source.make_openmc_sources()
for source in my_source.make_openmc_sources():
assert isinstance(source, Source)


def test_strengths_are_normalised():
"""Tests that the sum of the strengths attribute is equal to
"""
my_source = TokamakSource(
elongation=1.557,
ion_density_centre=1.09e20,
ion_density_peaking_factor=1,
ion_density_pedestal=1.09e20,
ion_density_separatrix=3e19,
ion_temperature_centre=45.9,
ion_temperature_peaking_factor=8.06,
ion_temperature_pedestal=6.09,
ion_temperature_separatrix=0.1,
major_radius=9.06,
minor_radius=2.92258,
pedestal_radius=0.8 * 2.92258,
mode="H",
shafranov_factor=0.44789,
triangularity=0.270,
ion_temperature_beta=6
)
assert pytest.approx(sum(my_source.strengths), 1)


def test_angles():
"""Checks that custom angles can be set
"""
my_source = TokamakSource(
elongation=1.557,
ion_density_centre=1.09e20,
ion_density_peaking_factor=1,
ion_density_pedestal=1.09e20,
ion_density_separatrix=3e19,
ion_temperature_centre=45.9,
ion_temperature_peaking_factor=8.06,
ion_temperature_pedestal=6.09,
ion_temperature_separatrix=0.1,
major_radius=9.06,
minor_radius=2.92258,
pedestal_radius=0.8 * 2.92258,
mode="H",
shafranov_factor=0.44789,
triangularity=0.270,
ion_temperature_beta=6,
angles=(0, 1)
)

0 comments on commit 52bd93d

Please sign in to comment.