@@ -29,23 +29,23 @@ function do_computation(nsteps, ncells, tmax, ifirst, ilast, statelft, statergt,
29
29
# loop over timesteps
30
30
while istep < nsteps && t < tmax
31
31
# right boundary condition: outgoing wave
32
- for ic= ncells: lc
32
+ @unsafe for ic= ncells: lc
33
33
u[ic]= u[ncells- 1 ]
34
34
end
35
35
# left boundary condition: specified value
36
- for ic= fc: - 1
36
+ @unsafe for ic= fc: - 1
37
37
u[ic]= statelft
38
38
end
39
39
40
40
# upwind fluxes times dt (ie, flux time integral over cell side)
41
41
# assumes velocity > 0
42
42
vdt= velocity* dt
43
- for ie= ifirst: ilast+ 1
43
+ @unsafe for ie= ifirst: ilast+ 1
44
44
flux[ie]= vdt* u[ie- 1 ]
45
45
end
46
46
47
47
# conservative difference
48
- for ic= ifirst: ilast
48
+ @unsafe for ic= ifirst: ilast
49
49
u[ic] -= (flux[ic+ 1 ]- flux[ic]) / (x[ic+ 1 ]- x[ic])
50
50
end
51
51
@@ -98,27 +98,27 @@ function main()
98
98
99
99
# uniform mesh:
100
100
dx= (x_right- x_left)/ ncells
101
- for ie in ifirst: ilast+ 1
101
+ @unsafe for ie in ifirst: ilast+ 1
102
102
x[ie]= x_left+ ie* dx
103
103
end
104
104
105
105
# initial values for diffential equation:
106
106
ijump= max (ifirst- 1 ,min (convert (Int,round (ncells* (jump- x_left)/ (x_right- x_left))),ilast+ 1 ))
107
107
# left state to left of jump
108
- for ic= ifirst: ijump- 1
108
+ @unsafe for ic= ifirst: ijump- 1
109
109
u[ic]= statelft
110
110
end
111
111
# volume-weighted average in cell containing jump
112
112
frac= (jump- x_left- ijump* dx)/ (x_right- x_left)
113
113
u[ijump]= statelft* frac+ statergt* (1.0 - frac)
114
114
# right state to right of jump
115
- for ic= ijump+ 1 : ilast
115
+ @unsafe for ic= ijump+ 1 : ilast
116
116
u[ic]= statergt
117
117
end
118
118
119
119
# stable timestep (independent of time for linear advection):
120
120
mindx= 1.0e300
121
- for ic= ifirst: ilast
121
+ @unsafe for ic= ifirst: ilast
122
122
mindx= min (mindx,x[ic+ 1 ]- x[ic])
123
123
end
124
124
@@ -127,7 +127,7 @@ function main()
127
127
u = do_computation (nsteps, ncells, tmax, ifirst, ilast, statelft, statergt, velocity, dt, fc, lc, flux, x, u)
128
128
129
129
# write final results (plot later)
130
- for ic= 0 : ncells- 1
130
+ @unsafe for ic= 0 : ncells- 1
131
131
xc = (x[ic]+ x[ic+ 1 ])* 0.5
132
132
uc = u[ic]
133
133
# @printf("%e %e\n",xc,uc)
0 commit comments