1*e090d566SSatish Balay /*$Id: euler.c,v 1.22 2000/04/12 04:25:58 bsmith Exp balay $*/ 24b33d51aSBarry Smith /* 3fb4a63b6SLois Curfman McInnes Code for Timestepping with explicit Euler. 44b33d51aSBarry Smith */ 5*e090d566SSatish Balay #include "src/ts/tsimpl.h" /*I "petscts.h" I*/ 64b33d51aSBarry Smith 78b1af7b3SBarry Smith typedef struct { 88b1af7b3SBarry Smith Vec update; /* work vector where F(t[i],u[i]) is stored */ 98b1af7b3SBarry Smith } TS_Euler; 108b1af7b3SBarry Smith 1158562591SBarry Smith #undef __FUNC__ 12b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"TSSetUp_Euler" 138b1af7b3SBarry Smith static int TSSetUp_Euler(TS ts) 144b33d51aSBarry Smith { 158b1af7b3SBarry Smith TS_Euler *euler = (TS_Euler*)ts->data; 164b33d51aSBarry Smith int ierr; 174b33d51aSBarry Smith 183a40ed3dSBarry Smith PetscFunctionBegin; 198b1af7b3SBarry Smith ierr = VecDuplicate(ts->vec_sol,&euler->update);CHKERRQ(ierr); 203a40ed3dSBarry Smith PetscFunctionReturn(0); 214b33d51aSBarry Smith } 224b33d51aSBarry Smith 2358562591SBarry Smith #undef __FUNC__ 24b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"TSStep_Euler" 25c3e30b67SBarry Smith static int TSStep_Euler(TS ts,int *steps,double *time) 264b33d51aSBarry Smith { 278b1af7b3SBarry Smith TS_Euler *euler = (TS_Euler*)ts->data; 288b1af7b3SBarry Smith Vec sol = ts->vec_sol,update = euler->update; 298b1af7b3SBarry Smith int ierr,i,max_steps = ts->max_steps; 30c3e30b67SBarry Smith Scalar dt = ts->time_step; 314b33d51aSBarry Smith 323a40ed3dSBarry Smith PetscFunctionBegin; 338b1af7b3SBarry Smith *steps = -ts->steps; 34c3e30b67SBarry Smith ierr = TSMonitor(ts,ts->steps,ts->ptime,sol);CHKERRQ(ierr); 354b33d51aSBarry Smith 368b1af7b3SBarry Smith for (i=0; i<max_steps; i++) { 378b1af7b3SBarry Smith ts->ptime += ts->time_step; 38c3e30b67SBarry Smith ierr = TSComputeRHSFunction(ts,ts->ptime,sol,update);CHKERRQ(ierr); 39c3e30b67SBarry Smith ierr = VecAXPY(&dt,update,sol);CHKERRQ(ierr); 408b1af7b3SBarry Smith ts->steps++; 41c3e30b67SBarry Smith ierr = TSMonitor(ts,ts->steps,ts->ptime,sol);CHKERRQ(ierr); 428b1af7b3SBarry Smith if (ts->ptime > ts->max_time) break; 438b1af7b3SBarry Smith } 444b33d51aSBarry Smith 458b1af7b3SBarry Smith *steps += ts->steps; 468b1af7b3SBarry Smith *time = ts->ptime; 473a40ed3dSBarry Smith PetscFunctionReturn(0); 484b33d51aSBarry Smith } 494b33d51aSBarry Smith /*------------------------------------------------------------*/ 5058562591SBarry Smith #undef __FUNC__ 51b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"TSDestroy_Euler" 52e1311b90SBarry Smith static int TSDestroy_Euler(TS ts) 534b33d51aSBarry Smith { 548b1af7b3SBarry Smith TS_Euler *euler = (TS_Euler*)ts->data; 55606d414cSSatish Balay int ierr; 568b1af7b3SBarry Smith 573a40ed3dSBarry Smith PetscFunctionBegin; 587c922b88SBarry Smith ierr = VecDestroy(euler->update);CHKERRQ(ierr); 59606d414cSSatish Balay ierr = PetscFree(euler);CHKERRQ(ierr); 603a40ed3dSBarry Smith PetscFunctionReturn(0); 618b1af7b3SBarry Smith } 628b1af7b3SBarry Smith /*------------------------------------------------------------*/ 638b1af7b3SBarry Smith 6458562591SBarry Smith #undef __FUNC__ 65b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"TSSetFromOptions_Euler" 668b1af7b3SBarry Smith static int TSSetFromOptions_Euler(TS ts) 678b1af7b3SBarry Smith { 683a40ed3dSBarry Smith PetscFunctionBegin; 693a40ed3dSBarry Smith PetscFunctionReturn(0); 704b33d51aSBarry Smith } 714b33d51aSBarry Smith 7258562591SBarry Smith #undef __FUNC__ 73b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"TSPrintHelp_Euler" 74ca4b7087SBarry Smith static int TSPrintHelp_Euler(TS ts,char *p) 754b33d51aSBarry Smith { 763a40ed3dSBarry Smith PetscFunctionBegin; 773a40ed3dSBarry Smith PetscFunctionReturn(0); 788b1af7b3SBarry Smith } 798b1af7b3SBarry Smith 8058562591SBarry Smith #undef __FUNC__ 81b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"TSView_Euler" 82e1311b90SBarry Smith static int TSView_Euler(TS ts,Viewer viewer) 838b1af7b3SBarry Smith { 843a40ed3dSBarry Smith PetscFunctionBegin; 853a40ed3dSBarry Smith PetscFunctionReturn(0); 868b1af7b3SBarry Smith } 878b1af7b3SBarry Smith 888b1af7b3SBarry Smith /* ------------------------------------------------------------ */ 89fb2e594dSBarry Smith EXTERN_C_BEGIN 9058562591SBarry Smith #undef __FUNC__ 91b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"TSCreate_Euler" 928b1af7b3SBarry Smith int TSCreate_Euler(TS ts) 938b1af7b3SBarry Smith { 948b1af7b3SBarry Smith TS_Euler *euler; 958b1af7b3SBarry Smith 963a40ed3dSBarry Smith PetscFunctionBegin; 978b1af7b3SBarry Smith ts->setup = TSSetUp_Euler; 988b1af7b3SBarry Smith ts->step = TSStep_Euler; 998b1af7b3SBarry Smith ts->destroy = TSDestroy_Euler; 1008b1af7b3SBarry Smith ts->printhelp = TSPrintHelp_Euler; 1018b1af7b3SBarry Smith ts->setfromoptions = TSSetFromOptions_Euler; 1028b1af7b3SBarry Smith ts->view = TSView_Euler; 1038b1af7b3SBarry Smith 1048b1af7b3SBarry Smith euler = PetscNew(TS_Euler);CHKPTRQ(euler); 105eed86810SBarry Smith PLogObjectMemory(ts,sizeof(TS_Euler)); 1068b1af7b3SBarry Smith ts->data = (void*)euler; 1074b33d51aSBarry Smith 1083a40ed3dSBarry Smith PetscFunctionReturn(0); 1094b33d51aSBarry Smith } 110fb2e594dSBarry Smith EXTERN_C_END 111c3e30b67SBarry Smith 112c3e30b67SBarry Smith 113c3e30b67SBarry Smith 114c3e30b67SBarry Smith 115