Skip to content

Instantly share code, notes, and snippets.

@guyer
Last active June 9, 2019 13:13
Show Gist options
  • Save guyer/aa70cb08ac386f1d64f1f93f4890e54d to your computer and use it in GitHub Desktop.
Save guyer/aa70cb08ac386f1d64f1f93f4890e54d to your computer and use it in GitHub Desktop.
from fipy import CellVariable, Grid1D,Viewer, TransientTerm, DiffusionTerm, ImplicitSourceTerm
from fipy.tools import numerix
size, dl, q = 100, 3e-6, 14.1
Ds, Ks = 1e-4, 5.8e-4
order = 2
dt = dl ** 2 / (2 * Ds)
mesh = Grid1D(dx=dl, nx=size)
phi_s = CellVariable(name='substrate', mesh=mesh)
B = CellVariable(name='biomass', mesh=mesh)
B.value[-10:] = 1000
phi_s.constrain(1, mesh.facesLeft)
reactionsCoeff = - q * B * (phi_s + Ks)
phi_s.setValue(numerix.linspace(1, 0, size))
equation = DiffusionTerm(coeff=Ds) + ImplicitSourceTerm(coeff=reactionsCoeff) == 0
res = 1e8
while res > 1e-4:
res = equation.sweep(var=phi_s)
print(phi_s.value[::20])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment