def buildMetalIonDiffusionEquation(ionVar = None, distanceVar = None, depositionRate = 1, transientCoeff = 1, diffusionCoeff = 1, metalIonMolarVolume = 1): r""" The `MetalIonDiffusionEquation` solves the diffusion of the metal species with a source term at the electrolyte interface. The governing equation is given by, .. math:: \frac{\partial c}{\partial t} = \nabla \cdot D \nabla c where, .. math:: D = \begin{cases} D_c & \text{when $\phi > 0$} \\ 0 & \text{when $\phi \le 0$} \end{cases} The velocity of the interface generally has a linear dependence on ion concentration. The following boundary condition applies at the zero level set, .. math:: D \hat{n} \cdot \nabla c = \frac{v(c)}{\Omega} \qquad \text{at $phi = 0$} where .. math:: v(c) = c V_0 The test case below is for a 1D steady state problem. The solution is given by: .. math:: c(x) = \frac{c^{\infty}}{\Omega D / V_0 + L}\left(x - L\right) + c^{\infty} This is the test case, >>> from fipy.meshes.grid1D import Grid1D >>> nx = 11 >>> dx = 1. >>> from fipy.tools import serial >>> mesh = Grid1D(nx = nx, dx = dx, parallelModule=serial) >>> x, = mesh.getCellCenters() >>> from fipy.variables.cellVariable import CellVariable >>> ionVar = CellVariable(mesh = mesh, value = 1.) >>> from fipy.models.levelSet.distanceFunction.distanceVariable \ ... import DistanceVariable >>> disVar = DistanceVariable(mesh = mesh, ... value = (x - 0.5) - 0.99, ... hasOld = 1) >>> v = 1. >>> diffusion = 1. >>> omega = 1. >>> cinf = 1. >>> from fipy.boundaryConditions.fixedValue import FixedValue >>> eqn = buildMetalIonDiffusionEquation(ionVar = ionVar, ... distanceVar = disVar, ... depositionRate = v * ionVar, ... diffusionCoeff = diffusion, ... metalIonMolarVolume = omega) >>> bc = (FixedValue(mesh.getFacesRight(), cinf),) >>> for i in range(10): ... eqn.solve(ionVar, dt = 1000, boundaryConditions = bc) >>> L = (nx - 1) * dx - dx / 2 >>> gradient = cinf / (omega * diffusion / v + L) >>> answer = gradient * (x - L - dx * 3 / 2) + cinf >>> answer[x < dx] = 1 >>> print ionVar.allclose(answer) 1 :Parameters: - `ionVar`: The metal ion concentration variable. - `distanceVar`: A `DistanceVariable` object. - `depositionRate`: A float or a `CellVariable` representing the interface deposition rate. - `transientCoeff`: The transient coefficient. - `diffusionCoeff`: The diffusion coefficient - `metalIonMolarVolume`: Molar volume of the metal ions. """ eq = _buildLevelSetDiffusionEquation(ionVar = ionVar, distanceVar = distanceVar, transientCoeff = transientCoeff, diffusionCoeff = diffusionCoeff) coeff = _MetalIonSourceVariable(ionVar = ionVar, distanceVar = distanceVar, depositionRate = depositionRate, metalIonMolarVolume = metalIonMolarVolume) return eq + ImplicitSourceTerm(coeff)
def buildSurfactantBulkDiffusionEquation(bulkVar = None, distanceVar = None, surfactantVar = None, otherSurfactantVar = None, diffusionCoeff = None, transientCoeff = 1., rateConstant = None): r""" The `buildSurfactantBulkDiffusionEquation` function returns a bulk diffusion of a species with a source term for the jump from the bulk to an interface. The governing equation is given by, .. math:: \frac{\partial c}{\partial t} = \nabla \cdot D \nabla c where, .. math:: D = \begin{cases} D_c & \text{when $\phi > 0$} \\ 0 & \text{when $\phi \le 0$} \end{cases} The jump condition at the interface is defined by Langmuir adsorption. Langmuir adsorption essentially states that the ability for a species to jump from an electrolyte to an interface is proportional to the concentration in the electrolyte, available site density and a jump coefficient. The boundary condition at the interface is given by .. math:: D \hat{n} \cdot \nabla c = -k c (1 - \theta) \qquad \text{at $\phi = 0$}. :Parameters: - `bulkVar`: The bulk surfactant concentration variable. - `distanceVar`: A `DistanceVariable` object - `surfactantVar`: A `SurfactantVariable` object - `otherSurfactantVar`: Any other surfactants that may remove this one. - `diffusionCoeff`: A float or a `FaceVariable`. - `transientCoeff`: In general 1 is used. - `rateConstant`: The adsorption coefficient. """ spSourceTerm = ImplicitSourceTerm(_AdsorptionCoeff(rateConstant = rateConstant, distanceVar = distanceVar)) coeff = _ScAdsorptionCoeff(bulkVar = bulkVar, surfactantVar = surfactantVar, rateConstant = rateConstant, distanceVar = distanceVar) eq = _buildLevelSetDiffusionEquation(ionVar = bulkVar, distanceVar = distanceVar, diffusionCoeff = diffusionCoeff, transientCoeff = transientCoeff) if otherSurfactantVar is not None: otherCoeff = _ScAdsorptionCoeff(bulkVar = bulkVar, surfactantVar = otherSurfactantVar, rateConstant = rateConstant, distanceVar = distanceVar) else: otherCoeff = 0 return eq - coeff + spSourceTerm - otherCoeff