1*94d884c6SBarry Smith /* $Id: vec.h,v 1.71 1998/04/03 23:19:27 bsmith Exp bsmith $ */ 22eac72dbSBarry Smith /* 337f753daSBarry Smith Defines the vector component of PETSc. Vectors generally represent 437f753daSBarry Smith degrees of freedom for finite element/finite difference functions 584cb2905SBarry Smith on a grid. They have more mathematical structure then simple arrays. 62eac72dbSBarry Smith */ 72eac72dbSBarry Smith 82eac72dbSBarry Smith #ifndef __VEC_PACKAGE 92eac72dbSBarry Smith #define __VEC_PACKAGE 102eac72dbSBarry Smith #include "is.h" 11bf5bf444SLois Curfman McInnes #include "sys.h" 122eac72dbSBarry Smith 139e25ed09SBarry Smith #define VEC_COOKIE PETSC_COOKIE+3 14*94d884c6SBarry Smith #define MAP_COOKIE PETSC_COOKIE+22 159e25ed09SBarry Smith #define VEC_SCATTER_COOKIE PETSC_COOKIE+4 169e25ed09SBarry Smith 17b56ba379SLois Curfman McInnes typedef enum {VECSAME=-1, VECSEQ, VECMPI} VecType; 18f0479e8cSBarry Smith 19*94d884c6SBarry Smith typedef struct _p_Map* Map; 20f09e8eb9SSatish Balay typedef struct _p_Vec* Vec; 21f09e8eb9SSatish Balay typedef struct _p_VecScatter* VecScatter; 222eac72dbSBarry Smith 23de7da479SBarry Smith extern int VecCreateSeq(MPI_Comm,int,Vec*); 24*94d884c6SBarry Smith extern int MapCreateMPI(MPI_Comm,int,int,Map*); 258ed539a5SBarry Smith extern int VecCreateMPI(MPI_Comm,int,int,Vec*); 263369ce9aSBarry Smith extern int VecCreateSeqWithArray(MPI_Comm,int,Scalar*,Vec*); 27e182c471SBarry Smith extern int VecCreateMPIWithArray(MPI_Comm,int,int,Scalar*,Vec*); 28522c5e43SBarry Smith extern int VecCreate(MPI_Comm,int,int,Vec*); 29522c5e43SBarry Smith extern int VecCreateShared(MPI_Comm,int,int,Vec*); 302eac72dbSBarry Smith 314b0e389bSBarry Smith extern int VecDestroy(Vec); 324b0e389bSBarry Smith 33*94d884c6SBarry Smith extern int MapDestroy(Map); 34*94d884c6SBarry Smith extern int MapGetLocalSize(Map,int *); 35*94d884c6SBarry Smith extern int MapGetGlobalSize(Map,int *); 36*94d884c6SBarry Smith extern int MapGetLocalRange(Map,int *,int *); 37*94d884c6SBarry Smith extern int MapGetGlobalRange(Map,int **); 38*94d884c6SBarry Smith 398ed539a5SBarry Smith extern int VecDot(Vec,Vec,Scalar*); 408ed539a5SBarry Smith extern int VecTDot(Vec,Vec,Scalar*); 418ed539a5SBarry Smith extern int VecMDot(int,Vec,Vec*,Scalar*); 428ed539a5SBarry Smith extern int VecMTDot(int,Vec,Vec*,Scalar*); 43cddf8d76SBarry Smith 4493c39befSBarry Smith typedef enum {NORM_1=1,NORM_2=2,NORM_FROBENIUS=3,NORM_INFINITY=4,NORM_1_AND_2=5} NormType; 45cddf8d76SBarry Smith #define NORM_MAX NORM_INFINITY 46cddf8d76SBarry Smith extern int VecNorm(Vec,NormType,double *); 47ee50ffe9SBarry Smith extern int VecSum(Vec,Scalar*); 487c16e1c9SBarry Smith extern int VecMax(Vec,int*,double*); 497c16e1c9SBarry Smith extern int VecMin(Vec,int*,double*); 508ed539a5SBarry Smith extern int VecScale(Scalar*,Vec); 518ed539a5SBarry Smith extern int VecCopy(Vec,Vec); 5277c4ece6SBarry Smith extern int VecSetRandom(PetscRandom,Vec); 538ed539a5SBarry Smith extern int VecSet(Scalar*,Vec); 548ed539a5SBarry Smith extern int VecSwap(Vec,Vec); 558ed539a5SBarry Smith extern int VecAXPY(Scalar*,Vec,Vec); 5677c4ece6SBarry Smith extern int VecAXPBY(Scalar*,Scalar *,Vec,Vec); 578ed539a5SBarry Smith extern int VecMAXPY(int,Scalar*,Vec,Vec*); 588ed539a5SBarry Smith extern int VecAYPX(Scalar*,Vec,Vec); 598ed539a5SBarry Smith extern int VecWAXPY(Scalar*,Vec,Vec,Vec); 6077c4ece6SBarry Smith extern int VecPointwiseMult(Vec,Vec,Vec); 6177c4ece6SBarry Smith extern int VecPointwiseDivide(Vec,Vec,Vec); 624b0e389bSBarry Smith extern int VecShift(Scalar*,Vec); 634b0e389bSBarry Smith extern int VecReciprocal(Vec); 644b0e389bSBarry Smith extern int VecAbs(Vec); 656469c4f9SBarry Smith extern int VecDuplicate(Vec,Vec*); 66afc8d9b6SBarry Smith extern int VecDuplicateVecs(Vec,int,Vec**); 674b0e389bSBarry Smith extern int VecDestroyVecs(Vec*,int); 68*94d884c6SBarry Smith extern int VecGetMap(Vec,Map*); 692eac72dbSBarry Smith 70e1311b90SBarry Smith typedef enum {NOT_SET_VALUES, INSERT_VALUES, ADD_VALUES, MAX_VALUES} InsertMode; 7120563c6bSBarry Smith extern int VecSetValues(Vec,int,int*,Scalar*,InsertMode); 72ee50ffe9SBarry Smith extern int VecAssemblyBegin(Vec); 73ee50ffe9SBarry Smith extern int VecAssemblyEnd(Vec); 74b951964fSBarry Smith #define VecSetValue(v,i,va,mode) \ 75b951964fSBarry Smith {int _ierr,_row = i; Scalar _va = va; \ 76b951964fSBarry Smith _ierr = VecSetValues(v,1,&_row,&_va,mode);CHKERRQ(_ierr); \ 77b951964fSBarry Smith } 7835c17c5bSBarry Smith extern int VecSetBlockSize(Vec,int); 7935c17c5bSBarry Smith extern int VecSetValuesBlocked(Vec,int,int*,Scalar*,InsertMode); 808ed539a5SBarry Smith 81d252947aSBarry Smith typedef enum {SCATTER_FORWARD=0,SCATTER_REVERSE=1,SCATTER_FORWARD_LOCAL=2, 82d252947aSBarry Smith SCATTER_REVERSE_LOCAL=3,SCATTER_LOCAL=2} ScatterMode; 8384cb2905SBarry Smith extern int VecScatterCreate(Vec,IS,Vec,IS,VecScatter *); 8490f02eecSBarry Smith extern int VecScatterPostRecvs(Vec,Vec,InsertMode,ScatterMode,VecScatter); 8508480c60SBarry Smith extern int VecScatterBegin(Vec,Vec,InsertMode,ScatterMode,VecScatter); 8608480c60SBarry Smith extern int VecScatterEnd(Vec,Vec,InsertMode,ScatterMode,VecScatter); 8708480c60SBarry Smith extern int VecScatterDestroy(VecScatter); 8808480c60SBarry Smith extern int VecScatterCopy(VecScatter,VecScatter *); 8908480c60SBarry Smith extern int VecScatterView(VecScatter,Viewer); 902195c698SBarry Smith extern int VecScatterRemap(VecScatter,int *,int*); 912195c698SBarry Smith 928ed539a5SBarry Smith extern int VecGetArray(Vec,Scalar**); 936b5873e3SBarry Smith extern int VecRestoreArray(Vec,Scalar**); 94afc8d9b6SBarry Smith extern int VecPlaceArray(Vec,Scalar*); 95707f76d8SBarry Smith extern int VecGetArrays(Vec*,int,Scalar***); 96707f76d8SBarry Smith extern int VecRestoreArrays(Vec*,int,Scalar***); 9784cb2905SBarry Smith 9877c4ece6SBarry Smith extern int VecValid(Vec,PetscTruth*); 998ed539a5SBarry Smith extern int VecView(Vec,Viewer); 10013054869SSatish Balay extern int VecEqual(Vec,Vec,PetscTruth*); 10184cb2905SBarry Smith extern int VecLoad(Viewer,Vec*); 1028ed539a5SBarry Smith 1038ed539a5SBarry Smith extern int VecGetSize(Vec,int*); 1041dd0cb96SLois Curfman McInnes extern int VecGetType(Vec,VecType*,char**); 1058ed539a5SBarry Smith extern int VecGetLocalSize(Vec,int*); 106d6dfbf8fSBarry Smith extern int VecGetOwnershipRange(Vec,int*,int*); 1078ed539a5SBarry Smith 108d4bb536fSBarry Smith extern int VecSetLocalToGlobalMapping(Vec, ISLocalToGlobalMapping); 10990f02eecSBarry Smith extern int VecSetValuesLocal(Vec,int,int*,Scalar*,InsertMode); 11035c17c5bSBarry Smith extern int VecSetLocalToGlobalMappingBlocked(Vec, ISLocalToGlobalMapping); 11135c17c5bSBarry Smith extern int VecSetValuesBlockedLocal(Vec,int,int*,Scalar*,InsertMode); 11290f02eecSBarry Smith 113f830108cSBarry Smith typedef enum {VEC_IGNORE_OFF_PROC_ENTRIES} VecOption; 11490f02eecSBarry Smith extern int VecSetOption(Vec,VecOption); 11590f02eecSBarry Smith 116522c5e43SBarry Smith extern int VecContourScale(Vec,double,double); 117522c5e43SBarry Smith 118e182c471SBarry Smith /* 119e182c471SBarry Smith Routines for dealing with ghosted vectors: 120e182c471SBarry Smith vectors with ghost elements at the end of the array. 121e182c471SBarry Smith */ 122e182c471SBarry Smith extern int VecCreateGhost(MPI_Comm,int,int,int,int*,Vec*); 123e182c471SBarry Smith extern int VecCreateGhostWithArray(MPI_Comm,int,int,int,int*,Scalar*,Vec*); 124e182c471SBarry Smith extern int VecGhostGetLocalRepresentation(Vec,Vec*); 125e182c471SBarry Smith extern int VecGhostRestoreLocalRepresentation(Vec,Vec*); 126e182c471SBarry Smith extern int VecGhostUpdateBegin(Vec,InsertMode,ScatterMode); 127e182c471SBarry Smith extern int VecGhostUpdateEnd(Vec,InsertMode,ScatterMode); 128e182c471SBarry Smith 129e182c471SBarry Smith 1303369ce9aSBarry Smith extern int DrawTensorContour(Draw,int,int,double *,double *,Vec); 13134233285SBarry Smith 1322eac72dbSBarry Smith #endif 1332eac72dbSBarry Smith 1342eac72dbSBarry Smith 1357588ac45SBarry Smith 136