two component incompressible flow in the headspace of a filter dryer

47
Two Component Incompressible Flow in the Headspace of a Filter Dryer MIE 604 - Term Project Aditya Dodda April 30, 2015 1

Upload: aditya

Post on 17-Dec-2015

220 views

Category:

Documents


4 download

DESCRIPTION

CFD to solve two species incompressible flow

TRANSCRIPT

  • Two Component Incompressible Flow

    in the Headspace of a Filter DryerMIE 604 - Term Project

    Aditya Dodda

    April 30, 2015

    1

  • Contents

    Nomenclature 3

    1 Problem statement 4

    2 Governing equations 5

    3 Numerical values for inputs 6

    4 Meshing 6

    5 Boundary conditions 7

    6 Numerical methods 7

    6.1 Navier-Stokes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    6.2 Vorticity and Stream Function . . . . . . . . . . . . . . . . . . . . . . . . . 10

    6.3 Species mass balance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

    7 Validation 11

    7.1 Navier-Stokes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

    7.2 mass balance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

    8 Grid dependency and computation cost 14

    9 Results 16

    9.1 Problem statement as is . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

    9.2 Problem statement with a minor modification . . . . . . . . . . . . . . . . 17

    10 Conclusion 17

    2

  • Nomenclature

    Dimensionless

    Dimensionless vorticity mass fraction of component 1 Dimensionless time Dimensionless stream function P Dimensionless pressure Pe Peclet number Re Reynolds number U Dimensionless velocity in x-direction V Dimensionless Velocity in y-direction X Dimensionless x Y Dimensionless y

    Subscripts

    i Index in y-direction j Index in x-direction

    Variables

    Viscosity Pa s Density kg/m3

    D Diffusion coefficient m2/s

    Lx Width of headspace m

    Ly Height of headspace m

    p Pressure Pa

    t time s

    u Velocity in x-direction m/s

    v Velocity in y-direction m/s

    v1 Inlet velocity of component 1 m/s

    v2 Inlet velocity of component 2 m/s

    v3 Outlet velocity m/s

    x x m

    y y m

    3

  • 1 Problem statement

    u = 0v = v2 = 0

    lpurge

    u = 0v = v3

    y= 0

    loutlet

    u = 0 , v = v1, = 1

    Lx

    Ly

    At all other boundariesu = 0v = 0

    z= 0

    P

    z= 0 at all boundaries

    z is thedirection perpendicular

    to the boundary

    Figure 1: Domain showing the boundary conditions.

    As seen in figure 1, in this problem there is component 1 that is entering at the bottom of

    the domain, denoted by a thick line, at a velocity of v1. The mass fraction of component

    1 is denoted by . Species 2 is entering from the dashed line section in the domain at

    a velocity of v2. As there are only two components, the mass fraction of component 2 is

    1 . The negative sign is used to denote the direction of velocity. A mixture of the twois exiting from the dotted line section at a velocity of v3. As the flow is incompressible,

    v1Lx + v2lpurge = v3loutlet.

    4

  • Initial conditions

    u(t, x) = 0, v(t, x) = 1, (t, x) = 0

    2 Governing equations

    u

    t+u2

    x+uv

    y= 1

    p

    x+

    1

    O2u (1)

    v

    t+uv

    x+v2

    y= 1

    p

    y+

    1

    O2v (2)

    t+ u

    x+ v

    y= DO2 (3)

    Scaled and dimensionless form of equations

    U =u

    v3, V =

    uv

    v3, P =

    p

    v23, =

    tLxv3, s =

    LxLy, Re =

    Lxv3

    , Pe =

    v3LxD

    U

    +U2

    X+ s

    UV

    Y= P

    X+

    1

    Re

    (2U

    X2+ s2

    2U

    Y 2

    )(4)

    V

    +UV

    X+ s

    V 2

    Y= P

    Y+

    1

    Re

    (2V

    X2+ s2

    2V

    Y 2

    )(5)

    + U

    X+ sV

    Y=

    1

    Pe

    (2

    X2+ s2

    2

    Y 2

    )(6)

    Divergence in scaled form

    U

    X+ s

    V

    Y= 0

    5

  • 3 Numerical values for inputs

    Most inputs are provided to replicate the values seen in experiments. For parameters that

    are not known via experiments simple existing models are used.

    From experiment,

    v3 = 0.06 m/s, Lx = 0.08 m, Ly = 0.16m

    From wolframalpha,

    = 0.05 kg/m3, = 2 105 Pa s

    Diffusion coefficient D = 1 105 m2/s using elementary theory of diffusion coefficient ingases.

    From these,

    Re = 12, P e = 480, s = 0.5

    4 Meshing

    The meshing is over a square domain of sides with length unit 1. This is possible as s takes

    care of the stretching in the y direction. lpurge and loutlet are both 0.1 units.

    A uniform mesh is used in this problem. To capture the boundary values correctly, the

    minimum grid spacing dX = dY = 0.1. Consequently, halving the value of dX also captures

    the boundary values accurately. This process can be repeated till the desired fineness is

    achieved.

    All the values are at cell centers and the cell is the same for U, V, P & .

    Index i & j represent the y & x directions, respectively.

    6

  • 5 Boundary conditions

    The boundary conditions are extracted from an excel file. The can handle Neumann and

    Dirichlet boundary conditions.

    Dirichlet

    Suppose the boundary condition is u(t, x = 0, y) = 1.2. Then the excel file would have 0

    for the type of boundary condition and 1.2 for the value.

    When solving the equations, x = 0 corresponds to j = 1/2. When face values are calculated

    for advection, the Dirichlet condition is directly used. However, for diffusion calculations,

    value at i, j = 0 are necessary. This a ghost point.

    Therefore, ui,0 = 2ui,1/2 ui,1 where, ui,1/2 comes directly from the boundary condition.

    Neumann

    Suppose the boundary condition isu

    x(t, x = 0, y) = 2.3. Then the excel file would have 1

    for the type of boundary condition and 2.3 for the value.

    Unlike the case of Dirichlet condition, ui,0 is easily obtained as ui,1 2.3 dx. Then ui,1/2is calculated as

    ui,0 + ui,12

    .

    6 Numerical methods

    6.1 Navier-Stokes

    The Navier-Stokes equations (4 and 5) are solved in a similar manner as they are of similar

    form.

    7

  • Advection

    The advection terms are solved using TVD with superbee as the flux limiter. The can take

    in other forms of flux limiters as well. Two flux limiters tested for advection were minmod

    and superbee. Of these, superbee performed a little better.

    U

    = U

    2

    X sUV

    Y(7)

    U2

    X=

    U2i,j+1/2 U2i,j1/2dX

    (8)

    U2i,j+1/2 = Ui,j+1/2[UUWi,j+1/2

    (ri,j+1/2

    ) (UUWi,j+1/2 Ui,j+1/2

    )](9)

    UUWi,j+1/2 =

    Ui,j, if Ui,j+1/2 0

    Ui,j+1, if Ui,j+1/2 < 0

    (10)

    ri,j+1/2 =Ui,j Ui,j1Ui,j+1 Ui,j (11)

    (r) = max(0,min (1, 2r) ,min (2, r)) (12)

    Similar procedure is used for UVY

    . All these calculations are done for interior faces in the

    domain. The flux at faces on the boundary are evaluated from boundary conditions.

    Analogous algorithm is used for the advection terms in eq 5.

    The code for this is in advection navier stokes tvd.m.

    Diffusion

    The output of the advection solver is fed to the diffusion solver (diffusion solver.m).

    The diffusion terms were calculated using the ADI algorithm for Crank-Nicolson method.

    Tridiagonal matrix algorithm was used in the process of solving matrices. (This implementation

    is identical to that used in the homework assignments.)

    8

  • U Ud

    =1

    2Re

    (2U

    X2+2U

    Y 2

    )

    U Ud

    =1

    2Re

    (2U

    X2+2U

    Y 2

    )Analogous steps for V

    Pressure solver (2P

    X2+ s2

    2P

    Y 2

    )=

    1

    d

    (U

    X+ s

    V

    Y

    )

    U

    X=Ui,j+1/2 Ui,j1/2

    dX

    V

    Y=V i+1/2,j V i1/2,j

    dY

    Conjugate gradient method is used to solve the pressure equation. The code corresponding

    to this section is in pressure solver.m.

    Pressure correction

    Un+1 = U dt PX

    V n+1 = V s dtPY

    P

    X=Pi,j+1/2 Pi,j1/2

    dX

    P

    Y=Pi+1/2,j Pi1/2,j

    dY

    9

  • 6.2 Vorticity and Stream Function

    Vorticity and the stream function are solved for using Un+1. The code for this is in

    vorticity.m and stream function.m.

    =V

    X sU

    Y(2

    X2+ s2

    2

    Y 2

    )=

    6.3 Species mass balance

    Advection

    = U

    X sV

    Y(13)

    i,j+1/2 =[UWi,j+1/2

    (ri,j+1/2

    ) (UWi,j+1/2 i,j+1/2

    )](14)

    UWi,j+1/2 =

    i,j, if U

    n+1i,j+1/2 0

    i,j+1, if Un+1i,j+1/2 < 0

    (15)

    ri,j+1/2 =i,j i,j1i,j+1 i,j (16)

    (r) = max(0,min (1, 2r) ,min (2, r)) (17)

    U

    X= Un+1i,j

    i,j+1/2 i,j1/2dX

    (18)

    Diffusion

    =

    1

    Pe

    (2

    X2+ s2

    2

    Y 2

    )This is identical to the diffusion part of the Navier-Stokes equation. The same function

    (diffusion solver.m) is used to solve the diffusion portion by passing the appropriate coefficients

    to the solver.

    10

  • 7 Validation

    7.1 Navier-Stokes

    The code was validated for a a lid-driven cavity problem in an unit square for Re = 20.

    The output was matched to the output of the code mentioned in http://math.mit.edu/

    ~stoopn/18.086/code/mit18086_navierstokes.pdf.

    X0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

    U

    -0.25

    -0.2

    -0.15

    -0.1

    -0.05

    0 Re = 20, N = 40, CFL = 0.8

    SourceMy code

    Y0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

    V

    -0.01

    0

    0.01

    0.02

    0.03SourceMy code

    Figure 2: Validation of Navier-Stokes solver by comparing to output from code providedin the link mentioned. Re = 20 with 40 x 40 grid. U and V ar plotted at Y = 0.5 and X= 0.5, respectively.

    11

  • 7.2 mass balance

    Advection

    To validate the advection of in x and y directions, the boundary conditions were set

    to mimic a case of step wave in each of the directions respectively. As seen in figure 3,

    the numerical solution matches the analytical solution very well (RMS error = 0.08). The

    error is reduced with further discretization. Also, in case of the problem being dealt with,

    the presence of diffusion will reduce the need to have a very high level of discretization to

    capture a wave front accurately.

    The governing equation for the case of x-direction,

    = U

    X

    V (,X, Y ) = 0, U(,X, Y ) = 1

    x

    0 0.2 0.4 0.6 0.8 1

    0

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1t = 0.31667, rms = 0.079057

    AnalyticalNumerical

    (a) Validation of advection of inx-direction

    y0 0.2 0.4 0.6 0.8 1

    0

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1t = 0.31667, rms = 0.079057

    AnalyticalNumerical

    (b) Validation of advection of iny-direction

    Figure 3: Validation of advection of

    12

  • Diffusion

    For validating diffusion of , the following problem was setup. Only the validation in

    x-direction is discussed here. The validation is y-direction is identical. s = 1 in both cases.

    ( = 0, X, Y ) = sin(X), (,X = 0, Y ) = 0, (,X = 1, Y ) = 0,

    Y(,X, Y = 0) = 0,

    Y(,X, Y = 1) = 0

    V (,X, Y ) = 0, U(,X, Y ) = 0

    x

    0 0.2 0.4 0.6 0.8 1

    0

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1t = 0.48, rms = 8.3849e-05

    AnalyticalNumerical

    (a) Validation of diffusion of in thex-direction

    y0 0.2 0.4 0.6 0.8 1

    0

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1t = 0.48, rms = 8.3849e-05

    AnalyticalNumerical

    (b) Validation of diffusion of in they-direction

    Figure 4: Validation of diffusion of

    The governing equation is,

    = 4

    The solution to this problem is,

    (,X, Y ) = exp(pi2) sin(piX)

    13

  • As seen in figure 4, there is a very good (RMS error = 8.4e-5) agreement between the

    analytical and numerical solution.

    8 Grid dependency and computation cost

    Y0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

    (X

    =0.5,

    Y)

    0

    0.2

    0.4

    0.6

    0.8

    1

    0.10.050.0250.0125

    X0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

    (X

    ,Y=0

    .5)

    0

    0.2

    0.4

    0.6

    0.8

    1

    0.10.050.0250.0125

    Figure 5: Grid dependency of solution. The plot legends show the grid spacing in eachcase. CFL = 1.5 was used without stability issues.

    14

  • Table 1: Details of grid dependency test results

    dXdA Simulation time (s) 1

    N

    (X = 0.5, Y ) 1

    N

    (X, Y = 0.5)

    0.1 0.7152 0.8635 0.8301 0.80310.05 0.7230 3.0642 0.8335 0.8054

    0.025 0.7206 15.5306 0.8293 0.80280.0125 0.7178 221.3552 0.8265 0.7999

    To look into grid dependency, the problem statement was solved at dX = 0.1, 0.05, 0.025

    and 0.0125. This translates to 10x10, 20x20, 40x40 and 80x80 grid point mesh. After

    solving, (X = 0.5, Y ) & (X, Y = 0.5) were plotted. These plots are shown in figure 5.

    4 5 6 7 8 9-2

    0

    2

    4

    6

    8

    10

    12

    14

    16

    18log(t) vs. log(N2)Reference line: Slope = 2

    Figure 6: Log plot of simulation time vs number of grid points N2

    In table 1, the first column is the grid spacing. The second column, gives the sum of in

    the domain. The third column is the time taken for simulating 20 s of real time. Columns

    4 and 5 correspond to plots in figure 5. They give the average represented by the lines.

    15

  • From figure 6, it is clear that the log of simulation time increase linearly with number of

    grid points initially and then moves to a slope = 2. Most the computation time is taken up

    in solving the Laplace equation for pressure using conjugate gradient method. The second

    highest time consuming routine is the tridiagonal matrix algorithm. The reason for this is

    due to shear number of calls made to the function as the diffusion part needs to be solved

    thrice, once each for U, V & .

    From the mean value of (X = 0.5, Y ) & (X, Y = 0.5) shown in table 1, it is easy to

    conclude that the benefit of increasing fineness of the grid is lost after dX = 0.025. For

    this reason, the results in the next section will correspond to dX = 0.025.

    9 Results

    9.1 Problem statement as is

    As the Re is much smaller than Pe, the velocity field reaches steady state much faster than

    .

    From figures 7, 8, 9, 10 and 11 (look in appendix) component 1 almost completely fills

    up the headspace in 60 seconds. This is very much of interest as drying is a very slow

    process. The fact that the headspace fills up so fast would mean that the data from the

    mass spectrometer is reasonably reliable. From, experiments the mass spectrometer takes

    about 30 seconds to start reading component 1 after the boiling is visible. This about what

    is seen from the simulations. The t in the titles of the images is real time.

    16

  • 9.2 Problem statement with a minor modification

    The only difference in this section is that at t = 30 s, at Y = 0 will cease to enter the

    domain. This means (,X, Y = 0) = 0. In addition, v1 = 0 and v3 = v2.

    From figures 12, 13, 14, 15 and 16 (look in appendix) after t = 30 s, it takes a long

    time to purge the headspace of component 1. This is in agreement with what is observed

    experimentally.

    10 Conclusion

    The code is robust and simulate the experiment procedure. There is definite qualitative

    match between the model results and experiments. The implementation is robust enough

    to capture changes in boundary conditions.

    17

  • Appendix

    Figures for problem statement

    U, t: 0.1

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.5

    1

    1.5V, t: 0.1

    0 0.5 10

    0.5

    1

    1.5

    2

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    P, t: 0.1

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    5

    10

    15

    20

    25

    30

    35

    0

    0

    0.10.2

    , t: 0.1

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.2

    0.4

    0.6

    0.8

    1

    , t: 0.1

    0 0.5 10

    0.5

    1

    1.5

    2

    -0.03

    -0.02

    -0.01

    0

    0.01

    0.02

    0.03

    Figure 7: Solution at t = 0.1

    18

  • U, t: 15

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.5

    1

    1.5V, t: 15

    0 0.5 10

    0.5

    1

    1.5

    2

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    P, t: 15

    0 0.5 10

    0.5

    1

    1.5

    2

    -1

    -0.8

    -0.6

    -0.4

    -0.2

    00.10.20.30.40.50.60.70.80.90.950.99

    , t: 15

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.2

    0.4

    0.6

    0.8

    1

    , t: 15

    0 0.5 10

    0.5

    1

    1.5

    210-3

    -10

    -5

    0

    5

    Figure 8: Solution at t = 15

    19

  • U, t: 30

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.5

    1

    1.5V, t: 30

    0 0.5 10

    0.5

    1

    1.5

    2

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    P, t: 30

    0 0.5 10

    0.5

    1

    1.5

    2

    -1

    -0.8

    -0.6

    -0.4

    -0.2

    00.20.30.40.50.60.7

    0.80.8

    0.90.9

    0.950.99

    , t: 30

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.2

    0.4

    0.6

    0.8

    1

    , t: 30

    0 0.5 10

    0.5

    1

    1.5

    210-3

    -10

    -5

    0

    5

    Figure 9: Solution at t = 30

    20

  • U, t: 45

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.5

    1

    1.5V, t: 45

    0 0.5 10

    0.5

    1

    1.5

    2

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    P, t: 45

    0 0.5 10

    0.5

    1

    1.5

    2

    -1

    -0.8

    -0.6

    -0.4

    -0.2

    00.50.60.70.80.90.9

    50.99

    , t: 45

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.2

    0.4

    0.6

    0.8

    1

    , t: 45

    0 0.5 10

    0.5

    1

    1.5

    210-3

    -10

    -5

    0

    5

    Figure 10: Solution at t = 45

    21

  • U, t: 60

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.5

    1

    1.5V, t: 60

    0 0.5 10

    0.5

    1

    1.5

    2

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    P, t: 60

    0 0.5 10

    0.5

    1

    1.5

    2

    -1

    -0.8

    -0.6

    -0.4

    -0.2

    00.70.80.90.950.9

    9

    , t: 60

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.2

    0.4

    0.6

    0.8

    1

    , t: 60

    0 0.5 10

    0.5

    1

    1.5

    210-3

    -10

    -5

    0

    5

    Figure 11: Solution at t = 60

    22

  • Figures for modified problem statement

    U, t: 0.1

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.5

    1

    1.5V, t: 0.1

    0 0.5 10

    0.5

    1

    1.5

    2

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    P, t: 0.1

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    5

    10

    15

    20

    25

    30

    35

    0

    0

    0.10.2

    , t: 0.1

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.2

    0.4

    0.6

    0.8

    1

    , t: 0.1

    0 0.5 10

    0.5

    1

    1.5

    2

    -0.03

    -0.02

    -0.01

    0

    0.01

    0.02

    0.03

    Figure 12: Solution at t = 0.1

    23

  • U, t: 15

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.5

    1

    1.5V, t: 15

    0 0.5 10

    0.5

    1

    1.5

    2

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    P, t: 15

    0 0.5 10

    0.5

    1

    1.5

    2

    -1

    -0.8

    -0.6

    -0.4

    -0.2

    00.10.20.30.40.50.60.70.80.90.950.99

    , t: 15

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.2

    0.4

    0.6

    0.8

    1

    , t: 15

    0 0.5 10

    0.5

    1

    1.5

    210-3

    -10

    -5

    0

    5

    Figure 13: Solution at t = 15

    24

  • U, t: 30

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.5

    1

    1.5V, t: 30

    0 0.5 10

    0.5

    1

    1.5

    2

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    P, t: 30

    0 0.5 10

    0.5

    1

    1.5

    2

    -1

    -0.8

    -0.6

    -0.4

    -0.2

    00.20.30.40.50.60.7

    0.80.8

    0.90.9

    0.950.99

    , t: 30

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.2

    0.4

    0.6

    0.8

    1

    , t: 30

    0 0.5 10

    0.5

    1

    1.5

    210-3

    -10

    -5

    0

    5

    Figure 14: Solution at t = 30

    25

  • U, t: 45

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.5

    1

    1.5V, t: 45

    0 0.5 10

    0.5

    1

    1.5

    2

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    P, t: 45

    0 0.5 10

    0.5

    1

    1.5

    210-4

    -6

    -4

    -2

    0

    2

    4

    6

    0.40.50.60.70.8

    0.90.95

    0.99

    , t: 45

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.2

    0.4

    0.6

    0.8

    1

    , t: 45

    0 0.5 10

    0.5

    1

    1.5

    210-6

    -20

    -15

    -10

    -5

    0

    5

    Figure 15: Solution at t = 45

    26

  • U, t: 60

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.5

    1

    1.5V, t: 60

    0 0.5 10

    0.5

    1

    1.5

    2

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    P, t: 60

    0 0.5 10

    0.5

    1

    1.5

    210-4

    -6

    -4

    -2

    0

    2

    4

    6

    0.40.50.6 0.70.8

    0.9

    0.95

    0.99

    , t: 60

    0 0.5 10

    0.5

    1

    1.5

    2

    0

    0.2

    0.4

    0.6

    0.8

    1

    , t: 60

    0 0.5 10

    0.5

    1

    1.5

    210-6

    -20

    -15

    -10

    -5

    0

    5

    Figure 16: Solution at t = 60

    27

  • main.m

    %clear; %close all; clc;

    %% Collecting boundariesfilename = 'boundaries actual.xlsx';% filename = 'boundaries.xlsx';sheets = {'u','v','phi'};

    sides = {'north', 'east','south','west'};

    Bound = boundaries(filename, sheets, sides);for gridSep = 0.025%[0.1 0.05 0.025 0.0125]

    %% Gridx edge = (0:gridSep:1)';y edge = x edge;dx = diff(x edge);dy = diff(y edge);

    x = (x edge(2:end) + x edge(1:end1))/2;y = (y edge(2:end) + y edge(1:end1))/2;

    [X,Y] = meshgrid(x,y);[dX,dY] = meshgrid(dx,dy);

    Ny = size(X,1);Nx = size(X,2);

    s = 0.5;% s = Lx/Ly

    %% Boundary values for solvingBoundVals = boundary values(Bound,sheets,sides,x,y,Nx,Ny);

    %%CFL = 1.5;

    COMPUTE STREAM FUNCTION = 1;VISUALIZE = 1;TYPE = 'superbee';COMPARE DISCRETIZATION = 0;

    [maxV, minV] = maximum velocity(BoundVals);

    D = 1e5;Lx = 0.08;rho = 0.05;mu = 2e5;

    28

  • vOut = 6e2;tfReal = 60;

    % InitializePhi = 0.0*ones(size(X));U = 0.0*ones(size(X));V = 1.0*ones(size(X));Ap = matrix poisson eqn(dX(1,1),dY(1,1),Nx,Ny,s);A sparse = sparse(Ap);

    if abs(maxV) > 2*eps && D > 0

    Pe = vOut*Lx/D;Re = (Lx*vOut*rho)/mu;tau = Lx/vOut;

    dt = CFL*dx(1)/abs(maxV);

    g = (1/Pe)*(dt/2);gu = (1/Re)*(dt/2);gv = (1/Re)*(dt/2);

    tf = tfReal/tau;

    NS COMPUTE = 1;Phi COMPUTE = 1;Phi ADVECTION = 1;ADVECTION = 1;

    elseif D > 0

    tau = Lx2/D;

    tf = tfReal/tau;dt = tf/100;

    g = 1*(dt/2);

    NS COMPUTE = 0;Phi COMPUTE = 1;Phi ADVECTION = 0;ADVECTION = 0;

    elseif D

  • g = 0;

    NS COMPUTE = 0;Phi COMPUTE = 1;Phi ADVECTION = 1;ADVECTION = 1;

    end

    Nt = floor(tf/dt)+1;Ntsim = Nt;

    plotSteps = 20;tmat = 0:tf/plotSteps:tf;timePoints = interp1(dt*(0:Ntsim),1:Ntsim+1,tmat,'nearest');timePoints = unique(timePoints);timePoints = timePoints(isnan(timePoints));

    %% Grid point coefficients for diffusion dsolver[dxIn,dxMid,dxOut,dyIn,dyMid,dyOut] = ...

    grid spacing matrixes(dX,dY,Nx,Ny);

    %% Solving

    Ustore = cell(Ntsim+1,1);Vstore = cell(Ntsim+1,1);Pstore = cell(Ntsim+1,1);Phistore = cell(Ntsim+1,1);

    U0 = U;V0 = V;Phi0 = Phi;

    Ustore{1} = U0;Vstore{1} = V0;Phistore{1} = Phi;Pstore{1} = zeros(size(X));

    endPoint = Ntsim;

    normCheckUV = 0;normCheckPhi = 0;changeBC = 0;startTime = tic;for ii = 1:Ntsim

    storeIndx = ii+1;% Solution for NavierStokesif NS COMPUTE == 1

    % TVD Advectionif ADVECTION > 0

    if ii == 1

    30

  • U n = U;V n = V;

    elseif ii == 2U n = Ustore{storeIndx1};V n = Vstore{storeIndx1};

    elseU n = Ustore{storeIndx1};V n = Vstore{storeIndx1};

    end[Us, Vs] = advection navier stokes tvd(U n,V n, ...

    dX,dY,dt,BoundVals,s,TYPE);else

    %If no advectionUs = U0;Vs = V0;

    end

    % Implicit DiffusionUss = diffusion solver(Us,gu,gu*s2,dy,dx, ...

    BoundVals.u.Xb,BoundVals.u.Yb, ...dxIn,dxMid,dxOut,dyIn,dyMid,dyOut);

    Vss = diffusion solver(Vs,gv,gv*s2,dy,dx,...BoundVals.v.Xb,BoundVals.v.Yb, ...dxIn,dxMid,dxOut,dyIn,dyMid,dyOut);

    % Poisson equation[P, B] = pressure solver(A sparse,Uss,Vss,dt,Nx,Ny, ...

    dX,dY,BoundVals,s);

    if mod(ii,20)clcdisp(['Time: ',num2str(ii*dt*tau),' s'])disp(['Simulation time: ',num2str(toc(startTime)),' s']);disp(['Divergence check: ',num2str(sum(B(:))/(Nx*Ny))])

    end

    % Pressure correction[Usss, Vsss] = pressure correction(P,Uss,Vss,dX,dY,dt,Nx,Ny,s);

    Unorm = norm(Usss U0)/(Nx*Ny);Vnorm = norm(Vsss V0)/(Nx*Ny);

    Ustore{storeIndx} = Usss;Vstore{storeIndx} = Vsss;Pstore{storeIndx} = P;

    U0 = Ustore{storeIndx};V0 = Vstore{storeIndx};

    if sum(abs(Unorm)/maxV) < 1e6 && sum(abs(Vnorm)/maxV) < 1e6normCheckUV = 1;

    31

  • elsenormCheckUV = 0;

    endend

    % Solution for phiif Phi COMPUTE == 1

    if Phi ADVECTION == 1Phis = advection phi(Phi0,dX,dY,dt,BoundVals,U0,V0,s,TYPE);

    elsePhis = Phi0;

    end

    [Phiss, Phiint] = ...diffusion solver(Phis,g,g*s2,dy,dx, ...BoundVals.phi.Xb,BoundVals.phi.Yb, ...dxIn,dxMid,dxOut,dyIn,dyMid,dyOut);

    Phistore{ii} = Phiss;

    phinorm = norm(Phiss Phi0)/(Nx*Ny);

    Phi0 = Phistore{ii};

    if sum(abs(phinorm)) < 1e6normCheckPhi = 1;

    elsenormcheckPhi = 0;

    end

    if changeBC == 0 && ii*dt*tau > 30BoundVals.phi.Yb(:,4) = 0;BoundVals.phi.Yb(:,3) = 1;

    BoundVals.v.Yb(:,4) = 0;BoundVals.v.Yb(BoundVals.v.Yb(:,2) > 0,2) = abs(min(BoundVals.v.Yb(:,2)));

    changeBC = 1;end

    end

    if normCheckUV ==1 && normCheckPhi == 1%endPoint = ii;disp(['Simulation stopped at ', ...

    num2str(dt*ii*tau),' seconds as tolerance was met.'])break;

    end

    32

  • endcomputetime = toc(startTime);disp(['Time to solve: ',num2str(computetime)])

    if NS COMPUTE == 1disp(['Pe: ',num2str(Pe)])disp(['Re: ',num2str(Re)])

    end%%

    if COMPUTE STREAM FUNCTION == 1 && NS COMPUTE == 1Asf = matrix stream function(dX(1,1),dY(1,1),Nx,Ny,s);Asf sparse = sparse(Asf);vorticityStore = cell(Ntsim,1);streamFunction = cell(Ntsim,1);divergence = cell(Ntsim,1);streamStarttime = tic;for ii = 1:endPoint

    [vortTmp, Ux, Uy, Vx, Vy] = ...vorticity(Ustore{ii},Vstore{ii},dX,dY,BoundVals,s);

    SFtmp = stream function(Asf sparse,vortTmp,Nx,Ny);vorticityStore{ii} = vortTmp;streamFunction{ii} = SFtmp;divergence{ii} = Ux+Vy;

    endstreamStoptime = toc(streamStarttime);disp(['Time to compute stream function : ', ...

    num2str(streamStoptime)])end

    %% Visualization

    if VISUALIZE == 1h = figure(1);set(h,'Position',[400 100 1400 800])for ii = [2 300 600 900 1200]%[timePoints(timePoints < endPoint) endPoint]

    colormap grayif NS COMPUTE == 1

    subplot(2,3,1)contour(X,Y/s,Ustore{ii}, ...

    maxV:2*maxV/10:maxV)caxis([0.3 1.5])title(['U, t: ',num2str(dt*ii*tau)])axis equalxlim([0 1])ylim([0 1]/s)colorbardrawnow

    33

  • subplot(2,3,2)contour(X,Y/s,Vstore{ii}, ...

    maxV:2*maxV/10:maxV)caxis([0.3 1.1])title(['V, t: ',num2str(dt*ii*tau)])axis equalxlim([0 1])ylim([0 1]/s)colorbardrawnow

    subplot(2,3,4)contour(X,Y/s,Pstore{ii})title(['P, t: ',num2str(dt*ii*tau)])axis equalxlim([0 1])ylim([0 1]/s)colorbardrawnow

    end

    %if Phi COMPUTE ==1

    subplot(2,3,5)contour(X,Y/s,Phistore{ii},[0.1:0.1:0.9 0.95 0.99 1], ...

    'Showtext','on')zlim([0.1 1.1])caxis([0.01 1.01])title(['\phi, t: ',num2str(dt*ii*tau)])axis equalxlim([0 1])ylim([0 1]/s)colorbardrawnow

    end

    if COMPUTE STREAM FUNCTION == 1 && NS COMPUTE == 1subplot(2,3,3)contour(X,Y/s,streamFunction{ii},20)title(['\xi, t: ',num2str(dt*ii*tau)])axis equalxlim([0 1])ylim([0 1]/s)colorbardrawnow

    end

    saveas(h, ...['solution mod ',strrep(num2str(dt*ii*tau),'.',' ')],'fig')

    saveas(h, ...['solution mod ',strrep(num2str(dt*ii*tau),'.',' ')],'epsc')

    34

  • end

    % close(h)end

    %%

    if COMPARE DISCRETIZATION == 1figure(100)

    subplot(2,1,1)hold onplot(y,mean(Phistore{endPoint}(:,[Nx Nx+2]/2),2))ylim([0 1])

    subplot(2,1,2)hold onplot(x,mean(Phistore{endPoint}([Ny Ny+2]/2,:)))ylim([0 1])

    end

    %%fileSave = ['GridSep',strrep(num2str(gridSep),'.',' '), ...

    ' ',strrep(char(datetime),':',' ')];save(fileSave)

    end%% End

    diffusion solver.m

    function [Unew, Uint] = diffusion solver(U,gx,gy,dy,dx,Xb,Yb, ...dxIn,dxMid,dxOut,dyIn,dyMid,dyOut)

    ny = size(U,1);nx = size(U,2);

    Us = U;

    U i j = U;U endp1 j = ((2*Yb(:,1)1)'.*U(end,:))+ ...

    (Yb(:,1)'*(dy(end) 2) + 2).*Yb(:,2)';U ip1 j = [U(2:end, :); U endp1 j];U 0 j = ((2*Yb(:,3)1)'.*U(1,:))+ ...

    (Yb(:,3)'*(dy(1) 2) + 2).*Yb(:,4)';U im1 j = [U 0 j; U(1:end1,:)];

    RHSmat explicit y = gy*dyOut.*U ip1 j + ...(1gy*dyMid).*U i j + gy*dyIn.*U im1 j;

    35

  • for ii = 1:ny % solving for Us corresponding to each block using TDMAa = gx*dxOut(ii,2:end)';b = (1+gx*dxMid(ii,1:end))';b(1) = b(1) gx*dxIn(ii,1)*(2*Xb(ii,3) 1);b(end) = b(end) gx*dxOut(ii,end)*(2*Xb(ii,1) 1);c = gx*dxIn(ii,1:end1)';d = RHSmat explicit y(ii,1:nx)';d(1) = d(1) + gx*dxIn(ii,1)*((dx(1) 2)*Xb(ii,3) + 2)*Xb(ii,4);d(end) = d(end) + gx*dxOut(ii,end)*((dx(end) 2)*Xb(ii,1) + 2)*Xb(ii,2);Us(ii,1:nx) = tdma(a,b,c,d);

    end

    Uint = Us;U = Us;

    U i j = U;U i endp1 = ((2*Xb(:,1)1).*U(:,end)) + ...

    (Xb(:,1)*(dx(end) 2) + 2).*Xb(:,2);U i jp1 = [U(:,2:end) U i endp1];U i 0 = ((2*Xb(:,3)1).*U(:,1)) + ...

    (Xb(:,3)*(dx(1) 2) + 2).*Xb(:,4);U i jm1 = [U i 0 U(:,1:end1)];

    RHSmat explicit x = gx*dxOut.*U i jp1 + ...(1gx*dxMid).*U i j + gx*dxIn.*U i jm1;

    for jj = 1:nxa = gy*dyOut(2:end,jj);b = (1+gy*dyMid(1:end,jj));b(1) = b(1) gy*dyIn(1,jj)*(2*Yb(jj,3) 1);b(end) = b(end) gy*dyOut(end,jj)*(2*Yb(jj,1) 1);c = gy*dyIn(1:end1,jj);d = RHSmat explicit x(1:ny,jj);d(1) = d(1) + gy*dyIn(1,jj)*((dy(1) 2)*Yb(jj,3) + 2)*Yb(jj,4);d(end) = d(end) + gy*dyOut(end,jj)*((dy(end) 2)*Yb(jj,1) + 2)*Yb(jj,2);Us(1:ny,jj) = tdma(a,b,c,d);

    end

    Unew = Us;

    end

    advection navier stokes tvd.m

    function [Us, Vs] = advection navier stokes tvd(U,V, ...dX,dY,dt,BoundVals,s,type)

    u = BoundVals.u;v = BoundVals.v;

    36

  • [,,Ubottom,Uleft] = Uedges(u,U,dX,dY);Umodx = [Uleft U];Umody = [Ubottom; U];

    [,,Vbottom,Vleft] = Uedges(v,V,dX,dY);Vmodx = [Vleft V];Vmody = [Vbottom; V];

    [, , Umidx, Umidy] = gradient vel(U,dX,dY,u);[, , Vmidx, Vmidy] = gradient vel(V,dX,dY,v);

    % U

    bUx = sign(Umidx(:,2:end1)) >= 0;UxUpwind = (bUx.*U(:,1:end1) + (1bUx).*U(:,2:end));

    rUx = (Umodx(:,2:end1) Umodx(:,1:end2))./ ...(Umodx(:,3:end) Umodx(:,2:end1));

    psiUx = fluxLimiter(rUx,type);

    bUy = sign(Vmidy(2:end1,:)) >= 0;UyUpwind = (bUy.*U(1:end1,:) + (1bUy).*U(2:end,:));

    rUy = (Umody(2:end1,:) Umody(1:end2,:))./ ...(Umody(3:end,:) Umody(2:end1,:));

    psiUy = fluxLimiter(rUy,type);

    FUx = [Umidx(:,1).2 Umidx(:,2:end1).*(UxUpwind ...psiUx.*(UxUpwind Umidx(:,2:end1))) Umidx(:,end).2];

    FUy = [Vmidy(1,:).*Umidy(1,:); Vmidy(2:end1,:).*(UyUpwind ...psiUy.*(UyUpwind Umidy(2:end1,:))); Vmidy(end,:).*Umidy(end,:)];

    Us = U dt*(diff(FUx,[],2)./dX + s*diff(FUy)./dY);

    % V

    bVx = sign(Umidx(:,2:end1)) >= 0;VxUpwind = (bVx.*V(:,1:end1) + (1bVx).*V(:,2:end));

    rVx = (Vmodx(:,2:end1) Vmodx(:,1:end2))./ ...(Vmodx(:,3:end) Vmodx(:,2:end1));

    psiVx = fluxLimiter(rVx,type);

    bVy = sign(Vmidy(2:end1,:)) >= 0;VyUpwind = (bVy.*V(1:end1,:) + (1bVy).*V(2:end,:));

    rVy = (Vmody(2:end1,:) Vmody(1:end2,:))./ ...(Vmody(3:end,:) Vmody(2:end1,:));

    37

  • psiVy = fluxLimiter(rVy,type);

    FVx = [Umidx(:,1).*Vmidx(:,1) Umidx(:,2:end1).*(VxUpwind ...psiVx.*(VxUpwind Vmidx(:,2:end1))) Umidx(:,end).*Vmidx(:,end)];

    FVy = [Vmidy(1,:).2; Vmidy(2:end1,:).*(VyUpwind ...psiVy.*(VyUpwind Vmidy(2:end1,:))); Vmidy(end,:).2];

    Vs = V dt*(diff(FVx,[],2)./dX + s*diff(FVy)./dY);

    end

    pressure solver.m

    function [P, B] = pressure solver(A, U,V,dt,nx,ny,dX,dY,BoundVals,s)

    [Ux, , , ] = gradient vel(U,dX,dY,BoundVals.u);[, Vy, , ] = gradient vel(V,dX,dY,BoundVals.v);

    B = (1/dt)*(Ux + s*Vy);

    b = reshape(B,[],1);

    %% Conjugate gradient method

    % Tolerance for conjugate gradient methodTol = 1e8;

    % Maximum number of iterationsnIter = 2*nx*ny;

    % Solving for pressure[Pvec, ] = conjugateGradient(A,b,nIter,Tol);

    % Reshaping vector to matrixP = reshape(Pvec,ny,nx);end

    pressure correction.m

    function [Usss, Vsss] = pressure correction(P,Uss,Vss,dX,dY,dt,nx,ny,s)Px = zeros(ny,nx+1);Py = zeros(ny+1,nx);

    Px(:,2:end) = P;Px(:,1:end1) = Px(:,1:end1) + P;Px(:,2:end1) = Px(:,2:end1)/2;

    38

  • Py(2:end,:) = P;Py(1:end1,:) = Py(1:end1,:) + P;Py(2:end1,:) = Py(2:end1,:)/2;

    Usss = Uss ...dt*(Px(:,2:end) Px(:,1:end1))./dX;

    Vsss = Vss ...dt*s*(Py(2:end,:) Py(1:end1,:))./dY;

    end

    advection phi.m

    function Phis = advection phi(Phi,dX,dY,dt,BoundVals,U,V,s,type)

    phi = BoundVals.phi;u = BoundVals.u;v = BoundVals.v;

    [,,Phibottom,Phileft] = Uedges(phi,Phi,dX,dY);Phimodx = [Phileft Phi];Phimody = [Phibottom; Phi];

    [, , Umidx, ] = gradient vel(U,dX,dY,u);[, , , Vmidy] = gradient vel(V,dX,dY,v);[, , Phimidx, Phimidy] = gradient vel(Phi,dX,dY,phi);

    bPhix = sign(Umidx(:,2:end1)) >= 0;PhixUpwind = (bPhix.*Phi(:,1:end1) + (1bPhix).*Phi(:,2:end));

    rx = (Phimodx(:,2:end1) Phimodx(:,1:end2))./ ...(Phimodx(:,3:end) Phimodx(:,2:end1));

    psix = fluxLimiter(rx,type);

    bPhiy = sign(Vmidy(2:end1,:)) >= 0;PhiyUpwind = (bPhiy.*Phi(1:end1,:) + (1bPhiy).*Phi(2:end,:));

    ry = (Phimody(2:end1,:) Phimody(1:end2,:))./ ...(Phimody(3:end,:) Phimody(2:end1,:));

    psiy = fluxLimiter(ry,type);

    Fx = [Phimidx(:,1) (PhixUpwind ...psix.*(PhixUpwind Phimidx(:,2:end1))) Phimidx(:,end)];

    Fy = [Phimidy(1,:); (PhiyUpwind ...psiy.*(PhiyUpwind Phimidy(2:end1,:))); Phimidy(end,:)];

    39

  • Phis = Phi dt*(U.*diff(Fx,[],2)./dX + s*V.*diff(Fy)./dY);

    end

    conjugateGradient.m

    function [u, U] = conjugateGradient(A,b,nIter,Tol)

    if nargin == 3Tol = 1e8;

    end

    U = cell(nIter+1,1);x = zeros(size(b));r = b A*x;p = r;cnt = 1;U{cnt} = x;rmserr = 10*Tol;while rmserr > Tol

    z = A*p;rpr = r'*r;a = rpr/(p'*z);x = x + a*p;r1 = r a*z;

    rmserr = norm(r)/sqrt(length(r));

    b = (r1'*r1)/rpr;p = r1 + b*p;

    r = r1;

    cnt = cnt+1;

    U{cnt} = x;end

    if cnt == nIter && nIter = 1disp('Max iter reached')

    end

    U = U(1:cnt);u = x;end

    vorticity.m

    40

  • function varargout = vorticity(U,V,dX,dY,BoundVals,s)

    [Ux, Uy, , ] = gradient vel(U,dX,dY,BoundVals.u);[Vx, Vy, , ] = gradient vel(V,dX,dY,BoundVals.v);

    varargout{1} = Vx s*Uy;varargout{2} = Ux;varargout{3} = Uy;varargout{4} = Vx;varargout{5} = Vy;

    end

    stream function.m

    function SF = stream function(A sparse,vort,Nx,Ny,s)

    % Tolerance for conjugate gradient methodTol = 1e8;

    % Maximum number of iterationsnIter = 2*Nx*Ny;

    b = reshape(vort,[],1);

    % startTime = tic;[SFvec, ] = conjugateGradient(A sparse,b,nIter,Tol);% stopTime = toc(startTime);

    SF = reshape(SFvec,Nx,Ny);

    end

    matrix poisson eqn.m

    function A = matrix poisson eqn(dx,dy,Nx,Ny,s)

    d2x = 1/dx2;d2y = (s2)/dy2;

    A1 = diag(ones(Ny,1)*2*(d2y+d2x),0) + diag(ones(Ny1,1)*d2y,1) + ...diag(ones(Ny1,1)*d2y,1);

    A1(1,1) = A1(1,1) + d2y;A1(Ny,Ny) = A1(Ny,Ny) + d2y;

    A3 = A1 + diag(ones(Ny,1)*d2x,0);

    A2 = diag(ones(Ny,1)*d2x,0);

    41

  • A = zeros(Ny*Nx,Ny*Nx);

    for ii = 2:Nx1

    A((ii1)*Ny + (1:Ny),(ii1)*Ny + (1:Ny)) = A1;A((ii1)*Ny + (1:Ny),(ii)*Ny + (1:Ny)) = A2;A((ii1)*Ny + (1:Ny),(ii2)*Ny + (1:Ny)) = A2;

    end

    A(1:Ny,1:Ny) = A3;A(1:Ny,Ny+(1:Ny)) = A2;

    A((Nx1)*Ny+(1:Ny),(Nx1)*Ny+(1:Ny)) = A3;A((Nx1)*Ny+(1:Ny),(Nx2)*Ny+(1:Ny)) = A2;

    % Making P(X(1,1),Y(1,1)) = 0A(1,1) = 2*A(1,1);

    end

    matrix stream function.m

    function A = matrix stream function(dx,dy,Nx,Ny,s)

    d2x = 1/dx2;d2y = s2/dy2;

    A1 = diag(ones(Ny,1)*2*(d2y+d2x),0) + diag(ones(Ny1,1)*d2y,1) + ...diag(ones(Ny1,1)*d2y,1);

    A1(1,1) = A1(1,1) d2y;A1(Ny,Ny) = A1(Ny,Ny) d2y;

    A3 = A1 diag(ones(Ny,1)*d2x,0);

    A2 = diag(ones(Ny,1)*d2x,0);

    A = zeros(Ny*Nx,Ny*Nx);

    for ii = 2:Nx1

    A((ii1)*Ny + (1:Ny),(ii1)*Ny + (1:Ny)) = A1;A((ii1)*Ny + (1:Ny),(ii)*Ny + (1:Ny)) = A2;A((ii1)*Ny + (1:Ny),(ii2)*Ny + (1:Ny)) = A2;

    end

    A(1:Ny,1:Ny) = A3;

    42

  • A(1:Ny,Ny+(1:Ny)) = A2;

    A((Nx1)*Ny+(1:Ny),(Nx1)*Ny+(1:Ny)) = A3;A((Nx1)*Ny+(1:Ny),(Nx2)*Ny+(1:Ny)) = A2;

    end

    gradient vel.m

    function [Ux, Uy, Umidx, Umidy] = gradient vel(U,dX,dY,u,V,v)

    if nargin == 4

    [U endp1 j,U i endp1,U 0 j,U i 0] = Uedges(u,U,dX,dY);

    Umidx = [(U i 0 + U(:,1))/2 ...(U(:,2:end) + U(:,1:end1))/2 ...(U(:,end) + U i endp1)/2];

    Umidy = [(U 0 j + U(1,:))/2; ...(U(2:end,:) + U(1:end1,:))/2; ...(U(end,:) + U endp1 j)/2];

    elseif nargin == 6

    [U endp1 j,U i endp1,U 0 j,U i 0] = Uedges(u,U,dX,dY);[V endp1 j,V i endp1,V 0 j,V i 0] = Uedges(v,V,dX,dY);

    Z = U.*V;Z i 0 = U i 0.*V i 0;Z i endp1 = U i endp1.*V i endp1;Z 0 j = U 0 j.*V 0 j;Z endp1 j = U endp1 j.*V endp1 j;

    Umidx = [(Z i 0 + Z(:,1))/2 ...(Z(:,2:end) + Z(:,1:end1))/2 ...(Z(:,end) + Z i endp1)/2];

    Umidy = [(Z 0 j + Z(1,:))/2; ...(Z(2:end,:) + Z(1:end1,:))/2; ...(Z(end,:) + Z endp1 j)/2];

    elsedisp('Wrong number of inputs')

    end

    Ux = (Umidx(:,2:end) Umidx(:,1:end1))./dX;Uy = (Umidy(2:end,:) Umidy(1:end1,:))./dY;

    end

    43

  • Uedges.m

    function [Utop,Uright,Ubottom,Uleft] = Uedges(p,P,dX,dY)Xb = p.Xb;Yb = p.Yb;Uleft = ((2*Xb(:,3)1).*P(:,1)) + ...

    (Xb(:,3).*(dX(:,1) 2) + 2).*Xb(:,4);Uright = ((2*Xb(:,1)1).*P(:,end)) + ...

    (Xb(:,1).*(dX(:,end) 2) + 2).*Xb(:,2);Ubottom = ((2*Yb(:,3)1)'.*P(1,:))+ ...

    (Yb(:,3)'.*(dY(1,:) 2) + 2).*Yb(:,4)';Utop = ((2*Yb(:,1)1)'.*P(end,:))+ ...

    (Yb(:,1)'.*(dY(end,:) 2) + 2).*Yb(:,2)';end

    fluxLimiter.m

    function P = fluxLimiter(r,type)

    switch typecase 'superbee'

    P = max(0,max(min(1,2*r),min(2,r)));case 'minmod'

    P = max(0,min(1,r));case 'Koren'

    P = max(0,min(min(2*r,(2+r)/3),2));case 'van leer'

    P = 2*r./(1 + r);P(isinf(P)) = 0;P(isnan(P)) = 0;

    case 'UMIST'P = max(0, ...

    min( ...min(...min(2*r,(0.25+0.75*r)), ...(0.75+0.25*r)),...2)....);

    otherwisedisp('superbee')P = max(0,min(1,r));

    end

    end

    boundary values.m

    44

  • function BoundVals = boundary values(Bound,sheets,sides,x,y,Nx,Ny)

    for kk = 1:length(sheets)BoundVals.(sheets{kk}).Xb = zeros(Ny,4);BoundVals.(sheets{kk}).Yb = zeros(Nx,4);cnt = 1;for ii = [2 4]

    data = Bound.(sheets{kk}).(sides{ii});for jj = 1:size(data,1)

    BoundVals.(sheets{kk}).Xb(y >= data(jj,1) & ...y = data(jj,1) & ...y = data(jj,1) & ...x = data(jj,1) & ...x

  • tdma.m

    function x = tdma(a,b,c,d)

    n = length(d);

    a = [0; a];c = [c; 0];

    c new = zeros(size(c));d new = zeros(size(d));

    c new(1) = c(1)/b(1);for ll = 2:n1;

    c new(ll) = c(ll)/(b(ll) a(ll)*c new(ll1));end

    d new(1) = d(1)/b(1);for ll = 2:n;

    d new(ll) = (d(ll) a(ll)*d new(ll1))/ ...(b(ll) a(ll)*c new(ll1));

    end

    x = zeros(size(d));

    x(n) = d new(n);for kk = n1:1:1

    x(kk) = d new(kk) c new(kk).*x(kk+1);end

    end

    maximum velocity.m

    function [maxV, minV] = maximum velocity(b)

    a1 = b.u.Xb(:,[2 4]);a2 = b.u.Yb(:,[2 4]);a3 = b.v.Xb(:,[2 4]);a4 = b.v.Yb(:,[2 4]);

    A = [a1(:); a2(:); a3(:); a4(:)];

    maxV = max(abs(A(:)));minV = min(abs(A(:)));

    if sum(A(:) < 0)/length(A(:)) == 1

    46

  • tmpV = maxV;maxV = minV;minV = tmpV;

    end

    47

    NomenclatureProblem statementGoverning equationsNumerical values for inputsMeshingBoundary conditionsNumerical methodsNavier-StokesVorticity and Stream FunctionSpecies mass balance

    ValidationNavier-Stokes mass balance

    Grid dependency and computation costResultsProblem statement as isProblem statement with a minor modification

    Conclusion