Actual source code: tsreg.c

  1: /*$Id: tsreg.c,v 1.68 2001/04/10 19:37:09 bsmith Exp $*/

  3: #include "src/ts/tsimpl.h"      /*I "petscts.h"  I*/

  5: PetscFList      TSList              = 0;
  6: PetscTruth 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
 19:    of available methods (for instance, euler)

 21:    Notes:
 22:    See "petsc/include/petscts.h" for available methods (for instance)
 23: +  TS_EULER - Euler
 24: .  TS_PVODE - PVODE interface
 25: .  TS_BEULER - Backward Euler
 26: -  TS_PSEUDO - Pseudo-timestepping

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

 40:    Level: intermediate

 42: .keywords: TS, set, type
 43: @*/
 44: int TSSetType(TS ts,TSType type)
 45: {
 46:   int        ierr,(*r)(TS);
 47:   PetscTruth match;


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

 56:   /* Get the function pointers for the method requested */
 57:   if (!TSRegisterAllCalled) {TSRegisterAll(PETSC_NULL);}
 58:    PetscFListFind(ts->comm,TSList,type,(void (**)(void)) &r);
 59:   if (!r) {SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Unknown type: %s",type);}

 61:   if (ts->sles) {SLESDestroy(ts->sles);}
 62:   if (ts->snes) {SNESDestroy(ts->snes);}
 63:   if (ts->destroy) {(*(ts)->destroy)(ts);}
 64:   ts->sles = 0;
 65:   ts->snes = 0;

 67:   (*r)(ts);

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

 73: /* --------------------------------------------------------------------- */
 74: /*@C
 75:    TSRegisterDestroy - Frees the list of timesteppers that were
 76:    registered by PetscFListAddDynamic().

 78:    Not Collective

 80:    Level: advanced

 82: .keywords: TS, timestepper, register, destroy

 84: .seealso: TSRegisterAll()
 85: @*/
 86: int TSRegisterDestroy(void)
 87: {

 91:   if (TSList) {
 92:     PetscFListDestroy(&TSList);
 93:     TSList = 0;
 94:   }
 95:   TSRegisterAllCalled = PETSC_FALSE;
 96:   return(0);
 97: }

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

102:    Not Collective

104:    Input Parameter:
105: .  ts - timestepper solver context

107:    Output Parameter:
108: .  type - name of TS method

110:    Level: intermediate

112: .keywords: TS, timestepper, get, type, name
113: @*/
114: int TSGetType(TS ts,TSType *type)
115: {

119:   if (!TSRegisterAllCalled) {TSRegisterAll(PETSC_NULL);}
120:   *type = ts->type_name;
121:   return(0);
122: }

124: /*@
125:    TSSetFromOptions - Sets various TS parameters from user options.

127:    Collective on TS

129:    Input Parameter:
130: .  ts - the TS context obtained from TSCreate()

132:    Options Database Keys:
133: +  -ts_type <type> - TS_EULER, TS_BEULER, TS_PVODE, TS_PSEUDO, TS_CRANK_NICHOLSON
134: .  -ts_max_steps maxsteps - maximum number of time-steps to take
135: .  -ts_max_time time - maximum time to compute to
136: .  -ts_monitor - print information at each timestep
137: -  -ts_xmonitor - plot information at each timestep

139:    Level: beginner

141: .keywords: TS, timestep, set, options, database

143: .seealso: TSSetTypeFromOptions()
144: @*/
145: int TSSetFromOptions(TS ts)
146: {
147:   int        ierr;
148:   PetscTruth flg;
149:   char       *deft,type[256];


154:   PetscOptionsBegin(ts->comm,ts->prefix,"Time step options","TS");
155:     if (ts->type_name) {
156:       deft = ts->type_name;
157:     } else {
158:       deft = TS_EULER;
159:     }
160:     if (!TSRegisterAllCalled) {TSRegisterAll(PETSC_NULL);}
161:     PetscOptionsList("-ts_type","Timestep method","TSSetType",TSList,deft,type,256,&flg);
162:     if (flg) {
163:       TSSetType(ts,type);
164:     } else if (!ts->type_name) {
165:       TSSetType(ts,deft);
166:     }

168:     PetscOptionsInt("-ts_max_steps","Maximum number of time steps","TSSetDuration",ts->max_steps,&ts->max_steps,PETSC_NULL);
169:     PetscOptionsDouble("-ts_max_time","Time to run to","TSSetDuration",ts->max_time,&ts->max_time,PETSC_NULL);
170:     PetscOptionsName("-ts_monitor","Monitor timestep size","TSDefaultMonitor",&flg);
171:     if (flg) {
172:       TSSetMonitor(ts,TSDefaultMonitor,PETSC_NULL,PETSC_NULL);
173:     }
174:     PetscOptionsName("-ts_xmonitor","Monitor timestep size graphically","TSLGMonitor",&flg);
175:     if (flg) {
176:       TSSetMonitor(ts,TSLGMonitor,PETSC_NULL,PETSC_NULL);
177:     }
178:     PetscOptionsName("-ts_vecmonitor","Monitor solution graphically","TSVecViewMonitor",&flg);
179:     if (flg) {
180:       TSSetMonitor(ts,TSVecViewMonitor,PETSC_NULL,PETSC_NULL);
181:     }
182:     if (ts->setfromoptions) {
183:       (*ts->setfromoptions)(ts);
184:     }
185:   PetscOptionsEnd();
186:   return(0);
187: }