1 #include <petsc/private/tsimpl.h> /*I "petscts.h" I*/ 2 3 PetscFunctionList TSList = NULL; 4 PetscBool TSRegisterAllCalled = PETSC_FALSE; 5 6 /*@C 7 TSSetType - Sets the method to be used as the timestepping solver. 8 9 Collective on TS 10 11 Input Parameters: 12 + ts - The TS context 13 - type - A known method 14 15 Options Database Command: 16 . -ts_type <type> - Sets the method; use -help for a list of available methods (for instance, euler) 17 18 Notes: 19 See "petsc/include/petscts.h" for available methods (for instance) 20 + TSEULER - Euler 21 . TSSUNDIALS - SUNDIALS interface 22 . TSBEULER - Backward Euler 23 - TSPSEUDO - Pseudo-timestepping 24 25 Normally, it is best to use the TSSetFromOptions() command and 26 then set the TS type from the options database rather than by using 27 this routine. Using the options database provides the user with 28 maximum flexibility in evaluating the many different solvers. 29 The TSSetType() routine is provided for those situations where it 30 is necessary to set the timestepping solver independently of the 31 command line or options database. This might be the case, for example, 32 when the choice of solver changes during the execution of the 33 program, and the user's application is taking responsibility for 34 choosing the appropriate method. In other words, this routine is 35 not for beginners. 36 37 Level: intermediate 38 39 .keywords: TS, set, type 40 41 .seealso: TS, TSSolve(), TSCreate(), TSSetFromOptions(), TSDestroy(), TSType 42 43 @*/ 44 PetscErrorCode TSSetType(TS ts,TSType type) 45 { 46 PetscErrorCode (*r)(TS); 47 PetscBool match; 48 PetscErrorCode ierr; 49 50 PetscFunctionBegin; 51 PetscValidHeaderSpecific(ts, TS_CLASSID,1); 52 PetscValidCharPointer(type,2); 53 ierr = PetscObjectTypeCompare((PetscObject) ts, type, &match);CHKERRQ(ierr); 54 if (match) PetscFunctionReturn(0); 55 56 ierr = PetscFunctionListFind(TSList,type,&r);CHKERRQ(ierr); 57 if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown TS type: %s", type); 58 if (ts->ops->destroy) { 59 ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr); 60 } 61 ierr = PetscMemzero(ts->ops,sizeof(*ts->ops));CHKERRQ(ierr); 62 ts->usessnes = PETSC_FALSE; 63 ts->default_adapt_type = TSADAPTNONE; 64 65 ts->setupcalled = PETSC_FALSE; 66 67 ierr = PetscObjectChangeTypeName((PetscObject)ts, type);CHKERRQ(ierr); 68 ierr = (*r)(ts);CHKERRQ(ierr); 69 PetscFunctionReturn(0); 70 } 71 72 /*@C 73 TSGetType - Gets the TS method type (as a string). 74 75 Not Collective 76 77 Input Parameter: 78 . ts - The TS 79 80 Output Parameter: 81 . type - The name of TS method 82 83 Level: intermediate 84 85 .keywords: TS, timestepper, get, type, name 86 .seealso TSSetType() 87 @*/ 88 PetscErrorCode TSGetType(TS ts, TSType *type) 89 { 90 PetscFunctionBegin; 91 PetscValidHeaderSpecific(ts,TS_CLASSID,1); 92 PetscValidPointer(type,2); 93 *type = ((PetscObject)ts)->type_name; 94 PetscFunctionReturn(0); 95 } 96 97 /*--------------------------------------------------------------------------------------------------------------------*/ 98 99 /*@C 100 TSRegister - Adds a creation method to the TS package. 101 102 Not Collective 103 104 Input Parameters: 105 + name - The name of a new user-defined creation routine 106 - create_func - The creation routine itself 107 108 Notes: 109 TSRegister() may be called multiple times to add several user-defined tses. 110 111 Sample usage: 112 .vb 113 TSRegister("my_ts", MyTSCreate); 114 .ve 115 116 Then, your ts type can be chosen with the procedural interface via 117 .vb 118 TS ts; 119 TSCreate(MPI_Comm, &ts); 120 TSSetType(ts, "my_ts") 121 .ve 122 or at runtime via the option 123 .vb 124 -ts_type my_ts 125 .ve 126 127 Level: advanced 128 129 .keywords: TS, register 130 131 .seealso: TSRegisterAll(), TSRegisterDestroy() 132 @*/ 133 PetscErrorCode TSRegister(const char sname[], PetscErrorCode (*function)(TS)) 134 { 135 PetscErrorCode ierr; 136 137 PetscFunctionBegin; 138 ierr = PetscFunctionListAdd(&TSList,sname,function);CHKERRQ(ierr); 139 PetscFunctionReturn(0); 140 } 141 142