xref: /petsc/include/petscvec.h (revision e7592fafdafd2d48ae4a0483061ac14bd099dfe3)
1*e7592fafSBarry Smith /* $Id: vec.h,v 1.106 2000/04/07 15:18: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 
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);
34*e7592fafSBarry Smith extern int VecPrintHelp(Vec);
352eac72dbSBarry Smith 
364b0e389bSBarry Smith extern int VecDestroy(Vec);
374b0e389bSBarry Smith 
3894d884c6SBarry Smith extern int MapDestroy(Map);
3994d884c6SBarry Smith extern int MapGetLocalSize(Map,int *);
4083271157SBarry Smith extern int MapGetSize(Map,int *);
4194d884c6SBarry Smith extern int MapGetLocalRange(Map,int *,int *);
4262dc5420SSatish Balay extern int MapGetGlobalRange(Map,int *[]);
4394d884c6SBarry Smith 
448ed539a5SBarry Smith extern int VecDot(Vec,Vec,Scalar*);
458ed539a5SBarry Smith extern int VecTDot(Vec,Vec,Scalar*);
4662dc5420SSatish Balay extern int VecMDot(int,Vec,const Vec[],Scalar*);
4762dc5420SSatish Balay extern int VecMTDot(int,Vec,const Vec[],Scalar*);
48cddf8d76SBarry Smith 
4993c39befSBarry Smith typedef enum {NORM_1=1,NORM_2=2,NORM_FROBENIUS=3,NORM_INFINITY=4,NORM_1_AND_2=5} NormType;
50cddf8d76SBarry Smith #define NORM_MAX NORM_INFINITY
51cddf8d76SBarry Smith extern int VecNorm(Vec,NormType,double *);
52ee50ffe9SBarry Smith extern int VecSum(Vec,Scalar*);
537c16e1c9SBarry Smith extern int VecMax(Vec,int*,double*);
547c16e1c9SBarry Smith extern int VecMin(Vec,int*,double*);
5562dc5420SSatish Balay extern int VecScale(const Scalar*,Vec);
568ed539a5SBarry Smith extern int VecCopy(Vec,Vec);
5777c4ece6SBarry Smith extern int VecSetRandom(PetscRandom,Vec);
5862dc5420SSatish Balay extern int VecSet(const Scalar*,Vec);
598ed539a5SBarry Smith extern int VecSwap(Vec,Vec);
6062dc5420SSatish Balay extern int VecAXPY(const Scalar*,Vec,Vec);
6162dc5420SSatish Balay extern int VecAXPBY(const Scalar*,const Scalar *,Vec,Vec);
6262dc5420SSatish Balay extern int VecMAXPY(int,const Scalar*,Vec,Vec*);
6362dc5420SSatish Balay extern int VecAYPX(const Scalar*,Vec,Vec);
6462dc5420SSatish Balay extern int VecWAXPY(const Scalar*,Vec,Vec,Vec);
6577c4ece6SBarry Smith extern int VecPointwiseMult(Vec,Vec,Vec);
6677c4ece6SBarry Smith extern int VecPointwiseDivide(Vec,Vec,Vec);
6762dc5420SSatish Balay extern int VecShift(const Scalar*,Vec);
684b0e389bSBarry Smith extern int VecReciprocal(Vec);
694b0e389bSBarry Smith extern int VecAbs(Vec);
706469c4f9SBarry Smith extern int VecDuplicate(Vec,Vec*);
7162dc5420SSatish Balay extern int VecDuplicateVecs(Vec,int,Vec*[]);
7262dc5420SSatish Balay extern int VecDestroyVecs(const Vec[],int);
7394d884c6SBarry Smith extern int VecGetMap(Vec,Map*);
742eac72dbSBarry Smith 
7590edef3dSSatish Balay typedef enum {NOT_SET_VALUES,INSERT_VALUES,ADD_VALUES,MAX_VALUES} InsertMode;
7690edef3dSSatish Balay 
77d2655a18SBarry Smith extern int VecStrideNorm(Vec,int,NormType,double*);
78731415e4SBarry Smith extern int VecStrideGather(Vec,int,Vec,InsertMode);
79731415e4SBarry Smith extern int VecStrideScatter(Vec,int,Vec,InsertMode);
80f02e6ac2SBarry Smith extern int VecStrideMax(Vec,int,int *,double *);
81f02e6ac2SBarry Smith extern int VecStrideMin(Vec,int,int *,double *);
827c922b88SBarry Smith extern int VecStrideGatherAll(Vec,Vec*,InsertMode);
837c922b88SBarry Smith extern int VecStrideScatterAll(Vec*,Vec,InsertMode);
84d2655a18SBarry Smith 
8562dc5420SSatish Balay extern int VecSetValues(Vec,int,const int[],const Scalar[],InsertMode);
86ee50ffe9SBarry Smith extern int VecAssemblyBegin(Vec);
87ee50ffe9SBarry Smith extern int VecAssemblyEnd(Vec);
88649db694SBarry Smith extern int VecSetStashInitialSize(Vec,int,int);
897c922b88SBarry Smith extern int VecStashView(Vec,Viewer);
9062dc5420SSatish Balay 
91b951964fSBarry Smith #define VecSetValue(v,i,va,mode) \
92b951964fSBarry Smith {int _ierr,_row = i; Scalar _va = va; \
93b951964fSBarry Smith   _ierr = VecSetValues(v,1,&_row,&_va,mode);CHKERRQ(_ierr); \
94b951964fSBarry Smith }
9535c17c5bSBarry Smith extern int VecSetBlockSize(Vec,int);
967ecc41b3SBarry Smith extern int VecGetBlockSize(Vec,int*);
9762dc5420SSatish Balay extern int VecSetValuesBlocked(Vec,int,const int[],const Scalar[],InsertMode);
988ed539a5SBarry Smith 
992bad1931SBarry Smith extern PetscTruth VecRegisterAllCalled;
10062dc5420SSatish Balay extern int        VecRegisterAll(const char []);
101f1af5d2fSBarry Smith extern int        VecRegister(const char[],const char[],const char[],int(*)(Vec));
102aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
103f1af5d2fSBarry Smith #define VecRegisterDynamic(a,b,c,d) VecRegister(a,b,c,0)
10488d459dfSBarry Smith #else
105f1af5d2fSBarry Smith #define VecRegisterDynamic(a,b,c,d) VecRegister(a,b,c,d)
10688d459dfSBarry Smith #endif
10788d459dfSBarry Smith 
108d252947aSBarry Smith typedef enum {SCATTER_FORWARD=0,SCATTER_REVERSE=1,SCATTER_FORWARD_LOCAL=2,
109d252947aSBarry Smith               SCATTER_REVERSE_LOCAL=3,SCATTER_LOCAL=2} ScatterMode;
11084cb2905SBarry Smith extern int VecScatterCreate(Vec,IS,Vec,IS,VecScatter *);
11190f02eecSBarry Smith extern int VecScatterPostRecvs(Vec,Vec,InsertMode,ScatterMode,VecScatter);
11208480c60SBarry Smith extern int VecScatterBegin(Vec,Vec,InsertMode,ScatterMode,VecScatter);
11308480c60SBarry Smith extern int VecScatterEnd(Vec,Vec,InsertMode,ScatterMode,VecScatter);
11408480c60SBarry Smith extern int VecScatterDestroy(VecScatter);
11508480c60SBarry Smith extern int VecScatterCopy(VecScatter,VecScatter *);
11608480c60SBarry Smith extern int VecScatterView(VecScatter,Viewer);
1172195c698SBarry Smith extern int VecScatterRemap(VecScatter,int *,int*);
1182195c698SBarry Smith 
119cb5b572fSBarry Smith typedef enum {PIPELINE_DOWN=0,PIPELINE_UP=1} PipelineDirection;
120cb5b572fSBarry Smith typedef enum {PIPELINE_NONE=1,PIPELINE_SEQUENTIAL=2,
1218ea6152fSSatish Balay 	      PIPELINE_REDBLACK=3,PIPELINE_MULTICOLOR=4} PipelineType;
122cb5b572fSBarry Smith 
123cb5b572fSBarry Smith typedef struct _p_VecPipeline*  VecPipeline;
124cb5b572fSBarry Smith 
12545d8df80SSatish Balay extern int VecPipelineCreate(MPI_Comm,Vec,IS,Vec,IS,VecPipeline *);
12645d8df80SSatish Balay extern int VecPipelineSetType(VecPipeline,PipelineType,PetscObject);
12745d8df80SSatish Balay extern int VecPipelineSetup(VecPipeline);
128cb5b572fSBarry Smith extern int VecPipelineBegin(Vec,Vec,InsertMode,ScatterMode,PipelineDirection,VecPipeline);
129cb5b572fSBarry Smith extern int VecPipelineEnd(Vec,Vec,InsertMode,ScatterMode,PipelineDirection,VecPipeline);
13045d8df80SSatish Balay extern int VecPipelineView(VecPipeline,Viewer);
13145d8df80SSatish Balay extern int VecPipelineDestroy(VecPipeline);
132cb5b572fSBarry Smith 
13362dc5420SSatish Balay extern int VecGetArray(Vec,Scalar*[]);
13462dc5420SSatish Balay extern int VecRestoreArray(Vec,Scalar*[]);
1357ce0f21dSBarry Smith extern int VecGetArray4d(Vec,int,int,int,int,int,int,int,int,Scalar**[]);
1367ce0f21dSBarry Smith extern int VecRestoreArray4d(Vec,int,int,int,int,int,int,int,int,Scalar**[]);
1377ce0f21dSBarry Smith extern int VecGetArray3d(Vec,int,int,int,int,int,int,Scalar**[]);
1387ce0f21dSBarry Smith extern int VecRestoreArray3d(Vec,int,int,int,int,int,int,Scalar**[]);
139ab360428SBarry Smith extern int VecGetArray2d(Vec,int,int,int,int,Scalar**[]);
140ab360428SBarry Smith extern int VecRestoreArray2d(Vec,int,int,int,int,Scalar**[]);
141611ecbcaSBarry Smith extern int VecGetArray1d(Vec,int,int,Scalar *[]);
142611ecbcaSBarry Smith extern int VecRestoreArray1d(Vec,int,int,Scalar *[]);
143ab360428SBarry Smith 
14462dc5420SSatish Balay extern int VecPlaceArray(Vec,const Scalar[]);
145c9067a45SBarry Smith extern int VecReplaceArray(Vec,const Scalar[]);
14662dc5420SSatish Balay extern int VecGetArrays(const Vec[],int,Scalar**[]);
14762dc5420SSatish Balay extern int VecRestoreArrays(const Vec[],int,Scalar**[]);
14884cb2905SBarry Smith 
14977c4ece6SBarry Smith extern int VecValid(Vec,PetscTruth*);
1508ed539a5SBarry Smith extern int VecView(Vec,Viewer);
15113054869SSatish Balay extern int VecEqual(Vec,Vec,PetscTruth*);
15284cb2905SBarry Smith extern int VecLoad(Viewer,Vec*);
1537ecc41b3SBarry Smith extern int VecLoadIntoVector(Viewer,Vec);
1548ed539a5SBarry Smith 
1558ed539a5SBarry Smith extern int VecGetSize(Vec,int*);
1563f1db9ecSBarry Smith extern int VecGetType(Vec,VecType*);
1578ed539a5SBarry Smith extern int VecGetLocalSize(Vec,int*);
158d6dfbf8fSBarry Smith extern int VecGetOwnershipRange(Vec,int*,int*);
1598ed539a5SBarry Smith 
160d4bb536fSBarry Smith extern int VecSetLocalToGlobalMapping(Vec,ISLocalToGlobalMapping);
16162dc5420SSatish Balay extern int VecSetValuesLocal(Vec,int,const int[],const Scalar[],InsertMode);
16235c17c5bSBarry Smith extern int VecSetLocalToGlobalMappingBlocked(Vec,ISLocalToGlobalMapping);
16362dc5420SSatish Balay extern int VecSetValuesBlockedLocal(Vec,int,const int[],const Scalar[],InsertMode);
16490f02eecSBarry Smith 
165d3c178dbSBarry Smith extern int VecDotBegin(Vec,Vec,Scalar *);
166d3c178dbSBarry Smith extern int VecDotEnd(Vec,Vec,Scalar *);
16773f094bcSBarry Smith extern int VecTDotBegin(Vec,Vec,Scalar *);
16873f094bcSBarry Smith extern int VecTDotEnd(Vec,Vec,Scalar *);
16970f1696fSBarry Smith extern int VecNormBegin(Vec,NormType,double *);
17070f1696fSBarry Smith extern int VecNormEnd(Vec,NormType,double *);
171d3c178dbSBarry Smith 
172f830108cSBarry Smith typedef enum {VEC_IGNORE_OFF_PROC_ENTRIES} VecOption;
17390f02eecSBarry Smith extern int VecSetOption(Vec,VecOption);
17490f02eecSBarry Smith 
175522c5e43SBarry Smith extern int VecContourScale(Vec,double,double);
176522c5e43SBarry Smith 
17715091d37SBarry Smith /*
17815091d37SBarry Smith     These numbers need to match the entries in
17915091d37SBarry Smith   the function table in src/vec/vecimpl.h
18015091d37SBarry Smith */
181*e7592fafSBarry Smith typedef enum { VECOP_VIEW = 33,
18215091d37SBarry Smith                VECOP_LOADINTOVECTOR = 40
18315091d37SBarry Smith              } VecOperation;
184*e7592fafSBarry Smith extern int VecSetOperation(Vec,VecOperation,void*); /*  */
185b19c1e4cSBarry Smith 
186e182c471SBarry Smith /*
187e182c471SBarry Smith      Routines for dealing with ghosted vectors:
188e182c471SBarry Smith   vectors with ghost elements at the end of the array.
189e182c471SBarry Smith */
19062dc5420SSatish Balay extern int VecCreateGhost(MPI_Comm,int,int,int,const int[],Vec*);
19162dc5420SSatish Balay extern int VecCreateGhostWithArray(MPI_Comm,int,int,int,const int[],const Scalar[],Vec*);
19285614651SBarry Smith extern int VecCreateGhostBlock(MPI_Comm,int,int,int,int,const int[],Vec*);
19385614651SBarry Smith extern int VecCreateGhostBlockWithArray(MPI_Comm,int,int,int,int,const int[],const Scalar[],Vec*);
194d2655a18SBarry Smith extern int VecGhostGetLocalForm(Vec,Vec*);
195d2655a18SBarry Smith extern int VecGhostRestoreLocalForm(Vec,Vec*);
196e182c471SBarry Smith extern int VecGhostUpdateBegin(Vec,InsertMode,ScatterMode);
197e182c471SBarry Smith extern int VecGhostUpdateEnd(Vec,InsertMode,ScatterMode);
198e182c471SBarry Smith 
199e182c471SBarry Smith 
20034233285SBarry Smith 
2012eac72dbSBarry Smith #endif
2022eac72dbSBarry Smith 
2032eac72dbSBarry Smith 
2047588ac45SBarry Smith 
205