Actual source code: dareg.c

  1: #define PETSCDM_DLL

 3:  #include private/daimpl.h

  5: PetscFList DAList                       = PETSC_NULL;
  6: PetscTruth DARegisterAllCalled          = PETSC_FALSE;

 10: /*@C
 11:   DASetType - Builds a DA, for a particular DA implementation.

 13:   Collective on DA

 15:   Input Parameters:
 16: + da     - The DA object
 17: - method - The name of the DA type

 19:   Options Database Key:
 20: . -da_type <type> - Sets the DA type; use -help for a list of available types

 22:   Notes:
 23:   See "petsc/include/petscda.h" for available DA types (for instance, DA1D, DA2D, or DA3D).

 25:   Level: intermediate

 27: .keywords: DA, set, type
 28: .seealso: DAGetType(), DACreate()
 29: @*/
 30: PetscErrorCode  DASetType(DA da, const DAType method)
 31: {
 32:   PetscErrorCode (*r)(DA);
 33:   PetscTruth     match;

 38:   PetscTypeCompare((PetscObject) da, method, &match);
 39:   if (match) return(0);

 41:   if (!DARegisterAllCalled) {DARegisterAll(PETSC_NULL);}
 42:   PetscFListFind(DAList, ((PetscObject)da)->comm, method,(void (**)(void)) &r);
 43:   if (!r) SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown DA type: %s", method);

 45:   if (da->ops->destroy) {
 46:     (*da->ops->destroy)(da);
 47:   }
 48:   (*r)(da);
 49:   PetscObjectChangeTypeName((PetscObject)da,method);
 50:   return(0);
 51: }

 55: /*@C
 56:   DAGetType - Gets the DA type name (as a string) from the DA.

 58:   Not Collective

 60:   Input Parameter:
 61: . da  - The DA

 63:   Output Parameter:
 64: . type - The DA type name

 66:   Level: intermediate

 68: .keywords: DA, get, type, name
 69: .seealso: DASetType(), DACreate()
 70: @*/
 71: PetscErrorCode  DAGetType(DA da, const DAType *type)
 72: {

 78:   if (!DARegisterAllCalled) {
 79:     DARegisterAll(PETSC_NULL);
 80:   }
 81:   *type = ((PetscObject)da)->type_name;
 82:   return(0);
 83: }


 86: /*--------------------------------------------------------------------------------------------------------------------*/

 90: /*@C
 91:   DARegister - See DARegisterDynamic()

 93:   Level: advanced
 94: @*/
 95: PetscErrorCode  DARegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(DA))
 96: {
 97:   char fullname[PETSC_MAX_PATH_LEN];

101:   PetscStrcpy(fullname, path);
102:   PetscStrcat(fullname, ":");
103:   PetscStrcat(fullname, name);
104:   PetscFListAdd(&DAList, sname, fullname, (void (*)(void)) function);
105:   return(0);
106: }


109: /*--------------------------------------------------------------------------------------------------------------------*/
112: /*@C
113:    DARegisterDestroy - Frees the list of DA methods that were registered by DARegister()/DARegisterDynamic().

115:    Not Collective

117:    Level: advanced

119: .keywords: DA, register, destroy
120: .seealso: DARegister(), DARegisterAll(), DARegisterDynamic()
121: @*/
122: PetscErrorCode  DARegisterDestroy(void)
123: {

127:   PetscFListDestroy(&DAList);
128:   DARegisterAllCalled = PETSC_FALSE;
129:   return(0);
130: }