-
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 #2 from Shimwell/python_version
Python version
- Loading branch information
Showing
13 changed files
with
1,274 additions
and
10 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 |
---|---|---|
|
@@ -30,3 +30,13 @@ | |
*.exe | ||
*.out | ||
*.app | ||
|
||
# Build path | ||
build/ | ||
dist/ | ||
*.egg-info/ | ||
|
||
# Python | ||
__pycache__/ | ||
*.py[cod] | ||
|
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 @@ | ||
[submodule "pybind11"] | ||
path = pybind11 | ||
url = https://github.com/pybind/pybind11 |
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,45 @@ | ||
cmake_minimum_required(VERSION 3.3 FATAL_ERROR) | ||
project(parametric_plasma_source) | ||
|
||
set(CMAKE_VERBOSE_MAKEFILE OFF) | ||
|
||
set(SRC_DIR parametric_plasma_source) | ||
|
||
if(NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE Release) | ||
endif() | ||
|
||
set(CMAKE_CXX_FLAGS "-Wall") | ||
set(CMAKE_CXX_FLAGS_DEBUG "-g") | ||
set(CMAKE_CXX_FLAGS_RELEASE "-O3") | ||
|
||
# Use output paths from OpenMC install - change if needed | ||
set(OPENMC_DIR /opt/openmc) | ||
set(OPENMC_INC_DIR ${OPENMC_DIR}/include) | ||
set(OPENMC_LIB_DIR ${OPENMC_DIR}/lib) | ||
|
||
# Build source_sampling | ||
list(APPEND source_sampling_SOURCES | ||
${SRC_DIR}/source_sampling.cpp | ||
${SRC_DIR}/plasma_source.cpp | ||
) | ||
|
||
add_library(source_sampling SHARED ${source_sampling_SOURCES}) | ||
|
||
find_library(OPENMC_LIB openmc HINTS ${OPENMC_LIB_DIR}) | ||
|
||
set_target_properties(source_sampling PROPERTIES PREFIX "") | ||
set_target_properties(source_sampling PROPERTIES POSITION_INDEPENDENT_CODE ON) | ||
target_include_directories(source_sampling PUBLIC ${OPENMC_INC_DIR}) | ||
target_include_directories(source_sampling PUBLIC ${OPENMC_DIR}/vendor/pugixml) | ||
target_link_libraries(source_sampling ${OPENMC_LIB} gfortran) | ||
|
||
# Build plasma_source Python bindings | ||
list(APPEND plasma_source_pybind_SOURCES | ||
${SRC_DIR}/plasma_source.cpp | ||
${SRC_DIR}/plasma_source_pybind.cpp | ||
) | ||
|
||
add_subdirectory(pybind11) | ||
|
||
pybind11_add_module(plasma_source ${plasma_source_pybind_SOURCES}) |
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 |
---|---|---|
@@ -1,5 +1,47 @@ | ||
# parametric-plasma-source | ||
Source and build files for parametric plasma source for use in fusion neutron transport calculations. | ||
|
||
Python package, C++ source and build files for parametric plasma source for use in fusion neutron transport calculations with OpenMC. | ||
|
||
The plasma source is based on a paper by [C. Fausser et al](https://www.sciencedirect.com/science/article/pii/S0920379612000853) | ||
|
||
# Installation | ||
|
||
```pip install parametric_plasma_source``` | ||
|
||
# Usage | ||
|
||
The parametric plasma source can be imported an used in Python 3 in the following manner. | ||
|
||
``` | ||
from parametric_plasma_source import Plasma | ||
my_plasma = Plasma(major_radius=6, | ||
minor_radius=1.5, | ||
elongation = 2.0 | ||
triangularity = 0.55) | ||
my_plasma.export_plasma_source('custom_openmc_plasma_source.so') | ||
``` | ||
|
||
In the above example the major_radius, minor_radius, elongation and triangularity while the other varibles are kept as the default values. | ||
|
||
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) | ||
|
||
``` | ||
ion_density_pedistal = 1.09e+20 | ||
ion_density_seperatrix = 3e+19 | ||
ion_density_origin = 1.09e+20 | ||
ion_temperature_pedistal = 6.09 | ||
ion_temperature_seperatrix = 0.1 | ||
ion_temperature_origin = 45.9 | ||
pedistal_radius = 0.8 | ||
ion_density_peaking_factor = 1 | ||
ion_temperature_peaking_factor = 8.06 | ||
minor_radius = 1.56 | ||
major_radius = 2.5 | ||
elongation = 2.0 | ||
triangularity = 0.55 | ||
shafranov_shift = 0.0 | ||
number_of_bins = 100 | ||
plasma_type = 1 | ||
``` | ||
|
||
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. |
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,2 @@ | ||
from .plasma import Plasma | ||
from .plasma_source import PlasmaSource |
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,56 @@ | ||
import os | ||
|
||
plasma_source_cpp = "plasma_source.cpp" | ||
plasma_source_hpp = "plasma_source.hpp" | ||
source_sampling_cpp = "source_sampling.cpp" | ||
make_file = "Makefile" | ||
|
||
py_file = "source.py" | ||
|
||
def write_disclaimer(py_file_path): | ||
disclaimer = "\"\"\"\n" | ||
disclaimer += "Auto-generated file. To edit, run `python build_python.py`.\n" | ||
disclaimer += "This will need to be run whenever a new C++ version is made available.\n" | ||
disclaimer += "\"\"\"\n\n" | ||
with open(py_file_path, "a+") as f_py: | ||
f_py.write(disclaimer) | ||
|
||
def generate_variable(cpp_file_path, variable_name, py_file_path, end_str="\n\n"): | ||
with open(cpp_file_path, "r") as f_cpp: | ||
lines = f_cpp.readlines() | ||
py_lines = variable_name | ||
py_lines += " = (\n\"\"\"" | ||
py_lines += "".join(lines) | ||
py_lines += "\"\"\"\n)" | ||
py_lines += end_str | ||
with open(py_file_path, "a+") as f_py: | ||
f_py.write(py_lines) | ||
|
||
def build(source_dir="."): | ||
output_path = os.path.join(source_dir, py_file) | ||
|
||
if os.path.exists(output_path): | ||
os.remove(output_path) | ||
|
||
write_disclaimer(output_path) | ||
generate_variable( | ||
os.path.join(source_dir, source_sampling_cpp), | ||
"source_sampling_cpp", | ||
output_path | ||
) | ||
generate_variable( | ||
os.path.join(source_dir, plasma_source_cpp), | ||
"plasma_source_cpp", | ||
output_path | ||
) | ||
generate_variable( | ||
os.path.join(source_dir, plasma_source_hpp), | ||
"plasma_source_hpp", | ||
output_path | ||
) | ||
generate_variable( | ||
os.path.join(source_dir, make_file), | ||
"make_file", | ||
output_path, | ||
"\n" | ||
) |
Oops, something went wrong.