Changeset 22736


Ignore:
Timestamp:
05/02/18 18:25:10 (7 years ago)
Author:
schlegel
Message:

CHG: conserve energy when adding or removing bottom layers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/modules/SurfaceMassBalancex/Gembx.cpp

    r22728 r22736  
    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       
     
    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
     
    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
     
    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       
     
    17451744                n=D_size;
    17461745                xDelete<int>(D);
    1747        
    17481746        }
    17491747
     
    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"
Note: See TracChangeset for help on using the changeset viewer.