xref: /petsc/include/petscvec.h (revision ac2a4f0d24b3b6a4ee93edbcad41f4bb9e923944)
1 /* $Id: vec.h,v 1.98 1999/09/14 19:20:24 bsmith Exp balay $ */
2 /*
3     Defines the vector component of PETSc. Vectors generally represent
4   degrees of freedom for finite element/finite difference functions
5   on a grid. They have more mathematical structure then simple arrays.
6 */
7 
8 #ifndef __VEC_H
9 #define __VEC_H
10 #include "is.h"
11 #include "sys.h"
12 
13 #define VEC_COOKIE         PETSC_COOKIE+3
14 #define MAP_COOKIE         PETSC_COOKIE+22
15 #define VEC_SCATTER_COOKIE PETSC_COOKIE+4
16 
17 typedef struct _p_Map*         Map;
18 typedef struct _p_Vec*         Vec;
19 typedef struct _p_VecScatter*  VecScatter;
20 #define VEC_SEQ    "seq"
21 #define VEC_MPI    "mpi"
22 #define VEC_SHARED "shared"
23 typedef char*                  VecType;
24 
25 extern int VecCreateSeq(MPI_Comm,int,Vec*);
26 extern int MapCreateMPI(MPI_Comm,int,int,Map*);
27 extern int VecCreateMPI(MPI_Comm,int,int,Vec*);
28 extern int VecCreateSeqWithArray(MPI_Comm,int,const Scalar[],Vec*);
29 extern int VecCreateMPIWithArray(MPI_Comm,int,int,const Scalar[],Vec*);
30 extern int VecCreateShared(MPI_Comm,int,int,Vec*);
31 extern int VecCreate(MPI_Comm,int,int,Vec*);
32 extern int VecSetType(Vec,VecType);
33 extern int VecSetFromOptions(Vec);
34 
35 extern int VecDestroy(Vec);
36 
37 extern int MapDestroy(Map);
38 extern int MapGetLocalSize(Map,int *);
39 extern int MapGetSize(Map,int *);
40 extern int MapGetLocalRange(Map,int *,int *);
41 extern int MapGetGlobalRange(Map,int *[]);
42 
43 extern int VecDot(Vec,Vec,Scalar*);
44 extern int VecTDot(Vec,Vec,Scalar*);
45 extern int VecMDot(int,Vec,const Vec[],Scalar*);
46 extern int VecMTDot(int,Vec,const Vec[],Scalar*);
47 
48 typedef enum {NORM_1=1,NORM_2=2,NORM_FROBENIUS=3,NORM_INFINITY=4,NORM_1_AND_2=5} NormType;
49 #define NORM_MAX NORM_INFINITY
50 extern int VecNorm(Vec,NormType,double *);
51 extern int VecSum(Vec,Scalar*);
52 extern int VecMax(Vec,int*,double*);
53 extern int VecMin(Vec,int*,double*);
54 extern int VecScale(const Scalar*,Vec);
55 extern int VecCopy(Vec,Vec);
56 extern int VecSetRandom(PetscRandom,Vec);
57 extern int VecSet(const Scalar*,Vec);
58 extern int VecSwap(Vec,Vec);
59 extern int VecAXPY(const Scalar*,Vec,Vec);
60 extern int VecAXPBY(const Scalar*,const Scalar *,Vec,Vec);
61 extern int VecMAXPY(int,const Scalar*,Vec,Vec*);
62 extern int VecAYPX(const Scalar*,Vec,Vec);
63 extern int VecWAXPY(const Scalar*,Vec,Vec,Vec);
64 extern int VecPointwiseMult(Vec,Vec,Vec);
65 extern int VecPointwiseDivide(Vec,Vec,Vec);
66 extern int VecShift(const Scalar*,Vec);
67 extern int VecReciprocal(Vec);
68 extern int VecAbs(Vec);
69 extern int VecDuplicate(Vec,Vec*);
70 extern int VecDuplicateVecs(Vec,int,Vec*[]);
71 extern int VecDestroyVecs(const Vec[],int);
72 extern int VecGetMap(Vec,Map*);
73 
74 typedef enum {NOT_SET_VALUES, INSERT_VALUES, ADD_VALUES, MAX_VALUES} InsertMode;
75 
76 extern int VecStrideNorm(Vec,int,NormType,double*);
77 extern int VecStrideGather(Vec,int,Vec,InsertMode);
78 extern int VecStrideScatter(Vec,int,Vec,InsertMode);
79 extern int VecStrideMax(Vec,int,int *,double *);
80 extern int VecStrideMin(Vec,int,int *,double *);
81 
82 extern int VecSetValues(Vec,int,const int[],const Scalar[],InsertMode);
83 extern int VecAssemblyBegin(Vec);
84 extern int VecAssemblyEnd(Vec);
85 extern int VecSetStashInitialSize(Vec,int, int);
86 
87 #define VecSetValue(v,i,va,mode) \
88 {int _ierr,_row = i; Scalar _va = va; \
89   _ierr = VecSetValues(v,1,&_row,&_va,mode);CHKERRQ(_ierr); \
90 }
91 extern int VecSetBlockSize(Vec,int);
92 extern int VecGetBlockSize(Vec,int*);
93 extern int VecSetValuesBlocked(Vec,int,const int[],const Scalar[],InsertMode);
94 
95 extern int VecRegisterAllCalled;
96 extern int VecRegisterAll(const char []);
97 extern int VecRegister_Private(const char[],const char[],const char[],int(*)(Vec));
98 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
99 #define VecRegister(a,b,c,d) VecRegister_Private(a,b,c,0)
100 #else
101 #define VecRegister(a,b,c,d) VecRegister_Private(a,b,c,d)
102 #endif
103 
104 typedef enum {SCATTER_FORWARD=0,SCATTER_REVERSE=1,SCATTER_FORWARD_LOCAL=2,
105               SCATTER_REVERSE_LOCAL=3,SCATTER_LOCAL=2} ScatterMode;
106 extern int VecScatterCreate(Vec,IS,Vec,IS,VecScatter *);
107 extern int VecScatterPostRecvs(Vec,Vec,InsertMode,ScatterMode,VecScatter);
108 extern int VecScatterBegin(Vec,Vec,InsertMode,ScatterMode,VecScatter);
109 extern int VecScatterEnd(Vec,Vec,InsertMode,ScatterMode,VecScatter);
110 extern int VecScatterDestroy(VecScatter);
111 extern int VecScatterCopy(VecScatter,VecScatter *);
112 extern int VecScatterView(VecScatter,Viewer);
113 extern int VecScatterRemap(VecScatter,int *,int*);
114 
115 typedef enum {PIPELINE_DOWN=0,PIPELINE_UP=1} PipelineDirection;
116 typedef enum {PIPELINE_NONE=1, PIPELINE_SEQUENTIAL=2,
117 	      PIPELINE_REDBLACK=3, PIPELINE_MULTICOLOR=4} PipelineType;
118 
119 typedef struct _p_VecPipeline*  VecPipeline;
120 
121 extern int VecPipelineCreate(MPI_Comm,Vec,IS,Vec,IS,VecPipeline *);
122 extern int VecPipelineSetType(VecPipeline,PipelineType,PetscObject);
123 extern int VecPipelineSetup(VecPipeline);
124 extern int VecPipelineBegin(Vec,Vec,InsertMode,ScatterMode,PipelineDirection,VecPipeline);
125 extern int VecPipelineEnd(Vec,Vec,InsertMode,ScatterMode,PipelineDirection,VecPipeline);
126 extern int VecPipelineView(VecPipeline,Viewer);
127 extern int VecPipelineDestroy(VecPipeline);
128 
129 extern int VecGetArray(Vec,Scalar*[]);
130 extern int VecRestoreArray(Vec,Scalar*[]);
131 extern int VecPlaceArray(Vec,const Scalar[]);
132 extern int VecReplaceArray(Vec,const Scalar[]);
133 extern int VecGetArrays(const Vec[],int,Scalar**[]);
134 extern int VecRestoreArrays(const Vec[],int,Scalar**[]);
135 
136 extern int VecValid(Vec,PetscTruth*);
137 extern int VecView(Vec,Viewer);
138 extern int VecEqual(Vec,Vec,PetscTruth*);
139 extern int VecLoad(Viewer,Vec*);
140 extern int VecLoadIntoVector(Viewer,Vec);
141 
142 extern int VecGetSize(Vec,int*);
143 extern int VecGetType(Vec,VecType*);
144 extern int VecGetLocalSize(Vec,int*);
145 extern int VecGetOwnershipRange(Vec,int*,int*);
146 
147 extern int VecSetLocalToGlobalMapping(Vec, ISLocalToGlobalMapping);
148 extern int VecSetValuesLocal(Vec,int,const int[],const Scalar[],InsertMode);
149 extern int VecSetLocalToGlobalMappingBlocked(Vec, ISLocalToGlobalMapping);
150 extern int VecSetValuesBlockedLocal(Vec,int,const int[],const Scalar[],InsertMode);
151 
152 extern int VecDotBegin(Vec,Vec,Scalar *);
153 extern int VecDotEnd(Vec,Vec,Scalar *);
154 extern int VecTDotBegin(Vec,Vec,Scalar *);
155 extern int VecTDotEnd(Vec,Vec,Scalar *);
156 extern int VecNormBegin(Vec,NormType,double *);
157 extern int VecNormEnd(Vec,NormType,double *);
158 
159 typedef enum {VEC_IGNORE_OFF_PROC_ENTRIES} VecOption;
160 extern int VecSetOption(Vec,VecOption);
161 
162 extern int VecContourScale(Vec,double,double);
163 
164 /*
165     These numbers need to match the entries in
166   the function table in src/vec/vecimpl.h
167 */
168 typedef enum { VECOP_VIEW = 32,
169                VECOP_LOADINTOVECTOR = 40
170              } VecOperation;
171 extern int VecSetOperation(Vec,VecOperation,void*);
172 
173 /*
174      Routines for dealing with ghosted vectors:
175   vectors with ghost elements at the end of the array.
176 */
177 extern int VecCreateGhost(MPI_Comm,int,int,int,const int[],Vec*);
178 extern int VecCreateGhostWithArray(MPI_Comm,int,int,int,const int[],const Scalar[],Vec*);
179 extern int VecCreateGhostBlock(MPI_Comm,int,int,int,int,const int[],Vec*);
180 extern int VecCreateGhostBlockWithArray(MPI_Comm,int,int,int,int,const int[],const Scalar[],Vec*);
181 extern int VecGhostGetLocalForm(Vec,Vec*);
182 extern int VecGhostRestoreLocalForm(Vec,Vec*);
183 extern int VecGhostUpdateBegin(Vec,InsertMode,ScatterMode);
184 extern int VecGhostUpdateEnd(Vec,InsertMode,ScatterMode);
185 
186 
187 
188 #endif
189 
190 
191 
192