getfem-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Getfem-users] Getfem python interface questions


From: Julien Pommier
Subject: Re: [Getfem-users] Getfem python interface questions
Date: Wed, 28 Nov 2007 01:39:18 +0100
User-agent: Internet Messaging Program (IMP) 3.2.6

Quoting LUK ShunTim <address@hidden>:

>
> Can you explain what do the arguments in mfd.eval('[0, x[1]*x[1]/1000]')
> in this line
>
> b1.set('param', 'M', mfd, mfd.eval('[0, x[1]*x[1]/1000]'))

It evaluates the vector field [0, x^2/1000] on the mesh_fem mfd. There is no
magic in the eval function, its source code is really short:

    def eval(self, expression):
        """interpolate an expression on the (lagrangian) MeshFem.

        Examples:
          mf.eval('x[0]*x[1]') interpolates the function 'x*y'
          mf.eval('[x[0],x[1]]') interpolates the vector field '[x,y]'
        """
        P=self.dof_nodes()
        nbd = P.shape[1];

        if not self.is_lagrangian:
            raise RuntimeError('cannot eval on a non-Lagragian MeshFem')
        if self.qdim() != 1:
            raise RuntimeError('only works (for now) with qdim == 1')
        x=P[:,0]; r=numarray.array(eval(expression))
        Z=numarray.zeros(r.shape + (nbd,),'d')
        for i in range(0,nbd):
            x=P[:,i]
            Z[...,i]=eval(expression)
        return Z


> Does MeshFem.eval() requires a numarray array argument?

No, it is just a string expression that is dynamically evaluated for each dof
node. For vector fields, just enclose the expression in brackets.


--
Julien



reply via email to

[Prev in Thread] Current Thread [Next in Thread]