Skip to content

Commit 081834e

Browse files
committed
feat(example): 1st-draft Burgers eq. solver
This commit completes one full times step of the 1D Burgers equation solver, using 2nd- or 4th-order mimetic discretization and 2nd-order Runge-Kutta time advancement. To Do ----- 1. Set time step based on stability criterion 3. Loop over more time steps 2. Compare to exact solution in Fig. 6 of Rouson, Xia & Xu (2011)
1 parent 92ee253 commit 081834e

1 file changed

Lines changed: 24 additions & 13 deletions

File tree

‎example/burgers-1D.F90‎

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ pure function initial_condition(x)
1010
!! Initial solution to Burgers equation
1111
double precision, intent(in) :: x(:)
1212
double precision, allocatable :: initial_condition(:)
13-
double precision, parameter :: pi = acos(-1D0)
14-
initial_condition = x/sqrt(2D0)
13+
initial_condition = 10*sin(x)
1514
! To change this function, please edit only the right-hand-side (RHS) expression,
1615
! keeping the rest in place for proper display of the function at runtime.
1716
end function
@@ -25,10 +24,8 @@ program burgers_1D
2524
use formal_m, only : scalar_1D_t, scalar_1D_initializer_i, d_dx, d2_dx2
2625
implicit none
2726

28-
procedure(scalar_1D_initializer_i), pointer :: scalar_1D_initializer => initial_condition
2927
character(len=:), allocatable :: order_string
3028
type(command_line_t) command_line
31-
type(scalar_1D_t) :: u
3229
integer order
3330

3431
if (command_line%argument_present([character(len=len("--help")) :: ("--help"), "-h"])) then
@@ -58,20 +55,34 @@ program burgers_1D
5855

5956
print *, "order = ", order
6057

61-
u = scalar_1D_t(scalar_1D_initializer, order, x_min=0D0, x_max=20D0, cells=10)
62-
6358
block
64-
double precision dt, nu
65-
dt = 1D0
66-
nu = 1D0
67-
! u_next = u + dt * d_dt(u)
68-
! u_next = u + dt * (nu * d2_dx2(u) - d_dx((u**2)/2))
69-
associate(du_dt => nu*d2_dx2(u) - d_dx((u**2)/2))
70-
end associate
59+
procedure(scalar_1D_initializer_i), pointer :: scalar_1D_initializer => initial_condition
60+
double precision, parameter :: dt = 1D0, pi = acos(-1D0)
61+
type(scalar_1D_t) u
62+
63+
u = scalar_1D_t(scalar_1D_initializer, order, x_min=0D0, x_max=2*pi, cells=20)
64+
!dt = u%runge_kutta_2nd_step(nu ,grid_resolution)
65+
66+
!do while (t<=t_final) ! 2nd-order Runge-Kutta:
67+
associate(u_half => u + d_dt(u)*dt/2) ! first substep
68+
u = u + d_dt(u_half)*dt ! second substep
69+
end associate
70+
!t = t + dt
71+
!end do
72+
7173
end block
7274

7375
#ifdef __GFORTRAN__
7476
stop
7577
#endif
7678

79+
contains
80+
81+
pure function d_dt(u) result(du_dt)
82+
type(scalar_1D_t), intent(in) :: u
83+
type(scalar_1D_t) du_dt
84+
double precision, parameter :: nu=1D0
85+
du_dt = nu*d2_dx2(u) - d_dx((u**2)/2)
86+
end function
87+
7788
end program

0 commit comments

Comments
 (0)