***Error: Unable to define nonlinear variational problem F(u; v) = 0 for all v.
*** Reason: Expecting the residual F to be a linear form (not rank 2).
*** Where: This error was encountered inside NonlinearVariationalProblem.cpp.
*** Process: 0
***
*** DOLFIN version: 2018.1.0
*** Git changeset: unknown
Which I don’t understand because F is linear in the trial and test functions?
Another interesting problem appears when changing the form to F = (C[0] - u_n.vector()[0] + 1 / Lambda * (C[0]- Constant(1))) * self.CV[0] * dx + dt / Lambda * u1 * CV[0].dx(1) * dx
then I get the following exception: ArityMismatch: “Adding expressions with non-matching form arguments”
I shortened the exception a bit to make it more readable. Thank you for taking the time to help me out!
'mesh = UnitSquareMesh(32, 32)
V = FunctionSpace(mesh, "Lagrange", 1)
def boundary(x, on_boundary):
return on_boundary
u0 = Expression("cos(10*x[0])", degree=1)
bc = DirichletBC(V, u0, boundary)
u = TrialFunction(V)
v = TestFunction(V)
f = Expression("(x[0] - 0.5)*(x[0] - 0.5)", degree=1)
# Missing variational formulation
a = inner(grad(u),grad(v))*dx
L = f*v
u = Function(V)
solve(a == L, u, bc)
print ("The norm of u is {}".format(u.vector().norm("l2")))'
It gives me the following error:
*** Error: Unable to define nonlinear variational problem F(u; v) = 0 for all v.
*** Reason: Expecting the residual F to be a linear form (not rank 2).
*** Where: This error was encountered inside NonlinearVariationalProblem.cpp.
*** Process: 0