Changeset 22614
- Timestamp:
- 03/22/18 19:44:48 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/modules/SurfaceMassBalancex/Gembx.cpp
r22539 r22614 1247 1247 IssmDouble* surpT=NULL; 1248 1248 IssmDouble* surpE=NULL; 1249 IssmDouble* F=NULL;1250 1249 IssmDouble* flxDn=NULL; 1251 1250 IssmDouble ER=0.0; … … 1311 1310 /*Allocations: */ 1312 1311 M=xNewZeroInit<IssmDouble>(n); 1313 maxF=xNew <IssmDouble>(n);1314 dW=xNew <IssmDouble>(n);1312 maxF=xNewZeroInit<IssmDouble>(n); 1313 dW=xNewZeroInit<IssmDouble>(n); 1315 1314 1316 1315 // store initial mass [kg] and energy [J] … … 1355 1354 1356 1355 // if pore water froze in ice then adjust d and dz thickness 1357 for(int i=0;i<n;i++)if(d[i]>dIce )d[i]=dIce;1356 for(int i=0;i<n;i++)if(d[i]>dIce-Dtol)d[i]=dIce; 1358 1357 for(int i=0;i<n;i++) dz[i]= m[i]/d[i]; 1359 1358 } … … 1375 1374 // (maximum T of snow before entire grid cell melts is a constant 1376 1375 // LF/CI = 159.1342) 1377 surpT=xNew<IssmDouble>(n); for(int i=0;i<n;i++)surpT[i] = fmax(0.0, exsT[i]- 159.1342);1376 surpT=xNew<IssmDouble>(n); for(int i=0;i<n;i++)surpT[i] = fmax(0.0, exsT[i]- LF/CI); 1378 1377 1379 if (cellsum(surpT,n) > 0.0 + Ttol 1378 if (cellsum(surpT,n) > 0.0 + Ttol){ 1380 1379 // _printf_("T Surplus"); 1381 1380 // calculate surplus energy … … 1390 1389 T[i+1] = fmin(CtoK, T[i+1]); 1391 1390 1392 surpT[i+1] = fmax(0.0, exsT[i+1] - 159.1342);1391 surpT[i+1] = fmax(0.0, exsT[i+1] - LF/CI); 1393 1392 surpE[i+1] = surpT[i+1] * CI * m[i+1]; 1394 1393 1395 1394 // adjust current cell properties (again 159.1342 is the max T) 1396 exsT[i] = 159.1342;1395 exsT[i] = LF/CI; 1397 1396 surpE[i] = 0.0; 1398 1397 i = i + 1; … … 1401 1400 1402 1401 // convert temperature excess to melt [kg] 1403 for(int i=0;i<n;i++) M[i] = exsT[i] * d[i] * dz[i] * CI / LF;// melt1404 sumM = cellsum(M,n); // total melt [kg]1402 for(int i=0;i<n;i++) M[i] = fmin(exsT[i] * d[i] * dz[i] * CI / LF, m[i]); // melt 1403 sumM = cellsum(M,n); // total melt [kg] 1405 1404 1406 1405 // calculate maximum refreeze amount, maxF [kg] … … 1409 1408 // initialize refreeze, runoff, flxDn and dW vectors [kg] 1410 1409 IssmDouble* F = xNewZeroInit<IssmDouble>(n); 1411 IssmDouble* R =xNewZeroInit<IssmDouble>(n);1410 IssmDouble* R = xNewZeroInit<IssmDouble>(n); 1412 1411 1413 1412 for(int i=0;i<n;i++)dW[i] = 0.0; 1414 flxDn=xNewZeroInit<IssmDouble>(n+1); for(int i=0;i<n;i++)flxDn[i+1]=F[i];1413 flxDn=xNewZeroInit<IssmDouble>(n+1); 1415 1414 1416 1415 // determine the deepest grid cell where melt/pore water is generated … … 1442 1441 m[i] = m[i] - M[i]; // mass after melt 1443 1442 Wi = (dIce-d[i]) * Swi * (m[i]/d[i]); // irreducible water 1444 dW[i] = fm in(inM, Wi -W[i]); // change in pore water1443 dW[i] = fmax(fmin(inM, Wi - W[i]),-1*W[i]); // change in pore water 1445 1444 R[i] = fmax(0.0, inM - dW[i]); // runoff 1445 F[i] = 0.0; 1446 1446 } 1447 1447 // check if no energy to refreeze meltwater … … 1453 1453 m[i] = m[i] - M[i]; // mass after melt 1454 1454 Wi = (dIce-d[i]) * Swi * (m[i]/d[i]); // irreducible water 1455 dW[i] = fmin(inM, Wi-W[i]); // change in pore water 1456 flxDn[i+1] = fmax(0.0, inM-dW[i]); // meltwater out 1455 dW[i] = fmax(fmin(inM, Wi - W[i]),-1*W[i]); // change in pore water 1456 flxDn[i+1] = fmax(0.0, inM - dW[i]); // meltwater out 1457 R[i] = 0.0; 1457 1458 F[i] = 0.0; // no freeze 1458 1459 } … … 1462 1463 // _printf_("MELT REFREEZE"); 1463 1464 //-----------------------melt water----------------------------- 1465 m[i] = m[i] - M[i]; 1464 1466 IssmDouble dz_0 = m[i]/d[i]; 1465 1467 IssmDouble dMax = (dIce - d[i])*dz_0; // d max = dIce … … 1471 1473 Wi = (dIce-d[i])* Swi * dz_0; // irreducible water 1472 1474 dW[i] = fmin(inM - F1, Wi-W[i]); // change in pore water 1473 if ( -1*dW[i]>W[i]-Wtol ){1475 if (dW[i] < 0.0-Wtol && -1*dW[i]>W[i]-Wtol ){ 1474 1476 dW[i]= -1*W[i]; 1475 1477 } … … 1482 1484 m[i] = m[i] + F2; // mass after refreeze 1483 1485 d[i] = m[i]/dz_0; 1486 dW[i] = dW[i] - F2; 1484 1487 } 1485 1488 1486 flxDn[i+1] = inM - F1 - dW[i] - F2; // meltwater out 1489 F[i] = F1 + F2; 1490 1491 flxDn[i+1] = inM - F1 - dW[i]; // meltwater out 1487 1492 T[i] = T[i] + ((F1+F2)*(LF+(CtoK - T[i])*CI)/(m[i]*CI));// change in temperature 1488 1493 … … 1507 1512 for(int i=0;i<n;i++)W[i] += dW[i]; 1508 1513 1514 //calculate Rsum: 1515 Rsum=cellsum(R,n); 1516 1509 1517 // delete all cells with zero mass 1510 D_size=0; for(int i=0;i<n;i++)if(m[i] !=0)D_size++;1518 D_size=0; for(int i=0;i<n;i++)if(m[i]>0.0)D_size++; 1511 1519 D=xNew<int>(D_size); 1512 D_size=0; for(int i=0;i<n;i++)if(m[i] !=0){ D[D_size] = i; D_size++;}1513 1520 D_size=0; for(int i=0;i<n;i++)if(m[i]>0.0){ D[D_size] = i; D_size++;} 1521 1514 1522 celldelete(&m,n,D,D_size); 1515 1523 celldelete(&W,n,D,D_size); … … 1522 1530 celldelete(&EI,n,D,D_size); 1523 1531 celldelete(&EW,n,D,D_size); 1524 celldelete(&R,n,D,D_size);1525 1532 n=D_size; 1526 1533 xDelete<int>(D); … … 1528 1535 // calculate new grid lengths 1529 1536 for(int i=0;i<n;i++)dz[i] = m[i] / d[i]; 1530 1531 //calculate Rsum:1532 Rsum=cellsum(R,n);1533 1537 1534 1538 /*Free ressources:*/ … … 1592 1596 1593 1597 // set cell to 99999 for deletion 1594 m[i] = 99999;1598 m[i] = -99999; 1595 1599 } 1596 1600 } … … 1600 1604 //find closest cell to merge with 1601 1605 for(int i=n-2;i>=0;i--){ 1602 if(m[i]!= 99999){1606 if(m[i]!=-99999){ 1603 1607 X2=i; 1604 1608 X1=n-1; … … 1622 1626 1623 1627 // set cell to 99999 for deletion 1624 m[X2] = 99999;1628 m[X2] = -99999; 1625 1629 } 1626 1630 1627 1631 // delete combined cells 1628 D_size=0; for(int i=0;i<n;i++)if(m[i]!= 99999)D_size++;1632 D_size=0; for(int i=0;i<n;i++)if(m[i]!=-99999)D_size++; 1629 1633 D=xNew<int>(D_size); 1630 D_size=0; for(int i=0;i<n;i++)if(m[i]!= 99999){ D[D_size] = i; D_size++;}1634 D_size=0; for(int i=0;i<n;i++)if(m[i]!=-99999){ D[D_size] = i; D_size++;} 1631 1635 1632 1636 celldelete(&m,n,D,D_size); … … 1723 1727 dz_add=-(dz[n-1]); 1724 1728 1725 // add a grid cell of the same size and temperature tothe bottom1729 // remove a grid cell from the bottom 1726 1730 D_size=n-1; 1727 1731 D=xNew<int>(D_size); … … 1756 1760 /*checks: */ 1757 1761 for(int i=0;i<n;i++) if (W[i]<0.0-Wtol) _error_("negative pore water generated in melt equations\n"); 1758 1762 1759 1763 /*only in forward mode! avoid round in AD mode as it is not differentiable: */ 1760 1764 #ifndef _HAVE_ADOLC_
Note:
See TracChangeset
for help on using the changeset viewer.