Changeset 27053


Ignore:
Timestamp:
06/10/22 14:27:30 (3 years ago)
Author:
caronlam
Message:

BUG: memory leaks in sealevelchange core

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

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/analyses/SealevelchangeAnalysis.cpp

    r26800 r27053  
    264264
    265265                        parameters->AddObject(new DoubleParam(SolidearthSettingsTimeAccEnum,timeacc));
    266                         parameters->AddObject(new DoubleMatParam(LoadLoveHEnum,love_h,ndeg,precomputednt));
    267                         parameters->AddObject(new DoubleMatParam(LoadLoveKEnum,love_k,ndeg,precomputednt));
    268                         parameters->AddObject(new DoubleMatParam(LoadLoveLEnum,love_l,ndeg,precomputednt));
    269266
    270267                        if (rotation){
     
    274271                                iomodel->FetchData(&love_pmtf_colinear,&dummy,&precomputednt,"md.solidearth.lovenumbers.pmtf_colinear");
    275272                                iomodel->FetchData(&love_pmtf_ortho,&dummy,&precomputednt,"md.solidearth.lovenumbers.pmtf_ortho");
    276 
    277                                 parameters->AddObject(new DoubleMatParam(LovePolarMotionTransferFunctionColinearEnum,love_pmtf_colinear,1,precomputednt));
    278                                 parameters->AddObject(new DoubleMatParam(LovePolarMotionTransferFunctionOrthogonalEnum,love_pmtf_ortho,1,precomputednt));
    279                                 parameters->AddObject(new DoubleMatParam(TidalLoveHEnum,love_th,ndeg,precomputednt));
    280                                 parameters->AddObject(new DoubleMatParam(TidalLoveKEnum,love_tk,ndeg,precomputednt));
    281                                 parameters->AddObject(new DoubleMatParam(TidalLoveLEnum,love_tl,ndeg,precomputednt));
    282273                        }
    283274
     
    595586                                xDelete<IssmDouble>(G_viscoelastic);
    596587                                xDelete<IssmDouble>(G_viscoelastic_local);
     588                                xDelete<IssmDouble>(G_viscoelastic_interpolated);
    597589                                xDelete<IssmDouble>(U_viscoelastic);
    598590                                xDelete<IssmDouble>(U_viscoelastic_local);
     591                                xDelete<IssmDouble>(U_viscoelastic_interpolated);
    599592                                if(horiz){
    600593                                        xDelete<IssmDouble>(H_viscoelastic);
    601594                                        xDelete<IssmDouble>(H_viscoelastic_local);
     595                                        xDelete<IssmDouble>(H_viscoelastic_interpolated);
    602596                                }
    603597                                if(rotation){
     598                                        xDelete<IssmDouble>(Love_th2_interpolated);
     599                                        xDelete<IssmDouble>(Love_tk2_interpolated);
     600                                        if (horiz) xDelete<IssmDouble>(Love_tl2_interpolated);
    604601                                        xDelete<IssmDouble>(love_pmtf_colinear);
    605602                                        xDelete<IssmDouble>(love_pmtf_ortho);
     603                                        xDelete<IssmDouble>(Pmtf_col_interpolated);
     604                                        xDelete<IssmDouble>(Pmtf_ortho_interpolated);
     605                                        xDelete<IssmDouble>(Pmtf_z_interpolated);
    606606
    607607                                }
  • issm/trunk-jpl/src/c/classes/Elements/Tria.cpp

    r27026 r27053  
    63716371        bool computerotation = false;
    63726372        bool computeviscous = false;
     6373        bool computesatgravi = false;
    63736374        int  horiz;
    63746375        bool istime=true;
     
    63846385        IssmDouble* __restrict__ tide_love_l  = NULL;
    63856386        IssmDouble* __restrict__ LoveRotRSL   = NULL;
     6387        IssmDouble* __restrict__ LoveRotSatG  = NULL;
    63866388        IssmDouble* __restrict__ LoveRotU     = NULL;
    63876389        IssmDouble* __restrict__ LoveRothoriz = NULL;
     
    63956397        IssmDouble* tide_love_l  = NULL;
    63966398        IssmDouble* LoveRotRSL   = NULL;
     6399        IssmDouble* LoveRotSatG  = NULL;
    63976400        IssmDouble* LoveRotU     = NULL;
    63986401        IssmDouble* LoveRothoriz = NULL;
    63996402        IssmDouble*  Grot        = NULL;
     6403
    64006404        IssmDouble* GUrot        = NULL;
    64016405        IssmDouble* GNrot        = NULL;
     
    65876591                GUrot       = xNewZeroInit<IssmDouble>(3*3*nt);
    65886592
     6593
    65896594                if (horiz){
    65906595                        GErot=xNewZeroInit<IssmDouble>(3*3*nt);
     
    66796684                this->inputs->SetArrayInput(SealevelchangeViscousUEnum,this->lid,viscousU,3*nt);
    66806685                this->parameters->SetParam(0,SealevelchangeViscousIndexEnum);
     6686
    66816687                if(horiz){
    66826688                        viscousN=xNewZeroInit<IssmDouble>(3*nt);
     
    66916697        #ifdef _HAVE_RESTRICT_
    66926698        delete G;
     6699        delete G_gravi_precomputed;
    66936700        if(computeelastic){
    66946701                delete GU;
     6702                delete G_viscoelastic_precomputed;
     6703                delete U_viscoelastic_precomputed;
    66956704                if(horiz){
    66966705                        delete GN;
    66976706                        delete GE;
     6707                        delete H_viscoelastic_precomputed;
    66986708                }
    66996709                if(computerotation){
    67006710                        delete Grot;
    67016711                        delete GUrot;
     6712                        delete tide_love_h;
     6713                        delete tide_love_k;
     6714                        delete tide_love_l;
     6715                        delete LoveRotRSL;
     6716                        delete LoveRotU;
    67026717                        if (horiz){
    67036718                                delete GNrot;
    67046719                                delete GErot;
    6705                         }
     6720                                delete LoveRothoriz;
     6721                        }
     6722                }
     6723        }
     6724        if(computeviscous){
     6725                delete viscousRSL;
     6726                delete viscousU;
     6727
     6728                if(horiz){
     6729                        delete viscousN;
     6730                        delete viscousE;
    67066731                }
    67076732        }
    67086733        #else
    67096734        xDelete(G);
     6735        xDelete(G_gravi_precomputed);
    67106736        if(computeelastic){
    67116737                xDelete(GU);
     6738                xDelete(G_viscoelastic_precomputed);
     6739                xDelete(U_viscoelastic_precomputed);
    67126740                if(horiz){
    67136741                        xDelete(GN);
    67146742                        xDelete(GE);
     6743                        xDelete(H_viscoelastic_precomputed);
    67156744                }
    67166745                if(computerotation){
    67176746                        xDelete(Grot);
    67186747                        xDelete(GUrot);
     6748                        xDelete(tide_love_h);
     6749                        xDelete(tide_love_k);
     6750                        xDelete(tide_love_l);
     6751                        xDelete(LoveRotRSL);
     6752                        xDelete(LoveRotU);
    67196753                        if (horiz){
    67206754                                xDelete(GNrot);
    67216755                                xDelete(GErot);
    6722                         }
     6756                                xDelete(LoveRothoriz);
     6757                        }
     6758                }
     6759               
     6760        }
     6761        if(computeviscous){
     6762                xDelete(viscousRSL);
     6763                xDelete(viscousU);
     6764
     6765                if(horiz){
     6766                        xDelete(viscousN);
     6767                        xDelete(viscousE);
    67236768                }
    67246769        }
     
    72627307        }
    72637308        xDelete<IssmDouble*>(Gsubel);
     7309        xDelete<IssmDouble>(G_gravi_precomputed);
    72647310        if(computeelastic){
    72657311                xDelete<IssmDouble*>(GUsubel);
     7312                xDelete<IssmDouble>(G_viscoelastic_precomputed);
     7313                xDelete<IssmDouble>(U_viscoelastic_precomputed);
    72667314                if(horiz){
     7315                        xDelete<IssmDouble>(H_viscoelastic_precomputed);
    72677316                        xDelete<IssmDouble*>(GNsubel);
    72687317                        xDelete<IssmDouble*>(GEsubel);
     
    72787327        /*Inputs:*/
    72797328        IssmDouble* viscousRSL=NULL;
     7329        IssmDouble* viscousSG=NULL;
    72807330        IssmDouble* viscousU=NULL;
    72817331        IssmDouble* viscousN=NULL;
     
    72937343
    72947344                this->inputs->GetArrayPtr(SealevelchangeViscousRSLEnum,this->lid,&viscousRSL,&dummy);
     7345                this->inputs->GetArrayPtr(SealevelchangeViscousSGEnum,this->lid,&viscousSG,&dummy);
    72957346                this->inputs->GetArrayPtr(SealevelchangeViscousUEnum,this->lid,&viscousU,&dummy);
    72967347                if(horiz){
     
    73017352                for(int i=0;i<NUMVERTICES;i++){
    73027353                        viscousRSL[i*viscousnumsteps+newindex+offset]=(1-lincoeff)*viscousRSL[i*viscousnumsteps+newindex]+lincoeff*viscousRSL[i*viscousnumsteps+newindex+1];
     7354                        viscousSG[i*viscousnumsteps+newindex+offset]=(1-lincoeff)*viscousSG[i*viscousnumsteps+newindex]+lincoeff*viscousSG[i*viscousnumsteps+newindex+1];
    73037355                        viscousU[i*viscousnumsteps+newindex+offset]=(1-lincoeff)*viscousU[i*viscousnumsteps+newindex]+lincoeff*viscousU[i*viscousnumsteps+newindex+1];
    73047356                        if(horiz){
     
    73097361
    73107362        }
     7363
     7364        /*Free ressources*/
     7365        xDelete<IssmDouble>(viscousRSL);
     7366        xDelete<IssmDouble>(viscousSG);
     7367        xDelete<IssmDouble>(viscousU);
     7368        xDelete<IssmDouble>(viscousN);
     7369        xDelete<IssmDouble>(viscousE);
    73117370
    73127371}
     
    73937452        barycontrib->Set(this->Sid(),bslcice,bslchydro,bslcbp);
    73947453
     7454        xDelete<IssmDouble>(areae);
     7455
    73957456}
    73967457/*}}}*/
     
    74267487        }
    74277488
     7489        xDelete<IssmDouble>(G);
     7490        xDelete<IssmDouble>(Grot);
     7491        for (int l=0;l<SLGEOM_NUMLOADS;l++) xDelete<IssmDouble>(Gsub[l]);
     7492        xDelete<IssmDouble>(Gsub[SLGEOM_NUMLOADS]);
     7493
    74287494        return;
    74297495} /*}}}*/
     
    74687534        IssmDouble SealevelGrd[3]={0,0,0};
    74697535        IssmDouble RSLGrd[3]={0,0,0};
     7536        IssmDouble SGGrd[3]={0,0,0}; //Satellite Gravimetry
    74707537        IssmDouble UGrd[3]={0,0,0};
    74717538        IssmDouble NGrd[3]={0,0,0};
     
    74787545        IssmDouble* GN=NULL;
    74797546        IssmDouble* Grot=NULL;
     7547        IssmDouble* GSGrot=NULL;
    74807548        IssmDouble* GUrot=NULL;
    74817549        IssmDouble* GNrot=NULL;
     
    74947562        bool percpu=false;
    74957563        bool planethasocean=false;
     7564        bool SatelliteGravi=false;
    74967565
    74977566        this->parameters->FindParam(&nel,MeshNumberofelementsEnum);
     
    75017570        this->parameters->FindParam(&horiz,SolidearthSettingsHorizEnum);
    75027571        this->parameters->FindParam(&planethasocean,SolidearthSettingsGrdOceanEnum);
     7572        this->parameters->FindParam(&SatelliteGravi,SolidearthSettingsSatelliteGraviEnum);
    75037573
    75047574        if(sal){
     
    75287598                                this->inputs->GetArrayPtr(SealevelchangeGrotEnum,this->lid,&Grot,&size);
    75297599                                this->inputs->GetArrayPtr(SealevelchangeGUrotEnum,this->lid,&GUrot,&size);
     7600                                if (SatelliteGravi) this->inputs->GetArrayPtr(SealevelchangeGSatGravirotEnum,this->lid,&GSGrot,&size);
    75307601                                if (horiz){
    75317602                                        this->inputs->GetArrayPtr(SealevelchangeGErotEnum,this->lid,&GErot,&size);
     
    75357606                }
    75367607                this->SealevelchangeGxL(&RSLGrd[0],G, Gsub, Grot, loads, polarmotionvector, slgeom, nel,percpu=false,SealevelchangeViscousRSLEnum,computefuture=true);
     7608                if (SatelliteGravi) this->SealevelchangeGxL(&SGGrd[0],G, Gsub, GSGrot, loads, polarmotionvector, slgeom, nel,percpu=false,SealevelchangeViscousSGEnum,computefuture=true);
    75377609
    75387610                if(elastic){
     
    75547626
    75557627        /*Create geoid: */
    7556         for(int i=0;i<NUMVERTICES;i++)SealevelGrd[i]=UGrd[i]+RSLGrd[i];
     7628        for(int i=0;i<NUMVERTICES;i++){
     7629                SealevelGrd[i]=UGrd[i]+RSLGrd[i];
     7630                if (SatelliteGravi) SGGrd[i]+=UGrd[i];
     7631        }
    75577632
    75587633        /*Create inputs*/
    75597634        this->AddInput(SealevelGRDEnum,SealevelGrd,P1Enum);
    75607635        this->AddInput(BedGRDEnum,UGrd,P1Enum);
     7636        if (SatelliteGravi) this->AddInput(SatGraviGRDEnum,SGGrd,P1Enum);
    75617637        if(horiz){
    75627638                this->AddInput(BedNorthGRDEnum,NGrd,P1Enum);
    75637639                this->AddInput(BedEastGRDEnum,EGrd,P1Enum);
    75647640        }
     7641
     7642        /*Free ressources*/
     7643
     7644        xDelete<IssmDouble>(G);
     7645        xDelete<IssmDouble>(GU);
     7646        xDelete<IssmDouble>(GE);
     7647        xDelete<IssmDouble>(GN);
     7648        xDelete<IssmDouble>(Grot);
     7649        xDelete<IssmDouble>(GSGrot);
     7650        xDelete<IssmDouble>(GUrot);
     7651        xDelete<IssmDouble>(GNrot);
     7652        xDelete<IssmDouble>(GErot);
     7653
     7654        for (int l=0;l<SLGEOM_NUMLOADS;l++){
     7655                xDelete<IssmDouble>(Gsub[l]);
     7656                xDelete<IssmDouble>(GUsub[l]);
     7657                xDelete<IssmDouble>(GNsub[l]);
     7658                xDelete<IssmDouble>(GEsub[l]);
     7659        }
     7660        xDelete<IssmDouble>(Gsub[SLGEOM_NUMLOADS]);
     7661        xDelete<IssmDouble>(GUsub[SLGEOM_NUMLOADS]);
     7662        xDelete<IssmDouble>(GNsub[SLGEOM_NUMLOADS]);
     7663        xDelete<IssmDouble>(GEsub[SLGEOM_NUMLOADS]);
    75657664
    75667665} /*}}}*/
     
    75777676        int viscousindex=0; //important
    75787677        int viscousnumsteps=1; //important
     7678
     7679        IssmDouble* grdfieldinterp=NULL;
     7680        IssmDouble* viscoustimes=NULL;
     7681        IssmDouble  final_time;
     7682        IssmDouble  lincoeff;
     7683        IssmDouble  timeacc;
    75797684
    75807685        this->parameters->FindParam(&computeviscous,SolidearthSettingsViscousEnum);
     
    76617766                // 3*: subtract from viscous stack the grdfield that has already been accounted for so we don't add it again at the next time step
    76627767
    7663                 IssmDouble* grdfieldinterp=NULL;
    7664                 IssmDouble* viscoustimes=NULL;
    7665                 IssmDouble  final_time;
    7666                 IssmDouble  lincoeff;
    7667                 IssmDouble  timeacc;
    7668 
    76697768                this->parameters->FindParam(&viscoustimes,NULL,SealevelchangeViscousTimesEnum);
    76707769                this->parameters->FindParam(&final_time,TimesteppingFinalTimeEnum);
     
    77107809                }
    77117810
    7712                 /*Free allocatoins:*/
    7713                 xDelete<IssmDouble>(viscoustimes);
    77147811        }
    77157812        /*}}}*/
     
    77277824        }
    77287825
     7826
     7827        /*Free allocatoins:*/
     7828        xDelete<IssmDouble>(grdfield);
     7829        if (computeviscous){
     7830                xDelete<IssmDouble>(viscoustimes);
     7831                xDelete<IssmDouble>(viscousfield);
     7832                if(computefuture){
     7833                        xDelete<IssmDouble>(grdfieldinterp);
     7834                }
     7835        }
     7836
    77297837} /*}}}*/
    77307838
     
    77407848
    77417849} /*}}}*/
     7850
    77427851#endif
    77437852
  • issm/trunk-jpl/src/c/cores/sealevelchange_core.cpp

    r26800 r27053  
    430430        }
    431431
     432        /*Free ressources*/
     433        delete loads;
     434        delete oldsealevelloads;
     435        delete oceanareas;
     436        delete subelementoceanareas;
     437
    432438}
    433439/*}}}*/
     
    607613        #endif
    608614
     615        xDelete<IssmDouble>(xxe);
     616        xDelete<IssmDouble>(yye);
     617        xDelete<IssmDouble>(zze);
     618        xDelete<IssmDouble>(areae);
     619
    609620        return;
    610621
     
    672683        femmodel->parameters->AddObject(new DoubleVecParam(ZzeEnum,zze,nel));
    673684        femmodel->parameters->AddObject(new DoubleVecParam(AreaeEnum,areae,nel));
     685
     686        xDelete<IssmDouble>(xxe);
     687        xDelete<IssmDouble>(yye);
     688        xDelete<IssmDouble>(zze);
     689        xDelete<IssmDouble>(areae);
    674690
    675691        return slgeom;
     
    864880        xDelete<IssmDouble>(m2);
    865881        xDelete<IssmDouble>(m3);
     882
     883        xDelete<IssmDouble>(pmtf_col);
     884        xDelete<IssmDouble>(pmtf_ortho);
     885        xDelete<IssmDouble>(pmtf_z);
    866886        if (viscous){
     887                xDelete<IssmDouble>(viscoustimes);
     888                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        xDelete<IssmDouble>(viscouspolarmotion);
    867889                if (computefuture){
    868890                        xDelete<IssmDouble>(m1interp);
     
    935957                /*free allocations:*/
    936958                xDelete<IssmDouble>(viscoustimes);
    937         }
    938 
    939 
    940 }
     959                if (rotation) xDelete<IssmDouble>(viscouspolarmotion);
     960        }
     961
     962
     963} /*}}}*/
    941964void        ConserveOceanMass(FemModel* femmodel,GrdLoads* loads, IssmDouble offset, SealevelGeometry* slgeom){ /*{{{*/
    942965
     
    974997        loadcopy=vloadcopy->ToMPISerial();
    975998
     999        delete vloadcopy;
    9761000        return loadcopy;
    9771001
Note: See TracChangeset for help on using the changeset viewer.