1*4bbc92c1SBarry Smith /*$Id: tsreg.c,v 1.62 2000/08/17 04:52:57 bsmith Exp bsmith $*/ 23f3760d9SBarry Smith 3e090d566SSatish Balay #include "src/ts/tsimpl.h" /*I "petscts.h" I*/ 43f3760d9SBarry Smith 5488ecbafSBarry Smith FList TSList = 0; 64c49b128SBarry Smith PetscTruth TSRegisterAllCalled = PETSC_FALSE; 73f3760d9SBarry Smith 85615d1e5SSatish Balay #undef __FUNC__ 9b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"TSSetType" 1082bf6240SBarry Smith /*@C 11ae12b187SLois Curfman McInnes TSSetType - Sets the method for the timestepping solver. 123f3760d9SBarry Smith 13fee21e36SBarry Smith Collective on TS 14fee21e36SBarry Smith 15bef22f13SLois Curfman McInnes Input Parameters: 16bef22f13SLois Curfman McInnes + ts - the TS context 17454a90a3SBarry Smith - type - a known method 18bef22f13SLois Curfman McInnes 19ae12b187SLois Curfman McInnes Options Database Command: 20454a90a3SBarry Smith . -ts_type <type> - Sets the method; use -help for a list 21bef22f13SLois Curfman McInnes of available methods (for instance, euler) 22ae12b187SLois Curfman McInnes 233f3760d9SBarry Smith Notes: 24e090d566SSatish Balay See "petsc/include/petscts.h" for available methods (for instance) 25d5d37b61SLois Curfman McInnes + TS_EULER - Euler 26bef22f13SLois Curfman McInnes . TS_PVODE - PVODE interface 27bef22f13SLois Curfman McInnes . TS_BEULER - Backward Euler 28d5d37b61SLois Curfman McInnes - TS_PSEUDO - Pseudo-timestepping 293f3760d9SBarry Smith 30ae12b187SLois Curfman McInnes Normally, it is best to use the TSSetFromOptions() command and 31ae12b187SLois Curfman McInnes then set the TS type from the options database rather than by using 32ae12b187SLois Curfman McInnes this routine. Using the options database provides the user with 33ae12b187SLois Curfman McInnes maximum flexibility in evaluating the many different solvers. 34ae12b187SLois Curfman McInnes The TSSetType() routine is provided for those situations where it 35ae12b187SLois Curfman McInnes is necessary to set the timestepping solver independently of the 36ae12b187SLois Curfman McInnes command line or options database. This might be the case, for example, 37ae12b187SLois Curfman McInnes when the choice of solver changes during the execution of the 38ae12b187SLois Curfman McInnes program, and the user's application is taking responsibility for 39ae12b187SLois Curfman McInnes choosing the appropriate method. In other words, this routine is 40d5d37b61SLois Curfman McInnes not for beginners. 41d5d37b61SLois Curfman McInnes 42d5d37b61SLois Curfman McInnes Level: intermediate 433f3760d9SBarry Smith 44ae12b187SLois Curfman McInnes .keywords: TS, set, type 453f3760d9SBarry Smith @*/ 46454a90a3SBarry Smith int TSSetType(TS ts,TSType type) 473f3760d9SBarry Smith { 48d83d6502SBarry Smith int ierr,(*r)(TS); 496831982aSBarry Smith PetscTruth match; 508b1af7b3SBarry Smith 513a40ed3dSBarry Smith PetscFunctionBegin; 52c3e30b67SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 530f5bd95cSBarry Smith PetscValidCharPointer(type); 540f5bd95cSBarry Smith 556831982aSBarry Smith ierr = PetscTypeCompare((PetscObject)ts,type,&match);CHKERRQ(ierr); 560f5bd95cSBarry Smith if (match) PetscFunctionReturn(0); 57df8cb225SBarry Smith 588b1af7b3SBarry Smith /* Get the function pointers for the method requested */ 5982bf6240SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 60454a90a3SBarry Smith ierr = FListFind(ts->comm,TSList,type,(int (**)(void *)) &r);CHKERRQ(ierr); 61454a90a3SBarry Smith if (!r) {SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,0,"Unknown type: %s",type);} 6282bf6240SBarry Smith 63df8cb225SBarry Smith if (ts->sles) {ierr = SLESDestroy(ts->sles);CHKERRQ(ierr);} 64df8cb225SBarry Smith if (ts->snes) {ierr = SNESDestroy(ts->snes);CHKERRQ(ierr);} 65e1311b90SBarry Smith if (ts->destroy) {ierr = (*(ts)->destroy)(ts);CHKERRQ(ierr);} 66df8cb225SBarry Smith ts->sles = 0; 67df8cb225SBarry Smith ts->snes = 0; 6882bf6240SBarry Smith 693a40ed3dSBarry Smith ierr = (*r)(ts);CHKERRQ(ierr); 70df8cb225SBarry Smith 71454a90a3SBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)ts,type);CHKERRQ(ierr); 723a40ed3dSBarry Smith PetscFunctionReturn(0); 733f3760d9SBarry Smith } 74df8cb225SBarry Smith 753f3760d9SBarry Smith /* --------------------------------------------------------------------- */ 765615d1e5SSatish Balay #undef __FUNC__ 77b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"TSRegisterDestroy" 783f3760d9SBarry Smith /*@C 7984cb2905SBarry Smith TSRegisterDestroy - Frees the list of timesteppers that were 80f1af5d2fSBarry Smith registered by FListAddDynamic(). 813f3760d9SBarry Smith 82fee21e36SBarry Smith Not Collective 83fee21e36SBarry Smith 84d5d37b61SLois Curfman McInnes Level: advanced 85d5d37b61SLois Curfman McInnes 862d872ea7SLois Curfman McInnes .keywords: TS, timestepper, register, destroy 873f3760d9SBarry Smith 8882bf6240SBarry Smith .seealso: TSRegisterAll() 893f3760d9SBarry Smith @*/ 90cf256101SBarry Smith int TSRegisterDestroy(void) 913f3760d9SBarry Smith { 92df8cb225SBarry Smith int ierr; 93df8cb225SBarry Smith 943a40ed3dSBarry Smith PetscFunctionBegin; 9582bf6240SBarry Smith if (TSList) { 961d1367b7SBarry Smith ierr = FListDestroy(&TSList);CHKERRQ(ierr); 9782bf6240SBarry Smith TSList = 0; 983f3760d9SBarry Smith } 994c49b128SBarry Smith TSRegisterAllCalled = PETSC_FALSE; 1003a40ed3dSBarry Smith PetscFunctionReturn(0); 1013f3760d9SBarry Smith } 1023f3760d9SBarry Smith 1035615d1e5SSatish Balay #undef __FUNC__ 104b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"TSGetType" 1053f3760d9SBarry Smith /*@C 106fee21e36SBarry Smith TSGetType - Gets the TS method type (as a string). 1073f3760d9SBarry Smith 108bef22f13SLois Curfman McInnes Not Collective 109bef22f13SLois Curfman McInnes 1103f3760d9SBarry Smith Input Parameter: 1112d872ea7SLois Curfman McInnes . ts - timestepper solver context 1123f3760d9SBarry Smith 1133f3760d9SBarry Smith Output Parameter: 11482bf6240SBarry Smith . type - name of TS method 1153f3760d9SBarry Smith 116d5d37b61SLois Curfman McInnes Level: intermediate 117d5d37b61SLois Curfman McInnes 118df8cb225SBarry Smith .keywords: TS, timestepper, get, type, name 1193f3760d9SBarry Smith @*/ 12082bf6240SBarry Smith int TSGetType(TS ts,TSType *type) 1213f3760d9SBarry Smith { 1223f3760d9SBarry Smith int ierr; 1233a40ed3dSBarry Smith 1243a40ed3dSBarry Smith PetscFunctionBegin; 12582bf6240SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 12682bf6240SBarry Smith *type = ts->type_name; 1273a40ed3dSBarry Smith PetscFunctionReturn(0); 1283f3760d9SBarry Smith } 1293f3760d9SBarry Smith 1305615d1e5SSatish Balay #undef __FUNC__ 131b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"TSSetFromOptions" 132ca161407SBarry Smith /*@ 133ca161407SBarry Smith TSSetFromOptions - Sets various TS parameters from user options. 134ca161407SBarry Smith 135bef22f13SLois Curfman McInnes Collective on TS 136bef22f13SLois Curfman McInnes 137ca161407SBarry Smith Input Parameter: 138ca161407SBarry Smith . ts - the TS context obtained from TSCreate() 139ca161407SBarry Smith 14015091d37SBarry Smith Options Database Keys: 14115091d37SBarry Smith + -ts_type <type> - TS_EULER, TS_BEULER, TS_PVODE, TS_PSEUDO, TS_CRANK_NICHOLSON 14215091d37SBarry Smith . -ts_max_steps maxsteps - maximum number of time-steps to take 14315091d37SBarry Smith . -ts_max_time time - maximum time to compute to 14415091d37SBarry Smith . -ts_monitor - print information at each timestep 14515091d37SBarry Smith - -ts_xmonitor - plot information at each timestep 14615091d37SBarry Smith 147d5d37b61SLois Curfman McInnes Level: beginner 148d5d37b61SLois Curfman McInnes 149ca161407SBarry Smith .keywords: TS, timestep, set, options, database 150ca161407SBarry Smith 151*4bbc92c1SBarry Smith .seealso: TSSetTypeFromOptions() 152ca161407SBarry Smith @*/ 153ca161407SBarry Smith int TSSetFromOptions(TS ts) 154ca161407SBarry Smith { 155*4bbc92c1SBarry Smith int ierr; 156f1af5d2fSBarry Smith PetscTruth flg; 157*4bbc92c1SBarry Smith char *deft,type[256]; 158ca161407SBarry Smith 159ca161407SBarry Smith PetscFunctionBegin; 160ca161407SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 161ca161407SBarry Smith 162*4bbc92c1SBarry Smith ierr = OptionsBegin(ts->comm,ts->prefix,"Time step options");CHKERRQ(ierr); 163*4bbc92c1SBarry Smith if (ts->type_name) { 164*4bbc92c1SBarry Smith deft = ts->type_name; 165*4bbc92c1SBarry Smith } else { 166*4bbc92c1SBarry Smith deft = TS_EULER; 167*4bbc92c1SBarry Smith } 168*4bbc92c1SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 169*4bbc92c1SBarry Smith ierr = OptionsList("-ts_type","Timestep method","TSSetType",TSList,deft,type,256,&flg);CHKERRQ(ierr); 170*4bbc92c1SBarry Smith if (flg) { 171*4bbc92c1SBarry Smith ierr = TSSetType(ts,type);CHKERRQ(ierr); 172*4bbc92c1SBarry Smith } else if (!ts->type_name) { 173*4bbc92c1SBarry Smith ierr = TSSetType(ts,deft);CHKERRQ(ierr); 174*4bbc92c1SBarry Smith } 175*4bbc92c1SBarry Smith 176*4bbc92c1SBarry Smith ierr = OptionsInt("-ts_max_steps","Maximum number of time steps","TSSetDuration",ts->max_steps,&ts->max_steps,PETSC_NULL);CHKERRQ(ierr); 177*4bbc92c1SBarry Smith ierr = OptionsDouble("-ts_max_time","Time to run to","TSSetDuration",ts->max_time,&ts->max_time,PETSC_NULL);CHKERRQ(ierr); 178*4bbc92c1SBarry Smith ierr = OptionsName("-ts_monitor","Monitor timestep size","TSDefaultMonitor",&flg);CHKERRQ(ierr); 179ca161407SBarry Smith if (flg) { 180329f5518SBarry Smith ierr = TSSetMonitor(ts,TSDefaultMonitor,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr); 181ca161407SBarry Smith } 182*4bbc92c1SBarry Smith ierr = OptionsName("-ts_xmonitor","Monitor timestep size graphically","TSLGMonitor",&flg);CHKERRQ(ierr); 183ca161407SBarry Smith if (flg) { 184329f5518SBarry Smith ierr = TSSetMonitor(ts,TSLGMonitor,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr); 185ca161407SBarry Smith } 186184914b5SBarry Smith if (ts->setfromoptions) { 187ca161407SBarry Smith ierr = (*ts->setfromoptions)(ts);CHKERRQ(ierr); 188184914b5SBarry Smith } 189*4bbc92c1SBarry Smith ierr = OptionsEnd();CHKERRQ(ierr); 190ca161407SBarry Smith PetscFunctionReturn(0); 191ca161407SBarry Smith } 192ca161407SBarry Smith 19382bf6240SBarry Smith 194184914b5SBarry Smith 195