1 2 #include "private/tsimpl.h" /*I "petscts.h" I*/ 3 4 PetscFList TSList = PETSC_NULL; 5 PetscBool 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 + TSEULER - Euler 24 . TSSUNDIALS - SUNDIALS interface 25 . TSBEULER - Backward Euler 26 - TSPSEUDO - 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 PetscBool match; 49 PetscErrorCode ierr; 50 51 PetscFunctionBegin; 52 PetscValidHeaderSpecific(ts, TS_CLASSID,1); 53 ierr = PetscTypeCompare((PetscObject) ts, type, &match);CHKERRQ(ierr); 54 if (match) PetscFunctionReturn(0); 55 56 ierr = PetscFListFind( TSList,((PetscObject)ts)->comm, type, (void (**)(void)) &r);CHKERRQ(ierr); 57 if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown TS type: %s", type); 58 if (ts->ksp) { 59 ierr = KSPDestroy(ts->ksp);CHKERRQ(ierr); 60 ts->ksp = PETSC_NULL; 61 } 62 if (ts->snes) { 63 ierr = SNESDestroy(ts->snes);CHKERRQ(ierr); 64 ts->snes = PETSC_NULL; 65 } 66 if (ts->ops->destroy) { 67 ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr); 68 } 69 ierr = (*r)(ts);CHKERRQ(ierr); 70 ierr = PetscObjectChangeTypeName((PetscObject)ts, type);CHKERRQ(ierr); 71 #if defined(PETSC_HAVE_AMS) 72 if (PetscAMSPublishAll) { 73 ierr = PetscObjectAMSPublish((PetscObject)ts);CHKERRQ(ierr); 74 } 75 #endif 76 PetscFunctionReturn(0); 77 } 78 79 #undef __FUNCT__ 80 #define __FUNCT__ "TSGetType" 81 /*@C 82 TSGetType - Gets the TS method type (as a string). 83 84 Not Collective 85 86 Input Parameter: 87 . ts - The TS 88 89 Output Parameter: 90 . type - The name of TS method 91 92 Level: intermediate 93 94 .keywords: TS, timestepper, get, type, name 95 .seealso TSSetType() 96 @*/ 97 PetscErrorCode TSGetType(TS ts, const TSType *type) 98 { 99 PetscFunctionBegin; 100 PetscValidHeaderSpecific(ts,TS_CLASSID,1); 101 PetscValidPointer(type,2); 102 *type = ((PetscObject)ts)->type_name; 103 PetscFunctionReturn(0); 104 } 105 106 /*--------------------------------------------------------------------------------------------------------------------*/ 107 108 #undef __FUNCT__ 109 #define __FUNCT__ "TSRegister" 110 /*@C 111 TSRegister - See TSRegisterDynamic() 112 113 Level: advanced 114 @*/ 115 PetscErrorCode TSRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(TS)) 116 { 117 char fullname[PETSC_MAX_PATH_LEN]; 118 PetscErrorCode ierr; 119 120 PetscFunctionBegin; 121 ierr = PetscStrcpy(fullname, path);CHKERRQ(ierr); 122 ierr = PetscStrcat(fullname, ":");CHKERRQ(ierr); 123 ierr = PetscStrcat(fullname, name);CHKERRQ(ierr); 124 ierr = PetscFListAdd(&TSList, sname, fullname, (void (*)(void)) function);CHKERRQ(ierr); 125 PetscFunctionReturn(0); 126 } 127 128 /*-------------------------------------------------------------------------------------------------------------------*/ 129 #undef __FUNCT__ 130 #define __FUNCT__ "TSRegisterDestroy" 131 /*@C 132 TSRegisterDestroy - Frees the list of timestepping routines that were registered by TSRegister()/TSRegisterDynamic(). 133 134 Not Collective 135 136 Level: advanced 137 138 .keywords: TS, timestepper, register, destroy 139 .seealso: TSRegister(), TSRegisterAll(), TSRegisterDynamic() 140 @*/ 141 PetscErrorCode TSRegisterDestroy(void) 142 { 143 PetscErrorCode ierr; 144 145 PetscFunctionBegin; 146 ierr = PetscFListDestroy(&TSList);CHKERRQ(ierr); 147 TSRegisterAllCalled = PETSC_FALSE; 148 PetscFunctionReturn(0); 149 } 150 151