Changeset 19613


Ignore:
Timestamp:
10/01/15 10:45:44 (10 years ago)
Author:
Eric.Larour
Message:

CHG: applying patches for the AD mode to compile.

Location:
issm/trunk-jpl/src/c
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/Elements/Element.cpp

    r19594 r19613  
    23752375                /*Calculate total system mass:*/
    23762376        sumMass=0; for(int i=0;i<m;i++) sumMass += dz[i]*d[i];
     2377
     2378        #ifndef _HAVE_ADOLC_ //we want to avoid the round operation at all cost. Not differentiable.
    23772379        dMass = sumMass + sumR + sumW - sumP - sumEC - initMass - sumMassAdd;
    2378         dMass = round(dMass * 100.0)/100.0;
     2380                dMass = round(dMass * 100.0)/100.0;
    23792381
    23802382                /*Check mass conservation:*/
    23812383        if (dMass != 0.0) _printf_("total system mass not conserved in MB function");
     2384                #endif
    23822385               
    23832386                /*Check bottom grid cell T is unchanged:*/
    23842387        if (T[m-1]!=T_bottom) _printf_("T(end)~=T_bottom" << "\n");
    23852388               
     2389                /*Free ressources: */
     2390                xDelete<IssmDouble>(swf);
     2391
     2392                /*increase counter:*/
    23862393                count++;
    23872394
     
    23992406        this->AddInput(new DoubleArrayInput(SmbWEnum,W,m));
    24002407        this->AddInput(new DoubleArrayInput(SmbAEnum,a,m));
    2401         this->AddInput(new DoubleArrayInput(SmbSwfEnum,swf,m));
    24022408        this->AddInput(new DoubleInput(SmbMassBalanceEnum,(sumP + sumEC -sumR)/rho_water/dt));
    24032409        this->AddInput(new DoubleInput(SmbRunoffEnum,sumR/rho_water/dt));
     
    24162422        xDelete<IssmDouble>(a);
    24172423        xDelete<IssmDouble>(T);
    2418         xDelete<IssmDouble>(swf);
    24192424        delete gauss;
    24202425        /*}}}*/
  • issm/trunk-jpl/src/c/modules/SurfaceMassBalancex/Gembx.cpp

    r19582 r19613  
    4343        //into specified top structure depth (zTop). Also make sure top grid cell
    4444        //structure length (dzTop) is greater than 5 cm
    45         if (dgpTop != round(dgpTop)){
     45        #ifndef _HAVE_ADOLC_  //avoid the round operation check!
     46        if (dgpTop != round(dgpTop)){
    4647                _error_("top grid cell structure length does not go evenly into specified top structure depth, adjust dzTop or zTop");
    4748        }
    48         else if(dzTop < 0.05){
     49        #endif
     50        if(dzTop < 0.05){
    4951                _printf_("initial top grid cell length (dzTop) is < 0.05 m");
    5052        }
    51         gpTop=round(dgpTop);
     53        gpTop=reCast<int,IssmDouble>(dgpTop);
    5254
    5355        //initialize top grid depth vector
     
    212214
    213215        // take absolute value of temperature gradient
    214         for(int i=0;i<m;i++)dT[i]=abs(dT[i]);
     216        for(int i=0;i<m;i++)dT[i]=fabs(dT[i]);
    215217       
    216218        /*Snow metamorphism. Depends on value of snow dendricity and wetness of the snowpack: */
     
    418420                for(int i=0;i<m;i++)if(W[i]>0)t0[i]=t0wet; // wet snow timescale
    419421                for(int i=0;i<m;i++)T[i]=TK[i] - 273.15; // change T from K to degC
    420                 for(int i=0;i<m;i++) t0warm[i]= abs(T[i]) * K + t0dry; //// 'warm' snow timescale
     422                for(int i=0;i<m;i++) t0warm[i]= fabs(T[i]) * K + t0dry; //// 'warm' snow timescale
    421423        for(int i=0;i<m;i++)if(W[i]==0.0 && T[i]>=-10)t0[i]= t0warm[i];
    422424        for(int i=0;i<m;i++)if(T[i]<-10) t0[i] =  10 * K + t0dry; // 'cold' snow timescale
     
    450452        if (a[0] > 1) _printf_("albedo > 1.0\n");
    451453        else if (a[0] < 0) _printf_("albedo is negative\n");
    452         else if (isnan(a[0])) _error_("albedo == NAN\n");
     454        else if (xIsNan(a[0])) _error_("albedo == NAN\n");
    453455}  /*}}}*/
    454456void thermo(IssmDouble* pEC, IssmDouble* T, IssmDouble* dz, IssmDouble* d, IssmDouble* swf, IssmDouble dlwrf, IssmDouble Ta, IssmDouble V, IssmDouble eAir, IssmDouble pAir, IssmDouble Ws, IssmDouble dt0, int m, IssmDouble Vz, IssmDouble Tz,int sid) { /*{{{*/
     
    692694
    693695        /* CALCULATE ENERGY SOURCES AND DIFFUSION FOR EVERY TIME STEP [dt]*/
    694         for (int i=1;i<=dt0;i+=dt){
     696        for (IssmDouble i=1;i<=dt0;i+=dt){
    695697
    696698                // PART OF ENERGY CONSERVATION CHECK
     
    964966                        xDelete<IssmDouble>(Qs1);
    965967                        xDelete<IssmDouble>(Qs2);
     968                       
     969                       
    966970                }
    967971                else{  //function of grid cell density
     
    11581162
    11591163                mass_diff = mass - massinit - P;
     1164               
     1165                #ifndef _HAVE_ADOLC_  //avoid round operation. only check in forward mode.
    11601166                mass_diff = round(mass_diff * 100)/100;
    1161 
    11621167                if (mass_diff > 0) _error_("mass not conserved in accumulation function");
     1168                #endif
    11631169
    11641170        }
     
    13451351                X = 0;
    13461352                for(int i=n-1;i>=0;i--){
    1347                         if(M[i]>0 || exsW[i]){
     1353                        if(M[i]>0 || reCast<int,IssmDouble>(exsW[i])){
    13481354                                X=i;
    13491355                                break;
     
    14511457                celldelete(&R,n,D,D_size);
    14521458                n=D_size;
     1459                xDelete<int>(D);
    14531460       
    14541461                // calculate new grid lengths
     
    14571464                //calculate Rsum:
    14581465                Rsum=cellsum(R,n);
    1459        
     1466
     1467                /*Free ressources:*/
     1468                xDelete<IssmDouble>(F);
     1469                xDelete<IssmDouble>(R);
    14601470        }
    14611471
     
    14921502
    14931503        // delete combined cells
    1494         xDelete<int>(D); D_size=0; for(int i=0;i<n;i++)if(m[i]!=99999)D_size++; D=xNew<int>(D_size);
     1504        D_size=0; for(int i=0;i<n;i++)if(m[i]!=99999)D_size++; D=xNew<int>(D_size);
    14951505        D_size=0; for(int i=0;i<n;i++)if(m[i]!=99999){ D[D_size] = i; D_size++;}
    14961506
     
    15071517        celldelete(&EW,n,D,D_size);
    15081518        n=D_size;
     1519        xDelete<int>(D);
    15091520
    15101521        // check if any of the top 10 cell depths are too large
     
    15861597        sumE1 = cellsum(EI,n) + cellsum(EW,n);
    15871598
     1599        /*checks: */
     1600        for(int i=0;i<n;i++) if (W[i]<0) _error_("negative pore water generated in melt equations\n");
     1601       
     1602        /*only in forward mode! avoid round in AD mode as it is not differentiable: */
     1603        #ifndef _HAVE_ADOLC_
    15881604        dm = round(mSum0 - mSum1 + mAdd);
    15891605        dE = round(sumE0 - sumE1 - sumER +  addE);
    1590        
    1591         for(int i=0;i<n;i++) if (W[i]<0) _error_("negative pore water generated in melt equations\n");
    1592 
    15931606        if (dm !=0  || dE !=0) _error_("mass or energy are not conserved in melt equations\n"
    15941607                        << "dm: " << dm << " dE: " << dE << "\n");
    1595 
     1608        #endif
    15961609       
    15971610        /*Free ressources:*/
Note: See TracChangeset for help on using the changeset viewer.