Actual source code: product.c
1: #include <petsc/private/dmproductimpl.h>
3: static PetscErrorCode DMDestroy_Product(DM dm)
4: {
5: DM_Product *product = (DM_Product *)dm->data;
7: PetscFunctionBeginUser;
8: for (PetscInt d = 0; d < DMPRODUCT_MAX_DIM; ++d) PetscCall(DMDestroy(&product->dm[d]));
9: PetscCall(PetscFree(product));
10: PetscFunctionReturn(PETSC_SUCCESS);
11: }
13: static PetscErrorCode DMView_Product(DM dm, PetscViewer viewer)
14: {
15: DM_Product *product = (DM_Product *)dm->data;
17: PetscFunctionBegin;
18: for (PetscInt d = 0; d < DMPRODUCT_MAX_DIM; ++d) {
19: if (product->dm[d]) {
20: PetscCall(PetscViewerASCIIPrintf(viewer, " DM that defines dimension %" PetscInt_FMT "\n", d));
21: PetscCall(PetscViewerASCIIPushTab(viewer));
22: PetscCall(PetscViewerASCIIPushTab(viewer));
23: PetscCall(DMView(product->dm[d], viewer));
24: PetscCall(PetscViewerASCIIPopTab(viewer));
25: PetscCall(PetscViewerASCIIPopTab(viewer));
26: }
27: }
28: PetscFunctionReturn(PETSC_SUCCESS);
29: }
31: /*MC
32: DMPRODUCT = "product" - a `DM` representing a local Cartesian product of other `DM`
34: Level: advanced
36: Notes:
37: The `DM` is usually used for managing coordinates of other `DM` via `DMGetCoordinateDM()` and `DMSetCoordinateDM()`
39: For each of `dim` dimensions, the `DMPRODUCT` contains a `DM` and a dimension index. The dimensional index, set with `DMProductSetDimensionIndex()`
40: specifies which dimension of the sub-`DM` coordinates corresponds to a particular dimension of the `DMPRODUCT`. For example,
41: .vb
42: DM da1, da2;
43: DM dm
44: DMCreate(PETSC_COMM_WORLD,&dm);
45: DMSetType(dm,DMPRODUCT);
46: DMSetDimension(dm,3);
47: DMProductSetDM(dm,0,da1);
48: DMProductSetDimensionIndex(dm,0,0);
49: DMProductSetDM(dm,1,da2);
50: DMProductSetDimensionIndex(dm,1,0);
51: DMProductSetDM(dm,2,da1);
52: DMProductSetDimensionIndex(dm,2,1);
53: .ve
54: results in a three-dimensional `DM` whose `x` coordinate values are obtained from the `x` coordinate values of `da1`, whose `y` coordinate values are obtained from
55: the 'x' coordinate values of `da2` and whose `z` coordinate values are obtained from the `y` coordinate values of `da1`.
57: .seealso: `DM`, `DMSTAG`, `DMProductGetDM()`, `DMProductSetDimensionIndex()`, `DMProductSetDM()`, `DMStagSetUniformCoordinatesProduct()`,
58: `DMStagGetProductCoordinateArrays()`, `DMStagGetProductCoordinateArraysRead()`, `DMGetCoordinateDM()`, `DMSetCoordinateDM()`
59: M*/
61: PETSC_EXTERN PetscErrorCode DMCreate_Product(DM dm)
62: {
63: DM_Product *product;
65: PetscFunctionBegin;
66: PetscAssertPointer(dm, 1);
67: PetscCall(PetscNew(&product));
68: dm->data = product;
70: for (PetscInt d = 0; d < DMPRODUCT_MAX_DIM; ++d) product->dm[d] = NULL;
71: for (PetscInt d = 0; d < DMPRODUCT_MAX_DIM; ++d) product->dim[d] = -1;
73: dm->ops->destroy = DMDestroy_Product;
74: dm->ops->view = DMView_Product;
75: PetscFunctionReturn(PETSC_SUCCESS);
76: }