1 2 #include "src/ts/tsimpl.h" /*I "petscts.h" I*/ 3 4 PetscFList TSList = PETSC_NULL; 5 PetscTruth TSRegisterAllCalled = PETSC_FALSE; 6 7 #undef __FUNCT__ 8 #define __FUNCT__ "TSSetType" 9 /*@C 10 TSSetType - Sets the method for the timestepping solver. 11 12 Collective on TS 13 14 Input Parameters: 15 + ts - The TS context 16 - type - A known method 17 18 Options Database Command: 19 . -ts_type <type> - Sets the method; use -help for a list of available methods (for instance, euler) 20 21 Notes: 22 See "petsc/include/petscts.h" for available methods (for instance) 23 + TS_EULER - Euler 24 . TS_PVODE - PVODE interface 25 . TS_BEULER - Backward Euler 26 - TS_PSEUDO - Pseudo-timestepping 27 28 Normally, it is best to use the TSSetFromOptions() command and 29 then set the TS type from the options database rather than by using 30 this routine. Using the options database provides the user with 31 maximum flexibility in evaluating the many different solvers. 32 The TSSetType() routine is provided for those situations where it 33 is necessary to set the timestepping solver independently of the 34 command line or options database. This might be the case, for example, 35 when the choice of solver changes during the execution of the 36 program, and the user's application is taking responsibility for 37 choosing the appropriate method. In other words, this routine is 38 not for beginners. 39 40 Level: intermediate 41 42 .keywords: TS, set, type 43 44 @*/ 45 PetscErrorCode TSSetType(TS ts, const TSType type) 46 { 47 PetscErrorCode (*r)(TS); 48 PetscTruth match; 49 PetscErrorCode ierr; 50 51 PetscFunctionBegin; 52 PetscValidHeaderSpecific(ts, TS_COOKIE,1); 53 ierr = PetscTypeCompare((PetscObject) ts, type, &match);CHKERRQ(ierr); 54 if (match) PetscFunctionReturn(0); 55 56 /* Get the function pointers for the method requested */ 57 if (!TSRegisterAllCalled) { 58 ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr); 59 } 60 ierr = PetscFListFind(ts->comm, TSList, type, (void (**)(void)) &r);CHKERRQ(ierr); 61 if (!r) SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown TS type: %s", type); 62 if (ts->ksp) { 63 ierr = KSPDestroy(ts->ksp);CHKERRQ(ierr); 64 ts->ksp = PETSC_NULL; 65 } 66 if (ts->snes) { 67 ierr = SNESDestroy(ts->snes);CHKERRQ(ierr); 68 ts->snes = PETSC_NULL; 69 } 70 if (ts->ops->destroy) { 71 ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr); 72 } 73 ierr = (*r)(ts);CHKERRQ(ierr); 74 ierr = PetscObjectChangeTypeName((PetscObject)ts, type);CHKERRQ(ierr); 75 PetscFunctionReturn(0); 76 } 77 78 #undef __FUNCT__ 79 #define __FUNCT__ "TSGetType" 80 /*@C 81 TSGetType - Gets the TS method type (as a string). 82 83 Not Collective 84 85 Input Parameter: 86 . ts - The TS 87 88 Output Parameter: 89 . type - The name of TS method 90 91 Level: intermediate 92 93 .keywords: TS, timestepper, get, type, name 94 .seealso TSSetType() 95 @*/ 96 PetscErrorCode TSGetType(TS ts, TSType *type) 97 { 98 PetscErrorCode ierr; 99 100 PetscFunctionBegin; 101 PetscValidHeaderSpecific(ts, TS_COOKIE,1); 102 PetscValidPointer(type,2); 103 if (!TSRegisterAllCalled) { 104 ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr); 105 } 106 *type = ts->type_name; 107 PetscFunctionReturn(0); 108 } 109 110 /*--------------------------------------------------------------------------------------------------------------------*/ 111 112 #undef __FUNCT__ 113 #define __FUNCT__ "TSRegister" 114 /*@C 115 TSRegister - See TSRegisterDynamic() 116 117 Level: advanced 118 @*/ 119 PetscErrorCode TSRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(TS)) 120 { 121 char fullname[PETSC_MAX_PATH_LEN]; 122 PetscErrorCode ierr; 123 124 PetscFunctionBegin; 125 ierr = PetscStrcpy(fullname, path);CHKERRQ(ierr); 126 ierr = PetscStrcat(fullname, ":");CHKERRQ(ierr); 127 ierr = PetscStrcat(fullname, name);CHKERRQ(ierr); 128 ierr = PetscFListAdd(&TSList, sname, fullname, (void (*)(void)) function);CHKERRQ(ierr); 129 PetscFunctionReturn(0); 130 } 131 132 /*-------------------------------------------------------------------------------------------------------------------*/ 133 #undef __FUNCT__ 134 #define __FUNCT__ "TSRegisterDestroy" 135 /*@C 136 TSRegisterDestroy - Frees the list of timestepping routines that were registered by TSRegister()/TSRegisterDynamic(). 137 138 Not Collective 139 140 Level: advanced 141 142 .keywords: TS, timestepper, register, destroy 143 .seealso: TSRegister(), TSRegisterAll(), TSRegisterDynamic() 144 @*/ 145 PetscErrorCode TSRegisterDestroy(void) 146 { 147 PetscErrorCode ierr; 148 149 PetscFunctionBegin; 150 if (TSList) { 151 ierr = PetscFListDestroy(&TSList);CHKERRQ(ierr); 152 TSList = PETSC_NULL; 153 } 154 TSRegisterAllCalled = PETSC_FALSE; 155 PetscFunctionReturn(0); 156 } 157 158