← Back to team overview

dolfin team mailing list archive

Re: Easiest way to add vectors in pydolfin

 

On Nov 22, 2011, at 4:26, Anders Logg <logg@xxxxxxxxx> wrote:

> On Tue, Nov 22, 2011 at 12:38:46PM +0100, Martin Sandve Alnæs wrote:
>> On 22 November 2011 12:33, Anders Logg <logg@xxxxxxxxx> wrote:
>>> On Tue, Nov 22, 2011 at 11:43:51AM +0100, Martin Sandve Alnæs wrote:
>>>> Currently I'm doing:
>>>>         v = u.vector()
>>>>         v[:] = x
>>>>         v.axpy(1.0, y)
>>>> to set the Vector of Function u to x+y, where x,y are Vectors. Is this
>>>> the best way?

You can also do:

v += y

But that just calls axpy. This is pretty transparent in the C++ code. 

>>> 
>>> This should work:
>>> 
>>>  u.vector()[:] = x + y
>> 
>> Ok, but that will create a temporary vector and thus be more costly, right?

Yes. 

Johan

> I expect so but I'm not sure. Johan Hake knows.
> 
> --
> Anders
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help   : https://help.launchpad.net/ListHelp


References