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
The pyrelational package offers a flexible workflow to enable active learning with as little change to the models and datasets as possible

pyrelational is a python active learning library developed by Relation Therapeutics for rapidly implementing active learning pipelines from data management, model development (and Bayesian approximation), to creating novel active learning strategies.

Relation Therapeutics 95 Dec 27, 2022
The personal repository of the work: *DanceNet3D: Music Based Dance Generation with Parametric Motion Transformer*.

DanceNet3D The personal repository of the work: DanceNet3D: Music Based Dance Generation with Parametric Motion Transformer. Dataset and Results Pleas

南嘉Nanga 36 Dec 21, 2022
This repository contains a pytorch implementation of "HeadNeRF: A Real-time NeRF-based Parametric Head Model (CVPR 2022)".

HeadNeRF: A Real-time NeRF-based Parametric Head Model This repository contains a pytorch implementation of "HeadNeRF: A Real-time NeRF-based Parametr

null 294 Jan 1, 2023
JumpDiff: Non-parametric estimator for Jump-diffusion processes for Python

jumpdiff jumpdiff is a python library with non-parametric Nadaraya─Watson estimators to extract the parameters of jump-diffusion processes. With jumpd

Rydin 28 Dec 10, 2022
The repository offers the official implementation of our paper in PyTorch.

Cloth Interactive Transformer (CIT) Cloth Interactive Transformer for Virtual Try-On Bin Ren1, Hao Tang1, Fanyang Meng2, Runwei Ding3, Ling Shao4, Phi

Bingoren 49 Dec 1, 2022
Virtual Dance Reality Stage: a feature that offers you to share a stage with another user virtually

Portrait Segmentation using Tensorflow This script removes the background from an input image. You can read more about segmentation here Setup The scr

null 291 Dec 24, 2022
A parametric soroban written with CADQuery.

A parametric soroban written in CADQuery The purpose of this project is to demonstrate how "code CAD" can be intuitive to learn. See soroban.py for a

Lee 4 Aug 13, 2022
Official implementation of NPMs: Neural Parametric Models for 3D Deformable Shapes - ICCV 2021

NPMs: Neural Parametric Models Project Page | Paper | ArXiv | Video NPMs: Neural Parametric Models for 3D Deformable Shapes Pablo Palafox, Aljaz Bozic

PabloPalafox 109 Nov 22, 2022
Parametric Contrastive Learning (ICCV2021)

Parametric-Contrastive-Learning This repository contains the implementation code for ICCV2021 paper: Parametric Contrastive Learning (https://arxiv.or

DV Lab 156 Dec 21, 2022
The official implementation of the research paper "DAG Amendment for Inverse Control of Parametric Shapes"

DAG Amendment for Inverse Control of Parametric Shapes This repository is the official Blender implementation of the paper "DAG Amendment for Inverse

Elie Michel 157 Dec 26, 2022
Adversarial Framework for (non-) Parametric Image Stylisation Mosaics

Fully Adversarial Mosaics (FAMOS) Pytorch implementation of the paper "Copy the Old or Paint Anew? An Adversarial Framework for (non-) Parametric Imag

Zalando Research 120 Dec 24, 2022
pytorch implementation of "Contrastive Multiview Coding", "Momentum Contrast for Unsupervised Visual Representation Learning", and "Unsupervised Feature Learning via Non-Parametric Instance-level Discrimination"

Unofficial implementation: MoCo: Momentum Contrast for Unsupervised Visual Representation Learning (Paper) InsDis: Unsupervised Feature Learning via N

Zhiqiang Shen 16 Nov 4, 2020
A non-linear, non-parametric Machine Learning method capable of modeling complex datasets

Fast Symbolic Regression Symbolic Regression is a non-linear, non-parametric Machine Learning method capable of modeling complex data sets. fastsr aim

VAMSHI CHOWDARY 3 Jun 22, 2022
A python software that can help blind people find things like laptops, phones, etc the same way a guide dog guides a blind person in finding his way.

GuidEye A python software that can help blind people find things like laptops, phones, etc the same way a guide dog guides a blind person in finding h

Munal Jain 0 Aug 9, 2022
MM1 and MMC Queue Simulation using python - Results and parameters in excel and csv files

implementation of MM1 and MMC Queue on randomly generated data and evaluate simulation results then compare with analytical results and draw a plot curve for them, simulate some integrals and compare results and run monte carlo algorithm with them

Mohamadreza Rezaei 1 Jan 19, 2022
Automates Machine Learning Pipeline with Feature Engineering and Hyper-Parameters Tuning :rocket:

MLJAR Automated Machine Learning Documentation: https://supervised.mljar.com/ Source Code: https://github.com/mljar/mljar-supervised Table of Contents

MLJAR 2.4k Dec 31, 2022
(Arxiv 2021) NeRF--: Neural Radiance Fields Without Known Camera Parameters

NeRF--: Neural Radiance Fields Without Known Camera Parameters Project Page | Arxiv | Colab Notebook | Data Zirui Wang¹, Shangzhe Wu², Weidi Xie², Min

Active Vision Laboratory 411 Dec 26, 2022
Pytorch implementation of "Training a 85.4% Top-1 Accuracy Vision Transformer with 56M Parameters on ImageNet"

Token Labeling: Training an 85.4% Top-1 Accuracy Vision Transformer with 56M Parameters on ImageNet (arxiv) This is a Pytorch implementation of our te

蒋子航 383 Dec 27, 2022
Unofficial & improved implementation of NeRF--: Neural Radiance Fields Without Known Camera Parameters

[Unofficial code-base] NeRF--: Neural Radiance Fields Without Known Camera Parameters [ Project | Paper | Official code base ] ⬅️ Thanks the original

Jianfei Guo 239 Dec 22, 2022