2

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?

Nico Schlömer
  • 3,126
  • 17
  • 36

2 Answers2

5

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.

Garth N. Wells
  • 431
  • 3
  • 4
3

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.

Anders Logg
  • 822
  • 7
  • 9