1*e1311b90SBarry Smith /* $Id: vec.h,v 1.70 1998/03/12 23:25:24 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 149e25ed09SBarry Smith #define VEC_SCATTER_COOKIE PETSC_COOKIE+4 159e25ed09SBarry Smith 16b56ba379SLois Curfman McInnes typedef enum {VECSAME=-1, VECSEQ, VECMPI} VecType; 17f0479e8cSBarry Smith 18f09e8eb9SSatish Balay typedef struct _p_Vec* Vec; 19f09e8eb9SSatish Balay typedef struct _p_VecScatter* VecScatter; 202eac72dbSBarry Smith 21de7da479SBarry Smith extern int VecCreateSeq(MPI_Comm,int,Vec*); 228ed539a5SBarry Smith extern int VecCreateMPI(MPI_Comm,int,int,Vec*); 233369ce9aSBarry Smith extern int VecCreateSeqWithArray(MPI_Comm,int,Scalar*,Vec*); 24e182c471SBarry Smith extern int VecCreateMPIWithArray(MPI_Comm,int,int,Scalar*,Vec*); 25522c5e43SBarry Smith extern int VecCreate(MPI_Comm,int,int,Vec*); 26522c5e43SBarry Smith extern int VecCreateShared(MPI_Comm,int,int,Vec*); 272eac72dbSBarry Smith 284b0e389bSBarry Smith extern int VecDestroy(Vec); 294b0e389bSBarry Smith 308ed539a5SBarry Smith extern int VecDot(Vec,Vec,Scalar*); 318ed539a5SBarry Smith extern int VecTDot(Vec,Vec,Scalar*); 328ed539a5SBarry Smith extern int VecMDot(int,Vec,Vec*,Scalar*); 338ed539a5SBarry Smith extern int VecMTDot(int,Vec,Vec*,Scalar*); 34cddf8d76SBarry Smith 3593c39befSBarry Smith typedef enum {NORM_1=1,NORM_2=2,NORM_FROBENIUS=3,NORM_INFINITY=4,NORM_1_AND_2=5} NormType; 36cddf8d76SBarry Smith #define NORM_MAX NORM_INFINITY 37cddf8d76SBarry Smith extern int VecNorm(Vec,NormType,double *); 38ee50ffe9SBarry Smith extern int VecSum(Vec,Scalar*); 397c16e1c9SBarry Smith extern int VecMax(Vec,int*,double*); 407c16e1c9SBarry Smith extern int VecMin(Vec,int*,double*); 418ed539a5SBarry Smith extern int VecScale(Scalar*,Vec); 428ed539a5SBarry Smith extern int VecCopy(Vec,Vec); 4377c4ece6SBarry Smith extern int VecSetRandom(PetscRandom,Vec); 448ed539a5SBarry Smith extern int VecSet(Scalar*,Vec); 458ed539a5SBarry Smith extern int VecSwap(Vec,Vec); 468ed539a5SBarry Smith extern int VecAXPY(Scalar*,Vec,Vec); 4777c4ece6SBarry Smith extern int VecAXPBY(Scalar*,Scalar *,Vec,Vec); 488ed539a5SBarry Smith extern int VecMAXPY(int,Scalar*,Vec,Vec*); 498ed539a5SBarry Smith extern int VecAYPX(Scalar*,Vec,Vec); 508ed539a5SBarry Smith extern int VecWAXPY(Scalar*,Vec,Vec,Vec); 5177c4ece6SBarry Smith extern int VecPointwiseMult(Vec,Vec,Vec); 5277c4ece6SBarry Smith extern int VecPointwiseDivide(Vec,Vec,Vec); 534b0e389bSBarry Smith extern int VecShift(Scalar*,Vec); 544b0e389bSBarry Smith extern int VecReciprocal(Vec); 554b0e389bSBarry Smith extern int VecAbs(Vec); 566469c4f9SBarry Smith extern int VecDuplicate(Vec,Vec*); 57afc8d9b6SBarry Smith extern int VecDuplicateVecs(Vec,int,Vec**); 584b0e389bSBarry Smith extern int VecDestroyVecs(Vec*,int); 592eac72dbSBarry Smith 60*e1311b90SBarry Smith typedef enum {NOT_SET_VALUES, INSERT_VALUES, ADD_VALUES, MAX_VALUES} InsertMode; 6120563c6bSBarry Smith extern int VecSetValues(Vec,int,int*,Scalar*,InsertMode); 62ee50ffe9SBarry Smith extern int VecAssemblyBegin(Vec); 63ee50ffe9SBarry Smith extern int VecAssemblyEnd(Vec); 64b951964fSBarry Smith #define VecSetValue(v,i,va,mode) \ 65b951964fSBarry Smith {int _ierr,_row = i; Scalar _va = va; \ 66b951964fSBarry Smith _ierr = VecSetValues(v,1,&_row,&_va,mode);CHKERRQ(_ierr); \ 67b951964fSBarry Smith } 6835c17c5bSBarry Smith extern int VecSetBlockSize(Vec,int); 6935c17c5bSBarry Smith extern int VecSetValuesBlocked(Vec,int,int*,Scalar*,InsertMode); 708ed539a5SBarry Smith 71d252947aSBarry Smith typedef enum {SCATTER_FORWARD=0,SCATTER_REVERSE=1,SCATTER_FORWARD_LOCAL=2, 72d252947aSBarry Smith SCATTER_REVERSE_LOCAL=3,SCATTER_LOCAL=2} ScatterMode; 7384cb2905SBarry Smith extern int VecScatterCreate(Vec,IS,Vec,IS,VecScatter *); 7490f02eecSBarry Smith extern int VecScatterPostRecvs(Vec,Vec,InsertMode,ScatterMode,VecScatter); 7508480c60SBarry Smith extern int VecScatterBegin(Vec,Vec,InsertMode,ScatterMode,VecScatter); 7608480c60SBarry Smith extern int VecScatterEnd(Vec,Vec,InsertMode,ScatterMode,VecScatter); 7708480c60SBarry Smith extern int VecScatterDestroy(VecScatter); 7808480c60SBarry Smith extern int VecScatterCopy(VecScatter,VecScatter *); 7908480c60SBarry Smith extern int VecScatterView(VecScatter,Viewer); 802195c698SBarry Smith extern int VecScatterRemap(VecScatter,int *,int*); 812195c698SBarry Smith 828ed539a5SBarry Smith extern int VecGetArray(Vec,Scalar**); 836b5873e3SBarry Smith extern int VecRestoreArray(Vec,Scalar**); 84afc8d9b6SBarry Smith extern int VecPlaceArray(Vec,Scalar*); 85707f76d8SBarry Smith extern int VecGetArrays(Vec*,int,Scalar***); 86707f76d8SBarry Smith extern int VecRestoreArrays(Vec*,int,Scalar***); 8784cb2905SBarry Smith 8877c4ece6SBarry Smith extern int VecValid(Vec,PetscTruth*); 898ed539a5SBarry Smith extern int VecView(Vec,Viewer); 9013054869SSatish Balay extern int VecEqual(Vec,Vec,PetscTruth*); 9184cb2905SBarry Smith extern int VecLoad(Viewer,Vec*); 928ed539a5SBarry Smith 938ed539a5SBarry Smith extern int VecGetSize(Vec,int*); 941dd0cb96SLois Curfman McInnes extern int VecGetType(Vec,VecType*,char**); 958ed539a5SBarry Smith extern int VecGetLocalSize(Vec,int*); 96d6dfbf8fSBarry Smith extern int VecGetOwnershipRange(Vec,int*,int*); 978ed539a5SBarry Smith 98d4bb536fSBarry Smith extern int VecSetLocalToGlobalMapping(Vec, ISLocalToGlobalMapping); 9990f02eecSBarry Smith extern int VecSetValuesLocal(Vec,int,int*,Scalar*,InsertMode); 10035c17c5bSBarry Smith extern int VecSetLocalToGlobalMappingBlocked(Vec, ISLocalToGlobalMapping); 10135c17c5bSBarry Smith extern int VecSetValuesBlockedLocal(Vec,int,int*,Scalar*,InsertMode); 10290f02eecSBarry Smith 103f830108cSBarry Smith typedef enum {VEC_IGNORE_OFF_PROC_ENTRIES} VecOption; 10490f02eecSBarry Smith extern int VecSetOption(Vec,VecOption); 10590f02eecSBarry Smith 106522c5e43SBarry Smith extern int VecContourScale(Vec,double,double); 107522c5e43SBarry Smith 108e182c471SBarry Smith /* 109e182c471SBarry Smith Routines for dealing with ghosted vectors: 110e182c471SBarry Smith vectors with ghost elements at the end of the array. 111e182c471SBarry Smith */ 112e182c471SBarry Smith extern int VecCreateGhost(MPI_Comm,int,int,int,int*,Vec*); 113e182c471SBarry Smith extern int VecCreateGhostWithArray(MPI_Comm,int,int,int,int*,Scalar*,Vec*); 114e182c471SBarry Smith extern int VecGhostGetLocalRepresentation(Vec,Vec*); 115e182c471SBarry Smith extern int VecGhostRestoreLocalRepresentation(Vec,Vec*); 116e182c471SBarry Smith extern int VecGhostUpdateBegin(Vec,InsertMode,ScatterMode); 117e182c471SBarry Smith extern int VecGhostUpdateEnd(Vec,InsertMode,ScatterMode); 118e182c471SBarry Smith 119e182c471SBarry Smith 1203369ce9aSBarry Smith extern int DrawTensorContour(Draw,int,int,double *,double *,Vec); 12134233285SBarry Smith 1222eac72dbSBarry Smith #endif 1232eac72dbSBarry Smith 1242eac72dbSBarry Smith 1257588ac45SBarry Smith 126