← Back to team overview

dolfin team mailing list archive

Re: Status of new Expression interface

 

On Thursday 26 November 2009 16:09:53 Garth N. Wells wrote:
> Anders Logg wrote:
> > On Thu, Nov 26, 2009 at 09:42:22PM +0000, Harish Narayanan wrote:
> >> Anders Logg wrote:
> >>> Looks like the new Expression interface might be working now but more
> >>> tests are needed. Please help out getting all the demos over to the
> >>> new interface.
> >>>
> >>> The changes to the interface are as follows:
> >>>
> >>> 1. V=V argument in Expression should be removed
> >>>
> >>> 2. mesh argument in Constant should be removed
> >>>
> >>> 3. Subclasses of Expression overloading eval must overload dim if not
> >>> scalar

Ok, this might seem to be a bit far fetched but I think it is quite nice. 

What with:

  class MyExpression(Expression):
      def eval(self, x):
          ....
          return x_values, y_values

The value dimension would then just be the length of the return argument. The 
_actual_ eval function would then, using the fabulous metaclass, be:

   def eval(self, values, x):
       values[0], values[1] = user_eval(self, x)

where user_eval is the eval method defined above by the user.

This will solve the value dimension problem for python expressions, and make 
the eval method the user specify more pythonic.

How do we evaluate the value dimension for multi line C++ expression? Do we 
require the user to initialize the base Expression class using either the uint 
dim constructor or the vector<uint> value_shape constructor?

If so I do not see that the code in __init__ take care of this case, yet...

We also need a cleanup of different erroneous user cases. The one that Garth 
sketches below, should issue an error. Now it assume the the V is a "cpparg", 
and somehow gets through.

I have also provided the protected attribute _ufl_element. Now there seems to 
be an element, and a degree attribute. The latter is OK, but I think the 
former should use the _ufl_element attribute, as other code use the method 
ufl_element() to access this. 

> How should subclaases be initialised?
> 
>   f = Source(V)
> 
> works, but

Should issue an error.

>   f = Source
> 
> doesn't.

Here you just tell f to be the subclass Source. With the present design you 
should just use:

  f = Source()

I have pushed a fix for a bug that prevented this :)

Johan

> Garth
> 
> >>> The Poisson and elasticity demos have been moved and both work.
> >>
> >> Attached a patch (I think) cleaning up the hyperelasticity demo.
> >>
> >> Harish
> >
> > I applied it, using
> >
> >  bzr pull <your-bundle>.bzr
> >
> > Is it possible to verify that the blob in the end after # begin bundle
> > does what the patch text seems to indicate and that it doesn't inject
> > some harmful code?
> >
> > --
> > Anders
> >
> >> # Bazaar merge directive format 2 (Bazaar 0.90)
> >> # revision_id: hnarayanan@xxxxxxxxx-20091126213524-01lfutt4pk7fz7c4
> >> # target_branch: bzr+ssh://bazaar.launchpad.net/~dolfin-\
> >> #   core/dolfin/main/
> >> # testament_sha1: 0211fe69b173e5afe7620f71c063b61f4b8c1056
> >> # timestamp: 2009-11-26 21:40:47 +0000
> >> # base_revision_id: logg@xxxxxxxxx-20091126211643-x3c3h07gz7kbd3k1
> >> #
> >> # Begin patch
> >> === modified file 'demo/pde/hyperelasticity/python/demo.py'
> >> --- demo/pde/hyperelasticity/python/demo.py	2009-10-12 08:20:23 +0000
> >> +++ demo/pde/hyperelasticity/python/demo.py	2009-11-26 21:35:24 +0000
> >> @@ -1,14 +1,13 @@
> >> -""" This demo program solves a hyperelastic problem
> >> -
> >> -Implemented in python from cpp demo by Johan Hake.
> >> -
> >> -"""
> >> +""" This demo program solves a hyperelastic problem. It is implemented
> >> +in Python by Johan Hake following the C++ demo by Harish Narayanan"""
> >>
> >>  __author__ = "Johan Hake (hake@xxxxxxxxx)"
> >>  __date__ = "2009-10-11 -- 2009-10-11"
> >>  __copyright__ = "Copyright (C) 2008 Johan Hake"
> >>  __license__  = "GNU LGPL Version 2.1"
> >>
> >> +# Modified by Harish Narayanan, 2009.
> >> +
> >>  from dolfin import *
> >>
> >>  # Optimize compilation of the form
> >> @@ -23,11 +22,11 @@
> >>  V = VectorFunctionSpace(mesh, "CG", 1)
> >>
> >>  # Define Dirichlet boundary (x = 0 or x = 1)
> >> -c = Expression(("0.0", "0.0", "0.0"), V = V)
> >> +c = Expression(("0.0", "0.0", "0.0"))
> >>  r = Expression(("0.0",
> >>                  "y0 + (x[1] - y0) * cos(theta) - (x[2] - z0) *
> >> sin(theta) - x[1]", "z0 + (x[1] - y0) * sin(theta) + (x[2] - z0) *
> >> cos(theta) - x[2]"), -                defaults = dict(y0 = 0.5, z0 =
> >> 0.5, theta = pi / 3), V = V) +                defaults = dict(y0 = 0.5,
> >> z0 = 0.5, theta = pi / 3))
> >>
> >>  left, right = compile_subdomains(["(fabs(x[0]) < DOLFIN_EPS) &&
> >> on_boundary", "(fabs(x[0] - 1.0) < DOLFIN_EPS) && on_boundary"]) @@
> >> -39,8 +38,8 @@
> >>  v  = TestFunction(V)      # Test function
> >>  du = TrialFunction(V)     # Incremental displacement
> >>  u  = Function(V)          # Displacement from previous iteration
> >> -B  = Expression(("0.0", "0.0", "0.0"), V = V)          # Body force per
> >> unit mass -T  = Expression(("0.0", "0.0", "0.0"), V = V)          #
> >> Traction force on the boundary +B  = Expression(("0.0", "0.0", "0.0"))  
> >>        # Body force per unit mass +T  = Expression(("0.0", "0.0",
> >> "0.0"))          # Traction force on the boundary
> >>
> >>  # Kinematics
> >>  I = Identity(v.cell().d)        # Identity tensor
> >> @@ -53,8 +52,8 @@
> >>  Em = 10.0
> >>  nu = 0.3
> >>
> >> -mu    = Constant(mesh, Em / (2*(1 + nu))) # Lame's constants
> >> -lmbda = Constant(mesh, Em * nu / ((1 + nu) * (1 - 2 * nu)));
> >> +mu    = Constant(Em / (2*(1 + nu))) # Lame's constants
> >> +lmbda = Constant(Em * nu / ((1 + nu) * (1 - 2 * nu)))
> >>
> >>  # Strain energy function (material model)
> >>  psi = lmbda/2*(tr(E)**2) + mu*tr(E*E)
> >> @@ -75,4 +74,4 @@
> >>  file << u;
> >>
> >>  # Plot and hold solution
> >> -plot(u, interactive = True)
> >> +plot(u, mode = "displacement", interactive = True)
> >>
> >> # Begin bundle
> >> IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWf7lducAAhrfgEEUWP//
> >>91p3
> >> RgC/79/wUASb22AOXo3rAHoGqeQoxGhoDNJkPUeoAAAAAMkFNpqeptMqb0jUNHqeoAAABoAG
> >>ggKT
> >> 9NUMTMoeobRMEMEaB6QANNUmjIyA00GTQDTTRoyDJkAASRJkAJoJ6GpgU9CbUa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leh+S9Umitq16UzhVGGIQb07ju
> >>Gmzx
> >> XTA36UGmJtZmz68v0myjMsUoKBXpBq26BGEfaJ88M8pUgcp8y5hdhz2U08IdqbEW5ajEOKWw
> >>KQpc
> >> PeFDkVr5zcfAVeMKX1qVZNH6E7isxfolsgqJEiq87KZhUSkStZEBpJmdkzIZJouI2pNMFrRZ
> >>Q4Tf
> >> AIhNUwykMmd1QEFosWzaDrasAf8v5aE/531ZbwNRdeydkdf7UajAKUdrq3VvfPbkzL2gQ+xO
> >>/kLP
> >> HfZu8wnK96f48OAcV5PeHPTIRAoiQRaFd0SJ3SWVCh6lSjje3qnFS5oB351hArEHGwjF2WwB
> >>xNMy
> >> V5YuVkqhd4OVoZ/1F1dzeoX7zwyKrkPCTEbDkyOKhXQe68tU8wUopk64CvOMA+XopaWiHdff
> >>bbMK utW6An1r4BBWclc+renM/osBHA9pGjOLopaC4/8XckU4UJD+5Xbn
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > 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
> 



Follow ups

References