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;

 26:   DMGetDimension(dm,&dim);
 28:   *subdm = product->dm[slot];
 29:   return 0;
 30: }

 32: /*@C
 33:   DMProductSetDM - Set sub-DM associated with a given slot of DMProduct

 35:   Not collective

 37:   Input Parameters:
 38: + dm - the DMProduct
 39: . slot - which dimension slot, in the range 0 to dim-1
 40: - subdm - the sub-DM

 42:   Notes:
 43:   This function does not destroy the provided sub-DM. You may safely destroy it after calling this function.

 45:   Level: advanced

 47: .seealso: DMPRODUCT, DMProductGetDM(), DMProductSetDimensionIndex()
 48: @*/
 49: PETSC_EXTERN PetscErrorCode DMProductSetDM(DM dm,PetscInt slot,DM subdm)
 50: {
 51:   DM_Product     *product = (DM_Product*)dm->data;
 52:   PetscInt       dim;

 55:   DMGetDimension(dm,&dim);
 57:   PetscObjectReference((PetscObject)subdm);
 58:   DMDestroy(&product->dm[slot]);
 59:   product->dm[slot] = subdm;
 60:   return 0;
 61: }

 63: /*@C
 64:   DMProductSetDimensionIndex - Set the dimension index associated with a given slot/sub-DM

 66:   Not collective

 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

 73:   Level: advanced

 75: .seealso: DMPRODUCT
 76: @*/
 77: PETSC_EXTERN PetscErrorCode DMProductSetDimensionIndex(DM dm,PetscInt slot,PetscInt idx)
 78: {
 79:   DM_Product     *product = (DM_Product*)dm->data;
 80:   PetscInt       dim;

 83:   DMGetDimension(dm,&dim);
 85:   product->dim[slot] = idx;
 86:   return 0;
 87: }