Subject: [FEniCS-users] grad() function in python

From: phil marinier <[email-masked]>
Date: Tue, 11 Aug 2009 11:38:47 -0400

I slightly modifed the basic poisson demo as a test like so:

from dolfin import *

# Create mesh and define function space
mesh = UnitSquare(32, 32)
V = FunctionSpace(mesh, "CG", 1)

# Define Dirichlet boundary (x = 0 or x = 1)
class DirichletBoundary(SubDomain):
    def inside(self, x, on_boundary):
        return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS

# Define boundary condition
u0 = Constant(mesh, 0.0)
bc = DirichletBC(V, u0, DirichletBoundary())

# Define variational problem
v = TestFunction(V)
u = TrialFunction(V)
f = Function(V, "500.0 * exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)")
a = inner(grad(v), grad(u))*dx
L = v*f*dx

# Compute solution
problem = VariationalProblem(a, L, bc)
u = problem.solve()

# Plot solution
plot(u, interactive="yes")
w = project(grad(u), V)
plot(w, interactive="yes")

and my error message was:

Dot product requires non-scalar arguments, got arguments with ranks 0 and 1.
ufl.log.UFLException: Dot product requires non-scalar arguments, got arguments with ranks 0 and 1.

Can someone try this so I can at least know if its a problem with my installation? 
Thanks
Phil

---

From: Patrick Riesen <[email-masked]>
Date: Tue, 11 Aug 2009 18:00:15 +0200

Hi,

i think you can just do plot(grad(u)) and the projection is handled 
automatically by a projection on continuous piecewise linears (actually 
as your 'V')

at least that works on my dolfin0.9.2 'automatic augustin'. but if i run 
your script, dolfin does not know the 'inner' function, and throws an 
error. it does work when i use the 'dot' product.

pat

phil marinier wrote:
> ------------------------------------------------------------------------
> 
> _______________________________________________
> FEniCS-users mailing list
> [email-masked]
> http://fenics.org/mailman/listinfo/fenics-users

---

From: Anders Logg <[email-masked]>
Date: Tue, 11 Aug 2009 23:17:53 +0200

This should be fixed now. There was a bug in the project() function
(not updated to using UFL syntax). See if it works.

--
Anders