Dear FEniCS users,
I met a strange problem in FEniCS. You can try it by yourself. At first try to run the code and then comment the blocks marked by (2).
from dolfin import *
mesh = UnitSquareMesh(15,15)
V = FunctionSpace(mesh, "CG", 3)
# Boundary conditions
def down(x, on_boundary): return x[0] < (0.0 + DOLFIN_EPS)
g0 = Constant(0.0)
bc = DirichletBC(V, g0, down)
# Parameters
epsilon = Constant(0.1)
b = Expression(('-x[1]', 'x[0]'))
f = Constant(1.)
uh = TrialFunction(V)
vh = TestFunction(V)
# (1)
a = (epsilon*dot(grad(uh),grad(vh)) + vh*dot(b,grad(uh)))*dx
L = f*vh*dx
# Compute solution (1)
uh = Function(V)
solve(a == L, uh, bc)
# (2)
psih = TrialFunction(V)
vh = TestFunction(V)
psih = Function(V)
a = (epsilon*dot(grad(psih),grad(vh)) + vh*dot(b,grad(psih)))*dx
L = f*vh*dx
# Compute solution (2)
psih = Function(V)
solve(a == L, psih, bc)
plot(uh)
interactive()
Why is fenics throwing the following error in the first case?
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** fenics@fenicsproject.org
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to define linear variational problem a(u, v) == L(v) for all v.
*** Reason: Expecting the left-hand side to be a bilinear form (not rank 1).
*** Where: This error was encountered inside LinearVariationalProblem.cpp.
*** Process: 0
***
*** DOLFIN version: 1.3.0
*** Git changeset: unknown
*** -------------------------------------------------------------------------