Gaussian random numbers

Asked by Achim Schroll

Hi,

has the random number generator changed since 0.9.8 ?

in DOLFIN 0.9.8 the instructions following instructions worked fine

from dolfin import *
from random import *

# random funtion
class myrand(Expression):
    def eval(self, values, x):
        values[0] = gauss(0,1)

# Create mesh and finite element
mesh = UnitCircle(60)
V = FunctionSpace(mesh, "CG", 1)

unoise = Function(V)
noise = myrand(V=V)

but in the latest version 0.9.10 we get the error:

Calling FFC just-in-time (JIT) compiler, this may take some time.
Traceback (most recent call last):
  File "noiser.py", line 23, in <module>
    noise = myrand(V=V)
  File "/usr/lib/python2.6/dist-packages/dolfin/function/expression.py", line 146, in __init__
    raise TypeError, "expected only 'kwargs' from one of "\
TypeError: expected only 'kwargs' from one of 'element', or 'degree'

Can you help?

Best, Morton & Achim

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Anders Logg
Solved:
Last query:
Last reply:
Revision history for this message
Best Anders Logg (logg) said :
#1

On Thu, Mar 10, 2011 at 02:30:39PM -0000, Achim Schroll wrote:
> New question #148576 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/148576
>
> Hi,
>
> has the random number generator changed since 0.9.8 ?
>
> in DOLFIN 0.9.8 the instructions following instructions worked fine
>
> from dolfin import *
> from random import *
>
> # random funtion
> class myrand(Expression):
> def eval(self, values, x):
> values[0] = gauss(0,1)
>
> # Create mesh and finite element
> mesh = UnitCircle(60)
> V = FunctionSpace(mesh, "CG", 1)
>
> unoise = Function(V)
> noise = myrand(V=V)
>
> but in the latest version 0.9.10 we get the error:
>
> Calling FFC just-in-time (JIT) compiler, this may take some time.
> Traceback (most recent call last):
> File "noiser.py", line 23, in <module>
> noise = myrand(V=V)
> File "/usr/lib/python2.6/dist-packages/dolfin/function/expression.py", line 146, in __init__
> raise TypeError, "expected only 'kwargs' from one of "\
> TypeError: expected only 'kwargs' from one of 'element', or 'degree'

It's the V=V that is the problem. Just remove that argument and it
should be fine.

--
Anders

Revision history for this message
Achim Schroll (achim-simula-deactivatedaccount) said :
#2

Thanks Anders Logg, that solved my question.