Changeset 13880


Ignore:
Timestamp:
11/05/12 15:35:08 (12 years ago)
Author:
Mathieu Morlighem
Message:

NEW: added new constructors for matrix and vector, with local and global sizes that are provided

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

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/matrix/Matrix.h

    r13869 r13880  
    7676                }
    7777                /*}}}*/
     78                /*FUNCTION Matrix(int m,int n,int M,int N,int* d_nnz,int* o_nnz,int type){{{*/
     79                #ifdef _HAVE_PETSC_
     80                Matrix(int m,int n,int M,int N,int* d_nnz,int* o_nnz,int in_type=PetscMatType){
     81                #else
     82                Matrix(int m,int n,int M,int N,int* d_nnz,int* o_nnz,int in_type=SeqMatType){
     83                #endif
     84
     85                        #ifdef _HAVE_PETSC_
     86                        pmatrix=NULL;
     87                        #endif
     88                        smatrix=NULL;
     89                        type=in_type;
     90
     91                        if(type==PetscMatType){
     92                                #ifdef _HAVE_PETSC_
     93                                this->pmatrix=new PetscMat(m,n,M,N,d_nnz,o_nnz);
     94                                #else
     95                                _error_("Petsc matrix format not usable, as Petsc has not been compiled!");
     96                                #endif
     97                        }
     98                        else if(type==SeqMatType){
     99                                this->smatrix=new SeqMat<doubletype>(m,n,M,N,d_nnz,o_nnz);
     100                        }
     101                        else _error_("Matrix type: " << type << " not supported yet!");
     102
     103                }
     104                /*}}}*/
    78105                /*FUNCTION Matrix(int M,int N,IssmDouble sparsity,int in_type){{{*/
    79106                #ifdef _HAVE_PETSC_
  • issm/trunk-jpl/src/c/classes/matrix/Vector.h

    r13801 r13880  
    7575                }
    7676                /*}}}*/
     77                /*FUNCTION Vector(int m,int M,int in_type){{{*/
     78                #ifdef _HAVE_PETSC_
     79                Vector(int m,int M,int in_type=PetscVecType){
     80                #else
     81                Vector(int m,int M,int in_type=SeqVecType){
     82                #endif
     83
     84                        #ifdef _HAVE_PETSC_
     85                        pvector=NULL;
     86                        #endif
     87                        svector=NULL;
     88                        type=in_type;
     89
     90                        if(type==PetscVecType){
     91                        #ifdef _HAVE_PETSC_
     92                                this->pvector=new PetscVec(m,M);
     93                         #else
     94                                _error_("Petsc matrix format not usable, as Petsc has not been compiled!");
     95                         #endif
     96                        }
     97                        else if(type==SeqVecType){
     98                                this->svector=new SeqVec<doubletype>(m,M);
     99                        }
     100                        else _error_("Vector type: " << type << " not supported yet!");
     101
     102                }
     103                /*}}}*/
    77104                /*FUNCTION Vector(doubletype* serial_vec,int M,int in_type){{{*/
    78105                #ifdef _HAVE_PETSC_
  • issm/trunk-jpl/src/c/toolkits/issm/SeqMat.h

    r13760 r13880  
    5959                        this->matrix=NULL;
    6060                        if(M*N) this->matrix=xNewZeroInit<doubletype>(pM*pN);
     61                }
     62                /*}}}*/
     63                /*FUNCTION SeqMat(int m,int n,int M,int N,int* d_nnz,int* o_nnz){{{*/
     64                SeqMat(int m,int n,int pM,int pN,int* d_nnz,int* o_nnz){
     65
     66                        this->M=pM;
     67                        this->N=pN;
     68                        this->matrix=NULL;
     69                        if(pM*pN) this->matrix=xNewZeroInit<doubletype>(pM*pN);
    6170                }
    6271                /*}}}*/
  • issm/trunk-jpl/src/c/toolkits/issm/SeqVec.h

    r13780 r13880  
    4949                }
    5050                /*}}}*/
     51                /*FUNCTION SeqVec(int m,int M){{{*/
     52                SeqVec(int pm,int pM){
     53
     54                        this->M=pM;
     55                        this->vector=NULL;
     56                        if(this->M) this->vector=xNewZeroInit<doubletype>(pM);
     57                }
     58                /*}}}*/
    5159                /*FUNCTION SeqVec(int M,bool fromlocalsize){{{*/
    5260                SeqVec(int pM,bool fromlocalsize){
  • issm/trunk-jpl/src/c/toolkits/petsc/objects/PetscMat.cpp

    r13869 r13880  
    3838
    3939        this->matrix=NewMat(M,N,sparsity,IssmComm::GetComm());
     40}
     41/*}}}*/
     42/*FUNCTION PetscMat::PetscMat(int M,int N, IssmDouble sparsity){{{*/
     43PetscMat::PetscMat(int m,int n,int M,int N,int* d_nnz,int* o_nnz){
     44
     45        MatCreate(IssmComm::GetComm(),&this->matrix);
     46        MatSetSizes(this->matrix,m,n,M,N);
     47        MatSetFromOptions(this->matrix);
     48        MatMPIAIJSetPreallocation(this->matrix,0,d_nnz,0,o_nnz);
     49
    4050}
    4151/*}}}*/
  • issm/trunk-jpl/src/c/toolkits/petsc/objects/PetscMat.h

    r13869 r13880  
    3131                #endif
    3232
    33                 /*PetscMat constructors, destructors {{{*/
     33                /*PetscMat constructors, destructors*/
    3434                PetscMat();
    3535                PetscMat(int M,int N);
    3636                PetscMat(int M,int N,IssmDouble sparsity);
     37                PetscMat(int m,int n,int M,int N,int* d_nnz,int* o_nnz);
    3738                PetscMat(IssmDouble* serial_mat,int M,int N,IssmDouble sparsity);
    3839                PetscMat(int M,int N,int connectivity,int numberofdofspernode);
    3940                ~PetscMat();
    40                 /*}}}*/
    41                 /*PetscMat specific routines {{{*/
     41
     42                /*PetscMat specific routines*/
    4243                void AllocationInfo(void);
    4344                void Echo(void);
     
    5152                void SetValues(int m,int* idxm,int n,int* idxn,IssmDouble* values,InsMode mode);
    5253                void Convert(MatrixType type);
    53                 /*}}}*/
    54 
    5554};
    5655
  • issm/trunk-jpl/src/c/toolkits/petsc/objects/PetscVec.cpp

    r13784 r13880  
    3131
    3232        this->vector=NewVec(M,IssmComm::GetComm(),fromlocalsize);
     33
     34}
     35/*}}}*/
     36/*FUNCTION PetscVec::PetscVec(int m,int M){{{*/
     37PetscVec::PetscVec(int m,int M){
     38
     39        VecCreate(IssmComm::GetComm(),&this->vector);
     40        VecSetSizes(this->vector,m,M);
     41        VecSetFromOptions(this->vector);
     42        VecSet(this->vector,0.0);
    3343
    3444}
  • issm/trunk-jpl/src/c/toolkits/petsc/objects/PetscVec.h

    r13623 r13880  
    3030                #endif
    3131
    32                 /*PetscVec constructors, destructors {{{*/
     32                /*PetscVec constructors, destructors*/
    3333                PetscVec();
    3434                PetscVec(int M,bool fromlocalsize=false);
     35                PetscVec(int m,int M);
    3536                PetscVec(IssmDouble* buffer, int M);
    3637                PetscVec(Vec petsc_vec);
    3738                ~PetscVec();
    38                 /*}}}*/
    39                 /*PetscVec specific routines {{{*/
     39
     40                /*PetscVec specific routines*/
    4041                void Echo(void);
    4142                void Assemble(void);
     
    5556                void PointwiseDivide(PetscVec* x,PetscVec* y);
    5657                IssmDouble Dot(PetscVec* vector);
    57                 /*}}}*/
    5858};
    5959
Note: See TracChangeset for help on using the changeset viewer.