xref: /petsc/src/dm/impls/product/productutils.c (revision 8fcddce65efd55a8fe3f87d4c08c15577ce4cbef)
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   product->dm[slot] = subdm;
63   PetscFunctionReturn(0);
64 }
65 
66 /*@C
67   DMProductSetDimensionIndex - Set the dimension index associated with a given slot/sub-DM
68 
69   Not collective
70 
71   Input Parameters:
72 + dm - the DMProduct
73 . slot - which dimension slot, in the range 0 to dim-1
74 - idx - the dimension index of the sub-DM
75 
76   Level: advanced
77 
78 .seealso: DMPRODUCT
79 @*/
80 PETSC_EXTERN PetscErrorCode DMProductSetDimensionIndex(DM dm,PetscInt slot,PetscInt idx)
81 {
82   PetscErrorCode ierr;
83   DM_Product     *product = (DM_Product*)dm->data;
84   PetscInt       dim;
85 
86   PetscFunctionBegin;
87   PetscValidHeaderSpecificType(dm,DM_CLASSID,1,DMPRODUCT);
88   ierr = DMGetDimension(dm,&dim);CHKERRQ(ierr);
89   if (slot >= dim || slot < 0) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"slot number must be in range 0-%D",dim-1);
90   product->dim[slot] = idx;
91   PetscFunctionReturn(0);
92 }
93