1 2 3 #ifndef lint 4 static char vcid[] = "$Id: tsreg.c,v 1.11 1996/11/07 19:00:08 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 #undef __FUNCTION__ 15 #define __FUNCTION__ "TSSetType" 16 /*@ 17 TSSetType - Sets the method for the timestepping solver. 18 19 Input Parameters: 20 . ts - the TS context 21 . method - a known method 22 23 Options Database Command: 24 $ -ts_type <method> 25 $ Use -help for a list of available methods 26 $ (for instance, euler) 27 28 Notes: 29 See "petsc/include/ts.h" for available methods (for instance) 30 $ TS_EULER 31 $ TS_BEULER 32 $ TS_PSEUDO 33 34 Normally, it is best to use the TSSetFromOptions() command and 35 then set the TS type from the options database rather than by using 36 this routine. Using the options database provides the user with 37 maximum flexibility in evaluating the many different solvers. 38 The TSSetType() routine is provided for those situations where it 39 is necessary to set the timestepping solver independently of the 40 command line or options database. This might be the case, for example, 41 when the choice of solver changes during the execution of the 42 program, and the user's application is taking responsibility for 43 choosing the appropriate method. In other words, this routine is 44 for the advanced user. 45 46 .keywords: TS, set, type 47 @*/ 48 int TSSetType(TS ts,TSType method) 49 { 50 int (*r)(TS); 51 52 PetscValidHeaderSpecific(ts,TS_COOKIE); 53 /* Get the function pointers for the method requested */ 54 if (!__TSList) {TSRegisterAll();} 55 if (!__TSList) {SETERRQ(1,"TSSetType:Could not get methods");} 56 r = (int (*)(TS))NRFindRoutine( __TSList, (int)method, (char *)0 ); 57 if (!r) {SETERRQ(1,"TSSetType:Unknown method");} 58 if (ts->data) PetscFree(ts->data); 59 return (*r)(ts); 60 } 61 62 /* --------------------------------------------------------------------- */ 63 #undef __FUNCTION__ 64 #define __FUNCTION__ "TSRegister" 65 /*@C 66 TSRegister - Adds the method to the nonlinear solver package, given 67 a function pointer and a nonlinear solver name of the type TSType. 68 69 Input Parameters: 70 . name - for instance TS_EQ_NLS, TS_EQ_NTR, ... 71 . sname - corfunPonding string for name 72 . create - routine to create method context 73 74 .keywords: TS, nonlinear, register 75 76 .seealso: TSRegisterAll(), TSRegisterDestroy() 77 @*/ 78 int TSRegister(int name, char *sname, int (*create)(TS)) 79 { 80 int ierr; 81 if (!__TSList) {ierr = NRCreate(&__TSList); CHKERRQ(ierr);} 82 NRRegister( __TSList, name, sname, (int (*)(void*))create ); 83 return 0; 84 } 85 /* --------------------------------------------------------------------- */ 86 #undef __FUNCTION__ 87 #define __FUNCTION__ "TSRegisterDestroy" 88 /*@C 89 TSRegisterDestroy - Frees the list of nonlinear solvers that were 90 registered by TSRegister(). 91 92 .keywords: TS, nonlinear, register, destroy 93 94 .seealso: TSRegisterAll(), TSRegisterAll() 95 @*/ 96 int TSRegisterDestroy() 97 { 98 if (__TSList) { 99 NRDestroy( __TSList ); 100 __TSList = 0; 101 } 102 return 0; 103 } 104 105 #undef __FUNCTION__ 106 #define __FUNCTION__ "TSGetType" 107 /*@C 108 TSGetType - Gets the TS method type and name (as a string). 109 110 Input Parameter: 111 . ts - nonlinear solver context 112 113 Output Parameter: 114 . method - TS method (or use PETSC_NULL) 115 . name - name of TS method (or use PETSC_NULL) 116 117 .keywords: TS, nonlinear, get, method, name 118 @*/ 119 int TSGetType(TS ts, TSType *method,char **name) 120 { 121 int ierr; 122 if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);} 123 if (method) *method = (TSType) ts->type; 124 if (name) *name = NRFindName( __TSList, (int) ts->type ); 125 return 0; 126 } 127 128 #include <stdio.h> 129 #undef __FUNCTION__ 130 #define __FUNCTION__ "TSPrintTypes_Private" 131 /* 132 TSPrintTypes_Private - Prints the TS methods available from the 133 options database. 134 135 Input Parameters: 136 . comm - The communicator (usually MPI_COMM_WORLD) 137 . prefix - prefix (usually "-") 138 . name - the options database name (by default "ts_type") 139 */ 140 int TSPrintTypes_Private(MPI_Comm comm,char* prefix,char *name) 141 { 142 FuncList *entry; 143 if (!__TSList) {TSRegisterAll();} 144 entry = __TSList->head; 145 PetscPrintf(comm," %s%s (one of)",prefix,name); 146 while (entry) { 147 PetscPrintf(comm," %s",entry->name); 148 entry = entry->next; 149 } 150 PetscPrintf(comm,"\n"); 151 return 0; 152 } 153 154 155 #undef __FUNCTION__ 156 #define __FUNCTION__ "TSGetTypeFromOptions_Private" 157 /* 158 TSGetTypeFromOptions_Private - Sets the selected method from the 159 options database. 160 161 Input Parameter: 162 . ctx - the TS context 163 164 Output Parameter: 165 . method - solver method 166 167 Returns: 168 Returns 1 if the method is found; 0 otherwise. 169 170 Options Database Key: 171 $ -ts_type method 172 */ 173 int TSGetTypeFromOptions_Private(TS ctx,TSType *method,int *flg) 174 { 175 int ierr; 176 char sbuf[50]; 177 ierr = OptionsGetString(ctx->prefix,"-ts_type", sbuf, 50, flg); CHKERRQ(ierr); 178 if (*flg) { 179 if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);} 180 *method = (TSType)NRFindID( __TSList, sbuf ); 181 } 182 return 0; 183 } 184