1a5eb4965SSatish Balay #ifdef PETSC_RCS_HEADER 2*fee21e36SBarry Smith static char vcid[] = "$Id: tsreg.c,v 1.34 1998/04/03 23:16:43 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 #include "pinclude/pviewer.h" 83f3760d9SBarry Smith #include <math.h> 93f3760d9SBarry Smith 1082bf6240SBarry Smith DLList 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 183f3760d9SBarry Smith Input Parameters: 198b1af7b3SBarry Smith . ts - the TS context 203f3760d9SBarry Smith . method - a known method 213f3760d9SBarry Smith 22*fee21e36SBarry Smith Collective on TS 23*fee21e36SBarry Smith 24ae12b187SLois Curfman McInnes Options Database Command: 25ae12b187SLois Curfman McInnes $ -ts_type <method> 26ae12b187SLois Curfman McInnes $ Use -help for a list of available methods 27ae12b187SLois Curfman McInnes $ (for instance, euler) 28ae12b187SLois Curfman McInnes 293f3760d9SBarry Smith Notes: 308b1af7b3SBarry Smith See "petsc/include/ts.h" for available methods (for instance) 318b1af7b3SBarry Smith $ TS_EULER 323a40ed3dSBarry Smith $ TS_PVODE 33ca90a507SBarry Smith $ TS_BEULER 34ca90a507SBarry Smith $ TS_PSEUDO 353f3760d9SBarry Smith 36ae12b187SLois Curfman McInnes Normally, it is best to use the TSSetFromOptions() command and 37ae12b187SLois Curfman McInnes then set the TS type from the options database rather than by using 38ae12b187SLois Curfman McInnes this routine. Using the options database provides the user with 39ae12b187SLois Curfman McInnes maximum flexibility in evaluating the many different solvers. 40ae12b187SLois Curfman McInnes The TSSetType() routine is provided for those situations where it 41ae12b187SLois Curfman McInnes is necessary to set the timestepping solver independently of the 42ae12b187SLois Curfman McInnes command line or options database. This might be the case, for example, 43ae12b187SLois Curfman McInnes when the choice of solver changes during the execution of the 44ae12b187SLois Curfman McInnes program, and the user's application is taking responsibility for 45ae12b187SLois Curfman McInnes choosing the appropriate method. In other words, this routine is 46ae12b187SLois Curfman McInnes for the advanced user. 473f3760d9SBarry Smith 48ae12b187SLois Curfman McInnes .keywords: TS, set, type 493f3760d9SBarry Smith @*/ 508b1af7b3SBarry Smith int TSSetType(TS ts,TSType method) 513f3760d9SBarry Smith { 52d83d6502SBarry Smith int ierr,(*r)(TS); 538b1af7b3SBarry Smith 543a40ed3dSBarry Smith PetscFunctionBegin; 55c3e30b67SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 5682bf6240SBarry Smith if (!PetscStrcmp(ts->type_name,method)) PetscFunctionReturn(0); 57df8cb225SBarry Smith 588b1af7b3SBarry Smith /* Get the function pointers for the method requested */ 5982bf6240SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL); CHKERRQ(ierr);} 60ecf371e4SBarry Smith ierr = DLRegisterFind(ts->comm, TSList, method, (int (**)(void *)) &r );CHKERRQ(ierr); 61a8c6a408SBarry Smith if (!r) {SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,0,"Unknown method");} 6282bf6240SBarry Smith 63df8cb225SBarry Smith if (ts->sles) {ierr = SLESDestroy(ts->sles); CHKERRQ(ierr);} 64df8cb225SBarry Smith if (ts->snes) {ierr = SNESDestroy(ts->snes); CHKERRQ(ierr);} 65e1311b90SBarry Smith if (ts->destroy) {ierr = (*(ts)->destroy)(ts); CHKERRQ(ierr);} 66df8cb225SBarry Smith ts->sles = 0; 67df8cb225SBarry Smith ts->snes = 0; 6882bf6240SBarry Smith 693a40ed3dSBarry Smith ierr = (*r)(ts);CHKERRQ(ierr); 70df8cb225SBarry Smith 7182bf6240SBarry Smith if (ts->type_name) PetscFree(ts->type_name); 7282bf6240SBarry Smith ts->type_name = (char *) PetscMalloc((PetscStrlen(method)+1)*sizeof(char));CHKPTRQ(ts->type_name); 7382bf6240SBarry Smith PetscStrcpy(ts->type_name,method); 743a40ed3dSBarry Smith PetscFunctionReturn(0); 753f3760d9SBarry Smith } 76df8cb225SBarry Smith 773f3760d9SBarry Smith /* --------------------------------------------------------------------- */ 785615d1e5SSatish Balay #undef __FUNC__ 79d4bb536fSBarry Smith #define __FUNC__ "TSRegisterDestroy" 803f3760d9SBarry Smith /*@C 8184cb2905SBarry Smith TSRegisterDestroy - Frees the list of timesteppers that were 8282bf6240SBarry Smith registered by DLRegister(). 833f3760d9SBarry Smith 84*fee21e36SBarry Smith Not Collective 85*fee21e36SBarry Smith 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) { 9682bf6240SBarry Smith ierr = DLRegisterDestroy( 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 106*fee21e36SBarry Smith TSGetType - Gets the TS method type (as a string). 1073f3760d9SBarry Smith 1083f3760d9SBarry Smith Input Parameter: 1092d872ea7SLois Curfman McInnes . ts - timestepper solver context 1103f3760d9SBarry Smith 1113f3760d9SBarry Smith Output Parameter: 11282bf6240SBarry Smith . type - name of TS method 1133f3760d9SBarry Smith 114*fee21e36SBarry Smith Not Collective 115*fee21e36SBarry Smith 116df8cb225SBarry Smith .keywords: TS, timestepper, get, type, name 1173f3760d9SBarry Smith @*/ 11882bf6240SBarry Smith int TSGetType(TS ts, TSType *type) 1193f3760d9SBarry Smith { 1203f3760d9SBarry Smith int ierr; 1213a40ed3dSBarry Smith 1223a40ed3dSBarry Smith PetscFunctionBegin; 12382bf6240SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL); CHKERRQ(ierr);} 12482bf6240SBarry Smith *type = ts->type_name; 1253a40ed3dSBarry Smith PetscFunctionReturn(0); 1263f3760d9SBarry Smith } 1273f3760d9SBarry Smith 1285615d1e5SSatish Balay #undef __FUNC__ 129ca161407SBarry Smith #define __FUNC__ "TSPrintHelp" 130ca161407SBarry Smith /*@ 131ca161407SBarry Smith TSPrintHelp - Prints all options for the TS (timestepping) component. 1323f3760d9SBarry Smith 1333f3760d9SBarry Smith Input Parameter: 134ca161407SBarry Smith . ts - the TS context obtained from TSCreate() 1353f3760d9SBarry Smith 136ca161407SBarry Smith Options Database Keys: 137ca161407SBarry Smith $ -help, -h 1383f3760d9SBarry Smith 139*fee21e36SBarry Smith Collective on TS 140*fee21e36SBarry 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"); 15482bf6240SBarry Smith ierr = DLRegisterPrintTypes(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 169ca161407SBarry Smith Input Parameter: 170ca161407SBarry Smith . ts - the TS context obtained from TSCreate() 171ca161407SBarry Smith 172*fee21e36SBarry Smith Collective on TS 173*fee21e36SBarry 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