FiPy: A Finite Volume PDE Solver Using Python
Version 2.1.3

Previous topic

steppers Package Documentation

Next topic

test Module Documentation

Contact

FiPy developers
Jonathan Guyer
Daniel Wheeler
James Warren

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

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

terms Package Documentation¶

The cellTerm Module¶

class fipy.terms.cellTerm.CellTerm(coeff=1.0)

Bases: fipy.terms.term.Term

Attention

This class is abstract. Always create one of its subclasses.

The centralDiffConvectionTerm Module¶

class fipy.terms.centralDiffConvectionTerm.CentralDifferenceConvectionTerm(coeff=1.0, diffusionTerm=None)

This Term represents

where and is calculated using the central differencing scheme. For further details see Numerical Schemes.

Create a ConvectionTerm object.

>>> from fipy.meshes.grid1D import Grid1D
>>> from fipy.variables.cellVariable import CellVariable
>>> from fipy.variables.faceVariable import FaceVariable
>>> m = Grid1D(nx = 2)
>>> cv = CellVariable(mesh = m)
>>> fv = FaceVariable(mesh = m)
>>> vcv = CellVariable(mesh=m, rank=1)
>>> vfv = FaceVariable(mesh=m, rank=1)
>>> __ConvectionTerm(coeff = cv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> __ConvectionTerm(coeff = fv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> __ConvectionTerm(coeff = vcv)
__ConvectionTerm(coeff=_ArithmeticCellToFaceVariable(value=array([[ 0.,  0.,  0.]]), mesh=UniformGrid1D(dx=1.0, nx=2)))
>>> __ConvectionTerm(coeff = vfv)
__ConvectionTerm(coeff=FaceVariable(value=array([[ 0.,  0.,  0.]]), mesh=UniformGrid1D(dx=1.0, nx=2)))
>>> __ConvectionTerm(coeff = (1,))
__ConvectionTerm(coeff=(1,))
>>> from fipy.terms.explicitUpwindConvectionTerm import ExplicitUpwindConvectionTerm
>>> ExplicitUpwindConvectionTerm(coeff = (0,)).solve(var = cv)
>>> ExplicitUpwindConvectionTerm(coeff = 1).solve(var = cv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> from fipy.meshes.grid2D import Grid2D
>>> m2 = Grid2D(nx=2, ny=1)
>>> cv2 = CellVariable(mesh=m2)
>>> vcv2 = CellVariable(mesh=m2, rank=1)
>>> vfv2 = FaceVariable(mesh=m2, rank=1)
>>> __ConvectionTerm(coeff=vcv2)
__ConvectionTerm(coeff=_ArithmeticCellToFaceVariable(value=array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.]]), mesh=UniformGrid2D(dx=1.0, nx=2, dy=1.0, ny=1)))
>>> __ConvectionTerm(coeff=vfv2)
__ConvectionTerm(coeff=FaceVariable(value=array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.]]), mesh=UniformGrid2D(dx=1.0, nx=2, dy=1.0, ny=1)))
>>> ExplicitUpwindConvectionTerm(coeff = ((0,),(0,))).solve(var=cv2)
>>> ExplicitUpwindConvectionTerm(coeff = (0,0)).solve(var=cv2)

Parameters : coeff : The Term‘s coefficient value. diffusionTerm : deprecated. The Peclet number is calculated automatically.

The convectionTerm Module¶

class fipy.terms.convectionTerm.ConvectionTerm(coeff=1.0, diffusionTerm=None)

Attention

This class is abstract. Always create one of its subclasses.

Create a ConvectionTerm object.

>>> from fipy.meshes.grid1D import Grid1D
>>> from fipy.variables.cellVariable import CellVariable
>>> from fipy.variables.faceVariable import FaceVariable
>>> m = Grid1D(nx = 2)
>>> cv = CellVariable(mesh = m)
>>> fv = FaceVariable(mesh = m)
>>> vcv = CellVariable(mesh=m, rank=1)
>>> vfv = FaceVariable(mesh=m, rank=1)
>>> __ConvectionTerm(coeff = cv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> __ConvectionTerm(coeff = fv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> __ConvectionTerm(coeff = vcv)
__ConvectionTerm(coeff=_ArithmeticCellToFaceVariable(value=array([[ 0.,  0.,  0.]]), mesh=UniformGrid1D(dx=1.0, nx=2)))
>>> __ConvectionTerm(coeff = vfv)
__ConvectionTerm(coeff=FaceVariable(value=array([[ 0.,  0.,  0.]]), mesh=UniformGrid1D(dx=1.0, nx=2)))
>>> __ConvectionTerm(coeff = (1,))
__ConvectionTerm(coeff=(1,))
>>> from fipy.terms.explicitUpwindConvectionTerm import ExplicitUpwindConvectionTerm
>>> ExplicitUpwindConvectionTerm(coeff = (0,)).solve(var = cv)
>>> ExplicitUpwindConvectionTerm(coeff = 1).solve(var = cv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> from fipy.meshes.grid2D import Grid2D
>>> m2 = Grid2D(nx=2, ny=1)
>>> cv2 = CellVariable(mesh=m2)
>>> vcv2 = CellVariable(mesh=m2, rank=1)
>>> vfv2 = FaceVariable(mesh=m2, rank=1)
>>> __ConvectionTerm(coeff=vcv2)
__ConvectionTerm(coeff=_ArithmeticCellToFaceVariable(value=array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.]]), mesh=UniformGrid2D(dx=1.0, nx=2, dy=1.0, ny=1)))
>>> __ConvectionTerm(coeff=vfv2)
__ConvectionTerm(coeff=FaceVariable(value=array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.]]), mesh=UniformGrid2D(dx=1.0, nx=2, dy=1.0, ny=1)))
>>> ExplicitUpwindConvectionTerm(coeff = ((0,),(0,))).solve(var=cv2)
>>> ExplicitUpwindConvectionTerm(coeff = (0,0)).solve(var=cv2)

Parameters : coeff : The Term‘s coefficient value. diffusionTerm : deprecated. The Peclet number is calculated automatically.

The diffusionTerm Module¶

class fipy.terms.diffusionTerm.DiffusionTerm(coeff=(1.0, ))

Bases: fipy.terms.term.Term

This term represents a higher order diffusion term. The order of the term is determined by the number of coeffs, such that:

DiffusionTerm(D1)


represents a typical 2nd-order diffusion term of the form

and:

DiffusionTerm((D1,D2))


represents a 4th-order Cahn-Hilliard term of the form

and so on.

Create a DiffusionTerm.

Parameters : coeff: Tuple or list of FaceVariables or numbers.
class fipy.terms.diffusionTerm.DiffusionTermNoCorrection(coeff=(1.0, ))

Create a DiffusionTerm.

Parameters : coeff: Tuple or list of FaceVariables or numbers.

The explicitDiffusionTerm Module¶

class fipy.terms.explicitDiffusionTerm.ExplicitDiffusionTerm(coeff=(1.0, ))

The discretization for the ExplicitDiffusionTerm is given by

where and are the old values of the variable. The term is added to the RHS vector and makes no contribution to the solution matrix.

Create a DiffusionTerm.

Parameters : coeff: Tuple or list of FaceVariables or numbers.

The explicitUpwindConvectionTerm Module¶

class fipy.terms.explicitUpwindConvectionTerm.ExplicitUpwindConvectionTerm(coeff=1.0, diffusionTerm=None)

The discretization for this Term is given by

where and is calculated using the upwind scheme. For further details see Numerical Schemes.

Create a ConvectionTerm object.

>>> from fipy.meshes.grid1D import Grid1D
>>> from fipy.variables.cellVariable import CellVariable
>>> from fipy.variables.faceVariable import FaceVariable
>>> m = Grid1D(nx = 2)
>>> cv = CellVariable(mesh = m)
>>> fv = FaceVariable(mesh = m)
>>> vcv = CellVariable(mesh=m, rank=1)
>>> vfv = FaceVariable(mesh=m, rank=1)
>>> __ConvectionTerm(coeff = cv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> __ConvectionTerm(coeff = fv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> __ConvectionTerm(coeff = vcv)
__ConvectionTerm(coeff=_ArithmeticCellToFaceVariable(value=array([[ 0.,  0.,  0.]]), mesh=UniformGrid1D(dx=1.0, nx=2)))
>>> __ConvectionTerm(coeff = vfv)
__ConvectionTerm(coeff=FaceVariable(value=array([[ 0.,  0.,  0.]]), mesh=UniformGrid1D(dx=1.0, nx=2)))
>>> __ConvectionTerm(coeff = (1,))
__ConvectionTerm(coeff=(1,))
>>> from fipy.terms.explicitUpwindConvectionTerm import ExplicitUpwindConvectionTerm
>>> ExplicitUpwindConvectionTerm(coeff = (0,)).solve(var = cv)
>>> ExplicitUpwindConvectionTerm(coeff = 1).solve(var = cv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> from fipy.meshes.grid2D import Grid2D
>>> m2 = Grid2D(nx=2, ny=1)
>>> cv2 = CellVariable(mesh=m2)
>>> vcv2 = CellVariable(mesh=m2, rank=1)
>>> vfv2 = FaceVariable(mesh=m2, rank=1)
>>> __ConvectionTerm(coeff=vcv2)
__ConvectionTerm(coeff=_ArithmeticCellToFaceVariable(value=array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.]]), mesh=UniformGrid2D(dx=1.0, nx=2, dy=1.0, ny=1)))
>>> __ConvectionTerm(coeff=vfv2)
__ConvectionTerm(coeff=FaceVariable(value=array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.]]), mesh=UniformGrid2D(dx=1.0, nx=2, dy=1.0, ny=1)))
>>> ExplicitUpwindConvectionTerm(coeff = ((0,),(0,))).solve(var=cv2)
>>> ExplicitUpwindConvectionTerm(coeff = (0,0)).solve(var=cv2)

Parameters : coeff : The Term‘s coefficient value. diffusionTerm : deprecated. The Peclet number is calculated automatically.

The exponentialConvectionTerm Module¶

class fipy.terms.exponentialConvectionTerm.ExponentialConvectionTerm(coeff=1.0, diffusionTerm=None)

The discretization for this Term is given by

where and is calculated using the exponential scheme. For further details see Numerical Schemes.

Create a ConvectionTerm object.

>>> from fipy.meshes.grid1D import Grid1D
>>> from fipy.variables.cellVariable import CellVariable
>>> from fipy.variables.faceVariable import FaceVariable
>>> m = Grid1D(nx = 2)
>>> cv = CellVariable(mesh = m)
>>> fv = FaceVariable(mesh = m)
>>> vcv = CellVariable(mesh=m, rank=1)
>>> vfv = FaceVariable(mesh=m, rank=1)
>>> __ConvectionTerm(coeff = cv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> __ConvectionTerm(coeff = fv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> __ConvectionTerm(coeff = vcv)
__ConvectionTerm(coeff=_ArithmeticCellToFaceVariable(value=array([[ 0.,  0.,  0.]]), mesh=UniformGrid1D(dx=1.0, nx=2)))
>>> __ConvectionTerm(coeff = vfv)
__ConvectionTerm(coeff=FaceVariable(value=array([[ 0.,  0.,  0.]]), mesh=UniformGrid1D(dx=1.0, nx=2)))
>>> __ConvectionTerm(coeff = (1,))
__ConvectionTerm(coeff=(1,))
>>> from fipy.terms.explicitUpwindConvectionTerm import ExplicitUpwindConvectionTerm
>>> ExplicitUpwindConvectionTerm(coeff = (0,)).solve(var = cv)
>>> ExplicitUpwindConvectionTerm(coeff = 1).solve(var = cv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> from fipy.meshes.grid2D import Grid2D
>>> m2 = Grid2D(nx=2, ny=1)
>>> cv2 = CellVariable(mesh=m2)
>>> vcv2 = CellVariable(mesh=m2, rank=1)
>>> vfv2 = FaceVariable(mesh=m2, rank=1)
>>> __ConvectionTerm(coeff=vcv2)
__ConvectionTerm(coeff=_ArithmeticCellToFaceVariable(value=array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.]]), mesh=UniformGrid2D(dx=1.0, nx=2, dy=1.0, ny=1)))
>>> __ConvectionTerm(coeff=vfv2)
__ConvectionTerm(coeff=FaceVariable(value=array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.]]), mesh=UniformGrid2D(dx=1.0, nx=2, dy=1.0, ny=1)))
>>> ExplicitUpwindConvectionTerm(coeff = ((0,),(0,))).solve(var=cv2)
>>> ExplicitUpwindConvectionTerm(coeff = (0,0)).solve(var=cv2)

Parameters : coeff : The Term‘s coefficient value. diffusionTerm : deprecated. The Peclet number is calculated automatically.

The faceTerm Module¶

class fipy.terms.faceTerm.FaceTerm(coeff=1.0)

Bases: fipy.terms.term.Term

Attention

This class is abstract. Always create one of its subclasses.

The hybridConvectionTerm Module¶

class fipy.terms.hybridConvectionTerm.HybridConvectionTerm(coeff=1.0, diffusionTerm=None)

The discretization for this Term is given by

where and is calculated using the hybrid scheme. For further details see Numerical Schemes.

Create a ConvectionTerm object.

>>> from fipy.meshes.grid1D import Grid1D
>>> from fipy.variables.cellVariable import CellVariable
>>> from fipy.variables.faceVariable import FaceVariable
>>> m = Grid1D(nx = 2)
>>> cv = CellVariable(mesh = m)
>>> fv = FaceVariable(mesh = m)
>>> vcv = CellVariable(mesh=m, rank=1)
>>> vfv = FaceVariable(mesh=m, rank=1)
>>> __ConvectionTerm(coeff = cv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> __ConvectionTerm(coeff = fv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> __ConvectionTerm(coeff = vcv)
__ConvectionTerm(coeff=_ArithmeticCellToFaceVariable(value=array([[ 0.,  0.,  0.]]), mesh=UniformGrid1D(dx=1.0, nx=2)))
>>> __ConvectionTerm(coeff = vfv)
__ConvectionTerm(coeff=FaceVariable(value=array([[ 0.,  0.,  0.]]), mesh=UniformGrid1D(dx=1.0, nx=2)))
>>> __ConvectionTerm(coeff = (1,))
__ConvectionTerm(coeff=(1,))
>>> from fipy.terms.explicitUpwindConvectionTerm import ExplicitUpwindConvectionTerm
>>> ExplicitUpwindConvectionTerm(coeff = (0,)).solve(var = cv)
>>> ExplicitUpwindConvectionTerm(coeff = 1).solve(var = cv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> from fipy.meshes.grid2D import Grid2D
>>> m2 = Grid2D(nx=2, ny=1)
>>> cv2 = CellVariable(mesh=m2)
>>> vcv2 = CellVariable(mesh=m2, rank=1)
>>> vfv2 = FaceVariable(mesh=m2, rank=1)
>>> __ConvectionTerm(coeff=vcv2)
__ConvectionTerm(coeff=_ArithmeticCellToFaceVariable(value=array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.]]), mesh=UniformGrid2D(dx=1.0, nx=2, dy=1.0, ny=1)))
>>> __ConvectionTerm(coeff=vfv2)
__ConvectionTerm(coeff=FaceVariable(value=array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.]]), mesh=UniformGrid2D(dx=1.0, nx=2, dy=1.0, ny=1)))
>>> ExplicitUpwindConvectionTerm(coeff = ((0,),(0,))).solve(var=cv2)
>>> ExplicitUpwindConvectionTerm(coeff = (0,0)).solve(var=cv2)

Parameters : coeff : The Term‘s coefficient value. diffusionTerm : deprecated. The Peclet number is calculated automatically.

The implicitSourceTerm Module¶

class fipy.terms.implicitSourceTerm.ImplicitSourceTerm(coeff=0.0)

The ImplicitSourceTerm represents

where is the coeff value.

The nthOrderDiffusionTerm Module¶

class fipy.terms.nthOrderDiffusionTerm.ExplicitNthOrderDiffusionTerm(coeff)

Attention

This class is deprecated. Use ExplicitDiffusionTerm instead.

class fipy.terms.nthOrderDiffusionTerm.NthOrderDiffusionTerm(coeff)

Attention

This class is deprecated. Use ImplicitDiffusionTerm instead.

The powerLawConvectionTerm Module¶

class fipy.terms.powerLawConvectionTerm.PowerLawConvectionTerm(coeff=1.0, diffusionTerm=None)

The discretization for this Term is given by

where and is calculated using the power law scheme. For further details see Numerical Schemes.

Create a ConvectionTerm object.

>>> from fipy.meshes.grid1D import Grid1D
>>> from fipy.variables.cellVariable import CellVariable
>>> from fipy.variables.faceVariable import FaceVariable
>>> m = Grid1D(nx = 2)
>>> cv = CellVariable(mesh = m)
>>> fv = FaceVariable(mesh = m)
>>> vcv = CellVariable(mesh=m, rank=1)
>>> vfv = FaceVariable(mesh=m, rank=1)
>>> __ConvectionTerm(coeff = cv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> __ConvectionTerm(coeff = fv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> __ConvectionTerm(coeff = vcv)
__ConvectionTerm(coeff=_ArithmeticCellToFaceVariable(value=array([[ 0.,  0.,  0.]]), mesh=UniformGrid1D(dx=1.0, nx=2)))
>>> __ConvectionTerm(coeff = vfv)
__ConvectionTerm(coeff=FaceVariable(value=array([[ 0.,  0.,  0.]]), mesh=UniformGrid1D(dx=1.0, nx=2)))
>>> __ConvectionTerm(coeff = (1,))
__ConvectionTerm(coeff=(1,))
>>> from fipy.terms.explicitUpwindConvectionTerm import ExplicitUpwindConvectionTerm
>>> ExplicitUpwindConvectionTerm(coeff = (0,)).solve(var = cv)
>>> ExplicitUpwindConvectionTerm(coeff = 1).solve(var = cv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> from fipy.meshes.grid2D import Grid2D
>>> m2 = Grid2D(nx=2, ny=1)
>>> cv2 = CellVariable(mesh=m2)
>>> vcv2 = CellVariable(mesh=m2, rank=1)
>>> vfv2 = FaceVariable(mesh=m2, rank=1)
>>> __ConvectionTerm(coeff=vcv2)
__ConvectionTerm(coeff=_ArithmeticCellToFaceVariable(value=array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.]]), mesh=UniformGrid2D(dx=1.0, nx=2, dy=1.0, ny=1)))
>>> __ConvectionTerm(coeff=vfv2)
__ConvectionTerm(coeff=FaceVariable(value=array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.]]), mesh=UniformGrid2D(dx=1.0, nx=2, dy=1.0, ny=1)))
>>> ExplicitUpwindConvectionTerm(coeff = ((0,),(0,))).solve(var=cv2)
>>> ExplicitUpwindConvectionTerm(coeff = (0,0)).solve(var=cv2)

Parameters : coeff : The Term‘s coefficient value. diffusionTerm : deprecated. The Peclet number is calculated automatically.

The sourceTerm Module¶

class fipy.terms.sourceTerm.SourceTerm(coeff=0.0)

Attention

This class is abstract. Always create one of its subclasses.

The term Module¶

class fipy.terms.term.Term(coeff=1.0)

Attention

This class is abstract. Always create one of its subclasses.

Create a Term.

Parameters : coeff: The coefficient for the term. A CellVariable or number. FaceVariable objects are also acceptable for diffusion or convection terms.
cacheMatrix()

Informs solve() and sweep() to cache their matrix so that getMatrix() can return the matrix.

cacheRHSvector()

Informs solve() and sweep() to cache their right hand side vector so that getRHSvector() can return it.

copy()
getDefaultSolver(solver=None, *args, **kwargs)
getMatrix()

Return the matrix caculated in solve() or sweep(). The cacheMatrix() method should be called before solve() or sweep() to cache the matrix.

getRHSvector()

Return the RHS vector caculated in solve() or sweep(). The cacheRHSvector() method should be called before solve() or sweep() to cache the vector.

justResidualVector(var, solver=None, boundaryConditions=(), dt=1.0, underRelaxation=None, residualFn=None)

Builds the Term‘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. Defaults to LinearPCGSolver for Pysparse and LinearLUSolver for Trilinos. 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 residualFn: A function that takes var, matrix, and RHSvector arguments used to customize the residual calculation.
residualVectorAndNorm(var, solver=None, boundaryConditions=(), dt=1.0, underRelaxation=None, residualFn=None)

Builds the Term‘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. Defaults to LinearPCGSolver for Pysparse and LinearLUSolver for Trilinos. 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 residualFn: A function that takes var, matrix, and RHSvector arguments used to customize the residual calculation.
solve(var, solver=None, boundaryConditions=(), dt=1.0)

Builds and solves the Term‘s linear system once. This method does not return the residual. It should be used when the residual is not required.

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. Defaults to LinearPCGSolver for Pysparse and LinearLUSolver for Trilinos. boundaryConditions: A tuple of boundaryConditions. dt: The time step size.
sweep(var, solver=None, boundaryConditions=(), dt=1.0, underRelaxation=None, residualFn=None)

Builds and solves the Term‘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. Defaults to LinearPCGSolver for Pysparse and LinearLUSolver for Trilinos. 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 residualFn: A function that takes var, matrix, and RHSvector arguments, used to customize the residual calculation.

The transientTerm Module¶

class fipy.terms.transientTerm.TransientTerm(coeff=1.0)

The TransientTerm represents

where is the coeff value.

The following test case verifies that variable coefficients and old coefficient values work correctly. We will solve the following equation

The analytic solution is given by

where is the initial value.

>>> phi0 = 1.
>>> k = 1.
>>> dt = 1.
>>> relaxationFactor = 1.5
>>> steps = 2
>>> sweeps = 8

>>> from fipy.meshes.grid1D import Grid1D
>>> mesh = Grid1D(nx = 1)
>>> from fipy.variables.cellVariable import CellVariable
>>> var = CellVariable(mesh = mesh, value = phi0, hasOld = 1)
>>> from fipy.terms.transientTerm import TransientTerm
>>> from fipy.terms.implicitSourceTerm import ImplicitSourceTerm


Relaxation, given by relaxationFactor, is required for a converged solution.

>>> eq = TransientTerm(var) == ImplicitSourceTerm(-relaxationFactor) \
...                            + var * relaxationFactor + k


A number of sweeps at each time step are required to let the relaxation take effect.

>>> for step in range(steps):
...     var.updateOld()
...     for sweep in range(sweeps):
...         eq.solve(var, dt = dt)


Compare the final result with the analytical solution.

>>> from fipy.tools import numerix
>>> print var.allclose(numerix.sqrt(k * dt * steps + phi0**2))
1


The upwindConvectionTerm Module¶

class fipy.terms.upwindConvectionTerm.UpwindConvectionTerm(coeff=1.0, diffusionTerm=None)

The discretization for this Term is given by

where and is calculated using the upwind convection scheme. For further details see Numerical Schemes.

Create a ConvectionTerm object.

>>> from fipy.meshes.grid1D import Grid1D
>>> from fipy.variables.cellVariable import CellVariable
>>> from fipy.variables.faceVariable import FaceVariable
>>> m = Grid1D(nx = 2)
>>> cv = CellVariable(mesh = m)
>>> fv = FaceVariable(mesh = m)
>>> vcv = CellVariable(mesh=m, rank=1)
>>> vfv = FaceVariable(mesh=m, rank=1)
>>> __ConvectionTerm(coeff = cv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> __ConvectionTerm(coeff = fv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> __ConvectionTerm(coeff = vcv)
__ConvectionTerm(coeff=_ArithmeticCellToFaceVariable(value=array([[ 0.,  0.,  0.]]), mesh=UniformGrid1D(dx=1.0, nx=2)))
>>> __ConvectionTerm(coeff = vfv)
__ConvectionTerm(coeff=FaceVariable(value=array([[ 0.,  0.,  0.]]), mesh=UniformGrid1D(dx=1.0, nx=2)))
>>> __ConvectionTerm(coeff = (1,))
__ConvectionTerm(coeff=(1,))
>>> from fipy.terms.explicitUpwindConvectionTerm import ExplicitUpwindConvectionTerm
>>> ExplicitUpwindConvectionTerm(coeff = (0,)).solve(var = cv)
>>> ExplicitUpwindConvectionTerm(coeff = 1).solve(var = cv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> from fipy.meshes.grid2D import Grid2D
>>> m2 = Grid2D(nx=2, ny=1)
>>> cv2 = CellVariable(mesh=m2)
>>> vcv2 = CellVariable(mesh=m2, rank=1)
>>> vfv2 = FaceVariable(mesh=m2, rank=1)
>>> __ConvectionTerm(coeff=vcv2)
__ConvectionTerm(coeff=_ArithmeticCellToFaceVariable(value=array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.]]), mesh=UniformGrid2D(dx=1.0, nx=2, dy=1.0, ny=1)))
>>> __ConvectionTerm(coeff=vfv2)
__ConvectionTerm(coeff=FaceVariable(value=array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.]]), mesh=UniformGrid2D(dx=1.0, nx=2, dy=1.0, ny=1)))
>>> ExplicitUpwindConvectionTerm(coeff = ((0,),(0,))).solve(var=cv2)
>>> ExplicitUpwindConvectionTerm(coeff = (0,0)).solve(var=cv2)

Parameters : coeff : The Term‘s coefficient value. diffusionTerm : deprecated. The Peclet number is calculated automatically.

The vanLeerConvectionTerm Module¶

class fipy.terms.vanLeerConvectionTerm.VanLeerConvectionTerm(coeff=1.0, diffusionTerm=None)

Create a ConvectionTerm object.

>>> from fipy.meshes.grid1D import Grid1D
>>> from fipy.variables.cellVariable import CellVariable
>>> from fipy.variables.faceVariable import FaceVariable
>>> m = Grid1D(nx = 2)
>>> cv = CellVariable(mesh = m)
>>> fv = FaceVariable(mesh = m)
>>> vcv = CellVariable(mesh=m, rank=1)
>>> vfv = FaceVariable(mesh=m, rank=1)
>>> __ConvectionTerm(coeff = cv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> __ConvectionTerm(coeff = fv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> __ConvectionTerm(coeff = vcv)
__ConvectionTerm(coeff=_ArithmeticCellToFaceVariable(value=array([[ 0.,  0.,  0.]]), mesh=UniformGrid1D(dx=1.0, nx=2)))
>>> __ConvectionTerm(coeff = vfv)
__ConvectionTerm(coeff=FaceVariable(value=array([[ 0.,  0.,  0.]]), mesh=UniformGrid1D(dx=1.0, nx=2)))
>>> __ConvectionTerm(coeff = (1,))
__ConvectionTerm(coeff=(1,))
>>> from fipy.terms.explicitUpwindConvectionTerm import ExplicitUpwindConvectionTerm
>>> ExplicitUpwindConvectionTerm(coeff = (0,)).solve(var = cv)
>>> ExplicitUpwindConvectionTerm(coeff = 1).solve(var = cv)
Traceback (most recent call last):
...
TypeError: The coefficient must be a vector value.
>>> from fipy.meshes.grid2D import Grid2D
>>> m2 = Grid2D(nx=2, ny=1)
>>> cv2 = CellVariable(mesh=m2)
>>> vcv2 = CellVariable(mesh=m2, rank=1)
>>> vfv2 = FaceVariable(mesh=m2, rank=1)
>>> __ConvectionTerm(coeff=vcv2)
__ConvectionTerm(coeff=_ArithmeticCellToFaceVariable(value=array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.]]), mesh=UniformGrid2D(dx=1.0, nx=2, dy=1.0, ny=1)))
>>> __ConvectionTerm(coeff=vfv2)
__ConvectionTerm(coeff=FaceVariable(value=array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.]]), mesh=UniformGrid2D(dx=1.0, nx=2, dy=1.0, ny=1)))
>>> ExplicitUpwindConvectionTerm(coeff = ((0,),(0,))).solve(var=cv2)
>>> ExplicitUpwindConvectionTerm(coeff = (0,0)).solve(var=cv2)

Parameters : coeff : The Term‘s coefficient value. diffusionTerm : deprecated. The Peclet number is calculated automatically.