1 /* 2 Defines the vector component of PETSc. Vectors generally represent 3 degrees of freedom for finite element/finite difference functions 4 on a grid. They have more mathematical structure then simple arrays. 5 */ 6 7 #ifndef __PETSCVEC_H 8 #define __PETSCVEC_H 9 #include "petscis.h" 10 #include "petscsys.h" 11 PETSC_EXTERN_CXX_BEGIN 12 13 /*S 14 Vec - Abstract PETSc vector object 15 16 Level: beginner 17 18 Concepts: field variables, unknowns, arrays 19 20 .seealso: VecCreate(), VecType, VecSetType() 21 S*/ 22 typedef struct _p_Vec* Vec; 23 24 /*S 25 VecScatter - Object used to manage communication of data 26 between vectors in parallel. Manages both scatters and gathers 27 28 Level: beginner 29 30 Concepts: scatter 31 32 .seealso: VecScatterCreate(), VecScatterBegin(), VecScatterEnd() 33 S*/ 34 typedef struct _p_VecScatter* VecScatter; 35 36 /*E 37 VecType - String with the name of a PETSc vector or the creation function 38 with an optional dynamic library name, for example 39 http://www.mcs.anl.gov/petsc/lib.a:myveccreate() 40 41 Level: beginner 42 43 .seealso: VecSetType(), Vec 44 E*/ 45 #define VecType char* 46 #define VECSEQ "seq" 47 #define VECMPI "mpi" 48 #define VECFETI "feti" 49 #define VECSHARED "shared" 50 #define VECSIEVE "sieve" 51 52 /* Logging support */ 53 #define VEC_FILE_COOKIE 1211214 54 extern PETSCVEC_DLLEXPORT PetscCookie VEC_COOKIE; 55 extern PETSCVEC_DLLEXPORT PetscCookie VEC_SCATTER_COOKIE; 56 57 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecInitializePackage(const char[]); 58 59 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecCreate(MPI_Comm,Vec*); 60 PetscPolymorphicSubroutine(VecCreate,(Vec *x),(PETSC_COMM_SELF,x)) 61 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecCreateSeq(MPI_Comm,PetscInt,Vec*); 62 PetscPolymorphicSubroutine(VecCreateSeq,(PetscInt n,Vec *x),(PETSC_COMM_SELF,n,x)) 63 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecCreateMPI(MPI_Comm,PetscInt,PetscInt,Vec*); 64 PetscPolymorphicSubroutine(VecCreateMPI,(PetscInt n,PetscInt N,Vec *x),(PETSC_COMM_WORLD,n,N,x)) 65 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecCreateSeqWithArray(MPI_Comm,PetscInt,const PetscScalar[],Vec*); 66 PetscPolymorphicSubroutine(VecCreateSeqWithArray,(PetscInt n,PetscScalar s[],Vec *x),(PETSC_COMM_SELF,n,s,x)) 67 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecCreateMPIWithArray(MPI_Comm,PetscInt,PetscInt,const PetscScalar[],Vec*); 68 PetscPolymorphicSubroutine(VecCreateMPIWithArray,(PetscInt n,PetscInt N,PetscScalar s[],Vec *x),(PETSC_COMM_WORLD,n,N,s,x)) 69 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecCreateShared(MPI_Comm,PetscInt,PetscInt,Vec*); 70 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSetFromOptions(Vec); 71 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSetUp(Vec); 72 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecDestroy(Vec); 73 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecZeroEntries(Vec); 74 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSetOptionsPrefix(Vec,const char[]); 75 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecAppendOptionsPrefix(Vec,const char[]); 76 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGetOptionsPrefix(Vec,const char*[]); 77 78 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSetSizes(Vec,PetscInt,PetscInt); 79 80 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecDotNorm2(Vec,Vec,PetscScalar*,PetscScalar*); 81 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecDot(Vec,Vec,PetscScalar*); 82 PetscPolymorphicFunction(VecDot,(Vec x,Vec y),(x,y,&s),PetscScalar,s) 83 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecTDot(Vec,Vec,PetscScalar*); 84 PetscPolymorphicFunction(VecTDot,(Vec x,Vec y),(x,y,&s),PetscScalar,s) 85 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecMDot(Vec,PetscInt,const Vec[],PetscScalar[]); 86 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecMTDot(Vec,PetscInt,const Vec[],PetscScalar[]); 87 88 /*E 89 NormType - determines what type of norm to compute 90 91 Level: beginner 92 93 .seealso: VecNorm(), VecNormBegin(), VecNormEnd(), MatNorm() 94 E*/ 95 typedef enum {NORM_1=0,NORM_2=1,NORM_FROBENIUS=2,NORM_INFINITY=3,NORM_1_AND_2=4} NormType; 96 extern const char *NormTypes[]; 97 #define NORM_MAX NORM_INFINITY 98 99 /*MC 100 NORM_1 - the one norm, ||v|| = sum_i | v_i |. ||A|| = max_j || v_*j ||, maximum column sum 101 102 Level: beginner 103 104 .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_2, NORM_FROBENIUS, 105 NORM_INFINITY, NORM_1_AND_2 106 107 M*/ 108 109 /*MC 110 NORM_2 - the two norm, ||v|| = sqrt(sum_i (v_i)^2) (vectors only) 111 112 Level: beginner 113 114 .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_FROBENIUS, 115 NORM_INFINITY, NORM_1_AND_2 116 117 M*/ 118 119 /*MC 120 NORM_FROBENIUS - ||A|| = sqrt(sum_ij (A_ij)^2), same as NORM_2 for vectors 121 122 Level: beginner 123 124 .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_2, 125 NORM_INFINITY, NORM_1_AND_2 126 127 M*/ 128 129 /*MC 130 NORM_INFINITY - ||v|| = max_i |v_i|. ||A|| = max_i || v_i* ||, maximum row sum 131 132 Level: beginner 133 134 .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_2, 135 NORM_FROBINIUS, NORM_1_AND_2 136 137 M*/ 138 139 /*MC 140 NORM_1_AND_2 - computes both the 1 and 2 norm of a vector 141 142 Level: beginner 143 144 .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_2, 145 NORM_FROBINIUS, NORM_INFINITY 146 147 M*/ 148 149 /*MC 150 NORM_MAX - see NORM_INFINITY 151 152 Level: beginner 153 154 M*/ 155 156 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecNorm(Vec,NormType,PetscReal *); 157 PetscPolymorphicSubroutine(VecNorm,(Vec x,PetscReal *r),(x,NORM_2,r)) 158 PetscPolymorphicFunction(VecNorm,(Vec x,NormType t),(x,t,&r),PetscReal,r) 159 PetscPolymorphicFunction(VecNorm,(Vec x),(x,NORM_2,&r),PetscReal,r) 160 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecNormalize(Vec,PetscReal *); 161 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSum(Vec,PetscScalar*); 162 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecMax(Vec,PetscInt*,PetscReal *); 163 PetscPolymorphicSubroutine(VecMax,(Vec x,PetscReal *r),(x,PETSC_NULL,r)) 164 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecMin(Vec,PetscInt*,PetscReal *); 165 PetscPolymorphicSubroutine(VecMin,(Vec x,PetscReal *r),(x,PETSC_NULL,r)) 166 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecScale(Vec,PetscScalar); 167 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecCopy(Vec,Vec); 168 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSetRandom(Vec,PetscRandom); 169 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSet(Vec,PetscScalar); 170 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSwap(Vec,Vec); 171 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecAXPY(Vec,PetscScalar,Vec); 172 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecAXPBY(Vec,PetscScalar,PetscScalar,Vec); 173 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecMAXPY(Vec,PetscInt,const PetscScalar[],Vec[]); 174 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecAYPX(Vec,PetscScalar,Vec); 175 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecWAXPY(Vec,PetscScalar,Vec,Vec); 176 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecAXPBYPCZ(Vec,PetscScalar,PetscScalar,PetscScalar,Vec,Vec); 177 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecPointwiseMax(Vec,Vec,Vec); 178 PetscPolymorphicSubroutine(VecPointwiseMax,(Vec x,Vec y),(x,y,y)) 179 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecPointwiseMaxAbs(Vec,Vec,Vec); 180 PetscPolymorphicSubroutine(VecPointwiseMaxAbs,(Vec x,Vec y),(x,y,y)) 181 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecPointwiseMin(Vec,Vec,Vec); 182 PetscPolymorphicSubroutine(VecPointwiseMin,(Vec x,Vec y),(x,y,y)) 183 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecPointwiseMult(Vec,Vec,Vec); 184 PetscPolymorphicSubroutine(VecPointwiseMult,(Vec x,Vec y),(x,x,y)) 185 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecPointwiseDivide(Vec,Vec,Vec); 186 PetscPolymorphicSubroutine(VecPointwiseDivide,(Vec x,Vec y),(x,x,y)) 187 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecMaxPointwiseDivide(Vec,Vec,PetscReal*); 188 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecShift(Vec,PetscScalar); 189 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecReciprocal(Vec); 190 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecPermute(Vec, IS, PetscTruth); 191 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSqrt(Vec); 192 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecLog(Vec); 193 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecExp(Vec); 194 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecAbs(Vec); 195 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecDuplicate(Vec,Vec*); 196 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecDuplicateVecs(Vec,PetscInt,Vec*[]); 197 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecDestroyVecs(Vec[],PetscInt); 198 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecStrideNormAll(Vec,NormType,PetscReal[]); 199 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecStrideMaxAll(Vec,PetscInt [],PetscReal []); 200 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecStrideMinAll(Vec,PetscInt [],PetscReal []); 201 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecStrideScaleAll(Vec,PetscScalar[]); 202 203 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecStrideNorm(Vec,PetscInt,NormType,PetscReal*); 204 PetscPolymorphicFunction(VecStrideNorm,(Vec x,PetscInt i),(x,i,NORM_2,&r),PetscReal,r) 205 PetscPolymorphicFunction(VecStrideNorm,(Vec x,PetscInt i,NormType t),(x,i,t,&r),PetscReal,r) 206 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecStrideMax(Vec,PetscInt,PetscInt *,PetscReal *); 207 PetscPolymorphicFunction(VecStrideMax,(Vec x,PetscInt i),(x,i,PETSC_NULL,&r),PetscReal,r) 208 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecStrideMin(Vec,PetscInt,PetscInt *,PetscReal *); 209 PetscPolymorphicFunction(VecStrideMin,(Vec x,PetscInt i),(x,i,PETSC_NULL,&r),PetscReal,r) 210 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecStrideScale(Vec,PetscInt,PetscScalar); 211 212 213 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecStrideGather(Vec,PetscInt,Vec,InsertMode); 214 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecStrideScatter(Vec,PetscInt,Vec,InsertMode); 215 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecStrideGatherAll(Vec,Vec[],InsertMode); 216 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecStrideScatterAll(Vec[],Vec,InsertMode); 217 218 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSetValues(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode); 219 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGetValues(Vec,PetscInt,const PetscInt[],PetscScalar[]); 220 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecAssemblyBegin(Vec); 221 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecAssemblyEnd(Vec); 222 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecStashSetInitialSize(Vec,PetscInt,PetscInt); 223 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecStashView(Vec,PetscViewer); 224 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecStashGetInfo(Vec,PetscInt*,PetscInt*,PetscInt*,PetscInt*); 225 226 /*MC 227 VecSetValue - Set a single entry into a vector. 228 229 Synopsis: 230 PetscErrorCode VecSetValue(Vec v,int row,PetscScalar value, InsertMode mode); 231 232 Not Collective 233 234 Input Parameters: 235 + v - the vector 236 . row - the row location of the entry 237 . value - the value to insert 238 - mode - either INSERT_VALUES or ADD_VALUES 239 240 Notes: 241 For efficiency one should use VecSetValues() and set several or 242 many values simultaneously if possible. 243 244 These values may be cached, so VecAssemblyBegin() and VecAssemblyEnd() 245 MUST be called after all calls to VecSetValues() have been completed. 246 247 VecSetValues() uses 0-based indices in Fortran as well as in C. 248 249 Level: beginner 250 251 .seealso: VecSetValues(), VecAssemblyBegin(), VecAssemblyEnd(), VecSetValuesBlockedLocal(), VecSetValueLocal() 252 M*/ 253 PETSC_STATIC_INLINE PetscErrorCode VecSetValue(Vec v,PetscInt i,PetscScalar va,InsertMode mode) {return VecSetValues(v,1,&i,&va,mode);} 254 255 256 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSetBlockSize(Vec,PetscInt); 257 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGetBlockSize(Vec,PetscInt*); 258 PetscPolymorphicFunction(VecGetBlockSize,(Vec x),(x,&i),PetscInt,i) 259 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSetValuesBlocked(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode); 260 261 /* Dynamic creation and loading functions */ 262 extern PetscFList VecList; 263 extern PetscTruth VecRegisterAllCalled; 264 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSetType(Vec, const VecType); 265 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGetType(Vec, const VecType *); 266 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecRegister(const char[],const char[],const char[],PetscErrorCode (*)(Vec)); 267 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecRegisterAll(const char []); 268 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecRegisterDestroy(void); 269 270 /*MC 271 VecRegisterDynamic - Adds a new vector component implementation 272 273 Synopsis: 274 PetscErrorCode VecRegisterDynamic(char *name, char *path, char *func_name, PetscErrorCode (*create_func)(Vec)) 275 276 Not Collective 277 278 Input Parameters: 279 + name - The name of a new user-defined creation routine 280 . path - The path (either absolute or relative) of the library containing this routine 281 . func_name - The name of routine to create method context 282 - create_func - The creation routine itself 283 284 Notes: 285 VecRegisterDynamic() may be called multiple times to add several user-defined vectors 286 287 If dynamic libraries are used, then the fourth input argument (routine_create) is ignored. 288 289 Sample usage: 290 .vb 291 VecRegisterDynamic("my_vec","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyVectorCreate", MyVectorCreate); 292 .ve 293 294 Then, your vector type can be chosen with the procedural interface via 295 .vb 296 VecCreate(MPI_Comm, Vec *); 297 VecSetType(Vec,"my_vector_name"); 298 .ve 299 or at runtime via the option 300 .vb 301 -vec_type my_vector_name 302 .ve 303 304 Notes: $PETSC_ARCH occuring in pathname will be replaced with appropriate values. 305 If your function is not being put into a shared library then use VecRegister() instead 306 307 Level: advanced 308 309 .keywords: Vec, register 310 .seealso: VecRegisterAll(), VecRegisterDestroy(), VecRegister() 311 M*/ 312 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 313 #define VecRegisterDynamic(a,b,c,d) VecRegister(a,b,c,0) 314 #else 315 #define VecRegisterDynamic(a,b,c,d) VecRegister(a,b,c,d) 316 #endif 317 318 319 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecScatterCreate(Vec,IS,Vec,IS,VecScatter *); 320 PetscPolymorphicFunction(VecScatterCreate,(Vec x,IS is1,Vec y,IS is2),(x,is1,y,is2,&s),VecScatter,s) 321 PetscPolymorphicSubroutine(VecScatterCreate,(Vec x,IS is,Vec y,VecScatter *s),(x,is,y,PETSC_NULL,s)) 322 PetscPolymorphicFunction(VecScatterCreate,(Vec x,IS is,Vec y),(x,is,y,PETSC_NULL,&s),VecScatter,s) 323 PetscPolymorphicSubroutine(VecScatterCreate,(Vec x,Vec y,IS is,VecScatter *s),(x,PETSC_NULL,y,is,s)) 324 PetscPolymorphicFunction(VecScatterCreate,(Vec x,Vec y,IS is),(x,PETSC_NULL,y,is,&s),VecScatter,s) 325 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecScatterCreateEmpty(MPI_Comm,VecScatter *); 326 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecScatterCreateLocal(VecScatter,PetscInt,const PetscInt[],const PetscInt[],const PetscInt[],PetscInt,const PetscInt[],const PetscInt[],const PetscInt[],PetscInt); 327 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecScatterBegin(VecScatter,Vec,Vec,InsertMode,ScatterMode); 328 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecScatterEnd(VecScatter,Vec,Vec,InsertMode,ScatterMode); 329 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecScatterDestroy(VecScatter); 330 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecScatterCopy(VecScatter,VecScatter *); 331 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecScatterView(VecScatter,PetscViewer); 332 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecScatterRemap(VecScatter,PetscInt *,PetscInt*); 333 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecScatterGetMerged(VecScatter,PetscTruth*); 334 335 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGetArray_Private(Vec,PetscScalar*[]); 336 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecRestoreArray_Private(Vec,PetscScalar*[]); 337 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGetArray4d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar****[]); 338 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecRestoreArray4d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar****[]); 339 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGetArray3d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar***[]); 340 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecRestoreArray3d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar***[]); 341 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGetArray2d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar**[]); 342 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecRestoreArray2d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar**[]); 343 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGetArray1d(Vec,PetscInt,PetscInt,PetscScalar *[]); 344 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecRestoreArray1d(Vec,PetscInt,PetscInt,PetscScalar *[]); 345 346 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecPlaceArray(Vec,const PetscScalar[]); 347 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecResetArray(Vec); 348 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecReplaceArray(Vec,const PetscScalar[]); 349 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGetArrays(const Vec[],PetscInt,PetscScalar**[]); 350 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecRestoreArrays(const Vec[],PetscInt,PetscScalar**[]); 351 352 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecValid(Vec,PetscTruth*); 353 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecView(Vec,PetscViewer); 354 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecViewFromOptions(Vec, const char *); 355 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecEqual(Vec,Vec,PetscTruth*); 356 PetscPolymorphicFunction(VecEqual,(Vec x,Vec y),(x,y,&s),PetscTruth,s) 357 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecLoad(PetscViewer,const VecType,Vec*); 358 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecLoadIntoVector(PetscViewer,Vec); 359 360 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGetSize(Vec,PetscInt*); 361 PetscPolymorphicFunction(VecGetSize,(Vec x),(x,&s),PetscInt,s) 362 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGetLocalSize(Vec,PetscInt*); 363 PetscPolymorphicFunction(VecGetLocalSize,(Vec x),(x,&s),PetscInt,s) 364 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGetOwnershipRange(Vec,PetscInt*,PetscInt*); 365 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGetOwnershipRanges(Vec,const PetscInt *[]); 366 367 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSetLocalToGlobalMapping(Vec,ISLocalToGlobalMapping); 368 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSetValuesLocal(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode); 369 370 /*MC 371 VecSetValueLocal - Set a single entry into a vector using the local numbering 372 373 Synopsis: 374 PetscErrorCode VecSetValueLocal(Vec v,int row,PetscScalar value, InsertMode mode); 375 376 Not Collective 377 378 Input Parameters: 379 + v - the vector 380 . row - the row location of the entry 381 . value - the value to insert 382 - mode - either INSERT_VALUES or ADD_VALUES 383 384 Notes: 385 For efficiency one should use VecSetValues() and set several or 386 many values simultaneously if possible. 387 388 These values may be cached, so VecAssemblyBegin() and VecAssemblyEnd() 389 MUST be called after all calls to VecSetValues() have been completed. 390 391 VecSetValues() uses 0-based indices in Fortran as well as in C. 392 393 Level: beginner 394 395 .seealso: VecSetValues(), VecAssemblyBegin(), VecAssemblyEnd(), VecSetValuesBlockedLocal(), VecSetValue() 396 M*/ 397 PETSC_STATIC_INLINE PetscErrorCode VecSetValueLocal(Vec v,PetscInt i,PetscScalar va,InsertMode mode) {return VecSetValuesLocal(v,1,&i,&va,mode);} 398 399 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSetLocalToGlobalMappingBlock(Vec,ISLocalToGlobalMapping); 400 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSetValuesBlockedLocal(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode); 401 402 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecDotBegin(Vec,Vec,PetscScalar *); 403 PetscPolymorphicSubroutine(VecDotBegin,(Vec x,Vec y),(x,y,PETSC_NULL)) 404 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecDotEnd(Vec,Vec,PetscScalar *); 405 PetscPolymorphicFunction(VecDotEnd,(Vec x,Vec y),(x,y,&s),PetscScalar,s) 406 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecTDotBegin(Vec,Vec,PetscScalar *); 407 PetscPolymorphicSubroutine(VecTDotBegin,(Vec x,Vec y),(x,y,PETSC_NULL)) 408 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecTDotEnd(Vec,Vec,PetscScalar *); 409 PetscPolymorphicFunction(VecTDotEnd,(Vec x,Vec y),(x,y,&s),PetscScalar,s) 410 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecNormBegin(Vec,NormType,PetscReal *); 411 PetscPolymorphicSubroutine(VecNormBegin,(Vec x,NormType t),(x,t,PETSC_NULL)) 412 PetscPolymorphicSubroutine(VecNormBegin,(Vec x),(x,NORM_2,PETSC_NULL)) 413 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecNormEnd(Vec,NormType,PetscReal *); 414 PetscPolymorphicFunction(VecNormEnd,(Vec x,NormType t),(x,t,&s),PetscReal,s) 415 PetscPolymorphicFunction(VecNormEnd,(Vec x),(x,NORM_2,&s),PetscReal,s) 416 417 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecMDotBegin(Vec,PetscInt,const Vec[],PetscScalar[]); 418 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecMDotEnd(Vec,PetscInt,const Vec[],PetscScalar[]); 419 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecMTDotBegin(Vec,PetscInt,const Vec[],PetscScalar[]); 420 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecMTDotEnd(Vec,PetscInt,const Vec[],PetscScalar[]); 421 422 423 typedef enum {VEC_IGNORE_OFF_PROC_ENTRIES,VEC_IGNORE_NEGATIVE_INDICES} VecOption; 424 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSetOption(Vec,VecOption,PetscTruth); 425 426 /* 427 Expose VecGetArray()/VecRestoreArray() to users. Allows this to work without any function 428 call overhead on any 'native' Vecs. 429 */ 430 431 #include "private/vecimpl.h" 432 433 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecContourScale(Vec,PetscReal,PetscReal); 434 435 /* 436 These numbers need to match the entries in 437 the function table in vecimpl.h 438 */ 439 typedef enum { VECOP_VIEW = 33, VECOP_LOADINTOVECTOR = 41} VecOperation; 440 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecSetOperation(Vec,VecOperation,void(*)(void)); 441 442 /* 443 Routines for dealing with ghosted vectors: 444 vectors with ghost elements at the end of the array. 445 */ 446 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecCreateGhost(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],Vec*); 447 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecCreateGhostWithArray(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscScalar[],Vec*); 448 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecCreateGhostBlock(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],Vec*); 449 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecCreateGhostBlockWithArray(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscScalar[],Vec*); 450 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGhostGetLocalForm(Vec,Vec*); 451 PetscPolymorphicFunction(VecGhostGetLocalForm,(Vec x),(x,&s),Vec,s) 452 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGhostRestoreLocalForm(Vec,Vec*); 453 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGhostUpdateBegin(Vec,InsertMode,ScatterMode); 454 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecGhostUpdateEnd(Vec,InsertMode,ScatterMode); 455 456 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecConjugate(Vec); 457 458 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecScatterCreateToAll(Vec,VecScatter*,Vec*); 459 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT VecScatterCreateToZero(Vec,VecScatter*,Vec*); 460 461 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT PetscViewerMathematicaGetVector(PetscViewer, Vec); 462 EXTERN PetscErrorCode PETSCVEC_DLLEXPORT PetscViewerMathematicaPutVector(PetscViewer, Vec); 463 464 /*S 465 Vecs - Collection of vectors where the data for the vectors is stored in 466 one contiguous memory 467 468 Level: advanced 469 470 Notes: 471 Temporary construct for handling multiply right hand side solves 472 473 This is faked by storing a single vector that has enough array space for 474 n vectors 475 476 Concepts: parallel decomposition 477 478 S*/ 479 struct _n_Vecs {PetscInt n; Vec v;}; 480 typedef struct _n_Vecs* Vecs; 481 #define VecsDestroy(x) (VecDestroy((x)->v) || PetscFree(x)) 482 #define VecsCreateSeq(comm,p,m,x) (PetscNew(struct _n_Vecs,x) || VecCreateSeq(comm,p*m,&(*(x))->v) || (-1 == ((*(x))->n = (m)))) 483 #define VecsCreateSeqWithArray(comm,p,m,a,x) (PetscNew(struct _n_Vecs,x) || VecCreateSeqWithArray(comm,p*m,a,&(*(x))->v) || (-1 == ((*(x))->n = (m)))) 484 #define VecsDuplicate(x,y) (PetscNew(struct _n_Vecs,y) || VecDuplicate(x->v,&(*(y))->v) || (-1 == ((*(y))->n = (x)->n))) 485 486 487 PETSC_EXTERN_CXX_END 488 #endif 489