One dimensional theory of the electro-diffusion of ions in activated carbon porous electrodes is applied to describe the dynamic cycle of the capacitive mixing (CAPMIX) based on the double layer expansion (CDLE) technique to harvest renewable energy from salinity gradients. The model combines the electro-diffusion of ions with adsorption and desorption of charge and neutral salt into the double layers at the solid liquid interface, providing a comprehensive and accurate description of the full CAPMIX cycle experimentally measured in prototype cells. A careful analysis of the simulated cycles identifies key parameters for the optimization of the extracted power, like the appropriate thickness and micro-structure of the electrodes, best materials and operation conditions of the electrochemical cell. These directions will be fundamental in the development of this technique as an economically competitive renewable energy source.