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
  • TabularUnified ../trunk-jpl/src/c/modules/SurfaceMassBalancex/Gembx.cpp

     
    13321332        for(int i=0;i<n;i++) exsT[i]= fmax(0.0, T[i] - CtoK);        // [K] to [degC]
    13331333
    13341334        // new grid point center temperature, T [K]
    1335         //for(int i=0;i<n;i++) T[i]-=exsT[i];
     1335        // for(int i=0;i<n;i++) T[i]-=exsT[i];
    13361336        for(int i=0;i<n;i++) T[i]=fmin(T[i],CtoK);
    13371337       
    13381338        // specify irreducible water content saturation [fraction]
     
    13811381                        surpE=xNew<IssmDouble>(n); for(int i=0;i<n;i++)surpE[i] = surpT[i] * CI * m[i];
    13821382           
    13831383                        int i = 0;
    1384                         while (cellsum(surpE,n) > 0.0 + Ttol){
     1384                        while (cellsum(surpE,n) > 0.0 + Ttol && i<n-1){
     1385
    13851386                                // use surplus energy to increase the temperature of lower cell
    13861387                                T[i+1] = surpE[i]/m[i+1]/CI + T[i+1];
    1387                
    1388                                 exsT[i+1] = fmax(0.0, T[i+1] - CtoK) + exsT[i+1];
    1389                                 T[i+1] = fmin(CtoK, T[i+1]);
    1390                
    1391                                 surpT[i+1] = fmax(0.0, exsT[i+1] - LF/CI);
     1388                                surpT[i+1] = fmax(0.0, (T[i+1] - CtoK - LF/CI));
    13921389                                surpE[i+1] = surpT[i+1] * CI * m[i+1];
    1393                
     1390
    13941391                                // adjust current cell properties (again 159.1342 is the max T)
    1395                                 exsT[i] = LF/CI;
     1392                                T[i] = T[i]-surpE[i]/m[i+1]/CI;
    13961393                                surpE[i] = 0.0;
    13971394                                i = i + 1;
    13981395                        }
     1396                        // recalculate temperature excess above 0 deg C
     1397                        for(int i=0;i<n;i++) exsT[i] = fmax(0.0, T[i] - CtoK); 
    13991398                }
    14001399
    14011400                // convert temperature excess to melt [kg]
     
    16891688                // printf("Total depth < zMin %f \n", Ztot);
    16901689                // mass and energy to be added
    16911690                mAdd = m[n-1]+W[n-1];
    1692                 addE = T[n-1]*m[n-1]*CI;
     1691                addE = T[n-1]*m[n-1]*CI + W[n-1]*(LF+CtoK*CI);
    16931692       
    16941693                // add a grid cell of the same size and temperature to the bottom
    16951694                dz_bot=dz[n-1];
     
    17231722                // printf("Total depth > zMax %f \n", Ztot);
    17241723                // mass and energy loss
    17251724                mAdd = -(m[n-1]+W[n-1]);
    1726                 addE = -(T[n-1]*m[n-1]*CI);
     1725                addE = -(T[n-1]*m[n-1]*CI) - (W[n-1]*(LF+CtoK*CI));
    17271726                dz_add=-(dz[n-1]);
    17281727       
    17291728                // remove a grid cell from the bottom
     
    17441743                celldelete(&EW,n,D,D_size);
    17451744                n=D_size;
    17461745                xDelete<int>(D);
    1747        
    17481746        }
    17491747
    17501748        //// CHECK FOR MASS AND ENERGY CONSERVATION
     
    17621760
    17631761        /*only in forward mode! avoid round in AD mode as it is not differentiable: */
    17641762        #ifndef _HAVE_ADOLC_
    1765         dm = round(mSum0 - mSum1 + mAdd);
     1763        dm = round((mSum0 - mSum1 + mAdd)*1000);
    17661764        dE = round(sumE0 - sumE1 - sumER +  addE);
    17671765        if (dm !=0  || dE !=0) _error_("mass or energy are not conserved in melt equations\n"
    17681766                        << "dm: " << dm << " dE: " << dE << "\n");
Note: See TracBrowser for help on using the repository browser.