Created
November 8, 2012 09:48
-
-
Save danieljfarrell/4037850 to your computer and use it in GitHub Desktop.
Fipy: problems with flux=0 constraints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fipy import * | |
from fipy.tools.numerix import exp | |
# Basic Setup | |
nx = 200; dx = 0.01; L = nx * dx | |
A = 15.0; B = 0.1; phi_0 = 1.; D = 1. | |
mesh = Grid1D(nx = nx, dx = dx) | |
# Cell variable and constrains | |
phi = CellVariable(name="phi", mesh=mesh, value=phi_0 ) | |
phi.faceGrad.constrain(0., where=mesh.facesLeft) | |
# CHANGE ME! | |
#phi.faceGrad.constrain(0., where=mesh.facesRight) # NOT REALISTIC RESULT | |
phi.constrain(phi_0, where=mesh.facesRight) # REALISTIC RESULT | |
# Diffusion and Source terms | |
# Following: http://www.mail-archive.com/[email protected]/msg02119.html | |
diffusion_term = DiffusionTerm( coeff=D, var=phi ) | |
x = mesh.getCellCenters()[0] | |
source_term = A * exp(-A * x) + B * (phi**2 - phi_0 **2) | |
equation = 0 == diffusion_term + source_term | |
# Solver | |
equation.solve() | |
viewer = Viewer( vars = (phi,) ) | |
viewer.plot() | |
raw_input("Press <return> to proceed...") |
When both the left and right side have zero flux constrains I don't think the solution is correct.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For latex version of the equations here see, http://i.imgur.com/mCcX2.