1 #ifdef PETSC_RCS_HEADER 2 static char vcid[] = "$Id: euler.c,v 1.15 1998/12/03 04:03:59 bsmith Exp balay $"; 3 #endif 4 /* 5 Code for Timestepping with explicit Euler. 6 */ 7 #include "src/ts/tsimpl.h" /*I "ts.h" I*/ 8 9 typedef struct { 10 Vec update; /* work vector where F(t[i],u[i]) is stored */ 11 } TS_Euler; 12 13 #undef __FUNC__ 14 #define __FUNC__ "TSSetUp_Euler" 15 static int TSSetUp_Euler(TS ts) 16 { 17 TS_Euler *euler = (TS_Euler*) ts->data; 18 int ierr; 19 20 PetscFunctionBegin; 21 ierr = VecDuplicate(ts->vec_sol,&euler->update);CHKERRQ(ierr); 22 PetscFunctionReturn(0); 23 } 24 25 #undef __FUNC__ 26 #define __FUNC__ "TSStep_Euler" 27 static int TSStep_Euler(TS ts,int *steps,double *time) 28 { 29 TS_Euler *euler = (TS_Euler*) ts->data; 30 Vec sol = ts->vec_sol,update = euler->update; 31 int ierr,i,max_steps = ts->max_steps; 32 Scalar dt = ts->time_step; 33 34 PetscFunctionBegin; 35 *steps = -ts->steps; 36 ierr = TSMonitor(ts,ts->steps,ts->ptime,sol);CHKERRQ(ierr); 37 38 for ( i=0; i<max_steps; i++ ) { 39 ts->ptime += ts->time_step; 40 ierr = TSComputeRHSFunction(ts,ts->ptime,sol,update);CHKERRQ(ierr); 41 ierr = VecAXPY(&dt,update,sol);CHKERRQ(ierr); 42 ts->steps++; 43 ierr = TSMonitor(ts,ts->steps,ts->ptime,sol);CHKERRQ(ierr); 44 if (ts->ptime > ts->max_time) break; 45 } 46 47 *steps += ts->steps; 48 *time = ts->ptime; 49 PetscFunctionReturn(0); 50 } 51 /*------------------------------------------------------------*/ 52 #undef __FUNC__ 53 #define __FUNC__ "TSDestroy_Euler" 54 static int TSDestroy_Euler(TS ts) 55 { 56 TS_Euler *euler = (TS_Euler*) ts->data; 57 58 PetscFunctionBegin; 59 VecDestroy(euler->update); 60 PetscFree(euler); 61 PetscFunctionReturn(0); 62 } 63 /*------------------------------------------------------------*/ 64 65 #undef __FUNC__ 66 #define __FUNC__ "TSSetFromOptions_Euler" 67 static int TSSetFromOptions_Euler(TS ts) 68 { 69 PetscFunctionBegin; 70 PetscFunctionReturn(0); 71 } 72 73 #undef __FUNC__ 74 #define __FUNC__ "TSPrintHelp_Euler" 75 static int TSPrintHelp_Euler(TS ts,char *p) 76 { 77 PetscFunctionBegin; 78 PetscFunctionReturn(0); 79 } 80 81 #undef __FUNC__ 82 #define __FUNC__ "TSView_Euler" 83 static int TSView_Euler(TS ts,Viewer viewer) 84 { 85 PetscFunctionBegin; 86 PetscFunctionReturn(0); 87 } 88 89 /* ------------------------------------------------------------ */ 90 EXTERN_C_BEGIN 91 #undef __FUNC__ 92 #define __FUNC__ "TSCreate_Euler" 93 int TSCreate_Euler(TS ts ) 94 { 95 TS_Euler *euler; 96 97 PetscFunctionBegin; 98 ts->setup = TSSetUp_Euler; 99 ts->step = TSStep_Euler; 100 ts->destroy = TSDestroy_Euler; 101 ts->printhelp = TSPrintHelp_Euler; 102 ts->setfromoptions = TSSetFromOptions_Euler; 103 ts->view = TSView_Euler; 104 105 euler = PetscNew(TS_Euler);CHKPTRQ(euler); 106 PLogObjectMemory(ts,sizeof(TS_Euler)); 107 ts->data = (void *) euler; 108 109 PetscFunctionReturn(0); 110 } 111 EXTERN_C_END 112 113 114 115 116