This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

FEniCS error: Unable to define linear variational problem a(u, v) == L(v) for all v.

0 votes

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!

`

asked Sep 28, 2014 by Orange FEniCS Novice (470 points)

1 Answer

0 votes
 
Best answer

u_k is a Function, making a linear. To get a bilinear form use

a = inner(nabla_grad(u), nabla_grad(v))*dx
answered Sep 28, 2014 by mikael-mortensen FEniCS Expert (29,340 points)
selected Sep 28, 2014 by Orange

Thanks for your time.

One question though.

I have to use 'u' not 'u_k' in the bilinear form since there is no non-linear term in the bilinear form.

Correct??

Not sure I get your question, but for a nonlinear solver, simply create a linear form F like this

F = inner(nabla_grad(u_k), nabla_grad(v))*dx + f*v*dfdeta**2*dfdeta2*dx
solve(F == 0, u_k)

thanks. I am grateful.

Your few words solved my 4 problems!!!!

...