xref: /petsc/include/petscvec.h (revision 8ea6152f2c018360cbdec8a6cd457bc7e51b488e) !
1*8ea6152fSSatish Balay /* $Id: vec.h,v 1.92 1999/03/18 15:38:02 bsmith Exp balay $ */
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 
1794d884c6SBarry Smith typedef struct _p_Map*         Map;
18f09e8eb9SSatish Balay typedef struct _p_Vec*         Vec;
19f09e8eb9SSatish Balay typedef struct _p_VecScatter*  VecScatter;
203f1db9ecSBarry Smith #define VEC_SEQ    "seq"
213f1db9ecSBarry Smith #define VEC_MPI    "mpi"
223f1db9ecSBarry Smith #define VEC_SHARED "shared"
233f1db9ecSBarry Smith typedef char*                  VecType;
242eac72dbSBarry Smith 
25de7da479SBarry Smith extern int VecCreateSeq(MPI_Comm,int,Vec*);
2694d884c6SBarry Smith extern int MapCreateMPI(MPI_Comm,int,int,Map*);
278ed539a5SBarry Smith extern int VecCreateMPI(MPI_Comm,int,int,Vec*);
2862dc5420SSatish Balay extern int VecCreateSeqWithArray(MPI_Comm,int,const Scalar[],Vec*);
2962dc5420SSatish Balay extern int VecCreateMPIWithArray(MPI_Comm,int,int,const Scalar[],Vec*);
30522c5e43SBarry Smith extern int VecCreateShared(MPI_Comm,int,int,Vec*);
3188d459dfSBarry Smith extern int VecCreate(MPI_Comm,int,int,Vec*);
327b2a1423SBarry Smith extern int VecSetType(Vec,VecType);
337b2a1423SBarry Smith extern int VecSetFromOptions(Vec);
342eac72dbSBarry Smith 
354b0e389bSBarry Smith extern int VecDestroy(Vec);
364b0e389bSBarry Smith 
3794d884c6SBarry Smith extern int MapDestroy(Map);
3894d884c6SBarry Smith extern int MapGetLocalSize(Map,int *);
3983271157SBarry Smith extern int MapGetSize(Map,int *);
4094d884c6SBarry Smith extern int MapGetLocalRange(Map,int *,int *);
4162dc5420SSatish Balay extern int MapGetGlobalRange(Map,int *[]);
4294d884c6SBarry Smith 
438ed539a5SBarry Smith extern int VecDot(Vec,Vec,Scalar*);
448ed539a5SBarry Smith extern int VecTDot(Vec,Vec,Scalar*);
4562dc5420SSatish Balay extern int VecMDot(int,Vec,const Vec[],Scalar*);
4662dc5420SSatish Balay extern int VecMTDot(int,Vec,const Vec[],Scalar*);
47cddf8d76SBarry Smith 
4893c39befSBarry Smith typedef enum {NORM_1=1,NORM_2=2,NORM_FROBENIUS=3,NORM_INFINITY=4,NORM_1_AND_2=5} NormType;
49cddf8d76SBarry Smith #define NORM_MAX NORM_INFINITY
50cddf8d76SBarry Smith extern int VecNorm(Vec,NormType,double *);
51ee50ffe9SBarry Smith extern int VecSum(Vec,Scalar*);
527c16e1c9SBarry Smith extern int VecMax(Vec,int*,double*);
537c16e1c9SBarry Smith extern int VecMin(Vec,int*,double*);
5462dc5420SSatish Balay extern int VecScale(const Scalar*,Vec);
558ed539a5SBarry Smith extern int VecCopy(Vec,Vec);
5677c4ece6SBarry Smith extern int VecSetRandom(PetscRandom,Vec);
5762dc5420SSatish Balay extern int VecSet(const Scalar*,Vec);
588ed539a5SBarry Smith extern int VecSwap(Vec,Vec);
5962dc5420SSatish Balay extern int VecAXPY(const Scalar*,Vec,Vec);
6062dc5420SSatish Balay extern int VecAXPBY(const Scalar*,const Scalar *,Vec,Vec);
6162dc5420SSatish Balay extern int VecMAXPY(int,const Scalar*,Vec,Vec*);
6262dc5420SSatish Balay extern int VecAYPX(const Scalar*,Vec,Vec);
6362dc5420SSatish Balay extern int VecWAXPY(const Scalar*,Vec,Vec,Vec);
6477c4ece6SBarry Smith extern int VecPointwiseMult(Vec,Vec,Vec);
6577c4ece6SBarry Smith extern int VecPointwiseDivide(Vec,Vec,Vec);
6662dc5420SSatish Balay extern int VecShift(const Scalar*,Vec);
674b0e389bSBarry Smith extern int VecReciprocal(Vec);
684b0e389bSBarry Smith extern int VecAbs(Vec);
696469c4f9SBarry Smith extern int VecDuplicate(Vec,Vec*);
7062dc5420SSatish Balay extern int VecDuplicateVecs(Vec,int,Vec*[]);
7162dc5420SSatish Balay extern int VecDestroyVecs(const Vec[],int);
7294d884c6SBarry Smith extern int VecGetMap(Vec,Map*);
732eac72dbSBarry Smith 
7496a927feSBarry Smith typedef enum {NOT_SET_VALUES, INSERT_VALUES, ADD_VALUES, MAX_VALUES} InsertMode;
75d2655a18SBarry Smith extern int VecStrideNorm(Vec,int,NormType,double*);
76731415e4SBarry Smith extern int VecStrideGather(Vec,int,Vec,InsertMode);
77731415e4SBarry Smith extern int VecStrideScatter(Vec,int,Vec,InsertMode);
78f02e6ac2SBarry Smith extern int VecStrideMax(Vec,int,int *,double *);
79f02e6ac2SBarry Smith extern int VecStrideMin(Vec,int,int *,double *);
80d2655a18SBarry Smith 
8162dc5420SSatish Balay extern int VecSetValues(Vec,int,const int[],const Scalar[],InsertMode);
82ee50ffe9SBarry Smith extern int VecAssemblyBegin(Vec);
83ee50ffe9SBarry Smith extern int VecAssemblyEnd(Vec);
84649db694SBarry Smith extern int VecSetStashInitialSize(Vec,int, int);
8562dc5420SSatish Balay 
86b951964fSBarry Smith #define VecSetValue(v,i,va,mode) \
87b951964fSBarry Smith {int _ierr,_row = i; Scalar _va = va; \
88b951964fSBarry Smith   _ierr = VecSetValues(v,1,&_row,&_va,mode);CHKERRQ(_ierr); \
89b951964fSBarry Smith }
9035c17c5bSBarry Smith extern int VecSetBlockSize(Vec,int);
917ecc41b3SBarry Smith extern int VecGetBlockSize(Vec,int*);
9262dc5420SSatish Balay extern int VecSetValuesBlocked(Vec,int,const int[],const Scalar[],InsertMode);
938ed539a5SBarry Smith 
9488d459dfSBarry Smith extern int VecRegisterAllCalled;
9562dc5420SSatish Balay extern int VecRegisterAll(const char []);
9662dc5420SSatish Balay extern int VecRegister_Private(const char[],const char[],const char[],int(*)(Vec));
9788d459dfSBarry Smith #if defined(USE_DYNAMIC_LIBRARIES)
9888d459dfSBarry Smith #define VecRegister(a,b,c,d) VecRegister_Private(a,b,c,0)
9988d459dfSBarry Smith #else
10088d459dfSBarry Smith #define VecRegister(a,b,c,d) VecRegister_Private(a,b,c,d)
10188d459dfSBarry Smith #endif
10288d459dfSBarry Smith 
103d252947aSBarry Smith typedef enum {SCATTER_FORWARD=0,SCATTER_REVERSE=1,SCATTER_FORWARD_LOCAL=2,
104d252947aSBarry Smith               SCATTER_REVERSE_LOCAL=3,SCATTER_LOCAL=2} ScatterMode;
10584cb2905SBarry Smith extern int VecScatterCreate(Vec,IS,Vec,IS,VecScatter *);
10690f02eecSBarry Smith extern int VecScatterPostRecvs(Vec,Vec,InsertMode,ScatterMode,VecScatter);
10708480c60SBarry Smith extern int VecScatterBegin(Vec,Vec,InsertMode,ScatterMode,VecScatter);
10808480c60SBarry Smith extern int VecScatterEnd(Vec,Vec,InsertMode,ScatterMode,VecScatter);
10908480c60SBarry Smith extern int VecScatterDestroy(VecScatter);
11008480c60SBarry Smith extern int VecScatterCopy(VecScatter,VecScatter *);
11108480c60SBarry Smith extern int VecScatterView(VecScatter,Viewer);
1122195c698SBarry Smith extern int VecScatterRemap(VecScatter,int *,int*);
1132195c698SBarry Smith 
114cb5b572fSBarry Smith typedef enum {PIPELINE_DOWN=0,PIPELINE_UP=1} PipelineDirection;
115cb5b572fSBarry Smith typedef enum {PIPELINE_NONE=1, PIPELINE_SEQUENTIAL=2,
116*8ea6152fSSatish Balay 	      PIPELINE_REDBLACK=3, PIPELINE_MULTICOLOR=4} PipelineType;
117cb5b572fSBarry Smith 
118cb5b572fSBarry Smith typedef struct _p_VecPipeline*  VecPipeline;
119cb5b572fSBarry Smith 
120cb5b572fSBarry Smith extern int VecPipelineCreate(MPI_Comm comm,Vec xin,IS ix,Vec yin,IS iy,VecPipeline *newctx);
121cb5b572fSBarry Smith extern int VecPipelineSetType(VecPipeline ctx,PipelineType typ,PetscObject x);
122cb5b572fSBarry Smith extern int VecPipelineSetup(VecPipeline ctx);
123cb5b572fSBarry Smith extern int VecPipelineBegin(Vec,Vec,InsertMode,ScatterMode,PipelineDirection,VecPipeline);
124cb5b572fSBarry Smith extern int VecPipelineEnd(Vec,Vec,InsertMode,ScatterMode,PipelineDirection,VecPipeline);
125cb5b572fSBarry Smith extern int VecPipelineView(VecPipeline pipe,Viewer viewer);
126cb5b572fSBarry Smith extern int VecPipelineDestroy(VecPipeline ctx);
127cb5b572fSBarry Smith 
12862dc5420SSatish Balay extern int VecGetArray(Vec,Scalar*[]);
12962dc5420SSatish Balay extern int VecRestoreArray(Vec,Scalar*[]);
13062dc5420SSatish Balay extern int VecPlaceArray(Vec,const Scalar[]);
131c9067a45SBarry Smith extern int VecReplaceArray(Vec,const Scalar[]);
13262dc5420SSatish Balay extern int VecGetArrays(const Vec[],int,Scalar**[]);
13362dc5420SSatish Balay extern int VecRestoreArrays(const Vec[],int,Scalar**[]);
13484cb2905SBarry Smith 
13577c4ece6SBarry Smith extern int VecValid(Vec,PetscTruth*);
1368ed539a5SBarry Smith extern int VecView(Vec,Viewer);
13713054869SSatish Balay extern int VecEqual(Vec,Vec,PetscTruth*);
13884cb2905SBarry Smith extern int VecLoad(Viewer,Vec*);
1397ecc41b3SBarry Smith extern int VecLoadIntoVector(Viewer,Vec);
1408ed539a5SBarry Smith 
1418ed539a5SBarry Smith extern int VecGetSize(Vec,int*);
1423f1db9ecSBarry Smith extern int VecGetType(Vec,VecType*);
1438ed539a5SBarry Smith extern int VecGetLocalSize(Vec,int*);
144d6dfbf8fSBarry Smith extern int VecGetOwnershipRange(Vec,int*,int*);
1458ed539a5SBarry Smith 
146d4bb536fSBarry Smith extern int VecSetLocalToGlobalMapping(Vec, ISLocalToGlobalMapping);
14762dc5420SSatish Balay extern int VecSetValuesLocal(Vec,int,const int[],const Scalar[],InsertMode);
14835c17c5bSBarry Smith extern int VecSetLocalToGlobalMappingBlocked(Vec, ISLocalToGlobalMapping);
14962dc5420SSatish Balay extern int VecSetValuesBlockedLocal(Vec,int,const int[],const Scalar[],InsertMode);
15090f02eecSBarry Smith 
151d3c178dbSBarry Smith extern int VecDotBegin(Vec,Vec,Scalar *);
152d3c178dbSBarry Smith extern int VecDotEnd(Vec,Vec,Scalar *);
15373f094bcSBarry Smith extern int VecTDotBegin(Vec,Vec,Scalar *);
15473f094bcSBarry Smith extern int VecTDotEnd(Vec,Vec,Scalar *);
15570f1696fSBarry Smith extern int VecNormBegin(Vec,NormType,double *);
15670f1696fSBarry Smith extern int VecNormEnd(Vec,NormType,double *);
157d3c178dbSBarry Smith 
158f830108cSBarry Smith typedef enum {VEC_IGNORE_OFF_PROC_ENTRIES} VecOption;
15990f02eecSBarry Smith extern int VecSetOption(Vec,VecOption);
16090f02eecSBarry Smith 
161522c5e43SBarry Smith extern int VecContourScale(Vec,double,double);
162522c5e43SBarry Smith 
16315091d37SBarry Smith /*
16415091d37SBarry Smith     These numbers need to match the entries in
16515091d37SBarry Smith   the function table in src/vec/vecimpl.h
16615091d37SBarry Smith */
16715091d37SBarry Smith typedef enum { VEC_VIEW = 32,
16815091d37SBarry Smith                VECOP_LOADINTOVECTOR = 40
16915091d37SBarry Smith              } VecOperation;
17015091d37SBarry Smith extern int VecSetOperation(Vec,VecOperation,void*);
171b19c1e4cSBarry Smith 
172e182c471SBarry Smith /*
173e182c471SBarry Smith      Routines for dealing with ghosted vectors:
174e182c471SBarry Smith   vectors with ghost elements at the end of the array.
175e182c471SBarry Smith */
17662dc5420SSatish Balay extern int VecCreateGhost(MPI_Comm,int,int,int,const int[],Vec*);
17762dc5420SSatish Balay extern int VecCreateGhostWithArray(MPI_Comm,int,int,int,const int[],const Scalar[],Vec*);
178d2655a18SBarry Smith extern int VecGhostGetLocalForm(Vec,Vec*);
179d2655a18SBarry Smith extern int VecGhostRestoreLocalForm(Vec,Vec*);
180e182c471SBarry Smith extern int VecGhostUpdateBegin(Vec,InsertMode,ScatterMode);
181e182c471SBarry Smith extern int VecGhostUpdateEnd(Vec,InsertMode,ScatterMode);
182e182c471SBarry Smith 
183e182c471SBarry Smith 
18434233285SBarry Smith 
1852eac72dbSBarry Smith #endif
1862eac72dbSBarry Smith 
1872eac72dbSBarry Smith 
1887588ac45SBarry Smith 
189