|
| 1 | +import mesh.reconstruction as reconstruction |
| 2 | +import numpy as np |
| 3 | + |
| 4 | +def unsplit_fluxes(my_data, rp, dt, scalar_name): |
| 5 | + """ |
| 6 | + Construct the fluxes through the interfaces for the linear advection |
| 7 | + equation: |
| 8 | +
|
| 9 | + .. math:: |
| 10 | +
|
| 11 | + a_t + u a_x + v a_y = 0 |
| 12 | +
|
| 13 | + We use a second-order (piecewise linear) unsplit Godunov method |
| 14 | + (following Colella 1990). |
| 15 | +
|
| 16 | + In the pure advection case, there is no Riemann problem we need to |
| 17 | + solve -- we just simply do upwinding. So there is only one 'state' |
| 18 | + at each interface, and the zone the information comes from depends |
| 19 | + on the sign of the velocity. |
| 20 | +
|
| 21 | + Our convection is that the fluxes are going to be defined on the |
| 22 | + left edge of the computational zones:: |
| 23 | +
|
| 24 | + | | | | |
| 25 | + | | | | |
| 26 | + -+------+------+------+------+------+------+-- |
| 27 | + | i-1 | i | i+1 | |
| 28 | +
|
| 29 | + a_l,i a_r,i a_l,i+1 |
| 30 | +
|
| 31 | +
|
| 32 | + a_r,i and a_l,i+1 are computed using the information in |
| 33 | + zone i,j. |
| 34 | +
|
| 35 | + Parameters |
| 36 | + ---------- |
| 37 | + my_data : CellCenterData2d object |
| 38 | + The data object containing the grid and advective scalar that |
| 39 | + we are advecting. |
| 40 | + rp : RuntimeParameters object |
| 41 | + The runtime parameters for the simulation |
| 42 | + dt : float |
| 43 | + The timestep we are advancing through. |
| 44 | + scalar_name : str |
| 45 | + The name of the variable contained in my_data that we are |
| 46 | + advecting |
| 47 | +
|
| 48 | + Returns |
| 49 | + ------- |
| 50 | + out : ndarray, ndarray |
| 51 | + The fluxes on the x- and y-interfaces |
| 52 | +
|
| 53 | + """ |
| 54 | + |
| 55 | + myg = my_data.grid |
| 56 | + |
| 57 | + a = my_data.get_var(scalar_name) |
| 58 | + |
| 59 | + u = my_data.get_var("x-velocity") |
| 60 | + v = my_data.get_var("y-velocity") |
| 61 | + |
| 62 | + cx = myg.scratch_array() |
| 63 | + cy = myg.scratch_array() |
| 64 | + |
| 65 | + cx.v(buf=1)[:, :] = u.v(buf=1)*dt/myg.dx |
| 66 | + cy.v(buf=1)[:, :] = v.v(buf=1)*dt/myg.dy |
| 67 | + |
| 68 | + #-------------------------------------------------------------------------- |
| 69 | + # monotonized central differences |
| 70 | + #-------------------------------------------------------------------------- |
| 71 | + |
| 72 | + limiter = rp.get_param("advection.limiter") |
| 73 | + |
| 74 | + ldelta_ax = reconstruction.limit(a, myg, 1, limiter) |
| 75 | + ldelta_ay = reconstruction.limit(a, myg, 2, limiter) |
| 76 | + |
| 77 | + # x-direction |
| 78 | + a_x = myg.scratch_array() |
| 79 | + shift_x = my_data.get_var("x-shift").astype(int) |
| 80 | + |
| 81 | + for index,vel in np.ndenumerate(u.v(buf=1)): |
| 82 | + # upwind |
| 83 | + if vel < 0: |
| 84 | + a_x.v(buf=1)[index] = a.ip(shift_x.v(buf=1)[index], buf=1)[index] - \ |
| 85 | + 0.5*(1.0 + cx.v(buf=1)[index])* \ |
| 86 | + ldelta_ax.ip(shift_x.v(buf=1)[index], buf=1)[index] |
| 87 | + else: |
| 88 | + a_x.v(buf=1)[index] = a.ip(shift_x.v(buf=1)[index], buf=1)[index] + \ |
| 89 | + 0.5*(1.0 - cx.v(buf=1)[index])* \ |
| 90 | + ldelta_ax.ip(shift_x.v(buf=1)[index], buf=1)[index] |
| 91 | + |
| 92 | + # y-direction |
| 93 | + a_y = myg.scratch_array() |
| 94 | + shift_y = my_data.get_var("y-shift").astype(int) |
| 95 | + |
| 96 | + for index,vel in np.ndenumerate(v.v(buf=1)): |
| 97 | + # upwind |
| 98 | + if vel < 0: |
| 99 | + a_y.v(buf=1)[index] = a.jp(shift_y.v(buf=1)[index], buf=1)[index] - \ |
| 100 | + 0.5*(1.0 + cy.v(buf=1)[index])* \ |
| 101 | + ldelta_ay.jp(shift_y.v(buf=1)[index], buf=1)[index] |
| 102 | + else: |
| 103 | + a_y.v(buf=1)[index] = a.jp(shift_y.v(buf=1)[index], buf=1)[index] + \ |
| 104 | + 0.5*(1.0 - cy.v(buf=1)[index])* \ |
| 105 | + ldelta_ay.jp(shift_y.v(buf=1)[index], buf=1)[index] |
| 106 | + |
| 107 | + # compute the transverse flux differences. The flux is just (u a) |
| 108 | + # HOTF |
| 109 | + F_xt = u*a_x |
| 110 | + F_yt = v*a_y |
| 111 | + |
| 112 | + F_x = myg.scratch_array() |
| 113 | + F_y = myg.scratch_array() |
| 114 | + |
| 115 | + # the zone where we grab the transverse flux derivative from |
| 116 | + # depends on the sign of the advective velocity |
| 117 | + dtdx2 = 0.5*dt/myg.dx |
| 118 | + dtdy2 = 0.5*dt/myg.dy |
| 119 | + |
| 120 | + for index, vel in np.ndenumerate(u.v(buf=1)): |
| 121 | + F_x.v(buf=1)[index] = vel*(a_x.v(buf=1)[index] - |
| 122 | + dtdy2*(F_yt.ip_jp(shift_x.v(buf=1)[index], 1, buf=1)[index] - |
| 123 | + F_yt.ip(shift_x.v(buf=1)[index], buf=1)[index])) |
| 124 | + |
| 125 | + for index, vel in np.ndenumerate(v.v(buf=1)): |
| 126 | + F_y.v(buf=1)[index] = vel*(a_y.v(buf=1)[index] - |
| 127 | + dtdx2*(F_xt.ip_jp(1, shift_y.v(buf=1)[index], buf=1)[index] - |
| 128 | + F_xt.jp(shift_y.v(buf=1)[index], buf=1)[index])) |
| 129 | + return F_x, F_y |
| 130 | + |
0 commit comments