from dolfin import *
if has_linear_algebra_backend("Epetra"):
parameters["linear_algebra_backend"] = "Epetra"
Create mesh and define function space
print("solving for mesh")
mesh = UnitSquareMesh(100, 100)
File("mesh.pvd") << mesh
Creating functionspace
V = FunctionSpace(mesh, "CG", 1)
Define boundary condition
S0 = Constant(8.3e-3)
bc = DirichletBC(V, S0, "x[0] < 0 || x[0] > 1 || x[1] < 0")
Define variational problem
D = Constant(0.5)
S = TrialFunction(V)
v = TestFunction(V)
Q = ('S(pow(C+S,-1)',1,4.0,S)
F = Ddot(grad(S)grad(v)dx) - dot(Qvdx)
Compute solution
solve(F == 0, S, bc, solver_parameters={"newton_solver":
{"relative_tolerance": 1e-10}})
Plot solution
plot(S, title="Concentration")
interactive()
Blockquote