Actual source code: petscda.h

  1: /*
  2:       Regular array object, for easy parallelism of simple grid 
  3:    problems on regular distributed arrays.
  4: */
 7:  #include petscvec.h
 8:  #include petscao.h

 11: /*S
 12:      DA - Abstract PETSc object that manages distributed field data for a single structured grid

 14:    Level: beginner

 16:   Concepts: distributed array

 18: .seealso:  DACreate1d(), DACreate2d(), DACreate3d(), DADestroy(), VecScatter, DACreate(), DM, DMComposite
 19: S*/
 20: typedef struct _p_DA* DA;

 22: #define DAType char*
 23: #define DA1D "da1d"
 24: #define DA2D "da2d"
 25: #define DA3D "da3d"

 27: /*E
 28:     DAStencilType - Determines if the stencil extends only along the coordinate directions, or also
 29:       to the northeast, northwest etc

 31:    Level: beginner

 33: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), DA, DACreate()
 34: E*/
 35: typedef enum { DA_STENCIL_STAR,DA_STENCIL_BOX } DAStencilType;

 37: /*MC
 38:      DA_STENCIL_STAR - "Star"-type stencil. In logical grid coordinates, only (i,j,k), (i+s,j,k), (i,j+s,k),
 39:                        (i,j,k+s) are in the stencil  NOT, for example, (i+s,j+s,k)

 41:      Level: beginner

 43: .seealso: DA_STENCIL_BOX, DAStencilType
 44: M*/

 46: /*MC
 47:      DA_STENCIL_Box - "Box"-type stencil. In logical grid coordinates, any of (i,j,k), (i+s,j+r,k+t) may 
 48:                       be in the stencil.

 50:      Level: beginner

 52: .seealso: DA_STENCIL_STAR, DAStencilType
 53: M*/

 55: /*E
 56:     DAPeriodicType - Is the domain periodic in one or more directions

 58:    Level: beginner

 60:    DA_XYZGHOSTED means that ghost points are put around all the physical boundaries
 61:    in the local representation of the Vec (i.e. DACreate/GetLocalVector().

 63: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), DA, DACreate()
 64: E*/
 65: typedef enum { DA_NONPERIODIC,DA_XPERIODIC,DA_YPERIODIC,DA_XYPERIODIC,
 66:                DA_XYZPERIODIC,DA_XZPERIODIC,DA_YZPERIODIC,DA_ZPERIODIC,DA_XYZGHOSTED} DAPeriodicType;

 69: /*E
 70:     DAInterpolationType - Defines the type of interpolation that will be returned by 
 71:        DAGetInterpolation.

 73:    Level: beginner

 75: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), DA, DAGetInterpolation(), DASetInterpolationType(), DACreate()
 76: E*/
 77: typedef enum { DA_Q0, DA_Q1 } DAInterpolationType;

 79: EXTERN PetscErrorCode   DASetInterpolationType(DA,DAInterpolationType);

 81: /*E
 82:     DAElementType - Defines the type of elements that will be returned by 
 83:        DAGetElements.

 85:    Level: beginner

 87: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), DA, DAGetInterpolation(), DASetInterpolationType(), 
 88:           DASetElementType(), DAGetElements(), DARestoreElements(), DACreate()
 89: E*/
 90: typedef enum { DA_ELEMENT_P1, DA_ELEMENT_Q1 } DAElementType;

 92: EXTERN PetscErrorCode   DASetElementType(DA,DAElementType);
 93: /*MC
 94:    DAGetElements - same as DMGetElements()
 95:    uses DA instead of DM as input
 96: M*/
 97: #define DAGetElements(da,a,b)      DMGetElements((DM)da,a,b)
 98: /*MC
 99:    DARestoreElements - same as DMRestoreElements()
100:    uses DA instead of DM as input
101: M*/
102: #define DARestoreElements(da,a,b)  DMRestoreElements((DM)da,a,b)


105: #define DAXPeriodic(pt) ((pt)==DA_XPERIODIC||(pt)==DA_XYPERIODIC||(pt)==DA_XZPERIODIC||(pt)==DA_XYZPERIODIC)
106: #define DAYPeriodic(pt) ((pt)==DA_YPERIODIC||(pt)==DA_XYPERIODIC||(pt)==DA_YZPERIODIC||(pt)==DA_XYZPERIODIC)
107: #define DAZPeriodic(pt) ((pt)==DA_ZPERIODIC||(pt)==DA_XZPERIODIC||(pt)==DA_YZPERIODIC||(pt)==DA_XYZPERIODIC)

109: typedef enum { DA_X,DA_Y,DA_Z } DADirection;


113: #define MATSEQUSFFT        "sequsfft"

115: EXTERN PetscErrorCode  DACreate(MPI_Comm,DA*);
116: EXTERN PetscErrorCode  DASetDim(DA,PetscInt);
117: EXTERN PetscErrorCode  DASetSizes(DA,PetscInt,PetscInt,PetscInt);
118: EXTERN PetscErrorCode     DACreate1d(MPI_Comm,DAPeriodicType,PetscInt,PetscInt,PetscInt,const PetscInt[],DA *);
119: EXTERN PetscErrorCode     DACreate2d(MPI_Comm,DAPeriodicType,DAStencilType,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscInt[],DA*);
120: EXTERN PetscErrorCode     DACreate3d(MPI_Comm,DAPeriodicType,DAStencilType,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscInt[],const PetscInt[],DA*);
121: EXTERN PetscErrorCode  DASetOptionsPrefix(DA,const char []);
122: EXTERN PetscErrorCode  DAViewFromOptions(DA, const char []);
123: EXTERN PetscErrorCode  DASetFromOptions(DA);
124: EXTERN PetscErrorCode     DADestroy(DA);
125: EXTERN PetscErrorCode     DAView(DA,PetscViewer);

127: EXTERN PetscErrorCode     DAGlobalToLocalBegin(DA,Vec,InsertMode,Vec);
128: EXTERN PetscErrorCode     DAGlobalToLocalEnd(DA,Vec,InsertMode,Vec);
129: EXTERN PetscErrorCode     DAGlobalToNaturalBegin(DA,Vec,InsertMode,Vec);
130: EXTERN PetscErrorCode     DAGlobalToNaturalEnd(DA,Vec,InsertMode,Vec);
131: EXTERN PetscErrorCode     DANaturalToGlobalBegin(DA,Vec,InsertMode,Vec);
132: EXTERN PetscErrorCode     DANaturalToGlobalEnd(DA,Vec,InsertMode,Vec);
133: EXTERN PetscErrorCode     DALocalToLocalBegin(DA,Vec,InsertMode,Vec);
134: EXTERN PetscErrorCode     DALocalToLocalEnd(DA,Vec,InsertMode,Vec);
135: EXTERN PetscErrorCode     DALocalToGlobal(DA,Vec,InsertMode,Vec);
136: EXTERN PetscErrorCode     DALocalToGlobalBegin(DA,Vec,Vec);
137: EXTERN PetscErrorCode     DALocalToGlobalEnd(DA,Vec,Vec);
138: EXTERN PetscErrorCode     DAGetOwnershipRanges(DA,const PetscInt*[],const PetscInt*[],const PetscInt*[]);
139: EXTERN PetscErrorCode     DACreateGlobalVector(DA,Vec *);
140: EXTERN PetscErrorCode     DACreateLocalVector(DA,Vec *);
141: EXTERN PetscErrorCode     DACreateNaturalVector(DA,Vec *);
142: #define  DAGetLocalVector(da,v)      DMGetLocalVector((DM)da,v)
143: #define  DARestoreLocalVector(da,v)  DMRestoreLocalVector((DM)da,v)
144: #define  DAGetGlobalVector(da,v)     DMGetGlobalVector((DM)da,v)
145: #define  DARestoreGlobalVector(da,v) DMRestoreGlobalVector((DM)da,v)
146: EXTERN PetscErrorCode     DALoad(PetscViewer,PetscInt,PetscInt,PetscInt,DA *);
147: EXTERN PetscErrorCode     DAGetCorners(DA,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*);
148: EXTERN PetscErrorCode     DAGetGhostCorners(DA,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*);
149: EXTERN PetscErrorCode     DAGetInfo(DA,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,DAPeriodicType*,DAStencilType*);
150: EXTERN PetscErrorCode     DAGetProcessorSubset(DA,DADirection,PetscInt,MPI_Comm*);
151: EXTERN PetscErrorCode     DARefine(DA,MPI_Comm,DA*);
152: EXTERN PetscErrorCode     DACoarsen(DA,MPI_Comm,DA*);
153: EXTERN PetscErrorCode     DARefineHierarchy(DA,PetscInt,DA[]);
154: EXTERN PetscErrorCode     DACoarsenHierarchy(DA,PetscInt,DA[]);

156: EXTERN PetscErrorCode     DAGlobalToNaturalAllCreate(DA,VecScatter*);
157: EXTERN PetscErrorCode     DANaturalAllToGlobalCreate(DA,VecScatter*);

159: EXTERN PetscErrorCode     DAGetGlobalIndices(DA,PetscInt*,PetscInt**);
160: EXTERN PetscErrorCode     DAGetISLocalToGlobalMapping(DA,ISLocalToGlobalMapping*);
161: EXTERN PetscErrorCode     DAGetISLocalToGlobalMappingBlck(DA,ISLocalToGlobalMapping*);

163: EXTERN PetscErrorCode     DAGetScatter(DA,VecScatter*,VecScatter*,VecScatter*);
164: EXTERN PetscErrorCode     DAGetNeighbors(DA,const PetscMPIInt**);

166: EXTERN PetscErrorCode     DAGetAO(DA,AO*);
167: EXTERN PetscErrorCode     DASetCoordinates(DA,Vec);
168: EXTERN PetscErrorCode     DAGetCoordinates(DA,Vec *);
169: EXTERN PetscErrorCode     DAGetGhostedCoordinates(DA,Vec *);
170: EXTERN PetscErrorCode     DAGetCoordinateDA(DA,DA *);
171: EXTERN PetscErrorCode     DASetUniformCoordinates(DA,PetscReal,PetscReal,PetscReal,PetscReal,PetscReal,PetscReal);
172: EXTERN PetscErrorCode     DAGetBoundingBox(DA,PetscReal[],PetscReal[]);
173: EXTERN PetscErrorCode     DAGetLocalBoundingBox(DA,PetscReal[],PetscReal[]);
174: EXTERN PetscErrorCode     DASetFieldName(DA,PetscInt,const char[]);
175: EXTERN PetscErrorCode     DAGetFieldName(DA,PetscInt,char **);

177: EXTERN PetscErrorCode  DASetPeriodicity(DA, DAPeriodicType);
178: EXTERN PetscErrorCode  DASetDof(DA, int);
179: EXTERN PetscErrorCode  DASetStencilWidth(DA, int);
180: EXTERN PetscErrorCode  DASetVertexDivision(DA, const PetscInt[], const PetscInt[], const PetscInt[]);
181: EXTERN PetscErrorCode  DASetNumProcs(DA, PetscInt, PetscInt, PetscInt);
182: EXTERN PetscErrorCode  DASetStencilType(DA, DAStencilType);

184: EXTERN PetscErrorCode     DAVecGetArray(DA,Vec,void *);
185: EXTERN PetscErrorCode     DAVecRestoreArray(DA,Vec,void *);

187: EXTERN PetscErrorCode     DAVecGetArrayDOF(DA,Vec,void *);
188: EXTERN PetscErrorCode     DAVecRestoreArrayDOF(DA,Vec,void *);

190: EXTERN PetscErrorCode     DASplitComm2d(MPI_Comm,PetscInt,PetscInt,PetscInt,MPI_Comm*);

192: /* Dynamic creation and loading functions */
195: EXTERN PetscErrorCode  DASetType(DA, const DAType);
196: EXTERN PetscErrorCode  DAGetType(DA, const DAType *);
197: EXTERN PetscErrorCode  DARegister(const char[],const char[],const char[],PetscErrorCode (*)(DA));
198: EXTERN PetscErrorCode  DARegisterAll(const char []);
199: EXTERN PetscErrorCode  DARegisterDestroy(void);

201: /*MC
202:   DARegisterDynamic - Adds a new DA component implementation

204:   Synopsis:
205:   PetscErrorCode DARegisterDynamic(char *name, char *path, char *func_name, PetscErrorCode (*create_func)(DA))

207:   Not Collective

209:   Input Parameters:
210: + name        - The name of a new user-defined creation routine
211: . path        - The path (either absolute or relative) of the library containing this routine
212: . func_name   - The name of routine to create method context
213: - create_func - The creation routine itself

215:   Notes:
216:   DARegisterDynamic() may be called multiple times to add several user-defined DAs

218:   If dynamic libraries are used, then the fourth input argument (routine_create) is ignored.

220:   Sample usage:
221: .vb
222:     DARegisterDynamic("my_da","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyDACreate", MyDACreate);
223: .ve

225:   Then, your DA type can be chosen with the procedural interface via
226: .vb
227:     DACreate(MPI_Comm, DA *);
228:     DASetType(DA,"my_da_name");
229: .ve
230:    or at runtime via the option
231: .vb
232:     -da_type my_da_name
233: .ve

235:   Notes: $PETSC_ARCH occuring in pathname will be replaced with appropriate values.
236:          If your function is not being put into a shared library then use DARegister() instead
237:         
238:   Level: advanced

240: .keywords: DA, register
241: .seealso: DARegisterAll(), DARegisterDestroy(), DARegister()
242: M*/
243: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
244: #define DARegisterDynamic(a,b,c,d) DARegister(a,b,c,0)
245: #else
246: #define DARegisterDynamic(a,b,c,d) DARegister(a,b,c,d)
247: #endif

249: /*S
250:      SDA - This provides a simplified interface to the DA distributed
251:            array object in PETSc. This is intended for people who are
252:            NOT using PETSc vectors or objects but just want to distribute
253:            simple rectangular arrays amoung a number of procesors and have
254:            PETSc handle moving the ghost-values when needed.

256:           In certain applications this can serve as a replacement for 
257:           BlockComm (which is apparently being phased out?).


260:    Level: beginner

262:   Concepts: simplified distributed array

264: .seealso:  SDACreate1d(), SDACreate2d(), SDACreate3d(), SDADestroy(), DA, SDALocalToLocalBegin(),
265:            SDALocalToLocalEnd(), SDAGetCorners(), SDAGetGhostCorners()
266: S*/
267: typedef struct _n_SDA* SDA;

269: EXTERN PetscErrorCode     SDACreate3d(MPI_Comm,DAPeriodicType,DAStencilType,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscInt[],const PetscInt[],SDA*);
270: EXTERN PetscErrorCode     SDACreate2d(MPI_Comm,DAPeriodicType,DAStencilType,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscInt[],SDA*);
271: EXTERN PetscErrorCode     SDACreate1d(MPI_Comm,DAPeriodicType,PetscInt,PetscInt,PetscInt,const PetscInt[],SDA*);
272: EXTERN PetscErrorCode     SDADestroy(SDA);
273: EXTERN PetscErrorCode     SDALocalToLocalBegin(SDA,PetscScalar*,InsertMode,PetscScalar*);
274: EXTERN PetscErrorCode     SDALocalToLocalEnd(SDA,PetscScalar*,InsertMode,PetscScalar*);
275: EXTERN PetscErrorCode     SDAGetCorners(SDA,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*);
276: EXTERN PetscErrorCode     SDAGetGhostCorners(SDA,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*);
277: EXTERN PetscErrorCode     SDAArrayView(SDA,PetscScalar*,PetscViewer);

279: EXTERN PetscErrorCode     MatRegisterDAAD(void);
280: EXTERN PetscErrorCode     MatCreateDAAD(DA,Mat*);
281: EXTERN PetscErrorCode    MatCreateSeqUSFFT(Vec, DA,Mat*);

283: /*S
284:      DALocalInfo - C struct that contains information about a structured grid and a processors logical
285:               location in it.

287:    Level: beginner

289:   Concepts: distributed array

291:   Developer note: Then entries in this struct are int instead of PetscInt so that the elements may
292:                   be extracted in Fortran as if from an integer array

294: .seealso:  DACreate1d(), DACreate2d(), DACreate3d(), DADestroy(), DA, DAGetLocalInfo(), DAGetInfo()
295: S*/
296: typedef struct {
297:   PetscInt       dim,dof,sw;
298:   PetscInt       mx,my,mz;    /* global number of grid points in each direction */
299:   PetscInt       xs,ys,zs;    /* starting pointd of this processor, excluding ghosts */
300:   PetscInt       xm,ym,zm;    /* number of grid points on this processor, excluding ghosts */
301:   PetscInt       gxs,gys,gzs;    /* starting point of this processor including ghosts */
302:   PetscInt       gxm,gym,gzm;    /* number of grid points on this processor including ghosts */
303:   DAPeriodicType pt;
304:   DAStencilType  st;
305:   DA             da;
306: } DALocalInfo;

308: /*MC
309:       DAForEachPointBegin2d - Starts a loop over the local part of a two dimensional DA

311:    Synopsis:
312:    void  DAForEachPointBegin2d(DALocalInfo *info,PetscInt i,PetscInt j);
313:    
314:    Level: intermediate

316: .seealso: DAForEachPointEnd2d(), DAVecGetArray()
317: M*/
318: #define DAForEachPointBegin2d(info,i,j) {\
319:   PetscInt _xints = info->xs,_xinte = info->xs+info->xm,_yints = info->ys,_yinte = info->ys+info->ym;\
320:   for (j=_yints; j<_yinte; j++) {\
321:     for (i=_xints; i<_xinte; i++) {\

323: /*MC
324:       DAForEachPointEnd2d - Ends a loop over the local part of a two dimensional DA

326:    Synopsis:
327:    void  DAForEachPointEnd2d;
328:    
329:    Level: intermediate

331: .seealso: DAForEachPointBegin2d(), DAVecGetArray()
332: M*/
333: #define DAForEachPointEnd2d }}}

335: /*MC
336:       DACoor2d - Structure for holding 2d (x and y) coordinates.

338:     Level: intermediate

340:     Sample Usage:
341:       DACoor2d **coors;
342:       Vec      vcoors;
343:       DA       cda;     

345:       DAGetCoordinates(da,&vcoors); 
346:       DAGetCoordinateDA(da,&cda);
347:       DAVecGetArray(cda,vcoors,&coors);
348:       DAGetCorners(cda,&mstart,&nstart,0,&m,&n,0)
349:       for (i=mstart; i<mstart+m; i++) {
350:         for (j=nstart; j<nstart+n; j++) {
351:           x = coors[j][i].x;
352:           y = coors[j][i].y;
353:           ......
354:         }
355:       }
356:       DAVecRestoreArray(dac,vcoors,&coors);

358: .seealso: DACoor3d, DAForEachPointBegin(), DAGetCoordinateDA(), DAGetCoordinates(), DAGetGhostCoordinates()
359: M*/
360: typedef struct {PetscScalar x,y;} DACoor2d;

362: /*MC
363:       DACoor3d - Structure for holding 3d (x, y and z) coordinates.

365:     Level: intermediate

367:     Sample Usage:
368:       DACoor3d ***coors;
369:       Vec      vcoors;
370:       DA       cda;     

372:       DAGetCoordinates(da,&vcoors); 
373:       DAGetCoordinateDA(da,&cda);
374:       DAVecGetArray(cda,vcoors,&coors);
375:       DAGetCorners(cda,&mstart,&nstart,&pstart,&m,&n,&p)
376:       for (i=mstart; i<mstart+m; i++) {
377:         for (j=nstart; j<nstart+n; j++) {
378:           for (k=pstart; k<pstart+p; k++) {
379:             x = coors[k][j][i].x;
380:             y = coors[k][j][i].y;
381:             z = coors[k][j][i].z;
382:           ......
383:         }
384:       }
385:       DAVecRestoreArray(dac,vcoors,&coors);

387: .seealso: DACoor2d, DAForEachPointBegin(), DAGetCoordinateDA(), DAGetCoordinates(), DAGetGhostCoordinates()
388: M*/
389: typedef struct {PetscScalar x,y,z;} DACoor3d;
390: 
391: EXTERN PetscErrorCode   DAGetLocalInfo(DA,DALocalInfo*);
392: typedef PetscErrorCode (*DALocalFunction1)(DALocalInfo*,void*,void*,void*);
393: EXTERN PetscErrorCode   DAFormFunctionLocal(DA, DALocalFunction1, Vec, Vec, void *);
394: EXTERN PetscErrorCode   DAFormFunctionLocalGhost(DA, DALocalFunction1, Vec, Vec, void *);
395: EXTERN PetscErrorCode   DAFormJacobianLocal(DA, DALocalFunction1, Vec, Mat, void *);
396: EXTERN PetscErrorCode   DAFormFunction1(DA,Vec,Vec,void*);
397: EXTERN PetscErrorCode   DAFormFunction(DA,PetscErrorCode (*)(void),Vec,Vec,void*);
398: EXTERN PetscErrorCode   DAFormFunctioni1(DA,PetscInt,Vec,PetscScalar*,void*);
399: EXTERN PetscErrorCode   DAFormFunctionib1(DA,PetscInt,Vec,PetscScalar*,void*);
400: EXTERN PetscErrorCode   DAComputeJacobian1WithAdic(DA,Vec,Mat,void*);
401: EXTERN PetscErrorCode   DAComputeJacobian1WithAdifor(DA,Vec,Mat,void*);
402: EXTERN PetscErrorCode   DAMultiplyByJacobian1WithAdic(DA,Vec,Vec,Vec,void*);
403: EXTERN PetscErrorCode   DAMultiplyByJacobian1WithAdifor(DA,Vec,Vec,Vec,void*);
404: EXTERN PetscErrorCode   DAMultiplyByJacobian1WithAD(DA,Vec,Vec,Vec,void*);
405: EXTERN PetscErrorCode   DAComputeJacobian1(DA,Vec,Mat,void*);
406: EXTERN PetscErrorCode   DAGetLocalFunction(DA,DALocalFunction1*);
407: EXTERN PetscErrorCode   DASetLocalFunction(DA,DALocalFunction1);
408: EXTERN PetscErrorCode   DASetLocalFunctioni(DA,PetscErrorCode (*)(DALocalInfo*,MatStencil*,void*,PetscScalar*,void*));
409: EXTERN PetscErrorCode   DASetLocalFunctionib(DA,PetscErrorCode (*)(DALocalInfo*,MatStencil*,void*,PetscScalar*,void*));
410: EXTERN PetscErrorCode   DAGetLocalJacobian(DA,DALocalFunction1*);
411: EXTERN PetscErrorCode   DASetLocalJacobian(DA,DALocalFunction1);
412: EXTERN PetscErrorCode   DASetLocalAdicFunction_Private(DA,DALocalFunction1);

414: EXTERN PetscErrorCode  MatSetDA(Mat,DA);

416: /*MC
417:        DASetLocalAdicFunction - Caches in a DA a local function computed by ADIC/ADIFOR

419:    Collective on DA

421:    Synopsis:
422:    PetscErrorCode DASetLocalAdicFunction(DA da,DALocalFunction1 ad_lf)
423:    
424:    Input Parameter:
425: +  da - initial distributed array
426: -  ad_lf - the local function as computed by ADIC/ADIFOR

428:    Level: intermediate

430: .keywords:  distributed array, refine

432: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), DADestroy(), DAGetLocalFunction(), DASetLocalFunction(),
433:           DASetLocalJacobian()
434: M*/
435: #if defined(PETSC_HAVE_ADIC)
436: #  define DASetLocalAdicFunction(a,d) DASetLocalAdicFunction_Private(a,(DALocalFunction1)d)
437: #else
438: #  define DASetLocalAdicFunction(a,d) DASetLocalAdicFunction_Private(a,0)
439: #endif

441: EXTERN PetscErrorCode   DASetLocalAdicMFFunction_Private(DA,DALocalFunction1);
442: #if defined(PETSC_HAVE_ADIC)
443: #  define DASetLocalAdicMFFunction(a,d) DASetLocalAdicMFFunction_Private(a,(DALocalFunction1)d)
444: #else
445: #  define DASetLocalAdicMFFunction(a,d) DASetLocalAdicMFFunction_Private(a,0)
446: #endif
447: EXTERN PetscErrorCode   DASetLocalAdicFunctioni_Private(DA,PetscErrorCode (*)(DALocalInfo*,MatStencil*,void*,void*,void*));
448: #if defined(PETSC_HAVE_ADIC)
449: #  define DASetLocalAdicFunctioni(a,d) DASetLocalAdicFunctioni_Private(a,(PetscErrorCode (*)(DALocalInfo*,MatStencil*,void*,void*,void*))d)
450: #else
451: #  define DASetLocalAdicFunctioni(a,d) DASetLocalAdicFunctioni_Private(a,0)
452: #endif
453: EXTERN PetscErrorCode   DASetLocalAdicMFFunctioni_Private(DA,PetscErrorCode (*)(DALocalInfo*,MatStencil*,void*,void*,void*));
454: #if defined(PETSC_HAVE_ADIC)
455: #  define DASetLocalAdicMFFunctioni(a,d) DASetLocalAdicMFFunctioni_Private(a,(PetscErrorCode (*)(DALocalInfo*,MatStencil*,void*,void*,void*))d)
456: #else
457: #  define DASetLocalAdicMFFunctioni(a,d) DASetLocalAdicMFFunctioni_Private(a,0)
458: #endif

460: EXTERN PetscErrorCode   DASetLocalAdicFunctionib_Private(DA,PetscErrorCode (*)(DALocalInfo*,MatStencil*,void*,void*,void*));
461: #if defined(PETSC_HAVE_ADIC)
462: #  define DASetLocalAdicFunctionib(a,d) DASetLocalAdicFunctionib_Private(a,(PetscErrorCode (*)(DALocalInfo*,MatStencil*,void*,void*,void*))d)
463: #else
464: #  define DASetLocalAdicFunctionib(a,d) DASetLocalAdicFunctionib_Private(a,0)
465: #endif
466: EXTERN PetscErrorCode   DASetLocalAdicMFFunctionib_Private(DA,PetscErrorCode (*)(DALocalInfo*,MatStencil*,void*,void*,void*));
467: #if defined(PETSC_HAVE_ADIC)
468: #  define DASetLocalAdicMFFunctionib(a,d) DASetLocalAdicMFFunctionib_Private(a,(PetscErrorCode (*)(DALocalInfo*,MatStencil*,void*,void*,void*))d)
469: #else
470: #  define DASetLocalAdicMFFunctionib(a,d) DASetLocalAdicMFFunctionib_Private(a,0)
471: #endif

473: EXTERN PetscErrorCode   DAFormFunctioniTest1(DA,void*);

475:  #include petscmat.h

477: /*S
478:      DM - Abstract PETSc object that manages an abstract grid object
479:           
480:    Level: intermediate

482:   Concepts: grids, grid refinement

484:    Notes: The DA object and the DMComposite object are examples of DMs

486:           Though the DA objects require the petscsnes.h include files the DM library is
487:     NOT dependent on the SNES or KSP library. In fact, the KSP and SNES libraries depend on
488:     DM. (This is not great design, but not trivial to fix).

490: .seealso:  DMCompositeCreate(), DA, DMComposite
491: S*/
492: typedef struct _p_DM* DM;

494: EXTERN PetscErrorCode   DMView(DM,PetscViewer);
495: EXTERN PetscErrorCode   DMDestroy(DM);
496: EXTERN PetscErrorCode   DMCreateGlobalVector(DM,Vec*);
497: EXTERN PetscErrorCode   DMCreateLocalVector(DM,Vec*);
498: EXTERN PetscErrorCode   DMGetLocalVector(DM,Vec *);
499: EXTERN PetscErrorCode   DMRestoreLocalVector(DM,Vec *);
500: EXTERN PetscErrorCode   DMGetGlobalVector(DM,Vec *);
501: EXTERN PetscErrorCode   DMRestoreGlobalVector(DM,Vec *);
502: EXTERN PetscErrorCode   DMGetColoring(DM,ISColoringType,const MatType,ISColoring*);
503: EXTERN PetscErrorCode   DMGetMatrix(DM, const MatType,Mat*);
504: EXTERN PetscErrorCode   DMGetInterpolation(DM,DM,Mat*,Vec*);
505: EXTERN PetscErrorCode   DMGetInjection(DM,DM,VecScatter*);
506: EXTERN PetscErrorCode   DMRefine(DM,MPI_Comm,DM*);
507: EXTERN PetscErrorCode   DMCoarsen(DM,MPI_Comm,DM*);
508: EXTERN PetscErrorCode   DMRefineHierarchy(DM,PetscInt,DM[]);
509: EXTERN PetscErrorCode   DMCoarsenHierarchy(DM,PetscInt,DM[]);
510: EXTERN PetscErrorCode   DMGetInterpolationScale(DM,DM,Mat,Vec*);
511: EXTERN PetscErrorCode   DMGetAggregates(DM,DM,Mat*);
512: EXTERN PetscErrorCode   DMGlobalToLocalBegin(DM,Vec,InsertMode,Vec);
513: EXTERN PetscErrorCode   DMGlobalToLocalEnd(DM,Vec,InsertMode,Vec);
514: EXTERN PetscErrorCode   DMLocalToGlobal(DM,Vec,InsertMode,Vec);
515: EXTERN PetscErrorCode   DMGetElements(DM,PetscInt *,const PetscInt*[]);
516: EXTERN PetscErrorCode   DMRestoreElements(DM,PetscInt *,const PetscInt*[]);
517: EXTERN PetscErrorCode   DMFinalizePackage(void);

519: EXTERN PetscErrorCode   DAGetColoring(DA,ISColoringType,const MatType,ISColoring *);
520: EXTERN PetscErrorCode   DAGetMatrix(DA, const MatType,Mat *);
521: EXTERN PetscErrorCode   DASetGetMatrix(DA,PetscErrorCode (*)(DA, const MatType,Mat *));
522: EXTERN PetscErrorCode   DAGetInterpolation(DA,DA,Mat*,Vec*);
523: EXTERN PetscErrorCode   DAGetAggregates(DA,DA,Mat*);
524: EXTERN PetscErrorCode   DAGetInjection(DA,DA,VecScatter*);
525: EXTERN PetscErrorCode   DASetBlockFills(DA,PetscInt*,PetscInt*);
526: EXTERN PetscErrorCode   DASetMatPreallocateOnly(DA,PetscTruth);
527: EXTERN PetscErrorCode   DASetRefinementFactor(DA,PetscInt,PetscInt,PetscInt);
528: EXTERN PetscErrorCode   DAGetRefinementFactor(DA,PetscInt*,PetscInt*,PetscInt*);

530: EXTERN PetscErrorCode   DAGetAdicArray(DA,PetscTruth,void**,void**,PetscInt*);
531: EXTERN PetscErrorCode   DARestoreAdicArray(DA,PetscTruth,void**,void**,PetscInt*);
532: EXTERN PetscErrorCode   DAGetAdicMFArray(DA,PetscTruth,void**,void**,PetscInt*);
533: EXTERN PetscErrorCode   DAGetAdicMFArray4(DA,PetscTruth,void**,void**,PetscInt*);
534: EXTERN PetscErrorCode   DAGetAdicMFArray9(DA,PetscTruth,void**,void**,PetscInt*);
535: EXTERN PetscErrorCode   DAGetAdicMFArrayb(DA,PetscTruth,void**,void**,PetscInt*);
536: EXTERN PetscErrorCode   DARestoreAdicMFArray(DA,PetscTruth,void**,void**,PetscInt*);
537: EXTERN PetscErrorCode   DAGetArray(DA,PetscTruth,void**);
538: EXTERN PetscErrorCode   DARestoreArray(DA,PetscTruth,void**);
539: EXTERN PetscErrorCode   ad_DAGetArray(DA,PetscTruth,void**);
540: EXTERN PetscErrorCode   ad_DARestoreArray(DA,PetscTruth,void**);
541: EXTERN PetscErrorCode   admf_DAGetArray(DA,PetscTruth,void**);
542: EXTERN PetscErrorCode   admf_DARestoreArray(DA,PetscTruth,void**);

544:  #include petscpf.h
545: EXTERN PetscErrorCode   DACreatePF(DA,PF*);

547: /*S
548:      DMComposite - Abstract PETSc object that manages treating several distinct vectors as if they
549:         were one.   The DMComposite routines allow one to manage a nonlinear solver that works on a
550:         vector that consists of several distinct parts. This is mostly used for LNKS solvers, 
551:         that is design optimization problems that are written as a nonlinear system

553:    Level: beginner

555:   Concepts: multi-component, LNKS solvers

557: .seealso:  DMCompositeCreate(), DMCompositeDestroy(), DM
558: S*/
559: typedef struct _p_DMComposite* DMComposite;

561: EXTERN PetscErrorCode   DMCompositeCreate(MPI_Comm,DMComposite*);
562: EXTERN PetscErrorCode   DMCompositeDestroy(DMComposite);
563: EXTERN PetscErrorCode   DMCompositeView(DMComposite,PetscViewer);
564: EXTERN PetscErrorCode   DMCompositeAddArray(DMComposite,PetscMPIInt,PetscInt);
565: EXTERN PetscErrorCode   DMCompositeAddDM(DMComposite,DM);
566: EXTERN PetscErrorCode   DMCompositeSetCoupling(DMComposite,PetscErrorCode (*)(DMComposite,Mat,PetscInt*,PetscInt*,PetscInt,PetscInt,PetscInt,PetscInt));
567: EXTERN PetscErrorCode   DMCompositeSetContext(DMComposite,void*);
568: EXTERN PetscErrorCode   DMCompositeGetContext(DMComposite,void**);
569: EXTERN PetscErrorCode   DMCompositeAddVecScatter(DMComposite,VecScatter);
570: EXTERN PetscErrorCode   DMCompositeScatter(DMComposite,Vec,...);
571: EXTERN PetscErrorCode   DMCompositeGather(DMComposite,Vec,...);
572: EXTERN PetscErrorCode   DMCompositeGetAccess(DMComposite,Vec,...);
573: EXTERN PetscErrorCode   DMCompositeGetNumberDM(DMComposite,PetscInt*);
574: EXTERN PetscErrorCode   DMCompositeRestoreAccess(DMComposite,Vec,...);
575: EXTERN PetscErrorCode   DMCompositeGetLocalVectors(DMComposite,...);
576: EXTERN PetscErrorCode   DMCompositeGetEntries(DMComposite,...);
577: EXTERN PetscErrorCode   DMCompositeRestoreLocalVectors(DMComposite,...);
578: EXTERN PetscErrorCode   DMCompositeCreateGlobalVector(DMComposite,Vec*);
579: EXTERN PetscErrorCode   DMCompositeCreateLocalVector(DMComposite,Vec*);
580: EXTERN PetscErrorCode   DMCompositeGetLocalISs(DMComposite,IS*[]);
581: EXTERN PetscErrorCode   DMCompositeGetGlobalISs(DMComposite,IS*[]);
582: EXTERN PetscErrorCode   DMCompositeRefine(DMComposite,MPI_Comm,DMComposite*);
583: EXTERN PetscErrorCode   DMCompositeGetInterpolation(DMComposite,DMComposite,Mat*,Vec*);
584: EXTERN PetscErrorCode   DMCompositeGetMatrix(DMComposite,const MatType,Mat*);
585: EXTERN PetscErrorCode   DMCompositeGetColoring(DMComposite,ISColoringType,const MatType,ISColoring*);
586: EXTERN PetscErrorCode   DMCompositeGlobalToLocalBegin(DMComposite,Vec,InsertMode,Vec);
587: EXTERN PetscErrorCode   DMCompositeGlobalToLocalEnd(DMComposite,Vec,InsertMode,Vec);

589: /*S
590:      Slice - Abstract PETSc object that manages distributed field data for a simple unstructured matrix

592:    Level: beginner

594:   Concepts: distributed array

596: .seealso:  DACreate1d(), DACreate2d(), DACreate3d(), DADestroy(), VecScatter, DACreate(), DMCompositeCreate(), DMComposite
597: S*/
598: typedef struct _p_Sliced* Sliced;

600: EXTERN PetscErrorCode   SlicedView(Sliced,PetscViewer);
601: EXTERN PetscErrorCode   SlicedCreate(MPI_Comm,Sliced*);
602: EXTERN PetscErrorCode   SlicedDestroy(Sliced);
603: EXTERN PetscErrorCode   SlicedCreateGlobalVector(Sliced,Vec*);
604: EXTERN PetscErrorCode   SlicedGetMatrix(Sliced, const MatType,Mat*);
605: EXTERN PetscErrorCode   SlicedGetGlobalIndices(Sliced,PetscInt*[]);
606: EXTERN PetscErrorCode   SlicedSetPreallocation(Sliced,PetscInt,const PetscInt[],PetscInt,const PetscInt[]);
607: EXTERN PetscErrorCode   SlicedSetBlockFills(Sliced,const PetscInt*,const PetscInt*);
608: EXTERN PetscErrorCode   SlicedSetGhosts(Sliced,PetscInt,PetscInt,PetscInt,const PetscInt[]);


611: typedef struct NLF_DAAD* NLF;

613: #include <petscbag.h>

615: EXTERN PetscErrorCode  PetscViewerBinaryMatlabOpen(MPI_Comm, const char [], PetscViewer*);
616: EXTERN PetscErrorCode  PetscViewerBinaryMatlabDestroy(PetscViewer);
617: EXTERN PetscErrorCode  PetscViewerBinaryMatlabOutputBag(PetscViewer, const char [], PetscBag);
618: EXTERN PetscErrorCode  PetscViewerBinaryMatlabOutputVec(PetscViewer, const char [], Vec);
619: EXTERN PetscErrorCode  PetscViewerBinaryMatlabOutputVecDA(PetscViewer, const char [], Vec, DA);


622: /*S
623:   ADDA - Abstract PETSc object that manages distributed field data for a single structured grid
624:          These are for any number of dimensions.

626:   Level: advanced. 

628:   Concepts: distributed array
629: .seealso: DA, DACreate(), ADDACreate()
630: S*/
631: typedef struct _p_ADDA* ADDA;


635: PetscErrorCode  ADDACreate(MPI_Comm,PetscInt,PetscInt*,PetscInt*,PetscInt,PetscTruth*,ADDA*);
636: PetscErrorCode  ADDADestroy(ADDA);

638: /* DM interface functions */
639: PetscErrorCode  ADDAView(ADDA,PetscViewer);
640: PetscErrorCode  ADDACreateGlobalVector(ADDA,Vec*);
641: PetscErrorCode  ADDAGetColoring(ADDA,ISColoringType,const MatType,ISColoring*);
642: PetscErrorCode  ADDAGetMatrix(ADDA,const MatType, Mat*);
643: PetscErrorCode  ADDAGetInterpolation(ADDA,ADDA,Mat*,Vec*);
644: PetscErrorCode  ADDARefine(ADDA, MPI_Comm,ADDA *);
645: PetscErrorCode  ADDACoarsen(ADDA, MPI_Comm, ADDA*);
646: PetscErrorCode  ADDAGetInjection(ADDA, ADDA, VecScatter*);
647: PetscErrorCode  ADDAGetAggregates(ADDA, ADDA, Mat *);

649: /* functions only supported by ADDA */
650: PetscErrorCode  ADDASetRefinement(ADDA, PetscInt *,PetscInt);
651: PetscErrorCode  ADDAGetCorners(ADDA, PetscInt **, PetscInt **);
652: PetscErrorCode  ADDAGetGhostCorners(ADDA, PetscInt **, PetscInt **);
653: PetscErrorCode  ADDAGetMatrixNS(ADDA, ADDA, const MatType , Mat *);

655: /* functions to set values in vectors and matrices */
656: struct _ADDAIdx_s {
657:   PetscInt     *x;               /* the coordinates, user has to make sure it is the correct size! */
658:   PetscInt     d;                /* indexes the dof */
659: };
660: typedef struct _ADDAIdx_s ADDAIdx;

662: PetscErrorCode  ADDAMatSetValues(Mat, ADDA, PetscInt, const ADDAIdx[], ADDA, PetscInt,
663:                                                   const ADDAIdx[], const PetscScalar[], InsertMode);

665: PetscTruth ADDAHCiterStartup(const PetscInt, const PetscInt *const, const PetscInt *const, PetscInt *const);
666: PetscTruth ADDAHCiter(const PetscInt, const PetscInt *const, const PetscInt *const, PetscInt *const);

669: #endif