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