← Back to team overview

dolfin team mailing list archive

Re: Problems overloading eval for vector valued Expression

 

On Wednesday November 10 2010 11:29:09 Stepan Roucka wrote:
> I think you use dim() method instead:

This will help you if you are running a stable release.

> 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?

It is the other way around. These demos follows the development version which 
now use the value_shape method.

> 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.

The ppa packages are based on the latest release, which use the dim method.

Johan

> 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
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help   : https://help.launchpad.net/ListHelp



References