# Numerical Simulation of Non-Linear Models of Reaction--Diffusion for a DGT Sensor
## 2 The Model
### Discretization  
The spatial discretization of a PDE model can be performed using different techniques. The most frequently used are those of finite differences, finite element (with all its variants) or finite volumes [4; 11]. Each of these techniques has its advantages and disadvantages. For instance, discretizing by the finite difference method leads to simple computer programming, as long as fixed spatial steps are used. However, this latter could imply the use of a large number of points and, therefore, longer calculation times.  
On the other hand, the finite element method allows working with arbitrary point distributions, using smaller spatial steps in regions where it is assumed that function could rapidly changes, so error in the iteration could be large, and larger widths where it is known that the error will be smaller [12]. Although this flexibility results in a computational cost lower than in the case of the finite differences, it involves an algorithmic and programming effort that can be significantly high.  
In this work, the finite differences method was used, taking fixed spatial steps of length \(\Delta z\), and temporal intervals equal to \(\Delta t\) (see Figure 4).  
Figure 4: Scheme of space and time discretization.  
Let \(F(z,t)\) be a function that can contain spatial derivatives (of different orders) of the function \(f(z,t)\). If  
\[\frac{\partial f(z,t)}{\partial t}=F(z,t)\, \tag{19}\]  
Equation (19) can be discretized as a linear combination of the form  
\[\frac{f(z_{i},t+\Delta t)-f(z_{i},t)}{\Delta t}\simeq\lambda F(z_{i},t+\Delta t )+(1-\lambda)F(z_{i},t)\, \tag{20}\]  
where, \(0\leq\lambda\leq 1\).  
In general, for the PDE of parabolic type, the backward Euler method for discretization (i.e., taking \(\lambda=1\) in Equation (20)), allows choosing arbitrary increases in \(z\) and \(t\), without risking its stability or introducing spurious oscillations in the iterative process [4].  
Next, for every substance \(i\), the differential Equation (15) will by discretized using the backward Euler scheme to obtain a system of algebraic equations.  
For species with diffusion coefficient different from zero, the Equation (15) is transformed into  
\[\begin{split}\frac{q_{i}(z,t+\Delta t)-q_{i}(z,t)}{\Delta t}& =\left\{\begin{aligned} d_{i}^{R}\\ d_{i}\end{aligned}\right\}\frac{q_{i}(z+\Delta z,t+\Delta t)-2q_{i}( z,t+\Delta t)+q_{i}(z-\Delta z,t+\Delta t)}{\Delta z^{2}}\\ &+\sum_{j=1}^{numerac}\hat{A}_{i,j}q_{mreac(j,1)}(z,t+\Delta t)q _{mreac(j,2)}(z,t+\Delta t)+\hat{B}_{i,j}q_{mreac(j,3)}(z,t+\Delta t)\.\end{split} \tag{21}\]  
In this case, the described boundary conditions in Equations (17) and (18) will be  
\[\begin{split} q_{i}(\Delta z,t+\Delta t)-q_{i}(0,t+\Delta t)& =0\,\\ q_{i}(r^{*}+g^{*},t+\Delta t)&=1\,\end{split} \tag{22}\]  
and  
\[q_{i}(r,t+\Delta t)-q_{i}(r-\Delta z,t+\Delta t)=\frac{d_{i}}{d_{i}^{R}} \left[q_{i}(r+\Delta z,t+\Delta t)-q_{i}(r,t+\Delta t)\right]. \tag{23}\]  
There is no need for any expression for the solution continuity at \(z=r^{*}\). Simply, from now on, it will be considered for such a position, that each substance has a unique concentration value (a simple way to state that it is continuous, due to the absence of electrostatic effects).  
Due to the fact that the resin and its components are considered motionless, the differential equations for these substances do not contain spatial derivatives. In this way, the equations described in (15) for species with zero coefficient diffusion are re-written as follows:  
\[\begin{split}\frac{q_{i}(z,t+\Delta t)-q_{i}(z,t)}{\Delta t}& =\sum_{j=1}^{numerac}\hat{A}_{i,j}^{\mathrm{R}}q_{mreac(j,1)}(z,t+ \Delta t)q_{mreac(j,2)}(z,t+\Delta t)\\ &+\hat{B}_{i,j}^{\mathrm{R}}q_{mreac(j,3)}(z,t+\Delta t)\,\end{split} \tag{24}\]  
for \((0,r^{*})\), and  
\[q_{i}(z,t+\Delta t)=0,\ \ \forall\ z\in(r^{*},r^{*}+g^{*}). \tag{25}\]