1 #ifdef PETSC_RCS_HEADER 2 static char vcid[] = "$Id: euler.c,v 1.16 1999/05/04 20:36:43 balay 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 int ierr; 58 59 PetscFunctionBegin; 60 VecDestroy(euler->update); 61 ierr = PetscFree(euler);CHKERRQ(ierr); 62 PetscFunctionReturn(0); 63 } 64 /*------------------------------------------------------------*/ 65 66 #undef __FUNC__ 67 #define __FUNC__ "TSSetFromOptions_Euler" 68 static int TSSetFromOptions_Euler(TS ts) 69 { 70 PetscFunctionBegin; 71 PetscFunctionReturn(0); 72 } 73 74 #undef __FUNC__ 75 #define __FUNC__ "TSPrintHelp_Euler" 76 static int TSPrintHelp_Euler(TS ts,char *p) 77 { 78 PetscFunctionBegin; 79 PetscFunctionReturn(0); 80 } 81 82 #undef __FUNC__ 83 #define __FUNC__ "TSView_Euler" 84 static int TSView_Euler(TS ts,Viewer viewer) 85 { 86 PetscFunctionBegin; 87 PetscFunctionReturn(0); 88 } 89 90 /* ------------------------------------------------------------ */ 91 EXTERN_C_BEGIN 92 #undef __FUNC__ 93 #define __FUNC__ "TSCreate_Euler" 94 int TSCreate_Euler(TS ts ) 95 { 96 TS_Euler *euler; 97 98 PetscFunctionBegin; 99 ts->setup = TSSetUp_Euler; 100 ts->step = TSStep_Euler; 101 ts->destroy = TSDestroy_Euler; 102 ts->printhelp = TSPrintHelp_Euler; 103 ts->setfromoptions = TSSetFromOptions_Euler; 104 ts->view = TSView_Euler; 105 106 euler = PetscNew(TS_Euler);CHKPTRQ(euler); 107 PLogObjectMemory(ts,sizeof(TS_Euler)); 108 ts->data = (void *) euler; 109 110 PetscFunctionReturn(0); 111 } 112 EXTERN_C_END 113 114 115 116 117