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

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

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

 18:    Level: intermediate

 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: .seealso: [](chapter_ts), `TS`, `TSSolve()`, `TSCreate()`, `TSSetFromOptions()`, `TSDestroy()`, `TSType`
 40: @*/
 41: PetscErrorCode TSSetType(TS ts, TSType type)
 42: {
 43:   PetscErrorCode (*r)(TS);
 44:   PetscBool match;

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

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

 58:   ts->setupcalled = PETSC_FALSE;

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

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

 68:   Not Collective

 70:   Input Parameter:
 71: . ts - The `TS`

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

 76:   Level: intermediate

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

 88: /*--------------------------------------------------------------------------------------------------------------------*/

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

 93:   Not Collective

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

 99:   Level: advanced

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

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

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

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