Actual source code: productutils.c
petsc-3.14.6 2021-03-30
1: /* Additional functions in the DMProduct API, which are not part of the general DM API. */
2: #include <petsc/private/dmproductimpl.h>
4: /*@C
5: DMProductGetDM - Get sub-DM associated with a given slot of a DMProduct
7: Not collective
9: Input Parameters:
10: + dm - the DMProduct
11: - slot - which dimension slot, in the range 0 to dim-1
13: Output Parameter:
14: . subdm - the sub-DM
16: Level: advanced
18: .seealso: DMPRODUCT, DMProductSetDM()
19: @*/
20: PETSC_EXTERN PetscErrorCode DMProductGetDM(DM dm,PetscInt slot,DM *subdm)
21: {
23: DM_Product *product = (DM_Product*)dm->data;
24: PetscInt dim;
28: DMGetDimension(dm,&dim);
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: return(0);
32: }
34: /*@C
35: DMProductSetDM - Set sub-DM associated with a given slot of DMProduct
37: Not collective
39: Input Parameters:
40: + dm - the DMProduct
41: . slot - which dimension slot, in the range 0 to dim-1
42: - subdm - the sub-DM
44: Notes:
45: This function does not destroy the provided sub-DM. You may safely destroy it after calling this function.
47: Level: advanced
49: .seealso: DMPRODUCT, DMProductGetDM(), DMProductSetDimensionIndex()
50: @*/
51: PETSC_EXTERN PetscErrorCode DMProductSetDM(DM dm,PetscInt slot,DM subdm)
52: {
54: DM_Product *product = (DM_Product*)dm->data;
55: PetscInt dim;
59: DMGetDimension(dm,&dim);
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: PetscObjectReference((PetscObject)subdm);
62: DMDestroy(&product->dm[slot]);
63: product->dm[slot] = subdm;
64: return(0);
65: }
67: /*@C
68: DMProductSetDimensionIndex - Set the dimension index associated with a given slot/sub-DM
70: Not collective
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
77: Level: advanced
79: .seealso: DMPRODUCT
80: @*/
81: PETSC_EXTERN PetscErrorCode DMProductSetDimensionIndex(DM dm,PetscInt slot,PetscInt idx)
82: {
84: DM_Product *product = (DM_Product*)dm->data;
85: PetscInt dim;
89: DMGetDimension(dm,&dim);
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: return(0);
93: }