# An Algorithm for Nutrient Mixing Optimization in Aquaponics
## 2 Materials and Methods
### Mathematical Description of the System  
The general system structure of a double-recirculation aquaponic system (DRAPS) will be similar across all implementations: multiple tanks and a fertilizer injection system, all connected to one mixing tank (MW) (Figure 1). It is a simple and precisely specified system, both in dimensions and other parameters, which allows for a mechanistic modeling approach using mass and volume balance equations. Note, that mixing dynamics are not included in the model; it is assumed that after adding ingredients, the system has enough time to mix homogeneously. Additionally, sedimentation is neglected. Two properties describe the so-called states of the system: liquid volume \(V\) in [L] and nutrient mass \(N\) in [g]. Instead of using concentrations, the absolute mass of a nutrient is used, as this simplifies the process of adding liquids with different concentrations and is overall more practical. Any number of tanks and water sources can be considered, but for this work, we chose a mixing tank, fish drain water tank (FW), plant drain/re-flow water tank (PW), rain water tank (RW), and tap water (TW), each with their respective volume \(V_{i}\), where \(I\) is a set of size \(i_{\text{max}}\) with  
\[i\in I:=\{\text{FW},\text{PW},\text{RW},\text{TW}\}. \tag{1}\]  
The mixed nutrient solution can then be used for plant fertigation. All solved ions that are found relevant by the user may be considered. In this work, we consider \(N_{q}\) with  
\[q\in Q:=\{\text{NO}_{3}-\text{N},\text{NH}_{4}-\text{N},\text{PO}_{4}-\text{ P},\text{SO}_{4}-\text{S},\text{K}^{+},\text{Ca}^{2+},\text{Mg}^{2+},\text{Fe}^{2+}, \text{Cl}^{-},\text{Na}^{+}\}. \tag{2}\]  
However, not all ions need to be accumulated in the system. Sodium and chloride in particular are harmful to plants at higher concentrations. Therefore we introduce two subsets of ions, the first being  
\[Q_{\text{nut}}:=\{\text{NO}_{3}-\text{N},\text{NH}_{4}-\text{N},\text{PO}_{4 }-\text{P},\text{SO}_{4}-\text{S},\text{K}^{+},\text{Ca}^{2+},\text{Mg}^{2+},\text{Fe}^{2+}\}, \tag{3}\]  
which is the set of nutrients that usually contribute positively to plant nutrition and that the user gives reference values for, and the second being  
\[Q_{\text{harm}}:=\{\text{Cl}^{-},\text{Na}^{+}\}, \tag{4}\]  
which contains ions that are harmful to plants at higher concentrations and that the user does not define a non-zero reference value for. Note that there might be beneficial interactions and compound effects between the two classes of ions, i.e., the meanings of  
Figure 1: Schematic description of the multi-tank system for mixing nutrient solutions. harmful and beneficial are more in the sense of'minimize in the solution' and 'accumulate in the solution', respectively. In the resulting solution, the concentrations of the nutrients \(q_{\text{nut}}\in Q_{\text{nut}}\) should be as close to a reference as possible and the concentrations of \(q_{\text{harm}}\in Q_{\text{harm}}\) should be minimized or not exceed a specific maximum concentration. Next, the inputs \(u\) to the system are described, where the term input in control engineering refers to a variable that can influence the system and can be chosen at will. Two types of inputs are considered: water flows and fertilizers. Water flows, denoted as \(u_{\text{V,i}}\), describe the water volume in [L] that is transferred from source \(i\) to the mixing tank in one mixing cycle. Fertilizers, denoted as \(u_{\text{N,f}}\), describe how much of a fertilizer \(f\) is added to the system in [g]. Possible fertilizers are  
\[f\in F:=\{\text{Ca(NO3)2},\text{KNO3},\text{K}_{2}\text{SO4},\text{NH4}\text{ NO3},\text{MgSO4},\text{Fe-Chelat},\text{KH3 PO4}\}. \tag{5}\]  
Once they are added to the mixing tank, they dissociate into their respective ions \(q\).