1a5eb4965SSatish Balay #ifdef PETSC_RCS_HEADER 2*488ecbafSBarry Smith static char vcid[] = "$Id: tsreg.c,v 1.36 1998/04/25 11:54:57 curfman Exp bsmith $"; 33f3760d9SBarry Smith #endif 43f3760d9SBarry Smith 570f55243SBarry Smith #include "src/ts/tsimpl.h" /*I "ts.h" I*/ 6f5eb4b81SSatish Balay #include "src/sys/nreg.h" 73f3760d9SBarry Smith #include "pinclude/pviewer.h" 83f3760d9SBarry Smith #include <math.h> 93f3760d9SBarry Smith 10*488ecbafSBarry Smith FList TSList = 0; 1184cb2905SBarry Smith int TSRegisterAllCalled = 0; 123f3760d9SBarry Smith 135615d1e5SSatish Balay #undef __FUNC__ 14d4bb536fSBarry Smith #define __FUNC__ "TSSetType" 1582bf6240SBarry Smith /*@C 16ae12b187SLois Curfman McInnes TSSetType - Sets the method for the timestepping solver. 173f3760d9SBarry Smith 18fee21e36SBarry Smith Collective on TS 19fee21e36SBarry Smith 20bef22f13SLois Curfman McInnes Input Parameters: 21bef22f13SLois Curfman McInnes + ts - the TS context 22bef22f13SLois Curfman McInnes - method - a known method 23bef22f13SLois Curfman McInnes 24ae12b187SLois Curfman McInnes Options Database Command: 25bef22f13SLois Curfman McInnes . -ts_type <method> - Sets the method; use -help for a list 26bef22f13SLois Curfman McInnes of available methods (for instance, euler) 27ae12b187SLois Curfman McInnes 283f3760d9SBarry Smith Notes: 298b1af7b3SBarry Smith See "petsc/include/ts.h" for available methods (for instance) 30bef22f13SLois Curfman McInnes . TS_EULER - Euler 31bef22f13SLois Curfman McInnes . TS_PVODE - PVODE interface 32bef22f13SLois Curfman McInnes . TS_BEULER - Backward Euler 33bef22f13SLois Curfman McInnes . TS_PSEUDO - Pseudo-timestepping 343f3760d9SBarry Smith 35ae12b187SLois Curfman McInnes Normally, it is best to use the TSSetFromOptions() command and 36ae12b187SLois Curfman McInnes then set the TS type from the options database rather than by using 37ae12b187SLois Curfman McInnes this routine. Using the options database provides the user with 38ae12b187SLois Curfman McInnes maximum flexibility in evaluating the many different solvers. 39ae12b187SLois Curfman McInnes The TSSetType() routine is provided for those situations where it 40ae12b187SLois Curfman McInnes is necessary to set the timestepping solver independently of the 41ae12b187SLois Curfman McInnes command line or options database. This might be the case, for example, 42ae12b187SLois Curfman McInnes when the choice of solver changes during the execution of the 43ae12b187SLois Curfman McInnes program, and the user's application is taking responsibility for 44ae12b187SLois Curfman McInnes choosing the appropriate method. In other words, this routine is 45ae12b187SLois Curfman McInnes for the advanced user. 463f3760d9SBarry Smith 47ae12b187SLois Curfman McInnes .keywords: TS, set, type 483f3760d9SBarry Smith @*/ 498b1af7b3SBarry Smith int TSSetType(TS ts,TSType method) 503f3760d9SBarry Smith { 51d83d6502SBarry Smith int ierr,(*r)(TS); 528b1af7b3SBarry Smith 533a40ed3dSBarry Smith PetscFunctionBegin; 54c3e30b67SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 5582bf6240SBarry Smith if (!PetscStrcmp(ts->type_name,method)) PetscFunctionReturn(0); 56df8cb225SBarry Smith 578b1af7b3SBarry Smith /* Get the function pointers for the method requested */ 5882bf6240SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL); CHKERRQ(ierr);} 59*488ecbafSBarry Smith ierr = FListFind(ts->comm, TSList, method, (int (**)(void *)) &r );CHKERRQ(ierr); 60a8c6a408SBarry Smith if (!r) {SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,0,"Unknown method");} 6182bf6240SBarry Smith 62df8cb225SBarry Smith if (ts->sles) {ierr = SLESDestroy(ts->sles); CHKERRQ(ierr);} 63df8cb225SBarry Smith if (ts->snes) {ierr = SNESDestroy(ts->snes); CHKERRQ(ierr);} 64e1311b90SBarry Smith if (ts->destroy) {ierr = (*(ts)->destroy)(ts); CHKERRQ(ierr);} 65df8cb225SBarry Smith ts->sles = 0; 66df8cb225SBarry Smith ts->snes = 0; 6782bf6240SBarry Smith 683a40ed3dSBarry Smith ierr = (*r)(ts);CHKERRQ(ierr); 69df8cb225SBarry Smith 7082bf6240SBarry Smith if (ts->type_name) PetscFree(ts->type_name); 7182bf6240SBarry Smith ts->type_name = (char *) PetscMalloc((PetscStrlen(method)+1)*sizeof(char));CHKPTRQ(ts->type_name); 7282bf6240SBarry Smith PetscStrcpy(ts->type_name,method); 733a40ed3dSBarry Smith PetscFunctionReturn(0); 743f3760d9SBarry Smith } 75df8cb225SBarry Smith 763f3760d9SBarry Smith /* --------------------------------------------------------------------- */ 775615d1e5SSatish Balay #undef __FUNC__ 78d4bb536fSBarry Smith #define __FUNC__ "TSRegisterDestroy" 793f3760d9SBarry Smith /*@C 8084cb2905SBarry Smith TSRegisterDestroy - Frees the list of timesteppers that were 81*488ecbafSBarry Smith registered by FListAdd(). 823f3760d9SBarry Smith 83fee21e36SBarry Smith Not Collective 84fee21e36SBarry Smith 852d872ea7SLois Curfman McInnes .keywords: TS, timestepper, register, destroy 863f3760d9SBarry Smith 8782bf6240SBarry Smith .seealso: TSRegisterAll() 883f3760d9SBarry Smith @*/ 89cf256101SBarry Smith int TSRegisterDestroy(void) 903f3760d9SBarry Smith { 91df8cb225SBarry Smith int ierr; 92df8cb225SBarry Smith 933a40ed3dSBarry Smith PetscFunctionBegin; 9482bf6240SBarry Smith if (TSList) { 95*488ecbafSBarry Smith ierr = FListDestroy( TSList );CHKERRQ(ierr); 9682bf6240SBarry Smith TSList = 0; 973f3760d9SBarry Smith } 9884cb2905SBarry Smith TSRegisterAllCalled = 0; 993a40ed3dSBarry Smith PetscFunctionReturn(0); 1003f3760d9SBarry Smith } 1013f3760d9SBarry Smith 1025615d1e5SSatish Balay #undef __FUNC__ 103d4bb536fSBarry Smith #define __FUNC__ "TSGetType" 1043f3760d9SBarry Smith /*@C 105fee21e36SBarry Smith TSGetType - Gets the TS method type (as a string). 1063f3760d9SBarry Smith 107bef22f13SLois Curfman McInnes Not Collective 108bef22f13SLois Curfman McInnes 1093f3760d9SBarry Smith Input Parameter: 1102d872ea7SLois Curfman McInnes . ts - timestepper solver context 1113f3760d9SBarry Smith 1123f3760d9SBarry Smith Output Parameter: 11382bf6240SBarry Smith . type - name of TS method 1143f3760d9SBarry Smith 115df8cb225SBarry Smith .keywords: TS, timestepper, get, type, name 1163f3760d9SBarry Smith @*/ 11782bf6240SBarry Smith int TSGetType(TS ts, TSType *type) 1183f3760d9SBarry Smith { 1193f3760d9SBarry Smith int ierr; 1203a40ed3dSBarry Smith 1213a40ed3dSBarry Smith PetscFunctionBegin; 12282bf6240SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL); CHKERRQ(ierr);} 12382bf6240SBarry Smith *type = ts->type_name; 1243a40ed3dSBarry Smith PetscFunctionReturn(0); 1253f3760d9SBarry Smith } 1263f3760d9SBarry Smith 1275615d1e5SSatish Balay #undef __FUNC__ 128ca161407SBarry Smith #define __FUNC__ "TSPrintHelp" 129ca161407SBarry Smith /*@ 130ca161407SBarry Smith TSPrintHelp - Prints all options for the TS (timestepping) component. 1313f3760d9SBarry Smith 132bef22f13SLois Curfman McInnes Collective on TS 133bef22f13SLois Curfman McInnes 1343f3760d9SBarry Smith Input Parameter: 135ca161407SBarry Smith . ts - the TS context obtained from TSCreate() 1363f3760d9SBarry Smith 137ca161407SBarry Smith Options Database Keys: 138bef22f13SLois Curfman McInnes + -help - Prints KSP options 139bef22f13SLois Curfman McInnes - -h - Prints KSP options 140fee21e36SBarry Smith 141ca161407SBarry Smith .keywords: TS, timestep, print, help 142ca161407SBarry Smith 143ca161407SBarry Smith .seealso: TSSetFromOptions() 144ca161407SBarry Smith @*/ 145ca161407SBarry Smith int TSPrintHelp(TS ts) 1463f3760d9SBarry Smith { 147ca161407SBarry Smith char *prefix = "-"; 1488b1af7b3SBarry Smith int ierr; 1493a40ed3dSBarry Smith 1503a40ed3dSBarry Smith PetscFunctionBegin; 151ca161407SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 152ca161407SBarry Smith if (ts->prefix) prefix = ts->prefix; 15376be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm,"TS options --------------------------------------------------\n"); 154*488ecbafSBarry Smith ierr = FListPrintTypes(ts->comm,stdout,ts->prefix,"ts_type",TSList);CHKERRQ(ierr); 15576be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_monitor: use default TS monitor\n",prefix); 15676be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_view: view TS info after each solve\n",prefix); 157ca161407SBarry Smith 15876be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_max_steps <steps>: maximum steps, defaults to %d\n",prefix,ts->max_steps); 15976be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_max_time <steps>: maximum time, defaults to %g\n",prefix,ts->max_time); 160ca161407SBarry Smith if (ts->printhelp) {ierr = (*ts->printhelp)(ts,prefix);CHKERRQ(ierr);} 1613a40ed3dSBarry Smith PetscFunctionReturn(0); 1623f3760d9SBarry Smith } 163ca161407SBarry Smith 164ca161407SBarry Smith #undef __FUNC__ 165ca161407SBarry Smith #define __FUNC__ "TSSetFromOptions" 166ca161407SBarry Smith /*@ 167ca161407SBarry Smith TSSetFromOptions - Sets various TS parameters from user options. 168ca161407SBarry Smith 169bef22f13SLois Curfman McInnes Collective on TS 170bef22f13SLois Curfman McInnes 171ca161407SBarry Smith Input Parameter: 172ca161407SBarry Smith . ts - the TS context obtained from TSCreate() 173ca161407SBarry Smith 174ca161407SBarry Smith .keywords: TS, timestep, set, options, database 175ca161407SBarry Smith 176ca161407SBarry Smith .seealso: TSPrintHelp() 177ca161407SBarry Smith @*/ 178ca161407SBarry Smith int TSSetFromOptions(TS ts) 179ca161407SBarry Smith { 180ca161407SBarry Smith int ierr,flg,loc[4],nmax; 18182bf6240SBarry Smith char type[256]; 182ca161407SBarry Smith 183ca161407SBarry Smith PetscFunctionBegin; 184ca161407SBarry Smith loc[0] = PETSC_DECIDE; loc[1] = PETSC_DECIDE; loc[2] = 300; loc[3] = 300; 185ca161407SBarry Smith 186ca161407SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 18782bf6240SBarry Smith if (ts->setupcalled) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,0,"Must call prior to TSSetUp!"); 18882bf6240SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 18982bf6240SBarry Smith ierr = OptionsGetString(ts->prefix,"-ts_type",(char *) type,256,&flg); 190ca161407SBarry Smith if (flg) { 191df8cb225SBarry Smith ierr = TSSetType(ts,type); CHKERRQ(ierr); 192ca161407SBarry Smith } 193ca161407SBarry Smith 194ca161407SBarry Smith ierr = OptionsGetInt(ts->prefix,"-ts_max_steps",&ts->max_steps,&flg);CHKERRQ(ierr); 195ca161407SBarry Smith ierr = OptionsGetDouble(ts->prefix,"-ts_max_time",&ts->max_time,&flg);CHKERRQ(ierr); 196ca161407SBarry Smith ierr = OptionsHasName(ts->prefix,"-ts_monitor",&flg); CHKERRQ(ierr); 197ca161407SBarry Smith if (flg) { 198ca161407SBarry Smith ierr = TSSetMonitor(ts,TSDefaultMonitor,0);CHKERRQ(ierr); 199ca161407SBarry Smith } 200ca161407SBarry Smith nmax = 4; 201ca161407SBarry Smith ierr = OptionsGetIntArray(ts->prefix,"-ts_xmonitor",loc,&nmax,&flg); CHKERRQ(ierr); 202ca161407SBarry Smith if (flg) { 203ca161407SBarry Smith int rank = 0; 204ca161407SBarry Smith DrawLG lg; 205ca161407SBarry Smith MPI_Comm_rank(ts->comm,&rank); 206ca161407SBarry Smith if (!rank) { 207ca161407SBarry Smith ierr = TSLGMonitorCreate(0,0,loc[0],loc[1],loc[2],loc[3],&lg); CHKERRQ(ierr); 208ca161407SBarry Smith PLogObjectParent(ts,(PetscObject) lg); 209ca161407SBarry Smith ierr = TSSetMonitor(ts,TSLGMonitor,(void *)lg);CHKERRQ(ierr); 210ca161407SBarry Smith } 211ca161407SBarry Smith } 21282bf6240SBarry Smith if (!ts->type_name) { 2136a6a5d1dSBarry Smith ierr = TSSetType(ts,TS_EULER);CHKERRQ(ierr); 2146a6a5d1dSBarry Smith } 2156a6a5d1dSBarry Smith ierr = OptionsHasName(PETSC_NULL,"-help",&flg); CHKERRQ(ierr); 2166a6a5d1dSBarry Smith if (flg) {ierr = TSPrintHelp(ts);CHKERRQ(ierr);} 217ca161407SBarry Smith if (!ts->setfromoptions) PetscFunctionReturn(0); 218ca161407SBarry Smith ierr = (*ts->setfromoptions)(ts);CHKERRQ(ierr); 219ca161407SBarry Smith PetscFunctionReturn(0); 220ca161407SBarry Smith } 221ca161407SBarry Smith 22282bf6240SBarry Smith 223