On Aug 16, 2007, at 1:09 AM, Jason Dione Bowen wrote:
I'd like to know how I may implement the following boundary
condition over
a subset of faces, while maitaining fixed-value boundary conditions
on the
complement:
Thank you for your interest. I'm answering this question on the
mailing list so that it can benefit others.
d(phi)/dx=constant*d2(phi)/dy2,
on a 2D grid.
I tried the following as suggested in the formums:
mask=FaceVariable(mesh=mesh)
mask.setValue(1., where=(x>innerBound,y>=endPos,y<endGap))
(where=(x>innerBounde & ... ) syntax doesn't seem to work)
It doesn't work because of operator precedence. '&' binds more
tightly than '>', '>=', and '<' (see http://docs.python.org/ref/
summary.html), so Python attempts to interpret "innerBound & y",
which it doesn't know how to do. By using commas, you've constructed
a tuple of three different boolean fields, which definitely won't
work. Try:
mask.setValue(1., where=(x > innerBound) & (y >= endPos) & (y <
endGap))
surfFlux=(electricPotential.getGrad()).getDivergence()
boundaryFlux=VectorFaceVariable(mesh=mesh,
value=constant*mask*surfFlux)
At least one problem here is that surfFlux is a CellVariable, but
mask is a FaceVariable. FiPy doesn't know how to multiply those.
Further, by declaring boundaryFlux that way, with
"value=constant*mask*surfFlux", you only get that value at that
instant in time; it'll never update.
To address the first problem, although it's still not ideal, is
surfFlux=(electricPotential.getFaceGrad()).getDivergence
().getArithmeticFaceValue()
The second problem is handled cleanly in a couple of different ways
by trunk/ by I'm not seeing an easy way to do it in version 1.2. This
isn't pretty, but should work:
mask=VectorFaceVariable(mesh=mesh)
mask.setValue(1., where=numerix.array((x > innerBound) & (y >=
endPos) & (y < endGap), (False,) * len(x)).swapaxes(0,1))
boundaryFlux = constant * mask * surfFlux
boundaryFlux is thus a Variable expression, rather than a static
value, and it's a VectorFaceVariable because mask is declared as such
(FiPy knows how to multiply scalar FaceVariables by
VectorFaceVariables to produce VectorFaceVariables).
This is all dodgy, and there are several edge effects that will
probably result in you not getting what you want. Daniel, do you see
an easier way to get this d(phi)/dx=constant*d2(phi)/dy2 boundary
condition that Jason wants?
Also, would you provide a snippet of code demonstrating the use of
sweeping for the above equation (with no time dependence)?
I believe that FAQ 6.5 addresses this.
Thanks. Judging from the forums, you guys (and gals) must be busy!
Indeed, which is why were not in a position to offer private support.
We welcome questions on our public mailing list, however.
I must say, fipy is an impressive
piece of work.
Thank you. We're glad you find it useful.