Changeset 27104


Ignore:
Timestamp:
06/24/22 10:10:09 (3 years ago)
Author:
Eric.Larour
Message:

CHG: fixed all memory leaks.

Location:
issm/branches/trunk-larour-SLPS2022/src/c
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • issm/branches/trunk-larour-SLPS2022/src/c/analyses/SealevelchangeAnalysis.cpp

    r27084 r27104  
    99
    1010/*Model processing*/
     11SealevelchangeAnalysis::~SealevelchangeAnalysis(){/*{{{*/
     12
     13        BarystaticContributions* barycontrib=NULL;
     14        GenericParam<BarystaticContributions*>* barycontribparam=NULL;
     15
     16        barycontribparam = xDynamicCast<GenericParam<BarystaticContributions*>*>(femmodel->parameters->FindParamObject(BarystaticContributionsEnum));
     17        barycontrib=barycontribparam->GetParameterValue();
     18
     19        delete barycontrib;
     20}/*}}}*/
    1121void SealevelchangeAnalysis::CreateConstraints(Constraints* constraints,IoModel* iomodel){/*{{{*/
    1222        /*No constraints*/
     
    4353        /*external solidearthsolution: solid-Earth model*/
    4454        iomodel->FetchData(&isexternal,"md.solidearth.isexternal");
     55
    4556        if(isexternal){
    4657                iomodel->FetchData(&horiz,"md.solidearth.settings.horiz");
     
    209220                iomodel->FetchData(&externalnature,"md.solidearth.external.nature");
    210221                if(externalnature>=3){
    211                         int modelid;
     222                        IssmDouble modelid;
    212223                        int nummodels;
    213224
     
    276287                        parameters->AddObject(new DoubleMatParam(LoveTimeFreqEnum,love_timefreq,precomputednt,1));
    277288                        parameters->AddObject(new BoolParam(LoveIsTimeEnum,love_istime));
     289
     290                        /*Free allocations:*/
     291                        xDelete<IssmDouble>(love_timefreq);
    278292
    279293                        // AD performance is sensitive to calls to ensurecontiguous.
     
    524538                                nt=1; //in elastic, or if we run only selfattraction, we need only one step
    525539#ifdef _HAVE_AD_
    526                                 G_viscoelastic_interpolated=G_viscoelastic;
    527                                 U_viscoelastic_interpolated=U_viscoelastic;
    528                                 if(horiz)H_viscoelastic_interpolated=H_viscoelastic;
     540                                G_viscoelastic_interpolated=xNew<IssmDouble>(M,"t");
     541                                U_viscoelastic_interpolated=xNew<IssmDouble>(M,"t");
     542                                if(horiz) H_viscoelastic_interpolated=xNew<IssmDouble>(M,"t");
    529543#else
    530                                 G_viscoelastic_interpolated=G_viscoelastic;
    531                                 U_viscoelastic_interpolated=U_viscoelastic;
    532                                 if(horiz)H_viscoelastic_interpolated=H_viscoelastic;
     544                                G_viscoelastic_interpolated=xNew<IssmDouble>(M);
     545                                U_viscoelastic_interpolated=xNew<IssmDouble>(M);
     546                                if(horiz) H_viscoelastic_interpolated=xNew<IssmDouble>(M);
    533547#endif
     548
     549
     550                                xMemCpy<IssmDouble>(G_viscoelastic_interpolated,G_viscoelastic,M);
     551                                xMemCpy<IssmDouble>(U_viscoelastic_interpolated,U_viscoelastic,M);
     552                                if(horiz) xMemCpy<IssmDouble>(H_viscoelastic_interpolated,H_viscoelastic,M);
    534553
    535554                                if(rotation){ //if this cpu handles degree 2
     
    550569#endif
    551570
    552                                         Pmtf_col_interpolated=love_pmtf_colinear;
    553                                         Pmtf_ortho_interpolated=love_pmtf_ortho;
     571                                        Pmtf_col_interpolated[0]=love_pmtf_colinear[0];
     572                                        Pmtf_ortho_interpolated[0]=love_pmtf_ortho[0];
    554573                                        Pmtf_z_interpolated[0]=1.0+love_k[2];
    555574                                        Love_tk2_interpolated[0]=love_tk[2];
     
    587606                                xDelete<IssmDouble>(G_viscoelastic);
    588607                                xDelete<IssmDouble>(G_viscoelastic_local);
     608                                xDelete<IssmDouble>(G_viscoelastic_interpolated);
    589609                                xDelete<IssmDouble>(U_viscoelastic);
     610                                xDelete<IssmDouble>(U_viscoelastic_interpolated);
    590611                                xDelete<IssmDouble>(U_viscoelastic_local);
    591612                                if(horiz){
    592613                                        xDelete<IssmDouble>(H_viscoelastic);
     614                                        xDelete<IssmDouble>(H_viscoelastic_interpolated);
    593615                                        xDelete<IssmDouble>(H_viscoelastic_local);
    594616                                }
     
    596618                                        xDelete<IssmDouble>(love_pmtf_colinear);
    597619                                        xDelete<IssmDouble>(love_pmtf_ortho);
     620                                       
     621                                        xDelete<IssmDouble>(Love_tk2_interpolated);
     622                                        xDelete<IssmDouble>(Love_th2_interpolated);
     623                                        xDelete<IssmDouble>(Pmtf_col_interpolated);
     624                                        xDelete<IssmDouble>(Pmtf_ortho_interpolated);
     625                                        xDelete<IssmDouble>(Pmtf_z_interpolated);
     626                                        if(horiz){
     627                                                xDelete<IssmDouble>(Love_tl2_interpolated);
     628                                        }
    598629
    599630                                }
     
    622653        iomodel->DeleteData(&requestedoutputs,numoutputs,"md.solidearth.requested_outputs");
    623654        /*}}}*/
     655
    624656}/*}}}*/
    625657
  • issm/branches/trunk-larour-SLPS2022/src/c/classes/Elements/Tria.cpp

    r26911 r27104  
    66576657                LoveRotRSL  = xNewZeroInit<IssmDouble>(nt);
    66586658                LoveRotU    = xNewZeroInit<IssmDouble>(nt);
    6659                 LoveRothoriz= xNewZeroInit<IssmDouble>(nt);
     6659                if(horiz)LoveRothoriz= xNewZeroInit<IssmDouble>(nt);
    66606660                Grot        = xNewZeroInit<IssmDouble>(3*3*nt); //3 polar motion components * 3 vertices * number of time steps
    66616661                GUrot       = xNewZeroInit<IssmDouble>(3*3*nt);
     
    67436743                        }
    67446744                }
     6745                /*Free ressources:*/
     6746                xDelete<IssmDouble>(LoveRotRSL);
     6747                xDelete<IssmDouble>(LoveRotU);
     6748                if(horiz)xDelete<IssmDouble>(LoveRothoriz);
    67456749        }
    67466750        /*}}}*/
     
    74667470        /*Keep track of barystatic contributions:*/
    74677471        barycontrib->Set(this->Sid(),bslcice,bslchydro,bslcbp);
     7472
     7473        /*Free ressources:*/
     7474        xDelete<IssmDouble>(areae);
    74687475
    74697476}
     
    77827789                        /*Save viscous stack now that we updated the values:*/
    77837790                        this->inputs->SetArrayInput(viscousenum,this->lid,viscousfield,3*viscousnumsteps);
     7791
     7792                        /*Free ressources:*/
     7793                        xDelete<IssmDouble>(grdfieldinterp);
    77847794                }
    77857795
     
    78007810                for(i=0;i<NUMVERTICES;i++) grdfieldout[i]=grdfield[i*nt+0];
    78017811        }
     7812        /*Free ressources:*/
     7813        xDelete<IssmDouble>(grdfield);
    78027814
    78037815} /*}}}*/
  • issm/branches/trunk-larour-SLPS2022/src/c/classes/GrdLoads.cpp

    r26800 r27104  
    1919GrdLoads::GrdLoads(int nel,SealevelGeometry* slgeom){ /*{{{*/
    2020
     21        /*allocate:*/
    2122        vloads=new Vector<IssmDouble>(nel);
    2223        for (int i=0;i<SLGEOM_NUMLOADS;i++) vsubloads[i]=new Vector<IssmDouble>(slgeom->nbar[i]);
     
    2627
    2728        vsubsealevelloads=new Vector<IssmDouble>(slgeom->nbar[SLGEOM_OCEAN]);
     29
     30        /*make sure all pointers that are not allocated are NULL:*/
     31        loads=NULL;
     32        for (int i=0;i<SLGEOM_NUMLOADS;i++)subloads[i]=NULL;
     33        sealevelloads=NULL;
     34        subsealevelloads=NULL;
     35
    2836
    2937}; /*}}}*/
     
    5058        }
    5159
     60        /*Avoid leaks:*/
     61        if(loads)xDelete<IssmDouble>(loads);
     62        for (int i=0;i<SLGEOM_NUMLOADS;i++){
     63                if(subloads[i])xDelete<IssmDouble>(subloads[i]);
     64        }
     65
     66        /*Serialize:*/
    5267        loads=vloads->ToMPISerial();
    5368        for (int i=0;i<SLGEOM_NUMLOADS;i++){
     
    6479void GrdLoads::BroadcastSealevelLoads(void){ /*{{{*/
    6580
     81        /*Avoid leakds:*/
     82        if(sealevelloads)xDelete<IssmDouble>(sealevelloads);
     83        if(subsealevelloads)xDelete<IssmDouble>(subsealevelloads);
     84
     85        /*Serialize:*/
    6686        sealevelloads=vsealevelloads->ToMPISerial();
    6787        subsealevelloads=vsubsealevelloads->ToMPISerial();
    6888
    6989} /*}}}*/
    70 void GrdLoads::SHDegree2Coefficients(IssmDouble* deg2coeff, FemModel* femmodel, SealevelGeometry* slgeom){
     90void GrdLoads::SHDegree2Coefficients(IssmDouble* deg2coeff, FemModel* femmodel, SealevelGeometry* slgeom){ /*{{{*/
    7191
    7292        IssmDouble area,re, S;
     
    119139        ISSM_MPI_Bcast(&deg2coeff[2],1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    120140
    121 }
     141} /*}}}*/
  • issm/branches/trunk-larour-SLPS2022/src/c/cores/sealevelchange_core.cpp

    r27083 r27104  
    8181        /*End profiler*/
    8282        femmodel->profiler->Stop(SLRCORE);
     83
     84        /*Free ressources:*/
     85        delete slgeom;
     86
    8387}
    8488/*}}}*/
     
    265269        /*only run if grd was requested, if we are the earth, and we have reached
    266270         * the necessary number of time steps dictated by :*/
    267         if(!grd)return;
     271        if(!grd)            return;
    268272        if(count!=frequency)return;
    269273        femmodel->parameters->FindParam(&iscoupling,IsSlcCouplingEnum);
     
    357361
    358362                //convergence?
    359                 if(slcconvergence(loads->vsealevelloads,oldsealevelloads,eps_rel,eps_abs))break;
     363                if(slcconvergence(loads->vsealevelloads,oldsealevelloads,eps_rel,eps_abs)){
     364                        delete oldsealevelloads; break;
     365                }
    360366
    361367                //early return?
    362                 if(iterations>=max_nonlinear_iterations)break;
     368                if(iterations>=max_nonlinear_iterations){
     369                        delete oldsealevelloads; break;
     370                }
    363371                iterations++;
     372                delete oldsealevelloads;
    364373        }
    365374
     
    381390        if(planethasocean){
    382391                if (!sealevelloading){ //we haven't done so before, so we need to compute the ocean average and area
    383                         loads->sealevelloads=NULL; //needed to trigger the calculation of areas
     392                        if(loads->sealevelloads)xDelete<IssmDouble>(loads->sealevelloads); loads->sealevelloads=NULL; //needed to trigger the calculation of areas
    384393                        /*retrieve sea level average  and ocean area:*/
    385394                        for(Object* & object : femmodel->elements->objects){
     
    423432        }
    424433
     434        /*Free ressources:*/
     435        delete loads;
     436        delete subelementoceanareas;
     437        delete oceanareas;
     438        xDelete<IssmDouble>(sealevelpercpu);
     439
    425440}
    426441/*}}}*/
     
    607622        #endif
    608623
     624        xDelete<IssmDouble>(xxe);
     625        xDelete<IssmDouble>(yye);
     626        xDelete<IssmDouble>(zze);
     627        xDelete<IssmDouble>(areae);
     628
    609629        /*Indicate we won't do this twice: */
    610630        femmodel->parameters->AddObject(new BoolParam(SealevelchangeGeometryDoneEnum,true));
     631
    611632
    612633        return;
     
    675696        femmodel->parameters->AddObject(new DoubleVecParam(ZzeEnum,zze,nel));
    676697        femmodel->parameters->AddObject(new DoubleVecParam(AreaeEnum,areae,nel));
     698
     699        /*Free ressources:*/
     700        xDelete<IssmDouble>(xxe);
     701        xDelete<IssmDouble>(yye);
     702        xDelete<IssmDouble>(zze);
     703        xDelete<IssmDouble>(areae);
    677704
    678705        return slgeom;
     
    873900                        xDelete<IssmDouble>(m3interp);
    874901                }
    875         }
     902                xDelete<IssmDouble>(viscoustimes);
     903                xDelete<IssmDouble>(viscouspolarmotion);
     904        }
     905        xDelete<IssmDouble>(pmtf_col);
     906        xDelete<IssmDouble>(pmtf_ortho);
     907        xDelete<IssmDouble>(pmtf_z);
    876908
    877909} /*}}}*/
  • issm/branches/trunk-larour-SLPS2022/src/c/modules/ModelProcessorx/CreateElementsVerticesAndMaterials.cpp

    r26327 r27104  
    223223                                                                                        {
    224224                                                                                                Tria* tria= xDynamicCast<Tria*>(element);
     225                                                                                                if(tria->hmaterial)delete tria->hmaterial;
    225226                                                                                                tria->hmaterial=NULL;
    226227                                                                                        }
Note: See TracChangeset for help on using the changeset viewer.