examples.levelSet.surfactant package¶
Submodules¶
examples.levelSet.surfactant.circle module¶
This example first imposes a circular distance function:
then the variable is advected with,
Also a surfactant is present of the interface, governed by the equation:
The result can be tested with the following code:
>>> surfactantBefore = numerix.sum(surfactantVariable * mesh.cellVolumes)
>>> from builtins import range
>>> for step in range(steps):
... distanceVariable.updateOld()
... surfactantEquation.solve(surfactantVariable, dt=1.)
... advectionEquation.solve(distanceVariable, dt = timeStepDuration)
>>> surfactantEquation.solve(surfactantVariable, dt=1.)
>>> surfactantAfter = numerix.sum(surfactantVariable * mesh.cellVolumes)
>>> print(surfactantBefore.allclose(surfactantAfter))
1
>>> areas = (distanceVariable.cellInterfaceAreas < 1e-6) * 1e+10 + distanceVariable.cellInterfaceAreas
>>> answer = initialSurfactantValue * initialRadius / (initialRadius + distanceToTravel)
>>> coverage = surfactantVariable * mesh.cellVolumes / areas
>>> error = (coverage / answer - 1)**2 * (coverage > 1e-3)
>>> print(numerix.sqrt(numerix.sum(error) / numerix.sum(error > 0)))
0.00813776069241
examples.levelSet.surfactant.expandingCircle module¶
This example represents an expanding circular interface with an initial coverage of surfactant. The rate of expansion is dependent on the coverage of surfactant, The governing equations are given by:
The solution for these set of equations is given by:
The following tests can be performed. First test for global conservation of surfactant:
>>> surfactantBefore = numerix.sum(surfactantVariable * mesh.cellVolumes)
>>> totalTime = 0
>>> steps = 5
>>> from builtins import range
>>> for step in range(steps):
... velocity.setValue(surfactantVariable.interfaceVar * k)
... distanceVariable.extendVariable(velocity)
... timeStepDuration = cfl * dx / velocity.max()
... distanceVariable.updateOld()
... advectionEquation.solve(distanceVariable, dt = timeStepDuration)
... surfactantEquation.solve(surfactantVariable, dt=1)
... totalTime += timeStepDuration
>>> surfactantEquation.solve(surfactantVariable, dt=1)
>>> surfactantAfter = numerix.sum(surfactantVariable * mesh.cellVolumes)
>>> print(surfactantBefore.allclose(surfactantAfter))
1
Next test for the correct local value of surfactant:
>>> finalRadius = numerix.sqrt(2 * k * initialRadius * initialSurfactantValue * totalTime + initialRadius**2)
>>> answer = initialSurfactantValue * initialRadius / finalRadius
>>> coverage = surfactantVariable.interfaceVar
>>> error = (coverage / answer - 1)**2 * (coverage > 1e-3)
>>> print(numerix.sqrt(numerix.sum(error) / numerix.sum(error > 0)) < 0.04)
1
Test for the correct position of the interface:
>>> x, y = mesh.cellCenters
>>> radius = numerix.sqrt((x - L / 2)**2 + (y - L / 2)**2)
>>> solution = radius - distanceVariable
>>> error = (solution / finalRadius - 1)**2 * (coverage > 1e-3)
>>> print(numerix.sqrt(numerix.sum(error) / numerix.sum(error > 0)) < 0.02)
1
examples.levelSet.surfactant.square module¶
This example advects a 2 by 2 initially square region outwards. The example checks for global conservation of surfactant.
Advect the interface and check the position.
>>> distanceVariable.calcDistanceFunction()
>>> initialSurfactant = numerix.sum(surfactantVariable)
>>> from builtins import range
>>> for step in range(steps):
... distanceVariable.updateOld()
... surfactantEquation.solve(surfactantVariable, dt=1)
... advectionEquation.solve(distanceVariable, dt = timeStepDuration)
>>> print(numerix.allclose(initialSurfactant, numerix.sum(surfactantVariable)))
1