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
From the basics to slightly more interesting applications of Tensorflow

TensorFlow Tutorials You can find python source code under the python directory, and associated notebooks under notebooks. Source code Description 1 b

Parag K Mital 5.6k Jan 09, 2023
An implementation of MobileFormer

MobileFormer An implementation of MobileFormer proposed by Yinpeng Chen, Xiyang Dai et al. Including [1] Mobile-Former proposed in:

slwang9353 62 Dec 28, 2022
An implementation of quantum convolutional neural network with MindQuantum. Huawei, classifying MNIST dataset

关于实现的一点说明 山东大学 2020级 苏博南 www.subonan.com 文件说明 tools.py 这里面主要有两个函数: resize(a, lenb) 这其实是我找同学写的一个小算法hhh。给出一个$28\times 28$的方阵a,返回一个$lenb\times lenb$的方阵。因

ぼっけなす 2 Aug 29, 2022
Code for "Learning Canonical Representations for Scene Graph to Image Generation", Herzig & Bar et al., ECCV2020

Learning Canonical Representations for Scene Graph to Image Generation (ECCV 2020) Roei Herzig*, Amir Bar*, Huijuan Xu, Gal Chechik, Trevor Darrell, A

roei_herzig 24 Jul 07, 2022
10th place solution for Google Smartphone Decimeter Challenge at kaggle.

Under refactoring 10th place solution for Google Smartphone Decimeter Challenge at kaggle. Google Smartphone Decimeter Challenge Global Navigation Sat

12 Oct 25, 2022
CS5242_2021 - Neural Networks and Deep Learning, NUS CS5242, 2021

CS5242_2021 Neural Networks and Deep Learning, NUS CS5242, 2021 Cloud Machine #1 : Google Colab (Free GPU) Follow this Notebook installation : https:/

Xavier Bresson 165 Oct 25, 2022
A Python framework for developing parallelized Computational Fluid Dynamics software to solve the hyperbolic 2D Euler equations on distributed, multi-block structured grids.

pyHype: Computational Fluid Dynamics in Python pyHype is a Python framework for developing parallelized Computational Fluid Dynamics software to solve

Mohamed Khalil 21 Nov 22, 2022
How will electric vehicles affect traffic congestion and energy consumption: an integrated modelling approach

EV-charging-impact This repository contains the code that has been used for the Queue modelling for the paper "How will electric vehicles affect traff

7 Nov 30, 2022
Pytorch implementation of the paper "Optimization as a Model for Few-Shot Learning"

Optimization as a Model for Few-Shot Learning This repo provides a Pytorch implementation for the Optimization as a Model for Few-Shot Learning paper.

Albert Berenguel Centeno 238 Jan 04, 2023
Solutions of Reinforcement Learning 2nd Edition

Solutions of Reinforcement Learning, An Introduction

YIFAN WANG 1.4k Dec 30, 2022
🎯 A comprehensive gradient-free optimization framework written in Python

Solid is a Python framework for gradient-free optimization. It contains basic versions of many of the most common optimization algorithms that do not

Devin Soni 565 Dec 26, 2022
Implementation of Gans

GAN Generative Adverserial Networks are an approach to generative data modelling using Deep learning methods. I have currently implemented : DCGAN on

Sibam Parida 5 Sep 07, 2021
Detecting Potentially Harmful and Protective Suicide-related Content on Twitter

TwitterSuicideML Scripts for reproducing the Machine Learning analysis of the paper: Detecting Potentially Harmful and Protective Suicide-related Cont

3 Oct 17, 2022
Liquid Warping GAN with Attention: A Unified Framework for Human Image Synthesis

Liquid Warping GAN with Attention: A Unified Framework for Human Image Synthesis, including human motion imitation, appearance transfer, and novel view synthesis. Currently the paper is under review

2.3k Jan 05, 2023
Global Rhythm Style Transfer Without Text Transcriptions

Global Prosody Style Transfer Without Text Transcriptions This repository provides a PyTorch implementation of AutoPST, which enables unsupervised glo

Kaizhi Qian 193 Dec 30, 2022
An official implementation of "SFNet: Learning Object-aware Semantic Correspondence" (CVPR 2019, TPAMI 2020) in PyTorch.

PyTorch implementation of SFNet This is the implementation of the paper "SFNet: Learning Object-aware Semantic Correspondence". For more information,

CV Lab @ Yonsei University 87 Dec 30, 2022
Train CPPNs as a Generative Model, using Generative Adversarial Networks and Variational Autoencoder techniques to produce high resolution images.

cppn-gan-vae tensorflow Train Compositional Pattern Producing Network as a Generative Model, using Generative Adversarial Networks and Variational Aut

hardmaru 343 Dec 29, 2022
Improving Compound Activity Classification via Deep Transfer and Representation Learning

Improving Compound Activity Classification via Deep Transfer and Representation Learning This repository is the official implementation of Improving C

NingLab 2 Nov 24, 2021
Adaptation through prediction: multisensory active inference torque control

Adaptation through prediction: multisensory active inference torque control Submitted to IEEE Transactions on Cognitive and Developmental Systems Abst

Cristian Meo 1 Nov 07, 2022
In the case of your data having only 1 channel while want to use timm models

timm_custom Description In the case of your data having only 1 channel while want to use timm models (with or without pretrained weights), run the fol

2 Nov 26, 2021