I am trying to solve a 1D differential equation, whose weak form is:
F(u; v) = - int(u', v') + 3*Ree* int( ( u' )^2 * u'' *v)
I have used:
a(u, v) = int( u', v')
and l(v) = 3*Ree* int( ( u' )^2 * u'' *v)
my following code is returning an 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: unknown
*** DOLFIN version: 1.4.0
*** Git changeset: unknown
My code:
` from dolfin import *
import numpy, sys
mesh = IntervalMesh(20, 1, 10)
V = FunctionSpace(mesh, 'CG', 1)
Ree = 3*0.1
# Define boundary conditions
u0 = Expression('2-x[0]')
u1 = Expression('12-x[0]')
def left_boundary(x, on_boundary):
return on_boundary
def right_boundary(x, on_boundary):
return on_boundary
Gamma_0 = DirichletBC(V, u0, left_boundary)
Gamma_1 = DirichletBC(V, u1, right_boundary)
bcs = [Gamma_0, Gamma_1]
# Define variational problem
v = TestFunction(V)
u = TrialFunction(V)
u_k = interpolate(Constant(0.0), V)
f = Constant(Ree)
dfdeta = Dx(u_k, 0)
dfdeta2 = Dx( dfdeta, 0)
f = Constant(3*Ree)
a = inner(nabla_grad(u_k), nabla_grad(v))*dx
L = f*v*dfdeta**2*dfdeta2*dx
u = Function(V)
eps = 1.0
tol = 1.0E-5
iteration = 0
maxiter = 100
while iteration < maxiter:
iteration += 1
solve(a == L, u, bcs)
diff = u.vector().array() - u_k.vector().array()
eps = numpy.linalg.norm(diff, ord = numpy.Inf)
if eps < tol:
print "Procedure successful"
plot(u, interactive = True)
else:
u_k.assign(u)
print "Max. number of iterations have reached."
I would appreciate any help I can get. Thanks!
`