← Back to team overview

ffc team mailing list archive

Re: outer product with grad(scalar)

 

Jake Ostien wrote:
I'd like to take the outer product of the gradient of a scalar and a normal vector. I am running into some trouble.

For example, when I try to compile the following code:

    elem = FiniteElement("Lagrange", "triangle", 1)

    v = TestFunction(elem)
    n = FacetNormal("triangle")

    test = outer(grad(v),n)


I get the following error


    [jtostie@tostien elasto-diffusion]$ ffc -d1 -l dolfin test.form
    This is FFC, the FEniCS Form Compiler, version 0.4.1.
    For further information, go to http://www/fenics.org/ffc/.

    Preprocessing form file: test.form --> test.py

    Traceback (most recent call last):
      File "/home/jtostie/builds/bin/ffc", line 180, in ?
        sys.exit(main(sys.argv[1:]))
      File "/home/jtostie/builds/bin/ffc", line 107, in main
        execfile(outname, ns)
      File "test.py", line 14, in ?
        test = outer(grad(v),n)
      File
    "/home/jtostie/builds/lib/python/ffc/compiler/language/operators.py",
    line 135, in outer
        raise FormError, (v, "Outer products are only defined for
    Functions.")


What I think this means is that the gradient of a function is no longer a function? Is this expected?

Correct. The result of grad(v) is a Python list of the partial derivatives:

  [v.dx(0), v.dx(1), v.dx(2)]

I can see that I could project grad(v) onto a continuous basis and then use that as a function, or simply hard code the outer product for this simple case, but my real question is whether or not this should be handled correctly as is.

The problem here seems to be that the person implementing the outer() method was a little lazy and chose only to handle Functions. It should be possible to take the outer product also of Python lists.

Take a look in operators.py. The outer() method is just a few lines of code. If you have a better implementation that works for you, just submit it as an hg bundle (or patch) and I'll add it.

/Anders


-Jake
_______________________________________________
FFC-dev mailing list
FFC-dev@xxxxxxxxxx
http://www.fenics.org/mailman/listinfo/ffc-dev


References