1a5eb4965SSatish Balay #ifdef PETSC_RCS_HEADER 2*3f1db9ecSBarry Smith static char vcid[] = "$Id: tsreg.c,v 1.38 1998/12/03 04:03:52 bsmith 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 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) 28bef22f13SLois Curfman McInnes . TS_EULER - Euler 29bef22f13SLois Curfman McInnes . TS_PVODE - PVODE interface 30bef22f13SLois Curfman McInnes . TS_BEULER - Backward Euler 31bef22f13SLois 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 43ae12b187SLois Curfman McInnes for the advanced user. 443f3760d9SBarry Smith 45ae12b187SLois Curfman McInnes .keywords: TS, set, type 463f3760d9SBarry Smith @*/ 478b1af7b3SBarry Smith int TSSetType(TS ts,TSType method) 483f3760d9SBarry Smith { 49d83d6502SBarry Smith int ierr,(*r)(TS); 508b1af7b3SBarry Smith 513a40ed3dSBarry Smith PetscFunctionBegin; 52c3e30b67SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 53*3f1db9ecSBarry Smith if (PetscTypeCompare(ts->type_name,method)) PetscFunctionReturn(0); 54df8cb225SBarry Smith 558b1af7b3SBarry Smith /* Get the function pointers for the method requested */ 5682bf6240SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL); CHKERRQ(ierr);} 57488ecbafSBarry Smith ierr = FListFind(ts->comm, TSList, method, (int (**)(void *)) &r );CHKERRQ(ierr); 58a8c6a408SBarry Smith if (!r) {SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,0,"Unknown method");} 5982bf6240SBarry Smith 60df8cb225SBarry Smith if (ts->sles) {ierr = SLESDestroy(ts->sles); CHKERRQ(ierr);} 61df8cb225SBarry Smith if (ts->snes) {ierr = SNESDestroy(ts->snes); CHKERRQ(ierr);} 62e1311b90SBarry Smith if (ts->destroy) {ierr = (*(ts)->destroy)(ts); CHKERRQ(ierr);} 63df8cb225SBarry Smith ts->sles = 0; 64df8cb225SBarry Smith ts->snes = 0; 6582bf6240SBarry Smith 663a40ed3dSBarry Smith ierr = (*r)(ts);CHKERRQ(ierr); 67df8cb225SBarry Smith 6882bf6240SBarry Smith if (ts->type_name) PetscFree(ts->type_name); 6982bf6240SBarry Smith ts->type_name = (char *) PetscMalloc((PetscStrlen(method)+1)*sizeof(char));CHKPTRQ(ts->type_name); 7082bf6240SBarry Smith PetscStrcpy(ts->type_name,method); 713a40ed3dSBarry Smith PetscFunctionReturn(0); 723f3760d9SBarry Smith } 73df8cb225SBarry Smith 743f3760d9SBarry Smith /* --------------------------------------------------------------------- */ 755615d1e5SSatish Balay #undef __FUNC__ 76d4bb536fSBarry Smith #define __FUNC__ "TSRegisterDestroy" 773f3760d9SBarry Smith /*@C 7884cb2905SBarry Smith TSRegisterDestroy - Frees the list of timesteppers that were 79488ecbafSBarry Smith registered by FListAdd(). 803f3760d9SBarry Smith 81fee21e36SBarry Smith Not Collective 82fee21e36SBarry Smith 832d872ea7SLois Curfman McInnes .keywords: TS, timestepper, register, destroy 843f3760d9SBarry Smith 8582bf6240SBarry Smith .seealso: TSRegisterAll() 863f3760d9SBarry Smith @*/ 87cf256101SBarry Smith int TSRegisterDestroy(void) 883f3760d9SBarry Smith { 89df8cb225SBarry Smith int ierr; 90df8cb225SBarry Smith 913a40ed3dSBarry Smith PetscFunctionBegin; 9282bf6240SBarry Smith if (TSList) { 93488ecbafSBarry Smith ierr = FListDestroy( TSList );CHKERRQ(ierr); 9482bf6240SBarry Smith TSList = 0; 953f3760d9SBarry Smith } 9684cb2905SBarry Smith TSRegisterAllCalled = 0; 973a40ed3dSBarry Smith PetscFunctionReturn(0); 983f3760d9SBarry Smith } 993f3760d9SBarry Smith 1005615d1e5SSatish Balay #undef __FUNC__ 101d4bb536fSBarry Smith #define __FUNC__ "TSGetType" 1023f3760d9SBarry Smith /*@C 103fee21e36SBarry Smith TSGetType - Gets the TS method type (as a string). 1043f3760d9SBarry Smith 105bef22f13SLois Curfman McInnes Not Collective 106bef22f13SLois Curfman McInnes 1073f3760d9SBarry Smith Input Parameter: 1082d872ea7SLois Curfman McInnes . ts - timestepper solver context 1093f3760d9SBarry Smith 1103f3760d9SBarry Smith Output Parameter: 11182bf6240SBarry Smith . type - name of TS method 1123f3760d9SBarry Smith 113df8cb225SBarry Smith .keywords: TS, timestepper, get, type, name 1143f3760d9SBarry Smith @*/ 11582bf6240SBarry Smith int TSGetType(TS ts, TSType *type) 1163f3760d9SBarry Smith { 1173f3760d9SBarry Smith int ierr; 1183a40ed3dSBarry Smith 1193a40ed3dSBarry Smith PetscFunctionBegin; 12082bf6240SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL); CHKERRQ(ierr);} 12182bf6240SBarry Smith *type = ts->type_name; 1223a40ed3dSBarry Smith PetscFunctionReturn(0); 1233f3760d9SBarry Smith } 1243f3760d9SBarry Smith 1255615d1e5SSatish Balay #undef __FUNC__ 126ca161407SBarry Smith #define __FUNC__ "TSPrintHelp" 127ca161407SBarry Smith /*@ 128ca161407SBarry Smith TSPrintHelp - Prints all options for the TS (timestepping) component. 1293f3760d9SBarry Smith 130bef22f13SLois Curfman McInnes Collective on TS 131bef22f13SLois Curfman McInnes 1323f3760d9SBarry Smith Input Parameter: 133ca161407SBarry Smith . ts - the TS context obtained from TSCreate() 1343f3760d9SBarry Smith 135ca161407SBarry Smith Options Database Keys: 136bef22f13SLois Curfman McInnes + -help - Prints KSP options 137bef22f13SLois Curfman McInnes - -h - Prints KSP options 138fee21e36SBarry Smith 139ca161407SBarry Smith .keywords: TS, timestep, print, help 140ca161407SBarry Smith 141ca161407SBarry Smith .seealso: TSSetFromOptions() 142ca161407SBarry Smith @*/ 143ca161407SBarry Smith int TSPrintHelp(TS ts) 1443f3760d9SBarry Smith { 145ca161407SBarry Smith char *prefix = "-"; 1468b1af7b3SBarry Smith int ierr; 1473a40ed3dSBarry Smith 1483a40ed3dSBarry Smith PetscFunctionBegin; 149ca161407SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 150ca161407SBarry Smith if (ts->prefix) prefix = ts->prefix; 15176be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm,"TS options --------------------------------------------------\n"); 152488ecbafSBarry Smith ierr = FListPrintTypes(ts->comm,stdout,ts->prefix,"ts_type",TSList);CHKERRQ(ierr); 15376be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_monitor: use default TS monitor\n",prefix); 15476be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_view: view TS info after each solve\n",prefix); 155ca161407SBarry Smith 15676be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_max_steps <steps>: maximum steps, defaults to %d\n",prefix,ts->max_steps); 15776be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_max_time <steps>: maximum time, defaults to %g\n",prefix,ts->max_time); 158ca161407SBarry Smith if (ts->printhelp) {ierr = (*ts->printhelp)(ts,prefix);CHKERRQ(ierr);} 1593a40ed3dSBarry Smith PetscFunctionReturn(0); 1603f3760d9SBarry Smith } 161ca161407SBarry Smith 162ca161407SBarry Smith #undef __FUNC__ 163ca161407SBarry Smith #define __FUNC__ "TSSetFromOptions" 164ca161407SBarry Smith /*@ 165ca161407SBarry Smith TSSetFromOptions - Sets various TS parameters from user options. 166ca161407SBarry Smith 167bef22f13SLois Curfman McInnes Collective on TS 168bef22f13SLois Curfman McInnes 169ca161407SBarry Smith Input Parameter: 170ca161407SBarry Smith . ts - the TS context obtained from TSCreate() 171ca161407SBarry Smith 172ca161407SBarry Smith .keywords: TS, timestep, set, options, database 173ca161407SBarry Smith 174ca161407SBarry Smith .seealso: TSPrintHelp() 175ca161407SBarry Smith @*/ 176ca161407SBarry Smith int TSSetFromOptions(TS ts) 177ca161407SBarry Smith { 178ca161407SBarry Smith int ierr,flg,loc[4],nmax; 17982bf6240SBarry Smith char type[256]; 180ca161407SBarry Smith 181ca161407SBarry Smith PetscFunctionBegin; 182ca161407SBarry Smith loc[0] = PETSC_DECIDE; loc[1] = PETSC_DECIDE; loc[2] = 300; loc[3] = 300; 183ca161407SBarry Smith 184ca161407SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 18582bf6240SBarry Smith if (ts->setupcalled) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,0,"Must call prior to TSSetUp!"); 18682bf6240SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 18782bf6240SBarry Smith ierr = OptionsGetString(ts->prefix,"-ts_type",(char *) type,256,&flg); 188ca161407SBarry Smith if (flg) { 189df8cb225SBarry Smith ierr = TSSetType(ts,type); CHKERRQ(ierr); 190ca161407SBarry Smith } 191ca161407SBarry Smith 192ca161407SBarry Smith ierr = OptionsGetInt(ts->prefix,"-ts_max_steps",&ts->max_steps,&flg);CHKERRQ(ierr); 193ca161407SBarry Smith ierr = OptionsGetDouble(ts->prefix,"-ts_max_time",&ts->max_time,&flg);CHKERRQ(ierr); 194ca161407SBarry Smith ierr = OptionsHasName(ts->prefix,"-ts_monitor",&flg); CHKERRQ(ierr); 195ca161407SBarry Smith if (flg) { 196ca161407SBarry Smith ierr = TSSetMonitor(ts,TSDefaultMonitor,0);CHKERRQ(ierr); 197ca161407SBarry Smith } 198ca161407SBarry Smith nmax = 4; 199ca161407SBarry Smith ierr = OptionsGetIntArray(ts->prefix,"-ts_xmonitor",loc,&nmax,&flg); CHKERRQ(ierr); 200ca161407SBarry Smith if (flg) { 201ca161407SBarry Smith int rank = 0; 202ca161407SBarry Smith DrawLG lg; 203ca161407SBarry Smith MPI_Comm_rank(ts->comm,&rank); 204ca161407SBarry Smith if (!rank) { 205ca161407SBarry Smith ierr = TSLGMonitorCreate(0,0,loc[0],loc[1],loc[2],loc[3],&lg); CHKERRQ(ierr); 206ca161407SBarry Smith PLogObjectParent(ts,(PetscObject) lg); 207ca161407SBarry Smith ierr = TSSetMonitor(ts,TSLGMonitor,(void *)lg);CHKERRQ(ierr); 208ca161407SBarry Smith } 209ca161407SBarry Smith } 21082bf6240SBarry Smith if (!ts->type_name) { 2116a6a5d1dSBarry Smith ierr = TSSetType(ts,TS_EULER);CHKERRQ(ierr); 2126a6a5d1dSBarry Smith } 2136a6a5d1dSBarry Smith ierr = OptionsHasName(PETSC_NULL,"-help",&flg); CHKERRQ(ierr); 2146a6a5d1dSBarry Smith if (flg) {ierr = TSPrintHelp(ts);CHKERRQ(ierr);} 215ca161407SBarry Smith if (!ts->setfromoptions) PetscFunctionReturn(0); 216ca161407SBarry Smith ierr = (*ts->setfromoptions)(ts);CHKERRQ(ierr); 217ca161407SBarry Smith PetscFunctionReturn(0); 218ca161407SBarry Smith } 219ca161407SBarry Smith 22082bf6240SBarry Smith 221