def __init__( self, surfactantVar=None, distanceVar=None, bulkVar=None, rateConstant=None, otherVar=None, otherBulkVar=None, otherRateConstant=None, consumptionCoeff=None, ): """ Create a `AdsorbingSurfactantEquation` object. :Parameters: - `surfactantVar`: The `SurfactantVariable` to be solved for. - `distanceVar`: The `DistanceVariable` that marks the interface. - `bulkVar`: The value of the `surfactantVar` in the bulk. - `rateConstant`: The adsorption rate of the `surfactantVar`. - `otherVar`: Another `SurfactantVariable` with more surface affinity. - `otherBulkVar`: The value of the `otherVar` in the bulk. - `otherRateConstant`: The adsorption rate of the `otherVar`. - `consumptionCoeff`: The rate that the `surfactantVar` is consumed during deposition. """ SurfactantEquation.__init__(self, distanceVar=distanceVar) spCoeff = _AdsorptionCoeffInterfaceFlag(distanceVar, bulkVar, rateConstant) scCoeff = _AdsorptionCoeffAreaOverVolume(distanceVar, bulkVar, rateConstant) self.eq += ImplicitSourceTerm(spCoeff) - scCoeff self.coeffs = (scCoeff, spCoeff) if otherVar is not None: otherSpCoeff = _AdsorptionCoeffInterfaceFlag(distanceVar, otherBulkVar, otherRateConstant) otherScCoeff = _AdsorptionCoeffAreaOverVolume( distanceVar, -bulkVar * otherVar.getInterfaceVar(), rateConstant ) self.eq += ImplicitSourceTerm(otherSpCoeff) - otherScCoeff self.coeffs += (otherScCoeff,) self.coeffs += (otherSpCoeff,) vars = (surfactantVar, otherVar) else: vars = (surfactantVar,) spMaxCoeff = _SpMaxCoeff(distanceVar, vars) scMaxCoeff = _ScMaxCoeff(distanceVar, vars) self.eq += ImplicitSourceTerm(spMaxCoeff) - scMaxCoeff - 1e-40 if consumptionCoeff is not None: self.eq += ImplicitSourceTerm(consumptionCoeff)
def solve(self, var, boundaryConditions=(), solver=LinearPCGSolver(), dt = 1.): """ Builds and solves the `AdsorbingSurfactantEquation`'s linear system once. :Parameters: - `var`: A `SurfactantVariable` to be solved for. Provides the initial condition, the old value and holds the solution on completion. - `solver`: The iterative solver to be used to solve the linear system of equations. - `boundaryConditions`: A tuple of boundaryConditions. - `dt`: The time step size. """ for coeff in self.coeffs: coeff._updateDt(dt) SurfactantEquation.solve(self, var, boundaryConditions=boundaryConditions, solver=solver, dt=dt)
def sweep(self, var, solver=None, boundaryConditions=(), dt=1.0, underRelaxation=None, residualFn=None): r""" Builds and solves the `AdsorbingSurfactantEquation`'s linear system once. This method also recalculates and returns the residual as well as applying under-relaxation. :Parameters: - `var`: The variable to be solved for. Provides the initial condition, the old value and holds the solution on completion. - `solver`: The iterative solver to be used to solve the linear system of equations. - `boundaryConditions`: A tuple of boundaryConditions. - `dt`: The time step size. - `underRelaxation`: Usually a value between `0` and `1` or `None` in the case of no under-relaxation """ for coeff in self.coeffs: coeff._updateDt(dt) if solver is None: solver = DefaultAsymmetricSolver() return SurfactantEquation.sweep( self, var, solver=solver, boundaryConditions=boundaryConditions, dt=dt, underRelaxation=underRelaxation, residualFn=residualFn, )