← Back to team overview

dolfin team mailing list archive

Re: Invalid conversion from dolfin::GenericVector to dolfin::Vector

 

On Wed, Apr 09, 2008 at 06:14:35PM +0200, 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

I don't think one should need to make a copy of the vector. It should
work to either use the vector you get by calling vector() directly,
for example

  solve(A, u.vector(), b); // Doesn't work currently but it should!

You may also do

  GenericVector& x = u.vector();

The thing that's changed is that a Function saves its data in a
GenericVector which can be anything, a PETScVector, a uBlasVector,
an EpetraVector, or even your own implementation of a vector class.

The class Vector is a particular implementation of a Vector, decided
at compile-time depending on how you have configured DOLFIN. If you
compile with PETSc, then it's a wrapper for a PETScVector, otherwise
it's a wrapper for a uBlasVector.

Some work needs to be done to get all the linear algebra behave well
in both Python and C++. This will likely take some weeks so we might
not be able to fix everything before the release.

(I will add the solve() problem above to the TODO list.)

-- 
Anders


> > error: invalid initialization of reference of type ‘dolfin::Vector&’ 
> > from expression of type ‘dolfin::GenericVector’
> > 
> > na55:cpp > scons
> > c++ -o test.o -c -Wall -pipe -ansi -g -Werror -O2 -pthread -DDEBUG 
> > -DNDEBUG -DPACKAGE_VERSION="0.7.2" -DHAS_UMFPACK=1 -DHAS_GTS=1 
> > -I/usr/local/include 
> > -I/usr/lib/python2.5/site-packages/numpy/core/include 
> > -I/usr/include/suitesparse -I/usr/include/python2.5 
> > -I/usr/include/libxml2 -I/usr/include/glib-2.0 
> > -I/usr/lib/glib-2.0/include test.cpp
> > test.cpp: In function ‘int main()’:
> > test.cpp:8: error: invalid initialization of reference of type 
> > ‘dolfin::Vector&’ from expression of type ‘dolfin::GenericVector’
> > cc1plus: warnings being treated as errors
> > test.cpp:8: warning: unused variable ‘v’
> > scons: *** [test.o] Error 1
> > 
> > I hope this functionality hasn't been removed.
> > 
> > /Dag
> > _______________________________________________
> > DOLFIN-dev mailing list
> > DOLFIN-dev@xxxxxxxxxx
> > http://www.fenics.org/mailman/listinfo/dolfin-dev
> _______________________________________________
> DOLFIN-dev mailing list
> DOLFIN-dev@xxxxxxxxxx
> http://www.fenics.org/mailman/listinfo/dolfin-dev


Follow ups

References