dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #20088
Re: Problems overloading eval for vector valued Expression
I think you use dim() method instead:
class InitialConditions(Expression):
def __init__(self):
random.seed(2 + MPI.process_number())
def eval(self, values, x):
values[0] = 0.63 + 0.02*(0.5 - random.random())
values[1] = 0.0
def dim(self):
return 2
The documentation of demos seems to be outdated?
The demos in the ppa packages use dim(), but in the
sources
http://bazaar.launchpad.net/~dolfin-core/dolfin/main/annotate/head%3A/demo/pde/cahn-hilliard/python/demo.py
value_shape is still used, I don't understand why.
Stepan
On 10 November 2010 18:48, Garth N. Wells <gnw20@xxxxxxxxx> wrote:
>
>
> On 10/11/10 17:44, N.A. Borggren wrote:
>>
>> Hello,
>> I am having some issues overloading eval for the class Expression
>> when I try to use vector valued functions. For example the error occurs
>> for me in the Cahn-Hilliard demo copied directly from
>> http://www.fenicsproject.org/doc/demos/pde/cahn-
>> hilliard/python/documentation.html
>>
>> $ python cahn.py
>>
>> Got expression dimension = 0
>> Traceback (most recent call last):
>> File "cahn.py", line 56, in<module>
>> u.interpolate(u_init)
>> File "cahn.py", line 10, in eval
>> values[1] = 0.0
>> IndexError: index out of bounds
>>
>> the problematic definition is:
>>
>> class InitialConditions(Expression):
>> def __init__(self):
>> random.seed(2 + MPI.process_number())
>> def eval(self, values, x):
>> values[0] = 0.63 + 0.02*(0.5 - random.random())
>> values[1] = 0.0
>> def value_shape(self):
>> return (2,)
>>
>> What is this value_shape accomplishing? The expression dimension seems
>> to still be zero. How do I resolve this?
>>
>
> Which version of DOLFIN are you using?
>
> Garth
>
>> Thank you very much,
>> Nathan Borggren
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help : https://help.launchpad.net/ListHelp
>
>
Follow ups
References