1a5eb4965SSatish Balay #ifdef PETSC_RCS_HEADER 2*888f2ed8SSatish Balay static char vcid[] = "$Id: tsreg.c,v 1.46 1999/05/04 20:36:38 balay Exp balay $"; 33f3760d9SBarry Smith #endif 43f3760d9SBarry Smith 570f55243SBarry Smith #include "src/ts/tsimpl.h" /*I "ts.h" I*/ 63f3760d9SBarry Smith 7488ecbafSBarry Smith FList TSList = 0; 884cb2905SBarry Smith int TSRegisterAllCalled = 0; 93f3760d9SBarry Smith 105615d1e5SSatish Balay #undef __FUNC__ 11d4bb536fSBarry Smith #define __FUNC__ "TSSetType" 1282bf6240SBarry Smith /*@C 13ae12b187SLois Curfman McInnes TSSetType - Sets the method for the timestepping solver. 143f3760d9SBarry Smith 15fee21e36SBarry Smith Collective on TS 16fee21e36SBarry Smith 17bef22f13SLois Curfman McInnes Input Parameters: 18bef22f13SLois Curfman McInnes + ts - the TS context 19bef22f13SLois Curfman McInnes - method - a known method 20bef22f13SLois Curfman McInnes 21ae12b187SLois Curfman McInnes Options Database Command: 22bef22f13SLois Curfman McInnes . -ts_type <method> - Sets the method; use -help for a list 23bef22f13SLois Curfman McInnes of available methods (for instance, euler) 24ae12b187SLois Curfman McInnes 253f3760d9SBarry Smith Notes: 268b1af7b3SBarry Smith See "petsc/include/ts.h" for available methods (for instance) 27d5d37b61SLois Curfman McInnes + TS_EULER - Euler 28bef22f13SLois Curfman McInnes . TS_PVODE - PVODE interface 29bef22f13SLois Curfman McInnes . TS_BEULER - Backward Euler 30d5d37b61SLois Curfman McInnes - TS_PSEUDO - Pseudo-timestepping 313f3760d9SBarry Smith 32ae12b187SLois Curfman McInnes Normally, it is best to use the TSSetFromOptions() command and 33ae12b187SLois Curfman McInnes then set the TS type from the options database rather than by using 34ae12b187SLois Curfman McInnes this routine. Using the options database provides the user with 35ae12b187SLois Curfman McInnes maximum flexibility in evaluating the many different solvers. 36ae12b187SLois Curfman McInnes The TSSetType() routine is provided for those situations where it 37ae12b187SLois Curfman McInnes is necessary to set the timestepping solver independently of the 38ae12b187SLois Curfman McInnes command line or options database. This might be the case, for example, 39ae12b187SLois Curfman McInnes when the choice of solver changes during the execution of the 40ae12b187SLois Curfman McInnes program, and the user's application is taking responsibility for 41ae12b187SLois Curfman McInnes choosing the appropriate method. In other words, this routine is 42d5d37b61SLois Curfman McInnes not for beginners. 43d5d37b61SLois Curfman McInnes 44d5d37b61SLois Curfman McInnes Level: intermediate 453f3760d9SBarry Smith 46ae12b187SLois Curfman McInnes .keywords: TS, set, type 473f3760d9SBarry Smith @*/ 488b1af7b3SBarry Smith int TSSetType(TS ts,TSType method) 493f3760d9SBarry Smith { 50d83d6502SBarry Smith int ierr,(*r)(TS); 518b1af7b3SBarry Smith 523a40ed3dSBarry Smith PetscFunctionBegin; 53c3e30b67SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 543f1db9ecSBarry Smith if (PetscTypeCompare(ts->type_name,method)) PetscFunctionReturn(0); 55df8cb225SBarry Smith 568b1af7b3SBarry Smith /* Get the function pointers for the method requested */ 5782bf6240SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 58488ecbafSBarry Smith ierr = FListFind(ts->comm, TSList, method, (int (**)(void *)) &r );CHKERRQ(ierr); 59596552b5SBarry Smith if (!r) {SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,0,"Unknown method: %s",method);} 6082bf6240SBarry Smith 61df8cb225SBarry Smith if (ts->sles) {ierr = SLESDestroy(ts->sles);CHKERRQ(ierr);} 62df8cb225SBarry Smith if (ts->snes) {ierr = SNESDestroy(ts->snes);CHKERRQ(ierr);} 63e1311b90SBarry Smith if (ts->destroy) {ierr = (*(ts)->destroy)(ts);CHKERRQ(ierr);} 64df8cb225SBarry Smith ts->sles = 0; 65df8cb225SBarry Smith ts->snes = 0; 6682bf6240SBarry Smith 673a40ed3dSBarry Smith ierr = (*r)(ts);CHKERRQ(ierr); 68df8cb225SBarry Smith 6982bf6240SBarry Smith if (ts->type_name) PetscFree(ts->type_name); 7082bf6240SBarry Smith ts->type_name = (char *) PetscMalloc((PetscStrlen(method)+1)*sizeof(char));CHKPTRQ(ts->type_name); 71549d3d68SSatish Balay ierr = PetscStrcpy(ts->type_name,method);CHKERRQ(ierr); 723a40ed3dSBarry Smith PetscFunctionReturn(0); 733f3760d9SBarry Smith } 74df8cb225SBarry Smith 753f3760d9SBarry Smith /* --------------------------------------------------------------------- */ 765615d1e5SSatish Balay #undef __FUNC__ 77d4bb536fSBarry Smith #define __FUNC__ "TSRegisterDestroy" 783f3760d9SBarry Smith /*@C 7984cb2905SBarry Smith TSRegisterDestroy - Frees the list of timesteppers that were 80488ecbafSBarry Smith registered by FListAdd(). 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) { 96488ecbafSBarry Smith ierr = FListDestroy( TSList );CHKERRQ(ierr); 9782bf6240SBarry Smith TSList = 0; 983f3760d9SBarry Smith } 9984cb2905SBarry Smith TSRegisterAllCalled = 0; 1003a40ed3dSBarry Smith PetscFunctionReturn(0); 1013f3760d9SBarry Smith } 1023f3760d9SBarry Smith 1035615d1e5SSatish Balay #undef __FUNC__ 104d4bb536fSBarry Smith #define __FUNC__ "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__ 131ca161407SBarry Smith #define __FUNC__ "TSPrintHelp" 132ca161407SBarry Smith /*@ 133ca161407SBarry Smith TSPrintHelp - Prints all options for the TS (timestepping) component. 1343f3760d9SBarry Smith 135bef22f13SLois Curfman McInnes Collective on TS 136bef22f13SLois Curfman McInnes 1373f3760d9SBarry Smith Input Parameter: 138ca161407SBarry Smith . ts - the TS context obtained from TSCreate() 1393f3760d9SBarry Smith 140ca161407SBarry Smith Options Database Keys: 141bef22f13SLois Curfman McInnes + -help - Prints KSP options 142bef22f13SLois Curfman McInnes - -h - Prints KSP options 143fee21e36SBarry Smith 144d5d37b61SLois Curfman McInnes Level: beginner 145d5d37b61SLois Curfman McInnes 146ca161407SBarry Smith .keywords: TS, timestep, print, help 147ca161407SBarry Smith 148ca161407SBarry Smith .seealso: TSSetFromOptions() 149ca161407SBarry Smith @*/ 150ca161407SBarry Smith int TSPrintHelp(TS ts) 1513f3760d9SBarry Smith { 152ca161407SBarry Smith char *prefix = "-"; 1538b1af7b3SBarry Smith int ierr; 1543a40ed3dSBarry Smith 1553a40ed3dSBarry Smith PetscFunctionBegin; 156ca161407SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 157ca161407SBarry Smith if (ts->prefix) prefix = ts->prefix; 158ebb8b11fSBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 159d132466eSBarry Smith ierr = (*PetscHelpPrintf)(ts->comm,"TS options --------------------------------------------------\n");CHKERRQ(ierr); 160488ecbafSBarry Smith ierr = FListPrintTypes(ts->comm,stdout,ts->prefix,"ts_type",TSList);CHKERRQ(ierr); 161d132466eSBarry Smith ierr = (*PetscHelpPrintf)(ts->comm," %sts_monitor: use default TS monitor\n",prefix);CHKERRQ(ierr); 162d132466eSBarry Smith ierr = (*PetscHelpPrintf)(ts->comm," %sts_view: view TS info after each solve\n",prefix);CHKERRQ(ierr); 163ca161407SBarry Smith 164d132466eSBarry Smith ierr = (*PetscHelpPrintf)(ts->comm," %sts_max_steps <steps>: maximum steps, defaults to %d\n",prefix,ts->max_steps);CHKERRQ(ierr); 165d132466eSBarry Smith ierr = (*PetscHelpPrintf)(ts->comm," %sts_max_time <steps>: maximum time, defaults to %g\n",prefix,ts->max_time);CHKERRQ(ierr); 166ca161407SBarry Smith if (ts->printhelp) {ierr = (*ts->printhelp)(ts,prefix);CHKERRQ(ierr);} 1673a40ed3dSBarry Smith PetscFunctionReturn(0); 1683f3760d9SBarry Smith } 169ca161407SBarry Smith 170ca161407SBarry Smith #undef __FUNC__ 17115091d37SBarry Smith #define __FUNC__ "TSSetTypeFromOptions" 17215091d37SBarry Smith /*@ 17315091d37SBarry Smith TSSetTypeFromOptions - Sets the TS type from the options database; sets 17415091d37SBarry Smith a default if none is given. 17515091d37SBarry Smith 17615091d37SBarry Smith Collective on TS 17715091d37SBarry Smith 17815091d37SBarry Smith Input Parameter: 17915091d37SBarry Smith . ts - the TS context obtained from TSCreate() 18015091d37SBarry Smith 18115091d37SBarry Smith Options Database Keys: 18215091d37SBarry Smith . -ts_type <type> - TS_EULER, TS_BEULER, TS_PVODE, TS_PSEUDO, TS_CRANK_NICHOLSON 18315091d37SBarry Smith 18415091d37SBarry Smith Level: beginner 18515091d37SBarry Smith 18615091d37SBarry Smith .keywords: TS, timestep, set, options, database, TS type 18715091d37SBarry Smith 18815091d37SBarry Smith .seealso: TSPrintHelp(), TSSetFromOptions() 18915091d37SBarry Smith @*/ 19015091d37SBarry Smith int TSSetTypeFromOptions(TS ts) 19115091d37SBarry Smith { 19215091d37SBarry Smith int ierr,flg; 19315091d37SBarry Smith char type[256]; 19415091d37SBarry Smith 19515091d37SBarry Smith PetscFunctionBegin; 19615091d37SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 19715091d37SBarry Smith if (ts->setupcalled) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,0,"Must call prior to TSSetUp()"); 198*888f2ed8SSatish Balay ierr = OptionsGetString(ts->prefix,"-ts_type",(char *) type,256,&flg);CHKERRQ(ierr); 19915091d37SBarry Smith if (flg) { 20015091d37SBarry Smith ierr = TSSetType(ts,type);CHKERRQ(ierr); 20115091d37SBarry Smith } 20215091d37SBarry Smith if (!ts->type_name) { 20315091d37SBarry Smith ierr = TSSetType(ts,TS_EULER);CHKERRQ(ierr); 20415091d37SBarry Smith } 20515091d37SBarry Smith PetscFunctionReturn(0); 20615091d37SBarry Smith } 20715091d37SBarry Smith 20815091d37SBarry Smith #undef __FUNC__ 209ca161407SBarry Smith #define __FUNC__ "TSSetFromOptions" 210ca161407SBarry Smith /*@ 211ca161407SBarry Smith TSSetFromOptions - Sets various TS parameters from user options. 212ca161407SBarry Smith 213bef22f13SLois Curfman McInnes Collective on TS 214bef22f13SLois Curfman McInnes 215ca161407SBarry Smith Input Parameter: 216ca161407SBarry Smith . ts - the TS context obtained from TSCreate() 217ca161407SBarry Smith 21815091d37SBarry Smith Options Database Keys: 21915091d37SBarry Smith + -ts_type <type> - TS_EULER, TS_BEULER, TS_PVODE, TS_PSEUDO, TS_CRANK_NICHOLSON 22015091d37SBarry Smith . -ts_max_steps maxsteps - maximum number of time-steps to take 22115091d37SBarry Smith . -ts_max_time time - maximum time to compute to 22215091d37SBarry Smith . -ts_monitor - print information at each timestep 22315091d37SBarry Smith - -ts_xmonitor - plot information at each timestep 22415091d37SBarry Smith 225d5d37b61SLois Curfman McInnes Level: beginner 226d5d37b61SLois Curfman McInnes 227ca161407SBarry Smith .keywords: TS, timestep, set, options, database 228ca161407SBarry Smith 22915091d37SBarry Smith .seealso: TSPrintHelp(), TSSetTypeFromOptions() 230ca161407SBarry Smith @*/ 231ca161407SBarry Smith int TSSetFromOptions(TS ts) 232ca161407SBarry Smith { 233ca161407SBarry Smith int ierr,flg,loc[4],nmax; 234ca161407SBarry Smith 235ca161407SBarry Smith PetscFunctionBegin; 236ca161407SBarry Smith loc[0] = PETSC_DECIDE; loc[1] = PETSC_DECIDE; loc[2] = 300; loc[3] = 300; 237ca161407SBarry Smith 238ca161407SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 23915091d37SBarry Smith ierr = TSSetTypeFromOptions(ts);CHKERRQ(ierr); 240ca161407SBarry Smith 241ca161407SBarry Smith ierr = OptionsGetInt(ts->prefix,"-ts_max_steps",&ts->max_steps,&flg);CHKERRQ(ierr); 242ca161407SBarry Smith ierr = OptionsGetDouble(ts->prefix,"-ts_max_time",&ts->max_time,&flg);CHKERRQ(ierr); 243ca161407SBarry Smith ierr = OptionsHasName(ts->prefix,"-ts_monitor",&flg);CHKERRQ(ierr); 244ca161407SBarry Smith if (flg) { 245ca161407SBarry Smith ierr = TSSetMonitor(ts,TSDefaultMonitor,0);CHKERRQ(ierr); 246ca161407SBarry Smith } 247ca161407SBarry Smith nmax = 4; 248ca161407SBarry Smith ierr = OptionsGetIntArray(ts->prefix,"-ts_xmonitor",loc,&nmax,&flg);CHKERRQ(ierr); 249ca161407SBarry Smith if (flg) { 250ca161407SBarry Smith int rank = 0; 251ca161407SBarry Smith DrawLG lg; 252d132466eSBarry Smith ierr = MPI_Comm_rank(ts->comm,&rank);CHKERRQ(ierr); 253ca161407SBarry Smith if (!rank) { 254ca161407SBarry Smith ierr = TSLGMonitorCreate(0,0,loc[0],loc[1],loc[2],loc[3],&lg);CHKERRQ(ierr); 255ca161407SBarry Smith PLogObjectParent(ts,(PetscObject) lg); 256ca161407SBarry Smith ierr = TSSetMonitor(ts,TSLGMonitor,(void *)lg);CHKERRQ(ierr); 257ca161407SBarry Smith } 258ca161407SBarry Smith } 2596a6a5d1dSBarry Smith ierr = OptionsHasName(PETSC_NULL,"-help",&flg);CHKERRQ(ierr); 2606a6a5d1dSBarry Smith if (flg) {ierr = TSPrintHelp(ts);CHKERRQ(ierr);} 261ca161407SBarry Smith if (!ts->setfromoptions) PetscFunctionReturn(0); 262ca161407SBarry Smith ierr = (*ts->setfromoptions)(ts);CHKERRQ(ierr); 263ca161407SBarry Smith PetscFunctionReturn(0); 264ca161407SBarry Smith } 265ca161407SBarry Smith 26682bf6240SBarry Smith 267