# Algorithms for Simulation of Shunt Currents in a Vanadium Redox Flow Battery
## 4 Methods
### Algorithms
#### 4.4.2 Codification of Node Equations
Unlike with the node equations, to codify the net equations, additional inputs are needed, relating to the EoC values of each cell as well as the resistances of each pipe segment. These inputs could be considered as inputs to the methods related to the coding of the equations. However, doing so was problematic. This is because introducing the values as inputs, given that these inputs contain arrays with the values of the resistors and EoC, implied that it was necessary to know from the outside how the electrical circuit is generated and to have such arrays generated by differentiating the cases. This same problem manifested itself with the output. It was therefore decided to associate the Cell and Stack objects with the inputs and outputs, making each object have attributes to receive the inputs and return the outputs. These attributes are lists of objects and not double-type values. In this way, the reference to those objects is stored not only internally in the case objects (Cell- and Stack-type objects), but also in an ordered way, in an external object. The same applies for current vectors and voltage variables. This makes it possible to externally modify the values without having to iterate over the objects related to the cases. Although not detailed, the construction of the external arrays is part of the construction of the data structures. Figure 4 shows a schematic of the above. Figure 4: Diagram of the organization of the inputs (the outputs follow the same logic). This is the major difference in how the coding of the net equations has been performed with respect to those of the nodes, with the rest being very similar. Algorithm 7 presents how to start coding the net equations in the StackList object type. As can be seen, the structure of Algorithm 3 is maintained. ```
Input:aVec: equation system column vector of the independent term,bMat: equation system coefficient matrix,current: imposed current to the battery. Result: Encode of the equations of stacks and cells nets. Class the method belongs to: StackList. ```

**Algorithm 7** Algorithm for the codification of the net equations (I). Apart from the method calling for stack objects, the only difference with respect to that shown in Algorithm 3 is that the equation pointer is not updated. This update is performed inside the method that was called for in the loop. Algorithm 8 shows the method related to the encoding of the equations of the net of stack-type objects. #### 4.4.4 Decoding the Current Vector

After performing the operation of the inverse of B and premultiplying vector A with this matrix, it is simply necessary to perform a complete iteration of the cell and stack objects to obtain the values of the currents of vector I using the indices. The output values are stored in the objects relative to the outputs of each Cell and Stack object, so that they are accessible from the outside. ## 5 Comparative Experiments

This section is dedicated to validating the implementation of the algorithm. Since we do not have our own experimental data, comparisons will be made using the parameters of other papers and their results with what is obtained with our model. ### First Comparison

A test of the model has been performed using the design parameters G of [12] and comparing the results. The parameters of model G of item [12] are shown in Table 6. \begin{table}
\begin{tabular}{c c} \hline \hline
**Parameter Name** & **Value** \\ \hline Number of stacks & 4 \\ Number of cells per stack & 30 \\ EoC & 1.4 volts \\ Cell electric resistance & 1.33 \(\times\) 10\({}^{-3}\) ohm \\ Cathode trunk electric resistances & 4.5271 ohm \\ Anode trunk electric resistances & 5.4325 ohm \\ Cathode branch electric resistances & 565.8842 ohm \\ Anode branch electric resistances & 679.0611 ohm \\ Cathode manifold electric resistances & 0.1857 ohm \\ Anode manifold electric resistances & 0.2228 ohm \\ Cathode channel electric resistances & 2777.88 ohm \\ Anode channel electric resistances & 3333.33 ohm \\ Imposed current & \(-90\) amperes \\ \hline \hline \end{tabular}
\end{table}