← Back to team overview

dolfin team mailing list archive

Re: No data.x in overloaded Expression.eval_data

 

Johan Hake wrote:
On Thursday 17 December 2009 03:13:13 David Beacham wrote:
Johan Hake wrote:
On Wednesday 16 December 2009 10:18:50 David Beacham wrote:
Johan Hake wrote:
On Wednesday 16 December 2009 09:28:21 David Beacham wrote:
Hi,

I'm not sure if it's my relative inexperience with python, but I can't
find the coordinates x in data, when overloading eval_data in
Expression. I'm guessing from doxygen/pydoc that they should be
available?
Have you tried:

  x = data.x()
No, I don't seem to have the Data.x() method either:

(Pdb) p data.x()
*** AttributeError: AttributeError("'Data' object has no attribute
'x'",)

although everything else from the cpp side is showing up and is useable:

(Pdb) p dir(data)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__',
'__str__', '__subclasshook__', '__swig_destroy__', '__weakref__',
'cell', 'clear', 'facet', 'geometric_dimension', 'normal', 'on_facet',
'set', 'this', 'thisown', 'ufc_cell']

FWIW, I can get Data.x to work in cpp.
This should be fixed now.

Johan
Thanks for this, I can now see data.x, but it isn't returning the
correct information:

(Pdb) !z = data.x()
(Pdb) z
array([], dtype=float64)
(Pdb) z.shape
(0,)

David!

Can you run the unit test of function and see if it pass? At line 77 we test subclassing of Expression using the eval_data interface. The test pass on my computer.

If it pass, can you hand a minimal example that break, either just attach one or tweak the unit test.

Johan
Thanks for pointing out the unittests. I've worked out my problem was related to directly plotting my expression but interpolating to a function space does the correct things with data.x():

class MyExp(Expression):
   def eval_data(self, value, data):
       x = data.x()
       print x
       value[0] = x[0]

mesh = UnitSquare(10,10)
V = FunctionSpace(mesh, "CG", 2)

my_exp = MyExp()

1. If I define an expression and then interpolate that to a function everything works correctly, and data.x() gives the correct results.
# this does the right thing: print x -> [x   y]

f = Function(V)
f.interpolate(my_exp)
plot(f, interactive=True)

2. If I try to plot my expression directly, then data.x() doesn't return anything.
#print x -> []
plot(my_exp, mesh=mesh, interactive=True)

David

David

We needed to make the x attribute a method returning the x array in
Python.

Johan

David

_______________________________________________
Mailing list: https://launchpad.net/~dolfin
Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~dolfin
More help   : https://help.launchpad.net/ListHelp


References