How do you specifiy a Neumann (fixed flux normal to face) boundary condition in Fipy?
<p>How do I explicitly set the flux normal to a boundary face in a fipy mesh to be a specific value, without constraining components of flux within the face?</p>

<p>A Neumann boundary condition can be specified as: (1) fixed component of flux normal to a boundary face, or (2) as a complete specification of flux at the face. The default fipy condition is the former (value = 0), but the explicit method (faceGrad.constrain) is the latter. The issue can be understood by adding the following code to the end of the fipy <a href="http://www.ctcms.nist.gov/fipy/examples/diffusion/generated/examples.diffusion.mesh20x20.html" rel="nofollow">diffusion.mesh20x20</a> example and noting different face gradient results. </p>

<pre><code>facesNeumann = mesh.exteriorFaces &amp; ~facesTopLeft &amp; ~facesBottomRight
print 'grad(phi) with default Neumann BC...'
print phi.faceGrad.value.T[facesNeumann.value]
phi.faceGrad.constrain(0.,facesNeumann)
DiffusionTerm().solve(var=phi)
print 'and with explicit Neumann BC...'
print phi.faceGrad.value.T[facesNeumann.value]
</code></pre>

<p>Please see the discussion on <a href="http://www.ctcms.nist.gov/fipy/documentation/USAGE.html#applying-fixed-flux-boundary-conditions" rel="nofollow">fixed flux boundary conditions</a>. Basically, you add a source containing the the divergence of the desired boundary flux to FiPy's default no-flux condition.</p>

python mesh pde fipy