173f4d377SMatthew Knepley /*$Id: tsreg.c,v 1.71 2001/08/06 21:18:08 bsmith Exp $*/ 23f3760d9SBarry Smith 3e090d566SSatish Balay #include "src/ts/tsimpl.h" /*I "petscts.h" I*/ 43f3760d9SBarry Smith 5bdad233fSMatthew Knepley PetscFList TSList = PETSC_NULL; 64c49b128SBarry Smith PetscTruth TSRegisterAllCalled = PETSC_FALSE; 73f3760d9SBarry Smith 84a2ae208SSatish Balay #undef __FUNCT__ 94a2ae208SSatish Balay #define __FUNCT__ "TSSetType" 1082bf6240SBarry Smith /*@C 11ae12b187SLois Curfman McInnes TSSetType - Sets the method for the timestepping solver. 123f3760d9SBarry Smith 13fee21e36SBarry Smith Collective on TS 14fee21e36SBarry Smith 15bef22f13SLois Curfman McInnes Input Parameters: 16bdad233fSMatthew Knepley + ts - The TS context 17bdad233fSMatthew Knepley - type - A known method 18bef22f13SLois Curfman McInnes 19ae12b187SLois Curfman McInnes Options Database Command: 20bdad233fSMatthew Knepley . -ts_type <type> - Sets the method; use -help for a list of available methods (for instance, euler) 21ae12b187SLois Curfman McInnes 223f3760d9SBarry Smith Notes: 23e090d566SSatish Balay See "petsc/include/petscts.h" for available methods (for instance) 24d5d37b61SLois Curfman McInnes + TS_EULER - Euler 25bef22f13SLois Curfman McInnes . TS_PVODE - PVODE interface 26bef22f13SLois Curfman McInnes . TS_BEULER - Backward Euler 27d5d37b61SLois Curfman McInnes - TS_PSEUDO - Pseudo-timestepping 283f3760d9SBarry Smith 29ae12b187SLois Curfman McInnes Normally, it is best to use the TSSetFromOptions() command and 30ae12b187SLois Curfman McInnes then set the TS type from the options database rather than by using 31ae12b187SLois Curfman McInnes this routine. Using the options database provides the user with 32ae12b187SLois Curfman McInnes maximum flexibility in evaluating the many different solvers. 33ae12b187SLois Curfman McInnes The TSSetType() routine is provided for those situations where it 34ae12b187SLois Curfman McInnes is necessary to set the timestepping solver independently of the 35ae12b187SLois Curfman McInnes command line or options database. This might be the case, for example, 36ae12b187SLois Curfman McInnes when the choice of solver changes during the execution of the 37ae12b187SLois Curfman McInnes program, and the user's application is taking responsibility for 38ae12b187SLois Curfman McInnes choosing the appropriate method. In other words, this routine is 39d5d37b61SLois Curfman McInnes not for beginners. 40d5d37b61SLois Curfman McInnes 41d5d37b61SLois Curfman McInnes Level: intermediate 423f3760d9SBarry Smith 43ae12b187SLois Curfman McInnes .keywords: TS, set, type 44*437fc6d7SBarry Smith 453f3760d9SBarry Smith @*/ 460e33f6ddSBarry Smith int TSSetType(TS ts, const TSType type) 473f3760d9SBarry Smith { 48bdad233fSMatthew Knepley int (*r)(TS); 496831982aSBarry Smith PetscTruth match; 50df8cb225SBarry Smith int ierr; 51df8cb225SBarry Smith 523a40ed3dSBarry Smith PetscFunctionBegin; 53bdad233fSMatthew Knepley PetscValidHeaderSpecific(ts, TS_COOKIE); 54bdad233fSMatthew Knepley ierr = PetscTypeCompare((PetscObject) ts, type, &match); CHKERRQ(ierr); 55bdad233fSMatthew Knepley if (match == PETSC_TRUE) PetscFunctionReturn(0); 56bdad233fSMatthew Knepley 57bdad233fSMatthew Knepley /* Get the function pointers for the method requested */ 58bdad233fSMatthew Knepley if (TSRegisterAllCalled == PETSC_FALSE) { 59bdad233fSMatthew Knepley ierr = TSRegisterAll(PETSC_NULL); CHKERRQ(ierr); 603f3760d9SBarry Smith } 61bdad233fSMatthew Knepley ierr = PetscFListFind(ts->comm, TSList, type, (void (**)(void)) &r); CHKERRQ(ierr); 62bdad233fSMatthew Knepley if (!r) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE, "Unknown TS type: %s", type); 63bdad233fSMatthew Knepley 6494b7f48cSBarry Smith if (ts->ksp != PETSC_NULL) { 6594b7f48cSBarry Smith ierr = KSPDestroy(ts->ksp); CHKERRQ(ierr); 6694b7f48cSBarry Smith ts->ksp = PETSC_NULL; 67bdad233fSMatthew Knepley } 68bdad233fSMatthew Knepley if (ts->snes != PETSC_NULL) { 69bdad233fSMatthew Knepley ierr = SNESDestroy(ts->snes); CHKERRQ(ierr); 70bdad233fSMatthew Knepley ts->snes = PETSC_NULL; 71bdad233fSMatthew Knepley } 72bdad233fSMatthew Knepley if (ts->ops->destroy != PETSC_NULL) { 73bdad233fSMatthew Knepley ierr = (*(ts)->ops->destroy)(ts); CHKERRQ(ierr); 74bdad233fSMatthew Knepley } 75bdad233fSMatthew Knepley ierr = (*r)(ts); CHKERRQ(ierr); 76bdad233fSMatthew Knepley 77bdad233fSMatthew Knepley ierr = PetscObjectChangeTypeName((PetscObject)ts, type); CHKERRQ(ierr); 783a40ed3dSBarry Smith PetscFunctionReturn(0); 793f3760d9SBarry Smith } 803f3760d9SBarry Smith 814a2ae208SSatish Balay #undef __FUNCT__ 824a2ae208SSatish Balay #define __FUNCT__ "TSGetType" 833f3760d9SBarry Smith /*@C 84fee21e36SBarry Smith TSGetType - Gets the TS method type (as a string). 853f3760d9SBarry Smith 86bef22f13SLois Curfman McInnes Not Collective 87bef22f13SLois Curfman McInnes 883f3760d9SBarry Smith Input Parameter: 89bdad233fSMatthew Knepley . ts - The TS 903f3760d9SBarry Smith 913f3760d9SBarry Smith Output Parameter: 92bdad233fSMatthew Knepley . type - The name of TS method 933f3760d9SBarry Smith 94d5d37b61SLois Curfman McInnes Level: intermediate 95d5d37b61SLois Curfman McInnes 96df8cb225SBarry Smith .keywords: TS, timestepper, get, type, name 97bdad233fSMatthew Knepley .seealso TSSetType() 983f3760d9SBarry Smith @*/ 9982bf6240SBarry Smith int TSGetType(TS ts, TSType *type) 1003f3760d9SBarry Smith { 1013f3760d9SBarry Smith int ierr; 1023a40ed3dSBarry Smith 1033a40ed3dSBarry Smith PetscFunctionBegin; 104bdad233fSMatthew Knepley PetscValidHeaderSpecific(ts, TS_COOKIE); 105bdad233fSMatthew Knepley PetscValidPointer(type); 106bdad233fSMatthew Knepley if (TSRegisterAllCalled == PETSC_FALSE) { 107bdad233fSMatthew Knepley ierr = TSRegisterAll(PETSC_NULL); CHKERRQ(ierr); 108bdad233fSMatthew Knepley } 10982bf6240SBarry Smith *type = ts->type_name; 1103a40ed3dSBarry Smith PetscFunctionReturn(0); 1113f3760d9SBarry Smith } 1123f3760d9SBarry Smith 113bdad233fSMatthew Knepley /*--------------------------------------------------------------------------------------------------------------------*/ 1143cea93caSBarry Smith 115bdad233fSMatthew Knepley #undef __FUNCT__ 116bdad233fSMatthew Knepley #define __FUNCT__ "TSRegister" 1173cea93caSBarry Smith /*@C 1183cea93caSBarry Smith TSRegister - See TSRegisterDynamic() 1193cea93caSBarry Smith 1207f6c08e0SMatthew Knepley Level: advanced 1213cea93caSBarry Smith @*/ 122bdad233fSMatthew Knepley int TSRegister(const char sname[], const char path[], const char name[], int (*function)(TS)) 123bdad233fSMatthew Knepley { 124bdad233fSMatthew Knepley char fullname[256]; 125bdad233fSMatthew Knepley int ierr; 126bdad233fSMatthew Knepley 127bdad233fSMatthew Knepley PetscFunctionBegin; 128bdad233fSMatthew Knepley ierr = PetscStrcpy(fullname, path); CHKERRQ(ierr); 129bdad233fSMatthew Knepley ierr = PetscStrcat(fullname, ":"); CHKERRQ(ierr); 130bdad233fSMatthew Knepley ierr = PetscStrcat(fullname, name); CHKERRQ(ierr); 131bdad233fSMatthew Knepley ierr = PetscFListAdd(&TSList, sname, fullname, (void (*)(void)) function); CHKERRQ(ierr); 132bdad233fSMatthew Knepley PetscFunctionReturn(0); 133bdad233fSMatthew Knepley } 134bdad233fSMatthew Knepley 135bdad233fSMatthew Knepley /*-------------------------------------------------------------------------------------------------------------------*/ 136bdad233fSMatthew Knepley #undef __FUNCT__ 137bdad233fSMatthew Knepley #define __FUNCT__ "TSRegisterDestroy" 138bdad233fSMatthew Knepley /*@C 1393cea93caSBarry Smith TSRegisterDestroy - Frees the list of timestepping routines that were registered by TSRegister()/TSRegisterDynamic(). 140bdad233fSMatthew Knepley 141bdad233fSMatthew Knepley Not Collective 142bdad233fSMatthew Knepley 143bdad233fSMatthew Knepley Level: advanced 144bdad233fSMatthew Knepley 145bdad233fSMatthew Knepley .keywords: TS, timestepper, register, destroy 146*437fc6d7SBarry Smith .seealso: TSRegister(), TSRegisterAll(), TSRegisterDynamic() 147bdad233fSMatthew Knepley @*/ 148bdad233fSMatthew Knepley int TSRegisterDestroy(void) 149bdad233fSMatthew Knepley { 150bdad233fSMatthew Knepley int ierr; 151bdad233fSMatthew Knepley 152bdad233fSMatthew Knepley PetscFunctionBegin; 153bdad233fSMatthew Knepley if (TSList != PETSC_NULL) { 154bdad233fSMatthew Knepley ierr = PetscFListDestroy(&TSList); CHKERRQ(ierr); 155bdad233fSMatthew Knepley TSList = PETSC_NULL; 156bdad233fSMatthew Knepley } 157bdad233fSMatthew Knepley TSRegisterAllCalled = PETSC_FALSE; 158bdad233fSMatthew Knepley PetscFunctionReturn(0); 159bdad233fSMatthew Knepley } 160bdad233fSMatthew Knepley 161