.. _section-A5.3:

Appendix 5.3: Cover Gas Flow and Pressure Algorithm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The main steps in the cover gas treatment in :numref:`section-5.7` may be
summarized in the following algorithm:

1. Initialize. Set :math:`I_{\text{n}} = 0`.

2. Start a loop on :math:`I_{\text{o}}` for :math:`I_{\text{o}}` = :math:`\text{ICV}1`, ..., :math:`\text{ICV}2`.
   Set up :math:`\text{INEW} \left( I_{\text{o}} \right)`, :math:`\text{IOLD} \left( I_{\text{n}} \right)`, where
   :math:`I_{\text{o}}` is the old compressible volume number and :math:`I_{\text{n}}` is
   the new compressible volume number for the compressed arrays.

3. Is there gas in this compressible volume? Is
   :math:`\text{ITYPCV} \left( I_{\text{o}} \right)` = 2,3,4,5, or 8? If so, go to step 5.

4. No gas in this compressible volume. :math:`\text{INEW} \left( I_{\text{o}} \right) = 0`,

    :math:`p_{4} \left( I_{\text{o}} \right) = p_{3} \left( I_{\text{o}} \right)`,

    :math:`T_{4} \left( I_{\text{o}} \right) = T_{3} \left( I_{\text{o}} \right)`,

    :math:`m_{4} \left( I_{\text{o}} \right) = 0`. Go to the end of the loop, step 6.

5. Gas in this compressible volume.

    :math:`I_{\text{n}} = I_{\text{n}} + 1`

    :math:`\text{INEW} \left(I_{\text{o}} \right) = I_{\text{n}}`

    :math:`\text{IOLD} \left(I_{\text{n}} \right) = I_{\text{o}}`

    :math:`{p'}_{3} \left( I_{\text{n}} \right) = p_{3} \left( I_{\text{o}} \right), {m'}_{3} \left( I_{\text{n}} \right) = m_{3} \left( I_{\text{o}} \right)` ,

    :math:`{V'}_{3} \left( I_{\text{n}} \right) = V_{3} \left( I_{\text{o}} \right), {V'}_{4} \left( I_{\text{n}} \right) = V_{4} \left( I_{\text{o}} \right)` ,

    :math:`\tau' \left( I_{\text{n}} \right) = \tau \left( I_{\text{o}} \right)`

6. End of loop on :math:`I_{\text{o}}`. Loop back to step 3 for the next value of :math:`I_{\text{o}}`.

7. :math:`I_{\text{nmax}} = I_{\text{n}}`

8. Start a loop on :math:`I_{\text{n}}` for :math:`I_{\text{n}}` = 1, ..., :math:`I_{\text{nmax}}`

Compute the adiabatic expansion and heat flow, as well as a temporary
array :math:`c \left( i \right)` (see below).

9.  Re-calculate :math:`{p'}_{3} \left( I_{\text{o}} \right)` giving.

    :math:`{p'}_{3} \left( I_{\text{n}} \right) = {p'}_{3} \left( I_{\text{n}} \right) \left\{ 1 - \gamma \left\lbrack \frac{{V'}_{4} \left( I_{\text{n}} \right) - {V'}_{3} \left( I_{\text{n}} \right)}{{V'}_{4} \left( I_{\text{n}} \right)} \right\rbrack \right\}`

    Calculate :math:`{T'}_{3} \left( I_{\text{n}} \right)`.

    Set :math:`c \left( I_{\text{n}} \right) = \frac{{p'}_{3} \left( I_{\text{n}} \right)\gamma \Delta t_{\text{s}}}{{m'}_{3} \left( I_{\text{n}} \right) {T'}_{3} \left( I_{\text{n}} \right)}`

    Also set :math:`c \left( I, J \right) = 0`, with :math:`c \left( I_{\text{n}}, I_{\text{n}} \right) = 0`,

    and :math:`d \left( I_{\text{n}} \right) = 0`.

10. End of loop on :math:`I_{\text{n}}`. Loop back to step 9 for the next value
    of :math:`I_{\text{n}}`.

11. Is there more than one gas compressible volume? Is :math:`I_{\text{nmax}} > 1`? If so, go to step 13.

12. Go to step 25.

13. Start loop on I for I = 1, ..., :math:`I_{\text{nmax}}-1`.

Initialize :math:`e_{\text{ij}}`, :math:`F_{1\text{ij}}`, :math:`F_{2\text{ij}}`.

14. Start loop on :math:`J` for :math:`J = I_{\text{n}} + 1`, ..., :math:`I_{\text{nmax}}`

15. Set :math:`c \left( I,J \right) = 0.0`, :math:`c \left( J,I \right) = 0.0`,
    :math:`F_{1} \left( I,J \right) = 0.0`,
    :math:`F_{1} \left( J,I \right) = 0.0`, :math:`F_{2} \left( I,J \right) = 0.0`,
    :math:`F_{2} \left( J,I \right) = 0.0`

16. End of loop on :math:`J`. Loop back to step 11 for additional values of :math:`J`.

17. End of loop on I. Loop back to step 14 for additional values of :math:`I`.

18. Are there any gas segments? Is :math:`\text{ISG} 1 > 0`?

If not, go to step 25.

19. Start loop on :math:`I_{\text{s}}` for :math:`I_{\text{s}}` =
    :math:`\text{ISG}1`, ..., :math:`\text{ISG}2`.

Compute gas flow between compressible volumes.

20. Find :math:`I_{\text{ni}}` and :math:`I_{\text{no}}`, the inlet and outlet
    compressible volumes for gas segment :math:`I_{\text{s}}`.

    :math:`I_{\text{ni}} = \text{INEW} \left( \text{JNODG} \left( 1,I_{\text{s}} \right) \right)`

    :math:`I_{\text{no}} = \text{INEW} \left( \text{JNODG} \left( 2,I_{\text{s}} \right) \right)`

21. Iterate routine to obtain
    :math:`{F'}_{\text{o}},\ {F'}_{1},\ {F'}_{2},\ T_{\text{ij}}` (See remarks after :eq:`5.7-12`).

22.

    :math:`F_{1} \left( I_{\text{ni}},I_{\text{no}} \right) = F_{1} \left( I_{\text{ni}},I_{\text{no}} \right) + {F'}_{1}`

    :math:`F_{1} \left( I_{\text{no}},I_{\text{ni}} \right) = F_{1} \left( I_{\text{no}},I_{\text{ni}} \right) + {F'}_{1}`

    :math:`F_{2} \left( I_{\text{ni}},I_{\text{no}} \right) = F_{2} \left( I_{\text{ni}},I_{\text{no}} \right) + {F'}_{2}`

    :math:`F_{2} \left( I_{\text{no}},I_{\text{ni}} \right) = F_{2} \left( I_{\text{no}},I_{\text{nio}} \right) + {F'}_{2}`

    :math:`c \left( I_{\text{no}},I_{no} \right) = c \left( I_{\text{no}},I_{\text{no}} \right) - e\left( I_{\text{no}} \right) T_{\text{ij}} {F'}_{1}`

    :math:`c \left( I_{\text{no}},I_{\text{ni}} \right) = c \left( I_{\text{no}},I_{\text{ni}} \right) - e\left( I_{\text{no}} \right) T_{\text{ij}} {F'}_{1}`

    :math:`c \left( I_{\text{ni}},I_{\text{ni}} \right) = c \left( I_{\text{ni}},I_{\text{ni}} \right) - e\left( I_{\text{ni}} \right) T_{\text{ij}} {F'}_{2}`

    :math:`c \left( I_{\text{ni}},I_{\text{no}} \right) = c \left( I_{\text{ni}},I_{\text{no}} \right) - e\left( I_{\text{ni}} \right) T_{\text{ij}} {F'}_{2}`

    :math:`d \left( I_{\text{no}} \right) = d \left( I_{\text{no}} \right) + e\left( I_{\text{no}} \right) T_{\text{ij}} {F'}_{0}`

    :math:`d \left( I_{\text{ni}} \right) = d \left( I_{\text{ni}} \right) - e\left( I_{\text{ni}} \right) T_{\text{ij}} {F'}_{0}`

    :math:`F_{\text{os}} \left( I_{\text{ni}} \right) = F_{\text{os}} \left( I_{\text{no}} \right) + {F'}_{0}`

    :math:`F_{\text{os}} \left( I_{\text{ni}} \right) = F_{\text{os}} \left( I_{\text{no}} \right) - {F'}_{0}`

    :math:`F_{\text{os}} \left( I_{\text{s}} \right) = {F'}_{0}`

    :math:`F_{\text{s}1} \left( I_{\text{s}} \right) = {F'}_{1}`

    :math:`F_{\text{s}2} \left( I_{\text{s}} \right) = {F'}_{2}`

23. End of loop on :math:`I_{\text{s}}`. Loop back to step 20 for the next value
    of :math:`I_{\text{s}}`.

24. Solve the matrix equation for :math:`\Delta p \left( i \right)` (see :eq:`5.7-20`).

25. Start loop on :math:`I_{\text{n}}` for :math:`I_{\text{n}} = 1`,
    ... :math:`I_{\text{nmax}}`

26.

    :math:`{p'}_{4}\left( I \right) = {p'}_{3}\left( I \right) + \Delta p_{\text{i}}`

    :math:`{m'}_{4}\left( I \right) = {m'}_{3}\left( I \right) + \Delta t_{\text{x}} F_{\text{os}}\left( I \right)`

27. End of loop on :math:`I_{\text{n}}`. Loop back to step 26 for additional
    values of :math:`I_{\text{n}}`.

28. If :math:`I_{\text{nmax}} = 1`, go to step 34.

29. Start loop on :math:`I` for :math:`I` = 1, ..., :math:`I_{\text{nmax}}-1`.

30. Start loop on :math:`J` for :math:`J` = :math:`I + 1`, :math:`I_{\text{nmax}}`.

31.

    :math:`{m'}_{4} \left( I \right) = {m'}_{4} \left( I \right) + \Delta t_{\text{s}} \left\lbrack F_{1}\left( J,I \right)\Delta p\left( I \right) + F_{2}\left( J,I \right)\Delta p\left( J \right) \right\rbrack`

    :math:`{m'}_{4} \left( J \right) = {m'}_{4} \left( J \right) + \Delta t_{\text{s}} \left\lbrack F_{1}\left( I,J \right)\Delta p\left( J \right) + F_{2}\left( I,J \right)\Delta p\left( J \right) \right\rbrack`

32. End of loop on :math:`J`. Loop back to step 31 for additional values of :math:`J`.

33. End of loop on :math:`I`. Loop back to step 30 for additional values of :math:`I`.

34. For :math:`I = 1`, ..., :math:`I_{\text{nmax}}` set

    :math:`{T'}_{4} \left( I \right) = \frac{{p'}_{4} \left( I \right) {V'}_{4} \left( I \right)}{{n'}_{4} \left( I \right)R}`

35. Start loop on :math:`I_{\text{n}}` for :math:`I_{\text{n}} = 1`, ..., :math:`I_{\text{nmax}}`

36.

    :math:`I_{o} = \text{IOLD}\left( I_{n} \right)`

    :math:`p_{3}\left( I_{o} \right) = {p'}_{3} \left( I_{n} \right)`

    :math:`m_{3}\left( I_{o} \right) = {m'}_{3} \left( I_{n} \right)`

    :math:`T_{3}\left( I_{o} \right) = {T'}_{3} \left( I_{n} \right)`

37. End of loop on :math:`I_{\text{n}}`. Loop back to step 36 for additional
    values of :math:`I_{\text{o}}`.

38. If :math:`\text{ISG}1 = 0`, go to step 40.

39. For :math:`I_{\text{s}} = \text{ISG}1`, ..., :math:`\text{ISG}2`

    :math:`I_{1} = \text{INEW}\left( \text{JNODG}\left( 1,I_{\text{s}} \right) \right)`

    :math:`I_{2} = \text{INEW}\left( \text{JNODG}\left( 2,I_{\text{s}} \right) \right)`

    :math:`F_{\text{g}4}\left( I_{\text{s}} \right) = F_{\text{so}}\left( I_{\text{s}} \right) + F_{\text{s}1}\left( I_{\text{s}} \right)\Delta p\left( I_{2} \right) = F_{\text{s}2}\left( I_{\text{s}} \right)\Delta p\left( I_{1} \right)`

40. Optional debugging print-out.

41. Return