Changeset 11743


Ignore:
Timestamp:
03/20/12 09:51:05 (13 years ago)
Author:
Mathieu Morlighem
Message:

no NULL pointer allowed for Vector or Matrix

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

Legend:

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

    r11734 r11743  
    2626Matrix::Matrix(){
    2727
    28         this->M=0;
    29         this->N=0;
    30 
    3128        #ifdef _HAVE_PETSC_
    3229        this->matrix=NULL;
     
    4037/*}}}*/
    4138/*FUNCTION Matrix::Matrix(int M,int N){{{1*/
    42 Matrix::Matrix(int pM,int pN){
    43 
    44         this->M=pM;
    45         this->N=pN;
    46 
    47         #ifdef _HAVE_PETSC_
    48         this->matrix=NewMat(pM,pN);
    49         #else
    50         this->matrix=new SeqMat(pM,pN);
    51         #endif
    52         #ifdef _HAVE_ADOLC_
    53         this->amatrix=(adouble*)xmalloc(pM*pN*sizeof(adouble));
     39Matrix::Matrix(int M,int N){
     40
     41        #ifdef _HAVE_PETSC_
     42        this->matrix=NewMat(M,N);
     43        #else
     44        this->matrix=new SeqMat(M,N);
     45        #endif
     46        #ifdef _HAVE_ADOLC_
     47        this->amatrix=(adouble*)xmalloc(M*N*sizeof(adouble));
    5448        #endif
    5549}
    5650/*}}}*/
    5751/*FUNCTION Matrix::Matrix(int M,int N,double sparsity){{{1*/
    58 Matrix::Matrix(int pM,int pN,double sparsity){
    59 
    60         this->M=pM;
    61         this->N=pN;
    62 
    63         #ifdef _HAVE_PETSC_
    64         this->matrix=NewMat(pM,pN,sparsity);
    65         #else
    66         this->matrix=new SeqMat(pM,pN,sparsity);
    67         #endif
    68         #ifdef _HAVE_ADOLC_
    69         this->amatrix=(adouble*)xmalloc(pM*pN*sizeof(adouble));
     52Matrix::Matrix(int M,int N,double sparsity){
     53
     54        #ifdef _HAVE_PETSC_
     55        this->matrix=NewMat(M,N,sparsity);
     56        #else
     57        this->matrix=new SeqMat(M,N,sparsity);
     58        #endif
     59        #ifdef _HAVE_ADOLC_
     60        this->amatrix=(adouble*)xmalloc(M*N*sizeof(adouble));
    7061        #endif
    7162}
    7263/*}}}*/
    7364/*FUNCTION Matrix::Matrix(double* serial_mat, int M,int N,double sparsity){{{1*/
    74 Matrix::Matrix(double* serial_mat, int pM,int pN,double sparsity){
    75 
    76         this->M=pM;
    77         this->N=pN;
     65Matrix::Matrix(double* serial_mat, int M,int N,double sparsity){
    7866
    7967        #ifdef _HAVE_PETSC_
    8068        int     i;
    81         int*    idxm=NULL;
    82         int*    idxn=NULL;
    83 
    84         this->matrix=NewMat(pM,pN,sparsity);
    85 
    86         idxm=(int*)xmalloc(M*sizeof(int));
    87         idxn=(int*)xmalloc(N*sizeof(int));
     69
     70        int* idxm=(int*)xmalloc(M*sizeof(int));
     71        int* idxn=(int*)xmalloc(N*sizeof(int));
    8872        for(i=0;i<M;i++)idxm[i]=i;
    8973        for(i=0;i<N;i++)idxn[i]=i;
    9074
     75        this->matrix=NewMat(M,N,sparsity);
    9176        MatSetValues(this->matrix,M,idxm,N,idxn,serial_mat,INSERT_VALUES);
    92 
    9377        MatAssemblyBegin(this->matrix,MAT_FINAL_ASSEMBLY);
    9478        MatAssemblyEnd(this->matrix,MAT_FINAL_ASSEMBLY);
     
    9781        xfree((void**)&idxn);
    9882        #else
    99         this->matrix=new SeqMat(serial_mat,pM,pN,sparsity);
    100         #endif
    101         #ifdef _HAVE_ADOLC_
    102         this->amatrix=(adouble*)xmalloc(pM*pN*sizeof(adouble));
     83        this->matrix=new SeqMat(serial_mat,M,N,sparsity);
     84        #endif
     85        #ifdef _HAVE_ADOLC_
     86        this->amatrix=(adouble*)xmalloc(M*N*sizeof(adouble));
    10387        #endif
    10488}
    10589/*}}}*/
    10690/*FUNCTION Matrix::Matrix(int M,int N,int connectivity,int numberofdofspernode){{{1*/
    107 Matrix::Matrix(int pM,int pN,int connectivity,int numberofdofspernode){
    108        
    109         this->M=pM;
    110         this->N=pN;
    111 
    112         #ifdef _HAVE_PETSC_
    113         this->matrix=NewMat(pM,pN,connectivity,numberofdofspernode);
    114         #else
    115         this->matrix=new SeqMat(pM,pN,connectivity,numberofdofspernode);
    116         #endif
    117         #ifdef _HAVE_ADOLC_
    118         this->amatrix=(adouble*)xmalloc(pM*pN*sizeof(adouble));
     91Matrix::Matrix(int M,int N,int connectivity,int numberofdofspernode){
     92       
     93        #ifdef _HAVE_PETSC_
     94        this->matrix=NewMat(M,N,connectivity,numberofdofspernode);
     95        #else
     96        this->matrix=new SeqMat(M,N,connectivity,numberofdofspernode);
     97        #endif
     98        #ifdef _HAVE_ADOLC_
     99        this->amatrix=(adouble*)xmalloc(M*N*sizeof(adouble));
    119100        #endif
    120101}
     
    183164
    184165        #ifdef _HAVE_PETSC_
    185         MatlabMatrixToPetscMatrix(&matrix->matrix,&matrix->M,&matrix->N,mxmatrix);
     166        MatlabMatrixToPetscMatrix(&matrix->matrix,NULL,NULL,mxmatrix);
    186167        #else
    187168        matrix->matrix=MatlabMatrixToSeqMat(mxmatrix);
  • issm/trunk-jpl/src/c/objects/Numerics/Matrix.h

    r11734 r11743  
    11/*!\file:  Matrix.h
    2  * \brief wrapper to matrix objects. The goal is to control which API (PETSC,Scalpack, Plapack?)
     2 * \brief wrapper to matrix objects. The goal is to control which API (PETSc,Scalpack, Plapack?)
    33 * implements our underlying matrix format.
    44 */
     
    3232        public:
    3333       
    34                 int M,N;
    35 
    3634                #ifdef _HAVE_PETSC_
    3735                Mat matrix;
  • issm/trunk-jpl/src/c/objects/Numerics/Vector.cpp

    r11739 r11743  
    5151Vector::Vector(double* serial_vec,int M){
    5252
    53         int i,j;
    54 
    55         #ifdef _HAVE_PETSC_
    56                 int* idxm=NULL;
     53        #ifdef _HAVE_PETSC_
     54                int* idxm=(int*)xmalloc(M*sizeof(int));
     55                for(int i=0;i<M;i++) idxm[i]=i;
    5756
    5857                this->vector=NewVec(M);
    59                
    60                 idxm=(int*)xmalloc(M*sizeof(int));
    61                 for(i=0;i<M;i++)idxm[i]=i;
    6258                VecSetValues(this->vector,M,idxm,serial_vec,INSERT_VALUES);
    63 
    6459                VecAssemblyBegin(this->vector);
    6560                VecAssemblyEnd(this->vector);
    6661
    6762                xfree((void**)&idxm);
    68 
    6963        #else
    7064                this->vector=new SeqVec(serial_vec,M);
     
    112106
    113107        #ifdef _HAVE_PETSC_
    114         if(!this->vector){
    115                 printf("Vector size: 0\n");
    116         }
    117         else VecView(this->vector,PETSC_VIEWER_STDOUT_WORLD);
     108        _assert_(this->vector);
     109        VecView(this->vector,PETSC_VIEWER_STDOUT_WORLD);
    118110        #else
    119111        this->vector->Echo();
     
    212204               
    213205        #ifdef _HAVE_PETSC_
    214                 if(!this->vector)*pM=0;
     206                _assert_(this->vector);
    215207                else VecGetSize(this->vector,pM);
    216208        #else
     
    218210        #endif
    219211
     212}
     213/*}}}*/
     214/*FUNCTION Vector::IsEmpty{{{1*/
     215bool Vector::IsEmpty(void){
     216
     217        int M;
     218        this->GetSize(&M);
     219
     220        if(M==0)
     221         return true;
     222        else
     223         return false;
    220224}
    221225/*}}}*/
     
    224228               
    225229        #ifdef _HAVE_PETSC_
    226                 if(!this->vector)*pM=0;
    227                 else VecGetLocalSize(this->vector,pM);
     230                _assert_(this->vector);
     231                VecGetLocalSize(this->vector,pM);
    228232        #else
    229233                this->vector->GetLocalSize(pM);
     
    236240       
    237241        Vector* output=NULL;
    238         output=new Vector();
    239         #ifdef _HAVE_PETSC_
     242        #ifdef _HAVE_PETSC_
     243                _assert_(this->vector);
    240244                Vec vec_output=NULL;
    241                 if(!this->vector){
    242                         VecDuplicate(this->vector,&vec_output);
    243                         output->vector=vec_output;
    244                 }
    245         #else
     245                VecDuplicate(this->vector,&vec_output);
     246                output=new Vector(vec_output);
     247        #else
     248                output=new Vector();
    246249                output->vector=this->vector->Duplicate();
    247250        #endif
  • issm/trunk-jpl/src/c/objects/Numerics/Vector.h

    r11734 r11743  
    11/*!\file:  Vector.h
    2  * \brief wrapper to vector objects. The goal is to control which API (PETSC,Scalpack, Plapack?)
     2 * \brief wrapper to vector objects. The goal is to control which API (PETSc,Scalpack, Plapack?)
    33 * implements our underlying vector format.
    44 */
     
    3232       
    3333                #ifdef _HAVE_PETSC_
    34                 Vec vector;
     34                        Vec vector;
    3535                #else
    36                 SeqVec* vector;
     36                        SeqVec* vector;
    3737                #endif
    3838                #ifdef _HAVE_ADOLC_
    39                 adouble* avector;
     39                        adouble* avector;
    4040                #endif
    4141
     
    5454                mxArray* ToMatlabVector(void);
    5555                #endif
    56                 void Assemble(void);
    57                 void SetValues(int ssize, int* list, double* values, InsMode mode);
    58                 void SetValue(int dof, double value, InsMode  mode);
    59                 void GetValue(double* pvalue, int dof);
    60                 void GetSize(int* pM);
    61                 void GetLocalSize(int* pM);
    62                 Vector* Duplicate(void);
    63                 void Set(double value);
    64                 void AXPY(Vector* X, double a);
    65                 void AYPX(Vector* X, double a);
    66                 double* ToMPISerial(void);
    67                 void Copy(Vector* to);
    68                 double Norm(NormMode norm_type);
    69                 void Scale(double scale_factor);
    70                 void PointwiseDivide(Vector* x,Vector* y);
    71                 double Dot(Vector* vector);
     56                void    AXPY(Vector *X, double a);
     57                void    AYPX(Vector *X, double a);
     58                void    Assemble(void);
     59                void    Copy(Vector *to);
     60                double  Dot(Vector *vector);
     61                Vector *Duplicate(void);
     62                void    GetValue(double *pvalue, int dof);
     63                void    GetSize(int *pM);
     64                void    GetLocalSize(int *pM);
     65                bool    IsEmpty(void);
     66                double  Norm(NormMode norm_type);
     67                void    PointwiseDivide(Vector  *x,Vector*y);
     68                void    Scale(double scale_factor);
     69                void    Set(double value);
     70                void    SetValues(int ssize, int *list, double*values, InsMode mode);
     71                void    SetValue(int dof, double value, InsMode mode);
     72                double *ToMPISerial(void);
    7273                /*}}}*/
    7374};
  • issm/trunk-jpl/src/c/toolkits/petsc/patches/MatlabMatrixToPetscMatrix.cpp

    r9320 r11743  
    116116        /*Assign output pointer: */
    117117        *pmatrix=matrix;
    118         *pmatrix_rows=rows;
    119         *pmatrix_cols=cols;
     118        if(pmatrix_rows) *pmatrix_rows=rows;
     119        if(pmatrix_cols) *pmatrix_cols=cols;
    120120
    121121        return 1;
  • issm/trunk-jpl/src/c/toolkits/petsc/patches/MatlabVectorToPetscVector.cpp

    r9320 r11743  
    9494        VecAssemblyEnd(vector);
    9595
    96 
    9796        /*Assign output pointer: */
    9897        *pvector=vector;
Note: See TracChangeset for help on using the changeset viewer.