Skip to content

Commit 1847c85

Browse files
committed
Create Python bindings and build
Add a pybind.cpp file and use it to wrap the basic plasma source functionality. Update CMakeLists to build the Python bindings. Ignore untracked Python artefacts in git.
1 parent da673e7 commit 1847c85

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@
3333

3434
# Build path
3535
build
36+
37+
# Python
38+
__pycache__
39+
*.pyc

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,13 @@ set_target_properties(source_sampling PROPERTIES POSITION_INDEPENDENT_CODE ON)
3535
target_include_directories(source_sampling PUBLIC ${OPENMC_INC_DIR})
3636
target_include_directories(source_sampling PUBLIC ${OPENMC_DIR}/vendor/pugixml)
3737
target_link_libraries(source_sampling ${OPENMC_LIB} gfortran)
38+
39+
# Build plasma_source Python bindings
40+
list(APPEND plasma_source_pybind_SOURCES
41+
${SRC_DIR}/plasma_source.cpp
42+
${SRC_DIR}/plasma_source_pybind.cpp
43+
)
44+
45+
add_subdirectory(pybind11)
46+
47+
pybind11_add_module(plasma_source ${plasma_source_pybind_SOURCES})
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <pybind11/pybind11.h>
2+
#include "plasma_source.hpp"
3+
4+
namespace py = pybind11;
5+
namespace ps = plasma_source;
6+
7+
PYBIND11_MODULE(plasma_source, m) {
8+
m.doc() = "A parametric plasma source";
9+
10+
py::class_<ps::PlasmaSource>(m, "PlasmaSource")
11+
.def(py::init<const double &, const double &, const double &, const double &,
12+
const double &, const double &, const double &, const double &,
13+
const double &, const double &, const double &, const double &,
14+
const double &, const double &, const std::string &, const int &,
15+
const int &, const double &, const double &>(),
16+
py::arg("ion_density_pedistal")=1.09e20,
17+
py::arg("ion_density_seperatrix")=3e19,
18+
py::arg("ion_density_origin")=1.09e20,
19+
py::arg("ion_temperature_pedistal")=6.09,
20+
py::arg("ion_temperature_seperatrix")=0.1,
21+
py::arg("ion_temperature_origin")=45.9,
22+
py::arg("pedistal_radius")=0.8,
23+
py::arg("ion_density_peaking_factor")=1.0,
24+
py::arg("ion_temperature_peaking_factor")=8.06,
25+
py::arg("minor_radius")=1.5,
26+
py::arg("major_radius")=4.5,
27+
py::arg("elongation")=2.0,
28+
py::arg("triangularity")=0.55,
29+
py::arg("shafranov_shift")=0.0,
30+
py::arg("plasma_type")="plasma",
31+
py::arg("plasma_id")=1,
32+
py::arg("number_of_bins")=100,
33+
py::arg("min_toroidal_angle") = 0.0,
34+
py::arg("max_toridal_angle") = 360.0)
35+
.def("ion_density",
36+
&ps::PlasmaSource::ion_density,
37+
"Calculate the ion density at a specific minor radius",
38+
py::arg("minor_radius"))
39+
.def("ion_temperature",
40+
&ps::PlasmaSource::ion_temperature,
41+
"calculate the ion temperature at a specific minor radius",
42+
py::arg("minor_radius"))
43+
.def("dt_xs",
44+
&ps::PlasmaSource::dt_xs,
45+
"determine the value of the dt xs cross sections at a specific ion temperature",
46+
py::arg("ion_temperature"));
47+
}

0 commit comments

Comments
 (0)