18b1af7b3SBarry Smith 2fae171e0SBarry Smith 33f3760d9SBarry Smith #ifndef lint 4*f5eb4b81SSatish Balay static char vcid[] = "$Id: tsreg.c,v 1.6 1996/03/26 04:47:26 bsmith Exp balay $"; 53f3760d9SBarry Smith #endif 63f3760d9SBarry Smith 78b1af7b3SBarry Smith #include "tsimpl.h" /*I "ts.h" I*/ 8*f5eb4b81SSatish Balay #include "src/sys/nreg.h" 93f3760d9SBarry Smith #include "pinclude/pviewer.h" 103f3760d9SBarry Smith #include <math.h> 113f3760d9SBarry Smith 128b1af7b3SBarry Smith static NRList *__TSList = 0; 133f3760d9SBarry Smith 143f3760d9SBarry Smith /*@ 158b1af7b3SBarry Smith TSSetType - Sets the method for the nonlinear solver. 163f3760d9SBarry Smith 173f3760d9SBarry Smith Input Parameters: 188b1af7b3SBarry Smith . ts - the TS context 193f3760d9SBarry Smith . method - a known method 203f3760d9SBarry Smith 213f3760d9SBarry Smith Notes: 228b1af7b3SBarry Smith See "petsc/include/ts.h" for available methods (for instance) 238b1af7b3SBarry Smith $ TS_EULER 24ca90a507SBarry Smith $ TS_BEULER 25ca90a507SBarry Smith $ TS_PSEUDO 263f3760d9SBarry Smith 273f3760d9SBarry Smith Options Database Command: 288b1af7b3SBarry Smith $ -ts_type <method> 293f3760d9SBarry Smith $ Use -help for a list of available methods 308b1af7b3SBarry Smith $ (for instance, euler) 313f3760d9SBarry Smith 328b1af7b3SBarry Smith .keysords: TS, set, method 333f3760d9SBarry Smith @*/ 348b1af7b3SBarry Smith int TSSetType(TS ts,TSType method) 353f3760d9SBarry Smith { 368b1af7b3SBarry Smith int (*r)(TS); 378b1af7b3SBarry Smith 38c3e30b67SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 398b1af7b3SBarry Smith /* Get the function pointers for the method requested */ 408b1af7b3SBarry Smith if (!__TSList) {TSRegisterAll();} 418b1af7b3SBarry Smith if (!__TSList) {SETERRQ(1,"TSSetType:Could not get methods");} 428b1af7b3SBarry Smith r = (int (*)(TS))NRFindRoutine( __TSList, (int)method, (char *)0 ); 438b1af7b3SBarry Smith if (!r) {SETERRQ(1,"TSSetType:Unknown method");} 448b1af7b3SBarry Smith if (ts->data) PetscFree(ts->data); 458b1af7b3SBarry Smith return (*r)(ts); 463f3760d9SBarry Smith } 473f3760d9SBarry Smith 483f3760d9SBarry Smith /* --------------------------------------------------------------------- */ 493f3760d9SBarry Smith /*@C 508b1af7b3SBarry Smith TSRegister - Adds the method to the nonlinear solver package, given 518b1af7b3SBarry Smith a function pointer and a nonlinear solver name of the type TSType. 523f3760d9SBarry Smith 533f3760d9SBarry Smith Input Parameters: 548b1af7b3SBarry Smith . name - for instance TS_EQ_NLS, TS_EQ_NTR, ... 553f3760d9SBarry Smith . sname - corfunPonding string for name 563f3760d9SBarry Smith . create - routine to create method context 573f3760d9SBarry Smith 588b1af7b3SBarry Smith .keywords: TS, nonlinear, register 593f3760d9SBarry Smith 608b1af7b3SBarry Smith .seealso: TSRegisterAll(), TSRegisterDestroy() 613f3760d9SBarry Smith @*/ 628b1af7b3SBarry Smith int TSRegister(int name, char *sname, int (*create)(TS)) 633f3760d9SBarry Smith { 643f3760d9SBarry Smith int ierr; 658b1af7b3SBarry Smith if (!__TSList) {ierr = NRCreate(&__TSList); CHKERRQ(ierr);} 668b1af7b3SBarry Smith NRRegister( __TSList, name, sname, (int (*)(void*))create ); 673f3760d9SBarry Smith return 0; 683f3760d9SBarry Smith } 693f3760d9SBarry Smith /* --------------------------------------------------------------------- */ 703f3760d9SBarry Smith /*@C 718b1af7b3SBarry Smith TSRegisterDestroy - Frees the list of nonlinear solvers that were 728b1af7b3SBarry Smith registered by TSRegister(). 733f3760d9SBarry Smith 748b1af7b3SBarry Smith .keywords: TS, nonlinear, register, destroy 753f3760d9SBarry Smith 768b1af7b3SBarry Smith .seealso: TSRegisterAll(), TSRegisterAll() 773f3760d9SBarry Smith @*/ 788b1af7b3SBarry Smith int TSRegisterDestroy() 793f3760d9SBarry Smith { 808b1af7b3SBarry Smith if (__TSList) { 818b1af7b3SBarry Smith NRDestroy( __TSList ); 828b1af7b3SBarry Smith __TSList = 0; 833f3760d9SBarry Smith } 843f3760d9SBarry Smith return 0; 853f3760d9SBarry Smith } 863f3760d9SBarry Smith 873f3760d9SBarry Smith /*@C 888b1af7b3SBarry Smith TSGetType - Gets the TS method type and name (as a string). 893f3760d9SBarry Smith 903f3760d9SBarry Smith Input Parameter: 918b1af7b3SBarry Smith . ts - nonlinear solver context 923f3760d9SBarry Smith 933f3760d9SBarry Smith Output Parameter: 948b1af7b3SBarry Smith . method - TS method (or use PETSC_NULL) 958b1af7b3SBarry Smith . name - name of TS method (or use PETSC_NULL) 963f3760d9SBarry Smith 978b1af7b3SBarry Smith .keywords: TS, nonlinear, get, method, name 983f3760d9SBarry Smith @*/ 998b1af7b3SBarry Smith int TSGetType(TS ts, TSType *method,char **name) 1003f3760d9SBarry Smith { 1013f3760d9SBarry Smith int ierr; 1028b1af7b3SBarry Smith if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);} 1038b1af7b3SBarry Smith if (method) *method = (TSType) ts->type; 1048b1af7b3SBarry Smith if (name) *name = NRFindName( __TSList, (int) ts->type ); 1053f3760d9SBarry Smith return 0; 1063f3760d9SBarry Smith } 1073f3760d9SBarry Smith 1083f3760d9SBarry Smith #include <stdio.h> 1093f3760d9SBarry Smith /* 1108b1af7b3SBarry Smith TSPrintTypes_Private - Prints the TS methods available from the 1113f3760d9SBarry Smith options database. 1123f3760d9SBarry Smith 1133f3760d9SBarry Smith Input Parameters: 114b5f69acfSSatish Balay . comm - The communicator ( usually MPI_COMM_WORLD) 1153f3760d9SBarry Smith . prefix - prefix (usually "-") 1168b1af7b3SBarry Smith . name - the options database name (by default "ts_type") 1173f3760d9SBarry Smith */ 118b5f69acfSSatish Balay int TSPrintTypes_Private(MPI_Comm comm,char* prefix,char *name) 1193f3760d9SBarry Smith { 1203f3760d9SBarry Smith FuncList *entry; 1218b1af7b3SBarry Smith if (!__TSList) {TSRegisterAll();} 1228b1af7b3SBarry Smith entry = __TSList->head; 123c3e30b67SBarry Smith PetscPrintf(comm," %s%s (one of)",prefix,name); 1243f3760d9SBarry Smith while (entry) { 125c3e30b67SBarry Smith PetscPrintf(comm," %s",entry->name); 1263f3760d9SBarry Smith entry = entry->next; 1273f3760d9SBarry Smith } 128c3e30b67SBarry Smith PetscPrintf(comm,"\n"); 1293f3760d9SBarry Smith return 0; 1303f3760d9SBarry Smith } 1313f3760d9SBarry Smith 1328b1af7b3SBarry Smith 1338b1af7b3SBarry Smith /* 1348b1af7b3SBarry Smith TSGetTypeFromOptions_Private - Sets the selected method from the 1358b1af7b3SBarry Smith options database. 1363f3760d9SBarry Smith 1373f3760d9SBarry Smith Input Parameter: 1388b1af7b3SBarry Smith . ctx - the TS context 1393f3760d9SBarry Smith 1403f3760d9SBarry Smith Output Parameter: 1418b1af7b3SBarry Smith . method - solver method 1423f3760d9SBarry Smith 1438b1af7b3SBarry Smith Returns: 1448b1af7b3SBarry Smith Returns 1 if the method is found; 0 otherwise. 1453f3760d9SBarry Smith 1468b1af7b3SBarry Smith Options Database Key: 1478b1af7b3SBarry Smith $ -ts_type method 1488b1af7b3SBarry Smith */ 1498b1af7b3SBarry Smith int TSGetTypeFromOptions_Private(TS ctx,TSType *method,int *flg) 1503f3760d9SBarry Smith { 1518b1af7b3SBarry Smith int ierr; 1528b1af7b3SBarry Smith char sbuf[50]; 1538b1af7b3SBarry Smith ierr = OptionsGetString(ctx->prefix,"-ts_type", sbuf, 50, flg); CHKERRQ(ierr); 1548b1af7b3SBarry Smith if (*flg) { 1558b1af7b3SBarry Smith if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);} 1568b1af7b3SBarry Smith *method = (TSType)NRFindID( __TSList, sbuf ); 1578b1af7b3SBarry Smith } 1583f3760d9SBarry Smith return 0; 1593f3760d9SBarry Smith } 160