Date: 2015-10-02T22:26:52+00:00

Actual source code: tsreg.c
petsc-3.6.2 2015-10-02
Report Typos and Errors

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

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

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

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

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

     66:   ts->setupcalled = PETSC_FALSE;

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

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

     78:   Not Collective

     80:   Input Parameter:
     81: . ts - The TS

     83:   Output Parameter:
     84: . type - The name of TS method

     86:   Level: intermediate

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

    100: /*--------------------------------------------------------------------------------------------------------------------*/

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

    107:   Not Collective

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

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

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

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

    132:   Level: advanced

    134: .keywords: TS, register

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

    143:   PetscFunctionListAdd(&TSList,sname,function);
    144:   return(0);
    145: }