1 2 3 #ifndef lint 4 static char vcid[] = "$Id: tsreg.c,v 1.9 1996/09/14 03:37:44 curfman Exp balay $"; 5 #endif 6 7 #include "src/ts/tsimpl.h" /*I "ts.h" I*/ 8 #include "src/sys/nreg.h" 9 #include "pinclude/pviewer.h" 10 #include <math.h> 11 12 static NRList *__TSList = 0; 13 14 /*@ 15 TSSetType - Sets the method for the nonlinear solver. 16 17 Input Parameters: 18 . ts - the TS context 19 . method - a known method 20 21 Notes: 22 See "petsc/include/ts.h" for available methods (for instance) 23 $ TS_EULER 24 $ TS_BEULER 25 $ TS_PSEUDO 26 27 Options Database Command: 28 $ -ts_type <method> 29 $ Use -help for a list of available methods 30 $ (for instance, euler) 31 32 .keywords: TS, set, method 33 @*/ 34 int TSSetType(TS ts,TSType method) 35 { 36 int (*r)(TS); 37 38 PetscValidHeaderSpecific(ts,TS_COOKIE); 39 /* Get the function pointers for the method requested */ 40 if (!__TSList) {TSRegisterAll();} 41 if (!__TSList) {SETERRQ(1,"TSSetType:Could not get methods");} 42 r = (int (*)(TS))NRFindRoutine( __TSList, (int)method, (char *)0 ); 43 if (!r) {SETERRQ(1,"TSSetType:Unknown method");} 44 if (ts->data) PetscFree(ts->data); 45 return (*r)(ts); 46 } 47 48 /* --------------------------------------------------------------------- */ 49 /*@C 50 TSRegister - Adds the method to the nonlinear solver package, given 51 a function pointer and a nonlinear solver name of the type TSType. 52 53 Input Parameters: 54 . name - for instance TS_EQ_NLS, TS_EQ_NTR, ... 55 . sname - corfunPonding string for name 56 . create - routine to create method context 57 58 .keywords: TS, nonlinear, register 59 60 .seealso: TSRegisterAll(), TSRegisterDestroy() 61 @*/ 62 int TSRegister(int name, char *sname, int (*create)(TS)) 63 { 64 int ierr; 65 if (!__TSList) {ierr = NRCreate(&__TSList); CHKERRQ(ierr);} 66 NRRegister( __TSList, name, sname, (int (*)(void*))create ); 67 return 0; 68 } 69 /* --------------------------------------------------------------------- */ 70 /*@C 71 TSRegisterDestroy - Frees the list of nonlinear solvers that were 72 registered by TSRegister(). 73 74 .keywords: TS, nonlinear, register, destroy 75 76 .seealso: TSRegisterAll(), TSRegisterAll() 77 @*/ 78 int TSRegisterDestroy() 79 { 80 if (__TSList) { 81 NRDestroy( __TSList ); 82 __TSList = 0; 83 } 84 return 0; 85 } 86 87 /*@C 88 TSGetType - Gets the TS method type and name (as a string). 89 90 Input Parameter: 91 . ts - nonlinear solver context 92 93 Output Parameter: 94 . method - TS method (or use PETSC_NULL) 95 . name - name of TS method (or use PETSC_NULL) 96 97 .keywords: TS, nonlinear, get, method, name 98 @*/ 99 int TSGetType(TS ts, TSType *method,char **name) 100 { 101 int ierr; 102 if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);} 103 if (method) *method = (TSType) ts->type; 104 if (name) *name = NRFindName( __TSList, (int) ts->type ); 105 return 0; 106 } 107 108 #include <stdio.h> 109 /* 110 TSPrintTypes_Private - Prints the TS methods available from the 111 options database. 112 113 Input Parameters: 114 . comm - The communicator (usually MPI_COMM_WORLD) 115 . prefix - prefix (usually "-") 116 . name - the options database name (by default "ts_type") 117 */ 118 int TSPrintTypes_Private(MPI_Comm comm,char* prefix,char *name) 119 { 120 FuncList *entry; 121 if (!__TSList) {TSRegisterAll();} 122 entry = __TSList->head; 123 PetscPrintf(comm," %s%s (one of)",prefix,name); 124 while (entry) { 125 PetscPrintf(comm," %s",entry->name); 126 entry = entry->next; 127 } 128 PetscPrintf(comm,"\n"); 129 return 0; 130 } 131 132 133 /* 134 TSGetTypeFromOptions_Private - Sets the selected method from the 135 options database. 136 137 Input Parameter: 138 . ctx - the TS context 139 140 Output Parameter: 141 . method - solver method 142 143 Returns: 144 Returns 1 if the method is found; 0 otherwise. 145 146 Options Database Key: 147 $ -ts_type method 148 */ 149 int TSGetTypeFromOptions_Private(TS ctx,TSType *method,int *flg) 150 { 151 int ierr; 152 char sbuf[50]; 153 ierr = OptionsGetString(ctx->prefix,"-ts_type", sbuf, 50, flg); CHKERRQ(ierr); 154 if (*flg) { 155 if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);} 156 *method = (TSType)NRFindID( __TSList, sbuf ); 157 } 158 return 0; 159 } 160