1 Introduction

Electrokinetic flows is a highly active topic of discussion branching over a multitude of scientific fields. Examples include chloride transport in reinforced concrete [13, 38], ion regulation in biological cells [20, 40], fuel cells [42] and electrochemical energy storage [23, 33], such as batteries and super-capacitors [17, 18, 32]. Consequently, the demand for the numerical modelling of electrokinetic flows, often due to complex geometries or multi-physics barring analytical solutions, spans a great deal of fields. While each real-world example given often comes with its own bespoke problems to consider, they are all describable as specific cases under a generalised model for electrokinetic flow problems. Therefore, the motivation for this paper is to lay the foundational work of a general-purpose open-source computational fluid dynamics (CFD) toolbox for the modelling of electrokinetic flows [11]. Built in a modular and sequential fashion so additional physics, like steric effects [14, 21, 37] or chemical activity [34], can be subsequently ’grafted’ onto the workflow and solved too. As such, we chose the finite-volume CFD package OpenFOAM® as our underlying CFD package for implementation.

With electrokinetic flows the involvement of electrical forces leads to a number of interesting phenomena. One such phenomenon is electro-osmosis [1], where an applied electric field induces fluid movement due to formation of electric double layers, see Fig. 2. Another interesting set of phenomena are known as induced-charge electrokinetics. Whilst similar to traditional electrokinetic phenomena, the difference comes from the double layer being induced by an applied electric field [36]. The main difficulty of modelling electrokinetic flows stems from the microscopic scale of phenomena. For applications with large scale domains, solving at the microscopic scale can be computationally taxing. For systems with complex geometries, such as porous media, this difficulty is furthered.

To describe electrokinetic flows we require modelling the ion concentrations, electric potential and fluid velocity, with the Stokes-Nernst-Planck-Poisson (SPNP) model. In this work, for the velocity field we will, in fact, consider Stokes’ flow as, at the micro- and meso-scale, the viscous forces far outweigh the inertial due to small velocities and length scale [35]. The Stokes equation is coupled with the Poisson’s equation for the electric potential, relating the electric fields composition to the variation in ion charge density. Finally these are both coupled with the Nernst-Planck equation to describe the ion transport. In using Nernst-Planck, we neglect any ion-ion interaction by assuming the ionic solution is sufficiently dilute.

The Nernst-Planck ionic flux was first formulated in its steady form for a one-dimensional cylinder by Nernst [26]. It was later extended by Planck [30] to a transient setting, furthermore introducing the continuity and Poisson’s equations [22]. In doing this the two paved the way in helping develop SPNP, providing a simple yet accurate description of electrokinetic flow for dilute solutions.

A common similarity in many applications containing electrokinetic flows is the involvement of multiple regions, such as fluid electrolyte and solid electrodes in batteries. These regions exchange ions with each other and in some instances contain chemical reactions exchanging mass between species. For batteries these reactions are a necessary process for operational use. However in examples such as chloride corrosion in reinforced concrete, it is a detriment [25]. As such, modelling these reactions has just as much importance as the flow they reside in.

Whilst used extensively in a wide range of physical settings by the research community, SPNP does come with its own caveats. For one, SPNP neglects any ion-ion interactions that may occur by assuming a dilute solution. This may not hold true for solutions with many ionic species [32]. Also, as SPNP is a continuum model, any steric effects are ignored. As such, many efforts have been made extending SPNP to be include other physical processes. To cover steric effects, free energy functionals using density functional theory (DFT) accounting for long-range Coulomb correlation and hard sphere (HS) interactions of ions [14, 21, 37] are formulated. Extensions to make Nernst-Planck more thermodynamically consistent under non-equilibrium thermodynamics [8, 18] have also been proposed. To model non-ideal solutions, [34] proposes an added term to the Nernst-Planck ionic flux considering varying chemical activities solved by the Debye-Hückel model.

Whilst these extensions do further the physical realism of the original SPNP model, this often exacerbates other challenges of SPNP. One of the foremost being the non-linear coupling between fields. For example, in [34] the Debye-Hückel model equates the chemical activity of a species to the solutions ionic strength. This in part creates explicit coupling between all ionic concentrations unlike in classic SPNP, resulting in more complex, often unviable, computational approaches.

The development of numerical solvers for such equations within general PDE and CFD toolboxes is something that has been discussed for decades.

Two common approaches can be taken to solve systems of coupled discretised equations. The first being the so-called block-coupled, with all equations solved at once in a large matrix. Whilst taking a large amount of memory, it upholds the coupling between fields and is numerically robust. The second is the segregated approach and consists in solving each equation separately and in sequence. Since this leads to a decoupling of the equations, appropriate iterative methods [27, 28] must be used to ensure coupling between fields. The advantages of a segregated approach are the lower memory requirements, easy preconditioning of the equations, and their multi-stage structure that allows a better control on the solution procedure. However, block-coupled approaches tend to scale better with the number of processors. When constructing our solvers to model electrokinetic flows, we chose a segregated iterative approach to couple the equations and the different domains.

This work presents a multi-region multi-species SPNP model and discusses its implementation in finite-volumes segregated solvers, built with the OpenFOAM® library and released open-source [11]. We present the mathematical model, including a dimensional analysis, and consider multiple solid and fluid regions, with general reaction and interface models.

Whilst other finite-volumes and finite-elements solvers have been developed [3, 19, 29, 39, 41], restrictions such as being designed for specific applications, single domains, dimensionality, absence of reactions, steady state or ignoring the fluid velocity are often made.

Another point of novelty also stems from a general non-linear reaction model, so that various reaction rate models such as Butler-Volmer [33] or the rate law [6] can be applied.

This work is organised in the following way. Within §2 we present the governing equations of Stokes-Poisson-Nernst-Planck and what fluid properties are assumed to gives accurate flow description. In §3 we perform dimensional analysis to understand the transport regimes possible and how this results in the often used electro-neutrality approximation. For §4 we outline what is required to capture reactions at a multi-region interface given different restriction on ion movement. In §5 the implementation of our solvers for single and multi-region is discussed, as well as the iterative algorithm performed when introducing our reactive conditions. To verify accuracy of our solvers and reactive conditions, we provide necessary numerical examples in §6, with concluding remarks given in §7.

2 Stokes-Poisson-Nernst-Planck model

Here we discuss the equations that make up Stokes-Poisson-Nernst-Planck, modelling the advective, diffusive and electrostatic forces of an ionic solution. As many real-world applications of electrochemistry involve interacting solids and fluids we consider a multi-domain scenario of a whole domain \(\Omega \) split, without loss of generality, into two sub-domains \(\Omega _{\text {f}}\), a fluid, and \(\Omega _{\text {s}}\), a solid, such that \(\Omega =\Omega _{\text {f}}\cup \Omega _{\text {s}}\), and with \(\Gamma \) being the solid–fluid interface and \(\partial \Omega =\partial \Omega _{\text {f}}\cup \partial \Omega _{\text {s}}\) the external boundaries. See Fig. 1 for a theoretical sketch of the domain \(\Omega \). More in general, in some applications and in our computational framework, we have allowed for an arbitrary number of solid and fluid regions, separated by different interfaces. We consider N ionic species, with concentrations and valencies \(c_i\) and \(z_i\) respectively, and \(i=1,...,N\). To describe the ionic transport we must define equations for the electric field \({\textbf {E}}\), ion concentrations \(c_i\) within \(\Omega \) and fluid velocity \({\textbf {u}}\) within \(\Omega _{\text {f}}\).

Fig. 1
figure 1

Graphical representation of the whole domain \(\Omega = \Omega _{\text {s}} \cup \Omega _{\text {f}}\) considering two sub-domains: \(\Omega _{\text {s}}\) a solid region (not necessarily connected), with external boundary \(\partial \Omega _{\text {s}}\); and, \(\Omega _{\text {f}}\) a fluid region with \(\partial \Omega _{\text {f}}\) external boundary such that \(\partial \Omega = \partial \Omega _{\text {s}}\cup \partial \Omega _{\text {f}}\). Solid–fluid interface denoted as \(\Gamma \)

2.1 Stokes’ flow

Consider \(\Omega _{\text {f}}\), with velocity profile \({\textbf {u}}({\textbf {x}},t)\) governing the advective dynamics of the ions. Assume a negligible Reynolds numbers \(\text {Re}\) defined by the fluid density \(\rho _{\text {f}}\), characteristic velocity U, characteristic length scale L and dynamic viscosity \(\mu \):

$$\begin{aligned} \text {Re}:= \frac{\rho _{\text {f}}L U}{\mu } \ll 1, \end{aligned}$$

such that viscous forces within \(\Omega _{\text {f}}\) outweigh the inertial. This common assumption in ionic transport [7, 15, 35] leads to linear Stokes flow. Furthermore we assume the fluid to be incompressible, i.e.,

$$\begin{aligned} \mu \nabla ^{2} {\textbf {u}}&= \varvec{\nabla }{p} - \rho _{\text {el}}{} {\textbf {E}},\quad {\textbf {x}}\in \Omega _{\text {f}}, \end{aligned}$$
(1)
$$\begin{aligned} \varvec{\nabla }\cdot {\textbf {u}}&=0, \quad {\textbf {x}}\in \Omega _{\text {f}}, \end{aligned}$$
(2)

where \(p=p({\textbf {x}},t)\), \(\rho _{\text {el}}=\rho _{\text {el}}({\textbf {x}},t)=F\sum \nolimits _{i=1}^{N}z_{i}c_{i}\) and \({\textbf {E}}\) are the static fluid pressure, electric charge density and electric field, respectively, and F is Faraday’s constant. Compared to the standard Stokes equation, we have the presence of the body force term \(\rho _{\text {el}}{} {\textbf {E}}\), describing the Coulomb forces acted on the fluid by the ions [15, 31]. We neglect any magnetic contribution by assuming our ions move slowly such that \({\textbf {E}}\) is irrotational, i.e. \(\varvec{\nabla }\times {\textbf {E}}={\textbf {0}}\). This body force term may be set to zero if the fluid is unaffected by \({\textbf {E}}\) or the fluid is approximated as electrically-neutral, \(\rho _{\text {el}}=0\). This will be further discussed in §3.

The first coupling term, between the variables \({\textbf {u}}\), \({\textbf {E}}\) and \(c_i\) appears here, showing one of the significant difficulties of describing electrokinetic flows. The coupling terms (particularly if non-linear) often add significant numerical difficulties. First of all, they make the velocity field time-dependent. Although by neglecting the time derivative we assume instantaneous relaxation to an equilibrium, and thereby a steady solution, by involving \(c_i({\textbf {x}},t)\) the relaxation becomes tied to the time scale of Nernst-Planck, which is order magnitudes different. For segregated approaches, the disparity of relaxation time scales between Stokes, Poisson and Nernst-Planck—leading to mixed parabolic-elliptic systems—can pose severe instability problems or slow convergence of the coupled system.

2.2 Poisson equation

To model the electric field \({\textbf {E}}\), neglecting magnetic forces, We may then write \({\textbf {E}}=-\varvec{\nabla }\phi \) and focus on the electric potential \(\phi =\phi ({\textbf {x}},t)\). Assume for each sub-domain their respective electric permittivity \(\varepsilon \) is spatially constant. From Maxwell’s equations we obtain Poisson’s electrostatic equation denoting variations in \(\phi \) by changes in the charge density \(\rho _{\text {el}}\),

$$\begin{aligned} \nabla ^{2}\phi = -\frac{\rho _{\text {el}}}{\varepsilon } = -\frac{F}{\varepsilon }\sum _{i=1}^N z_ic_i, \qquad {\textbf {x}}\in \Omega _{\{\text {f,s}\}}, \end{aligned}$$
(3)

where \(\varepsilon =\varepsilon _{\text {s}}\) in the solid and \(\varepsilon =\varepsilon _{\text {f}}\) in the fluid. Again we have direct coupling between our variables, here between \(c_i\) and \(\phi \), although this time the former appears linearly in the source term. Like for Stokes flow, this equation depends on time only through the source/coupling terms, in particular the time-dependent ionic concentration \(c_i({\textbf {x}},t)\).

2.3 Ionic transport

Assume the ionic fluid in \(\Omega _{\text {f}}\) is sufficiently dilute to ignore ion-ion interactions and diffusion is isotropic. Under these assumptions we may use the Nernst-Planck flux [10, 15, 22, 30] as

$$\begin{aligned} {\textbf {j}}_{i}{} & {} ={\textbf {j}}(c_i,\phi )\nonumber \\{} & {} = {\left\{ \begin{array}{ll} -D_{i\text {,s}}\left( \varvec{\nabla }c_{i} \right) &{} \qquad {\textbf {x}}\in \Omega _{\text {s}}, \\ -D_{i,\text {f}}\left( \varvec{\nabla }c_{i} + \frac{Fz_{i}}{RT}c_{i}\varvec{\nabla }\phi \right) + {\textbf {u}}c_i &{} \qquad {\textbf {x}}\in \Omega _{\text {f}}, \end{array}\right. } \end{aligned}$$
(4)

where denote R, T, \(D_{i,\text {f}}\) and \(D_{i,\text {s}}\) are, respectively, the ideal gas constant, absolute temperature and diffusion coefficient of species i in the fluid and in the solid. Taking Eq. (4) in conjunction with the continuity equation for mass conservation we arrive at the set of equations modelling transport of \(c_i\),

$$\begin{aligned} \frac{\partial c_i}{\partial t} + \varvec{\nabla }\cdot {\textbf {j}}_i =0, \qquad {\textbf {x}}\in \Omega _{\text {s,f}}. \end{aligned}$$
(5)

As mentioned, we assume a dilute solution to ignore ion-ion interactions. This may not hold true in some cases. Alternatively the Stefan-Maxwell equations [15, 16, 32] may be used in lieu of Nernst-Planck. In short, Stefan-Maxwell balances the driving forces exerted on a species with the frictional forces between species. This introduces cross diffusivities \(\mathcal {D}_{ij}\) describing the drag between species i and j due to these frictional forces [15]. The added complexity from such explicit coupling between species is difficult to describe, as the exact description of \(\mathcal {D}_{ij}\) is hard to determine [32]. Even in situations where the ionic fluid is bordering on dilute, it is common for Nernst-Planck to still be used [33] due to its simplicity.

To close the system of equations listed here, we must include conditions along the boundaries of \(\Omega _{\text {f}}\) and \(\Omega _{\text {s}}\). We briefly discuss some common choices below and their physical representation. We also require conditions at the interface \(\Gamma \) to describe interaction between sub-domains. This is discussed further below for \(c_i\) and \(\phi \) when considering reactions and (non-)conductive interfaces.

2.4 Boundary conditions

Below we list some relevant conditions for different physical situations often seen in electrokinetic problems:

  • Solid walls: Either a conductive or insulating wall. The no-penetration (\({\textbf {u}}\cdot {\textbf {n}}=0\), and zero normal stresses), where \({\textbf {n}}\) is the outward unit normal to the boundary, or no-slip condition (\({\textbf {u}}= {\textbf {0}}\)) may be used. Ions may not pass through the wall so their fluxes are zero (\({\textbf {j}}_i\cdot {\textbf {n}}=0\)). If conductive we impose a fixed normal current density \(I_\text {w}\) along the wall (\(\displaystyle {\textbf {i}}\cdot {\textbf {n}} = F\sum _i z_i{\textbf {j}}_i\cdot {\textbf {n}} = I_{\text {w}}\)) or fixed potential \(\phi _\text {w}\). If insulating (non-conductive) we may simply set \(I_\text {w}=0\).

  • Permeable membrane and reactive boundaries: For a membrane we may fix the flux of each species (\({\textbf {j}}_i\cdot {\textbf {n}}=j_{\text {m}}\)), non-zero for those capable of passing through, zero for who cannot. We will discuss the case of reactive boundaries later in §4.2.

  • Inlet/Outlet: Often used to model an in or outflow of fluid or ions. For a momentum driven inlet, pressure or flow velocity may be fixed (\({\textbf {u}}={\textbf {u}}_{\text {in}}\), \(p=p_{\text {in/out}}\)). For ions we may apply fixed fluxes (\({\textbf {j}}_i\cdot {\textbf {n}}=j_{\text {in/out}}\)), resulting in a fixed electric current (\(\displaystyle {\textbf {i}}\cdot {\textbf {n}} = I_{\text {in/out}}\)). More complicated is to determine suitable boundary conditions for the potential. Typically either a Dirichlet \(\phi =\phi _{\text {in/out}}\) or a Neumann condition can be imposed. The latter imposes the total electric current to be either equal to zero or a fixed value.

  • Periodicity: when dealing with large (quasi-)periodic (or homogeneous) structures, it is often impossible to solve for the entire domain of interest. In these cases, smaller representative unit cells can be solved with (quasi-)periodic external boundary conditions [5] are imposed. In these cases, an additional driving forces (as a bulk source term or a modification of the periodic BC) need to be added.

3 Dimensional analysis

When dealing with systems of coupled transport equations it is useful to perform a dimensional analysis to better understand the relationships between the different transport phenomena and identify the limiting regimes and possible approximations. We denote dimensionless variables with a hat symbol, e.g \({\hat{x}}\), and reference values with a bar unless stated otherwise. We use the reference values L, U, \({\bar{\phi }}\) and \({\bar{c}}_i\) for the length scale, velocity, electric potential and concentrations respectively. For pressure we take \({\bar{p}}=\frac{\mu U}{L}\) as this the appropriate form when under Stokes flow. For time, we take the diffusive timescale \({\bar{t}}=\frac{L^{2}}{D_{i}}\). With these choices and defining \({\bar{C}}=\displaystyle \frac{1}{2}\sum _{i=1}^{N}z_{i}^{2}\bar{c_i}\) as the reference total ionic strength, we obtain the dimensionless variables:

$$\begin{aligned}{} & {} {\hat{x}} = \frac{x}{L}, \quad {\hat{t}} = \frac{D_it}{L^2}, \quad \hat{ {\textbf {u}}} = \frac{ {\textbf {u}}}{U}, \quad {\hat{\phi }} = \frac{\phi }{{\bar{\phi }}}, \nonumber \\{} & {} \hat{c_{i}} = \frac{c_{i}}{\bar{c_i}}, \quad {\hat{p}} = \frac{pL}{\mu U}. \end{aligned}$$
(6)

Substituting these dimensionless variables into Eqs. (1), (3) and (5) the dimensionless system of equations are

$$\begin{aligned} \frac{D_i\bar{c_i}}{L^2}\frac{\partial \hat{c_{i}}}{\partial {\hat{t}}}{} & {} {+} \hat{\varvec{\nabla }}\cdot \left( -D_{i}\left( \frac{\bar{c_i}}{L^2}\hat{\varvec{\nabla }} \hat{c_{i}} {+} \frac{F{\bar{\phi }}\bar{c_i}}{L^{2}RT}{\hat{c}}_{i}z_{i}\hat{\varvec{\nabla }}{\hat{\phi }}\right) {+} \frac{U\bar{c_i}}{L}\hat{c_{i}}{\hat{{\textbf {u}}}}\right) {=}0, \nonumber \\ \end{aligned}$$
(7)
$$\begin{aligned} \frac{{\bar{\phi }}}{L^2}{\hat{\nabla }}^{2}{\hat{\phi }}{} & {} = -\frac{F}{\varepsilon }\sum _{i=1}^{N}z_i\hat{c_i}\bar{c_i}, \end{aligned}$$
(8)
$$\begin{aligned} \frac{\mu U}{L^{2}}{\hat{\nabla }}^{2}{\hat{{\textbf {u}}}}{} & {} = \frac{\mu U}{L^{2}}\hat{\varvec{\nabla }}{\hat{p}} + \frac{F{\bar{\phi }}}{L}\hat{\varvec{\nabla }}{\hat{\phi }}\sum _{i=1}^{N}z_{i}{\hat{c}}_{i}\bar{c_i}. \end{aligned}$$
(9)

The underlying dimensionless numbers may be found by dividing all other terms by the reference values of one term. For Eqs. (7) to (9) we divide by \(\frac{D_{i}\bar{c_i}}{L^{2}}\), \(\frac{2{\bar{C}}F}{\varepsilon }\) and \(\frac{2{\bar{C}}\mu U}{2{\bar{C}}L^{2}}\) respectively, where recall \({\bar{C}}\) is the reference ionic strength needed to resolve the issue of not being able to factor out the reference concentrations \({\bar{c}}_i\). As such, the dimensionless equations become:

$$\begin{aligned}&\frac{\partial \hat{c_i}}{\partial {\hat{t}}} + \hat{\varvec{\nabla }}\cdot \left( -\left( \hat{\varvec{\nabla }}\hat{c_{i}} + \mathcal {N}\hat{c_{i}}z_i\hat{\varvec{\nabla }}{\hat{\phi }}\right) +\text {Pe}_i {\hat{{\textbf {u}}}}\hat{c_{i}}\right) = 0, \end{aligned}$$
(10)
$$\begin{aligned}&\mathcal {L}^{2}{\hat{\nabla }}^{2}{\hat{\phi }} = -\frac{\sum _{i=1}^{N}\hat{c_i}\bar{c_{i}}z_{i}}{2{\bar{C}}}, \end{aligned}$$
(11)
$$\begin{aligned}&{\hat{\nabla }}^{2}{\hat{{\textbf {u}}}} = \hat{\varvec{\nabla }}{\hat{p}} + \frac{\mathcal {P}}{2{\bar{C}}}\sum _{i=1}^{N}\hat{c_i}\bar{c_{i}}z_{i}\hat{\varvec{\nabla }}{\hat{\phi }}, \end{aligned}$$
(12)

where we have defined four dimensionless numbers \(\mathcal {N}\), \(\text {Pe}\), \(\mathcal {L}\) and \(\mathcal {P}\). Note that whilst Eq. (7) had four terms, we only arrive at two numbers due to our choice of reference time. The same can be said with Eq. (12) and chosen reference pressure. The result, four numbers for the three equations with forms given in Eq. (13) as:

$$\begin{aligned} \mathcal {N}= & {} \frac{F{\bar{\phi }}}{RT} = \frac{e{\bar{\phi }}}{k_{\text {B}} T}, \quad \text {Pe}= \frac{UL}{D_i}, \nonumber \\ \mathcal {L}^2= & {} \frac{\varepsilon k_{\text {B}} T}{2N_{\text {A}} e^2 L^2 {\bar{C}}}, \quad \mathcal {P}= \frac{2FL{\bar{\phi }}{\bar{C}}}{\mu U}, \end{aligned}$$
(13)

written in terms of the aforementioned reference values, where we denote e, \(k_{\text {B}}\) and \(N_{\text {A}}\) to be the elementary charge, Boltzmann’s constant and Avogadro’s number respectively. \(\mathcal {N}\) represents the ratio of electrostatic over diffusive forces, with \(\mathcal {N}\ll 1\) indicating diffusion is dominant. We also obtain the Péclet number \(\text {Pe}\), i.e., the ratio of advective over diffusive phenomena, and \(\mathcal {L}= \frac{\lambda _{\text {D}}}{L}\) the dimensionless Debye length, with the dimensional form \(\lambda _{\text {D}}\) defined as

$$\begin{aligned} \lambda _{\text {D}} = \sqrt{\frac{\varepsilon k_{\text {B}}T}{2N_{A}e^2{\bar{C}}}}, \end{aligned}$$
(14)

approximating the distance at which a charge’s electrostatic effect persists. Typically \(\mathcal {L}\ll 1\), stating how the Debye length is much smaller than the reference length L. Finally we have \(\mathcal {P}\) denoting the ratio of viscous and electric forces upon our fluid. \(\lambda _{\text {D}}\) is also the approximate width of a common electrokinetic phenomena known as the electric double layer (EDL), see Fig. 2, that forms on boundaries. The EDL consists first of ions adsorbed at the boundary, known as the Stern layer, and another of free ions moved by electrical attraction and diffusive motion by the Stern layer, deemed the diffuse layer.

Fig. 2
figure 2

A graphical representation of the electric double layer along a positively charged surface, comprised of a thin layer of adsorbed negative ions (Stern layer) and loosely connected positive and negative ions (Diffuse layer)

For sufficiently thin EDLs there is a common model reduction known as the electro-neutrality assumption, often employed in development of macroscopic models [17, 33, 35]. This reduction can in fact be determined through dimensional analysis and will be briefly discussed next.

3.1 Asymptotics and electro-neutrality

The electro-neutrality approximation states that for a sufficiently dilute electrolyte all charges of ionic species within the solution roughly cancel each other out, leaving the solution electrically neutral. Electro-neutrality for a solution containing N species is defined as

$$\begin{aligned} \sum _{i=1}^{N}z_i c_i = 0, \end{aligned}$$
(15)

and is often used as model reduction when modelling ionic flows. Where Eq. (15) becomes invalid however is in the thin charged double layers, or EDL, mentioned above and often seen in real-world settings.

To get an understanding of where electro-neutrality comes from and how it relates to EDL formation, we perform an asymptotic analysis. Without any lack of generality, we limit here to a one-dimensional electrolyte and a binary electrolyte. In the numerical framework described above an arbitrary number of ionic species in three-dimensions can be considered. Let \(x \in \Xi \) where \(\Xi = [0,1]\) is a binary electrolyte solution with ionic concentrations \(c_1\) and \(c_2\) of opposing valencies. For now we omit any boundary conditions, only requiring those chosen result in a boundary layer formation near \(x=0\). To arrive at Eq. (15) we start by considering the asymptotics of the outer (bulk) layer away from \(x=0\). For simplicity we only consider the leading order terms.

Outer (bulk) layer To arrive at an asymptotic leading order solution in the bulk layer of \(\Xi \) we take the following expansions of \({\hat{u}}\), \({\hat{\phi }}\), \({\hat{p}}\), \(\hat{c_1}\) and \(\hat{c_2}\). These denote the fluid velocity, electric potential, pressure and ion concentrations respectively, all dimensionless. Expansions are taken in powers of \(\epsilon = \mathcal {L}^2\), the squared dimensionless Debye screening length since \(\epsilon \ll 1\), or, \(\lambda _{\text {D}} \ll L\):

$$\begin{aligned} {\hat{\phi }}{} & {} = \phi ^{(0)} + \epsilon \phi ^{(1)} + \mathcal {O}(\epsilon ^2), \end{aligned}$$
(16)
$$\begin{aligned} \hat{c_i}{} & {} = c_i^{(0)} + \epsilon c_i^{(1)} + \mathcal {O}(\epsilon ^2), \quad i=1,2, \end{aligned}$$
(17)
$$\begin{aligned} {\hat{u}}{} & {} = u^{(0)} + \epsilon u^{(1)} + \mathcal {O}(\epsilon ^2), \end{aligned}$$
(18)
$$\begin{aligned} {\hat{p}}{} & {} = p^{(0)} + \epsilon p^{(1)} + \mathcal {O}(\epsilon ^2). \end{aligned}$$
(19)

Substituting these expansions into the transport Eqs. (10)–(12) for one-dimension, alongside the incompressibility condition, we arrive at

$$\begin{aligned}{} & {} \mathcal {O}(\epsilon ^2) =\frac{\partial }{\partial t}\left( c_i^{(0)} + \epsilon c_i^{(1)}\right) + \frac{\partial }{\partial x}\bigg (\text {Pe}_i \left[ u^{(0)} + \epsilon u^{(1)}\right] \nonumber \\{} & {} \quad \left[ c_i^{(0)} + \epsilon c_i^{(1)}\right] - \frac{\partial }{\partial x}\left( c_i^{(0)} + \epsilon c_i^{(1)}\right) \nonumber \\{} & {} \quad - \mathcal {N}z_i\left( c_i^{(0)} +\epsilon c_i^{(1)}\right) \frac{\partial }{\partial x}\left( \phi ^{(0)} + \epsilon \phi ^{(1)}\right) \bigg ), \quad i=1,2, \end{aligned}$$
(20)
$$\begin{aligned}{} & {} \mathcal {O}(\epsilon ^2)=\epsilon \frac{\partial ^2 }{\partial x^2}\left( \phi ^{(0)} + \epsilon \phi ^{(1)}\right) +\frac{1}{2{\bar{C}}}\sum _{i=1}^2 z_i\bar{c_i}\left( c_i^{(0)} + \epsilon c_i^{(1)}\right) , \nonumber \\ \end{aligned}$$
(21)
$$\begin{aligned}{} & {} \mathcal {O}(\epsilon ^2)=-\frac{\partial ^2 }{\partial x^2}\left( u^{(0)} + \epsilon u^{(1)}\right) + \frac{\partial }{\partial x}\left( p^{(0)} + \epsilon p^{(1)}\right) \nonumber \\{} & {} \hspace{4em}+ \frac{\mathcal {P}}{2{\bar{C}}}\frac{\partial }{\partial x}\left( \phi ^{(0)} + \epsilon \phi ^{(1)}\right) \sum _{i=1}^2 z_i\bar{c_i}\left( c_i^{(0)} + \epsilon c_i^{(1)}\right) , \nonumber \\ \end{aligned}$$
(22)
$$\begin{aligned}{} & {} \mathcal {O}(\epsilon ^2)=\frac{\partial }{\partial x}\left( u^{(0)} +\epsilon u^{(1)}\right) . \end{aligned}$$
(23)

By considering only the leading order terms i.e., terms of \(\mathcal {O}(1)\), these equations reduce to,

$$\begin{aligned}{} & {} \frac{\partial }{\partial t}c_i^{(0)} + \frac{\partial }{\partial x}\left( \text {Pe}_i u^{(0)}c_i^{(0)} - \frac{\partial }{\partial x}c_i^{(0)} -\mathcal {N}z_ic_i^{(0)}\frac{\partial }{\partial x}\phi ^{(0)} \right) \nonumber \\{} & {} \quad = 0, \quad i=1,2, \end{aligned}$$
(24)
$$\begin{aligned}{} & {} 0= z_1\bar{c_1}c_1^{(0)} + z_2\bar{c_2}c_2^{(0)}, \end{aligned}$$
(25)
$$\begin{aligned}{} & {} \frac{\partial ^2 }{\partial x^2}u^{(0)} = \frac{\partial }{\partial x}p^{(0)}, \end{aligned}$$
(26)
$$\begin{aligned}{} & {} \frac{\partial }{\partial x}u^{(0)} =0. \end{aligned}$$
(27)

Note how Eq. (252627) is the electro-neutrality approximation mentioned before, for a binary solution, and a direct consequence of the asymptotics. This implies said electro-neutrality is only accurate up to leading order. What’s more the electric body force of Stokes vanishes as a consequence of Eq. (252627). To close the system an equation for the leading order potential \(\phi ^{(0)}\) is required. This is possible by multiplying Eq. (24) by their respective valencies \(z_i\) and reference values \(\bar{c_i}\), summing over i, and utilizing Eq. (252627). Resulting in the equation,

$$\begin{aligned}{} & {} \frac{\partial }{\partial x}\left( u^{(0)}\sum _i \text {Pe}_i z_i\bar{c_i} c_i^{(0)} - \sum _i z_i\bar{c_i}\frac{\partial }{\partial x}c_i^{(0)}\right. \nonumber \\{} & {} \quad \left. -\mathcal {N}\sum _i z_i^2 \bar{c_i}c_i^{(0)} \frac{\partial }{\partial x}\phi ^{(0)}\right) = 0, \end{aligned}$$
(28)

which represents a steady equation for \(\phi ^{(0)}\). This can be interpreted as a modified Ohm’s law with new conductivity accounting for all contributions to the total current: advective, diffusive and electrical, from left to right.

Now that we have constructed the asymptotic solution, up to \(\mathcal {O}(1)\), for the outer (bulk) layer of \(\Xi \), we move on to determine the inner (boundary) layer asymptotics. As mentioned at the start, we state said inner layer formation is near \(x=0\) of \(\Xi \). Much like the outer layer, we make no case of boundary conditions, only that a boundary layer near \(x=0\) forms as a result of them.

Inner solution:

To construct a solution for the inner layer near \(x=0\) of \(\Xi \) we define the variable y to span the inner layer and be a ’fast’ variable counterpart to x, changing more rapidly,

$$\begin{aligned} y = \frac{x}{\sqrt{\epsilon }}, \quad y \in [0,\infty ). \end{aligned}$$
(29)

By the definition of \(x\in \Xi \), y therefore has domain \([0,\infty )\), as \(y=0\) for \(x=0\) and \(y\rightarrow \infty \) for \(x\rightarrow 1\), since \(\epsilon \ll 1\). Such change of variable gives derivatives via chain rule as:

$$\begin{aligned} \frac{\partial }{\partial x} = \frac{1}{\sqrt{\epsilon }}\frac{\partial }{\partial y}, \quad \frac{\partial ^2 }{\partial x^2} = \frac{1}{\epsilon }\frac{\partial ^2 }{\partial y^2}. \end{aligned}$$
(30)

Substitution of the above derivatives into the original transport equations Eqs. (10)–(12) results in,

$$\begin{aligned}&\frac{\partial \hat{c_i}}{\partial {\hat{t}}} + \frac{1}{\sqrt{\epsilon }}\frac{\partial }{\partial y}\left( \text {Pe}_i {\hat{u}} \hat{c_i} -\frac{1}{\sqrt{\epsilon }}\frac{\partial \hat{c_i}}{\partial y} - \frac{1}{\sqrt{\epsilon }}\mathcal {N}z_i \hat{c_i}\frac{\partial {\hat{\phi }}}{\partial y}\right) = 0, \end{aligned}$$
(31)
$$\begin{aligned}&\frac{\partial ^2 {\hat{\phi }}}{\partial y^2} = -\frac{1}{2{\bar{C}}}\sum _{i=1}^2 z_i\bar{c_i}\hat{c_i}, \end{aligned}$$
(32)
$$\begin{aligned}&\frac{1}{\epsilon }\frac{\partial ^2 {\hat{u}}}{\partial y^2} = \frac{1}{\sqrt{\epsilon }}\frac{\partial {\hat{p}}}{\partial y} + \frac{1}{\sqrt{\epsilon }}\frac{\mathcal {P}}{2{\bar{C}}}\frac{\partial {\hat{\phi }}}{\partial y}\sum _{i=1}^2 z_i\bar{c_i}\hat{c_i}, \end{aligned}$$
(33)
$$\begin{aligned}&\frac{\partial {\hat{u}}}{\partial y} = 0, \end{aligned}$$
(34)

where all variables \({\hat{u}}\), \({\hat{p}}\), \({\hat{\phi }}\) and \(\hat{c_i}\) are in terms of y e.g., \(\hat{c_i} = \hat{c_i}(y,t)\). Just like the outer layer, we substitute the asymptotic expansions Eqs. (16)–(19) into the above equations to obtain,

$$\begin{aligned}&\frac{\partial }{\partial t}\left( c_i^{(0)} + \epsilon c_i^{(1)}\right) + \frac{1}{\sqrt{\epsilon }}\frac{\partial }{\partial y}\bigg (\text {Pe}_i\left[ u^{(0)} + \epsilon u^{(1)}\right] \left[ c_i^{(0)} + \epsilon c_i^{(1)}\right] \nonumber \\&\qquad -\frac{1}{\sqrt{\epsilon }}\frac{\partial }{\partial y}\left( c_i^{(0)} + \epsilon c_i^{(1)}\right) \nonumber \\&\qquad - \mathcal {N}z_i \frac{1}{\sqrt{\epsilon }}\left( c_i^{(0)} + \epsilon c_i^{(1)}\right) \frac{\partial }{\partial y}\left( \phi ^{(0)} + \epsilon \phi ^{(1)}\right) \bigg ) = \mathcal {O}(\epsilon ^2), \nonumber \\&\qquad i=1,2, \end{aligned}$$
(35)
$$\begin{aligned}&\frac{\partial ^2 }{\partial y^2}\left( \phi ^{(0)} + \epsilon \phi ^{(1)}\right) = -\frac{1}{2{\bar{C}}}\sum _{i=1}^2 z_i\bar{c_i}\left( c_i^{(0)} + \epsilon c_i^{(1)}\right) + \mathcal {O}(\epsilon ^2), \end{aligned}$$
(36)
$$\begin{aligned}&\frac{1}{\epsilon }\frac{\partial ^2 }{\partial y^2}\left( u^{(0)} + \epsilon u^{(1)}\right) = \frac{1}{\sqrt{\epsilon }}\frac{\partial }{\partial y}\left( p^{(0)} + \epsilon p^{(1)}\right) \nonumber \\&\qquad + \frac{1}{\sqrt{\epsilon }}\frac{\mathcal {P}}{2{\bar{C}}}\frac{\partial }{\partial y}\left( \phi ^{(0)} + \epsilon \phi ^{(1)}\right) \sum _{i=1}^2 z_i\bar{c_i}\left( c_i^{(0)} + \epsilon c_i^{(1)}\right) \nonumber \\&\qquad + \mathcal {O}(\epsilon ^2), \end{aligned}$$
(37)
$$\begin{aligned}&\frac{\partial }{\partial y}\left( u^{(0)} + \epsilon u^{(1)}\right) = \mathcal {O}(\epsilon ^2). \end{aligned}$$
(38)

Considering only the leading order terms of the four equations above we arrive at the following leading order set of equations for the inner layer:

$$\begin{aligned}{} & {} \frac{\partial }{\partial y}\left( -\frac{\partial }{\partial y}c_i^{(0)} -\mathcal {N}z_ic_i^{(0)}\frac{\partial }{\partial y}\phi ^{(0)}\right) =0, \quad i=1,2, \end{aligned}$$
(39)
$$\begin{aligned}{} & {} \frac{\partial ^2 }{\partial y^2}\phi ^{(0)} = -\frac{1}{2{\bar{C}}}\sum _{i=1}^2 z_i\bar{c_i}c_i^{(0)}, \end{aligned}$$
(40)
$$\begin{aligned}{} & {} \frac{\partial ^2 }{\partial y^2}u^{(0)} = 0, \end{aligned}$$
(41)
$$\begin{aligned}{} & {} \frac{\partial }{\partial y}u^{(0)} = 0. \end{aligned}$$
(42)

Like the outer layer equations, to close the system we need another equation, this time for \(p^{(0)}\). Considering the \(\mathcal {O}(\epsilon ^{(1/2)})\) terms of Eq. (37) we can retrieve such an equation as

$$\begin{aligned} \frac{\partial }{\partial y}p^{(0)} + \frac{\mathcal {P}}{2{\bar{C}}}\frac{\partial }{\partial y}\phi ^{(0)}\sum _{i=1}^2 z_i\bar{c_i}c_i^{(0)} = 0. \end{aligned}$$
(43)

As mentioned earlier, when considering situations involving multiple sub-domains we must also have appropriate interface conditions. In many real applications of electrokinetic flows there are chemical reactions at interfaces between sub-domains, exchanging mass across the ionic species involved. In these cases, neglecting the EDL might lead to significant errors. In the next section we will consider such reactions occurring on our interface \(\Gamma \), formulating appropriate conditions to capture them whilst retaining mass conservation.

4 Multi-domain formulation and reactions

Here we formulate conditions to model heterogeneous reactions which are crucial for many electrochemical and electrokinetic problems. We write a general reaction rate that ensures total mass conservation and apply it to form reactive interface conditions, where we consider the scenarios of species that exist in the whole domain (unrestricted) or only in a specific sub-domain (restricted). We then discuss conditions on \(\phi \) when the interface is conductive or non-conductive.

4.1 Reaction model

Consider a general elementary reaction transferring mass between reactants \(i=J,...,K\) and products \(i=K+1,...,M\) with exchanged molar masses \(B_{i}\) and valencies \(z_i\). We denote \(\nu _i>0\) to be the stoichiometric coefficients determining the number of moles of species i is lost or gained and n the number of released (\(n<0\)) or absorbed (\(n>0\)) electrons, alongside the electron mass \(e^{-}\). The mass balance of the reaction reads:

$$\begin{aligned} \sum _{i=J}^{K}\nu _{i}B_{i}&+ ne^{-} =\sum _{i=K+1}^{M}\nu _{i}B_{i}\,, \end{aligned}$$
(44)
$$\begin{aligned} n&=\sum _{i=K+1}^{M}z_{i}\nu _{i} - \sum _{i=J}^{K}\nu _{i}z_{i}. \end{aligned}$$
(45)

To formulate Eq. (44) as conditions on \(\Gamma \) we first determine the rate \(r_i\) at which each species in our reaction is exchanging mass. More complex reactions involving several intermediate reactions can be decomposed into elementary steps, i.e a set of elementary reactions. Typically the overall reaction rate is then given by the rate of the slowest elementary reaction [6]. One option to determine the rate is the law of mass action, also known as the rate law [2, 6]. Given an ideal solution and reaction involving chemical species [j] with stoichiometric coefficients \(\nu _{j}\), at dynamic equilibrium

$$\begin{aligned} \sum _{\text {reactants}}\nu _{j}[j] \rightleftharpoons \sum _{\text {products}}{\nu }_{j}[j], \end{aligned}$$
(46)

where the net reaction rate (density) \(r^\prime \) with units [mol/m\(^{2}\) s], is given by:

$$\begin{aligned} r^{\prime } = k_{\text {f}}\prod _{j}^{}\bigg (c_{j}^{\nu _{j}}\bigg )_{\text {reac}} - k_{r}\prod _{j}^{}\bigg (c_{j}^{\nu _{j}}\bigg )_{\text {prod}}. \end{aligned}$$
(47)

Here \(k_{\text {f}}\), \(k_{\text {r}}\) are the rate constants for the forward and reverse reaction and can be empirically modelled by the Arrhenius equation [6, 31]. Note that \(r^\prime \) is always positive, so we cannot simply take \(r_i=r^\prime \) as we must allow \(r_i< 0\) for reactant species. Instead, we define the coefficient \(\alpha _i\) as

$$\begin{aligned} \alpha _i = {\left\{ \begin{array}{ll} -1 &{} \text {reactants,} \\ +1 &{} \text {products,} \end{array}\right. } \end{aligned}$$
(48)

and, multiplying by \(r^\prime \) and \(\nu _i\), we obtain:

$$\begin{aligned} r_i= & {} \alpha _i \nu _i r^\prime = \alpha _i\nu _{i}\left( k_{\text {f}}\prod _{j=J}^{K}\bigg (c_{j}^{\nu _{j}}\bigg )_{\text {reac}} - k_{r}\prod _{j=K+1}^{M}\bigg (c_{j}^{\nu _{j}}\bigg )_{\text {prod}}\right) ,\nonumber \\ i= & {} J,...,M. \end{aligned}$$
(49)

For species not involved in the reaction we set \(r_i=0\). Assuming a closed reactive system, i.e no trace ion species, we can represent the mass conservation as the balance across reaction rates \(r_i\):

$$\begin{aligned} \sum _{i=1}^{N}m_i r_i = 0. \end{aligned}$$
(50)

We weight by the molar masses \(m_i\) to convert from moles (a non-conserved quantity between species) to grams. We use the rate law as the example here as it is valid for many reactions [6]. It is also the more general form for the commonly used Butler-Volmer equation for faradaic reactions, which uses the energy dependence of \(k_{\text {f}}\) and \(k_{\text {r}}\) to give explicit electric potential dependency. It is important to notice that the units of measure of the reaction rate are [mol/s] for bulk reaction and [m mol/s] for surface reactions. Therefore, for the case of linear reactions, the reaction constants \(k_i\) can be either [1/s] or [m/s].

4.2 Interface conditions

The reaction models above can be applied in the bulk or on a interface. Here we apply them on \(\Gamma \) for \(\phi \) and \(c_i\) given conductive or non-conductive interface and surface reactions respectively. We employ general reaction rates \(r_i\) to balance the ionic fluxes \({\textbf {j}}_i\) through \(\Gamma \) with mass exchanged by the reaction. For \(\phi \) we use conservation of charge to find conditions on the current passing through \(\Gamma \) when acting conductively or non-conductively.

4.2.1 Interface conditions for ions concentration

Here we outline reactive conditions along \(\Gamma \) to model Eq. (44). We use a set of general, possibly non-linear, reaction rates \(r_i\) for \(i=J,\dots ,M\) of ion species involved in Eq. (44). We make no assumptions on the form of \(r_i\), other than making sure Eq. (50) holds true. For species not involved we simply take flux continuity. the results is jump conditions in ionic flux between \(\Omega _{\text {s}}\) and \(\Omega _{\text {f}}\), equal to their respective reaction rates \(r_i\):

$$\begin{aligned} \bigg [{\textbf {j}}_i \cdot {\textbf {n}}\bigg ]^{\Gamma _{\text {s}}}_{\Gamma _{\text {f}}} = {\left\{ \begin{array}{ll} r_i &{} {\textbf {x}}\in \Gamma \text { for } i=J,...,M, \\ \\ 0 &{} {\textbf {x}}\in \Gamma \text { for } i\ne J,...,M. \end{array}\right. } \end{aligned}$$
(51)

Here we denote \(\big [{\textbf {j}}_i \cdot {\textbf {n}}\big ]_{\Gamma _{\text {f}}}\) to be the normal flux evaluated at \(\Gamma \) from \(\Omega _{\text {f}}\)’s side. Alongside this we assume continuity of concentrations to provide our second condition:

$$\begin{aligned} c_{i}\big |_{\Gamma _{\text {s}}} = c_{i}\big |_{\Gamma _{\text {f}}}, \quad {\textbf {x}}\in \Gamma . \end{aligned}$$
(52)

So, for all species involved in the reaction eq. (44) we have the difference in ionic flux from \(\Omega _{\text {s}}\) and \(\Omega _{\text {f}}\) to be the rate \(r_i\) of the respective species. In some scenarios one or more of the ion species may be restricted to reside in a single sub-domain of \(\Omega \). This can however be easily modelled by simply modifying the conditions of those restricted species, setting both \({\textbf {j}}_i\) and \(c_i\) to be zero in the inaccessible domains.

4.2.2 Interface conditions for the potential

We consider conditions for the electric potential \(\phi \) given two situations. Suppose our interface \(\Gamma \) is acting as a conductor such that we see a electric current flowing through. Assume we are under the most general case where all ion species are unrestricted. Conservation of charge and Ohm’s law then implies the change in current through \(\Gamma \) is proportional to the sum of changes in ionic fluxes:

$$\begin{aligned} F\sum _{i=1}^{N}z_{i}\bigg [{\textbf {j}}_i \cdot {\textbf {n}}\bigg ]^{\Gamma _{\text {s}}}_{\Gamma _{\text {f}}} = \bigg [\sigma \varvec{\nabla }\phi \cdot {\textbf {n}}\bigg ]^{\Gamma _{\text {s}}}_{\Gamma _{\text {f}}}, \quad {\textbf {x}}\in \Gamma . \end{aligned}$$
(53)

Here we denote \(\sigma \) to be the electric conductivity which is discontinuous across the interface. Alongside this we assume continuity of the potential:

$$\begin{aligned} \phi \big |_{\Gamma _{\text {s}}} = \phi \big |_{\Gamma _{\text {f}}}, \quad {\textbf {x}}\in \Gamma . \end{aligned}$$
(54)

We see therefore that the conditions on the current are closely linked to the previous reactive conditions. As if no reaction occurs at \(\Gamma \), we simply have continuity of current due to ionic flux continuity. If a reaction is present, then eq. (51) tells us our jump in current is proportional to the sum of reaction rates \(r_i\) alongside their respective charge numbers \(z_i\).

If \(\Gamma \) is non-conductive instead we fix separately the current on each side of \(\Gamma \) and no longer impose continuity:

$$\begin{aligned} F\sum _{i=1}^{N}z_{i}\big [{\textbf {j}}_i \cdot {\textbf {n}}\big ]_{\Gamma _{\text {f}}}{} & {} = \big [\sigma \varvec{\nabla }\phi \cdot {\textbf {n}}\big ]_{\Gamma _{\text {f}}},\quad {\textbf {x}}\in \Gamma , \end{aligned}$$
(55)
$$\begin{aligned} F\sum _{i=1}^{N}z_i \big [{\textbf {j}}_i \cdot {\textbf {n}}\big ]_{\Gamma _{\text {s}}}{} & {} =\big [\sigma \varvec{\nabla }\phi \cdot {\textbf {n}}\big ]_{\Gamma _{\text {s}}}, \quad {\textbf {x}}\in \Gamma . \end{aligned}$$
(56)

5 Numerical implementation

As we have mentioned our goal is to construct simple, effective numerical solvers to the Stoke-Poisson-Nernst-Planck (SPNP) model at the pore scale. To do so, we employ the computational fluid dynamics (CFD) package OpenFOAM® due to its open-source nature, large active community and robust handling of complex geometries. OpenFOAM® is a finite volume library for general unstructured mesh. Coupled equations are solved iteratively in a segregated/splitted approach, solving sequentially each discretised equation. This removes the explicit coupling between equations, as well as the need of linearising multi-linear terms (terms linear in each variable but where multiple variables appear) at the expense of having internal iterations. These would be unavoidable also if we adopted a monolithic approach due to the non-linearities of the model.

Two separate solvers have been implemented. The first, pnpFoam, models electrokinetic flow of a single ionic fluid, modelled by SPNP. The second, pnpMultiFoam, is more generalised, modelling a general set of ionic fluids and solids following SPNP and diffusion respectively. Furthermore we developed the numerical counterpart, named mappedChemicalKinetics, to the reactive conditions in §4.2.1 for the case of a binary reaction. In this section we will describe in detail the structure of the solvers and the corresponding boundary conditions.

5.1 Single- and multi-domain solvers

OpenFOAM® discretise each equation using a sparse matrix \({\textbf {M}}\) with entries relating to the cell centres of the mesh. For example, for the fluid momentum the discrete form reads:

$$\begin{aligned} {\textbf {M}}[{\textbf {u}}] = -\varvec{\nabla }p -\rho _{\text {el}}\varvec{\nabla }\phi , \end{aligned}$$
(57)

where \([{\textbf {u}}]\) is the vector of unknown velocities at cell centres and \({\textbf {M}}\) the coefficient matrix scaling the effect of neighbouring cell velocities. Note the right hand terms are left as source terms and are computed explicitly and the gradients operators can be discretised with different schemes (details about the schemes will be presented in the results section). To solve for the pressure–velocity coupling we employ the PIMPLE algorithm with an extra term due to the electric body force. This works by decomposing \({\textbf {M}}\) into its diagonal, A, and off-diagonal, \({\textbf {H}}\), parts \({\textbf {M}}[{\textbf {u}}] = A{\textbf {u}} - {\textbf {H}}\). This leads to the velocity correction equation:

$$\begin{aligned} {\textbf {u}} = \frac{{\textbf {H}}}{A} - \frac{1}{A}\varvec{\nabla }p - \frac{1}{A}\rho _{\text {el}}\varvec{\nabla }\phi . \end{aligned}$$
(58)

Interpolating \({\textbf {u}}\) to the cell faces and taking the dot product with cell face area vectors \({\textbf {S}}_{\text {f}}\) leads to the flux U correction equation,

$$\begin{aligned} U{} & {} = {\textbf {u}}_{\text {f}}\cdot {\textbf {S}}_{\text {f}} = \left( \frac{\varvec{H}}{A}\right) _{\text {f}}\cdot \varvec{S}_{\text {f}} - \left( \frac{1}{A}\right) _{\text {f}}\varvec{S}_{\text {f}}\cdot \varvec{\nabla }^{\perp }_{\text {f}}p^{n+1} \nonumber \\{} & {} \quad - \left( \frac{\rho _{\text {el}}\varvec{\nabla }\phi }{A}\right) _{\text {f}}\cdot \varvec{S}_{\text {f}}, \end{aligned}$$
(59)

where subscript \(\text {f}\) denotes values at cell faces. Discretising the incompressibility condition \(\varvec{\nabla }\cdot {\textbf {u}}=0\) gives \(\varvec{\nabla }\cdot U =0\) which when applied to the flux correction equation forms the pressure correction equation:

$$\begin{aligned} \varvec{\nabla }\cdot \left( \left[ \frac{{\textbf {H}}}{A}\right] _{\text {f}}\varvec{\nabla }p \right) = \varvec{\nabla }\cdot \left( \left[ \frac{{\textbf {H}}}{A}\right] _{\text {f}} - \left[ \frac{\rho _{\text {el}}\varvec{\nabla }\phi }{A}\right] _{\text {f}}\right) . \end{aligned}$$
(60)

This is solved iteratively until convergence. In an external loop, momentum and pressure equations are coupled with the concentration and potential equations. When the mesh is highly skewed, or for complex discretisation schemes with implicit-explicit terms, additional iterations can be added for each single equation. The pseudo-code algorithm for our single ionic fluid solver pnpFoam is presented in Algorithm 1.

figure a

The same method is employed within the algorithm of pnpMultiFoam, our solver for ionic transport over a general set of ionic fluids and solids, where each region is solved separately, and an additional outer loop is added to ensure the coupling between regions. The algorithm is presented in Algorithm 2. Both solvers here are presented for the case of non-electroneutral solution. In case the electroneutrality is assumed, the algorithm is slightly modified to solve a modified potential equation Eq. (28) (with ionic conductivity instead of permittivity) and with the last species calculated to ensure electro-neutrality.

5.2 Boundary and interface conditions

To make use of the object orientation of OpenFOAM® , all conditions are first reformulate as effective Robin conditions. We consider here, as an example, the inhomogeneous Robin BC for a variable c with coefficients \(D^\star \), \(K^\star \) and \(F^\star \) along a boundary \(\Gamma \) with normal \({\textbf {n}}\):

$$\begin{aligned} D^\star \varvec{\nabla }_{{\textbf {n}}}c|_{\Gamma } = -K^\star c|_{\Gamma } - F^\star . \end{aligned}$$
(61)

In OpenFOAM®   the boundary values \(c|_{\Gamma }\) and \(\varvec{\nabla }_{{\textbf {n}}}c|_{\Gamma }\) are approximated using the value of the cell centres with faces along \(\Gamma \):

$$\begin{aligned} c|_{\Gamma }&\approx \alpha _{1} c_{c} + \alpha _2, \end{aligned}$$
(62)
$$\begin{aligned} \varvec{\nabla }_{{\textbf {n}}}c|_{\Gamma }&\approx \alpha _3 c_{c} + \alpha _4 \approx B(c_{\text {f}} - c_{c})\,. \end{aligned}$$
(63)

Here \(c_{\text {c}}\) and \(c_{\text {f}}\) are the values of c at the cell centre and face respectively. The \(\alpha \)’s are the interpolation weights, and B is the inverse distance between the cell centre and the boundary. We can then rearrange Eq. (61) using Eqs. (62) and (63) to find the \(\alpha \) values that allow us to approximate Eq. (61) using the cell centres \(c_{\text {c}}\):

(64)

This forms the basis of the Robin BC implemented. Reformulating all other conditions into a form like Eq. (61) lets us reuse the same equations in Eq. (64) to approximate all other conditions.

The interface conditions are implemented as a derived class named mappedChemicalKinetics. If we consider here the limiting case of two reacting species \(c_{\text {s}}\) and \(c_{\text {f}}\), restricted to their respective sub-domains \(\Omega _{\text {s}}\) and \(\Omega _{\text {f}}\) respectively. Along the interface \(\Gamma \) connecting the two sub-domains is the reaction:

figure b
$$\begin{aligned} \beta _{\text {s}}X_{\text {s}} \leftrightarrow \beta _{\text {f}}X_{\text {f}}. \end{aligned}$$
(65)

The general reactive conditions eq. (51) in this case reduces to the following condition along \(\Gamma \):

$$\begin{aligned} {\textbf {j}}_{\text {f}}|_{\Gamma _{\text {f}}}\cdot {\textbf {n}} = {\textbf {j}}_{\text {s}}|_{\Gamma _{\text {s}}}\cdot {\textbf {n}} = r(c_{\text {f}}|_{\Gamma _{\text {f}}},c_{\text {s}}|_{\Gamma _{\text {s}}}), \end{aligned}$$
(66)

where we denote here \(\Gamma _{\text {s}}\) to be evaluation at the \(\Omega _{\text {s}}\) side of \(\Gamma \) and \({\textbf {n}}\) the unit normal of \(\Gamma \) facing into \(\Omega _{\text {f}}\). Note the reaction rate r is kept general and not necessarily linear. Equation 66 is solved iteratively using the Newton–Raphson method, linearised about the previous solution \({\textbf {c}}^{N} = (c_{\text {s}}^N \hspace{.5em} c_{\text {f}}^N)^\top \). Here the previous solution could be the solution at the previous time step (if an explicit time stepping is chosen) or at the previous internal iteration (for fully implicit time stepping). This allows us to rewrite Eq. (66) into two decoupled effective Robin conditions for \(c_{\text {s}}^{N+1}\) and \(c_{\text {f}}^{N+1}\) that we solve separately. The coupling between the two sides of the interface conditions (and therefore the two domains) is achieved through the internal iterations but, for stiff reactions, additional sub-looping to update both boundary values whenever one of the two domains is solved for. In Algorithm 3 we detail the mappedChemicalKinetics pseudo-code to solve the effective Robin conditions. As both resulting effective Robin conditions are solved in the same manner we only write here solving of the condition for \(c_{\text {f}}\).

More details about the linearisation can be found in Appendix A. Alongside the reactive conditions we have also implemented a number of simpler conditions, such as the continuity of total fluxes, continuity of value or continuity of derivatives, often used within applications. Just as with the non-linear reactive condition, we rewrite all conditions into effective Robin conditions.

figure c

6 Numerical examples

Here we present four numerical examples of electrokinetic flows. To verify accuracy of results we compare with the spectral Matlab® toolbox Chebfun [9] with machine-precision accuracy. The first case verifies accuracy of the flow description given a single ion species using a pressure-driven infinite ion channel similar to [4]. Next we verify accuracy when considering multiple ion species. Afterwards we verify the implemented reactive interface conditions counterpart to §4.2.1. The final case displays the capabilities of our solver(s), simulating ionic transport within a randomised solid–fluid porous medium.

To show spatial convergence of OpenFOAM® results we use the following normalised \(L^2\) error point norm. We use here the dummy variables v and \(v_{\text {cref}}\) to denote OpenFOAM® and Chebfun results respectively as an example:

$$\begin{aligned} L^2 \text {-norm error }=\frac{\Vert v - v_{\text {cref}}\Vert _2}{\Vert v_{\text {cref}}\Vert _2}. \end{aligned}$$
(67)

6.1 SPNP in an infinite channel

To verify pnpFoam and pnpMultiFoam for a single ion species take \(\Omega \), of length L, with two boundaries \(\Gamma _{\text {t}}\) and \(\Gamma _{\text {b}}\) denoting the top and bottom channel walls respectively. Take boundaries \(\Gamma _{\text {in}}\) and \(\Gamma _{\text {out}}\) denoting the inlet and outlet of fluid in \(\Omega \). To mathematically describe this channel as infinite in length we take periodic conditions on \(\Gamma _{\text {in}}\) and \(\Gamma _{\text {out}}\).

Fig. 3
figure 3

Graphical representation of the infinite ion channel with channel width H

Table 1 Dimensionless numbers, domain and transport properties for the SPNP equation in the infinite channel. We denote \(\varepsilon _0 = 8.85\times 10^{-12}\) to be the permittivity of vacuum
Fig. 4
figure 4

a Comparison of Chebfun (blue dots) and pnpFoam (red line) of the pressure, fluid velocity, ion concentration, and electric potential respectively, along the channel width i.e., in y. b \(L^2\) error norm convergence plot of pnpFoam results, showing spatial convergence of \(\mathcal {O}(N^{-1})\)

Take a monovalent ionic fluid, i.e a single ion species c with valency \(z=1\). Enforce a fixed external force \({\textbf {J}} =\bigg ({\begin{matrix} -\mu /H^2 \\ 0 \end{matrix}}\bigg )\) to induce transport across the channel length. To allow electro-migration of c between the two channel walls, fix \(\phi =0.1\) along \(\Gamma _{\text {t}}\) and \(\phi =0\) on \(\Gamma _{\text {b}}\). For c apply no-flux along \(\Gamma _{\text {t}}\) and \(\Gamma _{\text {b}}\), denoting \({\textbf {n}}\) to be the outward unit normal of either \(\Gamma _{\text {t}}\) or \(\Gamma _{\text {b}}\). We consider the channel at steady state and, by assuming L is sufficiently large, take all derivatives in x to be zero, i.e. \(\frac{\partial a}{\partial x}=0\) for \(a\in \{ {\textbf {u}}, \phi , c, p\}\). Just like Poiseuille flow we assume a uni-directional velocity, such that \({\textbf {u}}= \left( {\begin{matrix} u_1 \\ 0 \end{matrix}}\right) \). These assumptions in turn produce a one-dimensional reduce system of equations in y.

The SPNP system with a single ionic species in an infinite channel is considered with an added pressure-driven driving force \({\textbf {J}}\):

$$\begin{aligned}{} & {} \mu \nabla ^{2} {\textbf {u}}- {\textbf {J}} - \varvec{\nabla }p - Fc\varvec{\nabla }\phi = 0\,, \qquad {\textbf {x}}\in \Omega , \end{aligned}$$
(68)
$$\begin{aligned}{} & {} \varvec{\nabla }\cdot {\textbf {u}}=0\,, \qquad {\textbf {x}}\in \Omega , \end{aligned}$$
(69)
$$\begin{aligned}{} & {} \epsilon \nabla ^{2}\phi + Fc = 0 \,, \qquad {\textbf {x}}\in \Omega , \end{aligned}$$
(70)
$$\begin{aligned}{} & {} \varvec{\nabla }\cdot \left[ -D\left( \varvec{\nabla }c + \frac{F}{RT}c\varvec{\nabla }\phi \right) + {\textbf {u}}c\right] = 0\,, \qquad {\textbf {x}}\in \Omega , \end{aligned}$$
(71)
$$\begin{aligned}{} & {} {\textbf {u}}={\textbf {0}}\,, \quad \phi =0.05\,, \qquad {\textbf {x}}\in \Gamma _{\text {t}} \end{aligned}$$
(72)
$$\begin{aligned}{} & {} {\textbf {u}}={\textbf {0}}\,, \quad \phi =0\,, \qquad {\textbf {x}}\in \Gamma _{\text {b}} , \end{aligned}$$
(73)
$$\begin{aligned}{} & {} -D\bigg (\varvec{\nabla }_{{\textbf {n}}}c + \frac{F}{RT}c\varvec{\nabla }_{{\textbf {n}}}\phi \bigg ) + c {\textbf {u}}\cdot {\textbf {n}}=0\,, \qquad {\textbf {x}}\in \Gamma _{\text {b}}\cup \Gamma _{\text {t}} ,\nonumber \\ \end{aligned}$$
(74)
$$\begin{aligned}{} & {} {a}\bigg |_{\Gamma _{\text {in}}} = {a}\bigg |_{\Gamma _{\text {out}}}\,, \frac{\partial a}{\partial x}\bigg |_{\Gamma _{\text {in}}} = \frac{\partial a}{\partial x}\bigg |_{\Gamma _{\text {out}}}\,, \qquad a\in \{c, {\textbf {u}},\phi ,p\} .\nonumber \\ \end{aligned}$$
(75)

The complete system is solved in OpenFOAM® in a periodic channel, and compared with the equivalent one-dimensional model. By applying the assumptions of uni-directional flow and zero derivatives in x we obtain a one-dimensional reduced set of equations in y:

$$\begin{aligned}{} & {} \mu \frac{d^2 u_1}{d y^2} = -\frac{\mu }{H^2},\qquad {\textbf {x}}\in \Omega , \end{aligned}$$
(76)
$$\begin{aligned}{} & {} 0 = \frac{d p}{d y} + Fc\frac{d \phi }{d y}, \qquad {\textbf {x}}\in \Omega , \end{aligned}$$
(77)
$$\begin{aligned}{} & {} \varepsilon \frac{d^2 \phi }{d y^2} = -Fc, \qquad {\textbf {x}}\in \Omega , \end{aligned}$$
(78)
$$\begin{aligned}{} & {} 0 = \frac{d^2 c}{d y^2} + \frac{F}{RT}\left( \frac{d c}{d y}\frac{d \phi }{d y} + c\frac{d^2 \phi }{d y^2}\right) , \qquad {\textbf {x}}\in \Omega , \nonumber \\ \end{aligned}$$
(79)
$$\begin{aligned}{} & {} u_1 =0,\, \phi =0.05, \qquad {\textbf {x}}\in \Gamma _{\text {t}}, \end{aligned}$$
(80)
$$\begin{aligned}{} & {} u_1 =0,\, \phi =0, \qquad {\textbf {x}}\in \Gamma _{\text {b}}, \end{aligned}$$
(81)
$$\begin{aligned}{} & {} \frac{d c}{d y} + \frac{F}{RT}c\frac{d \phi }{d y} = 0, \qquad {\textbf {x}}\in \Gamma _{\text {b}}\cup \Gamma _{\text {t}}, \end{aligned}$$
(82)

where we excluded the incompressibility condition as this is trivially satisfied.

To compare results between Chebfun and our single ionic fluid solver pnpFoam we the following dimensionless numbers, geometrical parameters and transport properties, according to Table 1.

When running pnpFoam we solve it in steady state and take a large number of PIMPLE corrector iterations to insure convergence of the coupled system. The mesh used in OpenFOAM® is up to \(N=420\) cells (100 in x, 320 in y). Comparison of results and the \(L^{2}\) error norm convergence are shown in fig. 4. We observe an accumulation of c along \(\Gamma _{\text {b}}\), causing a large pressure gradient to form. sThe velocity profile follows a parabolic arc, as expected, whilst we see a non-linear profile for \(\phi \). Overall we find good agreement, with linear order spatial convergence \(\mathcal {O}(N^{-1})\).

Fig. 5
figure 5

a Results of \(c_1\) (left curve) and \(c_2\) (right) at \(t=1\times 10^{-5}\)s. Blue and red denote Chebfun and pnpFoam results respectively. Black is the initial condition. b Results of \(\phi \) for Chebfun (blue) and pnpFoam (red) at \(t=1\times 10^{-5}\)s, with initial condition in black. c \(L^2\) point error norm convergence plot, showing \(\mathcal {O}(N^{-1})\) spatial convergence of pnpFoam

6.2 Multi-component ionic fluid

To verify pnpFoam and pnpMultiFoam for a multi-component fluid we take two species \(c_1\) and \(c_2\) with opposite valencies \(z_1=-z_2=1\) over the domain \(\Omega \in [0,L]\) where \(L=1\times 10^{-6}\). We set a zero-flux BC, i.e., \(j(c_{i})=0\) at \(x=0,L\) for both species and fix \(\phi =0.1\) at \(x=L\) and \(\phi =0\) at \(x=0\). We fix here a constant velocity \( {\textbf {u}}=0.001\) for simplicity and we by-pass the solution of the Stokes system (frozenFlow flag). Concentrations and potential are initially set to \(c_i=1\times 10^{-3}\) and \(\phi =0.05(1-\cos {\frac{\pi x}{L}})\).

We consider here the dimensionless number values in Table 2, indicating electrostatic forces dominate. From \(\mathcal {L}\) we find the Debye length as approximately \(\lambda _{\text {D}} ={308}{\hbox {nm}}\). Since we are fixing \({\textbf {u}}\) and neglecting Stokes we have \(\mathcal {P}=0\).

Table 2 Dimensionless numbers and parameters for the multi-component ionic fluid testcase

When running pnpFoam we use a time step \(\Delta t=10^{-7}\)s, end time \(t=1\times 10^{-5}\)s, third-order implicit time scheme (backward keyword) and a mesh of up to \(N=1000\) cells. Results and \(L^{2}\) norm convergence plots are depicted in Sect. 6.3 where we find good agreement of results and linear spatial convergence of all fields.

We see the ions are transported to the outer walls due to the high electric potential gradient. Most of the ions then accumulate within \(\lambda _{\text {D}}\) from the walls forming two overlapping EDLs. Non-linear behaviour between \(c_i\) and \(\phi \) is observed through the slight shift in \(\phi \)’s profile due to the clustering of ions at the walls.

6.3 Reactive interface

Here we verify the accuracy of mappedChemicalKinetics, the numerical counterpart to the conditions found in §4.2.1. Consider the domain \(\Omega =\Omega _{\text {s}}\cup \Omega _{\text {f}}=[-1,1]\) split into fluid \(\Omega _{\text {f}}\in [-1,0]\) and solid \(\Omega _{\text {s}}\in [0,1]\), each containing the species \(c_{\text {f}}\) and \(c_{\text {s}}\) respectively. Both species are restricted to their respective sub-domain, i.e. \(c_{\text {s}}=0\) in \(\Omega _{\text {f}}\) and vice versa. Consider the following elementary reaction at the \(x=0\) interface: Figure. 5

$$\begin{aligned}{}[\text {s}] \leftrightharpoons [\text {f}]. \end{aligned}$$
(83)

As \(c_{\text {s}}\) and \(c_{\text {f}}\) are restricted to \(\Omega _{\text {s}}\) and \(\Omega _{\text {f}}\) respectively the reactive conditions of Eqs. (51) and (52) become

$$\begin{aligned} j(c_{\text {f}})&= j(c_{\text {s}}), \quad x=0, \end{aligned}$$
(84)
$$\begin{aligned} j(c_{\text {f}})&= k_{\text {f}} c_{\text {s}} - k_{\text {r}} c_{\text {f}}, \quad x=0, \end{aligned}$$
(85)

where we have used the linear rate law to model the reaction rate. Note \(c_{\text {f}}\) and \(c_{\text {s}}\) in Eqs. (84) and (85) are evaluated on \(\Omega _{\text {f}}\) and \(\Omega _{\text {s}}\)’s side of \(x=0\) respectively. We set both species as uncharged, i.e. \(z_i=0\), to remove electrostatic effects and \(u=1\) in \(\Omega _{\text {f}}\) to ignore Stokes. We initially set \(c_{\text {s}}=0\) in \(\Omega _{\text {s}}\) and \(c_{\text {f}} = e^{-200(x+0.5)^{2}}\) in \(\Omega _{\text {f}}\) so that a clear increase in \(c_{\text {s}}\) can be seen.

Table 3 Table of dimensionless values
Fig. 6
figure 6

Graphical representation of domain \(\Omega \) containing a solid and fluid with zero flux outer boundaries and reactive flux conditions at the shared interface

Looking at the dimensionless numbers for the problem in Table 3 we can notice here that advection dominates. We also include two more numbers from the reactive interface conditions at \(x=0\). These are \(\text {Da}_{\text {II,f}}\) and \(\text {Da}_{\text {II,r}}\), the Damköhler numbers given as the ratio between the diffusion rate and reaction rates, forward and reverse, respectively.

When running pnpMultiFoam to show qualitative comparison we use a time step \(\Delta t = 10^{-3}\)s, second-order implicit time scheme backwards and mesh discretisation of \(N=1000\) cells (500 in \(\Omega _{\text {f}}\), 500 in \(\Omega _{\text {s}}\)). To show convergence of results and compute the \(L^2\) error point norm we move to the steadyState time scheme to compare steady states. Results of the transient case are shown on the left in Fig. 7 where we find good agreement. First an initial diffusion and advection of \(c_{\text {f}}\) is seen towards the interface, once \(c_{\text {f}}\) reaches \(x=0\) it reacts to form \(c_{\text {s}}\) in \(\Omega _{\text {s}}\), where afterwards \(c_{\text {s}}\) diffuses through \(\Omega _{\text {s}}\). After \(t=15\)s a steady state is reached implying chemical equilibrium of the reaction. As for the \(L^{2}\) error norm of the steady case, seen in Fig. 7, we find a second-order convergence of mappedChemicalKinetics to Chebfun. This is because the interface conditions are linear and therefore exactly approximated by the linear approximation.

Fig. 7
figure 7

Left: Molar concentration results of \(c_{\text {f}}\) in fluid (dashed for pnpMultiFoam, markers for Chebfun) and \(c_{\text {s}}\) in solid (solid for pnpMultiFoam, markers for Chebfun). Blue for initial concentrations, black at intermediate times, red for final time (i.e steady state), Right: \(L^2\) norm convergence plot between Chebfun and mappedChemicalKinetics/pnpMultiFoam

6.4 Random porous REV

To demonstrate the capabilities of our solvers, we consider a randomly generated porous solid–fluid domain \(\Omega =\Omega _{\text {s}}\cup \Omega _{\text {f}}\), see Fig. 8. The random generation is done by a truncated Gaussian random field [12, 24], sampled at the mesh points and categorised into two bins, denoting solid and fluid cells, by a threshold. Raising or lowering this threshold alters the porosity of the domain.

To have \(\Omega \) be a microscopic representative elementary volume (REV) of a much larger macroscopic porous medium, we apply periodic conditions along the outer boundaries \(\Gamma _{\text {ext}}= \Gamma _{\text {in}}\cup \Gamma _{\text {out}}\cup \Gamma _{\text {t}}\cup \Gamma _{\text {b}}\). To generate movement, we fix a jump in \(\phi \) between \(\Gamma _{\text {in,s}}\) and \(\Gamma _{\text {out,s}}\), where the subscript s denotes the section of \(\Gamma _{\text {in}}\) neighbouring \(\Omega _{\text {s}}\). This is to mimic a fixed applied potential difference across the macroscopic medium, such as an applied voltage across a battery cell. We consider two ion species \(c_1\) and \(c_2\) with opposite valencies \(z_1=-z_2=-1\). The height and length of the region is set as \(H=1\times 10^{-4}\)m.

In \(\Omega _{\text {f}}\) we start with a uniform concentration of \(c_2\), the same is done for \(\Omega _{\text {s}}\) with \(c_1\). Fluid is initially taken at rest. Along \(\Gamma _{\text {sf}}\) we set no flux for \(c_1\) and flux continuity for \(c_2\). For \(\phi \) we assume continuity of the electric displacement \({\textbf {D}}=\varepsilon {\textbf {E}}\) along \(\Gamma _{\text {sf}}\). In Table 4 we list the dimensionless number values of the case.

The system is initialised with constant \(c_1\) and \(c_2\) in \(\Omega _{\text {f}}\) and \(\Omega _{\text {s}}\) respectively. All fields are periodic on the outer boundaries \(\Gamma _{\text {ext}}=\Gamma _{\text {in}}\cup \Gamma _{\text {out}}\cup \Gamma _{\text {t}}\cup \Gamma _{\text {b}}\), apart from \(\phi \) where we introduce a quasi-periodic condition with a fixed jump between \(\Gamma _{\text {in,s}}\) and \(\Gamma _{\text {out,s}}\), denoting the parts of \(\Gamma _{\text {in}}\) and \(\Gamma _{\text {out}}\) neighbouring \(\Omega _{\text {s}}\). We apply no flux and flux continuity for \(c_1\) and \(c_{\text {s}}\) along \(\Gamma _{\text {sf}}\) respectively. For \(\phi \) we assume continuity of the electric displacement \({\textbf {D}}=\varepsilon {\textbf {E}}\) along \(\Gamma _{\text {sf}}\):

$$\begin{aligned}{} & {} c_{1}({\textbf {x}},0) {=} 0,\!\quad c_{2}({\textbf {x}},0) {=} 1\times 10^{-8},\!\quad \phi ({\textbf {x}},0){=}0, \quad {\textbf {x}}\in \Omega _{\text {s}}; \nonumber \\ \end{aligned}$$
(86)
$$\begin{aligned}{} & {} c_{1}({\textbf {x}},0) = 1\times 10^{-8}\,,\quad c_{2}({\textbf {x}},0) = 0\,,\quad \phi ({\textbf {x}},0)=0\,,\nonumber \\{} & {} {\textbf {u}}({\textbf {x}},0)={\textbf {0}}\,,\quad p({\textbf {x}},0)=0, \quad {\textbf {x}}\in \Omega _{\text {f}}; \nonumber \\ \end{aligned}$$
(87)
$$\begin{aligned}{} & {} \bigg [\varvec{\nabla }_{{\textbf {n}}}a\bigg ]^{\Gamma _{\text {in,s}}}_{\Gamma _{\text {out,s}}} =0 \,,\quad \bigg [a\bigg ]^{\Gamma _{\text {in,s}}}_{\Gamma _{\text {out,s}}} =0\,,\nonumber \\{} & {} \bigg [\varvec{\nabla }_{{\textbf {n}}}\phi \bigg ]^{\Gamma _{\text {in,s}}}_{\Gamma _{\text {out,s}}} = 0\,,\quad \bigg [\phi \bigg ]^{\Gamma _{\text {in,s}}}_{\Gamma _{\text {out,s}}} = 1\times 10^{-2}, \quad a\in \{c_{1},c_{2}\};\nonumber \\ \end{aligned}$$
(88)
$$\begin{aligned}{} & {} \bigg [\varvec{\nabla }_{{\textbf {n}}}a\bigg ]^{\Gamma _{\text {in,f}}}_{\Gamma _{out,f}} =0 \,,\quad \bigg [a\bigg ]^{\Gamma _{\text {in,f}}}_{\Gamma _{out,f}} =0, \quad a\in \{c_{1},c_{2},\phi ,p,{\textbf {u}}\}; \nonumber \\ \end{aligned}$$
(89)
$$\begin{aligned}{} & {} \bigg [\varvec{\nabla }_{{\textbf {n}}}a\bigg ]^{\Gamma _{\text {t}}}_{\Gamma _{\text {b}}} =0 \,,\quad \bigg [a\bigg ]^{\Gamma _{\text {t}}}_{\Gamma _{\text {b}}} =0, \quad a\in \{c_{1},c_{2},\phi ,p,{\textbf {u}}\} ; \nonumber \\ \end{aligned}$$
(90)
$$\begin{aligned}{} & {} {\textbf {j}}_{1}\cdot {\textbf {n}} = 0\,,\quad \bigg [{\textbf {j}}_{2}\cdot {\textbf {n}}\bigg ]^{\Gamma _{\text {sf,f}}}_{\Gamma _{\text {sf,s}}}=0\,,\quad \varvec{\nabla }p\cdot {\textbf {n}}=0\,,\quad {\textbf {u}}\cdot {\textbf {n}}=0\,,\nonumber \\{} & {} \bigg [\varepsilon \varvec{\nabla }_{{\textbf {n}}}\phi \bigg ]^{\Gamma _{\text {sf,f}}}_{\Gamma _{\text {sf,s}}}=0, \quad {\textbf {x}}\in \Gamma _{\text {sf}}.\nonumber \\ \end{aligned}$$
(91)
Fig. 8
figure 8

Visual representation of the random porous domain containing solid \(\Omega _{\text {s}}\) (grey) and fluid \(\Omega _{\text {f}}\) (white) with shared interface \(\Gamma _{\text {sf}}\)

To show consistency in the results we run four simulations in total. This is done for two randomly generated meshes, each discretised over two levels of refinement for \(N=1\times 10^{4}\) and \(N=4\times 10^{4}\) cells. We will use letters A and B to differentiate between the random generations and subscripts 1 and 2 for the levels of refinement. E.g, \(A_{2}\) denotes the first random mesh, refined using \(4\times 10^{4}\) cells. All runs use a time step \(\Delta t = 5\times 10^{-4}\) and second-order implicit time scheme backwards. To observe the advective and electrostatic effects on our ions we define the following velocities in \(\Omega _{\text {f}}\):

$$\begin{aligned} {\textbf {v}}_{i} = {\textbf {u}}- \frac{D_i z_i F}{RT}\varvec{\nabla }\phi , \end{aligned}$$
(92)

such that the continuity Eq. (5) in \(\Omega _{\text {f}}\) may be written as

$$\begin{aligned} \frac{\partial c_i}{\partial t} + \varvec{\nabla }\cdot \left( {\textbf {v}}_i c_i - D_{i}\varvec{\nabla }c_i\right) = 0. \end{aligned}$$
(93)
Table 4 Dimensionless numbers for the random porous media testcase
Fig. 9
figure 9

Results of the first random solid–fluid geometry, discretised using \(4\times 10^{4}\) cells. af Profiles of \(c_1\) and \(c_2\) at \(t=0.3\), 1, 2s within \(\Omega _{\text {f}}\). gi Profiles of \(c_2\) at \(t=0.3\), 1, 2s within \(\Omega _{\text {s}}\). jl Profiles of \(||{\textbf {v}}_1||\), \(||{\textbf {v}}_2||\) and \(\phi \) at \(t=2\)s

Fig. 10
figure 10

Results of the first random solid–fluid geometry, discretised using \(N=1\times 10^{4}\) cells. Top two rows: Profiles of \(c_1\) and \(c_2\) at \(t=0.3\), 1, 2s within \(\Omega _{\text {f}}\). Third row: Profiles of \(c_2\) at \(t=0.3\), 1, 2s within \(\Omega _{\text {s}}\). Bottom row: Profiles of \(||{\textbf {u}}_1||\), \(||{\textbf {u}}_2||\) and \(\phi \) at \(t=2\)s

Figure 9 shows the results of the first random realisation with a finer mesh (\(N=4\times 10 ^{4}\)), where we observe a gradient in \(\phi \) formed between regions of \(\Omega _{\text {s}}\) connected at \(\Gamma _{\text {in}}\) and \(\Gamma _{\text {out}}\). This is primarily due to our jump condition for \(\phi \) applied along \(\Gamma _{\text {in,s}}\) and \(\Gamma _{\text {out,s}}\). Whilst movement of our ion species have an effect on this gradient, for the most part it remains steady. The applied electrical driving force causes the uniform concentration \(c_1\) in \(\Omega _{\text {f}}\) to accumulate around the regions of \(\Omega _{\text {s}}\) connected at \(\Gamma _{\text {out}}\), where a higher electric potential is present. Conversely, around \(\Omega _{\text {s}}\) connected at \(\Gamma _{\text {in}}\) we find a much lower, but not zero, concentration of \(c_1\). A similar observation is found with \(c_2\), once diffused out of \(\Omega _{\text {s}}\), accumulating where there is a lower potential. As with \(c_1\), at the region of \(\Omega _{\text {s}}\) connected at \(\Gamma _{\text {out}}\) there is a much lower, but again not zero, concentration of \(c_2\). We observe therefore the formation of EDL’s, see §3, around these connected solids. Given more time to evolve these EDL’s would become further apparent, with more of \(c_2\) diffusing out of \(\Omega _{\text {s}}\). As for \({\textbf {v}}_1\) and \({\textbf {v}}_2\) we find their magnitudes \(||{\textbf {v}}_1||\) and \(||{\textbf {v}}_2||\) are highest within these EDL’s located at the connected solids due to higher gradients in \(\phi \).

We can compare these results with coarse mesh (\(N=1\times 10 ^{4}\)) results as well as with other random generation seed. Results of first realisation with a coarse mesh, and of a coarse and fine simulation of a second random realisation are reported respectively in Figs. 10,  11, and  12.

Fig. 11
figure 11

Results of the second random solid–fluid geometry, discretised using \(N=1\times 10^{4}\) cells. Top two rows: Profiles of \(c_1\) and \(c_2\) at \(t=0.3\), 1, 2s within \(\Omega _{\text {f}}\). Third row: Profiles of \(c_2\) at \(t=0.3\), 1, 2s within \(\Omega _{\text {s}}\). Bottom row: Profiles of \(||{\textbf {u}}_1||\), \(||{\textbf {u}}_2||\) and \(\phi \) at \(t=2\)s

Fig. 12
figure 12

Results of the second random solid–fluid geometry, discretised using \(N=4\times 10^{4}\) cells. Top two rows: Profiles of \(c_1\) and \(c_2\) at \(t=0.3\), 1, 2s within \(\Omega _{\text {f}}\). Third row: Profiles of \(c_2\) at \(t=0.3\), 1, 2s within \(\Omega _{\text {s}}\). Bottom row: Profiles of \(||{\textbf {u}}_1||\), \(||{\textbf {u}}_2||\) and \(\phi \) at \(t=2\)s

7 Conclusions

In this paper we present the development of open-source solvers in OpenFOAM® capable of simulating microscopic electrokinetic flows of dilute ionic fluids. The underlying system, known as Stokes-Poisson-Nernst-Planck, is thoroughly reviewed where we discuss the assumptions on the fluid properties and limitations these bring. We later apply dimensional analysis to characterise the effects of dominating physical forces. This analysis is later used to give better understanding to a common model reduction, known as the electro-neutrality assumption, as a result of such analysis.

Many real-world applications of these flows involve some form of reactions between involved ionic species at the interface between fluid and solid. As such, we formulate a fully general reaction model capable of describing said heterogeneous reactions as a balance of fluxes across all reacting species.

To verify flow descriptions obtained from our solvers are accurate, we compare against highly accurate solutions obtained, for simplified cases, with the Matlab toolbox Chebfun for a number of cases. With each case we find good agreement, showing spatial grid convergence of the results. We later use our solvers across a randomly generated solid–fluid porous cell, similar to a representative elementary volume (REV) used in homogenisation theory, to show the solvers ability in handling complex micro-structures.

In the future we plan on constructing full physically realistic cases, such as modelling the electrokinetic flow through a porous battery half-cell. Furthermore we later plan to apply uncertainty quantification in conjunction with these randomly generated porous cells, quantifying the effects on the flow for varying geometrical properties.