1 | C Last change: C 1 Mar 2001 12:27 pm |
---|
2 | program Landslide_Tadmor |
---|
3 | c |
---|
4 | c Stiff source term solution using the second order |
---|
5 | c central scheme of Landslide and the modifications |
---|
6 | c suggested by Liotta, Romano and Russo, SIAM |
---|
7 | c J. Numer. Anal. 38(4), 1337-1356, 2000. |
---|
8 | c This is the Randau scheme. |
---|
9 | c |
---|
10 | c============================================================ |
---|
11 | implicit none |
---|
12 | integer md,nxmax,nxd, mn |
---|
13 | parameter (md=3, nxmax=1601, nxd=nxmax+2*md, mn=2) |
---|
14 | real*8 u(nxd,mn),x(nxd,2),z(nxd,2),dz(nxd,2) |
---|
15 | |
---|
16 | integer nx, nxx, io, i, isteps |
---|
17 | real*8 toll,cfl,theta,g,dx,dtmax,Tout,Tfinal,tc,a,tau,B,t0, |
---|
18 | . p,s,zeta_0,zeta_1,zeta,u0,version,hl,hr |
---|
19 | |
---|
20 | open(11,file='data.w') |
---|
21 | open(12,file='data.t') |
---|
22 | open(13,file='data.h') |
---|
23 | open(14,file='data.uh') |
---|
24 | open(15,file='data.n') |
---|
25 | open(16,file='data.x') |
---|
26 | |
---|
27 | open(1,file='MacDonald.bed') |
---|
28 | c |
---|
29 | c Parameters |
---|
30 | c |
---|
31 | version = 1.0 |
---|
32 | nx = 101 |
---|
33 | nxx = nx+2*md |
---|
34 | if (nx.gt.nxmax) write(*,*)'nx too large' |
---|
35 | toll = 1.d-6 |
---|
36 | cfl = 0.2d0 |
---|
37 | theta = 1.0d0 |
---|
38 | g = 9.81d0 |
---|
39 | hl=10.0d0 |
---|
40 | hr = 0.d0 |
---|
41 | dx = 10000.d0/dble(nx-1) |
---|
42 | dtmax = 0.5d0 |
---|
43 | Tout = 1.0d0 |
---|
44 | Tfinal = 1500.0d0 |
---|
45 | |
---|
46 | t0 = 0.d0 |
---|
47 | |
---|
48 | c |
---|
49 | c Setup Terrain |
---|
50 | c |
---|
51 | c ---- Non-uniform terrain from MacDonald |
---|
52 | io = 1 |
---|
53 | do i = 1,nxx |
---|
54 | read(1,*)x(i,io),z(i,io) |
---|
55 | z(i,io) = z(i,io)*5.d0 |
---|
56 | end do |
---|
57 | do i = 2,nxx-1 |
---|
58 | dz(i,io) = (z(i+1,io) - z(i-1,io))/2.d0/dx |
---|
59 | end do |
---|
60 | dz(1,io) = dz(2,io) |
---|
61 | dz(nxx,io) = dz(nxx-1,io) |
---|
62 | |
---|
63 | io = 2 |
---|
64 | do i = 1,nxx |
---|
65 | x(i,io) = x(i,io-1) |
---|
66 | z(i,io) = z(i,io-1) |
---|
67 | dz(i,io) = dz(i,io-1) |
---|
68 | end do |
---|
69 | |
---|
70 | c |
---|
71 | c Initial Conditions |
---|
72 | c |
---|
73 | c ---- Rectangular pulse initial condition |
---|
74 | do i = md+1, nx+md |
---|
75 | if (x(i,io).lt.100.d0.or.x(i,io).gt.200.d0) then |
---|
76 | u(i,1) = hr |
---|
77 | else |
---|
78 | u(i,1) = hl |
---|
79 | endif |
---|
80 | u(i,2) = 0.0d0 |
---|
81 | end do |
---|
82 | |
---|
83 | c |
---|
84 | c Setup for Time looping |
---|
85 | c |
---|
86 | |
---|
87 | tc = 0.0d0 |
---|
88 | call dump_solution(u,z,nx,tc,isteps) |
---|
89 | c |
---|
90 | c Evolve |
---|
91 | c |
---|
92 | call momentum_mass(nx,dx,cfl,g,theta,Tfinal, |
---|
93 | . u,dtmax,toll,z,dz,Tout,isteps) |
---|
94 | |
---|
95 | write(15,*)isteps,nxx,version |
---|
96 | do i=1,nxx |
---|
97 | write(16,*) x(i,1) |
---|
98 | enddo |
---|
99 | |
---|
100 | |
---|
101 | c |
---|
102 | c Close down |
---|
103 | c |
---|
104 | close(1) |
---|
105 | close(2) |
---|
106 | close(3) |
---|
107 | close(4) |
---|
108 | close(5) |
---|
109 | close(8) |
---|
110 | |
---|
111 | stop |
---|
112 | end |
---|
113 | |
---|
114 | c=============================================================== |
---|
115 | c The evolver |
---|
116 | c=============================================================== |
---|
117 | subroutine momentum_mass(nx,dx,cfl,g,theta,tf,u,dtmax,toll, |
---|
118 | . z,dz,Tout,isteps) |
---|
119 | c |
---|
120 | c INPUT nx # of cells in x-direction |
---|
121 | c dx: step sizes in x-direction |
---|
122 | c cfl: CFL # g: Acceleration due to gravity |
---|
123 | c tf: final time |
---|
124 | c theta=1: MM1 limiter; =2: MM2 limiter; >2: UNO limiter. |
---|
125 | c u: initial cell averages of conservative variables. |
---|
126 | c Supply entries of u((md+1):(nx+md),mn) |
---|
127 | c OUTPUT u: cell averages at final time 'tf' |
---|
128 | c REMARK 1. Reset 'ndx' to adjust array dimensions. |
---|
129 | c 2. Padded to each side of the computational domain are |
---|
130 | c 'md' ghost cells, average values on which are |
---|
131 | c assigned by boundary conditions. |
---|
132 | c |
---|
133 | implicit none |
---|
134 | integer md,nxmax,nxd, mn |
---|
135 | parameter (md=3, nxmax=1601, nxd=nxmax+2*md, mn=2) |
---|
136 | real*8 u(nxd,mn), ux(nxd,mn) |
---|
137 | real*8 f(nxd,mn), fx(nxd,mn) |
---|
138 | real*8 v(nxd), du(nxd,2), df(nxd,2), dz(nxd,2), u2(nxd,2), |
---|
139 | . u3(nxd,2), h(nxd), z(nxd,2), hz(nxd) |
---|
140 | |
---|
141 | integer nx, nxx, io, i, isteps |
---|
142 | real*8 toll,cfl,theta,g,dx,dt,Tout,Tfinal,tc |
---|
143 | |
---|
144 | integer istop,iout,nt,ii,oi,i2,m |
---|
145 | real*8 dtmax, tf,a,b,xmin,t,xmic,Tleft,em_x,dtcdx2,dtcdx3 |
---|
146 | real*8 den,xmt,pre, Tnext, em_old |
---|
147 | real*8 aterm1 ,term1, aterm2 ,term2, aterm3 ,term3 |
---|
148 | c |
---|
149 | xmin(a,b) = 0.5d0*(dsign(1.d0,a) |
---|
150 | . + dsign(1.d0,b))*dmin1(dabs(a),dabs(b)) |
---|
151 | xmic(t,a,b) = xmin(t*xmin(a,b), 0.5d0*(a+b) ) |
---|
152 | c |
---|
153 | c---------------------------------------------------------- |
---|
154 | c |
---|
155 | em_old = 1.0d0 |
---|
156 | tc = 0.d0 |
---|
157 | istop = 0 |
---|
158 | c iplot = 100 |
---|
159 | isteps = 0 |
---|
160 | iout = 0 |
---|
161 | nt =0 |
---|
162 | Tleft = dmin1(Tout,tf) |
---|
163 | Tnext = dmin1(Tout,tf) |
---|
164 | dt = dmin1(dtmax,Tleft) |
---|
165 | nxx = nx + 2*md |
---|
166 | c |
---|
167 | do while (.true.) |
---|
168 | nt = nt+1 |
---|
169 | do ii = 1, 2 |
---|
170 | io=ii-1 |
---|
171 | oi = 1-io |
---|
172 | i2 = 3-ii |
---|
173 | c |
---|
174 | c Naive Boundary Conditions |
---|
175 | c |
---|
176 | do i = 1, md |
---|
177 | u(i,1) = 0.d0 |
---|
178 | u(nx+i,1) = 0.d0 |
---|
179 | u(i,2) = 0.d0 |
---|
180 | u(nx+i,2) = 0.d0 |
---|
181 | end do |
---|
182 | c |
---|
183 | c Compute f and maximum wave speeds 'em_x' |
---|
184 | c see (2.1) and (4.3) |
---|
185 | c |
---|
186 | call swflux(f,u,1,nxx,em_x,g,toll) |
---|
187 | c |
---|
188 | c Compute numerical derivatives 'ux', 'fx'. |
---|
189 | c see (3.1) and (4.1) |
---|
190 | c |
---|
191 | call derivative(u(1,1),ux(1,1),nxx,theta) |
---|
192 | call derivative(u(1,2),ux(1,2),nxx,theta) |
---|
193 | |
---|
194 | call derivative(f(1,1),fx(1,1),nxx,theta) |
---|
195 | call derivative(f(1,2),fx(1,2),nxx,theta) |
---|
196 | |
---|
197 | c |
---|
198 | c Compute time step size according to the input CFL # |
---|
199 | c |
---|
200 | if(ii.eq.1) then |
---|
201 | dt = dmin1(cfl*dx/em_x,dtmax,Tout) |
---|
202 | if( ( tc + 2.d0*dt ) .ge. Tnext ) then |
---|
203 | dt = 0.5d0*(Tnext - tc ) |
---|
204 | iout = 1 |
---|
205 | Tnext = Tnext+Tout |
---|
206 | end if |
---|
207 | if (Tnext.gt.tf ) then |
---|
208 | istop = 1 |
---|
209 | endif |
---|
210 | end if |
---|
211 | |
---|
212 | dtcdx2 = dt/dx/2.d0 |
---|
213 | dtcdx3 = dt/dx/3.d0 |
---|
214 | c |
---|
215 | c Compute the flux values of f at half time step, |
---|
216 | c the conservative values at the half and third time steps. |
---|
217 | c see (2.15) and (2.16). |
---|
218 | do i = 3, nxx-2 |
---|
219 | c Half time step |
---|
220 | u2(i,1) = u(i,1) - dtcdx2*fx(i,1) |
---|
221 | u2(i,2) = u(i,2) - dtcdx2*fx(i,2) |
---|
222 | c Third Step |
---|
223 | u3(i,1) = u(i,1) - dtcdx3*fx(i,1) |
---|
224 | u3(i,2) = u(i,2) - dtcdx3*fx(i,2) |
---|
225 | if(u3(i,1).lt.toll)then |
---|
226 | u3(i,1) = 0.d0 |
---|
227 | end if |
---|
228 | enddo |
---|
229 | |
---|
230 | call swflux(f,u2,3,nxx-2,em_x,g,toll) |
---|
231 | |
---|
232 | c |
---|
233 | c Compute the values of 'u' at the next time level. see (2.16). |
---|
234 | c Continuity equation |
---|
235 | m = 1 |
---|
236 | aterm1 = 0.0d0 |
---|
237 | aterm2 = 0.0d0 |
---|
238 | aterm3 = 0.0d0 |
---|
239 | |
---|
240 | do i = md + 1 - io, nx + md - io |
---|
241 | term1 = (0.250d0 * ( u(i,m) + u(i+1,m) ) |
---|
242 | . + 0.0625d0 * ( ux(i,m) - ux(i+1,m) ) |
---|
243 | . + dtcdx2 * ( f(i,m) - f(i+1,m) ) )*2.d0 |
---|
244 | v(i) = term1 |
---|
245 | aterm1 = dmax1(aterm1,abs(term1)) |
---|
246 | end do |
---|
247 | do i = md + 1, nx + md |
---|
248 | u(i,m) = v(i-io) |
---|
249 | end do |
---|
250 | |
---|
251 | c |
---|
252 | c Momentum equation |
---|
253 | m = mn |
---|
254 | |
---|
255 | do i = md + 1 - io, nx + md - io |
---|
256 | term2 = (0.250d0 * ( u(i,m) + u(i+1,m) ) |
---|
257 | . + 0.0625d0 * ( ux(i,m) - ux(i+1,m) ) |
---|
258 | . + dtcdx2 * ( f(i,m) - f(i+1,m) ) )*2.d0 |
---|
259 | v(i) = term2 |
---|
260 | aterm2 = dmax1(aterm2,abs(term2)) |
---|
261 | term3 = 0.5d0*dt*g*( u2(i,1)*dz(i,ii) + |
---|
262 | . u2(i+1,1)*dz(i+1,ii)) |
---|
263 | aterm3 = dmax1(aterm3,abs(term3)) |
---|
264 | v(i) = v(i) - term3 |
---|
265 | end do |
---|
266 | |
---|
267 | do i = md + 1, nx + md |
---|
268 | u(i,m) = v(i-io) |
---|
269 | c |
---|
270 | c Friction term |
---|
271 | c u(i,m) = u(i,m)*exp(-0.001d0*dt) |
---|
272 | end do |
---|
273 | c |
---|
274 | tc = tc + dt |
---|
275 | end do |
---|
276 | |
---|
277 | if(iout.eq.1) then |
---|
278 | call dump_solution(u,z,nx,tc,isteps) |
---|
279 | iout = 0 |
---|
280 | endif |
---|
281 | if(istop.eq.1) go to 1001 |
---|
282 | end do |
---|
283 | c |
---|
284 | 1001 write(*,*)isteps |
---|
285 | |
---|
286 | return |
---|
287 | |
---|
288 | end |
---|
289 | |
---|
290 | c=========================================================== |
---|
291 | c Shallow Water Flux |
---|
292 | c=========================================================== |
---|
293 | subroutine swflux(f,q,n0,n1,em_x,g,toll) |
---|
294 | implicit real*8 (a-h) |
---|
295 | implicit real*8 (o-z) |
---|
296 | parameter (md=3, nxmax=1601, nxd=nxmax+2*md, mn=2) |
---|
297 | real*8 f(nxd,mn),q(nxd,mn) |
---|
298 | integer n0,n1 |
---|
299 | |
---|
300 | |
---|
301 | em_x = 1.d-15 |
---|
302 | do i = n0,n1 |
---|
303 | h = q(i,1) |
---|
304 | uh = q(i,2) |
---|
305 | if(h.le.toll)then |
---|
306 | u = 0.d0 |
---|
307 | h = 0.0d0 |
---|
308 | uh = 0.0d0 |
---|
309 | else |
---|
310 | u = uh / h |
---|
311 | endif |
---|
312 | if (abs(u).gt.1.0d3) then |
---|
313 | u = dsign(1.0d0,u)*1.0d3 |
---|
314 | uh = u*h |
---|
315 | end if |
---|
316 | cvel = dsqrt( g*h ) |
---|
317 | em_x = dmax1( em_x, dabs(u) + cvel ) |
---|
318 | f(i,1) = uh |
---|
319 | f(i,2) = uh*u + 0.5d0*g*h**2 |
---|
320 | c q(i,1) = h |
---|
321 | c q(i,2) = uh |
---|
322 | enddo |
---|
323 | |
---|
324 | return |
---|
325 | end |
---|
326 | c=========================================================== |
---|
327 | c Calculate limited derivatives |
---|
328 | c=========================================================== |
---|
329 | subroutine derivative(q,qx,n,theta) |
---|
330 | implicit real*8 (a-h) |
---|
331 | implicit real*8 (o-z) |
---|
332 | |
---|
333 | parameter (md=3, nxmax=1601, nxd=nxmax+2*md, mn=2) |
---|
334 | real*8 dq(nxd,2) |
---|
335 | real*8 q(n),qx(n) |
---|
336 | |
---|
337 | xmin(a,b) = 0.5d0*(dsign(1.d0,a) |
---|
338 | . + dsign(1.d0,b))*dmin1(dabs(a),dabs(b)) |
---|
339 | xmic(z,a,b) = xmin(z*xmin(a,b), 0.5d0*(a+b) ) |
---|
340 | |
---|
341 | |
---|
342 | do i = 1,n-1 |
---|
343 | dq(i,1) = q(i+1) - q(i) |
---|
344 | end do |
---|
345 | do i = 1,n-2 |
---|
346 | dq(i,2) = dq(i+1,1) - dq(i,1) |
---|
347 | end do |
---|
348 | if( theta .lt. 2.5d0 ) then |
---|
349 | do i = 3,n-2 |
---|
350 | qx(i) = xmic( theta, dq(i-1,1), dq(i,1) ) |
---|
351 | end do |
---|
352 | else |
---|
353 | do i = 3,n-2 |
---|
354 | qx(i) = xmin(dq(i-1,1) |
---|
355 | . + 0.5d0*xmin(dq(i-2,2),dq(i-1,2)), |
---|
356 | . dq(i,1) - 0.5d0*xmin(dq(i-1,2),dq(i,2))) |
---|
357 | end do |
---|
358 | end if |
---|
359 | return |
---|
360 | end |
---|
361 | |
---|
362 | |
---|
363 | |
---|
364 | c=========================================================== |
---|
365 | c Output Routine |
---|
366 | c=========================================================== |
---|
367 | subroutine dump_solution(u,z,nx,tc,isteps) |
---|
368 | implicit real*8 (a-h) |
---|
369 | implicit real*8 (o-z) |
---|
370 | parameter (md=3, nxmax=1601, nxd=nxmax+2*md, mn=2) |
---|
371 | real*8 u(nxd,mn),z(nxd,2) |
---|
372 | |
---|
373 | write(12,*)tc |
---|
374 | io = 1 |
---|
375 | i = 2 |
---|
376 | isteps = isteps + 1 |
---|
377 | write(*,*)isteps, tc |
---|
378 | |
---|
379 | do i = 1, nx + 2*md |
---|
380 | write(13,200)u(i,1) |
---|
381 | write(14,200)u(i,2) |
---|
382 | write(11,200)z(i,io) + u(i,1) |
---|
383 | 200 format(e20.8) |
---|
384 | end do |
---|
385 | |
---|
386 | return |
---|
387 | end |
---|