# FEniCS: check if function is globally greater than 0

Given a Dolfin Function u on a mesh, I'd like to check if it is greater than 0 throughout the mesh. I noticed that the expression

u > 0


is an object of the type

GT(Coefficient(FiniteElement('Lagrange', Domain(Cell('triangle', 2), 'triangle_multiverse', 2, 2), 2, None), 0), Zero((), (), {}))


How can I evaluate that thing?

If the function is piecewise linear, an easy check would be the following:

print u.vector().min()


This would also work as a good approximation for other spaces.

Looks like you're using the Python interface, in which case u is both a DOLFIN Function object and a UFL object (it inherits from both). The type information you're seeing is related to UFL.

You can evaluate the function u at an arbitrary point:

f = u((0.5, 0.5, 0.5))


if DOLFIN is configured with CGAL.

I don't know how you could check that the solution is strictly positive everywhere for arbitrary element type, but you could do a pretty good check integrating a UFL conditional,

c = conditional(lt(u, 0), 1, 0)

# This should be zero if u > 0
print assemble(c*dx)


Conditional UFL statements are presented in http://arxiv.org/abs/1211.4047.

• Last line should be assemble(c*dx). – Anders Logg May 9 '13 at 19:44
• Are you shure that quadrature rule will sample every possible negative region for arbitrary element supported in FEniCS? – Jan Blechta May 12 '13 at 0:06