Anders Logg wrote:
> On Mon, Oct 19, 2009 at 12:21:36PM +0100, Garth N. Wells wrote:
>>
>> Anders Logg wrote:
>>> On Sat, Oct 17, 2009 at 05:41:54PM +0100, Garth N. Wells wrote:
>>>> Anders Logg wrote:
>>>>> On Sat, Oct 17, 2009 at 01:54:57PM +0100, Garth N. Wells wrote:
>>>>>> Johan Hake wrote:
>>>>>>> On Saturday 17 October 2009 12:32:54 Garth N. Wells wrote:
>>>>>>>> Will
>>>>>>>>
>>>>>>>>      uh = U[1]
>>>>>>>>
>>>>>>>> return a deep or shallow copy of the sub-Function?
>>>>>>> To avoid confusion with the ufl interface we have limited the interface 
>>>>>>> for
>>>>>>> SubFunctions in PyDOLFIN to split. split returns a shallow copy by 
>>>>>>> default.
>>>>>>> pass True to split and it will return a deepcopy. In your case it would 
>>>>>>> be:
>>>>>>>
>>>>>>>   uh = U.split()[0]
>>>>>>>
>>>>>>> and
>>>>>>>
>>>>>>>   uh = U.split(True)[0]
>>>>>>>
>>>>>>> operator[] is used when you define forms. We have not yet managed to 
>>>>>>> merge the
>>>>>>> two operations into one.
>>>>>>>
>>>>>> OK. Do we still have the function 'sub'?
>>>>>>
>>>>>>
>>>>>>>> Where is the operator [] define for sub-Functions?
>>>>>>> The operator you are using is the ufl one, which is defined in
>>>>>>> ufl.exproperators.py.
>>>>>>>
>>>>>> OK, but it's not clear to me then what's happing with this extract of my
>>>>>> code:
>>>>>>
>>>>>>   problem = VariationalProblem(a, L, bcs)
>>>>>>   Uh = problem.solve()
>>>>>>
>>>>>>   u = Expression("epx(x[0])", V = Vexact)
>>>>>>
>>>>>>   uh = Uh[1]
>>>>>>   M = (uh-u)*(uh-u)*dx
>>>>>>   error = sqrt(assemble(M, mesh=mesh))
>>>>> This should work fine since uh will be a component of the coefficient
>>>>> Uh in the UFL form.
>>>>>
>>>>> Same as when you write say inner(v, u)*dx or anything else that
>>>>> accesses components.
>>>>>
>>>>> So in summary [] can be used for any purpose in forms. It can also be
>>>>> used for plotting, but extracting the vector etc will not work.
>>>>>
>>>> It works as expected, but what's going on behind the scenes? Who is
>>>> creating the dof map and is the vector being copied?
>>> There's nothing out of the ordinary going on behind the scenes.
>>>
>> There must be something going on - either a reference to or a copy of
>> the underlying vector, and a dof map. Where are these coming from?
> 
> Why must there be a reference? Are we discussing different things
> here?
>

This is what I'm doing/want to know:

   # Compute Uh
   Uh = my_pde.solve()

   # Get sub-function. uh is both a UFL and a cpp Function. What's
   # happening on the cpp side here?
   uh = Uh[1]

Garth


> --
> Anders
> 
> 
>> Garth
>>
>>> When you write
>>>
>>>   uh = Uh[1]
>>>
>>> it's no different from doing
>>>
>>>   a = uh[1]*v*dx
>>>
>>> or doing
>>>
>>>   gradu = grad(u)
>>>   a = dot(grad(v), gradu)*dx
>>>
>>> gradu is not a new Function, it's a UFL expression involving the grad
>>> operator and the Function u. gradu can be used in forms and plotted
>>> (since the plot will project it to a Function), but you can't do
>>> gradu.vector().
>>>
>> _______________________________________________
>> DOLFIN-dev mailing list
>> DOLFIN-dev@fenics.org
>> http://www.fenics.org/mailman/listinfo/dolfin-dev
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> DOLFIN-dev mailing list
>> DOLFIN-dev@fenics.org
>> http://www.fenics.org/mailman/listinfo/dolfin-dev
_______________________________________________
DOLFIN-dev mailing list
DOLFIN-dev@fenics.org
http://www.fenics.org/mailman/listinfo/dolfin-dev

Reply via email to