Skip to main content

Thank you for visiting You are using a browser version with limited support for CSS. To obtain the best experience, we recommend you use a more up to date browser (or turn off compatibility mode in Internet Explorer). In the meantime, to ensure continued support, we are displaying the site without styles and JavaScript.

Flexible modeling and control of capacitive-deionization processes through a linear-state-space dynamic Langmuir model


While black-box models such as neural networks have been powerful in many applications, direct physical modeling (white box) remains crucial in many fields where experimental data are difficult or time-consuming to obtain. Here, we demonstrate with an example from desalination by capacitive deionization (CDI), how an existing physical model could be strengthened by combining a general modeling framework with physical insights (gray box). Thus, a dynamic Langmuir (DL) model is extended to a linear-state-space DL model (LDL). Results obtained show the new LDL model could incorporate general structural and operational modes, including membrane CDI and constant-current operation. The formulation removes the need for direct measurements of detailed device properties without adding model complexity, and MATLAB code for automatically implementing the model is provided in the Supplementary Information. We conclude the new LDL model is widely applicable, offering great flexibility in calibration data, and enabling prediction over general operating modes.


Although black-box models1, such as neural networks2,3, have seen widespread success in recent years for modeling complex systems using a lot of data2, physical modeling (white-box4) remains a prominent tool in many fields where detailed system knowledge is required while data for learning is difficult or time-consuming to extract4. A gray-box model leverages the system’s known physical behavior to effectively use available data in generalized fitting methods, making it a trade-off between black and white-box approaches4,5, and extensive theory and software exist for systems that can be written in this form6. In this work, we present an example from desalination modeling, showing how an existing physical model can be lifted up to a gray-box form, making it possible to leverage the existing framework to significantly improve the model performance.

Desalination technologies7,8,9,10,11 such as reverse osmosis (RO)12,13,14, are becoming increasingly important owing to the global shortage of traditional sources of fresh water15,16,17. However, capacitive deionization (CDI) is an emerging technology being increasingly recognized for its efficacy of removing charged species especially from brackish water and industrial effluents18,19,20. In CDI, water passes through a cell comprising of two electrically conducting porous electrodes separated by a spacer (Fig. 1)18,19,21,22. Upon the application of an electric potential, the induced electric field pulls out the ions from water and electro-adsorbs them on the electrodes, thus producing desalted water. Structural parameters affecting the desalination process include cell structure23,24,25,26, electrode material23,27,28,29,30,31,32,33,34,35, and membranes (membrane CDI (MCDI))36,37,38. Operational parameters influencing the desalination process include the inlet ion concentration39 and ionic species in the water37,40,41,42,43,44,45, as well as the flow rate46. The applied voltage is another crucial parameter47, and common operating modes include charging with a time-invariant voltage (constant-voltage mode, CV48) or applying a voltage such that the current is uniform throughout the charging phase (constant-current mode, CC49).

Fig. 1: A schematic illustration of the working of a typical CDI device.

In a CDI device, water flows through a cell with two porous electrodes. A voltage applied to these electrodes induces an electric field removing ions from the solution by electrosorption on the electrodes.

Because CDI is a technology strongly affected by material and operational conditions, physics-based white-box models24,39,50,51,52 have been important for describing, predicting, and efficiently optimizing the operations of CDI systems. One such model is the dynamic Langmuir (DL)53,54,55 model, which has been shown to be applicable to a wide range of CDI systems and could predict device performance with respect to the applied voltage in CV mode54, different flow rates54, ion concentration53,54, ion composition in multi-ion solutions55, and electrode asymmetry53.

Among the various modeling approaches in CDI, the decoupled nature of the DL model53 makes it a solid base for constructing a linear-state-space formulation to describe the CDI processes. In this work, we have constructed such a formulation (termed the LDL model) in order to take advantage of the existing framework of such gray-box models and significantly improve the performance of the simulations. Crucially, this also enables strong and flexible control systems for operating the CDI devices.


The DL model describes the salt removal in CDI through the macroscopic properties of adsorption and desorption strengths (see the method section). The salt ions are assumed to adsorb on voltage-induced sites, and the net adsorption is rapid at the beginning of the desalination process but slows down as the device approaches saturation.

Models can be valuable for CDI as they make it possible to describe, predict, and optimize device performance. This section shows the results when the derived LDL model is applied to various systems and experiments from the literature, in order to validate the model performance for describing and predicting CDI processes.

Specifically, this section will investigate three key aspects. First, could the model describe and predict CDI performance under various operating conditions? Second, could the model be applied to general systems and operations, including MCDI devices and operations with time-varying voltages such as the CC operation? Third, could the state-space formulation enable a basic control system to be implemented?

Modeling CDI

Hemmatifar et al.51 used a two-dimensional porous electrode model to investigate CDI dynamics, and their work includes data for effluent ion concentration over time, depending on the applied voltage. For operation at 1 V, Fig. 2a demonstrates that the LDL model gives a great fit to data in the desalination phase and slightly underestimates the effluent ion concentration at the beginning of the regeneration phase. The basic modeling accuracy is similar to that of the mD model51, and the modeling error could be attributed to electrode starvation (low concentrations asymmetrically prolong the desalination phase) which is not accounted for in the LDL model51. Crucially, the model accurately predicts the variations in effluent concentration depending on the applied voltage (Fig. 2b).

Fig. 2: The effluent ion concentration over time for a flow-between CDI cell.

The effluent concentration was extracted from ref. 51. The ion concentration was normalized w.r.t. the inlet concentration, whereas the time was normalized to the diffusion time scale following Hemmatifar et al.51. The influent concentration was 20 mM KCl and the flow rate was 0.42 mL min−1. a The LDL model was fitted to the effluent concentration data at an applied voltage of 1 V. b The experimental data for operations with 0.4 V, 0.6 V, and 0.8 V. c The model predictions, based on the fitting in a, for operations with 0.4 V, 0.6 V, and 0.8 V.

For completeness, note that the model can also predict the CDI performance with varying flow rates (Supplementary Fig. 1, data from ref. 54), and for batch-mode operations (Supplementary Fig. 2, data from ref. 56).

Wider applicability

Wang et al. investigated the performance of an MCDI system operating in either CV or CC modes, to compare which operational mode was most efficient48. The DL model applied to the data for the CV operation is shown in Fig. 3a. There is a very good agreement between the model and experiment for both the effluent concentration (Fig. 3a) and the current (Fig. 3b) over time.

Fig. 3: The performance over time for an MCDI cell in CV mode.

This MCDI operation is based on data from ref. 48. The model fitting was based on Eq. 11, with a CV voltage of 1.2 V and a constant 20 mM influent ion concentration, whereas the effluent concentration and the current were the outputs. The graphs show experimental data and model fit for a the cell effluent concentration and b the current through the device.

Wang et al. 48 also investigated CC-mode operation with the same device. Because the same device was used for both operations, the fitting from Fig. 3 and the input voltage from Fig. 4b can be used the predict the MCDI performance during CC-mode operation. (Fig. 4a). There is excellent agreement with reported experimental results, which demonstrates that the LDL model could be applied to CC-mode operations in MCDI and, more generally, operations with time-varying voltages.

Fig. 4: The performance over time of an MCDI cell in CC mode.

For this MCDI device, the data was retrieved from ref. 48 and the model fitting was based on Eq. 11. a The cell effluent concentration over time. b The applied voltage during the CC operation which was used as an input for the fitting in a.

As a side note, the LDL model is flexible in that it allows for fitting using only concentration, only current, or both. This is demonstrated in Supplementary Note 4, where either only effluent ion concentration is used for fitting (Supplementary Fig. 3), both current and ion concentration is used (Supplementary Fig. 4), or the current is used as input (Supplementary Fig. 5). Although it is possible to fit using only ion concentration or current through the device, using both could reduce overfitting as discussed in Supplementary Note 4.

Control circuit

The linear-state-space form that has been developed in this work has for the DL model makes it possible to implement a proportional integral derivative (PID) controller to automate the cell operation. Crucially, MATLAB provides support and great flexibility for tuning such controllers based on the performance requirements57. MATLAB code for creating the state-space model and automatically tuning such a controller is provided in Supplementary Note 1.

A tuned controller can automatically choose the input (μ, the voltage in Eq. 11) to make the output value y approach some given reference signal r. This can reliably improve the operation’s efficacy in various ways depending on the operating targets, such as energy efficiency, desalination rate, a combination of these, or the volume of produced water with a given outlet concentration. For instance, the CDI device could reliably produce clean water with the same specified quality (ion concentration) while requiring a short time to reach this state (Fig. 5a). Similarly, the operation could be either in CC (Fig. 5b) or CV mode (discussed in Supplementary Notes 2 and 4). As previous works have argued that CC mode is more energy-efficient than CV58, this already means the controller can improve energy efficiency compared to a CV operation. Moreover, any combination of CC and CV mode could be achieved by choosing y = I/I0 + V/V0, for some chosen constants I0,V0 (Fig. 5c). Because this operation combines the CC and CV modes, it is at least as good as the best of the CC and CV modes, and future work may find a combined operation (values for I0,V0) that is even more energetically efficient for a given system.

Fig. 5: Response from a CDI control system.

A state-space model was derived from Eq. 11 and the parameter fitting in Fig. 3. A PID controller was automatically tuned to this system using the tool in Supplementary Note 1 so that the model output y will approach a supplied reference signal r. The graphs show simulated step responses for the controlled CDI system, under various outputs y. a The output is the concentration y = (c0 − c)/c0 and the reference value is r = 0.2. b The output is the current y = I/I0(I0 = 100[mA]) and the reference value is r = 1. c As an example of combined CC/CV operation, the output is a combination of the current and the voltage I/I0 + V/V0 (I0 = 100[mA], V0 = 1[V]) and the reference value is r = 1.

Note that the control system in Fig. 5 is meant as a proof-of concept and does not include extra boundary conditions that might be present in reality, such as an upper limit on the current or voltage the cell and circuit can handle. However, MATLAB also provides the option to set limits on the input through the Simulink control systems interface (Fig. 6a, Supplementary Note 1). Thus, an actuator (the part limiting the maximum voltage) connects to the PID controller and the extracted model structure from Fig. 5.

Fig. 6: PID system for CDI.

a The Simulink model for the LDL control system. The Model Process determines how the system is affected by the applied voltage, as extracted from the data in Fig. 3. The PID component determines what voltage to apply depending on the output (e.g., the effluent concentration), and the actuator limits the applied voltage to 1.2 V. Also, the PID component contains an anti-windup feature to improve overall performance if the applied voltage reaches its maximum value during parts of the process. b The simulated effluent concentration when the operator applied a reference signal cref/c0 = 0.5, meaning the device is supposed to produce outlet water with half the concentration of the inlet water.

Figure 6b shows that the complete control circuit works very well for effectively and safely pursue operational targets. In this example, the reference signal cref/c0 = 0.5 makes the effluent concentration quickly and reliably reach half the ion concentration of the inlet solution. Crucially, the limit on the applied voltage means the ion removal steadily begins to drop when the adsorption is so large that the maximum voltage is no longer enough to achieve the target ion removal rate. In effect, this means the device operates as close as possible to the stated goals without exceeding the critical input boundaries.

So far, the work has found a linear-state-space formulation that basically allowed us to construct control systems that effectively and safely operate toward generalized objectives and efficiency metrics. Having these control systems intuitively means future work could systematically investigate the general operational modes to find faster and more energy-efficient operations. Also, although this work uses a PID controller as a proof-of-concept, notice that a strength of the linear-state-space formulation is that it additionally provides a solid foundation for deriving even more effective control systems in the future.


This work demonstrates that converting an existing physical model to a gray-box form could have several advantages.

First, the new LDL model retains all the properties of the DL model, such as predicting device performance with respect to the applied voltage in CV mode54, different flow rates54, ion concentration53,54, ion composition in multi-ion solutions55, and electrode asymmetry53. Therefore, this work has focused on showing data sets that are new in the LDL model, such as MCDI systems, CC charging, and control systems. Future work could focus on further expanding the LDL model by, for instance, including Faradaic reactions and spatiotemporal resolution. Also, to create a linear formulation, the LDL model has integrated the main concentration dependence into the state-space constants, which complicates the simulations of processes where the variation in concentration is large. Thus, future non-linear control systems have the potential to further improve control in such processes.

Second, the existing framework for state-space models made LDL more generally applicable and more flexible than DL. The LDL model could predict the performance of MCDI systems without increasing the model complexity. Also, it could predict the performance under time-varying voltages. The model makes it possible to fit and predict device performances without making any direct measurements of device components, such as contact resistance or cell structures, which could make the model easier to implement for large systems where direct measurements could be difficult to perform. Furthermore, the model allows fitting to the initial state, thus circumventing the need for the calibration experiments to start at equilibrium. This could be valuable if it takes time and several cycles for the CDI system to reach a stable operation after the first cycle is initiated, meaning that erratic data at the beginning of the experiment could be ignored when providing data to the model for fitting. In summary, we are excited to learn that the CDI process has fundamental underlying principles that make it possible to describe a wide variety of operations and cell structures even with limited device-specific knowledge, and enables powerful system-identification and control methods.

Third, software exists that automatically fits state-space models to data. In this work, the system-identification and control systems toolboxes have been used in MATLAB. These made it possible for us to develop MATLAB programs for automatically fitting and predicting with the LDL model, as well as constructing control systems. These programs have been provided in Supplementary Note 1 to make CDI modeling more accessible to researchers.

It is hoped that the work presented here could aid in modeling and controlling complex CDI process while inspiring researchers in other areas where physical modeling is prominent to try to improve their modeling process by incorporating elements from gray-box modeling.


The idea behind this work is that the decoupled nature of the DL model53 makes it a good candidate for constructing a linear-state-space formulation, and such formulations are well-adapted for system-identification and control.

As a background, a compressed version of the theory behind the DL model is derived at the beginning of the methods section. The full derivation can be seen in refs 53,54,55,59,60. Mainly, a linear-state-space formulation version of the DL model (LDL) is derived. Also, we describe how the LDL can be used in system identification for parameter fitting and control systems for achieving the desired system dynamics.

The DL model

The basis for the DL model is the Langmuir isotherm61,62. In the Langmuir isotherm, gas molecules adsorb on a surface, and the fractional surface coverage, θ, changes at a rate depending on the number of free sites, (1−θ), the partial pressure, pA, and the adsorption/desorption rate constants, kads and kdes (Eq. 1). The Langmuir isotherm has been used for explaining adsorption in liquids by exchanging the partial pressure with the ion concentration c61, and this formulation has been used to model the concentration dependence of the equilibrium adsorption in CDI63,64,65,66,67,68,69.

$$\frac{{d{{\uptheta }}}}{{dt}} = k_{ads}p_A\left({1 - {{\uptheta }}} \right)-k_{des}{{\uptheta }}$$

To construct a formulation that can incorporate the operational parameter in CDI electro-adsorption, several aspects should be noted. The number of sites can be interpreted as voltage-induced sites S, which depend proportionally on the applied voltage V, rather than physical sites. We will not consider electrode redox reactions, so the intended voltage operation range is in the non-Faradaic (V < 1.2) regime. Also, the fundamental mechanism during the electro-adsorption is the storage of charged species, σ, onto these sites. Thus, Eq. 1 can be simplified to Eq. 2, where subscript “ads” denote the corresponding adsorbed quantities (Eq. 2).

$$\frac{{d{{\upsigma }}_{ads}}}{{dt}} = k_{ads}{{\upsigma }}\left({S - {{\upsigma }}_{ads}} \right)-k_{des}{{\upsigma }}_{ads}$$

Ideally, the number of charged species, σ, would relate to the ion concentration, c, through the ion valency, z, as σads = zcads. However, the effective number of surface sites available for ion adsorption, S′, is typically lower than the sites for charges (S′ = S−β, where β is a constant at a given initial concentration) (Eq. 3). This could be due to several reasons, but the main factor considered here is co-ion expulsion; that is, the blockage could be attributed to charge storage leading to co-ions being repelled from the surface rather than counterions being attracted. The magnitude of the blockage can be attributed to charges on the electrodes being neutralized70 (reduces S by β0, a constant) and a passive presence of ions close to the pore wall before the CDI process starts (reduces S by β1c0, where β1 is a constant and c0 is the initial concentration), so that β = β0 + β1c.

$$\frac{{dc_{ads}}}{{dt}} = k_{ads}c\left({S - {{\upbeta }}_0 - {{\upbeta }}_1c_0-c_{ads}z} \right)-k_{des}c_{ads}$$

In experiments, typically the effluent concentration of the cell is measured rather than the number of ions adsorbed on the electrodes. Consider a uniform, well-stirred container (CDI cell) with a cell-free volume, vc. At any given time, all ions inside the cell are either adsorbed on the electrodes or free in the solution (total molar content at time t: vcc(t) = vccads(t)). Over a time period dt, the molar influx of ions (concentration cin, water volume flow Q) is Qcindt while the outflux is Qcdt. Thus, a formula for the time-varying molar content inside the cell can be represented by Eq. 4, which can be rearranged into Eq. 5 when going to the limit of small dt.

$${{\upnu }}_cc\left({t + dt} \right) + {{\upnu }}_cc_{ads}\left({t + dt} \right) = {{\upnu }}_cc\left(t \right) + {{\upnu }}_cc_{ads}\left(t \right) + Qc_{in}dt-Qcdt$$
$$\frac{{dc}}{{dt}} = - \frac{{dc_{ads}}}{{dt}} + \frac{Q}{{{{\upnu }}_c}}\left({c_{in} - c} \right)$$

State-space formulation

Linear-state-space formulations are desirable because they are relatively easy to use for system identification and control. They can be generally written as in Eqs. 6 and 7. Here x is the vector of internal states (typically \(\left[ {c\ c_{ads}\ {{\upsigma }}_{ads}} \right]^T\) in CDI), μ is the vector of system inputs (how the operator affects the system, typically [Vcin]T, the voltage and inlet concentration), y is the vector of system outputs (what is measured, typically [cI]T, the outlet concentration and the current through the CDI device), and A, B, C, D are matrices.

$${\dot{\boldsymbol{x}}} = A{\boldsymbol{x}} + B{\boldsymbol{u}}$$
$${\boldsymbol{y}} = C{\boldsymbol{x}} + D{\boldsymbol{u}}$$

Assuming the variation in the cell concentration during the experiment is not large enough to significantly change the adsorption/desorption rate, the concentration c in Eq. 3 can be exchanged for c0 (Eq. 8).

$$\begin{array}{l}\frac{{dc_{ads}}}{{dt}} = k_{ads}c\left({S - \beta _0 - \beta _1c_0-c_{ads}z} \right)-k_{des}c_{ads} \\ \approx \left({k_{ads}\left({S - \beta _0} \right)c_0 - k_{ads}\beta _1c_0^2} \right)-\left({k_{ads}c_0z + k_{des}} \right)c_{ads} \\ = K_a-K_bc_{ads}\end{array}$$

The parameter Ka depends on one term that is proportional to the applied voltage and one that arises from unideal charge efficiency (\(K_a = max(0,K_{ads}V - K_{{\Lambda }})\), where Kads and KΛ are constants corresponding to the terms in Ka with S or β0 and β1, respectively). Note that, the voltages applied to desalinate are typically such that, Ka = KadsV−KΛ, can be used53 (otherwise there would be no ion removal). In the regeneration phase, linearizing by directly removing the “max” induces a small error at 0 V discharge, unless the charge efficiency is high, which could be addressed by raising the discharge voltage during the regeneration phase while extracting the calibration data, or by fitting the model to data from the desalination phase only. Following the normal rules for matrix multiplication and the definition above, Eq. 9 summarizes the results from Eqs. 4, 7, and 2. Note that σ = zc (charge neutrality is assumed in bulk water) and that \(\bar Q \equiv Q/{{\upnu }}_c\).

The expression in Eq. 9 can be rewritten in several different forms depending on the choice of input and the type of operation (elaborated in Supplementary Notes2 and 3). For instance, it can be adapted to batch-mode operations or rewritten to simplify parameter fitting when only concentration or current data is available.

$$\left[ {\begin{array}{*{20}{c}} {\dot c} \\ {c_{ads}} \\ {\sigma _{ads}} \\ 1 \end{array}} \right] = \left[ {\begin{array}{*{20}{c}} { - \bar Q} & {K_b} & 0 & 0 \\ 0 & { - K_b} & 0 & { - K_{{\Lambda }}} \\ 0 & 0 & { - K_b} & 0 \\ 0 & 0 & 0 & 0 \end{array}} \right]\left[ {\begin{array}{*{20}{c}} c \\ {c_{ads}} \\ {\sigma _{ads}} \\ 1 \end{array}} \right] + \left[ {\begin{array}{*{20}{c}} { - K_{ads}} & {\bar Q} \\ {K_{ads}} & 0 \\ {zK_{ads}} & 0 \\ 0 & 0 \end{array}} \right]\left[ {\begin{array}{*{20}{c}} V \\ {c_{in}} \end{array}} \right]$$

Note that depending on the available data the output state can be chosen to incorporate either the effluent ion concentration or the current through the device, or both. Assuming the internal states and inputs in Eq. 9, only using the effluent ion concentration as output corresponds to y = c (C = [1000], D = [00])). We define the parameter relating the change in charge concentration to total current as, \({{\upeta }} = Fz{{\upnu }}_c = FzQ/\bar Q\), where F is the Faraday constant. Then, using the current passing through the cell corresponds to, \(y = {{\upeta \dot \upsigma }}_{ads}\) (\(C = \left[ {0\ 0 - {{\upeta}}K_b\ 0} \right],D = \left[ {{{\upeta }}\ K_{ads}\ 0} \right]\)). Finally, using both the above formulations, we can simplify to \(y = \left[ {c\ {{\upeta \dot \upsigma }}_{ads}} \right]^T\).

Normalizing the model states might increase the stability of the fitting process (Eq. 10). Thus, we introduce the normalizations \(\bar c = \left({c - c_0} \right)/c_0\), \(\bar c_{ads} = c_{ads}/c_0\), \(\bar \sigma _{ads} = \sigma _{ads}/c_0\), \(\bar K_{ads} = K_{ads}/c_0\), and \(\bar K_b = K_b\). Here, \(\bar c,\) \(\bar \sigma _{ads},\) and \(\bar c_{ads}\) are unitless, while the unit of \(\bar K_{ads}\) is s−1V−1 and \(\bar K_b\) is s−1. Notice that \(\bar K_b\) is supposed to be the same as Kb because the normalized parameters come from Eq. 8 divided by c0. Thus, this unchanged parameter’s altered notation just stresses that \(\bar K_b\) has the same unit as \(\bar K_{ads}\) with respect to concentration. Also, let \({{\bar \upeta }} = {{\upeta }}c_0\), be the factor that relates the normalized variation in the concentration of charges to the total current passing through the cell.

Because this work will move towards creating a controller, notice that a typical CDI operation will run in either continuous mode or batch mode, which prevents the controller from freely choosing the inlet concentration. This means a formulation with only V as input would be more appropriate for creating the controller. Thus, in Eq. 10, we have additionally assumed the inlet concentration to be constant (cin = c0), which removes the concentration from the input matrix to make the voltage the sole system input.

$$\left[ {\begin{array}{*{20}{c}} {\dot{\bar{c}}}\\ {\bar c_{ads}} \\ {{{\bar \upsigma }}_{ads}} \\ 1 \end{array}} \right] = \left[ {\begin{array}{*{20}{c}} { - \bar Q} & {\bar K_b} & 0 & 0 \\ 0 & { - \overline {K_b} } & 0 & { - \bar K_{{\Lambda }}} \\ 0 & 0 & { - \bar K_b} & 0 \\ 0 & 0 & 0 & 0 \end{array}} \right]\left[ {\begin{array}{*{20}{c}} {\bar c} \\ {\bar c_{ads}} \\ {{{\bar \upsigma }}_{ads}} \\ 1 \end{array}} \right] + \left[ {\begin{array}{*{20}{c}} { - \bar K_{ads}} \\ {\bar K_{ads}} \\ {z\bar K_{ads}} \\ 0 \end{array}} \right]\left[ V \right]$$

Furthermore, reducing the number of unknown parameters could improve stability and reduce overfitting. Note, therefore, that if the charge efficiency is high, such as by utilizing ion-selective membranes71, increasing the charging voltage39, treating the electrodes71, or raising the discharge voltage72, this simplifies the model formulation (Eq. 11). Note also, that if a CV charging is used and only effluent concentration data are supplied to the model (data for the current through the cell is not included in the fitting), then Eq. 11 must be used instead of Eq. 10 since the contributions from the \(\bar K_{{\Lambda }}\) and \(\bar K_{ads}\) parameters become indistinguishable (not identifiable).

Regarding the output states, in Eq. 12, \(y_1 = \bar c\) thus corresponds to the normalized effluent concentration, whereas \(y_2 = {{\bar \upeta }}{\dot{\bar{c}}}_{ads}\) corresponds to the current through the cell at high charging efficiency. Note that if the cell-free volume vc is measured (and thus known), \(\bar K_{ads}\) and \(\bar K_b\) are the only unknown parameters. However, the model can be implemented without measuring vc separately by declaring \(\bar Q\) as a fitting parameter in the provided program (it is assumed that the volume flow rate, Q, is known, so vc is uniquely determined by the relative volume flow rate, \(\bar Q\)). The program will then find the value of \(\bar Q\) that yields the best fit to data, considering both the direct dependence on \(\bar Q\) in Eq. 11 and the indirect dependence on \(\bar Q\) through \({{\bar \upeta }}\) in Eq. 12.

$$\left[ {\begin{array}{*{20}{c}} {\dot{\bar{c}}} \\ {\bar c_{ads}} \end{array}} \right] = \left[ {\begin{array}{*{20}{c}} { - \bar Q} & {\bar K_b} \\ 0 & { - \bar K_b} \end{array}} \right]\left[ {\begin{array}{*{20}{c}} {\bar c} \\ {\bar c_{ads}} \end{array}} \right] + \left[ {\begin{array}{*{20}{c}} { - \bar K_{ads}} \\ {\bar K_{ads}} \end{array}} \right]\left[ V \right]$$
$$\left[ {\begin{array}{*{20}{c}} {y_1} \\ {y_2} \end{array}} \right] = \left[ {\begin{array}{*{20}{c}} 1 & 0 \\ 0 & { - {{\bar \upeta }}\bar K_b} \end{array}} \right]\left[ {\begin{array}{*{20}{c}} {\bar c} \\ {\bar c_{ads}} \end{array}} \right] + \left[ {\begin{array}{*{20}{c}} 0 \\ {{{\bar \upeta }}\bar K_{ads}} \end{array}} \right]\left[ V \right]$$


For a purely physical model, the model structure and the model parameters are either known or calculated in specific experiments. In contrast, when constructing the gray-box model, we will derive a physical structure where unknown model parameters are extracted through generalized comparisons with time-series data.

Here, The LDL model was implemented in MATLAB73 using the system-identification toolbox; specifically, the linear gray-box estimation (grayest) was used6. Such modeling requires the user to specify the input μ, the reference data y, and the A, B, C, D matrices. Based on that the unknown parameters are automatically extracted.

A control system was implemented in MATLAB using the control system toolbox57. The program takes as input a calibrated model, extracted with the system-identification software, that can be implemented to automatically tune a PID controller.

In Supplementary Note 1, the programs and all data used are disclosed. The program files include a “data” folder with all the data sets used in this manuscript, a “files” folder and a “main” script for running the system-identification program, an “equation” folder with scripts describing different implementations of Eq. 810, and a “control” file for tuning the controller. An instruction document is also provided to facilitate learning and implementing the program for simulation.

Experimental validation

The derived model was validated solely using experimental data from reports available in the literature. These were chosen so that CDI/MCDI, continuous/batch mode, CV/CC charging were represented. In addition, data from the literature were chosen that reported multiple data sets, showing different operational modes, such that the model could be used for fitting one data set while predicting the others. Note that both the extracted data and the program used to implement the model are provided in Supplementary Note 1.

Data availability

All data used can be found in Supplementary Note 1.

Code availability

The code used to implement the LDL model can found in Supplementary Note 1.


  1. 1.

    Kumar, J. L. G. & Zhao, Y. Q. A review on numerous modeling approaches for effective, economical and ecological treatment wetlands. J. Environ. Manage. 92, 400–406 (2011).

    CAS  Article  Google Scholar 

  2. 2.

    Castelvecchi, D. The black box 2 0. Nature 538, 20–23 (2016).

    CAS  Article  Google Scholar 

  3. 3.

    Mjalli, F. S., Al-Asheh, S. & Alfadala, H. E. Use of artificial neural network black-box modeling for the prediction of wastewater treatment plants performance. J. Environ. Manage. 83, 329–338 (2007).

    CAS  Article  Google Scholar 

  4. 4.

    Afram, A. & Janabi-Sharifi, F. Review of modeling methods for HVAC systems. Appl. Therm. Eng. 67, 507–519 (2014).

    Article  Google Scholar 

  5. 5.

    Estrada-Flores, S., Merts, I., De Ketelaere, B. & Lammertyn, J. Development and validation of ‘grey-box’ models for refrigeration applications: a review of key concepts. Int. J. Refrig. 29, 931–946 (2006).

    Article  Google Scholar 

  6. 6.

    Ljung, L. ODE Parameter Estimation (Grey-Box Modeling). in System Identification Toolbox TM User’ s Guide (MathWorks, 2014).

  7. 7.

    Sharon, H. & Reddy, K. S. A review of solar energy driven desalination technologies. Renew. Sustain. Energy Rev. 41, 1080–1118 (2015).

    CAS  Article  Google Scholar 

  8. 8.

    Hsu, S. T., Cheng, K. T. & Chiou, J. S. Seawater desalination by direct contact membrane distillation. Desalination 143, 279–287 (2002).

    CAS  Article  Google Scholar 

  9. 9.

    Akther, N. et al. Recent advancements in forward osmosis desalination: a review. Chem. Eng. J. 281, 502–522 (2015).

    CAS  Article  Google Scholar 

  10. 10.

    Lutchmiah, K., Verliefde, A. R. D., Roest, K. & Rietveld, L. C. Forward osmosis for application in wastewater treatment: a review. Water Res. 58, 179–197 (2014).

    CAS  Article  Google Scholar 

  11. 11.

    Morton, A. J., Callister, I. K. & Wade, N. M. Environmental impacts of seawater distillation and reverse osmosis processes. Desalination 108, 1–10 (1996).

    Article  Google Scholar 

  12. 12.

    Greenlee, L. F. et al. Reverse osmosis desalination: water sources, technology, and today’ s challenges. Water Res. 43, 2317–2348 (2009).

    CAS  Article  Google Scholar 

  13. 13.

    Alghoul, M. A., Poovanaesvaran, P., Sopian, K. & Sulaiman, M. Y. Review of brackish water reverse osmosis (BWRO) system designs. Renew. Sustain. Energy Rev. 13, 2661–2667 (2009).

    CAS  Article  Google Scholar 

  14. 14.

    Al-Abri, M. et al. Chlorination disadvantages and alternative routes for biofouling control in reverse osmosis desalination. npj Clean Water 2, 2 (2019).

  15. 15.

    Boretti, A. & Rosa, L. Reassessing the projections of the World Water Development Report. npj Clean Water 2, 15 (2019).

  16. 16.

    A, S. I. Water in Crisis: a Guide to the World’s Fresh Water Resources. (Oxford university press, 1993).

  17. 17.

    Rijsberman, F. R. Water scarcity: fact or fiction? Agric. Water Manag. 80, 5–22 (2006).

    Article  Google Scholar 

  18. 18.

    Suss, M. E. et al. Water desalination via capacitive deionization: what is it and what can we expect from it? Energy Environ. Sci. 8, 2296–2319 (2015).

    CAS  Article  Google Scholar 

  19. 19.

    Porada, S., Zhao, R., Van Der Wal, A., Presser, V. & Biesheuvel, P. M. Review on the science and technology of water desalination by capacitive deionization. Prog. Mater. Sci. 58, 1388–1442 (2013).

    CAS  Article  Google Scholar 

  20. 20.

    Ahualli, S. & Iglesias, G. R. Principles and theoretical models of CDI: experimental approaches. Interface Sci. Technol. 24, 169–192 (2018).

    CAS  Article  Google Scholar 

  21. 21.

    Maddah, H. A. & Shihon, M. A. Activated Carbon Cloth for Desalination of Brackish Water Using Capacitive Deionization. (2018).

  22. 22.

    Maddah, H. A. Adsorption isotherm of NaCl from aqueous solutions onto activated carbon cloth to enhance membrane filtration. J. Appl. Sci. Eng. 23, 69–78 (2020).

    Google Scholar 

  23. 23.

    Mutha, H. K. et al. Salt rejection in flow-between capacitive deionization devices. Desalination 437, 154–163 (2018).

    CAS  Article  Google Scholar 

  24. 24.

    Guyes, E. N., Shocron, A. N., Simanovski, A., Biesheuvel, P. M. & Suss, M. E. A one-dimensional model for water desalination by flow-through electrode capacitive deionization. Desalination 415, 8–13 (2017).

    CAS  Article  Google Scholar 

  25. 25.

    Qu, Y. et al. Charging and transport dynamics of a flow-through electrode capacitive deionization system. J. Phys. Chem. B 122, 240–249 (2018).

    CAS  Article  Google Scholar 

  26. 26.

    Laxman, K., Husain, A., Nasser, A., Al, M. & Dutta, J. Tailoring the pressure drop and fluid distribution of a capacitive deionization device. Desalination 449, 111–117 (2019).

    CAS  Article  Google Scholar 

  27. 27.

    Xu, X. et al. Selection of Carbon Electrode Materials. in Interface Science and Technology (ed. Elsevier) 24, 65–83 (Elsevier Ltd., 2018).

  28. 28.

    Laxman, K., Tay, M., Myint, Z., Bourdoucen, H. & Dutta, J. Enhancement in ion adsorption rate and desalination efficiency in a capacitive deionization cell through improved electric field distribution using electrodes composed of activated carbon cloth coated with zinc oxide nanoros. Appl. Mater. interfaces 6, 10113–10120 (2014).

    CAS  Article  Google Scholar 

  29. 29.

    Laxman, K., Myint, M. T. Z., Khan, R., Pervez, T. & Dutta, J. Improved desalination by zinc oxide nanorod induced electric field enhancement in capacitive deionization of brackish water. Desalination 359, 64–70 (2015).

    CAS  Article  Google Scholar 

  30. 30.

    Laxman, K., Myint, M. T. Z., Khan, R., Pervez, T. & Dutta, J. Effect of a semiconductor dielectric coating on the salt adsorption capacity of a porous electrode in a capacitive deionization cell. Electrochim. Acta 166, 329–337 (2015).

    CAS  Article  Google Scholar 

  31. 31.

    Suss, M. E. et al. Impedance-based study of capacitive porous carbon electrodes with hierarchical and bimodal porosity. J. Power Sources 241, 266–273 (2013).

    CAS  Article  Google Scholar 

  32. 32.

    Suss, M. E. et al. Capacitive desalination with flow-through electrodes. Energy Environ. Sci. 5, 9511 (2012).

    CAS  Article  Google Scholar 

  33. 33.

    Porada, S., Bryjak, M., Van Der Wal, A. & Biesheuvel, P. M. Effect of electrode thickness variation on operation of capacitive deionization. Electrochim. Acta 75, 148–156 (2012).

    CAS  Article  Google Scholar 

  34. 34.

    Li, H., Zou, L., Pan, L. & Sun, Z. Using graphene nano-flakes as electrodes to remove ferric ions by capacitive deionization. Sep. Purif. Technol. 75, 8–14 (2010).

    CAS  Article  Google Scholar 

  35. 35.

    Wang, G. et al. Enhanced capacitance in partially exfoliated multi-walled carbon nanotubes. J. Power Sources 196, 5209–5214 (2011).

    CAS  Article  Google Scholar 

  36. 36.

    Długołęcki, P. & van der Wal, A. Energy rcovery in membrane capacitive deionization. Environ. Sci. Technol. 47, 4904–4910 (2013).

    Article  CAS  Google Scholar 

  37. 37.

    Tang, W., He, D., Zhang, C. & Waite, T. D. Optimization of sulfate removal from brackish water by membrane capacitive deionization (MCDI). Water Res. 121, 302–310 (2017).

    CAS  Article  Google Scholar 

  38. 38.

    Choi, J.-H. & Yoon, D.-J. The maximum allowable charge for operating membrane capacitive deionization without electrode reactions. Sep. Purif. Technol. 215, 125–133 (2019).

    CAS  Article  Google Scholar 

  39. 39.

    Biesheuvel, P. M., Porada, S., Levi, M. & Bazant, M. Z. Attractive forces in microporous carbon electrodes for capacitive deionization. J. Solid State Electrochem. 18, 1365–1376 (2014).

    CAS  Article  Google Scholar 

  40. 40.

    Zhao, R. et al. Time-dependent ion selectivity in capacitive charging of porous electrodes. J. Colloid Interface Sci. 384, 38–44 (2012).

    CAS  Article  Google Scholar 

  41. 41.

    Seo, S. et al. Investigation on removal of hardness ions by capacitive deionization (CDI) for water softening applications. Water Res. 44, 2267–2275 (2010).

    CAS  Article  Google Scholar 

  42. 42.

    Tang, W., Kovalsky, P., Cao, B. & Waite, T. D. Investigation of fluoride removal from low-salinity groundwater by single-pass constant-voltage capacitive deionization. Water Res. 99, 112–121 (2016).

    CAS  Article  Google Scholar 

  43. 43.

    Fan, C. S., Tseng, S. C., Li, K. C. & Hou, C. H. Electro-removal of arsenic(III) and arsenic(V) from aqueous solutions by capacitive deionization. J. Hazard. Mater. 312, 208–215 (2016).

    CAS  Article  Google Scholar 

  44. 44.

    Tang, W., Kovalsky, P., He, D. & Waite, T. D. Fluoride and nitrate removal from brackish groundwaters by batch-mode capacitive deionization. Water Res. 84, 342–349 (2015).

    CAS  Article  Google Scholar 

  45. 45.

    Hou, C. & Huang, Z.-Y. A comparative study of electrosorption selectivity of ions by activated carbon electrodes in capacitive deionization. Desalination 369, 46–50 (2013).

    Google Scholar 

  46. 46.

    Wang, C., Song, H., Zhang, Q., Wang, B. & Li, A. Parameter optimization based on capacitive deionization for highly efficient desalination of domestic wastewater biotreated effluent and the fouled electrode regeneration. Desalination 365, 407–415 (2015).

    CAS  Article  Google Scholar 

  47. 47.

    Demirer, O. N., Naylor, R. M., Rios Perez, C. A., Wilkes, E. & Hidrovo, C. Energetic performance optimization of a capacitive deionization system operating with transient cycles and brackish water. Desalination 314, 130–138 (2013).

    CAS  Article  Google Scholar 

  48. 48.

    Wang, L. & Lin, S. Membrane capacitive deionization with constant current vs constant voltage charging: which is better? Environ. Sci. Technol. 52, 4051–4060 (2018).

    CAS  Article  Google Scholar 

  49. 49.

    Jande, Y. A. C. & Kim, W. S. Desalination using capacitive deionization at constant current. Desalination 329, 29–34 (2013).

    CAS  Article  Google Scholar 

  50. 50.

    Suss, M. E., Biesheuvel, P. M., Baumann, T. F., Stadermann, M. & Santiago, J. G. In situ spatially and temporally resolved measurements of salt concentration between charging porous electrodes for desalination by capacitive deionization. Environ. Sci. Technol. 48, 2008–2015 (2014).

    CAS  Article  Google Scholar 

  51. 51.

    Hemmatifar, A., Stadermann, M. & Santiago, J. G. Two-dimensional porous electrode model for capacitive deionization. J. Phys. Chem. C 119, 24681–24694 (2015).

    CAS  Article  Google Scholar 

  52. 52.

    Qu, Y., Baumann, T. F., Santiago, J. G. & Stadermann, M. Characterization of resistances of a capacitive deionization system. Environ. Sci. Technol. 49, 9699–9706 (2015).

    CAS  Article  Google Scholar 

  53. 53.

    Nordstrand, J. & Dutta, J. Dynamic langmuir model: a simpler approach to modeling capacitive deionization. J. Phys. Chem. C 123, 16479–16485 (2019).

    CAS  Article  Google Scholar 

  54. 54.

    Nordstrand, J., Laxman, K., Myint, M. T. Z. & Dutta, J. An easy-to-use tool for modeling the dynamics of capacitive deionization. J. Phys. Chem. A 123, 6628–6634 (2019).

    CAS  Article  Google Scholar 

  55. 55.

    Nordstrand, J. & Dutta, J. Simplified prediction of ion removal in capacitive deionization of multi-ion solutions. Langmuir 36, 1338–1344 (2020).

  56. 56.

    Shi, W. et al. Ultrahigh performance of novel capacitive deionization electrodes based on a three-dimensional graphene architecture with nanopores. Sci. Rep. 6, 18966 (2016).

  57. 57.

    MathWorks. Control System Toolbox TM. (1998).

  58. 58.

    Qu, Y. et al. Energy consumption analysis of constant voltage and constant current operations in capacitive deionization. Desalination 400, 18–24 (2016).

    CAS  Article  Google Scholar 

  59. 59.

    Nordstrand, J. & Dutta, J. Predicting and enhancing the ion selectivity in multi-ion capacitive deionization. Langmuir 36, 8476–8484 (2020).

  60. 60.

    Nordstrand, J. & Dutta, J. Basis and prospects of combining electroadsorption modeling approaches for capacitive deionization. Physics (College. Park. Md). 2, 309–324 (2020).

    Google Scholar 

  61. 61.

    Azizian, S., Eris, S. & Wilson, L. D. Re-evaluation of the century-old Langmuir isotherm for modeling adsorption phenomena in solution. Chem. Phys. 513, 99–104 (2018).

    CAS  Article  Google Scholar 

  62. 62.

    Langmuir, I. The adsorption of gases on plane surfaces of glass, mica and platinum. J. Am. Chem. Soc. 40, 1361–1403 (1918).

    CAS  Article  Google Scholar 

  63. 63.

    Li, H., Lu, T., Pan, L., Zhang, Y. & Sun, Z. Electrosorption behavior of graphene in NaCl solutions. J. Mater. Chem. 19, 6773–6779 (2009).

    CAS  Article  Google Scholar 

  64. 64.

    Li, H. et al. A comparative study on electrosorptive behavior of carbon nanotubes and graphene for capacitive deionization. J. Electroanal. Chem. 653, 40–44 (2011).

    CAS  Article  Google Scholar 

  65. 65.

    Wang, L. et al. Capacitive deionization of NaCl solutions using carbon nanotube sponge electrodes. J. Mater. Chem. 21, 18295 (2011).

    CAS  Article  Google Scholar 

  66. 66.

    Ryoo, M. W., Kim, J. H. & Seo, G. Role of titania incorporated on activated carbon cloth for capacitive deionization of NaCl solution. J. Colloid Interface Sci. 264, 414–419 (2003).

    CAS  Article  Google Scholar 

  67. 67.

    Gabelich, C. J., Tran, T. D. & Suffet, I. H. Electrosorption of inorganic salts from aqueous solution using carbon aerogels. Environ. Sci. Technol. 36, 3010–3019 (2002).

    CAS  Article  Google Scholar 

  68. 68.

    Li, H. et al. Kinetics and thermodynamics study for electrosorption of NaCl onto carbon nanotubes and carbon nanofibers electrodes. Chem. Phys. Lett. 485, 161–166 (2010).

    CAS  Article  Google Scholar 

  69. 69.

    Wang, G. et al. Highly mesoporous activated carbon electrode for capacitive deionization. Sep. Purif. Technol. 103, 216–221 (2013).

    CAS  Article  Google Scholar 

  70. 70.

    Biesheuvel, P. M. Activated carbon is an electron-conducting amphoteric ion adsorbent. (2015).

  71. 71.

    Cohen, I., Avraham, E., Noked, M., Soffer, A. & Aurbach, D. Enhanced charge efficiency in capacitive deionization achieved by surface-treated electrodes and by means of a third electrode. J. Phys. Chem. C 115, 19856–19863 (2011).

    CAS  Article  Google Scholar 

  72. 72.

    Kim, T. et al. Enhanced charge efficiency and reduced energy use in capacitive deionization by increasing the discharge voltage. J. Colloid Interface Sci. 446, 317–326 (2015).

    CAS  Article  Google Scholar 

  73. 73.

    Johnson, R. MATLAB programming Style Guidelines 1.5. October V, 1–14 (2002).

Download references


The authors would like to acknowledge financial support from the Swedish research council (diary no. 2018-05387).


Open Access funding provided by Kungliga Tekniska Hogskolan.

Author information




Conceptualization, J.N. and J.D.; methodology, J.N.; software, J.N.; validation, J.N.; formal analysis, J.N.; investigation, J.N.; resources, J.D.; data curation, J.N.; writing—original draft preparation, J.N.; writing—review and editing, J.D.; visualization, J.N.; supervision, J.D.; project administration, J.D.; funding acquisition, J.D. All authors have read and agreed to the published version of the manuscript.

Corresponding author

Correspondence to Joydeep Dutta.

Ethics declarations

Competing interests

The authors declare that they have no competing interests as defined by Nature Research, or other interests that might be perceived to influence the results and/or discussion reported in this paper.

Additional information

Publisher’s note Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Supplementary information

Rights and permissions

Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made. The images or other third party material in this article are included in the article’s Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the article’s Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this license, visit

Reprints and Permissions

About this article

Verify currency and authenticity via CrossMark

Cite this article

Nordstrand, J., Dutta, J. Flexible modeling and control of capacitive-deionization processes through a linear-state-space dynamic Langmuir model. npj Clean Water 4, 5 (2021).

Download citation


Quick links

Nature Briefing

Sign up for the Nature Briefing newsletter — what matters in science, free to your inbox daily.

Get the most important science stories of the day, free in your inbox. Sign up for Nature Briefing