Skip to content

Commit b0697ff

Browse files
author
shimwell
committed
changed version number
1 parent 91f983e commit b0697ff

5 files changed

Lines changed: 106 additions & 51 deletions

File tree

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
# parametric-plasma-source
2-
Source and build files for parametric plasma source for use in fusion neutron transport calculations.
2+
3+
Python package, C++ source and build files for parametric plasma source for use in fusion neutron transport calculations with OpenMC.
34

45
The plasma source is based on a paper by [C. Fausser et al](https://www.sciencedirect.com/science/article/pii/S0920379612000853)
56

7+
# Installation
8+
9+
```pip install parametric_plasma_source```
10+
11+
# Usage
12+
13+
The parametric plasma source can be imported an used in Python 3 in the following manner.
14+
15+
```
16+
from parametric_plasma_source import Plasma
17+
my_plasma = Plasma(major_radius=6, minor_radius=1.5)
18+
my_plasma.export_plasma_source('custom_openmc_plasma_source.so')
19+
```
20+
21+
In the above example the major_radius and minor radius are changed from the default.
22+
23+
There are a number of additional arguments that can be passed to the Plasma class on construction. Units are in SI (e.g. meters not cm)
24+
25+
```
26+
ion_density_pedistal = 1.09e+20
27+
ion_density_seperatrix = 3e+19
28+
ion_density_origin = 1.09e+20
29+
ion_temperature_pedistal = 6.09
30+
ion_temperature_seperatrix = 0.1
31+
ion_temperature_origin = 45.9
32+
pedistal_radius = 0.8
33+
ion_density_peaking_factor = 1
34+
ion_temperature_peaking_factor = 8.06
35+
minor_radius = 1.56
36+
major_radius = 2.5
37+
elongation = 2.0
38+
triangularity = 0.55
39+
shafranov_shift = 0.0
40+
number_of_bins = 100
41+
plasma_type = 1
42+
```
43+
44+
For a better understanding of the varibles take a look at the [C. Fausser et al](https://www.sciencedirect.com/science/article/pii/S0920379612000853) paper.

parametric_plasma_source/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ C_FLAGS = -fPIC
2626
CXX_FLAGS = -fPIC
2727

2828
#this directory will need changing if your openmc path is different
29-
OPENMC_DIR = $openmc$
29+
OPENMC_DIR = /opt/openmc
3030
OPENMC_INC_DIR = $(OPENMC_DIR)/include
3131
OPENMC_LIB_DIR = $(OPENMC_DIR)/lib
3232
# setting the so name is important

parametric_plasma_source/plasma.py

Lines changed: 19 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,9 @@
1-
"""
2-
This file is part of PARAMAK which is a design tool capable
3-
of creating 3D CAD models compatible with automated neutronics
4-
analysis.
5-
6-
PARAMAK is released under GNU General Public License v3.0.
7-
Go to https://github.com/Shimwell/paramak/blob/master/LICENSE
8-
for full license details.
9-
10-
This program is free software: you can redistribute it and/or modify
11-
it under the terms of the GNU General Public License as published by
12-
the Free Software Foundation, either version 3 of the License, or
13-
(at your option) any later version.
14-
15-
Copyright (C) 2019 UKAEA
16-
17-
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
18-
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
19-
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
20-
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
21-
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22-
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
23-
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
24-
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
25-
"""
26-
import math
1+
272
import os
283
from pathlib import Path
294
import tempfile
305
import shutil
316

32-
import numpy as np
33-
import scipy
34-
357

368
class Plasma():
379

@@ -294,10 +266,10 @@ def export_plasma_source(self, output_filename):
294266
raise ValueError('directory must be set to create .so file')
295267

296268
temp_folder = Path(tempfile.mkdtemp())
297-
print(temp_folder)
269+
298270
Path(output_filename).parent.mkdir(parents=True, exist_ok=True)
299271

300-
editted_plasma_make_file = self.plasma_make_file.replace('$openmc$', self.openmc_install_directory)
272+
editted_plasma_make_file = self.plasma_make_file.replace('OPENMC_DIR = /opt/openmc', 'OPENMC_DIR = '+self.openmc_install_directory)
301273
with open(temp_folder/'Makefile', "w") as text_file:
302274
text_file.write(editted_plasma_make_file)
303275

@@ -308,22 +280,22 @@ def export_plasma_source(self, output_filename):
308280
text_file.write(self.plasma_source_hpp_file)
309281

310282
plasma_varibles = [
311-
('$ion_density_pedistal$',str(self.ion_density_pedistal)),
312-
('$ion_density_seperatrix$',str(self.ion_density_seperatrix)),
313-
('$ion_density_origin$',str(self.ion_density_origin)),
314-
('$ion_temperature_pedistal$',str(self.ion_temperature_pedistal)),
315-
('$ion_temperature_seperatrix$',str(self.ion_temperature_seperatrix)),
316-
('$ion_temperature_origin$',str(self.ion_temperature_origin)),
317-
('$pedistal_radius$',str(self.pedistal_radius)),
318-
('$ion_density_peaking_factor$',str(self.ion_density_peaking_factor)),
319-
('$ion_temperature_peaking_factor$',str(self.ion_temperature_peaking_factor)),
320-
('$minor_radius$',str(self.minor_radius / 100.)),
321-
('$major_radius$',str(self.major_radius / 100.)),
322-
('$elongation$',str(self.elongation)),
323-
('$triangularity$',str(self.triangularity)),
324-
('$shafranov_shift$',str(self.shafranov_shift / 100.)),
325-
('$number_of_bins$',str(self.number_of_bins)),
326-
('$plasma_type$',str(self.plasma_type))
283+
('const double ion_density_pedistal = 1.09e+20', 'const double ion_density_pedistal = ' + str(self.ion_density_pedistal)),
284+
('const double ion_density_seperatrix = 3e+19', 'const double ion_density_seperatrix = ' + str(self.ion_density_seperatrix)),
285+
('const double ion_density_origin = 1.09e+20', 'const double ion_density_origin = ' + str(self.ion_density_origin)),
286+
('const double ion_temperature_pedistal = 6.09', 'const double ion_temperature_pedistal = ' + str(self.ion_temperature_pedistal)),
287+
('const double ion_temperature_seperatrix = 0.1','const double ion_temperature_seperatrix = ' + str(self.ion_temperature_seperatrix)),
288+
('const double ion_temperature_origin = 45.9', 'const double ion_temperature_origin = ' + str(self.ion_temperature_origin)),
289+
('const double pedistal_radius = 0.8', 'const double pedistal_radius = ' + str(self.pedistal_radius)),
290+
('const double ion_density_peaking_factor = 1', 'const double ion_density_peaking_factor = ' + str(self.ion_density_peaking_factor)),
291+
('const double ion_temperature_peaking_factor = 8.06', 'const double ion_temperature_peaking_factor = ' + str(self.ion_temperature_peaking_factor)),
292+
('const double minor_radius = 1.56', 'const double minor_radius = ' + str(self.minor_radius / 100.)),
293+
('const double major_radius = 2.5', 'const double major_radius = ' + str(self.major_radius / 100.)),
294+
('const double elongation = 2.0', 'const double elongation = ' + str(self.elongation)),
295+
('const double triangularity = 0.55', 'const double triangularity = ' + str(self.triangularity)),
296+
('const double shafranov_shift = 0.0', 'const double shafranov_shift = ' + str(self.shafranov_shift / 100.)),
297+
('const int number_of_bins = 100', 'const int number_of_bins = ' + str(self.number_of_bins)),
298+
('const int plasma_type = 1', 'const int plasma_type = 1' + str(self.plasma_type))
327299
]
328300

329301
editted_source_sampling_cpp_file = self.source_sampling_cpp_file
@@ -343,8 +315,6 @@ def export_plasma_source(self, output_filename):
343315
os.system('make clean')
344316
os.system('make')
345317

346-
347-
348318
os.chdir(cwd)
349319
shutil.move(temp_folder/'source_sampling.so', output_filename)
350320
print('parametric plasma source compiled and saved to ', output_filename)

setup.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import setuptools
2+
3+
with open("README.md", "r") as fh:
4+
long_description = fh.read()
5+
6+
setuptools.setup(
7+
name="parametric_plasma_source",
8+
version="0.0.01",
9+
author="Jonathan Shimwell",
10+
author_email="jonathan.shimwell@ukaea.uk",
11+
description="Parametric plasma source for fusion simulations in OpenMC",
12+
long_description=long_description,
13+
long_description_content_type="text/markdown",
14+
url="https://github.com/shimwell/parametric_plasma_source",
15+
packages=setuptools.find_packages(),
16+
scripts=['parametric_plasma_source/'], #puts files in /usr/local/bin
17+
classifiers=[
18+
"Programming Language :: Python :: 3",
19+
"License :: OSI Approved :: MIT",
20+
"Operating System :: OS Independent",
21+
],
22+
)

tests/test_Compile.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
3+
import pytest
4+
import unittest
5+
6+
import os
7+
from pathlib import Path
8+
9+
from parametric_plasma_source.plasma import Plasma
10+
11+
class test_object_properties(unittest.TestCase):
12+
13+
def test_compile(self):
14+
15+
os.system('test_plasma.so')
16+
test_plasma = Plasma()
17+
test_plasma.export_plasma_source('test_plasma.so')
18+
19+
assert Path('test_plasma.so').exists() == True
20+
os.system('rm test_plasma.so')
21+
22+
23+
if __name__ == '__main__':
24+
unittest.main()

0 commit comments

Comments
 (0)