xref: /petsc/src/dm/impls/product/productutils.c (revision ccb4e88a40f0b86eaeca07ff64c64e4de2fae686)
1 /* Additional functions in the DMProduct API, which are not part of the general DM API. */
2 #include <petsc/private/dmproductimpl.h>
3 
4 /*@C
5   DMProductGetDM - Get sub-DM associated with a given slot of a DMProduct
6 
7   Not collective
8 
9   Input Parameters:
10 + dm - the DMProduct
11 - slot - which dimension slot, in the range 0 to dim-1
12 
13   Output Parameter:
14 . subdm - the sub-DM
15 
16   Level: advanced
17 
18 .seealso: DMPRODUCT, DMProductSetDM()
19 @*/
20 PETSC_EXTERN PetscErrorCode DMProductGetDM(DM dm,PetscInt slot,DM *subdm)
21 {
22   PetscErrorCode ierr;
23   DM_Product     *product = (DM_Product*)dm->data;
24   PetscInt       dim;
25 
26   PetscFunctionBegin;
27   PetscValidHeaderSpecificType(dm,DM_CLASSID,1,DMPRODUCT);
28   ierr = DMGetDimension(dm,&dim);CHKERRQ(ierr);
29   if (slot >= dim || slot < 0) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"slot number must be in range 0-%D",dim-1);
30   *subdm = product->dm[slot];
31   PetscFunctionReturn(0);
32 }
33 
34 /*@C
35   DMProductSetDM - Set sub-DM associated with a given slot of DMProduct
36 
37   Not collective
38 
39   Input Parameters:
40 + dm - the DMProduct
41 . slot - which dimension slot, in the range 0 to dim-1
42 - subdm - the sub-DM
43 
44   Notes:
45   This function does not destroy the provided sub-DM. You may safely destroy it after calling this function.
46 
47   Level: advanced
48 
49 .seealso: DMPRODUCT, DMProductGetDM(), DMProductSetDimensionIndex()
50 @*/
51 PETSC_EXTERN PetscErrorCode DMProductSetDM(DM dm,PetscInt slot,DM subdm)
52 {
53   PetscErrorCode ierr;
54   DM_Product     *product = (DM_Product*)dm->data;
55   PetscInt       dim;
56 
57   PetscFunctionBegin;
58   PetscValidHeaderSpecificType(dm,DM_CLASSID,1,DMPRODUCT);
59   ierr = DMGetDimension(dm,&dim);CHKERRQ(ierr);
60   if (slot >= dim || slot < 0) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"slot number must be in range 0-%D",dim-1);
61   ierr = PetscObjectReference((PetscObject)subdm);CHKERRQ(ierr);
62   ierr = DMDestroy(&product->dm[slot]);CHKERRQ(ierr);
63   product->dm[slot] = subdm;
64   PetscFunctionReturn(0);
65 }
66 
67 /*@C
68   DMProductSetDimensionIndex - Set the dimension index associated with a given slot/sub-DM
69 
70   Not collective
71 
72   Input Parameters:
73 + dm - the DMProduct
74 . slot - which dimension slot, in the range 0 to dim-1
75 - idx - the dimension index of the sub-DM
76 
77   Level: advanced
78 
79 .seealso: DMPRODUCT
80 @*/
81 PETSC_EXTERN PetscErrorCode DMProductSetDimensionIndex(DM dm,PetscInt slot,PetscInt idx)
82 {
83   PetscErrorCode ierr;
84   DM_Product     *product = (DM_Product*)dm->data;
85   PetscInt       dim;
86 
87   PetscFunctionBegin;
88   PetscValidHeaderSpecificType(dm,DM_CLASSID,1,DMPRODUCT);
89   ierr = DMGetDimension(dm,&dim);CHKERRQ(ierr);
90   if (slot >= dim || slot < 0) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"slot number must be in range 0-%D",dim-1);
91   product->dim[slot] = idx;
92   PetscFunctionReturn(0);
93 }
94