← Back to team overview

dolfin team mailing list archive

Re: Questions about new PyDOLFIN Functions design

 

On Sat, Nov 29, 2008 at 03:09:53PM +0100, Martin Sandve Alnæs wrote:
> How do you intend to handle (sub)functions in a mixed space?
> Currently I don't see how the function space stuff generalizes
> to even simple mixed spaces.
> 
> Take this simple example in a pure form language (FFC or UFL):
>     element1 = VectorElement("CG", "triangle", 2)
>     element2 = FiniteElement("CG", "triangle", 1)
>     mixed_element = element1 + element2
>     f, g = Functions(mixed_element)
> 
> Now in PyDOLFIN, would a function space be defined by (reusing the elements):
>     space1 = FunctionSpace(mesh, element1)
>     space2 = FunctionSpace(mesh, element2)
>     mixed_space1 = space1 + space2
> 
> or:
>     mixed_space2 = FunctionSpace(mesh, mixed_element)
> 
> and would the functions in this space be
>     f, g = Functions(mixed_space)
> or
>     fg = Function(mixed_space)
>     f, g = fg.sub(0), fg.sub(1)
> ?
> Neither of these two definitions of (f, g) works out.

It should be just as in your first example, but replace Element with
FunctionSpace:

  V1 = VectorFunctionSpace(mesh, "CG", 2)
  V2 = FunctionSpace(mesh, "CG", 1)
  mixed_space = V1 + V2
  f, g = Functions(mixed_space)

> The syntax
>     f, g = Functions(mixed_space)
> doesn't work, since ufl.Functions does not return ufl.Function objects,
> but ufl.Indexed objects that refer to subexpressions of ufl.Function objects.
> 
> The syntax
>     fg = Function(mixed_space)
>     f, g = fg.sub(0), fg.sub(1)
> would require that sub returns something that is a subclass of what
> ufl.Functions returns (ufl.Indexed) and at the same time is a dolfin.Function.

It should be enough to just define the following function:

def Functions(V):
    v = Function(V)
    return tuple(v[i] for i in range(V.num_subspaces()))

-- 
Anders

Attachment: signature.asc
Description: Digital signature


Follow ups

References