On Friday 13 February 2009 16:54:20 A Navaei wrote: > 2009/2/13 Kent Andre <[email protected]>: > > On fr., 2009-02-13 at 15:01 +0000, A Navaei wrote: > >> 2009/2/13 Kent Andre <[email protected]>: > >> > On fr., 2009-02-13 at 13:12 +0000, A Navaei wrote: > >> >> his error in python: > >> >> > >> >> File > >> >> "/usr/lib/InsightToolkit/WrapITK/lib/itkImageToDolfinFunctionPython.p > >> >>y", line 273, in Convert > >> >> return > >> >> _itkImageToDolfinFunctionPython.itkImageToDolfinFunctionID2_Convert(* > >> >>args) RuntimeError: *** Error: Unable to assign to function, missing > >> >> coefficients (user-defined function). > >> > > >> > This is caused by the following: > >> > >> Yes, I've noticed this. But why doesn't this error happen when calling > >> the sub-class from python? Why should v._vector be null when the > >> cub-class is called from c++? > > > > There are some magic that goes on in the python version of Function. > > Hake is the master of this function, so I cc him. > > Johan: Why the extensions in dolfin/site-packages/function.py are not > implemented in c++ and then wrapped in python? It seems focusing some > parts of the development in the python layer has caused some stuff to > be missed in the c++ core. For reference I copy the previous > communication with Kent:
I fell that I am jumping into a discussion I do not have the beginning of, but first of all: The thing we do in dolfin/site-packages/function.py is to be able to dynamically create python function classes that inherits both cpp.Function, i.e., the c++ version _and_ ffc.Function. Having this in place we are now able to define a Function like: V = FunctionSpace(UnitSquare(10,10),"CG",1) f = Function(V,"sin(x[0])") where f can be used both to define variational forms, and efficiently be used in the assemble loop, where the compiled c++ version of the function is used. This means that you can e.g. write a = assembe(f*dx) What we are doing in dolfin/site-packages/function.py is however probably _not_ causing your error, as it should still be possible to use pure cpp.Functions or subclasses of such, in PyDOLFIN. To assemble a form using such function you have to instantiate a ffc.Function and a DolfinImageFunction, where the former is used defining the form and the latter is passed to assemble(...,coefficients=[your_dolfin_image_function]) > ---------------------------- > There are some issues with coding dolfin under c++, a code which works > with python is difficult, if not impossible, to re-produce in c++. I > tried sub-classing > dolfin::Function as itk::DolfinImageFunction: > > http://code.google.com/p/wrapitk/source/browse/trunk/ExternalProjects/ItkDo >lfin/src/itkDolfinImageFunction.h > > After wrapping in python, using wrapped itk::DolfinImageFunction works fine > in python, but the same procedure fails when implemented in c++, as > demonstrated here: I am not quite sure I understand this, but are you saying that you are able to: V = FunctionSpace(UnitSquare(10,10),"Lagrange",1) f = DolfinImageFunction(V,someimage) but not by calling your wrapped ImageToDolfinFunction.DolfinImageFunction()? First I assume that you properly instantiate the templates somewhere else in your build script, as itkDolfin.swg does not define any such templates. Second you should probably return a pointer to the created function in DolfinImageFunction(), and set %newobject itk::ImageToDolfinFunction<YourImageTypes>.DolfinImageFunction; or define a copy constructor to your DolfinImageFunction, as you are returning by value now. Hope this helps! Johan > http://code.google.com/p/wrapitk/source/browse/trunk/ExternalProjects/ItkDo >lfin/src/itkImageToDolfinFunction.h#56 > > which generates this error in python: > > File > "/usr/lib/InsightToolkit/WrapITK/lib/itkImageToDolfinFunctionPython.py", > line 273, in Convert > return > _itkImageToDolfinFunctionPython.itkImageToDolfinFunctionID2_Convert(*args) > RuntimeError: *** Error: Unable to assign to function, missing > coefficients (user-defined function). > > Here is the python test generating the above error: > > http://code.google.com/p/wrapitk/source/browse/trunk/ExternalProjects/ItkDo >lfin/tests/test-01.py _______________________________________________ DOLFIN-dev mailing list [email protected] http://www.fenics.org/mailman/listinfo/dolfin-dev
