functions.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <grass/gis.h>
  5. #include <math.h>
  6. #include "local_proto.h"
  7. extern CELL f_c(CELL);
  8. extern FCELL f_f(FCELL);
  9. extern DCELL f_d(DCELL);
  10. /* constant definition */
  11. /* #define k_sb 4.903 //[MJ/m2*h] Stefan Bolzman constant */
  12. #define cp 1.013 /* [kJ/kg*°C] specific heat of moist air */
  13. #define epsilon 0.622 /* [-] ratio of molecular weigth of water to dry air */
  14. #define Po 101.3 /* [kPa] atmospheric pressure at sea level */
  15. #define Tko 293.16 /* [K] reference temperature at sea level */
  16. #define eta 0.0065 /* [K/m] constant lapse rate */
  17. #define Ao 0 /* [m] altitude at sea level */
  18. #define g 9.81 /* [m/s] gravitational accelleration */
  19. #define R 287 /* [J/kg*K] specific gas constant */
  20. #define Zw 2 /* [m] height of wind measurements */
  21. #define Zh 2 /* [m] height of humidity measurements */
  22. #define k 0.41 /* [-] Von Karman constant */
  23. DCELL calc_ETp(DCELL T, DCELL Z, DCELL u2, DCELL Rn, int night, DCELL Rh,
  24. DCELL hc)
  25. {
  26. DCELL ea, delta, gamma, gstar, lambda;
  27. DCELL P, ra, d, Zom, Zoh, G, ETrad, u10, rs, ed, Tkv, rho, ETaero, ETp;
  28. /* calculus: mean saturation vapoure pressure [KPa] */
  29. ea = 0.61078 * exp((17.27 * T) / (T + 237.3));
  30. /* calculus: slope of vapoure pressure curve [KPa/°C] */
  31. delta = (4098 * ea) / pow((237.3 + T), 2);
  32. /* calculus: latent heat vapourisation [MJ/kg] */
  33. lambda = 2.501 - (0.002361 * T);
  34. /* calculus: atmospheric pressure [KPa] */
  35. P = Po * pow(((Tko - eta * (Z - Ao)) / Tko), (g / (eta * R)));
  36. /* calculus: psichiometric constant [kPa/°C] */
  37. gamma = ((cp * P) / (epsilon * lambda)) * 0.001;
  38. /* calculus: aerodynamic resistance [s/m] */
  39. if (hc < 2) {
  40. d = (2 / 3) * hc;
  41. Zom = 0.123 * hc;
  42. Zoh = 0.1 * Zom;
  43. ra = (log((Zw - d) / Zom) * log((Zh - d) / Zoh)) / (k * k * u2);
  44. }
  45. else {
  46. u10 = u2 * (log((67.8 * 10) - 5.42)) / 4.87;
  47. ra = 94 / u10;
  48. }
  49. /* calculus: surface resistance [s/m] */
  50. rs = 100 / (0.5 * 24 * hc);
  51. /*calculus: modified psichiometric constant [kPa/°C] */
  52. gstar = gamma * (1 + (rs / ra));
  53. /*calculus: net radiation [MJ/m2*d] */
  54. /*Rn derived from r.sun */
  55. /*calculus: soil heat flux [MJ/m2*d] */
  56. if (night == FALSE)
  57. G = 0.1 * Rn;
  58. else
  59. G = 0.5 * Rn;
  60. /* calculus: radiation term [mm/h] */
  61. /* ETrad = (delta/(delta+gstar))*((Rn-G)/(lambda*1000000)); */
  62. ETrad = (delta / (delta + gstar)) * ((Rn - G) / lambda); /* torna da analisi dimensionale */
  63. /* calculus: actual vapoure pressure [kPa] */
  64. ed = Rh * ea / 100;
  65. /* calculus: virtual temperature [°C] */
  66. Tkv = (T + 273.15) / (1 - (0.378 * ed / P));
  67. /* calculus: atmospheric density [Kg/m^3] */
  68. rho = P / (Tkv * R / 100);
  69. /* calculus: aerodynamic term [mm/h] */
  70. /* ETaero = (0.001/lambda)*(1/(delta+gstar))*(rho*cp/ra)*(ea-ed); */
  71. ETaero = (3.6 / lambda) * (1 / (delta + gstar)) * (rho * cp / ra) * (ea - ed); /* torna da analisi dimensionale */
  72. /* calculus: potential evapotranspiration [mm/h] */
  73. ETp = ETrad + ETaero;
  74. return ETp;
  75. }
  76. DCELL calc_openwaterETp(DCELL T, DCELL Z, DCELL u2, DCELL Rn, int day,
  77. DCELL Rh, DCELL hc)
  78. {
  79. DCELL ea, delta, gamma, lambda;
  80. DCELL P, ed, ETaero, ETp;
  81. /* calculus: mean saturation vapoure pressure [KPa] */
  82. ea = 0.61078 * exp((17.27 * T) / (T + 237.3));
  83. /* calculus: slope of vapoure pressure curve [KPa/°C] */
  84. delta = (4098 * ea) / pow((237.3 + T), 2);
  85. /* calculus: latent heat vapourisation [MJ/kg] */
  86. lambda = 2.501 - (0.002361 * T);
  87. /* calculus: atmospheric pressure [KPa] */
  88. P = Po * pow(((Tko - eta * (Z - Ao)) / Tko), (g / (eta * R)));
  89. /* calculus: di psichiometric constant [kPa/°C] */
  90. gamma = ((cp * P) / (epsilon * lambda)) * 0.001;
  91. /* calculus: net radiation [MJ/m2*h] */
  92. /* Rn derived from r.sun */
  93. /*calculus: actual vapoure pressure [kPa] */
  94. ed = Rh * ea / 100;
  95. /*calculus: aerodynamic term [mm/h] */
  96. /*ETaero = 0.35*(0.5+(0.621375*u2/100))*7.500638*(ea-ed); */
  97. /*to convert mm/d to mm/h it results: */
  98. ETaero =
  99. (0.35 / 24) * (0.5 + (0.621375 * u2 / 100)) * 7.500638 * (ea - ed);
  100. /*calculus: potential evapotranspiration [mm/h] */
  101. ETp = (((Rn * delta) / lambda) + (gamma * ETaero)) / (delta + gamma);
  102. return ETp;
  103. }
  104. #if 0
  105. DCELL calc_ETp_WaSiM(){
  106. /* calculus of saturation vapour pressure at the temperature T: es[hPa] */
  107. /* with T[°C] */
  108. es = 6.1078*exp((17.27*T)/(237.3+T);
  109. /* tangent of the saturated vapour pressure curve: D[hPa/K] with T[°C] */
  110. D = (25029/pow((273.3+T),2))*exp((17.27*T)/(237.3+T);
  111. /* air pressure at level hM */
  112. P = 1013*exp(-hM/(7991+29.33*Tv));
  113. /* calculus of lambda [KJ/Kg] with T[°C] */
  114. lambda = 2500.8 - 2.372*T;
  115. /* calculus psichiometric constant gamma [hPa/°C] with cp=1.005[KJ/(Kg*K)] */
  116. gamma = ((1.005*P)/(0.622*lambda))*0.001;
  117. #endif