Skip to content

Integrate veqpy equilibrium solver into PROCESS - #4629

Draft
chencx04 wants to merge 11 commits into
ukaea:mainfrom
chencx04:feature/veqpy-integrate
Draft

chencx04 wants to merge 11 commits into
ukaea:mainfrom
chencx04:feature/veqpy-integrate

Conversation

@chencx04

Copy link
Copy Markdown

Description

This draft PR introduces an initial integration of [veqpy](https://github.com/FusionAlpha/veqpy) into PROCESS as an alternative tokamak equilibrium solver.

The main objective is to establish the interface between the existing PROCESS equilibrium inputs and the veqpy solver, and to evaluate how veqpy can be incorporated into the PROCESS equilibrium workflow.

Current implementation

The current implementation includes:

  • integrating veqpy into the PROCESS equilibrium calculation workflow;
  • translating relevant PROCESS equilibrium inputs into the corresponding veqpy inputs;
  • introducing a VeqpyRuntime interface for managing the veqpy equilibrium calculation;
  • passing the relevant equilibrium parameters from PROCESS to veqpy;
  • returning initial equilibrium quantities calculated by veqpy to the PROCESS workflow;
  • adding the necessary PROCESS-side inputs and validation for enabling the veqpy equilibrium model;
  • adding initial documentation for the new equilibrium-related functionality.

The current implementation is intended to provide a working integration framework and allow the PROCESS development team to review the proposed interface and data flow between PROCESS and veqpy.

Current status

The basic PROCESS–veqpy integration and the initial input/output interface have been implemented.

The test coverage is not yet complete. In particular, dedicated unit tests for the PROCESS-to-veqpy input mapping and integration tests covering the complete equilibrium workflow still need to be added.

Therefore, this pull request is opened as a Draft PR. At this stage, the main purpose is to obtain feedback on the integration structure, input mapping, and equilibrium output interface before completing the remaining tests and validation.

Planned work

The remaining work includes:

  • adding unit tests for the PROCESS-to-veqpy input mapping;
  • adding integration tests for the PROCESS–veqpy equilibrium workflow;
  • completing the equilibrium output interface required by downstream PROCESS physics models;
  • validating veqpy equilibrium quantities against appropriate reference calculations;
  • testing the robustness and convergence of veqpy over representative PROCESS parameter variations;
  • improving documentation and examples for the new equilibrium functionality.

In particular, the robustness tests can be performed after the initial integration, together with the integration tests. This will allow veqpy to be evaluated directly under the parameter variations encountered during PROCESS system-code calculations and optimisation.

Design considerations

The integration keeps veqpy as a separate equilibrium solver and introduces a PROCESS-side interface between the existing PROCESS equilibrium inputs and the veqpy API.

The relevant PROCESS inputs are translated into the corresponding veqpy representation within the integration layer. Selected equilibrium quantities calculated by veqpy are then returned to PROCESS for use in the subsequent physics calculations.

At this stage, feedback from the PROCESS development team would be particularly useful regarding:

  • the proposed PROCESS–veqpy interface;
  • the mapping between PROCESS and veqpy equilibrium inputs;
  • which equilibrium quantities should be exposed to the wider PROCESS workflow;
  • the appropriate location of the veqpy integration within the existing PROCESS architecture.

Testing

Dedicated tests for the new integration are still being developed.

Once the interface is agreed, the planned tests will cover:

  1. PROCESS-to-veqpy input conversion;
  2. veqpy equilibrium execution from within PROCESS;
  3. transfer of equilibrium outputs back to PROCESS;
  4. consistency of key equilibrium quantities with reference calculations;
  5. robustness over representative variations of equilibrium and optimisation parameters.

The PR will remain in draft status until the relevant unit and integration tests have been added and the integration has been validated.

Closes #4593

…a geometry

This commit introduces a new plasma geometry option (`i_plasma_geometry = 13`) that allows users to specify the last closed flux surface using discrete (R, Z) points. It includes the addition of `r_array` and `z_array` inputs, which are validated and processed to derive key plasma parameters such as `rmajor`, `rminor`, `kappa`, and `triang`. The implementation also tracks the number of LCFS points provided and updates relevant documentation to reflect these changes.
This commit refines the handling of the R_AND_Z_ARRAY plasma geometry model by moving the relevant calculations into the match-case structure. The logic for computing `kappa`, `triang`, `kappa95`, and `triang95` based on the last closed flux surface (LCFS) arrays is now encapsulated within the appropriate case, improving code organization and readability. The previous implementation using an if statement has been removed to streamline the code.
…olve.

Plasma current:
- Accept i_plasma_current = 0 and read the current from
  plasma_current_user_input.
- Require that input to be positive, and allow it with negative triangularity.
- Leave the existing scaling laws unchanged when another model is selected.

Equilibrium:
- Add i_equilibrium_solve. When it is 1, iterate the on-axis electron density
  and temperature in veqpy until their volume averages match the PROCESS targets.
- Rebuild the profiles from those axis values. Scale the ion temperature by the
  volume-average ion-to-electron temperature ratio.
- Take the density-weighted electron temperature, normalised internal inductance,
  and on-axis current density from the solved equilibrium.
- Revised comments to enhance understanding of the code, specifically regarding the integration of source for psin and the calculation of volume average <Bp^2>.
- Improved readability by translating comments from Chinese to English and standardizing terminology.
- Introduced validation checks for user-specified plasma current and current profile index when `i_equilibrium_solve` is set to 1.
- Enhanced the `Physics` class to compute the inboard and outboard toroidal magnetic fields based on the plasma equilibrium.
- Updated the calculation of the total magnetic field at both inboard and outboard locations, ensuring accurate representation of plasma conditions.
This commit introduces a new static method `bootstrap_fraction_sauter_equilibrium` in the `PlasmaBootstrapCurrent` class to calculate the bootstrap fraction based on Sauter equilibrium conditions. Additionally, a new static method `diamagnetic_integral` is added to the `PlasmaDiamagneticCurrent` class for calculating the diamagnetic integral based on the plasma equilibrium. These enhancements improve the accuracy and functionality of the plasma current models, facilitating more detailed plasma behavior analysis.
This commit updates the import statements in `main.py`, `init.py`, and `physics.py` to ensure consistency and clarity. Additionally, it enhances the docstrings in `input.py`, `plasma_equilibrium.py`, and `plasma_current.py` to provide better context and error handling information. These changes improve code readability and maintainability across the project.
…ntegration

This commit introduces a new `VeqpyRuntime` class to manage the latest veqpy equilibrium state and its associated axis iteration results. Additionally, it enhances the `plasma_equilibrium.py` file by adding functions to check the availability of veqpy equilibrium, clear transient results, and store equilibrium data. These changes improve the handling of plasma equilibrium states and facilitate better integration with veqpy functionalities.
This commit removes the direct instantiation of `PlasmaEquilibrium` from the `Models` and `Physics` classes, replacing it with a more integrated approach using the `VeqpyRuntime` class. It enhances the `Physics` class to utilize the new equilibrium management methods, ensuring that plasma equilibrium calculations are more streamlined and consistent with the latest veqpy functionalities. Additionally, validation checks for user inputs related to plasma equilibrium are updated to improve error handling.
This commit introduces a validation check in the `check_process` function to ensure that when the pedestal type is set to `GREENWALD_FRACTION` and the equilibrium solver is active (`i_equilibrium_solve = 1`), the user must provide absolute density values for pedestal and separatrix densities. An appropriate error is raised if these conditions are not met, enhancing the robustness of input handling in the plasma modeling framework.
…l_avg

This commit updates the VeqpyRuntime class to include a new attribute for the volume-averaged electron density, f_temp_plasma_electron_density_vol_avg. The Physics and PlasmaEquilibrium classes are modified to store and utilize this new attribute during equilibrium calculations. Additionally, references to the equilibrium state are streamlined to improve consistency across the plasma modeling framework.
@timothy-nunn

Copy link
Copy Markdown
Collaborator

Dear @chencx04,

Firstly, thank you for making this contribution to PROCESS. As an open-source code, we encourage and appreciate any and all contributions made by the wider fusion community.

With a contribution of this magnitude, I think it would be necessary to have discussions outside of GitHub pull requests/issues to make any design and architecture decisions. May I encourage you to make contact with us via our contact form https://www.ukaea.org/service/process/.

We look forward to hearing from you.

Many thanks,
Timothy Nunn
UK Atomic Energy Authority

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrate veqpy as an optional tokamak equilibrium solver

2 participants