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