Ola Skavhaug wrote:
> Dag Lindbo skrev den 09/04-2008 følgende:
>> Dag Lindbo wrote:
>>> Ola Skavhaug wrote:
>>>> Dag Lindbo skrev den 09/04-2008 følgende:
>>>>> Hello again!
>>>>>
>>>>> Why is it not possible any longer to get the Vector associated with 
>>>>> a Function? E.g:
>>>>>
>>>>> #include <dolfin.h>
>>>>> using namespace dolfin;
>>>>>
>>>>> int main()
>>>>> {
>>>>>    Function u;
>>>>>    Vector& v = u.vector();
>>>>> }
>>>> int main()
>>>> {
>>>>      Function u;
>>>>      Vector v;
>>>>      v = u.vector();
>>>>      return 0;
>>>> }
>>>>
>>>> Should work. A Function returns a GenericVector reference, and the Vector
>>>> reference needs to be a Vector. Then the operator= in Vector is  
>>>> applied in the
>>>> assignment.
>>>>
>>>> Ola
>>> Ola,
>>>
>>> Sorry if I'm this is a stupid/incorrect observation. What you propose 
>>> is a a deep copy of the vector. So something like
>>>
>>> uBlasVector& vv = *(v.instance());
>>> vv[0] = 1000.32;
>>>
>>> has no impact on the data owned by u. uBlas only has deep copy  
>>> semantics, which are invoked in dolfin::Vector::operator= (i.e. *vector 
>>> = *x; )
>>>
>>> Is this really what we want?
>>>
>>> /Dag
>>>
>> Seems I'm also sloppy with grammar today. My previous post may sound  
>> offensive towards Ola, but I only meant to pre-excuse _myself_ in case  
>> my understanding of C++ has deserted me this evening. /Dag
> 
> No offence taken :) My point was simply that since the underlying
> GenericVector is not a Vector, the lines:
> 
> Function u;
> Vector& v = u.vector();
> 
> does not work. But the compiler told you that already. Do you want a method
> for rebinding the DefaultVector* vector attribute of Vector? That way, the
> deep copy will be avoided.
> 
> Ola

No, I simply want to retrieve the Vector reference associated with a 
DiscreteFunction, so as to retain the reference semantics that used to 
be present in the LA interface. I realize now that it had to be changed 
out of necessity. For my purposes I now do

Vector& x = dynamic_cast<Vector&>(u.vector());
instead of
Vector& x = u.vector();

and

uBlasVector& xx = *x.instance();
instead of
uBlasVector& xx = x.vec();

Would anyone advise against this? I'm happy that it relieves me of 
dealing with explicit pointers (only one dereference), and "hides" the 
GenericVector.

Thanks a lot for your input guys!

/Dag
_______________________________________________
DOLFIN-dev mailing list
[email protected]
http://www.fenics.org/mailman/listinfo/dolfin-dev

Reply via email to