<commit_before>! Module that exposes the integrator that transforms the state_in to the state_out

module mod_integrator
  use mod_constants
  use mod_timestep
  use mod_read_parameters
  use mod_variables

  implicit none 
  private

  public :: do_timestep_T, do_timestep_S
  
contains
  ! (T(t+dt) - T(t))/dt = f(s, dt)
  function f (s, dt)
  !process the right term of \partial T* / \partial t* = (see Recapitulatif des adimensionenemts in report)
    implicit none
    
    type(state), intent(in)                    :: s
    real (kind=x_precision), intent(in)        :: dt
    real (kind=x_precision), dimension(n_cell) :: f

    real (kind=x_precision)                    :: overdx, overdx2, overdt
    real (kind=x_precision), dimension(n_cell) :: dS_over_dt, dS_over_x_over_dx, S_over_x, dT_over_dx, nuS

    overdx  = 1/params%dx
    overdx2 = overdx**2
    overdt  = 1/dt
    nuS = s%nu*s%S

    ! Compute dT/dx as the mean spatial derivative (left + right)/2
    dT_over_dx(1:n_cell - 1) = (s%T(2:n_cell) - s%T(1:n_cell - 1)) * overdx
    dT_over_dx(n_cell)       = 0

    ! Compute d(S/x)/dx as the mean spatial derivative (left + right)/2
    S_over_x                        = s%S / x_state%x
    ! dS_over_x_over_dx(1)            = -2._x_precision / s%v(1) / s%x(1)**2 * nuS(2) * overdx2
    dS_over_x_over_dx(1:n_cell - 1) = (S_over_x(2:n_cell) - S_over_x(1:n_cell - 1)) * overdx 
    dS_over_x_over_dx(n_cell)       = ( params%dx + nuS(n_cell)*(params%dx - 2._x_precision) &
    + nuS(n_cell-1) )/ x_state%x(n_cell)**2 / s%v(n_cell) &
    / params%dx**2 

    ! Compute dS/dt using the corresponding equation, with d²(nuS)/dx² as (d(left)+d(right))/2
    dS_over_dt(1:n_cell-1) = 1 / x_state%x(1:n_cell-1)**2 * (nuS(2:n_cell) - 2._x_precision*nuS(1:n_cell-1) + &
                             nuS(1:n_cell-1)) * overdx2
    dS_over_dt(n_cell)     = ( params%dx + nuS(n_cell)*(params%dx - 2._x_precision) + nuS(n_cell-1) ) &
    / params%dx**2 / x_state%x(n_cell)**2

    ! Second member of the dT/dt equation
    f = (3_x_precision * state_0%v_0**2 * s%nu * x_state%Omega**2 - &
         s%Fz * x_state%x / s%S &
         + params%RTM * (4._x_precision - 3._x_precision * s%beta) / s%beta * s%T / s%S * &
         (dS_over_dt + s%v * dS_over_x_over_dx) &
         - s%Cv * s%v / x_state%x * dT_over_dx) / s%Cv
  end function f

  subroutine do_timestep_S (states, dt)
  !process the temporal evolution of S
    implicit none
    
    type (state), intent(inout)                   :: states

    real(kind = x_precision)                      :: overdx, overdx2, overdt
    real(kind = x_precision), intent(in)          :: dt
    integer                                       :: info

    real(kind = x_precision), dimension(n_cell)   :: diag
    real(kind = x_precision), dimension(n_cell-1) :: diag_low, diag_up
    
    overdx  = 1_x_precision/params%dx
    overdx2 = overdx**2
    overdt  = 1_x_precision/dt<commit_msg>add limits condition<commit_after>! Module that exposes the integrator that transforms the state_in to the state_out

module mod_integrator
  use mod_constants
  use mod_timestep
  use mod_read_parameters
  use mod_variables

  implicit none 
  private

  public :: do_timestep_T, do_timestep_S
  
contains
  ! (T(t+dt) - T(t))/dt = f(s, dt)
  function f (s, dt)
  !process the right term of \partial T* / \partial t* = (see Recapitulatif des adimensionenemts in report)
    implicit none
    
    type(state), intent(in)                    :: s
    real (kind=x_precision), intent(in)        :: dt
    real (kind=x_precision), dimension(n_cell) :: f

    real (kind=x_precision)                    :: overdx, overdx2, overdt
    real (kind=x_precision), dimension(n_cell) :: dS_over_dt, dS_over_x_over_dx, S_over_x, dT_over_dx, nuS

    overdx  = 1/params%dx
    overdx2 = overdx**2
    overdt  = 1/dt
    nuS = s%nu*s%S

    ! Compute dT/dx as the mean spatial derivative (left + right)/2
    dT_over_dx(1:n_cell - 1) = (s%T(2:n_cell) - s%T(1:n_cell - 1)) * overdx
    dT_over_dx(n_cell)       = 0

    ! Compute d(S/x)/dx as the mean spatial derivative (left + right)/2
    S_over_x                        = s%S / x_state%x
    dS_over_x_over_dx(1:n_cell - 1) = (S_over_x(2:n_cell) - S_over_x(1:n_cell - 1)) * overdx
    dS_over_x_over_dx(n_cell)       = ( params%dx - nuS(n_cell) + nuS(n_cell-1) ) / &
                                      ( x_state%x(n_cell)**2 * s%v(n_cell) * params%dx**2 )

    ! Compute dS/dt using the corresponding equation, with d²(nuS)/dx² as (d(left)+d(right))/2
    dS_over_dt(1:n_cell-1) = 1 / x_state%x(1:n_cell-1)**2 * (nuS(2:n_cell) - 2._x_precision*nuS(1:n_cell-1) + &
                             nuS(1:n_cell-1)) * overdx2
    dS_over_dt(n_cell)     = ( params%dx - nuS(n_cell) + nuS(n_cell-1) ) / &
                             ( x_state%x(n_cell)**2 * params%dx**2 )

    ! Second member of the dT/dt equation
    f = (3_x_precision * state_0%v_0**2 * s%nu * x_state%Omega**2 - &
         s%Fz * x_state%x / s%S &
         + params%RTM * (4._x_precision - 3._x_precision * s%beta) / s%beta * s%T / s%S * &
         (dS_over_dt + s%v * dS_over_x_over_dx) &
         - s%Cv * s%v / x_state%x * dT_over_dx) / s%Cv
  end function f

  subroutine do_timestep_S (states, dt)
  !process the temporal evolution of S
    implicit none
    
    type (state), intent(inout)                   :: states

    real(kind = x_precision)                      :: overdx, overdx2, overdt
    real(kind = x_precision), intent(in)          :: dt
    integer                                       :: info

    real(kind = x_precision), dimension(n_cell)   :: diag
    real(kind = x_precision), dimension(n_cell-1) :: diag_low, diag_up
    
    overdx  = 1_x_precision/params%dx
    overdx2 = overdx**2
    overdt  = 1_x_precision/dt
{'fraction_non_alphanumeric': 0.1280013819312489, 'fraction_numerical': 0.01917429607877008, 'mean_word_length': 2.362369337979094, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1024519', 'n_tokens_mistral': 2371, 'n_tokens_neox': 2256, 'n_words': 461}