Skip to content

Commit 788d0f3

Browse files
Add RK scheme with variable dt for SWEs
1 parent cafe924 commit 788d0f3

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

SSPRK.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,40 @@ def SSPRK54(fun, u0, dt, t0, tfinal, nframes):
127127

128128
t += dt
129129
return u_frames, t_eval
130+
131+
def SSPRK33_SWE(fun, q0, dt, t0, tfinal, nframes, CFL, dx_restriction, g):
132+
#Time integration designed for SWEs
133+
#split q into two arrays, the first half is h, the second is hu
134+
n = len(q0)
135+
h = np.copy(q0[:n//2])
136+
hu = np.copy(q0[n//2:])
137+
q = np.copy(q0)
138+
139+
t = t0
140+
q_frames = [q]
141+
t_eval = [t0]
142+
143+
#For sampling solution (needs improvement)
144+
save_step_dt=(tfinal-t0)/nframes
145+
146+
while t<tfinal:
147+
lambda1 = hu/h-np.sqrt(g*h)
148+
lambda2 = hu/h+np.sqrt(g*h)
149+
maxspeed = np.max(np.abs(np.hstack((lambda1,lambda2))))
150+
dt = CFL*dx_restriction/maxspeed/2
151+
dt = min(dt, save_step_dt)
152+
t += dt
153+
154+
q1 = q + dt*fun(q)
155+
q2 = 0.75*q +0.25*q1 + 0.25*dt*fun(q1)
156+
q = (1./3.)*q + (2./3.)* q2 +(2./3.)*dt*fun(q2)
157+
158+
#Saving solution
159+
if t>t_eval[-1]+save_step_dt:
160+
q_frames.append(np.copy(q))
161+
t_eval.append(t)
162+
163+
return q_frames, t_eval
164+
165+
#random number between 0 and 1 numpy
166+
#np.random.rand(1)[0]

0 commit comments

Comments
 (0)