Ignore:
Timestamp:
03/19/12 20:11:39 (13 years ago)
Author:
Eric.Larour
Message:

Hook up new issm toolkit

File:
1 edited

Legend:

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

    r11713 r11734  
    2525Vector::Vector(){
    2626
    27         this->M=0;
    2827        #ifdef _HAVE_PETSC_
    2928        this->vector=NULL;
     
    4241        this->vector=NewVec(pM,fromlocalsize);
    4342        #else
    44         this->M=pM;
    45         this->vector=(double*)xcalloc(pM,sizeof(double));
     43        this->vector=new SeqVec(pM,fromlocalsize);
    4644        #endif
    4745        #ifdef _HAVE_ADOLC_
     
    5149/*}}}*/
    5250/*FUNCTION Vector::Vector(double* serial_vec,int M){{{1*/
    53 Vector::Vector(double* serial_vec,int pM){
     51Vector::Vector(double* serial_vec,int M){
    5452
    5553        int i,j;
     
    5856                int* idxm=NULL;
    5957
    60                 this->vector=NewVec(pM);
     58                this->vector=NewVec(M);
    6159               
    6260                idxm=(int*)xmalloc(M*sizeof(int));
     
    7068
    7169        #else
    72                 this->M=pM;
    73                 this->vector=(double*)xcalloc(pM,sizeof(double));
    74         #endif
    75         #ifdef _HAVE_ADOLC_
    76                 this->avector=(adouble*)xmalloc(pM*sizeof(adouble));
     70                this->vector=new SeqVec(serial_vec,M);
     71        #endif
     72        #ifdef _HAVE_ADOLC_
     73                this->avector=(adouble*)xmalloc(M*sizeof(adouble));
    7774        #endif
    7875}
     
    8279Vector::Vector(Vec petsc_vec){
    8380
    84         /*Get Vector size*/
    85         VecGetSize(petsc_vec,&this->M);
    86 
    8781        /*copy vector*/
    8882        VecDuplicate(petsc_vec,&this->vector);
     
    9892        VecFree(&this->vector);
    9993        #else
    100         xfree((void**)&this->vector);
     94        delete this->vector;
    10195        #endif
    10296        #ifdef _HAVE_ADOLC_
     
    115109        VecView(this->vector,PETSC_VIEWER_STDOUT_WORLD);
    116110        #else
    117         printf("Vector size: %i\n",M);
    118         for(i=0;i<M;i++){
    119                 printf("%g\n ",*(vector+i));
    120         }
    121         #endif
    122 
    123         #ifdef _HAVE_ADOLC_
    124         /*Not sure about that one. Should we use the overloaded operator >>?*/
    125         printf("ADOLC Vector equivalent:" );
    126         for(i=0;i<M;i++){
    127                 printf("%g\n ",*(avector+i));
    128         }
     111        this->vector->Echo();
     112        #endif
     113
     114        #ifdef _HAVE_ADOLC_
     115        /*do nothing for now: */
    129116        #endif
    130117}
     
    139126        PetscVectorToMatlabVector(&dataref,this->vector);
    140127        #else
    141         _error_("not implemented yet!");
     128        dataref=this->vector->ToMatlabVector();
    142129        #endif
    143130        return dataref;
    144131
     132}
     133/*}}}*/
     134/*FUNCTION MatlabVectorToVector{{{1*/
     135Vector* MatlabVectorToVector(const mxArray* mxvector){
     136
     137        int dummy;
     138        Vector* vector=NULL;
     139
     140        /*allocate vector object: */
     141        vector=new Vector();
     142
     143        #ifdef _HAVE_PETSC_
     144        MatlabVectorToPetscVector(&vector->vector,&dummy,mxvector);
     145        #else
     146        vector->vector=MatlabVectorToSeqVec(mxvector);
     147        #endif
     148       
     149        return vector;
    145150}
    146151/*}}}*/
     
    154159                VecAssemblyEnd(this->vector);
    155160        #else
    156                 /*do nothing*/
     161                this->vector->Assemble();
    157162        #endif
    158163
     
    167172                VecSetValues(this->vector,ssize,list,values,ISSMToPetscInsertMode(mode));
    168173        #else
    169                 _error_("not implemented yet!");
     174                this->vector->SetValues(ssize,list,values,mode);
    170175        #endif
    171176
     
    179184                VecSetValues(this->vector,1,&dof,&value,ISSMToPetscInsertMode(mode));
    180185        #else
    181                 _error_("not implemented yet!");
     186                this->vector->SetValue(dof,value,mode);
    182187        #endif
    183188
     
    191196                VecGetValues(this->vector,1,&dof,pvalue);
    192197        #else
    193                 _error_("not implemented yet!");
     198        this->vector->GetValue(pvalue,dof);
    194199        #endif
    195200}
     
    202207                VecGetSize(this->vector,pM);
    203208        #else
    204                 _error_("not implemented yet!");
     209                this->vector->GetSize(pM);
    205210        #endif
    206211
     
    214219                VecGetLocalSize(this->vector,pM);
    215220        #else
    216                 _error_("not implemented yet!");
     221                this->vector->GetLocalSize(pM);
    217222        #endif
    218223
     
    229234                VecDuplicate(this->vector,&vec_output);
    230235                output->vector=vec_output;
    231                 VecGetSize(output->vector,&output->M);
    232         #else
    233                 _error_("not implemented yet!");
     236        #else
     237                output->vector=this->vector->Duplicate();
    234238        #endif
    235239        return output;
     
    244248                VecSet(this->vector,value);
    245249        #else
    246                 _error_("not implemented yet!");
     250                this->vector->Set(value);
    247251        #endif
    248252
     
    256260                VecAXPY(this->vector,a,X->vector);
    257261        #else
    258                 _error_("not implemented yet!");
     262                this->vector->AXPY(X->vector,a);
    259263        #endif
    260264}
     
    267271                VecAYPX(this->vector,a,X->vector);
    268272        #else
    269                 _error_("not implemented yet!");
     273                this->vector->AYPX(X->vector,a);
    270274        #endif
    271275
     
    280284                VecToMPISerial(&vec_serial, this->vector);
    281285        #else
    282                 _error_("not implemented yet!");
     286                vec_serial=this->vector->ToMPISerial();
    283287        #endif
    284288
     
    293297                VecCopy(this->vector,to->vector);
    294298        #else
    295                 _error_("not implemented yet!");
     299                this->vector->Copy(to->vector);
    296300        #endif
    297301
     
    306310                VecNorm(this->vector,ISSMToPetscNormMode(norm_type),&norm);
    307311        #else
    308                 _error_("not implemented yet!");
     312                norm=this->vector->Norm(norm_type);
    309313        #endif
    310314        return norm;
     
    318322                VecScale(this->vector,scale_factor);
    319323        #else
    320                 _error_("not implemented yet!");
     324                this->vector->Scale(scale_factor);
    321325        #endif
    322326}
     
    330334                VecDot(this->vector,vector->vector,&dot);
    331335        #else
    332                 _error_("not implemented yet!");
     336                dot=this->vector->Dot(vector->vector);
    333337        #endif
    334338        return dot;
     
    342346                VecPointwiseDivide(this->vector,x->vector,y->vector);
    343347        #else
    344                 _error_("not implemented yet!");
    345         #endif
    346 }
    347 /*}}}*/
     348                this->vector->PointwiseDivide(x->vector,y->vector);
     349        #endif
     350}
     351/*}}}*/
Note: See TracChangeset for help on using the changeset viewer.