Changeset 12441


Ignore:
Timestamp:
06/18/12 09:17:08 (13 years ago)
Author:
Mathieu Morlighem
Message:

changing xmalloc to xNew and xfree to xDelete

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

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/objects/Numerics/ElementMatrix.cpp

    r12365 r12441  
    7878
    7979        /*Initialize itransformation matrix Ke[P[i]] = Ke2[i]*/
    80         P=(int*)xmalloc(Ke2->nrows*sizeof(int));
     80        P=xNew<int>(Ke2->nrows);
    8181
    8282        /*1: Get the new numbering of Ke2 and get size of the new matrix*/
     
    100100
    101101        /*Gset and values*/
    102         this->gglobaldoflist=(int*)xmalloc(this->nrows*sizeof(int));
    103         this->values=(double*)xcalloc(this->nrows*this->ncols,sizeof(double));
     102        this->gglobaldoflist=xNew<int>(this->nrows);
     103        this->values=xNewInit<double>(this->nrows*this->ncols,0.0);
    104104        for(i=0;i<Ke1->nrows;i++){
    105105                for(j=0;j<Ke1->ncols;j++){
     
    122122        this->row_fsize=fsize;
    123123        if(fsize){
    124                 this->row_flocaldoflist =(int*)xmalloc(fsize*sizeof(int));
    125                 this->row_fglobaldoflist=(int*)xmalloc(fsize*sizeof(int));
     124                this->row_flocaldoflist =xNew<int>(fsize);
     125                this->row_fglobaldoflist=xNew<int>(fsize);
    126126                for(i=0;i<Ke1->row_fsize;i++){
    127127                        this->row_flocaldoflist[i] =Ke1->row_flocaldoflist[i];
     
    149149        this->row_ssize=ssize;
    150150        if(ssize){
    151                 this->row_slocaldoflist =(int*)xmalloc(ssize*sizeof(int));
    152                 this->row_sglobaldoflist=(int*)xmalloc(ssize*sizeof(int));
     151                this->row_slocaldoflist =xNew<int>(ssize);
     152                this->row_sglobaldoflist=xNew<int>(ssize);
    153153                for(i=0;i<Ke1->row_ssize;i++){
    154154                        this->row_slocaldoflist[i] =Ke1->row_slocaldoflist[i];
     
    178178
    179179        /*clean-up*/
    180         xfree((void**)&P);
     180        xDelete<int>(P);
    181181}
    182182/*}}}*/
     
    205205
    206206        /*fill values with 0: */
    207         this->values=(double*)xcalloc(this->nrows*this->ncols,sizeof(double));
     207        this->values=xNewInit<double>(this->nrows*this->ncols,0.0);
    208208
    209209        /*g list*/
     
    231231ElementMatrix::~ElementMatrix(){
    232232       
    233         xfree((void**)&this->values);
    234         xfree((void**)&this->gglobaldoflist);
    235         xfree((void**)&this->row_flocaldoflist);
    236         xfree((void**)&this->row_fglobaldoflist);
    237         xfree((void**)&this->row_slocaldoflist);
    238         xfree((void**)&this->row_sglobaldoflist);
    239         xfree((void**)&this->col_flocaldoflist);
    240         xfree((void**)&this->col_fglobaldoflist);
    241         xfree((void**)&this->col_slocaldoflist);
    242         xfree((void**)&this->col_sglobaldoflist);
     233        xDelete<double>(this->values);
     234        xDelete<int>(this->gglobaldoflist);
     235        xDelete<int>(this->row_flocaldoflist);
     236        xDelete<int>(this->row_fglobaldoflist);
     237        xDelete<int>(this->row_slocaldoflist);
     238        xDelete<int>(this->row_sglobaldoflist);
     239        xDelete<int>(this->col_flocaldoflist);
     240        xDelete<int>(this->col_fglobaldoflist);
     241        xDelete<int>(this->col_slocaldoflist);
     242        xDelete<int>(this->col_sglobaldoflist);
    243243}
    244244/*}}}*/
     
    265265                if(this->row_fsize){
    266266                        /*first, retrieve values that are in the f-set from the g-set values matrix: */
    267                         localvalues=(double*)xmalloc(this->row_fsize*this->row_fsize*sizeof(double));
     267                        localvalues=xNew<double>(this->row_fsize*this->row_fsize);
    268268                        for(i=0;i<this->row_fsize;i++){
    269269                                for(j=0;j<this->row_fsize;j++){
     
    275275
    276276                        /*Free ressources:*/
    277                         xfree((void**)&localvalues);
     277                        xDelete<double>(localvalues);
    278278                }
    279279
     
    281281                if((this->row_ssize!=0) && (this->row_fsize!=0)){
    282282                        /*first, retrieve values that are in the f and s-set from the g-set values matrix: */
    283                         localvalues=(double*)xmalloc(this->row_fsize*this->row_ssize*sizeof(double));
     283                        localvalues=xNew<double>(this->row_fsize*this->row_ssize);
    284284                        for(i=0;i<this->row_fsize;i++){
    285285                                for(j=0;j<this->row_ssize;j++){
     
    291291
    292292                        /*Free ressources:*/
    293                         xfree((void**)&localvalues);
     293                        xDelete<double>(localvalues);
    294294                }
    295295        }
     
    317317                if(this->row_fsize){
    318318                        /*first, retrieve values that are in the f-set from the g-set values matrix: */
    319                         localvalues=(double*)xmalloc(this->row_fsize*this->row_fsize*sizeof(double));
     319                        localvalues=xNew<double>(this->row_fsize*this->row_fsize);
    320320                        for(i=0;i<this->row_fsize;i++){
    321321                                for(j=0;j<this->row_fsize;j++){
     
    327327
    328328                        /*Free ressources:*/
    329                         xfree((void**)&localvalues);
     329                        xDelete<double>(localvalues);
    330330                }
    331331
     
    428428        this->dofsymmetrical=Ke->dofsymmetrical;
    429429
    430         this->values=(double*)xmalloc(this->nrows*this->ncols*sizeof(double));
     430        this->values=xNew<double>(this->nrows*this->ncols);
    431431        memcpy(this->values,Ke->values,this->nrows*this->ncols*sizeof(double));
    432432
    433         this->gglobaldoflist=(int*)xmalloc(this->nrows*sizeof(int));
     433        this->gglobaldoflist=xNew<int>(this->nrows);
    434434        memcpy(this->gglobaldoflist,Ke->gglobaldoflist,this->nrows*sizeof(int));
    435435
    436436        this->row_fsize=Ke->row_fsize;
    437437        if(this->row_fsize){
    438                 this->row_flocaldoflist=(int*)xmalloc(this->row_fsize*sizeof(int));
     438                this->row_flocaldoflist=xNew<int>(this->row_fsize);
    439439                memcpy(this->row_flocaldoflist,Ke->row_flocaldoflist,this->row_fsize*sizeof(int));
    440                 this->row_fglobaldoflist=(int*)xmalloc(this->row_fsize*sizeof(int));
     440                this->row_fglobaldoflist=xNew<int>(this->row_fsize);
    441441                memcpy(this->row_fglobaldoflist,Ke->row_fglobaldoflist,this->row_fsize*sizeof(int));
    442442        }
     
    448448        this->row_ssize=Ke->row_ssize;
    449449        if(this->row_ssize){
    450                 this->row_slocaldoflist=(int*)xmalloc(this->row_ssize*sizeof(int));
     450                this->row_slocaldoflist=xNew<int>(this->row_ssize);
    451451                memcpy(this->row_slocaldoflist,Ke->row_slocaldoflist,this->row_ssize*sizeof(int));
    452                 this->row_sglobaldoflist=(int*)xmalloc(this->row_ssize*sizeof(int));
     452                this->row_sglobaldoflist=xNew<int>(this->row_ssize);
    453453                memcpy(this->row_sglobaldoflist,Ke->row_sglobaldoflist,this->row_ssize*sizeof(int));
    454454        }
     
    460460        this->col_fsize=Ke->col_fsize;
    461461        if(this->col_fsize){
    462                 this->col_flocaldoflist=(int*)xmalloc(this->col_fsize*sizeof(int));
     462                this->col_flocaldoflist=xNew<int>(this->col_fsize);
    463463                memcpy(this->col_flocaldoflist,Ke->col_flocaldoflist,this->col_fsize*sizeof(int));
    464                 this->col_fglobaldoflist=(int*)xmalloc(this->col_fsize*sizeof(int));
     464                this->col_fglobaldoflist=xNew<int>(this->col_fsize);
    465465                memcpy(this->col_fglobaldoflist,Ke->col_fglobaldoflist,this->col_fsize*sizeof(int));
    466466        }
     
    472472        this->col_ssize=Ke->col_ssize;
    473473        if(this->col_ssize){
    474                 this->col_slocaldoflist=(int*)xmalloc(this->col_ssize*sizeof(int));
     474                this->col_slocaldoflist=xNew<int>(this->col_ssize);
    475475                memcpy(this->col_slocaldoflist,Ke->col_slocaldoflist,this->col_ssize*sizeof(int));
    476                 this->col_sglobaldoflist=(int*)xmalloc(this->col_ssize*sizeof(int));
     476                this->col_sglobaldoflist=xNew<int>(this->col_ssize);
    477477                memcpy(this->col_sglobaldoflist,Ke->col_sglobaldoflist,this->col_ssize*sizeof(int));
    478478        }
  • issm/trunk-jpl/src/c/objects/Numerics/ElementVector.cpp

    r12365 r12441  
    5454
    5555        /*Initialize itransformation matrix pe[P[i]] = pe2[i]*/
    56         P=(int*)xmalloc(pe2->nrows*sizeof(int));
     56        P=xNew<int>(pe2->nrows);
    5757
    5858        /*1: Get the new numbering of pe2 and get size of the new matrix*/
     
    7474
    7575        /*Gset and values*/
    76         this->gglobaldoflist=(int*)xmalloc(this->nrows*sizeof(int));
    77         this->values=(double*)xcalloc(this->nrows,sizeof(double));
     76        this->gglobaldoflist=xNew<int>(this->nrows);
     77        this->values=xNewInit<double>(this->nrows,0.0);
    7878        for(i=0;i<pe1->nrows;i++){
    7979                this->values[i] += pe1->values[i];
     
    9292        this->fsize=fsize;
    9393        if(fsize){
    94                 this->flocaldoflist =(int*)xmalloc(fsize*sizeof(int));
    95                 this->fglobaldoflist=(int*)xmalloc(fsize*sizeof(int));
     94                this->flocaldoflist =xNew<int>(fsize);
     95                this->fglobaldoflist=xNew<int>(fsize);
    9696                for(i=0;i<pe1->fsize;i++){
    9797                        this->flocaldoflist[i] =pe1->flocaldoflist[i];
     
    113113
    114114        /*clean-up*/
    115         xfree((void**)&P);
     115        xDelete<int>(P);
    116116}
    117117/*}}}*/
     
    138138
    139139        /*fill values with 0: */
    140         this->values=(double*)xcalloc(this->nrows,sizeof(double));
     140        this->values=xNewInit<double>(this->nrows,0.0);
    141141       
    142142        /*g list*/
     
    152152ElementVector::~ElementVector(){
    153153       
    154         xfree((void**)&this->values);
    155         xfree((void**)&this->gglobaldoflist);
    156         xfree((void**)&this->flocaldoflist);
    157         xfree((void**)&this->fglobaldoflist);
     154        xDelete<double>(this->values);
     155        xDelete<int>(this->gglobaldoflist);
     156        xDelete<int>(this->flocaldoflist);
     157        xDelete<int>(this->fglobaldoflist);
    158158}
    159159/*}}}*/
     
    171171        if(this->fsize){
    172172                /*first, retrieve values that are in the f-set from the g-set values vector: */
    173                 localvalues=(double*)xmalloc(this->fsize*sizeof(double));
     173                localvalues=xNew<double>(this->fsize);
    174174                for(i=0;i<this->fsize;i++){
    175175                        localvalues[i]=this->values[this->flocaldoflist[i]];
     
    179179
    180180                /*Free ressources:*/
    181                 xfree((void**)&localvalues);
     181                xDelete<double>(localvalues);
    182182        }
    183183       
     
    192192        if(this->fsize){
    193193                /*first, retrieve values that are in the f-set from the g-set values vector: */
    194                 localvalues=(double*)xmalloc(this->fsize*sizeof(double));
     194                localvalues=xNew<double>(this->fsize);
    195195                for(i=0;i<this->fsize;i++){
    196196                        localvalues[i]=this->values[this->flocaldoflist[i]];
     
    200200
    201201                /*Free ressources:*/
    202                 xfree((void**)&localvalues);
     202                xDelete<double>(localvalues);
    203203        }
    204204
     
    245245        this->nrows =pe->nrows;
    246246
    247         this->values=(double*)xmalloc(this->nrows*sizeof(double));
     247        this->values=xNew<double>(this->nrows);
    248248        memcpy(this->values,pe->values,this->nrows*sizeof(double));
    249249
    250         this->gglobaldoflist=(int*)xmalloc(this->nrows*sizeof(int));
     250        this->gglobaldoflist=xNew<int>(this->nrows);
    251251        memcpy(this->gglobaldoflist,pe->gglobaldoflist,this->nrows*sizeof(int));
    252252
    253253        this->fsize=pe->fsize;
    254254        if(this->fsize){
    255                 this->flocaldoflist=(int*)xmalloc(this->fsize*sizeof(int));
     255                this->flocaldoflist=xNew<int>(this->fsize);
    256256                memcpy(this->flocaldoflist,pe->flocaldoflist,this->fsize*sizeof(int));
    257                 this->fglobaldoflist=(int*)xmalloc(this->fsize*sizeof(int));
     257                this->fglobaldoflist=xNew<int>(this->fsize);
    258258                memcpy(this->fglobaldoflist,pe->fglobaldoflist,this->fsize*sizeof(int));
    259259        }
  • issm/trunk-jpl/src/c/objects/Numerics/Matrix.cpp

    r12365 r12441  
    4545        #endif
    4646        #ifdef _HAVE_ADOLC_
    47         this->amatrix=(adouble*)xmalloc(M*N*sizeof(adouble));
     47        this->amatrix=xNew<adouble>(M*N);
    4848        #endif
    4949}
     
    5858        #endif
    5959        #ifdef _HAVE_ADOLC_
    60         this->amatrix=(adouble*)xmalloc(M*N*sizeof(adouble));
     60        this->amatrix=xNew<adouble>;
    6161        #endif
    6262}
     
    6969
    7070
    71         int* idxm=(int*)xmalloc(M*sizeof(int));
    72         int* idxn=(int*)xmalloc(N*sizeof(int));
     71        int* idxm=xNew<int>(M);
     72        int* idxn=xNew<int>(N);
    7373        for(i=0;i<M;i++)idxm[i]=i;
    7474        for(i=0;i<N;i++)idxn[i]=i;
     
    7979        MatAssemblyEnd(this->matrix,MAT_FINAL_ASSEMBLY);
    8080
    81         xfree((void**)&idxm);
    82         xfree((void**)&idxn);
     81        xDelete<int>(idxm);
     82        xDelete<int>(idxn);
    8383        #else
    8484        this->matrix=new SeqMat(serial_mat,M,N,sparsity);
    8585        #endif
    8686        #ifdef _HAVE_ADOLC_
    87         this->amatrix=(adouble*)xmalloc(M*N*sizeof(adouble));
     87        this->amatrix=xNew<adouble>(M*N);
    8888        #endif
    8989}
     
    9898        #endif
    9999        #ifdef _HAVE_ADOLC_
    100         this->amatrix=(adouble*)xmalloc(M*N*sizeof(adouble));
     100        this->amatrix=xNew<adouble>(M*N);
    101101        #endif
    102102}
     
    111111        #endif
    112112        #ifdef _HAVE_ADOLC_
    113         xfree((void**)&this->amatrix);
     113        xDelete<adouble>(this->amatrix);
    114114        #endif
    115115}
  • issm/trunk-jpl/src/c/objects/Numerics/Vector.cpp

    r12365 r12441  
    4444        #endif
    4545        #ifdef _HAVE_ADOLC_
    46         this->avector=(adouble*)xmalloc(pM*sizeof(adouble));
     46        this->avector=xNew<adouble>(pM);
    4747        #endif
    4848}
     
    5252
    5353        #ifdef _HAVE_PETSC_
    54                 int* idxm=(int*)xmalloc(M*sizeof(int));
     54                int* idxm=xNew<int>(M);
    5555                for(int i=0;i<M;i++) idxm[i]=i;
    5656
     
    6060                VecAssemblyEnd(this->vector);
    6161
    62                 xfree((void**)&idxm);
     62                xDelete<int>(idxm);
    6363        #else
    6464                this->vector=new SeqVec(serial_vec,M);
    6565        #endif
    6666        #ifdef _HAVE_ADOLC_
    67                 this->avector=(adouble*)xmalloc(M*sizeof(adouble));
     67                this->avector=xNew<adouble>(M);
    6868        #endif
    6969}
     
    109109        #endif
    110110        #ifdef _HAVE_ADOLC_
    111         xfree((void**)&this->avector);
     111        xDelete<adouble>(this->avector);
    112112        #endif
    113113}
  • issm/trunk-jpl/src/c/shared/Matrix/MatrixUtils.cpp

    r12440 r12441  
    188188        ncol=nrow;
    189189        det=1.;
    190         pivrc =(int(*)[2])xNew<int>(nrow*2);
     190        pivrc1 =xNew<int>(nrow);
     191        pivrc2 =xNew<int>(nrow);
    191192        pindx =xNew<int>(nrow);
    192193
     
    210211
    211212                if (fabs(pivot) < DBL_EPSILON) {
    212                         xfree((void**)&pivrc);
     213                        xDelete<int>(pivrc1);
     214                        xDelete<int>(pivrc2);
    213215                        xDelete<int>(pindx);
    214216                        _error_("Pivot %f less than machine epsilon",pivot);
     
    325327        }
    326328
    327         if (pdet)
    328                 *pdet=det;
    329 
    330         xfree((void**)&pivrc);
     329        if (pdet) *pdet=det;
     330        xDelete<int>(pivrc1);
     331        xDelete<int>(pivrc2);
    331332        xDelete<int>(pindx);
    332333        return noerr;
Note: See TracChangeset for help on using the changeset viewer.