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