← Back to team overview

dolfin team mailing list archive

Re: sub vs [] for FunctionSpace

 

On Wed, Jan 19, 2011 at 08:32:07AM -0800, Johan Hake wrote:
> On Wednesday January 19 2011 01:31:23 Anders Logg wrote:
> > 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.
>
> Ok, I missed that detail...
>
> > Using sub is probably better since it is consistent with sub for
> > Functions (which we need for the reasons you stated above).
>
> I actually think that this was the main reason of chosing sub.
>
> > 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.
>
> We do use SubSpaces in Python too. W.sub(0) returns a subspace.

Yes, I think it's fine now the way it is. Just that I'm writing some
documentation on the interface atm and then things like this become
obvious.

--
Anders



References