<commit_before>! Implementation of the Bastankhah and Porte Agel gaussian-shaped wind turbine wake 
! model (2016) with various farm modeling (TI and wake combination) methods included
! Created by <NAME>, 2017.
! FLight Optimization and Wind Laboratory (FLOW Lab)
! Brigham Young University

! implementation of the Bastankhah and Porte Agel (BPA) wake model for analysis
subroutine porteagel_analyze(nTurbines, nRotorPoints, turbineXw, sorted_x_idx, turbineYw, turbineZ, &
                             rotorDiameter, Ct, wind_speed, &
                             yawDeg, ky, kz, alpha, beta, TI, RotorPointsY, RotorPointsZ, &
                             z_ref, z_0, shear_exp, wake_combination_method, &
                             TI_calculation_method, calc_k_star, wtVelocity)

    ! independent variables: turbineXw turbineYw turbineZ rotorDiameter
    !                        Ct yawDeg

    ! dependent variables: wtVelocity

    implicit none

    ! define precision to be the standard for a double precision ! on local system
    integer, parameter :: dp = kind(0.d0)

    ! in
    integer, intent(in) :: nTurbines, nRotorPoints
    integer, intent(in) :: wake_combination_method, TI_calculation_method
    logical, intent(in) :: calc_k_star
    real(dp), dimension(nTurbines), intent(in) :: turbineXw, turbineYw, turbineZ
    integer, dimension(nTurbines), intent(in) :: sorted_x_idx
    real(dp), dimension(nTurbines), intent(in) :: rotorDiameter, yawDeg
    real(dp), dimension(nTurbines), intent(in) :: Ct
    real(dp), intent(in) :: ky, kz, alpha, beta, TI, wind_speed, z_ref, z_0, shear_exp
    real(dp), dimension(nRotorPoints), intent(in) :: RotorPointsY, RotorPointsZ

    ! local (General)
    real(dp), dimension(nTurbines) :: yaw, TIturbs, k_star
    real(dp) :: x0, deltax0, deltay, theta_c_0, sigmay, sigmaz, wake_offset
    real(dp) :: x, deltav, deltav0m, deltaz, sigmay0, sigmaz0, deficit_sum
    real(dp) :: ky_local, kz_local, tol
    real(dp) :: LocalRotorPointY, LocalRotorPointZ, point_velocity, point_z, point_velocity_with_shear
    Integer :: u, d, turb, turbI, p
    real(dp), parameter :: pi = 3.141592653589793_dp

    ! model out
    real(dp), dimension(nTurbines), intent(out) :: wtVelocity

    intrinsic sin, cos, atan, max, sqrt, log
    
    

    ! bastankhah and porte agel 2016 define yaw to be positive clockwise, this is reversed
    yaw = - yawDeg*pi/180.0_dp
    
    ! set tolerance for location checks
    tol = 0.1_dp
    
    ! initialize wind turbine velocities to 0.0
    wtVelocity = 0.0_dp
    
    ! initialize TI of all turbines to free-stream value
    !print *, "start TIturbs: ", TIturbs
    TIturbs = TI
    !print *, "initialized TIturbs: ", TIturbs
    ky_local = ky
    kz_local = kz

    do, d=1, nTurbines
    
        ! get index of downstream turbine
        turbI = sorted_x_idx(d) + 1
        
        do, p=1, nRotorPoints
    
            ! initialize deficit summation term to zero
            deficit_sum = 0.0_dp
        
            ! scale rotor sample point coordinate by rotor diameter (in rotor hub ref. frame)
            LocalRotorPointY = RotorPointsY(p)*0.5_dp*rotorDiameter(turbI)
            LocalRotorPointZ = RotorPointsZ(p)*0.5_dp*rotorDiameter(turbI)
!             print *, "rotorDiameter after local rotor points", rotorDiameter
!             print *, "local rotor points Y,Z: ", LocalRotorPointY, LocalRotorPointZ
        
            do, u=1, nTurbines ! at turbineX-locations
            
                ! get index of upstream turbine
                turb = sorted_x_idx(u) + 1
                
                if (turb .eq. turbI) cycle
            
                !print *, "rotorDiameter, turbI, turb ", rotorDiameter, turbI, turb
            
                
        
                ! downstream distance between upstream turbine and point
                x = turbineXw(turbI) - turbineXw(turb) + LocalRotorPointY*sin(yaw(turbI))
            
                ! set this iterations velocity deficit to 0
                deltav = 0.0_dp
                
                ! check turbine relative locations
                if (x > (0.0_dp + tol)) then
                
                    !print *, "rotorDiameter before x0 ", rotorDiameter
                
                    ! determine the onset location of far wake
                    call x0_func(rotorDiameter(turb), yaw(turb), Ct(turb), alpha, & 
                                & TIturbs(turb), beta, x0)
        
                    ! downstream distance from far wake onset to downstream turbine
                    deltax0 = x - x0
                
                    ! calculate wake spreading parameter at each turbine if desired
                    if (calc_k_star .eqv. .true.) then
                        call k_star_func(TIturbs(turb), k_star(turb))<commit_msg>added comment for cycle statement<commit_after>! Implementation of the Bastankhah and Porte Agel gaussian-shaped wind turbine wake 
! model (2016) with various farm modeling (TI and wake combination) methods included
! Created by <NAME>, 2017.
! FLight Optimization and Wind Laboratory (FLOW Lab)
! Brigham Young University

! implementation of the Bastankhah and Porte Agel (BPA) wake model for analysis
subroutine porteagel_analyze(nTurbines, nRotorPoints, turbineXw, sorted_x_idx, turbineYw, turbineZ, &
                             rotorDiameter, Ct, wind_speed, &
                             yawDeg, ky, kz, alpha, beta, TI, RotorPointsY, RotorPointsZ, &
                             z_ref, z_0, shear_exp, wake_combination_method, &
                             TI_calculation_method, calc_k_star, wtVelocity)

    ! independent variables: turbineXw turbineYw turbineZ rotorDiameter
    !                        Ct yawDeg

    ! dependent variables: wtVelocity

    implicit none

    ! define precision to be the standard for a double precision ! on local system
    integer, parameter :: dp = kind(0.d0)

    ! in
    integer, intent(in) :: nTurbines, nRotorPoints
    integer, intent(in) :: wake_combination_method, TI_calculation_method
    logical, intent(in) :: calc_k_star
    real(dp), dimension(nTurbines), intent(in) :: turbineXw, turbineYw, turbineZ
    integer, dimension(nTurbines), intent(in) :: sorted_x_idx
    real(dp), dimension(nTurbines), intent(in) :: rotorDiameter, yawDeg
    real(dp), dimension(nTurbines), intent(in) :: Ct
    real(dp), intent(in) :: ky, kz, alpha, beta, TI, wind_speed, z_ref, z_0, shear_exp
    real(dp), dimension(nRotorPoints), intent(in) :: RotorPointsY, RotorPointsZ

    ! local (General)
    real(dp), dimension(nTurbines) :: yaw, TIturbs, k_star
    real(dp) :: x0, deltax0, deltay, theta_c_0, sigmay, sigmaz, wake_offset
    real(dp) :: x, deltav, deltav0m, deltaz, sigmay0, sigmaz0, deficit_sum
    real(dp) :: ky_local, kz_local, tol
    real(dp) :: LocalRotorPointY, LocalRotorPointZ, point_velocity, point_z, point_velocity_with_shear
    Integer :: u, d, turb, turbI, p
    real(dp), parameter :: pi = 3.141592653589793_dp

    ! model out
    real(dp), dimension(nTurbines), intent(out) :: wtVelocity

    intrinsic sin, cos, atan, max, sqrt, log
    
    

    ! bastankhah and porte agel 2016 define yaw to be positive clockwise, this is reversed
    yaw = - yawDeg*pi/180.0_dp
    
    ! set tolerance for location checks
    tol = 0.1_dp
    
    ! initialize wind turbine velocities to 0.0
    wtVelocity = 0.0_dp
    
    ! initialize TI of all turbines to free-stream value
    !print *, "start TIturbs: ", TIturbs
    TIturbs = TI
    !print *, "initialized TIturbs: ", TIturbs
    ky_local = ky
    kz_local = kz

    do, d=1, nTurbines
    
        ! get index of downstream turbine
        turbI = sorted_x_idx(d) + 1
        
        do, p=1, nRotorPoints
    
            ! initialize deficit summation term to zero
            deficit_sum = 0.0_dp
        
            ! scale rotor sample point coordinate by rotor diameter (in rotor hub ref. frame)
            LocalRotorPointY = RotorPointsY(p)*0.5_dp*rotorDiameter(turbI)
            LocalRotorPointZ = RotorPointsZ(p)*0.5_dp*rotorDiameter(turbI)
!             print *, "rotorDiameter after local rotor points", rotorDiameter
!             print *, "local rotor points Y,Z: ", LocalRotorPointY, LocalRotorPointZ
        
            do, u=1, nTurbines ! at turbineX-locations
            
                ! get index of upstream turbine
                turb = sorted_x_idx(u) + 1
                
                ! skip this loop if turb = turbI (turbines impact on itself)
                if (turb .eq. turbI) cycle
            
                !print *, "rotorDiameter, turbI, turb ", rotorDiameter, turbI, turb
            
                
        
                ! downstream distance between upstream turbine and point
                x = turbineXw(turbI) - turbineXw(turb) + LocalRotorPointY*sin(yaw(turbI))
            
                ! set this iterations velocity deficit to 0
                deltav = 0.0_dp
                
                ! check turbine relative locations
                if (x > (0.0_dp + tol)) then
                
                    !print *, "rotorDiameter before x0 ", rotorDiameter
                
                    ! determine the onset location of far wake
                    call x0_func(rotorDiameter(turb), yaw(turb), Ct(turb), alpha, & 
                                & TIturbs(turb), beta, x0)
        
                    ! downstream distance from far wake onset to downstream turbine
                    deltax0 = x - x0
                
                    ! calculate wake spreading parameter at each turbine if desired
                    if (calc_k_star .eqv. .true.) then
                        call k_star_func(TIturbs(turb), k_star(turb))
{'fraction_non_alphanumeric': 0.08165353525017907, 'fraction_numerical': 0.014120536171083598, 'mean_word_length': 2.1137304874163747, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4208088', 'n_tokens_mistral': 3223, 'n_tokens_neox': 2901, 'n_words': 847}