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