← Back to team overview

dolfin team mailing list archive

Re: sub vs [] for FunctionSpace

 

On Tue, Jan 18, 2011 at 08:20:43AM -0800, Johan Hake wrote:
> On Tuesday January 18 2011 06:33:31 Anders Logg wrote:
> > Can somone remind me why we have sub() instead of [] for accessing
> > subspaces in Python?
>
> This is because the way UFL handles Indexed(*).
>
> We have not (yet) managed to figure out how we can inherit (dynamic or static)
> from and Indexed(*). We need this when the resulting subfunction is returned.
>
> So therefore is [] used in ufl forms and .sub when a dolfin.SubFunction is
> needed. I am also not sure it would work to extract a SubFunction and then let
> it inherite Indexed(Coefficient(MixedElement(*))) as UFL assume it is an index
> into a MixedFunction. If the underlaying dolfin.Function is a SubFunction the
> indexing might get screwed.
>
> It might be possible with some magic to recognize a passed
> Indexed(Coefficient(MixedElement(*))) and then extract the dolfin.SubFunction
> when that is needed. It is magic but might work if the number of occasions it
> is used is limited. We might also just keep .sub for direct access to the
> SubFunction.
>
> In what places do we need a SubFunction?

I was thinking more about the FunctionSpace class and how we set
subsystem boundary conditions with W.sub(0), W.sub(1) etc.

Using sub is probably better since it is consistent with sub for
Functions (which we need for the reasons you stated above).

One problem that remains is the inconsistency between C++ and Python
for setting the bcs. In Python we use sub() whereas in C++ we use
SubSpace.

--
Anders



Follow ups

References