-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from DanShort12/serialise_plasma_source
Serialise plasma source
- Loading branch information
Showing
23 changed files
with
817 additions
and
1,427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[flake8] | ||
max-line-length = 88 | ||
exclude = __init__.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,4 +39,11 @@ dist/ | |
# Python | ||
__pycache__/ | ||
*.py[cod] | ||
.venv | ||
|
||
# Outputs | ||
*.xml | ||
*.h5 | ||
|
||
# VS Code | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
major_radius=4.5, minor_radius=1.5, elongation=2, triangularity=0.55, shafranov_shift=0, pedestal_radius=1.2, ion_density_pedestal=1.09e+20, ion_density_separatrix=3e+19, ion_density_origin=1.09e+20, ion_density_alpha=1, ion_temperature_pedestal=6.09, ion_temperature_separatrix=0.1, ion_temperature_origin=45.9, ion_temperature_alpha=8.06, ion_temperature_beta=6, plasma_type=plasma, plasma_id=1, number_of_bins=100, minimum_toroidal_angle=0, maximum_toroidal_angle=360 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
""" | ||
OpenMC Plasma Source example. | ||
An example of how to generate a settings file containing the parameterised | ||
plasma source sampling library and how to generate the parameterisation in the | ||
OpenMC settings.xml file. | ||
""" | ||
|
||
from parametric_plasma_source import PlasmaSource, SOURCE_SAMPLING_PATH | ||
import openmc | ||
|
||
plasma_params = { | ||
"elongation": 1.557, | ||
"ion_density_origin": 1.09e20, | ||
"ion_density_peaking_factor": 1, | ||
"ion_density_pedestal": 1.09e20, | ||
"ion_density_separatrix": 3e19, | ||
"ion_temperature_origin": 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, | ||
"plasma_id": 1, | ||
"shafranov_shift": 0.44789, | ||
"triangularity": 0.270, | ||
"ion_temperature_beta": 6, | ||
} | ||
|
||
plasma = PlasmaSource(**plasma_params) | ||
|
||
# Create a single material | ||
iron = openmc.Material() | ||
iron.set_density("g/cm3", 5.0) | ||
iron.add_element("Fe", 1.0) | ||
mats = openmc.Materials([iron]) | ||
|
||
# Create a 5 cm x 5 cm box filled with iron | ||
cells = [] | ||
inner_box1 = openmc.ZCylinder(r=600.0) | ||
inner_box2 = openmc.ZCylinder(r=1400.0) | ||
outer_box = openmc.model.rectangular_prism(4000.0, 4000.0, boundary_type="vacuum") | ||
cells += [openmc.Cell(fill=iron, region=-inner_box1)] | ||
cells += [openmc.Cell(fill=None, region=+inner_box1 & -inner_box2)] | ||
cells += [openmc.Cell(fill=iron, region=+inner_box2 & outer_box)] | ||
geometry = openmc.Geometry(cells) | ||
|
||
# Tell OpenMC we're going to use our custom source | ||
settings = openmc.Settings() | ||
settings.run_mode = "fixed source" | ||
settings.batches = 10 | ||
settings.particles = 1000 | ||
source = openmc.Source() | ||
source.library = SOURCE_SAMPLING_PATH | ||
source.parameters = str(plasma) | ||
settings.source = source | ||
|
||
# Finally, define a mesh tally so that we can see the resulting flux | ||
mesh = openmc.RegularMesh() | ||
mesh.lower_left = (-2000.0, -2000.0) | ||
mesh.upper_right = (2000.0, 2000.0) | ||
mesh.dimension = (50, 50) | ||
|
||
tally = openmc.Tally() | ||
tally.filters = [openmc.MeshFilter(mesh)] | ||
tally.scores = ["flux"] | ||
tallies = openmc.Tallies([tally]) | ||
|
||
model = openmc.model.Model( | ||
materials=mats, geometry=geometry, settings=settings, tallies=tallies | ||
) | ||
|
||
model.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import matplotlib as mpl | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import openmc | ||
|
||
mpl.use("TkAgg") | ||
|
||
# Get the flux from the statepoint | ||
with openmc.StatePoint("statepoint.10.h5") as sp: | ||
flux = np.log(sp.get_tally(scores=["flux"]).mean) | ||
flux.shape = (50, 50) | ||
|
||
# Plot the flux | ||
fig, ax = plt.subplots() | ||
ax.imshow(flux, origin="lower", extent=(-2000.0, 2000.0, -2000.0, 2000.0)) | ||
ax.set_xlabel("x [cm]") | ||
ax.set_ylabel("y [cm]") | ||
plt.show() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import os | ||
|
||
PLASMA_SOURCE_PATH = os.path.dirname(__file__) | ||
SOURCE_SAMPLING_PATH = os.sep.join([PLASMA_SOURCE_PATH, "source_sampling.so"]) | ||
|
||
try: | ||
from .plasma_source import * | ||
except ImportError: | ||
print("The plasma_source module could not be found. Please compile before using.") |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.