This python-based package offers a way of creating a parametric OpenMC plasma source from plasma parameters.

Overview

openmc-plasma-source

This python-based package offers a way of creating a parametric OpenMC plasma source from plasma parameters. The OpenMC sources are ring sources which reduces the computational cost and the settings.xml file size.

image

The equations implemented here are taken from this paper.

Installation

To install openmc-plasma-source, simply run:

pip install openmc-plasma-source

Basic usage

from openmc_plasma_source import Plasma


# create a plasma source
my_plasma = Plasma(
    elongation=1.557,
    ion_density_centre=1.09e20,
    ion_density_peaking_factor=1,
    ion_density_pedestal=1.09e20,
    ion_density_separatrix=3e19,
    ion_temperature_centre=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,
    mode="H",
    shafranov_factor=0.44789,
    triangularity=0.270,
    ion_temperature_beta=6
  )

my_plasma.sample_sources()
my_sources = my_plasma.make_openmc_sources()

For a more complete example check out the example script.

Comments
  • Removed proper_tea, replaced with param

    Removed proper_tea, replaced with param

    I switched out proper_tea for the much more widely used package param. It supports much more than what my own library can do, though I personally think my version is more readable and easier to use.

    Advantages of param:

    • Better error reporting when setter conditions fail
    • Has far more features than the ones I've used here
    • Likely to be better supported in future

    Disadvantages of param:

    • Harder to read. I feel like positive_float(allow_zero=False) is easier to read than Number(1.0, bounds=(0, None), inclusive_bounds=(False, False)).
    • Some parameters require a non-optional default value, such as the example above of a float greater than zero. It may not always be obvious what this should be, and you often have to repeat the default values given in your __init__ function.
    opened by LiamPattinson 12
  • Add openmc_source_plotter features

    Add openmc_source_plotter features

    @shimwell what would you think of adding to ops some plotting features by importing openmc_source_plotter?

    I wonder if the packages should be merged. I guess the question is: "Would the openmc_source_plotter be used outside of fusion applications?" If the name of this org is fusion-energy, i think the answer's no. Maybe these two packages could be merged to reduce the number of dependencies.

    What do you think?

    enhancement 
    opened by RemDelaporteMathurin 12
  • What do you think?

    What do you think?

    @Shimwell what do you think of this?

    I've implemented the method of this paper in this python code

    What I didn't realise at first is that it's in fact what Andy did in parametric-plasma-source....

    image

    opened by RemDelaporteMathurin 11
  • Using openmc source plotter for plotting methods

    Using openmc source plotter for plotting methods

    This PR is a rework of #63 with feedback taken onboard.

    The source class is now openmc.Source and it has been monkey patched to add the desired plotting methods.

    This now just looks and behaves like a regular openmc source but it has a few plot methods

    opened by shimwell 7
  • tests are failing on main and develop

    tests are failing on main and develop

    Just running the tests on the main or develop branch and I am seeing this error and getting one failing test

        @given(tokamak_source=tokamak_source_strategy())
        @settings(max_examples=50)
        def test_strengths_are_normalised(tokamak_source):
            """Tests that the sum of the strengths attribute is equal to"""
    >       assert pytest.approx(sum(tokamak_source.strengths)) == 1
    E       assert nan ± ??? == 1
    E         comparison failed
    E         Obtained: 1
    E         Expected: nan ± ???
    E       Falsifying example: test_strengths_are_normalised(
    E           tokamak_source=TokamakSource(angles=(0, 6.283185307179586), elongation=1.0, ion_density_centre=1.09e+20, ion_density_peaking_factor=1, ion_density_pedestal=1.09e+20, ion_density_separatrix=3e+19, ion_temperature_beta=6, ion_temperature_centre=45.9, ion_temperature_peaking_factor=8.06, ion_temperature_pedestal=6.09, ion_temperature_separatrix=0.1, major_radius=1.0, minor_radius=1.5258789062500003e-05, mode='H', name='TokamakSource', pedestal_radius=1.52587890625e-05, sample_size=1000, triangularity=0.0),
    E       )
    
    bug 
    opened by shimwell 7
  • Update to package configuration

    Update to package configuration

    This update aims to bring openmc-plasma-source in line with PEP 517 recommendations for packaging etc. The build/install details in setup.py are moved to setup.cfg and pyproject.toml as simple input files. Rather than calling:

    • python setup.py install/python setup.py develop
    • python setup.py sdist bdist_wheel

    One should instead call:

    • pip install ./pip install -e . (for 'develop' mode)
    • python -m build

    Rather than using a requirements file, the project requirements may be listed in setup.cfg, and optional dependencies may be installed using:

    • pip install -e .[tests] (-e is optional)

    This update also introduces automatic version inference, meaning the git tag is the 'single source of truth' for versioning. The version is updated with developer tags when between patch versions, i.e. one commit after 0.5.3 will be 0.5.4.dev0+[git commit].d[date].

    opened by LiamPattinson 7
  • added ring and point source classes

    added ring and point source classes

    Not ready for review yet, missing tests

    Adding a few more sources. This adds a simple ring source and a point source.

    This point source is useful for inertial confinement fusion This ring source is useful for magnetic confinement fusion when extra plasma details are not known

    TODO tests

    opened by shimwell 6
  • Improved TokamakSource (with properties)

    Improved TokamakSource (with properties)

    I've made a series of updates to TokamakSource to ensure it can't be set up with broken data, and cleaned up some TODO sections while I was at it.

    The most significant change is the introduction of a utility file called properties.py, which implements a somewhat-generic 'property factory' and a few specific use cases. This allows you to do things like declare a class attribute must be a positive float, and protects against setting it to something inappropriate after initialisation. It might be a little overkill for these purposes, and it can instead be achieved by a simple list of checks within TokamakSource.__init__. I've mocked up both methods, and will submit the other version as a separate pull request. It's worth noting that I'm working on developing the property factory bits into an independent package, so I may be able to remove these files in a later build and simply replace them with a new dependency in setup.cfg.

    I believe I've figured out what combination of geometry inputs are acceptable (major radius, minor radius, pedestal radius, Shafranov factor, triangularity, elongation), but I don't know what bounds should be set on the various ion densities and ion temperatures. It would be helpful if you could let me know any further constraints we can place on these values.

    There were some sections marked TODO within TokamakSource, in which a list of ion densities/temperatures was built one element at a time in a for loop: https://github.com/fusion-energy/openmc-plasma-source/blob/ddef660343a211d1e9498a2cdcf38961ee3bdefc/openmc_plasma_source/tokamak_source.py#L112-L130 These have been rewritten to make use of np.where. As NumPy is a little better for reporting floating point issues than raw Python, I'm now seeing RuntimeWarnings for 'invalid value encountered in power'. It's hard to say if there's actually a cause for concern here, as I don't believe I've changed the overall logic anywhere. It would definitely be worth looking over those changes in detail to ensure I haven't broken anything.

    Finally, I've updated test_tokamak_source.py extensively, adding unit tests to ensure that TokamakSource builds correctly when fed 'good' data and that it exits in a particular way when fed 'bad' data. I also changed how the hypothesis strategy was working as it was struggling to generate useful data after a few more constraints were added.

    opened by LiamPattinson 5
  • Testing TokamakSource generates points correctly

    Testing TokamakSource generates points correctly

    I've added a test and refactored test_tokamak_source.py to ensure TokamakSource generates points within the expected shape. This change brings in hypothesis as an additional testing requirement, which is used to automatically generate a wide range of possible tokamaks and ensure it works for more than the single example given previously. It also includes a general refactor to avoid the repeated lines of code.

    I believe this goes some way towards solving issue https://github.com/fusion-energy/openmc-plasma-source/issues/34, but I'd like to go a bit further. For example, the inputs to TokamakSource aren't checked for validity in its __init__ function. It would be quite straightforward to implement these checks and associated unit tests, and I could raise this as separate issue/pull request.

    opened by LiamPattinson 4
  • classes are now SourceWithPlotting

    classes are now SourceWithPlotting

    This PR adds some plotting features to the package.

    The sources are now instances of openmc_source_plotter.SourceWithPlotting() which is just a class that inherits openmc.Source and adds some plotting methods.

    The additional plotting methods are .plot_source_position, .plot_source_energy, .plot_source_direction and there is also a sampling method called sample_initial_particles

    This doesn't remove any of the existing plotting methods but adds a few new ones.

    opened by shimwell 3
  • Widen range of matplotlib packages allowed

    Widen range of matplotlib packages allowed

    Is there any chance I can change this line to allow versions above 3.3.4

    https://github.com/fusion-energy/openmc-plasma-source/blob/e3931d18a9f53dcae23d158bbcd2e291ca3dab34/setup.cfg#L30

    I am installing this package in some CI and getting this error

    error: matplotlib 3.3.4 is installed but matplotlib>=3.4.3 is required by {'openmc-plasma-source'}

    Looking at the earlier releases (pre .toml file) it looks like "matplotlib >= 3.2.2" was accepted

    opened by shimwell 3
  • Should the sources have a method `get_neutron_rate` ?

    Should the sources have a method `get_neutron_rate` ?

    The sources should maybe have a method to compute the neutron rate in neutron/s .

    usage could be

    from openmc_plasma_source import FusionPointSource
    
    my_source = FusionPointSource(.....)
    
    neutron_rate = my_source.get_neutron_rate(fusion_power=1e9)  # for 1 GW
    
    opened by RemDelaporteMathurin 4
  • Add action to test conda package

    Add action to test conda package

    A github action can be added to check that proposed changes:

    • Don't break the conda package building process
    • That the built conda package passes the pytest tests

    This action can perhaps be reused for this role.

    opened by shimwell 0
  • plotting functions should be methods of TokamakSource

    plotting functions should be methods of TokamakSource

    I was looking at the functions in plotting and thought these should maybe be methods of TokamakSource so that users can do:

    
    my_source = TokamakSouce(....)
    my_source.plot_3d(...)
    
    enhancement good first issue 
    opened by RemDelaporteMathurin 5
  • Allowing blended fuel sources

    Allowing blended fuel sources

    Currently just 'DD' or 'DT' sources are allowed using the fuel: str = "DT", argument

    We could add sources that have a fraction of DT and a different fraction of DD with a more flexible input for fuel.

    How about fuel also accepts a list of tuples, where the first entry is 'DD' or 'DT' and the second entry is the relative strength

    fuel = [('DD', 0.1, ('DT',0.90)]
    

    or is a dictionary better

    fuel = {'DD':0.1, 'DT':0.9}
    
    enhancement 
    opened by shimwell 3
  • testing for multiple python versions

    testing for multiple python versions

    Not sure if this will work as we run ci in a container.

    However it would be great if multiple python versions can be tested

    Here is an example

    https://github.com/C-bowman/inference-tools/blob/760061e77bdc8ddeacb951196a3deb783a6ccffd/.github/workflows/tests.yml#L16-L17

    opened by shimwell 2
Releases(v0.2.7)
  • v0.2.7(Feb 23, 2022)

    What's Changed

    • Improved point and ring sources by @LiamPattinson in https://github.com/fusion-energy/openmc-plasma-source/pull/51
    • Further updates to TokamakSource and tests by @LiamPattinson in https://github.com/fusion-energy/openmc-plasma-source/pull/53
    • Fixed broken link by @RemDelaporteMathurin in https://github.com/fusion-energy/openmc-plasma-source/pull/54
    • Plotting improvements by @LiamPattinson in https://github.com/fusion-energy/openmc-plasma-source/pull/55
    • Older version of openmc used in CI by @RemDelaporteMathurin in https://github.com/fusion-energy/openmc-plasma-source/pull/57
    • Removed proper_tea, replaced with param by @LiamPattinson in https://github.com/fusion-energy/openmc-plasma-source/pull/56

    Full Changelog: https://github.com/fusion-energy/openmc-plasma-source/compare/v0.2.6...v0.2.7

    Source code(tar.gz)
    Source code(zip)
  • v0.2.6(Feb 7, 2022)

    What's Changed

    • Improved TokamakSource (with properties) by @LiamPattinson in https://github.com/fusion-energy/openmc-plasma-source/pull/48
    • Release 0.2.6 by @RemDelaporteMathurin in https://github.com/fusion-energy/openmc-plasma-source/pull/50

    Full Changelog: https://github.com/fusion-energy/openmc-plasma-source/compare/v0.2.5...v0.2.6

    Source code(tar.gz)
    Source code(zip)
  • v0.2.5(Feb 1, 2022)

    What's Changed

    • updating citation file version and authors by @shimwell in https://github.com/fusion-energy/openmc-plasma-source/pull/44
    • Revert matplotlib version to 3.2.2 by @LiamPattinson in https://github.com/fusion-energy/openmc-plasma-source/pull/45
    • relaxed matplotlib version and added liam to citation by @shimwell in https://github.com/fusion-energy/openmc-plasma-source/pull/46

    Full Changelog: https://github.com/fusion-energy/openmc-plasma-source/compare/v0.2.4...v0.2.5

    Source code(tar.gz)
    Source code(zip)
  • v0.2.4(Jan 30, 2022)

    What's Changed

    • Testing TokamakSource generates points correctly by @LiamPattinson in https://github.com/fusion-energy/openmc-plasma-source/pull/38
    • Update to package configuration by @LiamPattinson in https://github.com/fusion-energy/openmc-plasma-source/pull/39
    • Release 0.2.4 by @RemDelaporteMathurin in https://github.com/fusion-energy/openmc-plasma-source/pull/40

    New Contributors

    • @LiamPattinson made their first contribution in https://github.com/fusion-energy/openmc-plasma-source/pull/38

    Full Changelog: https://github.com/fusion-energy/openmc-plasma-source/compare/v0.2.3...v0.2.4

    Source code(tar.gz)
    Source code(zip)
  • v0.2.3(Nov 10, 2021)

    What's Changed

    • improved examples by @shimwell in https://github.com/fusion-energy/openmc-plasma-source/pull/27
    • Adding citation file by @shimwell in https://github.com/fusion-energy/openmc-plasma-source/pull/28
    • added auto pep formatting by @shimwell in https://github.com/fusion-energy/openmc-plasma-source/pull/31
    • allowing matplotlib above version 3.2.2 to be installed by @shimwell in https://github.com/fusion-energy/openmc-plasma-source/pull/32

    Full Changelog: https://github.com/fusion-energy/openmc-plasma-source/compare/v0.2.2...v0.2.3

    Source code(tar.gz)
    Source code(zip)
  • v0.2.2(Sep 29, 2021)

  • v0.2.1(Sep 29, 2021)

  • v0.2(Sep 27, 2021)

  • v0.1(Sep 22, 2021)

    This python-based package offers a way of creating a parametric OpenMC plasma source from plasma parameters. The OpenMC sources are ring sources which reduces the computational cost and the settings.xml file size.

    image

    The equations implemented here are taken from this paper.

    Source code(tar.gz)
    Source code(zip)
Owner
Fusion Energy
A collection of software projects related to fusion energy
Fusion Energy
CS50's Introduction to Artificial Intelligence Test Scripts

CS50's Introduction to Artificial Intelligence Test Scripts 🤷‍♂️ What's this? 🤷‍♀️ This repository contains Python scripts to automate tests for mos

Jet Kan 2 Dec 28, 2022
Code for NeurIPS 2021 paper 'Spatio-Temporal Variational Gaussian Processes'

Spatio-Temporal Variational GPs This repository is the official implementation of the methods in the publication: O. Hamelijnck, W.J. Wilkinson, N.A.

AaltoML 26 Sep 16, 2022
A curated (most recent) list of resources for Learning with Noisy Labels

A curated (most recent) list of resources for Learning with Noisy Labels

Jiaheng Wei 321 Jan 09, 2023
Pytorch Implementation of "Desigining Network Design Spaces", Radosavovic et al. CVPR 2020.

RegNet Pytorch Implementation of "Desigining Network Design Spaces", Radosavovic et al. CVPR 2020. Paper | Official Implementation RegNet offer a very

Vishal R 2 Feb 11, 2022
GLODISMO: Gradient-Based Learning of Discrete Structured Measurement Operators for Signal Recovery

GLODISMO: Gradient-Based Learning of Discrete Structured Measurement Operators for Signal Recovery This is the code to the paper: Gradient-Based Learn

3 Feb 15, 2022
Learning View Priors for Single-view 3D Reconstruction (CVPR 2019)

Learning View Priors for Single-view 3D Reconstruction (CVPR 2019) This is code for a paper Learning View Priors for Single-view 3D Reconstruction by

Hiroharu Kato 38 Aug 17, 2022
[ICCV2021] Official Pytorch implementation for SDGZSL (Semantics Disentangling for Generalized Zero-Shot Learning)

Semantics Disentangling for Generalized Zero-shot Learning This is the official implementation for paper Zhi Chen, Yadan Luo, Ruihong Qiu, Zi Huang, J

25 Dec 06, 2022
OBG-FCN - implementation of 'Object Boundary Guided Semantic Segmentation'

OBG-FCN This repository is to reproduce the implementation of 'Object Boundary Guided Semantic Segmentation' in http://arxiv.org/abs/1603.09742 Object

Jiu XU 3 Mar 11, 2019
The official github repository for Towards Continual Knowledge Learning of Language Models

Towards Continual Knowledge Learning of Language Models This is the official github repository for Towards Continual Knowledge Learning of Language Mo

Joel Jang | 장요엘 65 Jan 07, 2023
Python library to receive live stream events like comments and gifts in realtime from TikTok LIVE.

TikTokLive A python library to connect to and read events from TikTok's LIVE service A python library to receive and decode livestream events such as

Isaac Kogan 277 Dec 23, 2022
Knowledgeable Prompt-tuning: Incorporating Knowledge into Prompt Verbalizer for Text Classification

Knowledgeable Prompt-tuning: Incorporating Knowledge into Prompt Verbalizer for Text Classification

DingDing 143 Jan 01, 2023
[NeurIPS'21] "AugMax: Adversarial Composition of Random Augmentations for Robust Training" by Haotao Wang, Chaowei Xiao, Jean Kossaifi, Zhiding Yu, Animashree Anandkumar, and Zhangyang Wang.

[NeurIPS'21] "AugMax: Adversarial Composition of Random Augmentations for Robust Training" by Haotao Wang, Chaowei Xiao, Jean Kossaifi, Zhiding Yu, Animashree Anandkumar, and Zhangyang Wang.

VITA 112 Nov 07, 2022
Source code for CVPR 2021 paper "Riggable 3D Face Reconstruction via In-Network Optimization"

Riggable 3D Face Reconstruction via In-Network Optimization Source code for CVPR 2021 paper "Riggable 3D Face Reconstruction via In-Network Optimizati

130 Jan 02, 2023
1st-in-MICCAI2020-CPM - Combined Radiology and Pathology Classification

Combined Radiology and Pathology Classification MICCAI 2020 Combined Radiology a

22 Dec 08, 2022
Efficient and Accurate Arbitrary-Shaped Text Detection with Pixel Aggregation Network

Efficient and Accurate Arbitrary-Shaped Text Detection with Pixel Aggregation Network Paddle-PANet 目录 结果对比 论文介绍 快速安装 结果对比 CTW1500 Method Backbone Fine

7 Aug 08, 2022
Machine Learning Toolkit for Kubernetes

Kubeflow the cloud-native platform for machine learning operations - pipelines, training and deployment. Documentation Please refer to the official do

Kubeflow 12.1k Jan 03, 2023
PyTorch Implementation of SSTNs for hyperspectral image classifications from the IEEE T-GRS paper "Spectral-Spatial Transformer Network for Hyperspectral Image Classification: A FAS Framework."

PyTorch Implementation of SSTN for Hyperspectral Image Classification Paper links: SSTN published on IEEE T-GRS. Also, you can directly find the imple

Zilong Zhong 54 Dec 19, 2022
Graph Convolutional Neural Networks with Data-driven Graph Filter (GCNN-DDGF)

Graph Convolutional Gated Recurrent Neural Network (GCGRNN) Improved from Graph Convolutional Neural Networks with Data-driven Graph Filter (GCNN-DDGF

Lei Lin 21 Dec 18, 2022
Code for the paper: Adversarial Training Against Location-Optimized Adversarial Patches. ECCV-W 2020.

Adversarial Training Against Location-Optimized Adversarial Patches arXiv | Paper | Code | Video | Slides Code for the paper: Sukrut Rao, David Stutz,

Sukrut Rao 32 Dec 13, 2022
Denoising images with Fourier Ring Correlation loss

Denoising images with Fourier Ring Correlation loss The python code accompanies the working manuscript Image quality measurements and denoising using

2 Mar 12, 2022