Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor background equilibrium into dedicated functions #126

Merged
merged 24 commits into from
Mar 29, 2023

Conversation

n-claes
Copy link
Owner

@n-claes n-claes commented Mar 29, 2023

PR description

This PR deprecates the various equilibrium fields (rho_field, T_field, v_field and B_field) and favours dedicated functions to specify the background. A new background object is created with various instances containing pointers to the equilibrium functions, which can be subsequently called.

Note that this PR breaks the Legolas API in the user submodule. This change implies:

  • No more global field variables in the equilibrium module. These were imported were needed and it was hard to keep track of them.
  • Reduced cross-module dependencies. The background instance is initialised only once in the main program, and then passed on to the various subroutines. Dedicated intent(in) statements prevent unwanted changes in the background state.
  • The equilibrium functions are position dependent, such that they can be evaluated for any x. This means that we no longer have to interpolate between the base grid, Gaussian grid or eigenfunction grid (eg. for derived eigenfunctions).
  • More user-friendly at the expense of slightly more code, but everything should be more clear. Users no longer need to take the grid into account when setting the background.
  • Less memory usage, especially at high resolutions. The new functions eliminate the need to store the background in arrays and can be evaluated on-the-fly.

Before

real(dp) :: x
integer :: i 
do i = 1, size(grid_gauss)
    rho_field%rho0(i) = 2.0d0 * x**2
    rho_field%d_rho0_dr(i) = 4.0d0 * x
end do

After this PR

call background%set_density_funcs(rho0, drho0)

real(dp) function rho0(x)
  real(dp), intent(in) :: x 
  rho0 = 2.0d0 * x**2
end function rho0

real(dp) function drho0(x)
  real(dp), intent(in) :: x 
  drho0 = 4.0d0 * x
end function drho0

New features

Legolas

  • A new background object to govern the equilibrium background state

@n-claes n-claes added legolas-backend Under-the-hood changes to Legolas performance Affects performance refactor Refactoring existing code legolas-api Changes to the Legolas user API labels Mar 29, 2023
@n-claes n-claes added this to the Legolas 2.0 milestone Mar 29, 2023
@n-claes n-claes merged commit 8cff13b into develop Mar 29, 2023
@n-claes n-claes deleted the refactor/background branch March 29, 2023 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legolas-api Changes to the Legolas user API legolas-backend Under-the-hood changes to Legolas performance Affects performance refactor Refactoring existing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant