Skip to content

Commit c2cc5ea

Browse files
authored
Merge pull request #2 from makeclean/master
Merge makeclean master into fork
2 parents a82cfbd + a9d41fa commit c2cc5ea

13 files changed

Lines changed: 1274 additions & 10 deletions

File tree

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,13 @@
3030
*.exe
3131
*.out
3232
*.app
33+
34+
# Build path
35+
build/
36+
dist/
37+
*.egg-info/
38+
39+
# Python
40+
__pycache__/
41+
*.py[cod]
42+

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "pybind11"]
2+
path = pybind11
3+
url = https://github.com/pybind/pybind11

CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
2+
project(parametric_plasma_source)
3+
4+
set(CMAKE_VERBOSE_MAKEFILE OFF)
5+
6+
set(SRC_DIR parametric_plasma_source)
7+
8+
if(NOT CMAKE_BUILD_TYPE)
9+
set(CMAKE_BUILD_TYPE Release)
10+
endif()
11+
12+
set(CMAKE_CXX_FLAGS "-Wall")
13+
set(CMAKE_CXX_FLAGS_DEBUG "-g")
14+
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
15+
16+
# Use output paths from OpenMC install - change if needed
17+
set(OPENMC_DIR /opt/openmc)
18+
set(OPENMC_INC_DIR ${OPENMC_DIR}/include)
19+
set(OPENMC_LIB_DIR ${OPENMC_DIR}/lib)
20+
21+
# Build source_sampling
22+
list(APPEND source_sampling_SOURCES
23+
${SRC_DIR}/source_sampling.cpp
24+
${SRC_DIR}/plasma_source.cpp
25+
)
26+
27+
add_library(source_sampling SHARED ${source_sampling_SOURCES})
28+
29+
find_library(OPENMC_LIB openmc HINTS ${OPENMC_LIB_DIR})
30+
31+
set_target_properties(source_sampling PROPERTIES PREFIX "")
32+
set_target_properties(source_sampling PROPERTIES POSITION_INDEPENDENT_CODE ON)
33+
target_include_directories(source_sampling PUBLIC ${OPENMC_INC_DIR})
34+
target_include_directories(source_sampling PUBLIC ${OPENMC_DIR}/vendor/pugixml)
35+
target_link_libraries(source_sampling ${OPENMC_LIB} gfortran)
36+
37+
# Build plasma_source Python bindings
38+
list(APPEND plasma_source_pybind_SOURCES
39+
${SRC_DIR}/plasma_source.cpp
40+
${SRC_DIR}/plasma_source_pybind.cpp
41+
)
42+
43+
add_subdirectory(pybind11)
44+
45+
pybind11_add_module(plasma_source ${plasma_source_pybind_SOURCES})

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,47 @@
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,
18+
minor_radius=1.5,
19+
elongation = 2.0
20+
triangularity = 0.55)
21+
my_plasma.export_plasma_source('custom_openmc_plasma_source.so')
22+
```
23+
24+
In the above example the major_radius, minor_radius, elongation and triangularity while the other varibles are kept as the default values.
25+
26+
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)
27+
28+
```
29+
ion_density_pedistal = 1.09e+20
30+
ion_density_seperatrix = 3e+19
31+
ion_density_origin = 1.09e+20
32+
ion_temperature_pedistal = 6.09
33+
ion_temperature_seperatrix = 0.1
34+
ion_temperature_origin = 45.9
35+
pedistal_radius = 0.8
36+
ion_density_peaking_factor = 1
37+
ion_temperature_peaking_factor = 8.06
38+
minor_radius = 1.56
39+
major_radius = 2.5
40+
elongation = 2.0
41+
triangularity = 0.55
42+
shafranov_shift = 0.0
43+
number_of_bins = 100
44+
plasma_type = 1
45+
```
46+
47+
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.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .plasma import Plasma
2+
from .plasma_source import PlasmaSource
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import os
2+
3+
plasma_source_cpp = "plasma_source.cpp"
4+
plasma_source_hpp = "plasma_source.hpp"
5+
source_sampling_cpp = "source_sampling.cpp"
6+
make_file = "Makefile"
7+
8+
py_file = "source.py"
9+
10+
def write_disclaimer(py_file_path):
11+
disclaimer = "\"\"\"\n"
12+
disclaimer += "Auto-generated file. To edit, run `python build_python.py`.\n"
13+
disclaimer += "This will need to be run whenever a new C++ version is made available.\n"
14+
disclaimer += "\"\"\"\n\n"
15+
with open(py_file_path, "a+") as f_py:
16+
f_py.write(disclaimer)
17+
18+
def generate_variable(cpp_file_path, variable_name, py_file_path, end_str="\n\n"):
19+
with open(cpp_file_path, "r") as f_cpp:
20+
lines = f_cpp.readlines()
21+
py_lines = variable_name
22+
py_lines += " = (\n\"\"\""
23+
py_lines += "".join(lines)
24+
py_lines += "\"\"\"\n)"
25+
py_lines += end_str
26+
with open(py_file_path, "a+") as f_py:
27+
f_py.write(py_lines)
28+
29+
def build(source_dir="."):
30+
output_path = os.path.join(source_dir, py_file)
31+
32+
if os.path.exists(output_path):
33+
os.remove(output_path)
34+
35+
write_disclaimer(output_path)
36+
generate_variable(
37+
os.path.join(source_dir, source_sampling_cpp),
38+
"source_sampling_cpp",
39+
output_path
40+
)
41+
generate_variable(
42+
os.path.join(source_dir, plasma_source_cpp),
43+
"plasma_source_cpp",
44+
output_path
45+
)
46+
generate_variable(
47+
os.path.join(source_dir, plasma_source_hpp),
48+
"plasma_source_hpp",
49+
output_path
50+
)
51+
generate_variable(
52+
os.path.join(source_dir, make_file),
53+
"make_file",
54+
output_path,
55+
"\n"
56+
)

0 commit comments

Comments
 (0)