147c6ae99SBarry Smith 247c6ae99SBarry Smith /* 347c6ae99SBarry Smith Code for manipulating distributed regular arrays in parallel. 447c6ae99SBarry Smith */ 547c6ae99SBarry Smith 6af0996ceSBarry Smith #include <petsc/private/dmdaimpl.h> /*I "petscdmda.h" I*/ 7f19dbd58SToby Isaac #include <petscdmfield.h> 847c6ae99SBarry Smith 99371c9d4SSatish Balay PetscErrorCode DMCreateCoordinateDM_DA(DM dm, DM *cdm) { 103f2d3b52SPeter Brune PetscFunctionBegin; 119566063dSJacob Faibussowitsch PetscCall(DMDACreateCompatibleDMDA(dm, dm->dim, cdm)); 1247c6ae99SBarry Smith PetscFunctionReturn(0); 1347c6ae99SBarry Smith } 1447c6ae99SBarry Smith 159371c9d4SSatish Balay PetscErrorCode DMCreateCoordinateField_DA(DM dm, DMField *field) { 16f19dbd58SToby Isaac PetscReal gmin[3], gmax[3]; 174d1a973fSToby Isaac PetscScalar corners[24]; 18f19dbd58SToby Isaac PetscInt dim; 19f19dbd58SToby Isaac PetscInt i, j; 20f19dbd58SToby Isaac DM cdm; 21f19dbd58SToby Isaac 22f19dbd58SToby Isaac PetscFunctionBegin; 239566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 24f19dbd58SToby Isaac /* TODO: this is wrong if coordinates are not rectilinear */ 259566063dSJacob Faibussowitsch PetscCall(DMGetBoundingBox(dm, gmin, gmax)); 26f19dbd58SToby Isaac for (i = 0; i < (1 << dim); i++) { 27*ad540459SPierre Jolivet for (j = 0; j < dim; j++) corners[i * dim + j] = (i & (1 << j)) ? gmax[j] : gmin[j]; 28f19dbd58SToby Isaac } 299566063dSJacob Faibussowitsch PetscCall(DMClone(dm, &cdm)); 309566063dSJacob Faibussowitsch PetscCall(DMFieldCreateDA(cdm, dim, corners, field)); 319566063dSJacob Faibussowitsch PetscCall(DMDestroy(&cdm)); 32f19dbd58SToby Isaac PetscFunctionReturn(0); 33f19dbd58SToby Isaac } 34f19dbd58SToby Isaac 3547c6ae99SBarry Smith /*@C 36aa219208SBarry Smith DMDASetFieldName - Sets the names of individual field components in multicomponent 37aa219208SBarry Smith vectors associated with a DMDA. 3847c6ae99SBarry Smith 39b1dd8793SDave May Logically collective; name must contain a common value 4047c6ae99SBarry Smith 4147c6ae99SBarry Smith Input Parameters: 4247c6ae99SBarry Smith + da - the distributed array 43aa219208SBarry Smith . nf - field number for the DMDA (0, 1, ... dof-1), where dof indicates the 44aa219208SBarry Smith number of degrees of freedom per node within the DMDA 4547c6ae99SBarry Smith - names - the name of the field (component) 4647c6ae99SBarry Smith 4795452b02SPatrick Sanan Notes: 4895452b02SPatrick Sanan It must be called after having called DMSetUp(). 493eac1ceeSStefano Zampini 5047c6ae99SBarry Smith Level: intermediate 5147c6ae99SBarry Smith 52db781477SPatrick Sanan .seealso: `DMDAGetFieldName()`, `DMDASetCoordinateName()`, `DMDAGetCoordinateName()`, `DMDASetFieldNames()`, `DMSetUp()` 5347c6ae99SBarry Smith @*/ 549371c9d4SSatish Balay PetscErrorCode DMDASetFieldName(DM da, PetscInt nf, const char name[]) { 5547c6ae99SBarry Smith DM_DA *dd = (DM_DA *)da->data; 5647c6ae99SBarry Smith 5747c6ae99SBarry Smith PetscFunctionBegin; 58a9a02de4SBarry Smith PetscValidHeaderSpecificType(da, DM_CLASSID, 1, DMDA); 591dca8a05SBarry Smith PetscCheck(nf >= 0 && nf < dd->w, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid field number: %" PetscInt_FMT, nf); 607a8be351SBarry Smith PetscCheck(dd->fieldname, PetscObjectComm((PetscObject)da), PETSC_ERR_ORDER, "You should call DMSetUp() first"); 619566063dSJacob Faibussowitsch PetscCall(PetscFree(dd->fieldname[nf])); 629566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, &dd->fieldname[nf])); 6347c6ae99SBarry Smith PetscFunctionReturn(0); 6447c6ae99SBarry Smith } 6547c6ae99SBarry Smith 66c629b14aSBarry Smith /*@C 67c629b14aSBarry Smith DMDAGetFieldNames - Gets the name of each component in the vector associated with the DMDA 68c629b14aSBarry Smith 69b1dd8793SDave May Not collective; names will contain a common value 70c629b14aSBarry Smith 71c629b14aSBarry Smith Input Parameter: 72c629b14aSBarry Smith . dm - the DMDA object 73c629b14aSBarry Smith 74c629b14aSBarry Smith Output Parameter: 75c629b14aSBarry Smith . names - the names of the components, final string is NULL, will have the same number of entries as the dof used in creating the DMDA 76c629b14aSBarry Smith 77c629b14aSBarry Smith Level: intermediate 78c629b14aSBarry Smith 79f5f57ec0SBarry Smith Not supported from Fortran, use DMDAGetFieldName() 80f5f57ec0SBarry Smith 81db781477SPatrick Sanan .seealso: `DMDAGetFieldName()`, `DMDASetCoordinateName()`, `DMDAGetCoordinateName()`, `DMDASetFieldName()`, `DMDASetFieldNames()` 82c629b14aSBarry Smith @*/ 839371c9d4SSatish Balay PetscErrorCode DMDAGetFieldNames(DM da, const char *const **names) { 84c629b14aSBarry Smith DM_DA *dd = (DM_DA *)da->data; 85c629b14aSBarry Smith 86c629b14aSBarry Smith PetscFunctionBegin; 87c629b14aSBarry Smith *names = (const char *const *)dd->fieldname; 88c629b14aSBarry Smith PetscFunctionReturn(0); 89c629b14aSBarry Smith } 90c629b14aSBarry Smith 91c629b14aSBarry Smith /*@C 92c629b14aSBarry Smith DMDASetFieldNames - Sets the name of each component in the vector associated with the DMDA 93c629b14aSBarry Smith 94b1dd8793SDave May Logically collective; names must contain a common value 95c629b14aSBarry Smith 96c629b14aSBarry Smith Input Parameters: 97c629b14aSBarry Smith + dm - the DMDA object 98c629b14aSBarry Smith - names - the names of the components, final string must be NULL, must have the same number of entries as the dof used in creating the DMDA 99c629b14aSBarry Smith 10095452b02SPatrick Sanan Notes: 10195452b02SPatrick Sanan It must be called after having called DMSetUp(). 1023eac1ceeSStefano Zampini 103c629b14aSBarry Smith Level: intermediate 104c629b14aSBarry Smith 105f5f57ec0SBarry Smith Not supported from Fortran, use DMDASetFieldName() 106f5f57ec0SBarry Smith 107db781477SPatrick Sanan .seealso: `DMDAGetFieldName()`, `DMDASetCoordinateName()`, `DMDAGetCoordinateName()`, `DMDASetFieldName()`, `DMSetUp()` 108c629b14aSBarry Smith @*/ 1099371c9d4SSatish Balay PetscErrorCode DMDASetFieldNames(DM da, const char *const *names) { 110c629b14aSBarry Smith DM_DA *dd = (DM_DA *)da->data; 1113eac1ceeSStefano Zampini char **fieldname; 1123eac1ceeSStefano Zampini PetscInt nf = 0; 113c629b14aSBarry Smith 114c629b14aSBarry Smith PetscFunctionBegin; 1157a8be351SBarry Smith PetscCheck(dd->fieldname, PetscObjectComm((PetscObject)da), PETSC_ERR_ORDER, "You should call DMSetUp() first"); 1163eac1ceeSStefano Zampini while (names[nf++]) { }; 11763a3b9bcSJacob Faibussowitsch PetscCheck(nf == dd->w + 1, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid number of fields %" PetscInt_FMT, nf - 1); 1189566063dSJacob Faibussowitsch PetscCall(PetscStrArrayallocpy(names, &fieldname)); 1199566063dSJacob Faibussowitsch PetscCall(PetscStrArrayDestroy(&dd->fieldname)); 1203eac1ceeSStefano Zampini dd->fieldname = fieldname; 121c629b14aSBarry Smith PetscFunctionReturn(0); 122c629b14aSBarry Smith } 123c629b14aSBarry Smith 12447c6ae99SBarry Smith /*@C 125aa219208SBarry Smith DMDAGetFieldName - Gets the names of individual field components in multicomponent 126aa219208SBarry Smith vectors associated with a DMDA. 12747c6ae99SBarry Smith 128b1dd8793SDave May Not collective; name will contain a common value 12947c6ae99SBarry Smith 130d8d19677SJose E. Roman Input Parameters: 13147c6ae99SBarry Smith + da - the distributed array 132aa219208SBarry Smith - nf - field number for the DMDA (0, 1, ... dof-1), where dof indicates the 133aa219208SBarry Smith number of degrees of freedom per node within the DMDA 13447c6ae99SBarry Smith 13547c6ae99SBarry Smith Output Parameter: 13647c6ae99SBarry Smith . names - the name of the field (component) 13747c6ae99SBarry Smith 13895452b02SPatrick Sanan Notes: 13995452b02SPatrick Sanan It must be called after having called DMSetUp(). 1403eac1ceeSStefano Zampini 14147c6ae99SBarry Smith Level: intermediate 14247c6ae99SBarry Smith 143db781477SPatrick Sanan .seealso: `DMDASetFieldName()`, `DMDASetCoordinateName()`, `DMDAGetCoordinateName()`, `DMSetUp()` 14447c6ae99SBarry Smith @*/ 1459371c9d4SSatish Balay PetscErrorCode DMDAGetFieldName(DM da, PetscInt nf, const char **name) { 14647c6ae99SBarry Smith DM_DA *dd = (DM_DA *)da->data; 14747c6ae99SBarry Smith 14847c6ae99SBarry Smith PetscFunctionBegin; 149a9a02de4SBarry Smith PetscValidHeaderSpecificType(da, DM_CLASSID, 1, DMDA); 15047c6ae99SBarry Smith PetscValidPointer(name, 3); 1511dca8a05SBarry Smith PetscCheck(nf >= 0 && nf < dd->w, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid field number: %" PetscInt_FMT, nf); 1527a8be351SBarry Smith PetscCheck(dd->fieldname, PetscObjectComm((PetscObject)da), PETSC_ERR_ORDER, "You should call DMSetUp() first"); 15347c6ae99SBarry Smith *name = dd->fieldname[nf]; 15447c6ae99SBarry Smith PetscFunctionReturn(0); 15547c6ae99SBarry Smith } 15647c6ae99SBarry Smith 157109c9344SBarry Smith /*@C 158109c9344SBarry Smith DMDASetCoordinateName - Sets the name of the coordinate directions associated with a DMDA, for example "x" or "y" 159109c9344SBarry Smith 160b1dd8793SDave May Logically collective; name must contain a common value 161109c9344SBarry Smith 162109c9344SBarry Smith Input Parameters: 163c73cfb54SMatthew G. Knepley + dm - the DM 164109c9344SBarry Smith . nf - coordinate number for the DMDA (0, 1, ... dim-1), 165109c9344SBarry Smith - name - the name of the coordinate 166109c9344SBarry Smith 16795452b02SPatrick Sanan Notes: 16895452b02SPatrick Sanan It must be called after having called DMSetUp(). 1693eac1ceeSStefano Zampini 170109c9344SBarry Smith Level: intermediate 171109c9344SBarry Smith 172f5f57ec0SBarry Smith Not supported from Fortran 173f5f57ec0SBarry Smith 174db781477SPatrick Sanan .seealso: `DMDAGetCoordinateName()`, `DMDASetFieldName()`, `DMDAGetFieldName()`, `DMSetUp()` 175109c9344SBarry Smith @*/ 1769371c9d4SSatish Balay PetscErrorCode DMDASetCoordinateName(DM dm, PetscInt nf, const char name[]) { 177c73cfb54SMatthew G. Knepley DM_DA *dd = (DM_DA *)dm->data; 178109c9344SBarry Smith 179109c9344SBarry Smith PetscFunctionBegin; 180a9a02de4SBarry Smith PetscValidHeaderSpecificType(dm, DM_CLASSID, 1, DMDA); 1811dca8a05SBarry Smith PetscCheck(nf >= 0 && nf < dm->dim, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid coordinate number: %" PetscInt_FMT, nf); 1827a8be351SBarry Smith PetscCheck(dd->coordinatename, PetscObjectComm((PetscObject)dm), PETSC_ERR_ORDER, "You should call DMSetUp() first"); 1839566063dSJacob Faibussowitsch PetscCall(PetscFree(dd->coordinatename[nf])); 1849566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, &dd->coordinatename[nf])); 185109c9344SBarry Smith PetscFunctionReturn(0); 186109c9344SBarry Smith } 187109c9344SBarry Smith 188109c9344SBarry Smith /*@C 189109c9344SBarry Smith DMDAGetCoordinateName - Gets the name of a coodinate direction associated with a DMDA. 190109c9344SBarry Smith 191b1dd8793SDave May Not collective; name will contain a common value 192109c9344SBarry Smith 193d8d19677SJose E. Roman Input Parameters: 194c73cfb54SMatthew G. Knepley + dm - the DM 195109c9344SBarry Smith - nf - number for the DMDA (0, 1, ... dim-1) 196109c9344SBarry Smith 197109c9344SBarry Smith Output Parameter: 198109c9344SBarry Smith . names - the name of the coordinate direction 199109c9344SBarry Smith 20095452b02SPatrick Sanan Notes: 20195452b02SPatrick Sanan It must be called after having called DMSetUp(). 2023eac1ceeSStefano Zampini 203109c9344SBarry Smith Level: intermediate 204109c9344SBarry Smith 205f5f57ec0SBarry Smith Not supported from Fortran 206f5f57ec0SBarry Smith 207db781477SPatrick Sanan .seealso: `DMDASetCoordinateName()`, `DMDASetFieldName()`, `DMDAGetFieldName()`, `DMSetUp()` 208109c9344SBarry Smith @*/ 2099371c9d4SSatish Balay PetscErrorCode DMDAGetCoordinateName(DM dm, PetscInt nf, const char **name) { 210c73cfb54SMatthew G. Knepley DM_DA *dd = (DM_DA *)dm->data; 211109c9344SBarry Smith 212109c9344SBarry Smith PetscFunctionBegin; 213a9a02de4SBarry Smith PetscValidHeaderSpecificType(dm, DM_CLASSID, 1, DMDA); 214109c9344SBarry Smith PetscValidPointer(name, 3); 2151dca8a05SBarry Smith PetscCheck(nf >= 0 && nf < dm->dim, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid coordinate number: %" PetscInt_FMT, nf); 2167a8be351SBarry Smith PetscCheck(dd->coordinatename, PetscObjectComm((PetscObject)dm), PETSC_ERR_ORDER, "You should call DMSetUp() first"); 217109c9344SBarry Smith *name = dd->coordinatename[nf]; 218109c9344SBarry Smith PetscFunctionReturn(0); 219109c9344SBarry Smith } 220109c9344SBarry Smith 221a5d1443cSVincent Le Chenadec /*@C 222aa219208SBarry Smith DMDAGetCorners - Returns the global (x,y,z) indices of the lower left 22359f3ab6dSMatthew G. Knepley corner and size of the local region, excluding ghost points. 22447c6ae99SBarry Smith 225b1dd8793SDave May Not collective 22647c6ae99SBarry Smith 22747c6ae99SBarry Smith Input Parameter: 22847c6ae99SBarry Smith . da - the distributed array 22947c6ae99SBarry Smith 23047c6ae99SBarry Smith Output Parameters: 2316b867d5aSJose E. Roman + x - the corner index for the first dimension 2326b867d5aSJose E. Roman . y - the corner index for the second dimension (only used in 2D and 3D problems) 2336b867d5aSJose E. Roman . z - the corner index for the third dimension (only used in 3D problems) 2346b867d5aSJose E. Roman . m - the width in the first dimension 2356b867d5aSJose E. Roman . n - the width in the second dimension (only used in 2D and 3D problems) 2366b867d5aSJose E. Roman - p - the width in the third dimension (only used in 3D problems) 23747c6ae99SBarry Smith 23847c6ae99SBarry Smith Note: 23947c6ae99SBarry Smith The corner information is independent of the number of degrees of 240aa219208SBarry Smith freedom per node set with the DMDACreateXX() routine. Thus the x, y, z, and 24147c6ae99SBarry Smith m, n, p can be thought of as coordinates on a logical grid, where each 24247c6ae99SBarry Smith grid point has (potentially) several degrees of freedom. 2430298fd71SBarry Smith Any of y, z, n, and p can be passed in as NULL if not needed. 24447c6ae99SBarry Smith 24547c6ae99SBarry Smith Level: beginner 24647c6ae99SBarry Smith 247db781477SPatrick Sanan .seealso: `DMDAGetGhostCorners()`, `DMDAGetOwnershipRanges()`, `DMStagGetCorners()` 24847c6ae99SBarry Smith @*/ 2499371c9d4SSatish Balay PetscErrorCode DMDAGetCorners(DM da, PetscInt *x, PetscInt *y, PetscInt *z, PetscInt *m, PetscInt *n, PetscInt *p) { 25047c6ae99SBarry Smith PetscInt w; 25147c6ae99SBarry Smith DM_DA *dd = (DM_DA *)da->data; 25247c6ae99SBarry Smith 25347c6ae99SBarry Smith PetscFunctionBegin; 254a9a02de4SBarry Smith PetscValidHeaderSpecificType(da, DM_CLASSID, 1, DMDA); 25547c6ae99SBarry Smith /* since the xs, xe ... have all been multiplied by the number of degrees 25647c6ae99SBarry Smith of freedom per cell, w = dd->w, we divide that out before returning.*/ 25747c6ae99SBarry Smith w = dd->w; 25859bc5b24SSatish Balay if (x) *x = dd->xs / w + dd->xo; 25947c6ae99SBarry Smith /* the y and z have NOT been multiplied by w */ 26059bc5b24SSatish Balay if (y) *y = dd->ys + dd->yo; 26159bc5b24SSatish Balay if (z) *z = dd->zs + dd->zo; 26259bc5b24SSatish Balay if (m) *m = (dd->xe - dd->xs) / w; 26359bc5b24SSatish Balay if (n) *n = (dd->ye - dd->ys); 26459bc5b24SSatish Balay if (p) *p = (dd->ze - dd->zs); 26547c6ae99SBarry Smith PetscFunctionReturn(0); 26647c6ae99SBarry Smith } 26747c6ae99SBarry Smith 2689371c9d4SSatish Balay PetscErrorCode DMGetLocalBoundingIndices_DMDA(DM dm, PetscReal lmin[], PetscReal lmax[]) { 2697324c66bSJed Brown DMDALocalInfo info; 27047c6ae99SBarry Smith 27147c6ae99SBarry Smith PetscFunctionBegin; 2729566063dSJacob Faibussowitsch PetscCall(DMDAGetLocalInfo(dm, &info)); 273b2e4378dSMatthew G. Knepley lmin[0] = info.xs; 274b2e4378dSMatthew G. Knepley lmin[1] = info.ys; 275b2e4378dSMatthew G. Knepley lmin[2] = info.zs; 276b2e4378dSMatthew G. Knepley lmax[0] = info.xs + info.xm - 1; 277b2e4378dSMatthew G. Knepley lmax[1] = info.ys + info.ym - 1; 278b2e4378dSMatthew G. Knepley lmax[2] = info.zs + info.zm - 1; 27947c6ae99SBarry Smith PetscFunctionReturn(0); 28047c6ae99SBarry Smith } 281bc2bf880SBarry Smith 282bc2bf880SBarry Smith /*@ 28383d91586SPatrick Sanan DMDAGetReducedDMDA - Deprecated; use DMDACreateCompatibleDMDA() 28483d91586SPatrick Sanan 28583d91586SPatrick Sanan Level: deprecated 28683d91586SPatrick Sanan @*/ 2879371c9d4SSatish Balay PetscErrorCode DMDAGetReducedDMDA(DM da, PetscInt nfields, DM *nda) { 28883d91586SPatrick Sanan PetscFunctionBegin; 2899566063dSJacob Faibussowitsch PetscCall(DMDACreateCompatibleDMDA(da, nfields, nda)); 29083d91586SPatrick Sanan PetscFunctionReturn(0); 29183d91586SPatrick Sanan } 29283d91586SPatrick Sanan 29383d91586SPatrick Sanan /*@ 294211d3afbSPatrick Sanan DMDACreateCompatibleDMDA - Creates a DMDA with the same layout but with fewer or more fields 295bc2bf880SBarry Smith 296b1dd8793SDave May Collective 297bc2bf880SBarry Smith 298907376e6SBarry Smith Input Parameters: 299bc2bf880SBarry Smith + da - the distributed array 300907376e6SBarry Smith - nfields - number of fields in new DMDA 301bc2bf880SBarry Smith 302bc2bf880SBarry Smith Output Parameter: 303bc2bf880SBarry Smith . nda - the new DMDA 304bc2bf880SBarry Smith 305bc2bf880SBarry Smith Level: intermediate 306bc2bf880SBarry Smith 307db781477SPatrick Sanan .seealso: `DMDAGetGhostCorners()`, `DMSetCoordinates()`, `DMDASetUniformCoordinates()`, `DMGetCoordinates()`, `DMDAGetGhostedCoordinates()`, `DMStagCreateCompatibleDMStag()` 308bc2bf880SBarry Smith @*/ 3099371c9d4SSatish Balay PetscErrorCode DMDACreateCompatibleDMDA(DM da, PetscInt nfields, DM *nda) { 310bc2bf880SBarry Smith DM_DA *dd = (DM_DA *)da->data; 31195c13181SPeter Brune PetscInt s, m, n, p, M, N, P, dim, Mo, No, Po; 312320964c4SBlaise Bourdin const PetscInt *lx, *ly, *lz; 313bff4a2f0SMatthew G. Knepley DMBoundaryType bx, by, bz; 314320964c4SBlaise Bourdin DMDAStencilType stencil_type; 3156858538eSMatthew G. Knepley Vec coords; 31695c13181SPeter Brune PetscInt ox, oy, oz; 31795c13181SPeter Brune PetscInt cl, rl; 318320964c4SBlaise Bourdin 319320964c4SBlaise Bourdin PetscFunctionBegin; 320c73cfb54SMatthew G. Knepley dim = da->dim; 32195c13181SPeter Brune M = dd->M; 32295c13181SPeter Brune N = dd->N; 32395c13181SPeter Brune P = dd->P; 32495c13181SPeter Brune m = dd->m; 32595c13181SPeter Brune n = dd->n; 32695c13181SPeter Brune p = dd->p; 32795c13181SPeter Brune s = dd->s; 32895c13181SPeter Brune bx = dd->bx; 32995c13181SPeter Brune by = dd->by; 33095c13181SPeter Brune bz = dd->bz; 3318865f1eaSKarl Rupp 33295c13181SPeter Brune stencil_type = dd->stencil_type; 3338865f1eaSKarl Rupp 3349566063dSJacob Faibussowitsch PetscCall(DMDAGetOwnershipRanges(da, &lx, &ly, &lz)); 335320964c4SBlaise Bourdin if (dim == 1) { 3369566063dSJacob Faibussowitsch PetscCall(DMDACreate1d(PetscObjectComm((PetscObject)da), bx, M, nfields, s, dd->lx, nda)); 337320964c4SBlaise Bourdin } else if (dim == 2) { 3389566063dSJacob Faibussowitsch PetscCall(DMDACreate2d(PetscObjectComm((PetscObject)da), bx, by, stencil_type, M, N, m, n, nfields, s, lx, ly, nda)); 339320964c4SBlaise Bourdin } else if (dim == 3) { 3409566063dSJacob Faibussowitsch PetscCall(DMDACreate3d(PetscObjectComm((PetscObject)da), bx, by, bz, stencil_type, M, N, P, m, n, p, nfields, s, lx, ly, lz, nda)); 341bc2bf880SBarry Smith } 3429566063dSJacob Faibussowitsch PetscCall(DMSetUp(*nda)); 3436858538eSMatthew G. Knepley PetscCall(DMGetCoordinates(da, &coords)); 3446858538eSMatthew G. Knepley PetscCall(DMSetCoordinates(*nda, coords)); 34595c13181SPeter Brune 34695c13181SPeter Brune /* allow for getting a reduced DA corresponding to a domain decomposition */ 3479566063dSJacob Faibussowitsch PetscCall(DMDAGetOffset(da, &ox, &oy, &oz, &Mo, &No, &Po)); 3489566063dSJacob Faibussowitsch PetscCall(DMDASetOffset(*nda, ox, oy, oz, Mo, No, Po)); 34995c13181SPeter Brune 35095c13181SPeter Brune /* allow for getting a reduced DA corresponding to a coarsened DA */ 3519566063dSJacob Faibussowitsch PetscCall(DMGetCoarsenLevel(da, &cl)); 3529566063dSJacob Faibussowitsch PetscCall(DMGetRefineLevel(da, &rl)); 3538865f1eaSKarl Rupp 35495c13181SPeter Brune (*nda)->levelup = rl; 35595c13181SPeter Brune (*nda)->leveldown = cl; 356bc2bf880SBarry Smith PetscFunctionReturn(0); 357bc2bf880SBarry Smith } 358bc2bf880SBarry Smith 359c593f006SBarry Smith /*@C 360c593f006SBarry Smith DMDAGetCoordinateArray - Gets an array containing the coordinates of the DMDA 361c593f006SBarry Smith 362b1dd8793SDave May Not collective 363c593f006SBarry Smith 364c593f006SBarry Smith Input Parameter: 365c593f006SBarry Smith . dm - the DM 366c593f006SBarry Smith 367c593f006SBarry Smith Output Parameter: 368c593f006SBarry Smith . xc - the coordinates 369c593f006SBarry Smith 370c593f006SBarry Smith Level: intermediate 371c593f006SBarry Smith 372f5f57ec0SBarry Smith Not supported from Fortran 373f5f57ec0SBarry Smith 374db781477SPatrick Sanan .seealso: `DMDASetCoordinateName()`, `DMDASetFieldName()`, `DMDAGetFieldName()`, `DMDARestoreCoordinateArray()` 375c593f006SBarry Smith @*/ 3769371c9d4SSatish Balay PetscErrorCode DMDAGetCoordinateArray(DM dm, void *xc) { 377c593f006SBarry Smith DM cdm; 378c593f006SBarry Smith Vec x; 379c593f006SBarry Smith 380c593f006SBarry Smith PetscFunctionBegin; 381c593f006SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3829566063dSJacob Faibussowitsch PetscCall(DMGetCoordinates(dm, &x)); 3839566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateDM(dm, &cdm)); 3849566063dSJacob Faibussowitsch PetscCall(DMDAVecGetArray(cdm, x, xc)); 385c593f006SBarry Smith PetscFunctionReturn(0); 386c593f006SBarry Smith } 387c593f006SBarry Smith 388c593f006SBarry Smith /*@C 389c593f006SBarry Smith DMDARestoreCoordinateArray - Sets an array containing the coordinates of the DMDA 390c593f006SBarry Smith 391b1dd8793SDave May Not collective 392c593f006SBarry Smith 393d8d19677SJose E. Roman Input Parameters: 394c593f006SBarry Smith + dm - the DM 395c593f006SBarry Smith - xc - the coordinates 396c593f006SBarry Smith 397c593f006SBarry Smith Level: intermediate 398c593f006SBarry Smith 399f5f57ec0SBarry Smith Not supported from Fortran 400f5f57ec0SBarry Smith 401db781477SPatrick Sanan .seealso: `DMDASetCoordinateName()`, `DMDASetFieldName()`, `DMDAGetFieldName()`, `DMDAGetCoordinateArray()` 402c593f006SBarry Smith @*/ 4039371c9d4SSatish Balay PetscErrorCode DMDARestoreCoordinateArray(DM dm, void *xc) { 404c593f006SBarry Smith DM cdm; 405c593f006SBarry Smith Vec x; 406c593f006SBarry Smith 407c593f006SBarry Smith PetscFunctionBegin; 408c593f006SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 4099566063dSJacob Faibussowitsch PetscCall(DMGetCoordinates(dm, &x)); 4109566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateDM(dm, &cdm)); 4119566063dSJacob Faibussowitsch PetscCall(DMDAVecRestoreArray(cdm, x, xc)); 412c593f006SBarry Smith PetscFunctionReturn(0); 413c593f006SBarry Smith } 414