18b1af7b3SBarry Smith 23f3760d9SBarry Smith #ifndef lint 3*d83d6502SBarry Smith static char vcid[] = "$Id: tsreg.c,v 1.19 1997/02/22 02:27:41 bsmith Exp bsmith $"; 43f3760d9SBarry Smith #endif 53f3760d9SBarry Smith 670f55243SBarry Smith #include "src/ts/tsimpl.h" /*I "ts.h" I*/ 7f5eb4b81SSatish Balay #include "src/sys/nreg.h" 83f3760d9SBarry Smith #include "pinclude/pviewer.h" 93f3760d9SBarry Smith #include <math.h> 103f3760d9SBarry Smith 118b1af7b3SBarry Smith static NRList *__TSList = 0; 1284cb2905SBarry Smith int TSRegisterAllCalled = 0; 133f3760d9SBarry Smith 145615d1e5SSatish Balay #undef __FUNC__ 155eea60f9SBarry Smith #define __FUNC__ "TSSetType" /* ADIC Ignore */ 163f3760d9SBarry Smith /*@ 17ae12b187SLois Curfman McInnes TSSetType - Sets the method for the timestepping solver. 183f3760d9SBarry Smith 193f3760d9SBarry Smith Input Parameters: 208b1af7b3SBarry Smith . ts - the TS context 213f3760d9SBarry Smith . method - a known method 223f3760d9SBarry Smith 23ae12b187SLois Curfman McInnes Options Database Command: 24ae12b187SLois Curfman McInnes $ -ts_type <method> 25ae12b187SLois Curfman McInnes $ Use -help for a list of available methods 26ae12b187SLois Curfman McInnes $ (for instance, euler) 27ae12b187SLois Curfman McInnes 283f3760d9SBarry Smith Notes: 298b1af7b3SBarry Smith See "petsc/include/ts.h" for available methods (for instance) 308b1af7b3SBarry Smith $ TS_EULER 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 { 50*d83d6502SBarry Smith int ierr,(*r)(TS); 518b1af7b3SBarry Smith 52c3e30b67SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 538b1af7b3SBarry Smith /* Get the function pointers for the method requested */ 54*d83d6502SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(); CHKERRQ(ierr);} 55e3372554SBarry Smith if (!__TSList) {SETERRQ(1,0,"Could not get methods");} 568b1af7b3SBarry Smith r = (int (*)(TS))NRFindRoutine( __TSList, (int)method, (char *)0 ); 57e3372554SBarry Smith if (!r) {SETERRQ(1,0,"Unknown method");} 588b1af7b3SBarry Smith if (ts->data) PetscFree(ts->data); 598b1af7b3SBarry Smith return (*r)(ts); 603f3760d9SBarry Smith } 613f3760d9SBarry Smith 623f3760d9SBarry Smith /* --------------------------------------------------------------------- */ 635615d1e5SSatish Balay #undef __FUNC__ 645eea60f9SBarry Smith #define __FUNC__ "TSRegister" /* ADIC Ignore */ 653f3760d9SBarry Smith /*@C 662d872ea7SLois Curfman McInnes TSRegister - Adds the method to the timestepping package, given 672d872ea7SLois Curfman McInnes a function pointer and a solver name of the type TSType. 683f3760d9SBarry Smith 693f3760d9SBarry Smith Input Parameters: 702d872ea7SLois Curfman McInnes . name - either a predefined name such as TS_BEULER, or TS_NEW 712d872ea7SLois Curfman McInnes to indicate a new user-defined solver 722d872ea7SLois Curfman McInnes . sname - corresponding string for name 733f3760d9SBarry Smith . create - routine to create method context 743f3760d9SBarry Smith 7584cb2905SBarry Smith Output Parameter: 7684cb2905SBarry Smith . oname - type associated with this new method 7784cb2905SBarry Smith 782d872ea7SLois Curfman McInnes Notes: 792d872ea7SLois Curfman McInnes Multiple user-defined timestepping solvers can be added by calling 802d872ea7SLois Curfman McInnes TSRegister() with the input parameter "name" set to be TS_NEW; 812d872ea7SLois Curfman McInnes each call will return a unique solver type in the output 822d872ea7SLois Curfman McInnes parameter "oname". 832d872ea7SLois Curfman McInnes 842d872ea7SLois Curfman McInnes .keywords: TS, timestepper, register 853f3760d9SBarry Smith 868b1af7b3SBarry Smith .seealso: TSRegisterAll(), TSRegisterDestroy() 873f3760d9SBarry Smith @*/ 8884cb2905SBarry Smith int TSRegister(TSType name,TSType *oname, char *sname, int (*create)(TS)) 893f3760d9SBarry Smith { 903f3760d9SBarry Smith int ierr; 9184cb2905SBarry Smith static int numberregistered = 0; 9284cb2905SBarry Smith 93d252947aSBarry Smith if (name == TS_NEW) name = (TSType) ((int) TS_NEW + numberregistered++); 9484cb2905SBarry Smith 9584cb2905SBarry Smith if (oname) *oname = name; 968b1af7b3SBarry Smith if (!__TSList) {ierr = NRCreate(&__TSList); CHKERRQ(ierr);} 9784cb2905SBarry Smith NRRegister( __TSList, (int) name, sname, (int (*)(void*))create ); 983f3760d9SBarry Smith return 0; 993f3760d9SBarry Smith } 1003f3760d9SBarry Smith /* --------------------------------------------------------------------- */ 1015615d1e5SSatish Balay #undef __FUNC__ 1025eea60f9SBarry Smith #define __FUNC__ "TSRegisterDestroy" /* ADIC Ignore */ 1033f3760d9SBarry Smith /*@C 10484cb2905SBarry Smith TSRegisterDestroy - Frees the list of timesteppers that were 1058b1af7b3SBarry Smith registered by TSRegister(). 1063f3760d9SBarry Smith 1072d872ea7SLois Curfman McInnes .keywords: TS, timestepper, register, destroy 1083f3760d9SBarry Smith 1098b1af7b3SBarry Smith .seealso: TSRegisterAll(), TSRegisterAll() 1103f3760d9SBarry Smith @*/ 1118b1af7b3SBarry Smith int TSRegisterDestroy() 1123f3760d9SBarry Smith { 1138b1af7b3SBarry Smith if (__TSList) { 1148b1af7b3SBarry Smith NRDestroy( __TSList ); 1158b1af7b3SBarry Smith __TSList = 0; 1163f3760d9SBarry Smith } 11784cb2905SBarry Smith TSRegisterAllCalled = 0; 1183f3760d9SBarry Smith return 0; 1193f3760d9SBarry Smith } 1203f3760d9SBarry Smith 1215615d1e5SSatish Balay #undef __FUNC__ 1225eea60f9SBarry Smith #define __FUNC__ "TSGetType" /* ADIC Ignore */ 1233f3760d9SBarry Smith /*@C 1248b1af7b3SBarry Smith TSGetType - Gets the TS method type and name (as a string). 1253f3760d9SBarry Smith 1263f3760d9SBarry Smith Input Parameter: 1272d872ea7SLois Curfman McInnes . ts - timestepper solver context 1283f3760d9SBarry Smith 1293f3760d9SBarry Smith Output Parameter: 1308b1af7b3SBarry Smith . method - TS method (or use PETSC_NULL) 1318b1af7b3SBarry Smith . name - name of TS method (or use PETSC_NULL) 1323f3760d9SBarry Smith 1332d872ea7SLois Curfman McInnes .keywords: TS, timestepper, get, method, name 1343f3760d9SBarry Smith @*/ 1358b1af7b3SBarry Smith int TSGetType(TS ts, TSType *method,char **name) 1363f3760d9SBarry Smith { 1373f3760d9SBarry Smith int ierr; 13884cb2905SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(); CHKERRQ(ierr);} 1398b1af7b3SBarry Smith if (method) *method = (TSType) ts->type; 1408b1af7b3SBarry Smith if (name) *name = NRFindName( __TSList, (int) ts->type ); 1413f3760d9SBarry Smith return 0; 1423f3760d9SBarry Smith } 1433f3760d9SBarry Smith 1443f3760d9SBarry Smith #include <stdio.h> 1455615d1e5SSatish Balay #undef __FUNC__ 1465eea60f9SBarry Smith #define __FUNC__ "TSPrintTypes_Private" /* ADIC Ignore */ 1473f3760d9SBarry Smith /* 1488b1af7b3SBarry Smith TSPrintTypes_Private - Prints the TS methods available from the 1493f3760d9SBarry Smith options database. 1503f3760d9SBarry Smith 1513f3760d9SBarry Smith Input Parameters: 152b5f69acfSSatish Balay . comm - The communicator (usually MPI_COMM_WORLD) 1533f3760d9SBarry Smith . prefix - prefix (usually "-") 1548b1af7b3SBarry Smith . name - the options database name (by default "ts_type") 1553f3760d9SBarry Smith */ 156b5f69acfSSatish Balay int TSPrintTypes_Private(MPI_Comm comm,char* prefix,char *name) 1573f3760d9SBarry Smith { 1583f3760d9SBarry Smith FuncList *entry; 1598b1af7b3SBarry Smith if (!__TSList) {TSRegisterAll();} 1608b1af7b3SBarry Smith entry = __TSList->head; 161c3e30b67SBarry Smith PetscPrintf(comm," %s%s (one of)",prefix,name); 1623f3760d9SBarry Smith while (entry) { 163c3e30b67SBarry Smith PetscPrintf(comm," %s",entry->name); 1643f3760d9SBarry Smith entry = entry->next; 1653f3760d9SBarry Smith } 166c3e30b67SBarry Smith PetscPrintf(comm,"\n"); 1673f3760d9SBarry Smith return 0; 1683f3760d9SBarry Smith } 1693f3760d9SBarry Smith 1708b1af7b3SBarry Smith 1715615d1e5SSatish Balay #undef __FUNC__ 1725eea60f9SBarry Smith #define __FUNC__ "TSGetTypeFromOptions_Private" /* ADIC Ignore */ 1738b1af7b3SBarry Smith /* 1748b1af7b3SBarry Smith TSGetTypeFromOptions_Private - Sets the selected method from the 1758b1af7b3SBarry Smith options database. 1763f3760d9SBarry Smith 1773f3760d9SBarry Smith Input Parameter: 1788b1af7b3SBarry Smith . ctx - the TS context 1793f3760d9SBarry Smith 1803f3760d9SBarry Smith Output Parameter: 1818b1af7b3SBarry Smith . method - solver method 1823f3760d9SBarry Smith 1838b1af7b3SBarry Smith Returns: 1848b1af7b3SBarry Smith Returns 1 if the method is found; 0 otherwise. 1853f3760d9SBarry Smith 1868b1af7b3SBarry Smith Options Database Key: 1878b1af7b3SBarry Smith $ -ts_type method 1888b1af7b3SBarry Smith */ 1898b1af7b3SBarry Smith int TSGetTypeFromOptions_Private(TS ctx,TSType *method,int *flg) 1903f3760d9SBarry Smith { 1918b1af7b3SBarry Smith int ierr; 1928b1af7b3SBarry Smith char sbuf[50]; 1938b1af7b3SBarry Smith ierr = OptionsGetString(ctx->prefix,"-ts_type", sbuf, 50, flg); CHKERRQ(ierr); 1948b1af7b3SBarry Smith if (*flg) { 1958b1af7b3SBarry Smith if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);} 1968b1af7b3SBarry Smith *method = (TSType)NRFindID( __TSList, sbuf ); 1978b1af7b3SBarry Smith } 1983f3760d9SBarry Smith return 0; 1993f3760d9SBarry Smith } 200