function fun = calSw (S_w)
global fmmob fmdry S_wc S_gr krw0 krg0 nw ng visw visg epdry

Fwater=0.5+(atan(epdry*(S_w-fmdry)))/pi;

krw=krw0*((S_w-S_wc)/(1-S_gr-S_wc)).^nw;
krg=krg0*(1-(S_w-S_wc)/(1-S_gr-S_wc)).^ng.*(1./(1+fmmob*Fwater));

fg=0.9; %based on experimental data

fun=1./(1+krw.*visg./(krg.*visw))-fg;
