1*a5eb4965SSatish Balay #ifdef PETSC_RCS_HEADER 2*a5eb4965SSatish Balay static char vcid[] = "$Id: tsreg.c,v 1.20 1997/05/28 23:21:37 bsmith Exp balay $"; 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 108b1af7b3SBarry Smith static NRList *__TSList = 0; 1184cb2905SBarry Smith int TSRegisterAllCalled = 0; 123f3760d9SBarry Smith 135615d1e5SSatish Balay #undef __FUNC__ 145eea60f9SBarry Smith #define __FUNC__ "TSSetType" /* ADIC Ignore */ 153f3760d9SBarry Smith /*@ 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 30ca90a507SBarry Smith $ TS_BEULER 31ca90a507SBarry Smith $ TS_PSEUDO 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 43ae12b187SLois Curfman McInnes for the advanced user. 443f3760d9SBarry Smith 45ae12b187SLois Curfman McInnes .keywords: TS, set, type 463f3760d9SBarry Smith @*/ 478b1af7b3SBarry Smith int TSSetType(TS ts,TSType method) 483f3760d9SBarry Smith { 49d83d6502SBarry Smith int ierr,(*r)(TS); 508b1af7b3SBarry Smith 51c3e30b67SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 528b1af7b3SBarry Smith /* Get the function pointers for the method requested */ 53d83d6502SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(); CHKERRQ(ierr);} 54e3372554SBarry Smith if (!__TSList) {SETERRQ(1,0,"Could not get methods");} 558b1af7b3SBarry Smith r = (int (*)(TS))NRFindRoutine( __TSList, (int)method, (char *)0 ); 56e3372554SBarry Smith if (!r) {SETERRQ(1,0,"Unknown method");} 578b1af7b3SBarry Smith if (ts->data) PetscFree(ts->data); 588b1af7b3SBarry Smith return (*r)(ts); 593f3760d9SBarry Smith } 603f3760d9SBarry Smith 613f3760d9SBarry Smith /* --------------------------------------------------------------------- */ 625615d1e5SSatish Balay #undef __FUNC__ 635eea60f9SBarry Smith #define __FUNC__ "TSRegister" /* ADIC Ignore */ 643f3760d9SBarry Smith /*@C 652d872ea7SLois Curfman McInnes TSRegister - Adds the method to the timestepping package, given 662d872ea7SLois Curfman McInnes a function pointer and a solver name of the type TSType. 673f3760d9SBarry Smith 683f3760d9SBarry Smith Input Parameters: 692d872ea7SLois Curfman McInnes . name - either a predefined name such as TS_BEULER, or TS_NEW 702d872ea7SLois Curfman McInnes to indicate a new user-defined solver 712d872ea7SLois Curfman McInnes . sname - corresponding string for name 723f3760d9SBarry Smith . create - routine to create method context 733f3760d9SBarry Smith 7484cb2905SBarry Smith Output Parameter: 7584cb2905SBarry Smith . oname - type associated with this new method 7684cb2905SBarry Smith 772d872ea7SLois Curfman McInnes Notes: 782d872ea7SLois Curfman McInnes Multiple user-defined timestepping solvers can be added by calling 792d872ea7SLois Curfman McInnes TSRegister() with the input parameter "name" set to be TS_NEW; 802d872ea7SLois Curfman McInnes each call will return a unique solver type in the output 812d872ea7SLois Curfman McInnes parameter "oname". 822d872ea7SLois Curfman McInnes 832d872ea7SLois Curfman McInnes .keywords: TS, timestepper, register 843f3760d9SBarry Smith 858b1af7b3SBarry Smith .seealso: TSRegisterAll(), TSRegisterDestroy() 863f3760d9SBarry Smith @*/ 8784cb2905SBarry Smith int TSRegister(TSType name,TSType *oname, char *sname, int (*create)(TS)) 883f3760d9SBarry Smith { 893f3760d9SBarry Smith int ierr; 9084cb2905SBarry Smith static int numberregistered = 0; 9184cb2905SBarry Smith 92d252947aSBarry Smith if (name == TS_NEW) name = (TSType) ((int) TS_NEW + numberregistered++); 9384cb2905SBarry Smith 9484cb2905SBarry Smith if (oname) *oname = name; 958b1af7b3SBarry Smith if (!__TSList) {ierr = NRCreate(&__TSList); CHKERRQ(ierr);} 9684cb2905SBarry Smith NRRegister( __TSList, (int) name, sname, (int (*)(void*))create ); 973f3760d9SBarry Smith return 0; 983f3760d9SBarry Smith } 993f3760d9SBarry Smith /* --------------------------------------------------------------------- */ 1005615d1e5SSatish Balay #undef __FUNC__ 1015eea60f9SBarry Smith #define __FUNC__ "TSRegisterDestroy" /* ADIC Ignore */ 1023f3760d9SBarry Smith /*@C 10384cb2905SBarry Smith TSRegisterDestroy - Frees the list of timesteppers that were 1048b1af7b3SBarry Smith registered by TSRegister(). 1053f3760d9SBarry Smith 1062d872ea7SLois Curfman McInnes .keywords: TS, timestepper, register, destroy 1073f3760d9SBarry Smith 1088b1af7b3SBarry Smith .seealso: TSRegisterAll(), TSRegisterAll() 1093f3760d9SBarry Smith @*/ 1108b1af7b3SBarry Smith int TSRegisterDestroy() 1113f3760d9SBarry Smith { 1128b1af7b3SBarry Smith if (__TSList) { 1138b1af7b3SBarry Smith NRDestroy( __TSList ); 1148b1af7b3SBarry Smith __TSList = 0; 1153f3760d9SBarry Smith } 11684cb2905SBarry Smith TSRegisterAllCalled = 0; 1173f3760d9SBarry Smith return 0; 1183f3760d9SBarry Smith } 1193f3760d9SBarry Smith 1205615d1e5SSatish Balay #undef __FUNC__ 1215eea60f9SBarry Smith #define __FUNC__ "TSGetType" /* ADIC Ignore */ 1223f3760d9SBarry Smith /*@C 1238b1af7b3SBarry Smith TSGetType - Gets the TS method type and name (as a string). 1243f3760d9SBarry Smith 1253f3760d9SBarry Smith Input Parameter: 1262d872ea7SLois Curfman McInnes . ts - timestepper solver context 1273f3760d9SBarry Smith 1283f3760d9SBarry Smith Output Parameter: 1298b1af7b3SBarry Smith . method - TS method (or use PETSC_NULL) 1308b1af7b3SBarry Smith . name - name of TS method (or use PETSC_NULL) 1313f3760d9SBarry Smith 1322d872ea7SLois Curfman McInnes .keywords: TS, timestepper, get, method, name 1333f3760d9SBarry Smith @*/ 1348b1af7b3SBarry Smith int TSGetType(TS ts, TSType *method,char **name) 1353f3760d9SBarry Smith { 1363f3760d9SBarry Smith int ierr; 13784cb2905SBarry Smith if (!TSRegisterAllCalled) {ierr = TSRegisterAll(); CHKERRQ(ierr);} 1388b1af7b3SBarry Smith if (method) *method = (TSType) ts->type; 1398b1af7b3SBarry Smith if (name) *name = NRFindName( __TSList, (int) ts->type ); 1403f3760d9SBarry Smith return 0; 1413f3760d9SBarry Smith } 1423f3760d9SBarry Smith 1433f3760d9SBarry Smith #include <stdio.h> 1445615d1e5SSatish Balay #undef __FUNC__ 1455eea60f9SBarry Smith #define __FUNC__ "TSPrintTypes_Private" /* ADIC Ignore */ 1463f3760d9SBarry Smith /* 1478b1af7b3SBarry Smith TSPrintTypes_Private - Prints the TS methods available from the 1483f3760d9SBarry Smith options database. 1493f3760d9SBarry Smith 1503f3760d9SBarry Smith Input Parameters: 151b5f69acfSSatish Balay . comm - The communicator (usually MPI_COMM_WORLD) 1523f3760d9SBarry Smith . prefix - prefix (usually "-") 1538b1af7b3SBarry Smith . name - the options database name (by default "ts_type") 1543f3760d9SBarry Smith */ 155b5f69acfSSatish Balay int TSPrintTypes_Private(MPI_Comm comm,char* prefix,char *name) 1563f3760d9SBarry Smith { 1573f3760d9SBarry Smith FuncList *entry; 1588b1af7b3SBarry Smith if (!__TSList) {TSRegisterAll();} 1598b1af7b3SBarry Smith entry = __TSList->head; 160c3e30b67SBarry Smith PetscPrintf(comm," %s%s (one of)",prefix,name); 1613f3760d9SBarry Smith while (entry) { 162c3e30b67SBarry Smith PetscPrintf(comm," %s",entry->name); 1633f3760d9SBarry Smith entry = entry->next; 1643f3760d9SBarry Smith } 165c3e30b67SBarry Smith PetscPrintf(comm,"\n"); 1663f3760d9SBarry Smith return 0; 1673f3760d9SBarry Smith } 1683f3760d9SBarry Smith 1698b1af7b3SBarry Smith 1705615d1e5SSatish Balay #undef __FUNC__ 1715eea60f9SBarry Smith #define __FUNC__ "TSGetTypeFromOptions_Private" /* ADIC Ignore */ 1728b1af7b3SBarry Smith /* 1738b1af7b3SBarry Smith TSGetTypeFromOptions_Private - Sets the selected method from the 1748b1af7b3SBarry Smith options database. 1753f3760d9SBarry Smith 1763f3760d9SBarry Smith Input Parameter: 1778b1af7b3SBarry Smith . ctx - the TS context 1783f3760d9SBarry Smith 1793f3760d9SBarry Smith Output Parameter: 1808b1af7b3SBarry Smith . method - solver method 1813f3760d9SBarry Smith 1828b1af7b3SBarry Smith Returns: 1838b1af7b3SBarry Smith Returns 1 if the method is found; 0 otherwise. 1843f3760d9SBarry Smith 1858b1af7b3SBarry Smith Options Database Key: 1868b1af7b3SBarry Smith $ -ts_type method 1878b1af7b3SBarry Smith */ 1888b1af7b3SBarry Smith int TSGetTypeFromOptions_Private(TS ctx,TSType *method,int *flg) 1893f3760d9SBarry Smith { 1908b1af7b3SBarry Smith int ierr; 1918b1af7b3SBarry Smith char sbuf[50]; 1928b1af7b3SBarry Smith ierr = OptionsGetString(ctx->prefix,"-ts_type", sbuf, 50, flg); CHKERRQ(ierr); 1938b1af7b3SBarry Smith if (*flg) { 1948b1af7b3SBarry Smith if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);} 1958b1af7b3SBarry Smith *method = (TSType)NRFindID( __TSList, sbuf ); 1968b1af7b3SBarry Smith } 1973f3760d9SBarry Smith return 0; 1983f3760d9SBarry Smith } 199