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 int TSSetType(TS ts, const TSType type) 46 { 47 int (*r)(TS); 48 PetscTruth match; 49 int ierr; 50 51 PetscFunctionBegin; 52 PetscValidHeaderSpecific(ts, TS_COOKIE,1); 53 ierr = PetscTypeCompare((PetscObject) ts, type, &match);CHKERRQ(ierr); 54 if (match == PETSC_TRUE) PetscFunctionReturn(0); 55 56 /* Get the function pointers for the method requested */ 57 if (TSRegisterAllCalled == PETSC_FALSE) { 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_OUTOFRANGE, "Unknown TS type: %s", type); 62 63 if (ts->ksp != PETSC_NULL) { 64 ierr = KSPDestroy(ts->ksp);CHKERRQ(ierr); 65 ts->ksp = PETSC_NULL; 66 } 67 if (ts->snes != PETSC_NULL) { 68 ierr = SNESDestroy(ts->snes);CHKERRQ(ierr); 69 ts->snes = PETSC_NULL; 70 } 71 if (ts->ops->destroy != PETSC_NULL) { 72 ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr); 73 } 74 ierr = (*r)(ts);CHKERRQ(ierr); 75 76 ierr = PetscObjectChangeTypeName((PetscObject)ts, type);CHKERRQ(ierr); 77 PetscFunctionReturn(0); 78 } 79 80 #undef __FUNCT__ 81 #define __FUNCT__ "TSGetType" 82 /*@C 83 TSGetType - Gets the TS method type (as a string). 84 85 Not Collective 86 87 Input Parameter: 88 . ts - The TS 89 90 Output Parameter: 91 . type - The name of TS method 92 93 Level: intermediate 94 95 .keywords: TS, timestepper, get, type, name 96 .seealso TSSetType() 97 @*/ 98 int TSGetType(TS ts, TSType *type) 99 { 100 int ierr; 101 102 PetscFunctionBegin; 103 PetscValidHeaderSpecific(ts, TS_COOKIE,1); 104 PetscValidPointer(type,2); 105 if (TSRegisterAllCalled == PETSC_FALSE) { 106 ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr); 107 } 108 *type = ts->type_name; 109 PetscFunctionReturn(0); 110 } 111 112 /*--------------------------------------------------------------------------------------------------------------------*/ 113 114 #undef __FUNCT__ 115 #define __FUNCT__ "TSRegister" 116 /*@C 117 TSRegister - See TSRegisterDynamic() 118 119 Level: advanced 120 @*/ 121 int TSRegister(const char sname[], const char path[], const char name[], int (*function)(TS)) 122 { 123 char fullname[256]; 124 int ierr; 125 126 PetscFunctionBegin; 127 ierr = PetscStrcpy(fullname, path);CHKERRQ(ierr); 128 ierr = PetscStrcat(fullname, ":");CHKERRQ(ierr); 129 ierr = PetscStrcat(fullname, name);CHKERRQ(ierr); 130 ierr = PetscFListAdd(&TSList, sname, fullname, (void (*)(void)) function);CHKERRQ(ierr); 131 PetscFunctionReturn(0); 132 } 133 134 /*-------------------------------------------------------------------------------------------------------------------*/ 135 #undef __FUNCT__ 136 #define __FUNCT__ "TSRegisterDestroy" 137 /*@C 138 TSRegisterDestroy - Frees the list of timestepping routines that were registered by TSRegister()/TSRegisterDynamic(). 139 140 Not Collective 141 142 Level: advanced 143 144 .keywords: TS, timestepper, register, destroy 145 .seealso: TSRegister(), TSRegisterAll(), TSRegisterDynamic() 146 @*/ 147 int TSRegisterDestroy(void) 148 { 149 int ierr; 150 151 PetscFunctionBegin; 152 if (TSList != PETSC_NULL) { 153 ierr = PetscFListDestroy(&TSList);CHKERRQ(ierr); 154 TSList = PETSC_NULL; 155 } 156 TSRegisterAllCalled = PETSC_FALSE; 157 PetscFunctionReturn(0); 158 } 159 160