xref: /petsc/src/dm/impls/product/product.c (revision bcd3bd92eda2d5998e2f14c4bbfb33bd936bdc3e)
1 #include <petsc/private/dmproductimpl.h>
2 
3 static PetscErrorCode DMDestroy_Product(DM dm)
4 {
5   DM_Product *product = (DM_Product *)dm->data;
6   PetscInt    d;
7 
8   PetscFunctionBeginUser;
9   for (d = 0; d < DMPRODUCT_MAX_DIM; ++d) PetscCall(DMDestroy(&product->dm[d]));
10   PetscCall(PetscFree(product));
11   PetscFunctionReturn(PETSC_SUCCESS);
12 }
13 
14 /*MC
15   DMPRODUCT = "product" - a DM representing a local Cartesian product of other DMs
16 
17   For each of dim dimensions, stores a sub-DM (need not be unique) and a dimension index. This specifies
18   which dimension of the sub-DM corresponds to each dimension of the DMProduct.
19 
20   Level: advanced
21 
22 .seealso: `DM`, `DMSTAG`, `DMProductGetDM()`, `DMProductSetDimensionIndex()`, `DMProductSetDM()`, `DMStagSetUniformCoordinatesProduct()`,
23           `DMStagGetProductCoordinateArrays()`, `DMStagGetProductCoordinateArraysRead()`
24 M*/
25 
26 PETSC_EXTERN PetscErrorCode DMCreate_Product(DM dm)
27 {
28   DM_Product *product;
29   PetscInt    d;
30 
31   PetscFunctionBegin;
32   PetscAssertPointer(dm, 1);
33   PetscCall(PetscNew(&product));
34   dm->data = product;
35 
36   for (d = 0; d < DMPRODUCT_MAX_DIM; ++d) product->dm[d] = NULL;
37   for (d = 0; d < DMPRODUCT_MAX_DIM; ++d) product->dim[d] = -1;
38 
39   dm->ops->destroy = DMDestroy_Product;
40   PetscFunctionReturn(PETSC_SUCCESS);
41 }
42