###########################################################################################
###########################################################################################
## Function to model air-water gas transfer velocity for bubbles
###########################################################################################
###########################################################################################
## created by Marcus Klaus, Swedish University of Agricultural Sciences (SLU), Umeå, Sweden
## contact: marcus.klaus@slu.se
## last update: 2026/04/30
###########################################################################################

## INPUTS:
# D...Diffusivity (m2/s)
# Vb...bubble velocity (m/s), e.g. turbulent vertical flow velocity
# v...kinematic viscosity (m2/s)
# r...bubble radius (m)
# g...gravity acceleration (m/s2)
# k_bub_model...method (W93_Eq39, W93_Eq42, W93_Eq43, MM85)

## OUTPUTS:
# k_bub...transfer velocity of single bubble (m/s) 
#
# References
# Woolf 1993. Bubbles and the air‐sea transfer velocity of gases. Atmosphere-Ocean 31:4,517-540, DOI: 10.1080/07055900.1993.9649484
# Memery and Merlivat 1985. Modelling of gas flux through bubbles at the air-water interface. Tellus (1985), 37B, 212-285. https://doi.org/10.3402/tellusb.v37i4-5.15030
################################################################


calcKBubble <- function(D,Vb,v,r,g,k_bub_model){


# low estimate (Woolf 1993, Eq. 39, originally from Clift et al. (1978)),  dirty bubble, r>10 micron, quiescent liquid
if(k_bub_model=="W93_Eq39"){
  k_bub <- 0.42 * g^0.3*v^0.4*(D/v)^(2/3)*r^-0.1
}
# intermediate estimate (Woolf 1993, Eq. 42, originally from Clift et al. (1978)), clean bubble, quiscent liquid
if(k_bub_model=="W93_Eq42"){
  # Reynolds number (unitless)
  Re <- 2*Vb*r/v
  if(Re>=10){
    k_bub <- ((1-2.89/sqrt(Re))*2*D*Vb/(pi*r))^(1/2)
  }
  if(Re<10){
    k_bub <- 0.23*(D*Vb/r)^1/2
  } 
}
# high estimate (Woolf 1993, Eq. 43, originally from Clift et al. (1978)), clean bubble, quiescent liquid
if(k_bub_model=="W93_Eq43"){
  k_bub <- (1.75*10^-8*r^-3+1.84*r^(-0.25))*D^(1/2)
}
# intermediate estimate (Memery and Merlivat 1985, originally from Levich 1962), dirty bubble (solid sphere)
if(k_bub_model=="MM85_Eq5"){
  k_bub <- 8*(D^2*Vb/(r^2))^(1/3)
}
# very high estimate (Memery and Merlivat 1985, originally from Levich 1962), clean bubble, r > 500 pm
if(k_bub_model=="MM85_Eq7"){
  k_bub <- 8*(pi*D*Vb/(2*r))^(1/2)
}

  
return(k_bub)  
}
