Actual source code: tsreg.c

petsc-3.8.4 2018-03-24
Report Typos and Errors
  1:  #include <petsc/private/tsimpl.h>

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

  6: /*@C
  7:   TSSetType - Sets the method to be used as the timestepping solver.

  9:   Collective on TS

 11:   Input Parameters:
 12: + ts   - The TS context
 13: - type - A known method

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

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

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

 37:    Level: intermediate

 39: .keywords: TS, set, type

 41: .seealso: TS, TSSolve(), TSCreate(), TSSetFromOptions(), TSDestroy(), TSType

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

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

 56:   PetscFunctionListFind(TSList,type,&r);
 57:   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown TS type: %s", type);
 58:   if (ts->ops->destroy) {
 59:     (*(ts)->ops->destroy)(ts);
 60:   }
 61:   PetscMemzero(ts->ops,sizeof(*ts->ops));
 62:   ts->default_adapt_type = TSADAPTNONE;

 64:   ts->setupcalled = PETSC_FALSE;

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

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

 74:   Not Collective

 76:   Input Parameter:
 77: . ts - The TS

 79:   Output Parameter:
 80: . type - The name of TS method

 82:   Level: intermediate

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

 96: /*--------------------------------------------------------------------------------------------------------------------*/

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

101:   Not Collective

103:   Input Parameters:
104: + name        - The name of a new user-defined creation routine
105: - create_func - The creation routine itself

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

110:   Sample usage:
111: .vb
112:   TSRegister("my_ts",  MyTSCreate);
113: .ve

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

126:   Level: advanced

128: .keywords: TS, register

130: .seealso: TSRegisterAll(), TSRegisterDestroy()
131: @*/
132: PetscErrorCode  TSRegister(const char sname[], PetscErrorCode (*function)(TS))
133: {

137:   PetscFunctionListAdd(&TSList,sname,function);
138:   return(0);
139: }