← Back to team overview

dolfin team mailing list archive

Re: Expression and Function

 

> On Wednesday 04 November 2009 16:28:58 Garth N. Wells wrote:
>> kent-and@xxxxxxxxx wrote:
>> >> kent-and@xxxxxxxxx wrote:
>> >>> Hi, I am very happy with the  Expression, but old code like
>> >>>
>> >>> class Dabla(Function):
>> >>>     def eval(...)
>> >>>
>> >>> still works.
>> >>>
>> >>> The only problem is that the function is zero even though eval is
>> >>> implemented. Is it
>> >>> possible to turn this old code into an error?
>> >>
>> >> In C++, no. There is no mechanism in C++ to prevent a user
>> overloading
>> >> or hiding a member function.
>> >>
>> >> Garth
>> >
>> > But the problem here is that the method of the subclass is not called.
>> > Furthermore,
>> > code written prior to Expression called the method of the subclass.
>> >
>> > Consider the following code:
>> >
>> > from dolfin import *
>> >
>> > class Foo(Function):
>> >     def eval(self, v, x):
>> >         v[0] = 1
>> >
>> > mesh = UnitSquare(12,12)
>> > V = FunctionSpace(mesh, 'CG', 1)
>> >
>> > f = Foo(V)
>> > fi = interpolate(f, V)
>> > print fi.vector().norm("l2")
>> >
>> > here:
>> > fi.vector().norm("l2")
>> > will return 0.
>> >
>> > which is clearly not expected.
>> >
>> > What the user should of course do is to use Expression instead of
>> > Function. Then
>> > the above code would work. And I think the user should somehow be told
>> > to use Expression.
>>
>> You'll have to talk to the C++ standard committee to sort this out in
>> C++ ;), or to Dr Hake to fix it on the Python side.
>
> 6 lines of metaclass stuff added.
>
> Johan
>

Nice Dr Hake!

Kent



References