1cc4c1da9SBarry Smith #include <petsc/private/dmproductimpl.h> /*I "petsc/private/dmproductimpl.h" I*/
2d852a638SPatrick Sanan
3cc4c1da9SBarry Smith /*@
4*356ea6bcSBarry Smith DMProductGetDM - Get sub-`DM` whose coordinates will be associated with a particular dimension of the `DMPRODUCT`
5d852a638SPatrick Sanan
620f4b53cSBarry Smith Not Collective
7d852a638SPatrick Sanan
8d852a638SPatrick Sanan Input Parameters:
920f4b53cSBarry Smith + dm - the` DMPRODUCT`
10*356ea6bcSBarry Smith - slot - which dimension within `DMPRODUCT` whose coordinates is being provided, in the range 0 to $dim-1$
11d852a638SPatrick Sanan
12d852a638SPatrick Sanan Output Parameter:
1320f4b53cSBarry Smith . subdm - the sub-`DM`
14d852a638SPatrick Sanan
15d852a638SPatrick Sanan Level: advanced
16d852a638SPatrick Sanan
17*356ea6bcSBarry Smith Note:
18*356ea6bcSBarry Smith You can call `DMProductGetDimensionIndex()` to determine which dimension in `subdm` is to be used to provide the coordinates, see `DMPRODUCT`
19*356ea6bcSBarry Smith
20*356ea6bcSBarry Smith .seealso: `DMPRODUCT`, `DMProductSetDM()`, `DMProductGetDimensionIndex()`, `DMProductSetDimensionIndex()`
21d852a638SPatrick Sanan @*/
DMProductGetDM(DM dm,PetscInt slot,DM * subdm)22cc4c1da9SBarry Smith PetscErrorCode DMProductGetDM(DM dm, PetscInt slot, DM *subdm)
23d71ae5a4SJacob Faibussowitsch {
24d852a638SPatrick Sanan DM_Product *product = (DM_Product *)dm->data;
25d852a638SPatrick Sanan PetscInt dim;
26d852a638SPatrick Sanan
27d852a638SPatrick Sanan PetscFunctionBegin;
28d852a638SPatrick Sanan PetscValidHeaderSpecificType(dm, DM_CLASSID, 1, DMPRODUCT);
299566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim));
301dca8a05SBarry Smith PetscCheck(slot < dim && slot >= 0, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "slot number must be in range 0-%" PetscInt_FMT, dim - 1);
31d852a638SPatrick Sanan *subdm = product->dm[slot];
323ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
33d852a638SPatrick Sanan }
34d852a638SPatrick Sanan
35cc4c1da9SBarry Smith /*@
36*356ea6bcSBarry Smith DMProductSetDM - Set sub-`DM` whose coordinates will be associated with a particular dimension of the `DMPRODUCT`
37d852a638SPatrick Sanan
3820f4b53cSBarry Smith Not Collective
39d852a638SPatrick Sanan
40d852a638SPatrick Sanan Input Parameters:
4120f4b53cSBarry Smith + dm - the `DMPRODUCT`
42*356ea6bcSBarry Smith . slot - which dimension within `DMPRODUCT` whose coordinates is being provided, in the range 0 to $dim-1$
4320f4b53cSBarry Smith - subdm - the sub-`DM`
44d852a638SPatrick Sanan
45d852a638SPatrick Sanan Level: advanced
46d852a638SPatrick Sanan
47*356ea6bcSBarry Smith Notes:
4820f4b53cSBarry Smith This function does not destroy the provided sub-`DM`. You may safely destroy it after calling this function.
4920f4b53cSBarry Smith
50*356ea6bcSBarry Smith You can call `DMProductSetDimensionIndex()` to determine which dimension in `subdm` is to be used to provide the coordinates, see `DMPRODUCT`
51*356ea6bcSBarry Smith
52*356ea6bcSBarry Smith .seealso: `DMPRODUCT`, `DMProductGetDM()`, `DMProductSetDimensionIndex()`, `DMProductGetDimensionIndex()`
53d852a638SPatrick Sanan @*/
DMProductSetDM(DM dm,PetscInt slot,DM subdm)54cc4c1da9SBarry Smith PetscErrorCode DMProductSetDM(DM dm, PetscInt slot, DM subdm)
55d71ae5a4SJacob Faibussowitsch {
56d852a638SPatrick Sanan DM_Product *product = (DM_Product *)dm->data;
57d852a638SPatrick Sanan PetscInt dim;
58d852a638SPatrick Sanan
59d852a638SPatrick Sanan PetscFunctionBegin;
60d852a638SPatrick Sanan PetscValidHeaderSpecificType(dm, DM_CLASSID, 1, DMPRODUCT);
619566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim));
621dca8a05SBarry Smith PetscCheck(slot < dim && slot >= 0, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "slot number must be in range 0-%" PetscInt_FMT, dim - 1);
639566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)subdm));
649566063dSJacob Faibussowitsch PetscCall(DMDestroy(&product->dm[slot]));
65d852a638SPatrick Sanan product->dm[slot] = subdm;
663ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
67d852a638SPatrick Sanan }
68d852a638SPatrick Sanan
69cc4c1da9SBarry Smith /*@
70*356ea6bcSBarry Smith DMProductSetDimensionIndex - Set which dimension `idx` of the sub-`DM` coordinates will be used associated with the `DMPRODUCT` dimension `slot`
71d852a638SPatrick Sanan
7220f4b53cSBarry Smith Not Collective
73d852a638SPatrick Sanan
74d852a638SPatrick Sanan Input Parameters:
7520f4b53cSBarry Smith + dm - the `DMPRODUCT`
76*356ea6bcSBarry Smith . slot - which dimension, in the range 0 to $dim-1$ you are providing to the `dm`
77*356ea6bcSBarry Smith - idx - the dimension of the sub-`DM` to use
78d852a638SPatrick Sanan
79d852a638SPatrick Sanan Level: advanced
80d852a638SPatrick Sanan
81*356ea6bcSBarry Smith .seealso: `DMPRODUCT`, `DMProductGetDM()`, `DMProductGetDimensionIndex()`
82d852a638SPatrick Sanan @*/
DMProductSetDimensionIndex(DM dm,PetscInt slot,PetscInt idx)83cc4c1da9SBarry Smith PetscErrorCode DMProductSetDimensionIndex(DM dm, PetscInt slot, PetscInt idx)
84d71ae5a4SJacob Faibussowitsch {
85d852a638SPatrick Sanan DM_Product *product = (DM_Product *)dm->data;
86d852a638SPatrick Sanan PetscInt dim;
87d852a638SPatrick Sanan
88d852a638SPatrick Sanan PetscFunctionBegin;
89d852a638SPatrick Sanan PetscValidHeaderSpecificType(dm, DM_CLASSID, 1, DMPRODUCT);
909566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim));
911dca8a05SBarry Smith PetscCheck(slot < dim && slot >= 0, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "slot number must be in range 0-%" PetscInt_FMT, dim - 1);
92d852a638SPatrick Sanan product->dim[slot] = idx;
933ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
94d852a638SPatrick Sanan }
95*356ea6bcSBarry Smith
96*356ea6bcSBarry Smith /*@
97*356ea6bcSBarry Smith DMProductGetDimensionIndex - Get which dimension `idx` of the sub-`DM` coordinates will be used associated with the `DMPRODUCT` dimension `slot`
98*356ea6bcSBarry Smith
99*356ea6bcSBarry Smith Not Collective
100*356ea6bcSBarry Smith
101*356ea6bcSBarry Smith Input Parameters:
102*356ea6bcSBarry Smith + dm - the `DMPRODUCT`
103*356ea6bcSBarry Smith - slot - which dimension, in the range 0 to $dim-1$ of `dm`
104*356ea6bcSBarry Smith
105*356ea6bcSBarry Smith Output Parameter:
106*356ea6bcSBarry Smith . idx - the dimension of the sub-`DM`
107*356ea6bcSBarry Smith
108*356ea6bcSBarry Smith Level: advanced
109*356ea6bcSBarry Smith
110*356ea6bcSBarry Smith .seealso: `DMPRODUCT`, `DMProductGetDM()`, `DMProductSetDimensionIndex()`
111*356ea6bcSBarry Smith @*/
DMProductGetDimensionIndex(DM dm,PetscInt slot,PetscInt * idx)112*356ea6bcSBarry Smith PetscErrorCode DMProductGetDimensionIndex(DM dm, PetscInt slot, PetscInt *idx)
113*356ea6bcSBarry Smith {
114*356ea6bcSBarry Smith DM_Product *product = (DM_Product *)dm->data;
115*356ea6bcSBarry Smith PetscInt dim;
116*356ea6bcSBarry Smith
117*356ea6bcSBarry Smith PetscFunctionBegin;
118*356ea6bcSBarry Smith PetscValidHeaderSpecificType(dm, DM_CLASSID, 1, DMPRODUCT);
119*356ea6bcSBarry Smith PetscCall(DMGetDimension(dm, &dim));
120*356ea6bcSBarry Smith PetscAssertPointer(idx, 3);
121*356ea6bcSBarry Smith PetscCheck(slot < dim && slot >= 0, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "slot number must be in range 0-%" PetscInt_FMT, dim - 1);
122*356ea6bcSBarry Smith *idx = product->dim[slot];
123*356ea6bcSBarry Smith PetscFunctionReturn(PETSC_SUCCESS);
124*356ea6bcSBarry Smith }
125