source: issm/oecreview/Archive/21724-22754/ISSM-22735-22736.diff@ 22755

Last change on this file since 22755 was 22755, checked in by Mathieu Morlighem, 7 years ago

CHG: added 21724-22754

File size: 2.7 KB
RevLine 
[22755]1Index: ../trunk-jpl/src/c/modules/SurfaceMassBalancex/Gembx.cpp
2===================================================================
3--- ../trunk-jpl/src/c/modules/SurfaceMassBalancex/Gembx.cpp (revision 22735)
4+++ ../trunk-jpl/src/c/modules/SurfaceMassBalancex/Gembx.cpp (revision 22736)
5@@ -1332,7 +1332,7 @@
6 for(int i=0;i<n;i++) exsT[i]= fmax(0.0, T[i] - CtoK); // [K] to [degC]
7
8 // new grid point center temperature, T [K]
9- //for(int i=0;i<n;i++) T[i]-=exsT[i];
10+ // for(int i=0;i<n;i++) T[i]-=exsT[i];
11 for(int i=0;i<n;i++) T[i]=fmin(T[i],CtoK);
12
13 // specify irreducible water content saturation [fraction]
14@@ -1381,21 +1381,20 @@
15 surpE=xNew<IssmDouble>(n); for(int i=0;i<n;i++)surpE[i] = surpT[i] * CI * m[i];
16
17 int i = 0;
18- while (cellsum(surpE,n) > 0.0 + Ttol){
19+ while (cellsum(surpE,n) > 0.0 + Ttol && i<n-1){
20+
21 // use surplus energy to increase the temperature of lower cell
22 T[i+1] = surpE[i]/m[i+1]/CI + T[i+1];
23-
24- exsT[i+1] = fmax(0.0, T[i+1] - CtoK) + exsT[i+1];
25- T[i+1] = fmin(CtoK, T[i+1]);
26-
27- surpT[i+1] = fmax(0.0, exsT[i+1] - LF/CI);
28+ surpT[i+1] = fmax(0.0, (T[i+1] - CtoK - LF/CI));
29 surpE[i+1] = surpT[i+1] * CI * m[i+1];
30-
31+
32 // adjust current cell properties (again 159.1342 is the max T)
33- exsT[i] = LF/CI;
34+ T[i] = T[i]-surpE[i]/m[i+1]/CI;
35 surpE[i] = 0.0;
36 i = i + 1;
37 }
38+ // recalculate temperature excess above 0 deg C
39+ for(int i=0;i<n;i++) exsT[i] = fmax(0.0, T[i] - CtoK);
40 }
41
42 // convert temperature excess to melt [kg]
43@@ -1689,7 +1688,7 @@
44 // printf("Total depth < zMin %f \n", Ztot);
45 // mass and energy to be added
46 mAdd = m[n-1]+W[n-1];
47- addE = T[n-1]*m[n-1]*CI;
48+ addE = T[n-1]*m[n-1]*CI + W[n-1]*(LF+CtoK*CI);
49
50 // add a grid cell of the same size and temperature to the bottom
51 dz_bot=dz[n-1];
52@@ -1723,7 +1722,7 @@
53 // printf("Total depth > zMax %f \n", Ztot);
54 // mass and energy loss
55 mAdd = -(m[n-1]+W[n-1]);
56- addE = -(T[n-1]*m[n-1]*CI);
57+ addE = -(T[n-1]*m[n-1]*CI) - (W[n-1]*(LF+CtoK*CI));
58 dz_add=-(dz[n-1]);
59
60 // remove a grid cell from the bottom
61@@ -1744,7 +1743,6 @@
62 celldelete(&EW,n,D,D_size);
63 n=D_size;
64 xDelete<int>(D);
65-
66 }
67
68 //// CHECK FOR MASS AND ENERGY CONSERVATION
69@@ -1762,7 +1760,7 @@
70
71 /*only in forward mode! avoid round in AD mode as it is not differentiable: */
72 #ifndef _HAVE_ADOLC_
73- dm = round(mSum0 - mSum1 + mAdd);
74+ dm = round((mSum0 - mSum1 + mAdd)*1000);
75 dE = round(sumE0 - sumE1 - sumER + addE);
76 if (dm !=0 || dE !=0) _error_("mass or energy are not conserved in melt equations\n"
77 << "dm: " << dm << " dE: " << dE << "\n");
Note: See TracBrowser for help on using the repository browser.