Git Product home page Git Product logo

remkit1d-python's Introduction

ReMKiT1D Python support

tests black/mypy codecov Documentation Status

Contact: [email protected]

Overview

RMK_support is a collection of tools designed to configure and analyze ReMKiT1D runs. ReMKiT1D is a framework for building multi-fluid models in 1D with reaction and kinetic electron support, aimed primarily at simulating the tokamak Scrape-Off Layer.

ReMKiT1D runs use JSON files to configure the models and methods used by the code, and RMK_support provides convenient Python routines for the generation of these config files, while also providing features that enable analysis of data using obtained from ReMKiT1D runs.

For a high level overview of the framework and the Python interface see the code paper.

Prerequisites

All routines are written for Python3, with the following libraries required for the .py support modules:

  1. numpy
  2. xarray
  3. holoviews
  4. panel
  5. matplotlib
  6. h5py
  7. scipy

Installation

RMK_support is installable using pip through PyPI by simply calling

pip install RMK_support

Alternatively, it can be installed from this repository by running

pip install .

from the repository root.

Repository structure

The package files are in the RMK_support folder, together with the tests, which can be run using pytest.

The examples folder contains both general examples and tutorials for problems relevant in SOL physics, as well as a number of verification tests, some of which have been reported on in the code paper.

The data folder contains some atomic data used by some of the examples, in particular the spontaneous emission rates for hydrogen obtained from NIST (see the CRM example notebook). This folder should contain the amjuel.tex file from the EIRENE AMJUEL database in order to run some of the examples! This file is not distributed with the repository.

High-level workflow

1. Initialization

The main group of support modules handle the translation of initialization data into the JSON format in a way that ReMKiT1D's initialization routines can decode.

While it is possible to write most of the required config.json file by hand if the user knows the exact key names in the corresponding ReMKiT1D initialization routine, a wrapper ecosystem allows users to initialize config files with little to no knowledge of the underlying json structure.

The general workflow of initializing a functional config.json file using the RKWrapper class can be roughly divided into 5 steps:

  1. Setting up global external library options (MPI, PETSc, HDF5)
  2. Initializing the basic objects used by the code. These include normalization, the grid, a standard textbook object and optional custom derivations, as well as species data. Most of these have default options that can be used to simplify the initialization procedure.
  3. Setting up the variable container by adding variables and optionally initializing them, as well as associating derived variables in the variable container with derivations by supplying a derivation name and a number of required variables used in the calculation. At this stage the interaction between the MPI and HDF5 libraries and the variables can be specified through options to communicate or output specific variables.
  4. Defining the models used to evolve/calculate variables by specifying term options and modelbound data. This is the main part of the configuration file and the most complex. See different notebooks for examples of how to initialize models. Optional data manipulator objects can be specified here as well.
  5. The last step is specifying time integration options. Here the integrator structure and timestep control can be specified, as well as the structure of the main timeloop (timestep number, output frequency etc.)

The above steps are shown in the figure below, with some of the interdependencies shown in UML style.

2. Data analysis and visualization

The secondary feature of RMK_support modules is data analysis and visualization, powered by variable data being stored in an xarray dataset and visualization tools built on holoviews and panel. Examples of loading simulation data and using holoviews/panel for visualization are in multiple notebooks.

Further development is planned to streamline data analysis, including improvements to the included interactive dashboard.

Documentation, examples and tutorials

For a high level explanation of both the framework and the interface the user is referred to the ReMKiT1D code paper, where the code design is explained and an example workflow with this Python package is explained.

The examples/tutorials in the examples folder supplement the code paper, in particular the advection and custom fluid notebooks, which are documented in detail.

Further code documentation is available here.

Licence

RMK_support is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

RMK_support is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with RMK_support. If not, see https://www.gnu.org/licenses/.

Copyright 2023 United Kingdom Atomic Energy Authority

remkit1d-python's People

Contributors

smijin avatar alfieadhemar avatar

Stargazers

Lorenzo Campoli avatar Sid Leigh avatar  avatar  avatar John Lloyd Baker avatar  avatar  avatar  avatar

Watchers

Chris MacMackin avatar Alys Brett avatar Jonathan Hollocombe avatar  avatar  avatar

Forkers

lkampoli

remkit1d-python's Issues

Matrix-free advection example produces seg fault when BE integrator method used.

An advanced ReMKiT1D example revisiting the advection problem has been written, but this time using the v1.2.0 UnaryTransform("shift") feature to define stencils without actually having to explicitly use stencil or matrix objects.

It will also showcase other v1.2.0 features including Grid helper functions.

The example in my dev branch works fine for CVODE and RK integrators but not for the BE integrator, which seems to cause a segmentation fault on the first iteration. Will need to investigate this in closer detail.

To do:

  • Fix segmentation fault when using the BE integrator.
  • Pass Jacobians and DualWidth into the divNode and pGrad functions - thereby making them grid-agnostic.

Improve documentation in common models

The models in common_models should have their documentation improved to make what they are doing clearer.

For example, it should be made clear that staggeredAdvection produces a central difference stencil on the staggered grid when advecting staggered variables.

Implement an improved version of the RKWrapper class to enable nonlinear workflows

At the moment, the RKWrapper assumes a linear workflow through the majority of the simulation construction process. For example, it does not store individual model objects, and instead adds their dictionary representation to its internal configuration state. This means that it is difficult or impossible to retrieve added models for potential removal, modification, or detailed reference.

Ideally, an improved design would store all of the objects necessary to build the configuration file in such a way that the individual components can be changed or removed without rebuilding the entire wrapper. This would likely require redesigning the majority of ReMKiT1D objects to enable their modification.

Given the breaking nature of this redesign, it is almost certain that a new wrapper class should be added instead of modifying the existing wrapper to enable the backwards compatibility with current linear workflows.

Calculation tree evaluation on numpy arrays

Previously, calculation trees and nodes have only been used to build the corresponding derivations for use in the Fortran codebase. However, examples have appeared where it would be preferable to have a function produce both a node/calculation tree for the Fortran code as well as something that could be evaluated in the Python environment.

As such, the following syntax is desirable.

a = Node("a")
b = Node("b")
c = a + sin(b)
c.evaluate(variables) # -> np.ndarray

where variables would be of type Dict[str,np.ndarray] and would contain the keys for the leafVariables a and b.

To support different custom UnaryTransformations that could exist in the Fortran code, the UnaryTransformation class should have an additional optional component of type Callable[[List[float], List[int], List[bool], np.ndarray], np.ndarray]. For basic functions, this should be provided by the calculation_tree_support module.

Improve documentation for Grid and RKWrapper

There are missing docstrings in the Grid constructor and the addVar member function on the wrapper needs to have its documentation improved. Other improvements should also be done systematically.

Add __rtruediv__ operation for nodes

There are occasions where it is useful to have a number divided by a node. such as in the case of 1/Node. At present it is not possible for this to be done in the ReMKiT1D framework.

Initialisation of variables on dual grid permits non-zero last value

At the moment, there is no warning when users input a non-zero initial condition on the last (rightmost) cell boundary for variables on dual grids. This can lead to confusion, as it can confound with existing boundary conditions. For example, setting both a non-zero particle flux on the last cell as well as an explicit outflow boundary condition leads to those two fluxes adding together.

Given that there is a use case for setting these values to be non-zero (fixed outflow conditions), a warning should be added in case the user did not intend to do that.

Auto add custom derivation when adding derived variable.

When many variables are derived, it is cumbersome to have to create a custom derivation for each derived variable. It would be simpler to pass the derivOptions to the variable as it is declared such that it can automatically add the custom derivation used in the variable's derivation rule.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.