1a5eb4965SSatish Balay #ifdef PETSC_RCS_HEADER 2*ebb8b11fSBarry Smith static char vcid[] = "$Id: tsreg.c,v 1.42 1999/03/17 23:24:50 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) 28d5d37b61SLois Curfman McInnes + TS_EULER - Euler 29bef22f13SLois Curfman McInnes . TS_PVODE - PVODE interface 30bef22f13SLois Curfman McInnes . TS_BEULER - Backward Euler 31d5d37b61SLois 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 43d5d37b61SLois Curfman McInnes not for beginners. 44d5d37b61SLois Curfman McInnes 45d5d37b61SLois 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 85d5d37b61SLois Curfman McInnes Level: advanced 86d5d37b61SLois 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 117d5d37b61SLois Curfman McInnes Level: intermediate 118d5d37b61SLois 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 145d5d37b61SLois Curfman McInnes Level: beginner 146d5d37b61SLois 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; 159*ebb8b11fSBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL); CHKERRQ(ierr);} 16076be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm,"TS options --------------------------------------------------\n"); 161488ecbafSBarry Smith ierr = FListPrintTypes(ts->comm,stdout,ts->prefix,"ts_type",TSList);CHKERRQ(ierr); 16276be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_monitor: use default TS monitor\n",prefix); 16376be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_view: view TS info after each solve\n",prefix); 164ca161407SBarry Smith 16576be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_max_steps <steps>: maximum steps, defaults to %d\n",prefix,ts->max_steps); 16676be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_max_time <steps>: maximum time, defaults to %g\n",prefix,ts->max_time); 167ca161407SBarry Smith if (ts->printhelp) {ierr = (*ts->printhelp)(ts,prefix);CHKERRQ(ierr);} 1683a40ed3dSBarry Smith PetscFunctionReturn(0); 1693f3760d9SBarry Smith } 170ca161407SBarry Smith 171ca161407SBarry Smith #undef __FUNC__ 17215091d37SBarry Smith #define __FUNC__ "TSSetTypeFromOptions" 17315091d37SBarry Smith /*@ 17415091d37SBarry Smith TSSetTypeFromOptions - Sets the TS type from the options database; sets 17515091d37SBarry Smith a default if none is given. 17615091d37SBarry Smith 17715091d37SBarry Smith Collective on TS 17815091d37SBarry Smith 17915091d37SBarry Smith Input Parameter: 18015091d37SBarry Smith . ts - the TS context obtained from TSCreate() 18115091d37SBarry Smith 18215091d37SBarry Smith Options Database Keys: 18315091d37SBarry Smith . -ts_type <type> - TS_EULER, TS_BEULER, TS_PVODE, TS_PSEUDO, TS_CRANK_NICHOLSON 18415091d37SBarry Smith 18515091d37SBarry Smith Level: beginner 18615091d37SBarry Smith 18715091d37SBarry Smith .keywords: TS, timestep, set, options, database, TS type 18815091d37SBarry Smith 18915091d37SBarry Smith .seealso: TSPrintHelp(), TSSetFromOptions() 19015091d37SBarry Smith @*/ 19115091d37SBarry Smith int TSSetTypeFromOptions(TS ts) 19215091d37SBarry Smith { 19315091d37SBarry Smith int ierr,flg; 19415091d37SBarry Smith char type[256]; 19515091d37SBarry Smith 19615091d37SBarry Smith PetscFunctionBegin; 19715091d37SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 19815091d37SBarry Smith if (ts->setupcalled) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,0,"Must call prior to TSSetUp()"); 19915091d37SBarry Smith ierr = OptionsGetString(ts->prefix,"-ts_type",(char *) type,256,&flg); 20015091d37SBarry Smith if (flg) { 20115091d37SBarry Smith ierr = TSSetType(ts,type); CHKERRQ(ierr); 20215091d37SBarry Smith } 20315091d37SBarry Smith if (!ts->type_name) { 20415091d37SBarry Smith ierr = TSSetType(ts,TS_EULER);CHKERRQ(ierr); 20515091d37SBarry Smith } 20615091d37SBarry Smith PetscFunctionReturn(0); 20715091d37SBarry Smith } 20815091d37SBarry Smith 20915091d37SBarry Smith #undef __FUNC__ 210ca161407SBarry Smith #define __FUNC__ "TSSetFromOptions" 211ca161407SBarry Smith /*@ 212ca161407SBarry Smith TSSetFromOptions - Sets various TS parameters from user options. 213ca161407SBarry Smith 214bef22f13SLois Curfman McInnes Collective on TS 215bef22f13SLois Curfman McInnes 216ca161407SBarry Smith Input Parameter: 217ca161407SBarry Smith . ts - the TS context obtained from TSCreate() 218ca161407SBarry Smith 21915091d37SBarry Smith Options Database Keys: 22015091d37SBarry Smith + -ts_type <type> - TS_EULER, TS_BEULER, TS_PVODE, TS_PSEUDO, TS_CRANK_NICHOLSON 22115091d37SBarry Smith . -ts_max_steps maxsteps - maximum number of time-steps to take 22215091d37SBarry Smith . -ts_max_time time - maximum time to compute to 22315091d37SBarry Smith . -ts_monitor - print information at each timestep 22415091d37SBarry Smith - -ts_xmonitor - plot information at each timestep 22515091d37SBarry Smith 226d5d37b61SLois Curfman McInnes Level: beginner 227d5d37b61SLois Curfman McInnes 228ca161407SBarry Smith .keywords: TS, timestep, set, options, database 229ca161407SBarry Smith 23015091d37SBarry Smith .seealso: TSPrintHelp(), TSSetTypeFromOptions() 231ca161407SBarry Smith @*/ 232ca161407SBarry Smith int TSSetFromOptions(TS ts) 233ca161407SBarry Smith { 234ca161407SBarry Smith int ierr,flg,loc[4],nmax; 235ca161407SBarry Smith 236ca161407SBarry Smith PetscFunctionBegin; 237ca161407SBarry Smith loc[0] = PETSC_DECIDE; loc[1] = PETSC_DECIDE; loc[2] = 300; loc[3] = 300; 238ca161407SBarry Smith 239ca161407SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 24015091d37SBarry Smith ierr = TSSetTypeFromOptions(ts);CHKERRQ(ierr); 241ca161407SBarry Smith 242ca161407SBarry Smith ierr = OptionsGetInt(ts->prefix,"-ts_max_steps",&ts->max_steps,&flg);CHKERRQ(ierr); 243ca161407SBarry Smith ierr = OptionsGetDouble(ts->prefix,"-ts_max_time",&ts->max_time,&flg);CHKERRQ(ierr); 244ca161407SBarry Smith ierr = OptionsHasName(ts->prefix,"-ts_monitor",&flg); CHKERRQ(ierr); 245ca161407SBarry Smith if (flg) { 246ca161407SBarry Smith ierr = TSSetMonitor(ts,TSDefaultMonitor,0);CHKERRQ(ierr); 247ca161407SBarry Smith } 248ca161407SBarry Smith nmax = 4; 249ca161407SBarry Smith ierr = OptionsGetIntArray(ts->prefix,"-ts_xmonitor",loc,&nmax,&flg); CHKERRQ(ierr); 250ca161407SBarry Smith if (flg) { 251ca161407SBarry Smith int rank = 0; 252ca161407SBarry Smith DrawLG lg; 253ca161407SBarry Smith MPI_Comm_rank(ts->comm,&rank); 254ca161407SBarry Smith if (!rank) { 255ca161407SBarry Smith ierr = TSLGMonitorCreate(0,0,loc[0],loc[1],loc[2],loc[3],&lg); CHKERRQ(ierr); 256ca161407SBarry Smith PLogObjectParent(ts,(PetscObject) lg); 257ca161407SBarry Smith ierr = TSSetMonitor(ts,TSLGMonitor,(void *)lg);CHKERRQ(ierr); 258ca161407SBarry Smith } 259ca161407SBarry Smith } 2606a6a5d1dSBarry Smith ierr = OptionsHasName(PETSC_NULL,"-help",&flg); CHKERRQ(ierr); 2616a6a5d1dSBarry Smith if (flg) {ierr = TSPrintHelp(ts);CHKERRQ(ierr);} 262ca161407SBarry Smith if (!ts->setfromoptions) PetscFunctionReturn(0); 263ca161407SBarry Smith ierr = (*ts->setfromoptions)(ts);CHKERRQ(ierr); 264ca161407SBarry Smith PetscFunctionReturn(0); 265ca161407SBarry Smith } 266ca161407SBarry Smith 26782bf6240SBarry Smith 268