147c6ae99SBarry Smith /* 247c6ae99SBarry Smith Code for manipulating distributed regular arrays in parallel. 347c6ae99SBarry Smith */ 447c6ae99SBarry Smith 5af0996ceSBarry Smith #include <petsc/private/dmdaimpl.h> /*I "petscdmda.h" I*/ 6f19dbd58SToby Isaac #include <petscdmfield.h> 747c6ae99SBarry Smith 8d71ae5a4SJacob Faibussowitsch PetscErrorCode DMCreateCoordinateDM_DA(DM dm, DM *cdm) 9d71ae5a4SJacob Faibussowitsch { 10dd4c3f67SMatthew G. Knepley const char *prefix; 11dd4c3f67SMatthew G. Knepley 123f2d3b52SPeter Brune PetscFunctionBegin; 139566063dSJacob Faibussowitsch PetscCall(DMDACreateCompatibleDMDA(dm, dm->dim, cdm)); 14dd4c3f67SMatthew G. Knepley PetscCall(PetscObjectGetOptionsPrefix((PetscObject)dm, &prefix)); 15dd4c3f67SMatthew G. Knepley PetscCall(PetscObjectSetOptionsPrefix((PetscObject)*cdm, prefix)); 16dd4c3f67SMatthew G. Knepley PetscCall(PetscObjectAppendOptionsPrefix((PetscObject)*cdm, "cdm_")); 173ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1847c6ae99SBarry Smith } 1947c6ae99SBarry Smith 2047c6ae99SBarry Smith /*@C 21aa219208SBarry Smith DMDASetFieldName - Sets the names of individual field components in multicomponent 22dce8aebaSBarry Smith vectors associated with a `DMDA`. 2347c6ae99SBarry Smith 2420f4b53cSBarry Smith Logically Collective; name must contain a common value 2547c6ae99SBarry Smith 2647c6ae99SBarry Smith Input Parameters: 2772fd0fbdSBarry Smith + da - the `DMDA` 28dce8aebaSBarry Smith . nf - field number for the `DMDA` (0, 1, ... dof-1), where dof indicates the 29dce8aebaSBarry Smith number of degrees of freedom per node within the `DMDA` 3060225df5SJacob Faibussowitsch - name - the name of the field (component) 3147c6ae99SBarry Smith 3247c6ae99SBarry Smith Level: intermediate 3347c6ae99SBarry Smith 34dce8aebaSBarry Smith Note: 35dce8aebaSBarry Smith It must be called after having called `DMSetUp()`. 36dce8aebaSBarry Smith 3712b4a537SBarry Smith .seealso: [](sec_struct), `DM`, `DMDA`, `DMDAGetFieldName()`, `DMDASetCoordinateName()`, `DMDAGetCoordinateName()`, `DMDASetFieldNames()`, `DMSetUp()` 3847c6ae99SBarry Smith @*/ 39d71ae5a4SJacob Faibussowitsch PetscErrorCode DMDASetFieldName(DM da, PetscInt nf, const char name[]) 40d71ae5a4SJacob Faibussowitsch { 4147c6ae99SBarry Smith DM_DA *dd = (DM_DA *)da->data; 4247c6ae99SBarry Smith 4347c6ae99SBarry Smith PetscFunctionBegin; 44a9a02de4SBarry Smith PetscValidHeaderSpecificType(da, DM_CLASSID, 1, DMDA); 451dca8a05SBarry Smith PetscCheck(nf >= 0 && nf < dd->w, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid field number: %" PetscInt_FMT, nf); 467a8be351SBarry Smith PetscCheck(dd->fieldname, PetscObjectComm((PetscObject)da), PETSC_ERR_ORDER, "You should call DMSetUp() first"); 479566063dSJacob Faibussowitsch PetscCall(PetscFree(dd->fieldname[nf])); 489566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, &dd->fieldname[nf])); 493ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 5047c6ae99SBarry Smith } 5147c6ae99SBarry Smith 52c629b14aSBarry Smith /*@C 5372fd0fbdSBarry Smith DMDAGetFieldNames - Gets the name of all the components in the vector associated with the `DMDA` 54c629b14aSBarry Smith 5520f4b53cSBarry Smith Not Collective; names will contain a common value; No Fortran Support 56c629b14aSBarry Smith 57c629b14aSBarry Smith Input Parameter: 5860225df5SJacob Faibussowitsch . da - the `DMDA` object 59c629b14aSBarry Smith 60c629b14aSBarry Smith Output Parameter: 6120f4b53cSBarry 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` 62c629b14aSBarry Smith 63c629b14aSBarry Smith Level: intermediate 64c629b14aSBarry Smith 6512b4a537SBarry Smith Fortran Note: 6620f4b53cSBarry Smith Use `DMDAGetFieldName()` 67f5f57ec0SBarry Smith 6812b4a537SBarry Smith .seealso: [](sec_struct), `DM`, `DMDA`, `DMDAGetFieldName()`, `DMDASetCoordinateName()`, `DMDAGetCoordinateName()`, `DMDASetFieldName()`, `DMDASetFieldNames()` 69c629b14aSBarry Smith @*/ 70d71ae5a4SJacob Faibussowitsch PetscErrorCode DMDAGetFieldNames(DM da, const char *const **names) 71d71ae5a4SJacob Faibussowitsch { 72c629b14aSBarry Smith DM_DA *dd = (DM_DA *)da->data; 73c629b14aSBarry Smith 74c629b14aSBarry Smith PetscFunctionBegin; 75c629b14aSBarry Smith *names = (const char *const *)dd->fieldname; 763ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 77c629b14aSBarry Smith } 78c629b14aSBarry Smith 79c629b14aSBarry Smith /*@C 8072fd0fbdSBarry Smith DMDASetFieldNames - Sets the name of each component in the vector associated with the `DMDA` 81c629b14aSBarry Smith 8220f4b53cSBarry Smith Logically Collective; names must contain a common value; No Fortran Support 83c629b14aSBarry Smith 84c629b14aSBarry Smith Input Parameters: 8560225df5SJacob Faibussowitsch + da - the `DMDA` object 8612b4a537SBarry 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` 873eac1ceeSStefano Zampini 88c629b14aSBarry Smith Level: intermediate 89c629b14aSBarry Smith 90dce8aebaSBarry Smith Note: 91dce8aebaSBarry Smith It must be called after having called `DMSetUp()`. 92f5f57ec0SBarry Smith 9312b4a537SBarry Smith Fortran Note: 9420f4b53cSBarry Smith Use `DMDASetFieldName()` 95dce8aebaSBarry Smith 9612b4a537SBarry Smith .seealso: [](sec_struct), `DM`, `DMDA`, `DMDAGetFieldName()`, `DMDASetCoordinateName()`, `DMDAGetCoordinateName()`, `DMDASetFieldName()`, `DMSetUp()` 97c629b14aSBarry Smith @*/ 98d71ae5a4SJacob Faibussowitsch PetscErrorCode DMDASetFieldNames(DM da, const char *const *names) 99d71ae5a4SJacob Faibussowitsch { 100c629b14aSBarry Smith DM_DA *dd = (DM_DA *)da->data; 1013eac1ceeSStefano Zampini char **fieldname; 1023eac1ceeSStefano Zampini PetscInt nf = 0; 103c629b14aSBarry Smith 104c629b14aSBarry Smith PetscFunctionBegin; 1057a8be351SBarry Smith PetscCheck(dd->fieldname, PetscObjectComm((PetscObject)da), PETSC_ERR_ORDER, "You should call DMSetUp() first"); 106a8f51744SPierre Jolivet while (names[nf++]) { } 10763a3b9bcSJacob Faibussowitsch PetscCheck(nf == dd->w + 1, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid number of fields %" PetscInt_FMT, nf - 1); 1089566063dSJacob Faibussowitsch PetscCall(PetscStrArrayallocpy(names, &fieldname)); 1099566063dSJacob Faibussowitsch PetscCall(PetscStrArrayDestroy(&dd->fieldname)); 1103eac1ceeSStefano Zampini dd->fieldname = fieldname; 1113ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 112c629b14aSBarry Smith } 113c629b14aSBarry Smith 11447c6ae99SBarry Smith /*@C 115aa219208SBarry Smith DMDAGetFieldName - Gets the names of individual field components in multicomponent 116dce8aebaSBarry Smith vectors associated with a `DMDA`. 11747c6ae99SBarry Smith 11820f4b53cSBarry Smith Not Collective; name will contain a common value 11947c6ae99SBarry Smith 120d8d19677SJose E. Roman Input Parameters: 12172fd0fbdSBarry Smith + da - the `DMDA` 122dce8aebaSBarry Smith - nf - field number for the `DMDA` (0, 1, ... dof-1), where dof indicates the 123dce8aebaSBarry Smith number of degrees of freedom per node within the `DMDA` 12447c6ae99SBarry Smith 12547c6ae99SBarry Smith Output Parameter: 12660225df5SJacob Faibussowitsch . name - the name of the field (component) 12747c6ae99SBarry Smith 12847c6ae99SBarry Smith Level: intermediate 12947c6ae99SBarry Smith 130dce8aebaSBarry Smith Note: 131dce8aebaSBarry Smith It must be called after having called `DMSetUp()`. 132dce8aebaSBarry Smith 13312b4a537SBarry Smith .seealso: [](sec_struct), `DM`, `DMDA`, `DMDASetFieldName()`, `DMDASetCoordinateName()`, `DMDAGetCoordinateName()`, `DMSetUp()` 13447c6ae99SBarry Smith @*/ 135d71ae5a4SJacob Faibussowitsch PetscErrorCode DMDAGetFieldName(DM da, PetscInt nf, const char **name) 136d71ae5a4SJacob Faibussowitsch { 13747c6ae99SBarry Smith DM_DA *dd = (DM_DA *)da->data; 13847c6ae99SBarry Smith 13947c6ae99SBarry Smith PetscFunctionBegin; 140a9a02de4SBarry Smith PetscValidHeaderSpecificType(da, DM_CLASSID, 1, DMDA); 1414f572ea9SToby Isaac PetscAssertPointer(name, 3); 1421dca8a05SBarry Smith PetscCheck(nf >= 0 && nf < dd->w, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid field number: %" PetscInt_FMT, nf); 1437a8be351SBarry Smith PetscCheck(dd->fieldname, PetscObjectComm((PetscObject)da), PETSC_ERR_ORDER, "You should call DMSetUp() first"); 14447c6ae99SBarry Smith *name = dd->fieldname[nf]; 1453ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 14647c6ae99SBarry Smith } 14747c6ae99SBarry Smith 148109c9344SBarry Smith /*@C 149dce8aebaSBarry Smith DMDASetCoordinateName - Sets the name of the coordinate directions associated with a `DMDA`, for example "x" or "y" 150109c9344SBarry Smith 15120f4b53cSBarry Smith Logically Collective; name must contain a common value; No Fortran Support 152109c9344SBarry Smith 153109c9344SBarry Smith Input Parameters: 154dce8aebaSBarry Smith + dm - the `DMDA` 15512b4a537SBarry Smith . nf - coordinate number for the `DMDA` (0, 1, ... dim-1), 156109c9344SBarry Smith - name - the name of the coordinate 157109c9344SBarry Smith 158109c9344SBarry Smith Level: intermediate 159109c9344SBarry Smith 160dce8aebaSBarry Smith Note: 16120f4b53cSBarry Smith Must be called after having called `DMSetUp()`. 162f5f57ec0SBarry Smith 16312b4a537SBarry Smith .seealso: [](sec_struct), `DM`, `DMDA`, `DMDAGetCoordinateName()`, `DMDASetFieldName()`, `DMDAGetFieldName()`, `DMSetUp()` 164109c9344SBarry Smith @*/ 165d71ae5a4SJacob Faibussowitsch PetscErrorCode DMDASetCoordinateName(DM dm, PetscInt nf, const char name[]) 166d71ae5a4SJacob Faibussowitsch { 167c73cfb54SMatthew G. Knepley DM_DA *dd = (DM_DA *)dm->data; 168109c9344SBarry Smith 169109c9344SBarry Smith PetscFunctionBegin; 170a9a02de4SBarry Smith PetscValidHeaderSpecificType(dm, DM_CLASSID, 1, DMDA); 1711dca8a05SBarry Smith PetscCheck(nf >= 0 && nf < dm->dim, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid coordinate number: %" PetscInt_FMT, nf); 1727a8be351SBarry Smith PetscCheck(dd->coordinatename, PetscObjectComm((PetscObject)dm), PETSC_ERR_ORDER, "You should call DMSetUp() first"); 1739566063dSJacob Faibussowitsch PetscCall(PetscFree(dd->coordinatename[nf])); 1749566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, &dd->coordinatename[nf])); 1753ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 176109c9344SBarry Smith } 177109c9344SBarry Smith 178109c9344SBarry Smith /*@C 179da81f932SPierre Jolivet DMDAGetCoordinateName - Gets the name of a coordinate direction associated with a `DMDA`. 180109c9344SBarry Smith 18120f4b53cSBarry Smith Not Collective; name will contain a common value; No Fortran Support 182109c9344SBarry Smith 183d8d19677SJose E. Roman Input Parameters: 184dce8aebaSBarry Smith + dm - the `DMDA` 18520f4b53cSBarry Smith - nf - number for the `DMDA` (0, 1, ... dim-1) 186109c9344SBarry Smith 187109c9344SBarry Smith Output Parameter: 18860225df5SJacob Faibussowitsch . name - the name of the coordinate direction 189109c9344SBarry Smith 190109c9344SBarry Smith Level: intermediate 191109c9344SBarry Smith 192dce8aebaSBarry Smith Note: 193dce8aebaSBarry Smith It must be called after having called `DMSetUp()`. 194dce8aebaSBarry Smith 19512b4a537SBarry Smith .seealso: [](sec_struct), `DM`, `DMDA`, `DMDASetCoordinateName()`, `DMDASetFieldName()`, `DMDAGetFieldName()`, `DMSetUp()` 196109c9344SBarry Smith @*/ 197d71ae5a4SJacob Faibussowitsch PetscErrorCode DMDAGetCoordinateName(DM dm, PetscInt nf, const char **name) 198d71ae5a4SJacob Faibussowitsch { 199c73cfb54SMatthew G. Knepley DM_DA *dd = (DM_DA *)dm->data; 200109c9344SBarry Smith 201109c9344SBarry Smith PetscFunctionBegin; 202a9a02de4SBarry Smith PetscValidHeaderSpecificType(dm, DM_CLASSID, 1, DMDA); 2034f572ea9SToby Isaac PetscAssertPointer(name, 3); 2041dca8a05SBarry Smith PetscCheck(nf >= 0 && nf < dm->dim, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid coordinate number: %" PetscInt_FMT, nf); 2057a8be351SBarry Smith PetscCheck(dd->coordinatename, PetscObjectComm((PetscObject)dm), PETSC_ERR_ORDER, "You should call DMSetUp() first"); 206109c9344SBarry Smith *name = dd->coordinatename[nf]; 2073ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 208109c9344SBarry Smith } 209109c9344SBarry Smith 210a5d1443cSVincent Le Chenadec /*@C 21112b4a537SBarry Smith DMDAGetCorners - Returns the global (`x`,`y`,`z`) indices of the lower left 21259f3ab6dSMatthew G. Knepley corner and size of the local region, excluding ghost points. 21347c6ae99SBarry Smith 21420f4b53cSBarry Smith Not Collective 21547c6ae99SBarry Smith 21647c6ae99SBarry Smith Input Parameter: 21772fd0fbdSBarry Smith . da - the `DMDA` 21847c6ae99SBarry Smith 21947c6ae99SBarry Smith Output Parameters: 2206b867d5aSJose E. Roman + x - the corner index for the first dimension 2216b867d5aSJose E. Roman . y - the corner index for the second dimension (only used in 2D and 3D problems) 2226b867d5aSJose E. Roman . z - the corner index for the third dimension (only used in 3D problems) 2236b867d5aSJose E. Roman . m - the width in the first dimension 2246b867d5aSJose E. Roman . n - the width in the second dimension (only used in 2D and 3D problems) 2256b867d5aSJose E. Roman - p - the width in the third dimension (only used in 3D problems) 22647c6ae99SBarry Smith 227dce8aebaSBarry Smith Level: beginner 228dce8aebaSBarry Smith 229*f13dfd9eSBarry Smith Notes: 230*f13dfd9eSBarry Smith Any of `y`, `z`, `n`, and `p` can be passed in as `NULL` if not needed. 231*f13dfd9eSBarry Smith 23247c6ae99SBarry Smith The corner information is independent of the number of degrees of 23372fd0fbdSBarry Smith freedom per node set with the `DMDACreateXX()` routine. Thus the `x`, `y`, and `z` 23472fd0fbdSBarry Smith can be thought of as the lower left coordinates of the patch of values on process on a logical grid and `m`, `n`, and `p` as the 23572fd0fbdSBarry Smith extent of the patch, where each grid point has (potentially) several degrees of freedom. 23647c6ae99SBarry Smith 23772fd0fbdSBarry Smith .seealso: [](sec_struct), `DM`, `DMDA`, `DMDAGetGhostCorners()`, `DMDAGetOwnershipRanges()`, `DMStagGetCorners()`, `DMSTAG` 23847c6ae99SBarry Smith @*/ 239d71ae5a4SJacob Faibussowitsch PetscErrorCode DMDAGetCorners(DM da, PetscInt *x, PetscInt *y, PetscInt *z, PetscInt *m, PetscInt *n, PetscInt *p) 240d71ae5a4SJacob Faibussowitsch { 24147c6ae99SBarry Smith PetscInt w; 24247c6ae99SBarry Smith DM_DA *dd = (DM_DA *)da->data; 24347c6ae99SBarry Smith 24447c6ae99SBarry Smith PetscFunctionBegin; 245a9a02de4SBarry Smith PetscValidHeaderSpecificType(da, DM_CLASSID, 1, DMDA); 24647c6ae99SBarry Smith /* since the xs, xe ... have all been multiplied by the number of degrees 24747c6ae99SBarry Smith of freedom per cell, w = dd->w, we divide that out before returning.*/ 24847c6ae99SBarry Smith w = dd->w; 24959bc5b24SSatish Balay if (x) *x = dd->xs / w + dd->xo; 25047c6ae99SBarry Smith /* the y and z have NOT been multiplied by w */ 25159bc5b24SSatish Balay if (y) *y = dd->ys + dd->yo; 25259bc5b24SSatish Balay if (z) *z = dd->zs + dd->zo; 25359bc5b24SSatish Balay if (m) *m = (dd->xe - dd->xs) / w; 25459bc5b24SSatish Balay if (n) *n = (dd->ye - dd->ys); 25559bc5b24SSatish Balay if (p) *p = (dd->ze - dd->zs); 2563ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 25747c6ae99SBarry Smith } 25847c6ae99SBarry Smith 259d71ae5a4SJacob Faibussowitsch PetscErrorCode DMGetLocalBoundingIndices_DMDA(DM dm, PetscReal lmin[], PetscReal lmax[]) 260d71ae5a4SJacob Faibussowitsch { 2617324c66bSJed Brown DMDALocalInfo info; 26247c6ae99SBarry Smith 26347c6ae99SBarry Smith PetscFunctionBegin; 2649566063dSJacob Faibussowitsch PetscCall(DMDAGetLocalInfo(dm, &info)); 265b2e4378dSMatthew G. Knepley lmin[0] = info.xs; 266b2e4378dSMatthew G. Knepley lmin[1] = info.ys; 267b2e4378dSMatthew G. Knepley lmin[2] = info.zs; 268b2e4378dSMatthew G. Knepley lmax[0] = info.xs + info.xm - 1; 269b2e4378dSMatthew G. Knepley lmax[1] = info.ys + info.ym - 1; 270b2e4378dSMatthew G. Knepley lmax[2] = info.zs + info.zm - 1; 2713ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 27247c6ae99SBarry Smith } 273bc2bf880SBarry Smith 274a4e35b19SJacob Faibussowitsch // PetscClangLinter pragma ignore: -fdoc-* 275bc2bf880SBarry Smith /*@ 27683d91586SPatrick Sanan DMDAGetReducedDMDA - Deprecated; use DMDACreateCompatibleDMDA() 27783d91586SPatrick Sanan 27883d91586SPatrick Sanan Level: deprecated 27983d91586SPatrick Sanan @*/ 280d71ae5a4SJacob Faibussowitsch PetscErrorCode DMDAGetReducedDMDA(DM da, PetscInt nfields, DM *nda) 281d71ae5a4SJacob Faibussowitsch { 28283d91586SPatrick Sanan PetscFunctionBegin; 2839566063dSJacob Faibussowitsch PetscCall(DMDACreateCompatibleDMDA(da, nfields, nda)); 2843ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 28583d91586SPatrick Sanan } 28683d91586SPatrick Sanan 28783d91586SPatrick Sanan /*@ 28872fd0fbdSBarry Smith DMDACreateCompatibleDMDA - Creates a `DMDA` with the same layout as given `DMDA` but with fewer or more fields 289bc2bf880SBarry Smith 290b1dd8793SDave May Collective 291bc2bf880SBarry Smith 292907376e6SBarry Smith Input Parameters: 29372fd0fbdSBarry Smith + da - the `DMDA` 294dce8aebaSBarry Smith - nfields - number of fields in new `DMDA` 295bc2bf880SBarry Smith 296bc2bf880SBarry Smith Output Parameter: 297dce8aebaSBarry Smith . nda - the new `DMDA` 298bc2bf880SBarry Smith 299bc2bf880SBarry Smith Level: intermediate 300bc2bf880SBarry Smith 30112b4a537SBarry Smith .seealso: [](sec_struct), `DM`, `DMDA`, `DMDAGetGhostCorners()`, `DMSetCoordinates()`, `DMDASetUniformCoordinates()`, `DMGetCoordinates()`, `DMDAGetGhostedCoordinates()`, 30212b4a537SBarry Smith `DMStagCreateCompatibleDMStag()` 303bc2bf880SBarry Smith @*/ 304d71ae5a4SJacob Faibussowitsch PetscErrorCode DMDACreateCompatibleDMDA(DM da, PetscInt nfields, DM *nda) 305d71ae5a4SJacob Faibussowitsch { 306bc2bf880SBarry Smith DM_DA *dd = (DM_DA *)da->data; 30795c13181SPeter Brune PetscInt s, m, n, p, M, N, P, dim, Mo, No, Po; 308320964c4SBlaise Bourdin const PetscInt *lx, *ly, *lz; 309bff4a2f0SMatthew G. Knepley DMBoundaryType bx, by, bz; 310320964c4SBlaise Bourdin DMDAStencilType stencil_type; 3116858538eSMatthew G. Knepley Vec coords; 31295c13181SPeter Brune PetscInt ox, oy, oz; 31395c13181SPeter Brune PetscInt cl, rl; 314320964c4SBlaise Bourdin 315320964c4SBlaise Bourdin PetscFunctionBegin; 316c73cfb54SMatthew G. Knepley dim = da->dim; 31795c13181SPeter Brune M = dd->M; 31895c13181SPeter Brune N = dd->N; 31995c13181SPeter Brune P = dd->P; 32095c13181SPeter Brune m = dd->m; 32195c13181SPeter Brune n = dd->n; 32295c13181SPeter Brune p = dd->p; 32395c13181SPeter Brune s = dd->s; 32495c13181SPeter Brune bx = dd->bx; 32595c13181SPeter Brune by = dd->by; 32695c13181SPeter Brune bz = dd->bz; 3278865f1eaSKarl Rupp 32895c13181SPeter Brune stencil_type = dd->stencil_type; 3298865f1eaSKarl Rupp 3309566063dSJacob Faibussowitsch PetscCall(DMDAGetOwnershipRanges(da, &lx, &ly, &lz)); 331320964c4SBlaise Bourdin if (dim == 1) { 3329566063dSJacob Faibussowitsch PetscCall(DMDACreate1d(PetscObjectComm((PetscObject)da), bx, M, nfields, s, dd->lx, nda)); 333320964c4SBlaise Bourdin } else if (dim == 2) { 3349566063dSJacob Faibussowitsch PetscCall(DMDACreate2d(PetscObjectComm((PetscObject)da), bx, by, stencil_type, M, N, m, n, nfields, s, lx, ly, nda)); 335320964c4SBlaise Bourdin } else if (dim == 3) { 3369566063dSJacob Faibussowitsch PetscCall(DMDACreate3d(PetscObjectComm((PetscObject)da), bx, by, bz, stencil_type, M, N, P, m, n, p, nfields, s, lx, ly, lz, nda)); 337bc2bf880SBarry Smith } 3389566063dSJacob Faibussowitsch PetscCall(DMSetUp(*nda)); 3396858538eSMatthew G. Knepley PetscCall(DMGetCoordinates(da, &coords)); 3406858538eSMatthew G. Knepley PetscCall(DMSetCoordinates(*nda, coords)); 34195c13181SPeter Brune 34295c13181SPeter Brune /* allow for getting a reduced DA corresponding to a domain decomposition */ 3439566063dSJacob Faibussowitsch PetscCall(DMDAGetOffset(da, &ox, &oy, &oz, &Mo, &No, &Po)); 3449566063dSJacob Faibussowitsch PetscCall(DMDASetOffset(*nda, ox, oy, oz, Mo, No, Po)); 34595c13181SPeter Brune 34695c13181SPeter Brune /* allow for getting a reduced DA corresponding to a coarsened DA */ 3479566063dSJacob Faibussowitsch PetscCall(DMGetCoarsenLevel(da, &cl)); 3489566063dSJacob Faibussowitsch PetscCall(DMGetRefineLevel(da, &rl)); 3498865f1eaSKarl Rupp 35095c13181SPeter Brune (*nda)->levelup = rl; 35195c13181SPeter Brune (*nda)->leveldown = cl; 3523ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 353bc2bf880SBarry Smith } 354bc2bf880SBarry Smith 355c593f006SBarry Smith /*@C 356dce8aebaSBarry Smith DMDAGetCoordinateArray - Gets an array containing the coordinates of the `DMDA` 357c593f006SBarry Smith 35820f4b53cSBarry Smith Not Collective; No Fortran Support 359c593f006SBarry Smith 360c593f006SBarry Smith Input Parameter: 361dce8aebaSBarry Smith . dm - the `DMDA` 362c593f006SBarry Smith 363c593f006SBarry Smith Output Parameter: 364c593f006SBarry Smith . xc - the coordinates 365c593f006SBarry Smith 366c593f006SBarry Smith Level: intermediate 367c593f006SBarry Smith 36812b4a537SBarry Smith Note: 36912b4a537SBarry Smith Use `DMDARestoreCoordinateArray()` to return the array 37012b4a537SBarry Smith 37112b4a537SBarry Smith .seealso: [](sec_struct), `DM`, `DMDA`, `DMDASetCoordinateName()`, `DMDASetFieldName()`, `DMDAGetFieldName()`, `DMDARestoreCoordinateArray()` 372c593f006SBarry Smith @*/ 373d71ae5a4SJacob Faibussowitsch PetscErrorCode DMDAGetCoordinateArray(DM dm, void *xc) 374d71ae5a4SJacob Faibussowitsch { 375c593f006SBarry Smith DM cdm; 376c593f006SBarry Smith Vec x; 377c593f006SBarry Smith 378c593f006SBarry Smith PetscFunctionBegin; 379c593f006SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3809566063dSJacob Faibussowitsch PetscCall(DMGetCoordinates(dm, &x)); 3819566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateDM(dm, &cdm)); 3829566063dSJacob Faibussowitsch PetscCall(DMDAVecGetArray(cdm, x, xc)); 3833ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 384c593f006SBarry Smith } 385c593f006SBarry Smith 386c593f006SBarry Smith /*@C 38712b4a537SBarry Smith DMDARestoreCoordinateArray - Returns an array containing the coordinates of the `DMDA` obtained with `DMDAGetCoordinateArray()` 388c593f006SBarry Smith 38920f4b53cSBarry Smith Not Collective; No Fortran Support 390c593f006SBarry Smith 391d8d19677SJose E. Roman Input Parameters: 392dce8aebaSBarry Smith + dm - the `DMDA` 393c593f006SBarry Smith - xc - the coordinates 394c593f006SBarry Smith 395c593f006SBarry Smith Level: intermediate 396c593f006SBarry Smith 39712b4a537SBarry Smith .seealso: [](sec_struct), `DM`, `DMDA`, `DMDASetCoordinateName()`, `DMDASetFieldName()`, `DMDAGetFieldName()`, `DMDAGetCoordinateArray()` 398c593f006SBarry Smith @*/ 399d71ae5a4SJacob Faibussowitsch PetscErrorCode DMDARestoreCoordinateArray(DM dm, void *xc) 400d71ae5a4SJacob Faibussowitsch { 401c593f006SBarry Smith DM cdm; 402c593f006SBarry Smith Vec x; 403c593f006SBarry Smith 404c593f006SBarry Smith PetscFunctionBegin; 405c593f006SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 4069566063dSJacob Faibussowitsch PetscCall(DMGetCoordinates(dm, &x)); 4079566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateDM(dm, &cdm)); 4089566063dSJacob Faibussowitsch PetscCall(DMDAVecRestoreArray(cdm, x, xc)); 4093ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 410c593f006SBarry Smith } 411