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
A Python library created to assist programmers with complex mathematical functions

libmaths libmaths was created not only as a learning experience for me, but as a way to make mathematical models in seconds for Python users using mat

Simple 73 Oct 02, 2022
Hand-distance-measurement-game - Hand Distance Measurement Game

Hand Distance Measurement Game This is program is made to calculate the distance

Priyansh 2 Jan 12, 2022
Unofficial PyTorch implementation of "RTM3D: Real-time Monocular 3D Detection from Object Keypoints for Autonomous Driving" (ECCV 2020)

RTM3D-PyTorch The PyTorch Implementation of the paper: RTM3D: Real-time Monocular 3D Detection from Object Keypoints for Autonomous Driving (ECCV 2020

Nguyen Mau Dzung 271 Nov 29, 2022
Official PyTorch implementation of the paper: Improving Graph Neural Network Expressivity via Subgraph Isomorphism Counting.

Improving Graph Neural Network Expressivity via Subgraph Isomorphism Counting Official PyTorch implementation of the paper: Improving Graph Neural Net

Giorgos Bouritsas 58 Dec 31, 2022
code for EMNLP 2019 paper Text Summarization with Pretrained Encoders

PreSumm This code is for EMNLP 2019 paper Text Summarization with Pretrained Encoders Updates Jan 22 2020: Now you can Summarize Raw Text Input!. Swit

Yang Liu 1.2k Dec 28, 2022
Cowsay - A rewrite of cowsay in python

Python Cowsay A rewrite of cowsay in python. Allows for parsing of existing .cow

James Ansley 3 Jun 27, 2022
Generalized and Efficient Blackbox Optimization System.

OpenBox Doc | OpenBox中文文档 OpenBox: Generalized and Efficient Blackbox Optimization System OpenBox is an efficient and generalized blackbox optimizatio

DAIR Lab 238 Dec 29, 2022
The lightweight PyTorch wrapper for high-performance AI research. Scale your models, not the boilerplate.

The lightweight PyTorch wrapper for high-performance AI research. Scale your models, not the boilerplate. Website • Key Features • How To Use • Docs •

Pytorch Lightning 21.1k Jan 08, 2023
Project repo for the paper SILT: Self-supervised Lighting Transfer Using Implicit Image Decomposition

SILT: Self-supervised Lighting Transfer Using Implicit Image Decomposition (BMVC 2021) Project repo for the paper SILT: Self-supervised Lighting Trans

6 Dec 04, 2022
A simple and useful implementation of LPIPS.

lpips-pytorch Description Developing perceptual distance metrics is a major topic in recent image processing problems. LPIPS[1] is a state-of-the-art

So Uchida 121 Dec 24, 2022
Implementation of "StrengthNet: Deep Learning-based Emotion Strength Assessment for Emotional Speech Synthesis"

StrengthNet Implementation of "StrengthNet: Deep Learning-based Emotion Strength Assessment for Emotional Speech Synthesis" https://arxiv.org/abs/2110

RuiLiu 65 Dec 20, 2022
For the paper entitled ''A Case Study and Qualitative Analysis of Simple Cross-Lingual Opinion Mining''

Summary This is the source code for the paper "A Case Study and Qualitative Analysis of Simple Cross-Lingual Opinion Mining", which was accepted as fu

1 Nov 10, 2021
Video Instance Segmentation with a Propose-Reduce Paradigm (ICCV 2021)

Propose-Reduce VIS This repo contains the official implementation for the paper: Video Instance Segmentation with a Propose-Reduce Paradigm Huaijia Li

DV Lab 39 Nov 23, 2022
Pytorch implementation of NEGEV method. Paper: "Negative Evidence Matters in Interpretable Histology Image Classification".

Pytorch 1.10.0 code for: Negative Evidence Matters in Interpretable Histology Image Classification (https://arxiv. org/abs/xxxx.xxxxx) Citation: @arti

Soufiane Belharbi 4 Dec 01, 2022
Some experiments with tennis player aging curves using Hilbert space GPs in PyMC. Only experimental for now.

NOTE: This is still being developed! Setup notes This document uses Jeff Sackmann's tennis data. You can obtain it as follows: git clone https://githu

Martin Ingram 1 Jan 20, 2022
Inference code for "StylePeople: A Generative Model of Fullbody Human Avatars" paper. This code is for the part of the paper describing video-based avatars.

NeuralTextures This is repository with inference code for paper "StylePeople: A Generative Model of Fullbody Human Avatars" (CVPR21). This code is for

Visual Understanding Lab @ Samsung AI Center Moscow 18 Oct 06, 2022
hipCaffe: the HIP port of Caffe

Caffe Caffe is a deep learning framework made with expression, speed, and modularity in mind. It is developed by the Berkeley Vision and Learning Cent

ROCm Software Platform 126 Dec 05, 2022
Official PyTorch implementation of the NeurIPS 2021 paper StyleGAN3

Alias-Free Generative Adversarial Networks (StyleGAN3) Official PyTorch implementation of the NeurIPS 2021 paper Alias-Free Generative Adversarial Net

Eugenio Herrera 92 Nov 18, 2022
GndNet: Fast ground plane estimation and point cloud segmentation for autonomous vehicles using deep neural networks.

GndNet: Fast Ground plane Estimation and Point Cloud Segmentation for Autonomous Vehicles. Authors: Anshul Paigwar, Ozgur Erkent, David Sierra Gonzale

Anshul Paigwar 114 Dec 29, 2022
GPT, but made only out of gMLPs

GPT - gMLP This repository will attempt to crack long context autoregressive language modeling (GPT) using variations of gMLPs. Specifically, it will

Phil Wang 80 Dec 01, 2022