Actual source code: tsreg.c

petsc-3.4.0 2013-05-13
  1: #include <petsc-private/tsimpl.h>      /*I "petscts.h"  I*/

  3: PetscFunctionList TSList              = NULL;
  4: PetscBool         TSRegisterAllCalled = PETSC_FALSE;

  8: /*@C
  9:   TSSetType - Sets the method for the timestepping solver.

 11:   Collective on TS

 13:   Input Parameters:
 14: + ts   - The TS context
 15: - type - A known method

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

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

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

 39:    Level: intermediate

 41: .keywords: TS, set, type

 43: @*/
 44: PetscErrorCode  TSSetType(TS ts,TSType type)
 45: {
 46:   PetscErrorCode (*r)(TS);
 47:   PetscBool      match;

 52:   PetscObjectTypeCompare((PetscObject) ts, type, &match);
 53:   if (match) return(0);

 55:   PetscFunctionListFind(TSList,type,&r);
 56:   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown TS type: %s", type);
 57:   if (ts->ops->destroy) {
 58:     (*(ts)->ops->destroy)(ts);

 60:     ts->ops->destroy = NULL;
 61:   }
 62:   PetscMemzero(ts->ops,sizeof(*ts->ops));

 64:   ts->setupcalled = PETSC_FALSE;

 66:   PetscObjectChangeTypeName((PetscObject)ts, type);
 67:   (*r)(ts);
 68:   return(0);
 69: }

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

 76:   Not Collective

 78:   Input Parameter:
 79: . ts - The TS

 81:   Output Parameter:
 82: . type - The name of TS method

 84:   Level: intermediate

 86: .keywords: TS, timestepper, get, type, name
 87: .seealso TSSetType()
 88: @*/
 89: PetscErrorCode  TSGetType(TS ts, TSType *type)
 90: {
 94:   *type = ((PetscObject)ts)->type_name;
 95:   return(0);
 96: }

 98: /*--------------------------------------------------------------------------------------------------------------------*/

102: /*@C
103:   TSRegister - Adds a creation method to the TS package.

105:   Not Collective

107:   Input Parameters:
108: + name        - The name of a new user-defined creation routine
109: - create_func - The creation routine itself

111:   Notes:
112:   TSRegister() may be called multiple times to add several user-defined tses.

114:   Sample usage:
115: .vb
116:   TSRegister("my_ts",  MyTSCreate);
117: .ve

119:   Then, your ts type can be chosen with the procedural interface via
120: .vb
121:     TS ts;
122:     TSCreate(MPI_Comm, &ts);
123:     TSSetType(ts, "my_ts")
124: .ve
125:   or at runtime via the option
126: .vb
127:     -ts_type my_ts
128: .ve

130:   Level: advanced

132: .keywords: TS, register

134: .seealso: TSRegisterAll(), TSRegisterDestroy()
135: @*/
136: PetscErrorCode  TSRegister(const char sname[], PetscErrorCode (*function)(TS))
137: {

141:   PetscFunctionListAdd(&TSList,sname,function);
142:   return(0);
143: }