Changeset 19567


Ignore:
Timestamp:
09/19/15 14:55:36 (10 years ago)
Author:
Eric.Larour
Message:

CHG: adding verbosity + fixing some serious bugs

File:
1 edited

Legend:

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

    r19554 r19567  
    21372137        int        swIdx=0;
    21382138        IssmDouble cldFrac,t0wet, t0dry, K;
    2139         IssmDouble comp1,comp2;
    21402139        IssmDouble ulw;
    21412140        IssmDouble netSW;
     
    21462145    IssmDouble sumMass,dMass;
    21472146        bool isgraingrowth,isalbedo,isshortwave,isthermal,isaccumulation,ismelt,isdensification,isturbulentflux;
     2147        IssmDouble init_scaling=1.0;
    21482148        /*}}}*/
    21492149        /*Output variables:{{{ */
     
    21632163        IssmDouble  mAdd;
    21642164        int         m;
     2165        IssmDouble  SmbMassBalance=0;
    21652166        /*}}}*/
    21662167
    21672168        /*only compute SMB at the surface: */
    21682169        if (!IsOnSurface()) return;
     2170
    21692171
    21702172        /*Retrieve material properties and parameters:{{{ */
     
    21902192        parameters->FindParam(&isdensification,SmbIsdensificationEnum);
    21912193        parameters->FindParam(&isturbulentflux,SmbIsturbulentfluxEnum);
     2194        parameters->FindParam(&init_scaling,SmbInitDensityScalingEnum);
    21922195        /*}}}*/
    21932196        /*Retrieve inputs: {{{*/
     
    22252228        Vz_input->GetInputValue(&Vz,gauss);
    22262229        /*}}}*/
     2230
    22272231        /*First, check that the initial structures have been setup in GEMB. If not, initialize profile variables: layer thickness dz, * density d, temperature T, etc. {{{*/
    2228         if(!isinitialized_input){ 
    2229 
    2230                 /*Initialize grid:*/
     2232        if(!isinitialized_input){
     2233
     2234                if(VerboseSmb() && this->Sid()==0)_printf0_("smb core: Initializing grid\n");
    22312235                GembgridInitialize(&dz, &m, zTop, dzTop, zMax, zY);
    22322236                //if(this->Sid()==1) for(int i=0;i<m;i++)_printf_("z[" << i << "]=" <<
     
    22342238
    22352239                /*initialize profile variables:*/
    2236                 d = xNewZeroInit<IssmDouble>(m); for(int i=0;i<m;i++)d[i]=rho_ice; //ice density
     2240                d = xNewZeroInit<IssmDouble>(m); for(int i=0;i<m;i++)d[i]=rho_ice*init_scaling; //ice density scaled by a factor
    22372241                re = xNewZeroInit<IssmDouble>(m); for(int i=0;i<m;i++)re[i]=2.5;         //set grain size to old snow [mm]
    22382242                gdn = xNewZeroInit<IssmDouble>(m); for(int i=0;i<m;i++)gdn[i]=0;         //set grain dentricity to old snow
     
    22422246                a = xNewZeroInit<IssmDouble>(m); for(int i=0;i<m;i++)a[i]=aSnow;         //set albedo equal to fresh snow [fraction]
    22432247                T = xNewZeroInit<IssmDouble>(m); for(int i=0;i<m;i++)T[i]=Tmean;         //set initial grid cell temperature to the annual mean temperature [K]
     2248                swf = xNewZeroInit<IssmDouble>(m);
    22442249
    22452250                //fixed lower temperatuer bounday condition - T is fixed
     
    22512256        else{
    22522257                /*Recover inputs: */
    2253                 DoubleArrayInput* dz_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbDzEnum));
    2254                 DoubleArrayInput* d_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbDEnum));
    2255                 DoubleArrayInput* re_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbReEnum));
    2256                 DoubleArrayInput* gdn_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbGdnEnum));
    2257                 DoubleArrayInput* gsp_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbGspEnum));
    2258                 DoubleInput* EC_input= dynamic_cast<DoubleInput*>(this->GetInput(SmbECEnum));
    2259                 DoubleArrayInput* W_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbWEnum));
    2260                 DoubleArrayInput* a_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbAEnum));
    2261                 DoubleArrayInput* T_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbTEnum));
     2258                DoubleArrayInput* dz_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbDzEnum)); _assert_(dz_input);
     2259                DoubleArrayInput* d_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbDEnum));_assert_(d_input);
     2260                DoubleArrayInput* re_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbReEnum));_assert_(re_input);
     2261                DoubleArrayInput* gdn_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbGdnEnum));_assert_(gdn_input);
     2262                DoubleArrayInput* gsp_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbGspEnum));_assert_(gsp_input);
     2263                DoubleInput* EC_input= dynamic_cast<DoubleInput*>(this->GetInput(SmbECEnum));_assert_(EC_input);
     2264                DoubleArrayInput* W_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbWEnum));_assert_(W_input);
     2265                DoubleArrayInput* a_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbAEnum));_assert_(a_input);
     2266                DoubleArrayInput* T_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbTEnum));_assert_(T_input);
     2267                DoubleArrayInput* swf_input= dynamic_cast<DoubleArrayInput*>(this->GetInput(SmbSwfEnum));_assert_(swf_input);
    22622268               
    22632269                /*Recover arrays: */
     
    22712277                a_input->GetValues(&a,&m);
    22722278                T_input->GetValues(&T,&m);
     2279                swf_input->GetValues(&swf,&m);
    22732280
    22742281        } /*}}}*/
     
    22802287    sumR = 0; sumM = 0; sumEC = 0; sumP = 0; sumMassAdd = 0;
    22812288
     2289        //before starting loop, realize that the transient core runs this smb_core at time = time +deltaT.
     2290        //go back to time - deltaT:
     2291        time-=dt;
     2292
    22822293        /*Start loop: */
    22832294        for (t=time;t<=time+dt;t=t+smb_dt){
     2295
     2296                if(VerboseSmb() && this->Sid()==0 && IssmComm::GetRank()==0)_printf0_("Time: t=" << setprecision(8) << t/365.0/24.0/3600.0 << " yr/" << (time+dt)/365.0/24.0/3600.0 << " yr" << "\n");
    22842297
    22852298                /*extract daily data:{{{*/
     
    22952308
    22962309                /*Snow grain metamorphism:*/
    2297                 if(isgraingrowth)grainGrowth(re, gdn, gsp, T, dz, d, W, smb_dt, m, aIdx);
     2310                if(isgraingrowth)grainGrowth(re, gdn, gsp, T, dz, d, W, smb_dt, m, aIdx,this->Sid());
    22982311
    22992312                /*Snow, firn and ice albedo:*/
    2300                 if(isalbedo)albedo(a,aIdx,re,d,cldFrac,aIce, aSnow,T,W,P,EC,t0wet,t0dry,K,smb_dt,m);
     2313                if(isalbedo)albedo(a,aIdx,re,d,cldFrac,aIce, aSnow,T,W,P,EC,t0wet,t0dry,K,smb_dt,m,this->Sid());
    23012314               
     2315                                       
    23022316                /*Distribution of absorbed short wave radation with depth:*/
    2303         if(isshortwave)shortwave(&swf, swIdx, aIdx, dsw, a[0], d, dz, re,m);
     2317        if(isshortwave)shortwave(swf, swIdx, aIdx, dsw, a[0], d, dz, re,m,this->Sid());
    23042318               
    23052319                /*Thermal profile computation:*/
    2306         if(isthermal)thermo(&EC, T, dz, d, swf, dlw, Ta, V, eAir, pAir, W[0], smb_dt, Vz, Tz,m);     
     2320        if(isthermal)thermo(&EC, T, dz, d, swf, dlw, Ta, V, eAir, pAir, W[0], smb_dt, m, Vz, Tz,this->Sid());     
    23072321
    23082322                /*Change in thickness of top cell due to evaporation/condensation  assuming same density as top cell.
     
    23112325               
    23122326                /*Add snow/rain to top grid cell adjusting cell depth, temperature and density*/
    2313         if(isaccumulation)accumulation(&T, &dz, &d, &W, &a, &re, &gdn, &gsp, &m, Ta, P, dzMin, aSnow);
     2327        if(isaccumulation)accumulation(&T, &dz, &d, &W, &a, &re, &gdn, &gsp, &m, Ta, P, dzMin, aSnow,this->Sid());
    23142328
    23152329                /*Calculate water production, M [kg m-2] resulting from snow/ice temperature exceeding 273.15 deg K
    23162330                 * (> 0 deg C), runoff R [kg m-2] and resulting changes in density and determine wet compaction [m]*/
    2317                 comp2 = cellsum(dz,m);
    2318                 if(ismelt)melt(&M, &R, &mAdd, &T, &d, &dz, &W, &a, &re, &gdn, &gsp, &m, dzMin, zMax, zMin);
    2319         comp2 = (comp2 - cellsum(dz,m));
     2331                if(ismelt)melt(&M, &R, &mAdd, &T, &d, &dz, &W, &a, &re, &gdn, &gsp, &m, dzMin, zMax, zMin,this->Sid());
    23202332
    23212333                /*Allow non-melt densification and determine compaction [m]*/
    2322         comp1 = cellsum(dz,m);
    2323         if(isdensification)densification(d,dz, T, re, denIdx, C, smb_dt, Tmean,m);
    2324         comp1 = (comp1 - cellsum(dz,m));
     2334        if(isdensification)densification(d,dz, T, re, denIdx, C, smb_dt, Tmean,rho_ice,m,this->Sid());
    23252335               
    23262336                /*Calculate upward longwave radiation flux [W m-2] not used in energy balance. Calculated for every
     
    23332343               
    23342344                /*Calculate turbulent heat fluxes [W m-2]*/
    2335         if(isturbulentflux)turbulentFlux(&shf, &lhf, &dayEC, Ta, T[0], V, eAir, pAir, d[0], W[0], Vz, Tz);
     2345        if(isturbulentflux)turbulentFlux(&shf, &lhf, &dayEC, Ta, T[0], V, eAir, pAir, d[0], W[0], Vz, Tz,this->Sid());
    23362346               
    23372347                /*Sum component mass changes [kg m-2]*/
     
    23472357        dMass = sumMass + sumR + sumW - sumP - sumEC - initMass - sumMassAdd;
    23482358        dMass = round(dMass * 100.0)/100.0;
    2349                
     2359
    23502360                /*Check mass conservation:*/
    2351         if (dMass != 0.0) _error_("total system mass not conserved in MB function");
     2361        if(!VerboseSmb())if (dMass != 0.0) _printf_("total system mass not conserved in MB function");
    23522362               
    23532363                /*Check bottom grid cell T is unchanged:*/
    2354         if (T[m-1]!=T_bottom) _printf_("T(end)~=T_bottom");
    2355         }
     2364        if(!VerboseSmb())if (T[m-1]!=T_bottom) _printf_("T(end)~=T_bottom" << "\n");
     2365               
     2366                SmbMassBalance += sumP + sumEC - sumR; //increment SMB for the entire time span of ice-flow dynamics.
     2367
     2368
     2369        } //for (t=time;t<=time+dt;t=t+smb_dt)
    23562370
    23572371        /*Save generated inputs: */
     
    23612375        this->AddInput(new DoubleArrayInput(SmbGdnEnum,gdn,m));
    23622376        this->AddInput(new DoubleArrayInput(SmbGspEnum,gsp,m));
     2377        this->AddInput(new DoubleArrayInput(SmbTEnum,T,m));
    23632378        this->AddInput(new DoubleInput(SmbECEnum,EC));
    23642379        this->AddInput(new DoubleArrayInput(SmbWEnum,W,m));
    23652380        this->AddInput(new DoubleArrayInput(SmbAEnum,a,m));
    2366         this->AddInput(new DoubleArrayInput(SmbTEnum,T,m));
     2381        this->AddInput(new DoubleArrayInput(SmbSwfEnum,swf,m));
     2382        this->AddInput(new DoubleInput(SmbMassBalanceEnum,time));
     2383
    23672384
    23682385        /*Free allocations:{{{*/
Note: See TracChangeset for help on using the changeset viewer.