Actual source code: tsreg.c

  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: .seealso: `TS`, `TSSolve()`, `TSCreate()`, `TSSetFromOptions()`, `TSDestroy()`, `TSType`

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

 49:   PetscObjectTypeCompare((PetscObject)ts, type, &match);
 50:   if (match) return 0;

 52:   PetscFunctionListFind(TSList, type, &r);
 54:   PetscTryTypeMethod(ts, destroy);
 55:   PetscMemzero(ts->ops, sizeof(*ts->ops));
 56:   ts->usessnes           = PETSC_FALSE;
 57:   ts->default_adapt_type = TSADAPTNONE;

 59:   ts->setupcalled = PETSC_FALSE;

 61:   PetscObjectChangeTypeName((PetscObject)ts, type);
 62:   (*r)(ts);
 63:   return 0;
 64: }

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

 69:   Not Collective

 71:   Input Parameter:
 72: . ts - The TS

 74:   Output Parameter:
 75: . type - The name of TS method

 77:   Level: intermediate

 79: .seealso `TSSetType()`
 80: @*/
 81: PetscErrorCode TSGetType(TS ts, TSType *type)
 82: {
 85:   *type = ((PetscObject)ts)->type_name;
 86:   return 0;
 87: }

 89: /*--------------------------------------------------------------------------------------------------------------------*/

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

 94:   Not Collective

 96:   Input Parameters:
 97: + name        - The name of a new user-defined creation routine
 98: - create_func - The creation routine itself

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

103:   Sample usage:
104: .vb
105:   TSRegister("my_ts",  MyTSCreate);
106: .ve

108:   Then, your ts type can be chosen with the procedural interface via
109: .vb
110:     TS ts;
111:     TSCreate(MPI_Comm, &ts);
112:     TSSetType(ts, "my_ts")
113: .ve
114:   or at runtime via the option
115: .vb
116:     -ts_type my_ts
117: .ve

119:   Level: advanced

121: .seealso: `TSRegisterAll()`, `TSRegisterDestroy()`
122: @*/
123: PetscErrorCode TSRegister(const char sname[], PetscErrorCode (*function)(TS))
124: {
125:   TSInitializePackage();
126:   PetscFunctionListAdd(&TSList, sname, function);
127:   return 0;
128: }