Actual source code: productutils.c
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: {
22: DM_Product *product = (DM_Product *)dm->data;
23: PetscInt dim;
25: PetscFunctionBegin;
27: PetscCall(DMGetDimension(dm, &dim));
28: PetscCheck(slot < dim && slot >= 0, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "slot number must be in range 0-%" PetscInt_FMT, dim - 1);
29: *subdm = product->dm[slot];
30: PetscFunctionReturn(PETSC_SUCCESS);
31: }
33: /*@C
34: DMProductSetDM - Set sub-DM associated with a given slot of DMProduct
36: Not collective
38: Input Parameters:
39: + dm - the DMProduct
40: . slot - which dimension slot, in the range 0 to dim-1
41: - subdm - the sub-DM
43: Notes:
44: This function does not destroy the provided sub-DM. You may safely destroy it after calling this function.
46: Level: advanced
48: .seealso: `DMPRODUCT`, `DMProductGetDM()`, `DMProductSetDimensionIndex()`
49: @*/
50: PETSC_EXTERN PetscErrorCode DMProductSetDM(DM dm, PetscInt slot, DM subdm)
51: {
52: DM_Product *product = (DM_Product *)dm->data;
53: PetscInt dim;
55: PetscFunctionBegin;
57: PetscCall(DMGetDimension(dm, &dim));
58: PetscCheck(slot < dim && slot >= 0, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "slot number must be in range 0-%" PetscInt_FMT, dim - 1);
59: PetscCall(PetscObjectReference((PetscObject)subdm));
60: PetscCall(DMDestroy(&product->dm[slot]));
61: product->dm[slot] = subdm;
62: PetscFunctionReturn(PETSC_SUCCESS);
63: }
65: /*@C
66: DMProductSetDimensionIndex - Set the dimension index associated with a given slot/sub-DM
68: Not collective
70: Input Parameters:
71: + dm - the DMProduct
72: . slot - which dimension slot, in the range 0 to dim-1
73: - idx - the dimension index of the sub-DM
75: Level: advanced
77: .seealso: `DMPRODUCT`
78: @*/
79: PETSC_EXTERN PetscErrorCode DMProductSetDimensionIndex(DM dm, PetscInt slot, PetscInt idx)
80: {
81: DM_Product *product = (DM_Product *)dm->data;
82: PetscInt dim;
84: PetscFunctionBegin;
86: PetscCall(DMGetDimension(dm, &dim));
87: PetscCheck(slot < dim && slot >= 0, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "slot number must be in range 0-%" PetscInt_FMT, dim - 1);
88: product->dim[slot] = idx;
89: PetscFunctionReturn(PETSC_SUCCESS);
90: }