Bookmark and Share FiPy: A Finite Volume PDE Solver Using Python
Version 3.0.1-dev139-ge5d2233

This Page

Contact

FiPy developers
Jonathan Guyer
Daniel Wheeler
James Warren

Join our mailing list

100 Bureau Drive, M/S 6555
Gaithersburg, MD 20899

301-975-5329 Telephone
301-975-4553 Facsimile

examples.levelSet.distanceFunction.mesh1DΒΆ

Create a level set variable in one dimension.

The level set variable calculates its value over the domain to be the distance from the zero level set. This can be represented succinctly in the following equation with a boundary condition at the zero level set such that,

\frac{\partial \phi}{\partial x} = 1

with the boundary condition, \phi = 0 at x = L / 2.

The solution to this problem will be demonstrated in the following script. Firstly, setup the parameters.

>>> from fipy import *
>>> dx = 0.5
>>> nx = 10

Construct the mesh.

>>> from fipy.tools import serialComm
>>> mesh = Grid1D(dx=dx, nx=nx, communicator=serialComm)

Construct a distanceVariable object.

>>> var = DistanceVariable(name='level set variable',
...                        mesh=mesh,
...                        value=-1.,
...                        hasOld=1)
>>> x = mesh.cellCenters[0]
>>> var.setValue(1, where=x > dx * nx / 2)

Once the initial positive and negative regions have been initialized the calcDistanceFunction() method can be used to recalculate var as a distance function from the zero level set.

>>> var.calcDistanceFunction() 

The problem can then be solved by executing the solve() method of the equation.

>>> if __name__ == '__main__':
...     viewer = Viewer(vars=var, datamin=-5., datamax=5.)
...     viewer.plot()

The result can be tested with the following commands.

>>> print numerix.allclose(var, x - dx * nx / 2) 
1