1a5eb4965SSatish Balay #ifdef PETSC_RCS_HEADER 2*e1311b90SBarry Smith static char vcid[] = "$Id: tsreg.c,v 1.33 1998/03/23 21:23:45 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 22ae12b187SLois Curfman McInnes Options Database Command: 23ae12b187SLois Curfman McInnes $ -ts_type <method> 24ae12b187SLois Curfman McInnes $ Use -help for a list of available methods 25ae12b187SLois Curfman McInnes $ (for instance, euler) 26ae12b187SLois Curfman McInnes 273f3760d9SBarry Smith Notes: 288b1af7b3SBarry Smith See "petsc/include/ts.h" for available methods (for instance) 298b1af7b3SBarry Smith $ TS_EULER 303a40ed3dSBarry Smith $ TS_PVODE 31ca90a507SBarry Smith $ TS_BEULER 32ca90a507SBarry Smith $ TS_PSEUDO 333f3760d9SBarry Smith 34ae12b187SLois Curfman McInnes Normally, it is best to use the TSSetFromOptions() command and 35ae12b187SLois Curfman McInnes then set the TS type from the options database rather than by using 36ae12b187SLois Curfman McInnes this routine. Using the options database provides the user with 37ae12b187SLois Curfman McInnes maximum flexibility in evaluating the many different solvers. 38ae12b187SLois Curfman McInnes The TSSetType() routine is provided for those situations where it 39ae12b187SLois Curfman McInnes is necessary to set the timestepping solver independently of the 40ae12b187SLois Curfman McInnes command line or options database. This might be the case, for example, 41ae12b187SLois Curfman McInnes when the choice of solver changes during the execution of the 42ae12b187SLois Curfman McInnes program, and the user's application is taking responsibility for 43ae12b187SLois Curfman McInnes choosing the appropriate method. In other words, this routine is 44ae12b187SLois Curfman McInnes for the advanced user. 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); 5482bf6240SBarry Smith if (!PetscStrcmp(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);} 58ecf371e4SBarry Smith ierr = DLRegisterFind(ts->comm, TSList, method, (int (**)(void *)) &r );CHKERRQ(ierr); 59a8c6a408SBarry Smith if (!r) {SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,0,"Unknown 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);} 63*e1311b90SBarry 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); 7182bf6240SBarry Smith PetscStrcpy(ts->type_name,method); 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 8082bf6240SBarry Smith registered by DLRegister(). 813f3760d9SBarry Smith 822d872ea7SLois Curfman McInnes .keywords: TS, timestepper, register, destroy 833f3760d9SBarry Smith 8482bf6240SBarry Smith .seealso: TSRegisterAll() 853f3760d9SBarry Smith @*/ 86cf256101SBarry Smith int TSRegisterDestroy(void) 873f3760d9SBarry Smith { 88df8cb225SBarry Smith int ierr; 89df8cb225SBarry Smith 903a40ed3dSBarry Smith PetscFunctionBegin; 9182bf6240SBarry Smith if (TSList) { 9282bf6240SBarry Smith ierr = DLRegisterDestroy( TSList );CHKERRQ(ierr); 9382bf6240SBarry Smith TSList = 0; 943f3760d9SBarry Smith } 9584cb2905SBarry Smith TSRegisterAllCalled = 0; 963a40ed3dSBarry Smith PetscFunctionReturn(0); 973f3760d9SBarry Smith } 983f3760d9SBarry Smith 995615d1e5SSatish Balay #undef __FUNC__ 100d4bb536fSBarry Smith #define __FUNC__ "TSGetType" 1013f3760d9SBarry Smith /*@C 1028b1af7b3SBarry Smith TSGetType - Gets the TS method type and name (as a string). 1033f3760d9SBarry Smith 1043f3760d9SBarry Smith Input Parameter: 1052d872ea7SLois Curfman McInnes . ts - timestepper solver context 1063f3760d9SBarry Smith 1073f3760d9SBarry Smith Output Parameter: 10882bf6240SBarry Smith . type - name of TS method 1093f3760d9SBarry Smith 110df8cb225SBarry Smith .keywords: TS, timestepper, get, type, name 1113f3760d9SBarry Smith @*/ 11282bf6240SBarry Smith int TSGetType(TS ts, TSType *type) 1133f3760d9SBarry Smith { 1143f3760d9SBarry Smith int ierr; 1153a40ed3dSBarry Smith 1163a40ed3dSBarry Smith PetscFunctionBegin; 11782bf6240SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL); CHKERRQ(ierr);} 11882bf6240SBarry Smith *type = ts->type_name; 1193a40ed3dSBarry Smith PetscFunctionReturn(0); 1203f3760d9SBarry Smith } 1213f3760d9SBarry Smith 1225615d1e5SSatish Balay #undef __FUNC__ 123ca161407SBarry Smith #define __FUNC__ "TSPrintHelp" 124ca161407SBarry Smith /*@ 125ca161407SBarry Smith TSPrintHelp - Prints all options for the TS (timestepping) component. 1263f3760d9SBarry Smith 1273f3760d9SBarry Smith Input Parameter: 128ca161407SBarry Smith . ts - the TS context obtained from TSCreate() 1293f3760d9SBarry Smith 130ca161407SBarry Smith Options Database Keys: 131ca161407SBarry Smith $ -help, -h 1323f3760d9SBarry Smith 133ca161407SBarry Smith .keywords: TS, timestep, print, help 134ca161407SBarry Smith 135ca161407SBarry Smith .seealso: TSSetFromOptions() 136ca161407SBarry Smith @*/ 137ca161407SBarry Smith int TSPrintHelp(TS ts) 1383f3760d9SBarry Smith { 139ca161407SBarry Smith char *prefix = "-"; 1408b1af7b3SBarry Smith int ierr; 1413a40ed3dSBarry Smith 1423a40ed3dSBarry Smith PetscFunctionBegin; 143ca161407SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 144ca161407SBarry Smith if (ts->prefix) prefix = ts->prefix; 14576be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm,"TS options --------------------------------------------------\n"); 14682bf6240SBarry Smith ierr = DLRegisterPrintTypes(ts->comm,stdout,ts->prefix,"ts_type",TSList);CHKERRQ(ierr); 14776be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_monitor: use default TS monitor\n",prefix); 14876be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_view: view TS info after each solve\n",prefix); 149ca161407SBarry Smith 15076be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_max_steps <steps>: maximum steps, defaults to %d\n",prefix,ts->max_steps); 15176be9ce4SBarry Smith (*PetscHelpPrintf)(ts->comm," %sts_max_time <steps>: maximum time, defaults to %g\n",prefix,ts->max_time); 152ca161407SBarry Smith if (ts->printhelp) {ierr = (*ts->printhelp)(ts,prefix);CHKERRQ(ierr);} 1533a40ed3dSBarry Smith PetscFunctionReturn(0); 1543f3760d9SBarry Smith } 155ca161407SBarry Smith 156ca161407SBarry Smith #undef __FUNC__ 157ca161407SBarry Smith #define __FUNC__ "TSSetFromOptions" 158ca161407SBarry Smith /*@ 159ca161407SBarry Smith TSSetFromOptions - Sets various TS parameters from user options. 160ca161407SBarry Smith 161ca161407SBarry Smith Input Parameter: 162ca161407SBarry Smith . ts - the TS context obtained from TSCreate() 163ca161407SBarry Smith 164ca161407SBarry Smith .keywords: TS, timestep, set, options, database 165ca161407SBarry Smith 166ca161407SBarry Smith .seealso: TSPrintHelp() 167ca161407SBarry Smith @*/ 168ca161407SBarry Smith int TSSetFromOptions(TS ts) 169ca161407SBarry Smith { 170ca161407SBarry Smith int ierr,flg,loc[4],nmax; 17182bf6240SBarry Smith char type[256]; 172ca161407SBarry Smith 173ca161407SBarry Smith PetscFunctionBegin; 174ca161407SBarry Smith loc[0] = PETSC_DECIDE; loc[1] = PETSC_DECIDE; loc[2] = 300; loc[3] = 300; 175ca161407SBarry Smith 176ca161407SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 17782bf6240SBarry Smith if (ts->setupcalled) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,0,"Must call prior to TSSetUp!"); 17882bf6240SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 17982bf6240SBarry Smith ierr = OptionsGetString(ts->prefix,"-ts_type",(char *) type,256,&flg); 180ca161407SBarry Smith if (flg) { 181df8cb225SBarry Smith ierr = TSSetType(ts,type); CHKERRQ(ierr); 182ca161407SBarry Smith } 183ca161407SBarry Smith 184ca161407SBarry Smith ierr = OptionsGetInt(ts->prefix,"-ts_max_steps",&ts->max_steps,&flg);CHKERRQ(ierr); 185ca161407SBarry Smith ierr = OptionsGetDouble(ts->prefix,"-ts_max_time",&ts->max_time,&flg);CHKERRQ(ierr); 186ca161407SBarry Smith ierr = OptionsHasName(ts->prefix,"-ts_monitor",&flg); CHKERRQ(ierr); 187ca161407SBarry Smith if (flg) { 188ca161407SBarry Smith ierr = TSSetMonitor(ts,TSDefaultMonitor,0);CHKERRQ(ierr); 189ca161407SBarry Smith } 190ca161407SBarry Smith nmax = 4; 191ca161407SBarry Smith ierr = OptionsGetIntArray(ts->prefix,"-ts_xmonitor",loc,&nmax,&flg); CHKERRQ(ierr); 192ca161407SBarry Smith if (flg) { 193ca161407SBarry Smith int rank = 0; 194ca161407SBarry Smith DrawLG lg; 195ca161407SBarry Smith MPI_Comm_rank(ts->comm,&rank); 196ca161407SBarry Smith if (!rank) { 197ca161407SBarry Smith ierr = TSLGMonitorCreate(0,0,loc[0],loc[1],loc[2],loc[3],&lg); CHKERRQ(ierr); 198ca161407SBarry Smith PLogObjectParent(ts,(PetscObject) lg); 199ca161407SBarry Smith ierr = TSSetMonitor(ts,TSLGMonitor,(void *)lg);CHKERRQ(ierr); 200ca161407SBarry Smith } 201ca161407SBarry Smith } 20282bf6240SBarry Smith if (!ts->type_name) { 2036a6a5d1dSBarry Smith ierr = TSSetType(ts,TS_EULER);CHKERRQ(ierr); 2046a6a5d1dSBarry Smith } 2056a6a5d1dSBarry Smith ierr = OptionsHasName(PETSC_NULL,"-help",&flg); CHKERRQ(ierr); 2066a6a5d1dSBarry Smith if (flg) {ierr = TSPrintHelp(ts);CHKERRQ(ierr);} 207ca161407SBarry Smith if (!ts->setfromoptions) PetscFunctionReturn(0); 208ca161407SBarry Smith ierr = (*ts->setfromoptions)(ts);CHKERRQ(ierr); 209ca161407SBarry Smith PetscFunctionReturn(0); 210ca161407SBarry Smith } 211ca161407SBarry Smith 21282bf6240SBarry Smith 213