Actual source code: tsreg.c

  1: /*$Id: tsreg.c,v 1.69 2001/04/14 03:58:15 bsmith Exp $*/

 3:  #include src/ts/tsimpl.h

  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_dt dt - initial time step
137: .  -ts_monitor - print information at each timestep
138: -  -ts_xmonitor - plot information at each timestep

140:    Level: beginner

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

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


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

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