fipy.terms.vanLeerConvectionTerm¶
Classes
|
Create a _AbstractConvectionTerm object. |
- class fipy.terms.vanLeerConvectionTerm.VanLeerConvectionTerm(coeff=1.0, var=None)¶
Bases:
ExplicitUpwindConvectionTerm
Create a _AbstractConvectionTerm object.
>>> from fipy import * >>> 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): ... VectorCoeffError: The coefficient must be a vector value. >>> __ConvectionTerm(coeff = fv) Traceback (most recent call last): ... VectorCoeffError: 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,)) >>> ExplicitUpwindConvectionTerm(coeff = (0,)).solve(var=cv, solver=DummySolver()) Traceback (most recent call last): ... TransientTermError: The equation requires a TransientTerm with explicit convection. >>> (TransientTerm(0.) - ExplicitUpwindConvectionTerm(coeff = (0,))).solve(var=cv, solver=DummySolver(), dt=1.)
>>> (TransientTerm() - ExplicitUpwindConvectionTerm(coeff = 1)).solve(var=cv, solver=DummySolver(), dt=1.) Traceback (most recent call last): ... VectorCoeffError: The coefficient must be a vector value. >>> 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))) >>> (TransientTerm() - ExplicitUpwindConvectionTerm(coeff = ((0,), (0,)))).solve(var=cv2, solver=DummySolver(), dt=1.) >>> (TransientTerm() - ExplicitUpwindConvectionTerm(coeff = (0, 0))).solve(var=cv2, solver=DummySolver(), dt=1.)
- Parameters:
coeff (
MeshVariable
) – TheTerm
’s coefficient value.
- property RHSvector¶
Return the RHS vector calculated in solve() or sweep(). The cacheRHSvector() method should be called before solve() or sweep() to cache the vector.
- __eq__(other)¶
Return self==value.
- __hash__()¶
Return hash(self).
- __mul__(other)¶
Multiply a term
>>> 2. * __NonDiffusionTerm(coeff=0.5) __NonDiffusionTerm(coeff=1.0)
Test for ticket:291.
>>> from fipy import PowerLawConvectionTerm >>> PowerLawConvectionTerm(coeff=[[1], [0]]) * 1.0 PowerLawConvectionTerm(coeff=array([[ 1.], [ 0.]]))
- __neg__()¶
Negate a Term.
>>> -__NonDiffusionTerm(coeff=1.) __NonDiffusionTerm(coeff=-1.0)
- __repr__()¶
The representation of a Term object is given by,
>>> print(__UnaryTerm(123.456)) __UnaryTerm(coeff=123.456)
- __rmul__(other)¶
Multiply a term
>>> 2. * __NonDiffusionTerm(coeff=0.5) __NonDiffusionTerm(coeff=1.0)
Test for ticket:291.
>>> from fipy import PowerLawConvectionTerm >>> PowerLawConvectionTerm(coeff=[[1], [0]]) * 1.0 PowerLawConvectionTerm(coeff=array([[ 1.], [ 0.]]))
- cacheMatrix()¶
Informs solve() and sweep() to cache their matrix so that matrix can return the matrix.
- cacheRHSvector()¶
Informs solve() and sweep() to cache their right hand side vector so that getRHSvector() can return it.
- justErrorVector(var=None, solver=None, boundaryConditions=(), dt=1.0, underRelaxation=None, residualFn=None)¶
Builds the Term’s linear system once.
This method also recalculates and returns the error as well as applying under-relaxation.
justErrorVector returns the overlapping local value in parallel (not the non-overlapping value).
>>> from fipy.solvers import DummySolver >>> from fipy import * >>> m = Grid1D(nx=10) >>> v = CellVariable(mesh=m) >>> len(DiffusionTerm().justErrorVector(v, solver=DummySolver())) == m.numberOfCells True
- Parameters:
var (CellVariable) – Variable to be solved for. Provides the initial condition, the old value and holds the solution on completion.
solver (Solver) – Iterative solver to be used to solve the linear system of equations. The default sovler depends on the solver package selected.
boundaryConditions (
tuple
ofBoundaryCondition
) –dt (float) – Timestep size.
underRelaxation (float) – Usually a value between 0 and 1 or None in the case of no under-relaxation
residualFn (function) – Takes var, matrix, and RHSvector arguments, used to customize the residual calculation.
- Returns:
error – The residual vector \(\vec{e}=\mathsf{L}\vec{x}_\text{old} - \vec{b}\)
- Return type:
- justResidualVector(var=None, solver=None, boundaryConditions=(), dt=None, 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.
justResidualVector returns the overlapping local value in parallel (not the non-overlapping value).
>>> from fipy import * >>> m = Grid1D(nx=10) >>> v = CellVariable(mesh=m) >>> len(numerix.asarray(DiffusionTerm().justResidualVector(v))) == m.numberOfCells True
- Parameters:
var (CellVariable) – Variable to be solved for. Provides the initial condition, the old value and holds the solution on completion.
solver (Solver) – Iterative solver to be used to solve the linear system of equations. The default sovler depends on the solver package selected.
boundaryConditions (
tuple
ofBoundaryCondition
) –dt (float) – Timestep size.
underRelaxation (float) – Usually a value between 0 and 1 or None in the case of no under-relaxation
residualFn (function) – Takes var, matrix, and RHSvector arguments, used to customize the residual calculation.
- Returns:
residual – The residual vector \(\vec{r}=\mathsf{L}\vec{x} - \vec{b}\)
- Return type:
- property matrix¶
Return the matrix calculated in solve() or sweep(). The cacheMatrix() method should be called before solve() or sweep() to cache the matrix.
- residualVectorAndNorm(var=None, solver=None, boundaryConditions=(), dt=None, 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 (CellVariable) – Variable to be solved for. Provides the initial condition, the old value and holds the solution on completion.
solver (Solver) – Iterative solver to be used to solve the linear system of equations. The default sovler depends on the solver package selected.
boundaryConditions (
tuple
ofBoundaryCondition
) –dt (float) – Timestep size.
underRelaxation (float) – Usually a value between 0 and 1 or None in the case of no under-relaxation
residualFn (function) – Takes var, matrix, and RHSvector arguments, used to customize the residual calculation.
- Returns:
residual (~fipy.variables.cellVariable.CellVariable) – The residual vector \(\vec{r}=\mathsf{L}\vec{x} - \vec{b}\)
norm (float) – The L2 norm of residual, \(\|\vec{r}\|_2\)
- solve(var=None, solver=None, boundaryConditions=(), dt=None)¶
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 (CellVariable) – Variable to be solved for. Provides the initial condition, the old value and holds the solution on completion.
solver (Solver) – Iterative solver to be used to solve the linear system of equations. The default sovler depends on the solver package selected.
boundaryConditions (
tuple
ofBoundaryCondition
) –dt (float) – Timestep size.
- sweep(var=None, solver=None, boundaryConditions=(), dt=None, underRelaxation=None, residualFn=None, cacheResidual=False, cacheError=False)¶
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 (CellVariable) – Variable to be solved for. Provides the initial condition, the old value and holds the solution on completion.
solver (Solver) – Iterative solver to be used to solve the linear system of equations. The default sovler depends on the solver package selected.
boundaryConditions (
tuple
ofBoundaryCondition
) –dt (float) – Timestep size.
underRelaxation (float) – Usually a value between 0 and 1 or None in the case of no under-relaxation
residualFn (function) – Takes var, matrix, and RHSvector arguments, used to customize the residual calculation.
cacheResidual (bool) – If True, calculate and store the residual vector \(\vec{r}=\mathsf{L}\vec{x} - \vec{b}\) in the residualVector member of Term
cacheError (bool) – If True, use the residual vector \(\vec{r}\) to solve \(\mathsf{L}\vec{e}=\vec{r}\) for the error vector \(\vec{e}\) and store it in the errorVector member of Term
- Returns:
residual – The residual vector \(\vec{r}=\mathsf{L}\vec{x} - \vec{b}\)
- Return type: