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 DM_Product *product = (DM_Product *)dm->data; 23 PetscInt dim; 24 25 PetscFunctionBegin; 26 PetscValidHeaderSpecificType(dm, DM_CLASSID, 1, DMPRODUCT); 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 } 32 33 /*@C 34 DMProductSetDM - Set sub-DM associated with a given slot of DMProduct 35 36 Not collective 37 38 Input Parameters: 39 + dm - the DMProduct 40 . slot - which dimension slot, in the range 0 to dim-1 41 - subdm - the sub-DM 42 43 Notes: 44 This function does not destroy the provided sub-DM. You may safely destroy it after calling this function. 45 46 Level: advanced 47 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; 54 55 PetscFunctionBegin; 56 PetscValidHeaderSpecificType(dm, DM_CLASSID, 1, DMPRODUCT); 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 } 64 65 /*@C 66 DMProductSetDimensionIndex - Set the dimension index associated with a given slot/sub-DM 67 68 Not collective 69 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 74 75 Level: advanced 76 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; 83 84 PetscFunctionBegin; 85 PetscValidHeaderSpecificType(dm, DM_CLASSID, 1, DMPRODUCT); 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 } 91