On Jul 24, 2010, at 11:11 PM, William Gathright wrote:

> I understand that fipy assumes a zero-flux boundary condition for 
> CellVariables.  By this I mean that, even if I specify a different boundary 
> condition (fixed value) be used when I solve an equation for a variable that 
> boundary condition is not a property of the variable and is not considered at 
> other times - say when .getGrad() is calculate outside of the equation for 
> that specific variable.  This can be problematic and I was wondering if there 
> is a way to change this behavior or work around it.

We introduced fipy/variables/fixedBCFaceGradVariable.py awhile ago to deal with 
this as a workaround until boundary conditions are more fully integrated with 
Variables.

>>> from fipy import *
>>> mesh = Grid1D(nx=10)
>>> x, = mesh.getCellCenters()
>>> phi = CellVariable(mesh=mesh, value=x)

>>> bcs=(FixedValue(faces=mesh.getFacesLeft(), value=0.),
..      FixedValue(faces=mesh.getFacesRight(), value=10.))

# default gradients know nothing of boundary conditions

>>> print phi.getFaceGrad()
[[ 0.  1.  1.  1.  1.  1.  1.  1.  1.  1.  0.]]
>>> print phi.getGrad()
[[ 0.5  1.   1.   1.   1.   1.   1.   1.   1.   0.5]]

# change the gradient calculation so that it does know

>>> from fipy.variables.fixedBCFaceGradVariable import _FixedBCFaceGradVariable
>>> phi.faceGrad = _FixedBCFaceGradVariable(phi,
..                                         boundaryConditions=bcs)
>>> print phi.getFaceGrad()
[[ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]]
>>> print phi.getGrad()
[[ 0.5  1.   1.   1.   1.   1.   1.   1.   1.   0.5]]

Unfortunately, as you can see, this doesn't help with getGrad() (I'm curious 
why you need that? Any fluxes are properly and more accurately calculated at 
Faces). A similar substitution would need to be made for 
phi.arithmeticFaceValue to make getArithmeticFaceValue() and getGrad() work, 
too.

We're almost certainly going to be revamping this whole thing on the (very) 
near term for other reasons, so hopefully _FixedBCFaceGradVariable() and your 
getFaceGrad_constantslope() can serve your immediate needs.



Reply via email to