xref: /petsc/include/petscvec.h (revision cb5b572f1baa3b8b5e068cd6368cddce5382cbb3)
1*cb5b572fSBarry Smith /* $Id: vec.h,v 1.77 1998/07/22 15:25:57 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 
888d459dfSBarry Smith #ifndef __VEC_H
988d459dfSBarry Smith #define __VEC_H
102eac72dbSBarry Smith #include "is.h"
11bf5bf444SLois Curfman McInnes #include "sys.h"
122eac72dbSBarry Smith 
139e25ed09SBarry Smith #define VEC_COOKIE         PETSC_COOKIE+3
1494d884c6SBarry 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 
1994d884c6SBarry 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*);
2494d884c6SBarry 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 VecCreateShared(MPI_Comm,int,int,Vec*);
2988d459dfSBarry Smith extern int VecCreate(MPI_Comm,int,int,Vec*);
3088d459dfSBarry Smith extern int VecCreateWithType(MPI_Comm,char *,int,int,Vec*);
312eac72dbSBarry Smith 
324b0e389bSBarry Smith extern int VecDestroy(Vec);
334b0e389bSBarry Smith 
3494d884c6SBarry Smith extern int MapDestroy(Map);
3594d884c6SBarry Smith extern int MapGetLocalSize(Map,int *);
3694d884c6SBarry Smith extern int MapGetGlobalSize(Map,int *);
3794d884c6SBarry Smith extern int MapGetLocalRange(Map,int *,int *);
3894d884c6SBarry Smith extern int MapGetGlobalRange(Map,int **);
3994d884c6SBarry Smith 
408ed539a5SBarry Smith extern int VecDot(Vec,Vec,Scalar*);
418ed539a5SBarry Smith extern int VecTDot(Vec,Vec,Scalar*);
428ed539a5SBarry Smith extern int VecMDot(int,Vec,Vec*,Scalar*);
438ed539a5SBarry Smith extern int VecMTDot(int,Vec,Vec*,Scalar*);
44cddf8d76SBarry Smith 
4593c39befSBarry Smith typedef enum {NORM_1=1,NORM_2=2,NORM_FROBENIUS=3,NORM_INFINITY=4,NORM_1_AND_2=5} NormType;
46cddf8d76SBarry Smith #define NORM_MAX NORM_INFINITY
47cddf8d76SBarry Smith extern int VecNorm(Vec,NormType,double *);
48ee50ffe9SBarry Smith extern int VecSum(Vec,Scalar*);
497c16e1c9SBarry Smith extern int VecMax(Vec,int*,double*);
507c16e1c9SBarry Smith extern int VecMin(Vec,int*,double*);
518ed539a5SBarry Smith extern int VecScale(Scalar*,Vec);
528ed539a5SBarry Smith extern int VecCopy(Vec,Vec);
5377c4ece6SBarry Smith extern int VecSetRandom(PetscRandom,Vec);
548ed539a5SBarry Smith extern int VecSet(Scalar*,Vec);
558ed539a5SBarry Smith extern int VecSwap(Vec,Vec);
568ed539a5SBarry Smith extern int VecAXPY(Scalar*,Vec,Vec);
5777c4ece6SBarry Smith extern int VecAXPBY(Scalar*,Scalar *,Vec,Vec);
588ed539a5SBarry Smith extern int VecMAXPY(int,Scalar*,Vec,Vec*);
598ed539a5SBarry Smith extern int VecAYPX(Scalar*,Vec,Vec);
608ed539a5SBarry Smith extern int VecWAXPY(Scalar*,Vec,Vec,Vec);
6177c4ece6SBarry Smith extern int VecPointwiseMult(Vec,Vec,Vec);
6277c4ece6SBarry Smith extern int VecPointwiseDivide(Vec,Vec,Vec);
634b0e389bSBarry Smith extern int VecShift(Scalar*,Vec);
644b0e389bSBarry Smith extern int VecReciprocal(Vec);
654b0e389bSBarry Smith extern int VecAbs(Vec);
666469c4f9SBarry Smith extern int VecDuplicate(Vec,Vec*);
67afc8d9b6SBarry Smith extern int VecDuplicateVecs(Vec,int,Vec**);
684b0e389bSBarry Smith extern int VecDestroyVecs(Vec*,int);
6994d884c6SBarry Smith extern int VecGetMap(Vec,Map*);
702eac72dbSBarry Smith 
7196a927feSBarry Smith typedef enum {NOT_SET_VALUES, INSERT_VALUES, ADD_VALUES, MAX_VALUES} InsertMode;
72d2655a18SBarry Smith extern int VecStrideNorm(Vec,int,NormType,double*);
73731415e4SBarry Smith extern int VecStrideGather(Vec,int,Vec,InsertMode);
74731415e4SBarry Smith extern int VecStrideScatter(Vec,int,Vec,InsertMode);
75d2655a18SBarry Smith 
7620563c6bSBarry Smith extern int VecSetValues(Vec,int,int*,Scalar*,InsertMode);
77ee50ffe9SBarry Smith extern int VecAssemblyBegin(Vec);
78ee50ffe9SBarry Smith extern int VecAssemblyEnd(Vec);
79b951964fSBarry Smith #define VecSetValue(v,i,va,mode) \
80b951964fSBarry Smith {int _ierr,_row = i; Scalar _va = va; \
81b951964fSBarry Smith   _ierr = VecSetValues(v,1,&_row,&_va,mode);CHKERRQ(_ierr); \
82b951964fSBarry Smith }
8335c17c5bSBarry Smith extern int VecSetBlockSize(Vec,int);
8435c17c5bSBarry Smith extern int VecSetValuesBlocked(Vec,int,int*,Scalar*,InsertMode);
858ed539a5SBarry Smith 
8688d459dfSBarry Smith extern int VecRegisterAllCalled;
8788d459dfSBarry Smith extern int VecRegisterAll(char *);
8888d459dfSBarry Smith extern int VecRegister_Private(char*,char*,char*,int(*)(MPI_Comm,int,int,Vec*));
8988d459dfSBarry Smith #if defined(USE_DYNAMIC_LIBRARIES)
9088d459dfSBarry Smith #define VecRegister(a,b,c,d) VecRegister_Private(a,b,c,0)
9188d459dfSBarry Smith #else
9288d459dfSBarry Smith #define VecRegister(a,b,c,d) VecRegister_Private(a,b,c,d)
9388d459dfSBarry Smith #endif
9488d459dfSBarry Smith 
95d252947aSBarry Smith typedef enum {SCATTER_FORWARD=0,SCATTER_REVERSE=1,SCATTER_FORWARD_LOCAL=2,
96d252947aSBarry Smith               SCATTER_REVERSE_LOCAL=3,SCATTER_LOCAL=2} ScatterMode;
9784cb2905SBarry Smith extern int VecScatterCreate(Vec,IS,Vec,IS,VecScatter *);
9890f02eecSBarry Smith extern int VecScatterPostRecvs(Vec,Vec,InsertMode,ScatterMode,VecScatter);
9908480c60SBarry Smith extern int VecScatterBegin(Vec,Vec,InsertMode,ScatterMode,VecScatter);
10008480c60SBarry Smith extern int VecScatterEnd(Vec,Vec,InsertMode,ScatterMode,VecScatter);
10108480c60SBarry Smith extern int VecScatterDestroy(VecScatter);
10208480c60SBarry Smith extern int VecScatterCopy(VecScatter,VecScatter *);
10308480c60SBarry Smith extern int VecScatterView(VecScatter,Viewer);
1042195c698SBarry Smith extern int VecScatterRemap(VecScatter,int *,int*);
1052195c698SBarry Smith 
106*cb5b572fSBarry Smith typedef enum {PIPELINE_DOWN=0,PIPELINE_UP=1} PipelineDirection;
107*cb5b572fSBarry Smith typedef enum {PIPELINE_NONE=1, PIPELINE_SEQUENTIAL=2,
108*cb5b572fSBarry Smith 	      PIPELINE_REDBLACK=3, PIPELINE_MULTICOLOUR=4} PipelineType;
109*cb5b572fSBarry Smith 
110*cb5b572fSBarry Smith typedef struct _p_VecPipeline*  VecPipeline;
111*cb5b572fSBarry Smith 
112*cb5b572fSBarry Smith extern int VecPipelineCreate(MPI_Comm comm,Vec xin,IS ix,Vec yin,IS iy,VecPipeline *newctx);
113*cb5b572fSBarry Smith extern int VecPipelineSetType(VecPipeline ctx,PipelineType typ,PetscObject x);
114*cb5b572fSBarry Smith extern int VecPipelineSetup(VecPipeline ctx);
115*cb5b572fSBarry Smith extern int VecPipelineBegin(Vec,Vec,InsertMode,ScatterMode,PipelineDirection,VecPipeline);
116*cb5b572fSBarry Smith extern int VecPipelineEnd(Vec,Vec,InsertMode,ScatterMode,PipelineDirection,VecPipeline);
117*cb5b572fSBarry Smith extern int VecPipelineView(VecPipeline pipe,Viewer viewer);
118*cb5b572fSBarry Smith extern int VecPipelineDestroy(VecPipeline ctx);
119*cb5b572fSBarry Smith 
1208ed539a5SBarry Smith extern int VecGetArray(Vec,Scalar**);
1216b5873e3SBarry Smith extern int VecRestoreArray(Vec,Scalar**);
122afc8d9b6SBarry Smith extern int VecPlaceArray(Vec,Scalar*);
123707f76d8SBarry Smith extern int VecGetArrays(Vec*,int,Scalar***);
124707f76d8SBarry Smith extern int VecRestoreArrays(Vec*,int,Scalar***);
12584cb2905SBarry Smith 
12677c4ece6SBarry Smith extern int VecValid(Vec,PetscTruth*);
1278ed539a5SBarry Smith extern int VecView(Vec,Viewer);
12813054869SSatish Balay extern int VecEqual(Vec,Vec,PetscTruth*);
12984cb2905SBarry Smith extern int VecLoad(Viewer,Vec*);
1308ed539a5SBarry Smith 
1318ed539a5SBarry Smith extern int VecGetSize(Vec,int*);
13288d459dfSBarry Smith extern int VecGetType(Vec,char**);
1338ed539a5SBarry Smith extern int VecGetLocalSize(Vec,int*);
134d6dfbf8fSBarry Smith extern int VecGetOwnershipRange(Vec,int*,int*);
1358ed539a5SBarry Smith 
136d4bb536fSBarry Smith extern int VecSetLocalToGlobalMapping(Vec, ISLocalToGlobalMapping);
13790f02eecSBarry Smith extern int VecSetValuesLocal(Vec,int,int*,Scalar*,InsertMode);
13835c17c5bSBarry Smith extern int VecSetLocalToGlobalMappingBlocked(Vec, ISLocalToGlobalMapping);
13935c17c5bSBarry Smith extern int VecSetValuesBlockedLocal(Vec,int,int*,Scalar*,InsertMode);
14090f02eecSBarry Smith 
141f830108cSBarry Smith typedef enum {VEC_IGNORE_OFF_PROC_ENTRIES} VecOption;
14290f02eecSBarry Smith extern int VecSetOption(Vec,VecOption);
14390f02eecSBarry Smith 
144522c5e43SBarry Smith extern int VecContourScale(Vec,double,double);
145522c5e43SBarry Smith 
146e182c471SBarry Smith /*
147e182c471SBarry Smith      Routines for dealing with ghosted vectors:
148e182c471SBarry Smith   vectors with ghost elements at the end of the array.
149e182c471SBarry Smith */
150e182c471SBarry Smith extern int VecCreateGhost(MPI_Comm,int,int,int,int*,Vec*);
151e182c471SBarry Smith extern int VecCreateGhostWithArray(MPI_Comm,int,int,int,int*,Scalar*,Vec*);
152d2655a18SBarry Smith extern int VecGhostGetLocalForm(Vec,Vec*);
153d2655a18SBarry Smith extern int VecGhostRestoreLocalForm(Vec,Vec*);
154e182c471SBarry Smith extern int VecGhostUpdateBegin(Vec,InsertMode,ScatterMode);
155e182c471SBarry Smith extern int VecGhostUpdateEnd(Vec,InsertMode,ScatterMode);
156e182c471SBarry Smith 
157e182c471SBarry Smith 
1583369ce9aSBarry Smith extern int DrawTensorContour(Draw,int,int,double *,double *,Vec);
15934233285SBarry Smith 
1602eac72dbSBarry Smith #endif
1612eac72dbSBarry Smith 
1622eac72dbSBarry Smith 
1637588ac45SBarry Smith 
164