1a5eb4965SSatish Balay #ifdef PETSC_RCS_HEADER 2*d5d37b61SLois Curfman McInnes static char vcid[] = "$Id: tsreg.c,v 1.40 1999/01/04 21:52:56 bsmith Exp curfman $"; 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 8488ecbafSBarry Smith FList TSList = 0; 984cb2905SBarry Smith int TSRegisterAllCalled = 0; 103f3760d9SBarry Smith 115615d1e5SSatish Balay #undef __FUNC__ 12d4bb536fSBarry Smith #define __FUNC__ "TSSetType" 1382bf6240SBarry Smith /*@C 14ae12b187SLois Curfman McInnes TSSetType - Sets the method for the timestepping solver. 153f3760d9SBarry Smith 16fee21e36SBarry Smith Collective on TS 17fee21e36SBarry Smith 18bef22f13SLois Curfman McInnes Input Parameters: 19bef22f13SLois Curfman McInnes + ts - the TS context 20bef22f13SLois Curfman McInnes - method - a known method 21bef22f13SLois Curfman McInnes 22ae12b187SLois Curfman McInnes Options Database Command: 23bef22f13SLois Curfman McInnes . -ts_type <method> - Sets the method; use -help for a list 24bef22f13SLois Curfman McInnes of available methods (for instance, euler) 25ae12b187SLois Curfman McInnes 263f3760d9SBarry Smith Notes: 278b1af7b3SBarry Smith See "petsc/include/ts.h" for available methods (for instance) 28*d5d37b61SLois Curfman McInnes + TS_EULER - Euler 29bef22f13SLois Curfman McInnes . TS_PVODE - PVODE interface 30bef22f13SLois Curfman McInnes . TS_BEULER - Backward Euler 31*d5d37b61SLois Curfman McInnes - TS_PSEUDO - Pseudo-timestepping 323f3760d9SBarry Smith 33ae12b187SLois Curfman McInnes Normally, it is best to use the TSSetFromOptions() command and 34ae12b187SLois Curfman McInnes then set the TS type from the options database rather than by using 35ae12b187SLois Curfman McInnes this routine. Using the options database provides the user with 36ae12b187SLois Curfman McInnes maximum flexibility in evaluating the many different solvers. 37ae12b187SLois Curfman McInnes The TSSetType() routine is provided for those situations where it 38ae12b187SLois Curfman McInnes is necessary to set the timestepping solver independently of the 39ae12b187SLois Curfman McInnes command line or options database. This might be the case, for example, 40ae12b187SLois Curfman McInnes when the choice of solver changes during the execution of the 41ae12b187SLois Curfman McInnes program, and the user's application is taking responsibility for 42ae12b187SLois Curfman McInnes choosing the appropriate method. In other words, this routine is 43*d5d37b61SLois Curfman McInnes not for beginners. 44*d5d37b61SLois Curfman McInnes 45*d5d37b61SLois Curfman McInnes Level: intermediate 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); 553f1db9ecSBarry Smith if (PetscTypeCompare(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);} 59488ecbafSBarry Smith ierr = FListFind(ts->comm, TSList, method, (int (**)(void *)) &r );CHKERRQ(ierr); 60596552b5SBarry Smith if (!r) {SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,0,"Unknown method: %s",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 81488ecbafSBarry Smith registered by FListAdd(). 823f3760d9SBarry Smith 83fee21e36SBarry Smith Not Collective 84fee21e36SBarry Smith 85*d5d37b61SLois Curfman McInnes Level: advanced 86*d5d37b61SLois Curfman McInnes 872d872ea7SLois Curfman McInnes .keywords: TS, timestepper, register, destroy 883f3760d9SBarry Smith 8982bf6240SBarry Smith .seealso: TSRegisterAll() 903f3760d9SBarry Smith @*/ 91cf256101SBarry Smith int TSRegisterDestroy(void) 923f3760d9SBarry Smith { 93df8cb225SBarry Smith int ierr; 94df8cb225SBarry Smith 953a40ed3dSBarry Smith PetscFunctionBegin; 9682bf6240SBarry Smith if (TSList) { 97488ecbafSBarry Smith ierr = FListDestroy( TSList );CHKERRQ(ierr); 9882bf6240SBarry Smith TSList = 0; 993f3760d9SBarry Smith } 10084cb2905SBarry Smith TSRegisterAllCalled = 0; 1013a40ed3dSBarry Smith PetscFunctionReturn(0); 1023f3760d9SBarry Smith } 1033f3760d9SBarry Smith 1045615d1e5SSatish Balay #undef __FUNC__ 105d4bb536fSBarry Smith #define __FUNC__ "TSGetType" 1063f3760d9SBarry Smith /*@C 107fee21e36SBarry Smith TSGetType - Gets the TS method type (as a string). 1083f3760d9SBarry Smith 109bef22f13SLois Curfman McInnes Not Collective 110bef22f13SLois Curfman McInnes 1113f3760d9SBarry Smith Input Parameter: 1122d872ea7SLois Curfman McInnes . ts - timestepper solver context 1133f3760d9SBarry Smith 1143f3760d9SBarry Smith Output Parameter: 11582bf6240SBarry Smith . type - name of TS method 1163f3760d9SBarry Smith 117*d5d37b61SLois Curfman McInnes Level: intermediate 118*d5d37b61SLois Curfman McInnes 119df8cb225SBarry Smith .keywords: TS, timestepper, get, type, name 1203f3760d9SBarry Smith @*/ 12182bf6240SBarry Smith int TSGetType(TS ts, TSType *type) 1223f3760d9SBarry Smith { 1233f3760d9SBarry Smith int ierr; 1243a40ed3dSBarry Smith 1253a40ed3dSBarry Smith PetscFunctionBegin; 12682bf6240SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL); CHKERRQ(ierr);} 12782bf6240SBarry Smith *type = ts->type_name; 1283a40ed3dSBarry Smith PetscFunctionReturn(0); 1293f3760d9SBarry Smith } 1303f3760d9SBarry Smith 1315615d1e5SSatish Balay #undef __FUNC__ 132ca161407SBarry Smith #define __FUNC__ "TSPrintHelp" 133ca161407SBarry Smith /*@ 134ca161407SBarry Smith TSPrintHelp - Prints all options for the TS (timestepping) component. 1353f3760d9SBarry Smith 136bef22f13SLois Curfman McInnes Collective on TS 137bef22f13SLois Curfman McInnes 1383f3760d9SBarry Smith Input Parameter: 139ca161407SBarry Smith . ts - the TS context obtained from TSCreate() 1403f3760d9SBarry Smith 141ca161407SBarry Smith Options Database Keys: 142bef22f13SLois Curfman McInnes + -help - Prints KSP options 143bef22f13SLois Curfman McInnes - -h - Prints KSP options 144fee21e36SBarry Smith 145*d5d37b61SLois Curfman McInnes Level: beginner 146*d5d37b61SLois Curfman McInnes 147ca161407SBarry Smith .keywords: TS, timestep, print, help 148ca161407SBarry Smith 149ca161407SBarry Smith .seealso: TSSetFromOptions() 150ca161407SBarry Smith @*/ 151ca161407SBarry Smith int TSPrintHelp(TS ts) 1523f3760d9SBarry Smith { 153ca161407SBarry Smith char *prefix = "-"; 1548b1af7b3SBarry Smith int ierr; 1553a40ed3dSBarry Smith 1563a40ed3dSBarry Smith PetscFunctionBegin; 157ca161407SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 158ca161407SBarry Smith if (ts->prefix) prefix = ts->prefix; 15976be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm,"TS options --------------------------------------------------\n"); 160488ecbafSBarry Smith ierr = FListPrintTypes(ts->comm,stdout,ts->prefix,"ts_type",TSList);CHKERRQ(ierr); 16176be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_monitor: use default TS monitor\n",prefix); 16276be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_view: view TS info after each solve\n",prefix); 163ca161407SBarry Smith 16476be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_max_steps <steps>: maximum steps, defaults to %d\n",prefix,ts->max_steps); 16576be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_max_time <steps>: maximum time, defaults to %g\n",prefix,ts->max_time); 166ca161407SBarry Smith if (ts->printhelp) {ierr = (*ts->printhelp)(ts,prefix);CHKERRQ(ierr);} 1673a40ed3dSBarry Smith PetscFunctionReturn(0); 1683f3760d9SBarry Smith } 169ca161407SBarry Smith 170ca161407SBarry Smith #undef __FUNC__ 171ca161407SBarry Smith #define __FUNC__ "TSSetFromOptions" 172ca161407SBarry Smith /*@ 173ca161407SBarry Smith TSSetFromOptions - Sets various TS parameters from user options. 174ca161407SBarry Smith 175bef22f13SLois Curfman McInnes Collective on TS 176bef22f13SLois Curfman McInnes 177ca161407SBarry Smith Input Parameter: 178ca161407SBarry Smith . ts - the TS context obtained from TSCreate() 179ca161407SBarry Smith 180*d5d37b61SLois Curfman McInnes Level: beginner 181*d5d37b61SLois Curfman McInnes 182ca161407SBarry Smith .keywords: TS, timestep, set, options, database 183ca161407SBarry Smith 184ca161407SBarry Smith .seealso: TSPrintHelp() 185ca161407SBarry Smith @*/ 186ca161407SBarry Smith int TSSetFromOptions(TS ts) 187ca161407SBarry Smith { 188ca161407SBarry Smith int ierr,flg,loc[4],nmax; 18982bf6240SBarry Smith char type[256]; 190ca161407SBarry Smith 191ca161407SBarry Smith PetscFunctionBegin; 192ca161407SBarry Smith loc[0] = PETSC_DECIDE; loc[1] = PETSC_DECIDE; loc[2] = 300; loc[3] = 300; 193ca161407SBarry Smith 194ca161407SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 195596552b5SBarry Smith if (ts->setupcalled) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,0,"Must call prior to TSSetUp()"); 19682bf6240SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 19782bf6240SBarry Smith ierr = OptionsGetString(ts->prefix,"-ts_type",(char *) type,256,&flg); 198ca161407SBarry Smith if (flg) { 199df8cb225SBarry Smith ierr = TSSetType(ts,type); CHKERRQ(ierr); 200ca161407SBarry Smith } 201ca161407SBarry Smith 202ca161407SBarry Smith ierr = OptionsGetInt(ts->prefix,"-ts_max_steps",&ts->max_steps,&flg);CHKERRQ(ierr); 203ca161407SBarry Smith ierr = OptionsGetDouble(ts->prefix,"-ts_max_time",&ts->max_time,&flg);CHKERRQ(ierr); 204ca161407SBarry Smith ierr = OptionsHasName(ts->prefix,"-ts_monitor",&flg); CHKERRQ(ierr); 205ca161407SBarry Smith if (flg) { 206ca161407SBarry Smith ierr = TSSetMonitor(ts,TSDefaultMonitor,0);CHKERRQ(ierr); 207ca161407SBarry Smith } 208ca161407SBarry Smith nmax = 4; 209ca161407SBarry Smith ierr = OptionsGetIntArray(ts->prefix,"-ts_xmonitor",loc,&nmax,&flg); CHKERRQ(ierr); 210ca161407SBarry Smith if (flg) { 211ca161407SBarry Smith int rank = 0; 212ca161407SBarry Smith DrawLG lg; 213ca161407SBarry Smith MPI_Comm_rank(ts->comm,&rank); 214ca161407SBarry Smith if (!rank) { 215ca161407SBarry Smith ierr = TSLGMonitorCreate(0,0,loc[0],loc[1],loc[2],loc[3],&lg); CHKERRQ(ierr); 216ca161407SBarry Smith PLogObjectParent(ts,(PetscObject) lg); 217ca161407SBarry Smith ierr = TSSetMonitor(ts,TSLGMonitor,(void *)lg);CHKERRQ(ierr); 218ca161407SBarry Smith } 219ca161407SBarry Smith } 22082bf6240SBarry Smith if (!ts->type_name) { 2216a6a5d1dSBarry Smith ierr = TSSetType(ts,TS_EULER);CHKERRQ(ierr); 2226a6a5d1dSBarry Smith } 2236a6a5d1dSBarry Smith ierr = OptionsHasName(PETSC_NULL,"-help",&flg); CHKERRQ(ierr); 2246a6a5d1dSBarry Smith if (flg) {ierr = TSPrintHelp(ts);CHKERRQ(ierr);} 225ca161407SBarry Smith if (!ts->setfromoptions) PetscFunctionReturn(0); 226ca161407SBarry Smith ierr = (*ts->setfromoptions)(ts);CHKERRQ(ierr); 227ca161407SBarry Smith PetscFunctionReturn(0); 228ca161407SBarry Smith } 229ca161407SBarry Smith 23082bf6240SBarry Smith 231