Skip to content

Instantly share code, notes, and snippets.

@danieljfarrell
Created April 2, 2012 04:46
Show Gist options
  • Save danieljfarrell/2280822 to your computer and use it in GitHub Desktop.
Save danieljfarrell/2280822 to your computer and use it in GitHub Desktop.
Very simple semiconductor optical generation and recombination processes using FiPy
from fipy import *
#
# Solution mesh
#
nx = 200
dx = 0.01
L = nx * dx
mesh = Grid1D(nx = nx, dx = dx)
#
# Initial conditions
#
n0 = 1.
#
# Boundary conditions
#
fluxLeft = 0.
valueRight = n0
bc1 = FixedFlux(faces=mesh.getFacesLeft(), value=fluxLeft)
bc2 = FixedValue(faces=mesh.getFacesRight(), value=valueRight)
bcs = (bc1, bc2)
#
# solution variable
#
n = CellVariable(name="n", mesh=mesh)
n.setValue(n0)
#
# Diffusion term, with variable diffusion coefficient
#
D = 1.
diffusion = DiffusionTerm(coeff = D)
#
# Source Term
#
B = 0.1
Io = 2.
ni = n0
alpha = 3
x = mesh.getCellCenters()[0]
from fipy.tools.numerix import exp
source = ImplicitSourceTerm(coeff=B*n) - B * ni**2 + Io * alpha * exp(-alpha * x)
#
# Define equation
#
equation = diffusion + source
equation.solve(var=n, boundaryConditions=bcs)
viewer = Viewer( vars = (n,) )
viewer.plot()
raw_input("Press <return> to proceed...")
#
# Solve using time-step
#
#timeStepDuration = 0.9 * dx**2 / (2 * D)
#steps = 1000
#for step in range(steps):
# equation.solve(var=n, boundaryConditions=bcs, dt=timeStepDuration)
# viewer = Viewer( vars = (n,) )
# viewer.plot()
# raw_input("Press <return> to proceed...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment