# Algorithms for Simulation of Shunt Currents in a Vanadium Redox Flow Battery
## 4 Methods
### Analyzing the Equation System: Matrix Indexing  
The equation system must be converted to matrix form for solution by computer. This way, two column vectors (A and I) and a rectangular matrix (B) are defined, fulfilling the equality shown in Equation (1):  
\[[A]=[B][I] \tag{1}\]  
where \(A\) is a column vector with the independent terms of the system of equations, \(B\) is a matrix with the coefficients of the equations of the system, and \(I\) is a column vector with the unknowns of the system (the currents). The values of the unknowns are obtained by premultiplying by the inverse of B on both sides. In order to generate these matrices, it is necessary to define how they will be organized. It was decided to index the matrices in such a way that the unknowns of the instances of the cases are contiguous in vector \(I\). Table 2 serves as an example of indexing vector \(I\) for a case with 4 stacks of 3 cells each. \begin{table}
\begin{tabular}{c c c c c c c c} \hline \hline \multicolumn{2}{c}{**First Cell**} & \multicolumn{2}{c}{**First Cell of Stack**} & \multicolumn{2}{c}{**Middle Cell**} & \multicolumn{2}{c}{**Last Cell of Stack**} \\ \hline \hline
**Variables** & **Unknowns** & **Variables** & **Unknowns** & **Variables** & **Unknowns** & **Variables** & **Unknowns** \\ \hline EoC & ICell & EoC & ICell & EoC & ICell & EcoC & ICell \\ RCell & IChA1 & RCell & IChA1 & RCell & IChA1 & RCell & IChA1 \\ RChA1 & IChA2 & RChA1 & IChA2 & RChA1 & IChA2 & RChA1 & IChA2 \\ RChA2 & IChC1 & RChA2 & IChC1 & RChA2 & IChC1 & RChA2 & IChC1 \\ RChC1 & IChC2 & RChC1 & IChC2 & RChC1 & IChC2 & RChC1 & IChC2 \\ RChC2 & IMnA1 & RChC2 & IMnA1 & RChC2 & IMnA1 & RChC2 & IMnC1 \\ RMnA1 & IMnA2 & RMnA1 & IMnA2 & RMnA1 & IMnA2 & RMnC1 & IMnC2 \\ RMnA2 & & RMnA2 & RMnA2 & RMnC1 & RMnC2 & \\ \hline
**Equations** & **Equations** & & & & & & **Equations** \\ \hline  & & & & & & & & \\ \multicolumn{6}{c}{**Equations**} \\ \multicolumn{6}{c}{From (A1) to (A19)} \\ \multicolumn{6}{c}{**Last cell**} & \multicolumn{2}{c}{**First stack**} & \multicolumn{2}{c}{**Middle stack**} & \multicolumn{2}{c}{**Last stack**} \\ \hline
**Variables** & **Unknowns** & **Variables** & **Unknowns** & **Variables** & **Unknowns** & **Variables** & **Unknowns** \\ \hline EoC & ICell & RBrA1 & IBrA1 & RBrA1 & IBrA1 & RBrA1 & IBrA1 \\ RCell & IChA1 & RBrA2 & IBrA2 & RBrA2 & IBrA2 & RBrA2 & IBrA2 \\ RChA1 & IChA2 & RBrC1 & IBrC1 & RBrC1 & IBrC1 & RBrC1 \\ RChA2 & IChC1 & RBrC2 & IBrC2 & RBrC2 & IBrC2 & RBrC2 & IBrC2 \\ RChC1 & IChC2 & RTrA2 & ITrA2 & RTrA1 & ITrA1 & RTrA1 & ITrA1 \\ RChC2 & IMnC1 & KITrC1 & ITrC1 & RTrA2 & ITrA2 & RTrC2 & ITrC2 \\ \hline RMnC1 & IMnC2 & **Equations** & RTrC1 & ITrC1 & \multicolumn{2}{c}{**Equations**} \\ \cline{2-6} RMnC2 & & From (A29) to (A34) & RTrC2 & ITrC2 & From (A43) to (A48) \\ \hline
**Equations** & & & & & & & \\ \multicolumn{6}{c}{**Equations**} \\ \multicolumn{6}{c}{From (A20) to (A28)} \\ \hline  & & & & & & & \\ \hline \end{tabular} The colours are associated with each case and are to facilitate quick identification in the rest of the article.  
\end{table} 
Table 1: Variables, unknowns, and equations of the identified cases. Figure 1: Electrical circuit formation patterns between cells (**a**–**c**) and between stacks (**d**–**f**). The connections between the branches of the stacks and the cells are indicated by numbers. (**a**) First cells of stacks; (**b**) middle cells of the stacks; (**c**) last cells of stacks; (**d**) first stack of the battery; (**e**) middle stacks of the battery; (**f**) last stack of the battery. Each row of matrix B follows the same indexing as the column vector I. The equations of each case instance are entered one by one, in an orderly manner, into each row of the A and I vectors as well as the B matrix. First, the equations related to the nodes are entered and then those related to the nets. Thus, vector A is indexed as shown in Table 3 for the example case of Table 2.  
The first number in the parenthesis refers to the stack number and the second to the cell number within that stack.