1 #ifdef PETSC_RCS_HEADER 2 static char vcid[] = "$Id: tsreg.c,v 1.48 1999/06/30 23:54:35 balay Exp bsmith $"; 3 #endif 4 5 #include "src/ts/tsimpl.h" /*I "ts.h" I*/ 6 7 FList TSList = 0; 8 int TSRegisterAllCalled = 0; 9 10 #undef __FUNC__ 11 #define __FUNC__ "TSSetType" 12 /*@C 13 TSSetType - Sets the method for the timestepping solver. 14 15 Collective on TS 16 17 Input Parameters: 18 + ts - the TS context 19 - method - a known method 20 21 Options Database Command: 22 . -ts_type <method> - Sets the method; use -help for a list 23 of available methods (for instance, euler) 24 25 Notes: 26 See "petsc/include/ts.h" for available methods (for instance) 27 + TS_EULER - Euler 28 . TS_PVODE - PVODE interface 29 . TS_BEULER - Backward Euler 30 - TS_PSEUDO - Pseudo-timestepping 31 32 Normally, it is best to use the TSSetFromOptions() command and 33 then set the TS type from the options database rather than by using 34 this routine. Using the options database provides the user with 35 maximum flexibility in evaluating the many different solvers. 36 The TSSetType() routine is provided for those situations where it 37 is necessary to set the timestepping solver independently of the 38 command line or options database. This might be the case, for example, 39 when the choice of solver changes during the execution of the 40 program, and the user's application is taking responsibility for 41 choosing the appropriate method. In other words, this routine is 42 not for beginners. 43 44 Level: intermediate 45 46 .keywords: TS, set, type 47 @*/ 48 int TSSetType(TS ts,TSType method) 49 { 50 int ierr,(*r)(TS); 51 52 PetscFunctionBegin; 53 PetscValidHeaderSpecific(ts,TS_COOKIE); 54 if (PetscTypeCompare(ts->type_name,method)) PetscFunctionReturn(0); 55 56 /* Get the function pointers for the method requested */ 57 if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 58 ierr = FListFind(ts->comm, TSList, method, (int (**)(void *)) &r );CHKERRQ(ierr); 59 if (!r) {SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,0,"Unknown method: %s",method);} 60 61 if (ts->sles) {ierr = SLESDestroy(ts->sles);CHKERRQ(ierr);} 62 if (ts->snes) {ierr = SNESDestroy(ts->snes);CHKERRQ(ierr);} 63 if (ts->destroy) {ierr = (*(ts)->destroy)(ts);CHKERRQ(ierr);} 64 ts->sles = 0; 65 ts->snes = 0; 66 67 ierr = (*r)(ts);CHKERRQ(ierr); 68 69 ierr = PetscObjectChangeTypeName((PetscObject)ts,method);CHKERRQ(ierr); 70 PetscFunctionReturn(0); 71 } 72 73 /* --------------------------------------------------------------------- */ 74 #undef __FUNC__ 75 #define __FUNC__ "TSRegisterDestroy" 76 /*@C 77 TSRegisterDestroy - Frees the list of timesteppers that were 78 registered by FListAdd(). 79 80 Not Collective 81 82 Level: advanced 83 84 .keywords: TS, timestepper, register, destroy 85 86 .seealso: TSRegisterAll() 87 @*/ 88 int TSRegisterDestroy(void) 89 { 90 int ierr; 91 92 PetscFunctionBegin; 93 if (TSList) { 94 ierr = FListDestroy( TSList );CHKERRQ(ierr); 95 TSList = 0; 96 } 97 TSRegisterAllCalled = 0; 98 PetscFunctionReturn(0); 99 } 100 101 #undef __FUNC__ 102 #define __FUNC__ "TSGetType" 103 /*@C 104 TSGetType - Gets the TS method type (as a string). 105 106 Not Collective 107 108 Input Parameter: 109 . ts - timestepper solver context 110 111 Output Parameter: 112 . type - name of TS method 113 114 Level: intermediate 115 116 .keywords: TS, timestepper, get, type, name 117 @*/ 118 int TSGetType(TS ts, TSType *type) 119 { 120 int ierr; 121 122 PetscFunctionBegin; 123 if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 124 *type = ts->type_name; 125 PetscFunctionReturn(0); 126 } 127 128 #undef __FUNC__ 129 #define __FUNC__ "TSPrintHelp" 130 /*@ 131 TSPrintHelp - Prints all options for the TS (timestepping) component. 132 133 Collective on TS 134 135 Input Parameter: 136 . ts - the TS context obtained from TSCreate() 137 138 Options Database Keys: 139 + -help - Prints KSP options 140 - -h - Prints KSP options 141 142 Level: beginner 143 144 .keywords: TS, timestep, print, help 145 146 .seealso: TSSetFromOptions() 147 @*/ 148 int TSPrintHelp(TS ts) 149 { 150 char *prefix = "-"; 151 int ierr; 152 153 PetscFunctionBegin; 154 PetscValidHeaderSpecific(ts,TS_COOKIE); 155 if (ts->prefix) prefix = ts->prefix; 156 if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 157 ierr = (*PetscHelpPrintf)(ts->comm,"TS options --------------------------------------------------\n");CHKERRQ(ierr); 158 ierr = FListPrintTypes(ts->comm,stdout,ts->prefix,"ts_type",TSList);CHKERRQ(ierr); 159 ierr = (*PetscHelpPrintf)(ts->comm," %sts_monitor: use default TS monitor\n",prefix);CHKERRQ(ierr); 160 ierr = (*PetscHelpPrintf)(ts->comm," %sts_view: view TS info after each solve\n",prefix);CHKERRQ(ierr); 161 162 ierr = (*PetscHelpPrintf)(ts->comm," %sts_max_steps <steps>: maximum steps, defaults to %d\n",prefix,ts->max_steps);CHKERRQ(ierr); 163 ierr = (*PetscHelpPrintf)(ts->comm," %sts_max_time <steps>: maximum time, defaults to %g\n",prefix,ts->max_time);CHKERRQ(ierr); 164 if (ts->printhelp) {ierr = (*ts->printhelp)(ts,prefix);CHKERRQ(ierr);} 165 PetscFunctionReturn(0); 166 } 167 168 #undef __FUNC__ 169 #define __FUNC__ "TSSetTypeFromOptions" 170 /*@ 171 TSSetTypeFromOptions - Sets the TS type from the options database; sets 172 a default if none is given. 173 174 Collective on TS 175 176 Input Parameter: 177 . ts - the TS context obtained from TSCreate() 178 179 Options Database Keys: 180 . -ts_type <type> - TS_EULER, TS_BEULER, TS_PVODE, TS_PSEUDO, TS_CRANK_NICHOLSON 181 182 Level: beginner 183 184 .keywords: TS, timestep, set, options, database, TS type 185 186 .seealso: TSPrintHelp(), TSSetFromOptions() 187 @*/ 188 int TSSetTypeFromOptions(TS ts) 189 { 190 int ierr,flg; 191 char type[256]; 192 193 PetscFunctionBegin; 194 PetscValidHeaderSpecific(ts,TS_COOKIE); 195 if (ts->setupcalled) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,0,"Must call prior to TSSetUp()"); 196 ierr = OptionsGetString(ts->prefix,"-ts_type",(char *) type,256,&flg);CHKERRQ(ierr); 197 if (flg) { 198 ierr = TSSetType(ts,type);CHKERRQ(ierr); 199 } 200 if (!ts->type_name) { 201 ierr = TSSetType(ts,TS_EULER);CHKERRQ(ierr); 202 } 203 PetscFunctionReturn(0); 204 } 205 206 #undef __FUNC__ 207 #define __FUNC__ "TSSetFromOptions" 208 /*@ 209 TSSetFromOptions - Sets various TS parameters from user options. 210 211 Collective on TS 212 213 Input Parameter: 214 . ts - the TS context obtained from TSCreate() 215 216 Options Database Keys: 217 + -ts_type <type> - TS_EULER, TS_BEULER, TS_PVODE, TS_PSEUDO, TS_CRANK_NICHOLSON 218 . -ts_max_steps maxsteps - maximum number of time-steps to take 219 . -ts_max_time time - maximum time to compute to 220 . -ts_monitor - print information at each timestep 221 - -ts_xmonitor - plot information at each timestep 222 223 Level: beginner 224 225 .keywords: TS, timestep, set, options, database 226 227 .seealso: TSPrintHelp(), TSSetTypeFromOptions() 228 @*/ 229 int TSSetFromOptions(TS ts) 230 { 231 int ierr,flg,loc[4],nmax; 232 233 PetscFunctionBegin; 234 loc[0] = PETSC_DECIDE; loc[1] = PETSC_DECIDE; loc[2] = 300; loc[3] = 300; 235 236 PetscValidHeaderSpecific(ts,TS_COOKIE); 237 ierr = TSSetTypeFromOptions(ts);CHKERRQ(ierr); 238 239 ierr = OptionsGetInt(ts->prefix,"-ts_max_steps",&ts->max_steps,&flg);CHKERRQ(ierr); 240 ierr = OptionsGetDouble(ts->prefix,"-ts_max_time",&ts->max_time,&flg);CHKERRQ(ierr); 241 ierr = OptionsHasName(ts->prefix,"-ts_monitor",&flg);CHKERRQ(ierr); 242 if (flg) { 243 ierr = TSSetMonitor(ts,TSDefaultMonitor,0);CHKERRQ(ierr); 244 } 245 nmax = 4; 246 ierr = OptionsGetIntArray(ts->prefix,"-ts_xmonitor",loc,&nmax,&flg);CHKERRQ(ierr); 247 if (flg) { 248 int rank = 0; 249 DrawLG lg; 250 ierr = MPI_Comm_rank(ts->comm,&rank);CHKERRQ(ierr); 251 if (!rank) { 252 ierr = TSLGMonitorCreate(0,0,loc[0],loc[1],loc[2],loc[3],&lg);CHKERRQ(ierr); 253 PLogObjectParent(ts,(PetscObject) lg); 254 ierr = TSSetMonitor(ts,TSLGMonitor,(void *)lg);CHKERRQ(ierr); 255 } 256 } 257 ierr = OptionsHasName(PETSC_NULL,"-help",&flg);CHKERRQ(ierr); 258 if (flg) {ierr = TSPrintHelp(ts);CHKERRQ(ierr);} 259 if (!ts->setfromoptions) PetscFunctionReturn(0); 260 ierr = (*ts->setfromoptions)(ts);CHKERRQ(ierr); 261 PetscFunctionReturn(0); 262 } 263 264 265