Actual source code: tsreg.c

  1: #define PETSCTS_DLL

 3:  #include private/tsimpl.h

  5: PetscFList TSList                       = PETSC_NULL;
  6: PetscTruth TSRegisterAllCalled          = PETSC_FALSE;

 10: /*@C
 11:   TSSetType - Sets the method for the timestepping solver.  

 13:   Collective on TS

 15:   Input Parameters:
 16: + ts   - The TS context
 17: - type - A known method

 19:   Options Database Command:
 20: . -ts_type <type> - Sets the method; use -help for a list of available methods (for instance, euler)

 22:    Notes:
 23:    See "petsc/include/petscts.h" for available methods (for instance)
 24: +  TSEULER - Euler
 25: .  TSSUNDIALS - SUNDIALS interface
 26: .  TSBEULER - Backward Euler
 27: -  TSPSEUDO - Pseudo-timestepping

 29:    Normally, it is best to use the TSSetFromOptions() command and
 30:    then set the TS type from the options database rather than by using
 31:    this routine.  Using the options database provides the user with
 32:    maximum flexibility in evaluating the many different solvers.
 33:    The TSSetType() routine is provided for those situations where it
 34:    is necessary to set the timestepping solver independently of the
 35:    command line or options database.  This might be the case, for example,
 36:    when the choice of solver changes during the execution of the
 37:    program, and the user's application is taking responsibility for
 38:    choosing the appropriate method.  In other words, this routine is
 39:    not for beginners.

 41:    Level: intermediate

 43: .keywords: TS, set, type

 45: @*/
 46: PetscErrorCode  TSSetType(TS ts,const TSType type)
 47: {
 48:   PetscErrorCode (*r)(TS);
 49:   PetscTruth     match;

 54:   PetscTypeCompare((PetscObject) ts, type, &match);
 55:   if (match) return(0);

 57:   PetscFListFind( TSList,((PetscObject)ts)->comm, type, (void (**)(void)) &r);
 58:   if (!r) SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown TS type: %s", type);
 59:   if (ts->ksp) {
 60:     KSPDestroy(ts->ksp);
 61:     ts->ksp = PETSC_NULL;
 62:   }
 63:   if (ts->snes) {
 64:     SNESDestroy(ts->snes);
 65:     ts->snes = PETSC_NULL;
 66:   }
 67:   if (ts->ops->destroy) {
 68:     (*(ts)->ops->destroy)(ts);
 69:   }
 70:   (*r)(ts);
 71:   PetscObjectChangeTypeName((PetscObject)ts, type);
 72:   return(0);
 73: }

 77: /*@C
 78:   TSGetType - Gets the TS method type (as a string).

 80:   Not Collective

 82:   Input Parameter:
 83: . ts - The TS

 85:   Output Parameter:
 86: . type - The name of TS method

 88:   Level: intermediate

 90: .keywords: TS, timestepper, get, type, name
 91: .seealso TSSetType()
 92: @*/
 93: PetscErrorCode  TSGetType(TS ts, const TSType *type)
 94: {
 98:   *type = ((PetscObject)ts)->type_name;
 99:   return(0);
100: }

102: /*--------------------------------------------------------------------------------------------------------------------*/

106: /*@C
107:   TSRegister - See TSRegisterDynamic()

109:   Level: advanced
110: @*/
111: PetscErrorCode  TSRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(TS))
112: {
113:   char           fullname[PETSC_MAX_PATH_LEN];

117:   PetscStrcpy(fullname, path);
118:   PetscStrcat(fullname, ":");
119:   PetscStrcat(fullname, name);
120:   PetscFListAdd(&TSList, sname, fullname, (void (*)(void)) function);
121:   return(0);
122: }

124: /*-------------------------------------------------------------------------------------------------------------------*/
127: /*@C
128:    TSRegisterDestroy - Frees the list of timestepping routines that were registered by TSRegister()/TSRegisterDynamic().

130:    Not Collective

132:    Level: advanced

134: .keywords: TS, timestepper, register, destroy
135: .seealso: TSRegister(), TSRegisterAll(), TSRegisterDynamic()
136: @*/
137: PetscErrorCode  TSRegisterDestroy(void)
138: {

142:   PetscFListDestroy(&TSList);
143:   TSRegisterAllCalled = PETSC_FALSE;
144:   return(0);
145: }