Thanks Martin! It is much clearer now. My main concern here is as a 
"user", since a release is forthcoming. I only wish to clarify things 
here for the benefit of (myself and) other users. Comments below.

Martin Sandve Alnæs wrote:
> 2008/4/15, Dag Lindbo <[EMAIL PROTECTED]>:
>> Hello!
>>
>>  A lot has happened on the Vector/Function/<backend>Vector interface the
>>  last weeks. For clarity, I would like to have a little "summing up"
>>  thread. That is, I  think it would be beneficial to explicitly show how
>>  the new interface is intended to be used. Sounds good? Here are some
>>  situations, to which I propose solutions. Please correct if these are
>>  not in line with the intended interface, or if there are better ones.
>>
>>  How to:
>>  *) Get reference to Vector from a (discrete) Function u
>>  Vector& v = dynamic_cast<Vector&>(u.vector());
> 
> Why would you want that?
> All dolfin library code will now use GenericVector references.
> This way it will also work with f.ex. uBlasVector objects directly.

I understand that Generic* is used for all internal DOLFIN code.

It is still not clear how "application code", i.e. an actual solver for 
a user, is supposed to do this. Is GenericVector from now on part of the 
public interface of DOLFIN? (sorry if I'm repeating this question)

> So:
> 
> GenericVector& v = u.vector();
> 
> 
>>  *) Get reference to uBlasVector from Vector v:
>>  uBlasVector& uv = dynamic_cast<uBlasVector&>(*v.instance());
> 
> uBlasVector& uv = v.down_cast<uBlasVector>();
> 
> 
>>  *) Get reference to PETScVector from Vector:
>>  ???
> 
> PETScVector& pv = v.down_cast<PETScVector>();
> 
> 
>>  *) Get reference to uBlasVector from (discrete) Function u
>>  uBlasVector& uv = dynamic_cast<uBlasVector&>(*u.vector().instance());
> 
> uBlasVector& uv = u.vector().down_cast<uBlasVector>();
> 
> 
>>  *) Get reference to PETScVector from (discrete) Function u
>>  ???
> 
> PETScVector& uv = u.vector().down_cast<PETScVector>();
> 
> 
>>  Please add more situations and suggestions. Thanks!
> 
> In general, this works with v being any subclass of GenericVector
> including Vector:
> 
> Foo & fv = v.down_cast<Foo>();
> 
> It will trigger a dolfin error on failure.
> You can check the backend in use like:
> 
> bool b = v.has_type<Foo>();
> 
> with Foo being uBlasVector, PETScVector, etc.
> 
> The point is that v.down_cast<MyVec> and v.has_type<MyVec> works with
> v being an instance of MyVec or an instance of Vector with MyVec as
> the actual backend.

Very nice!

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

Reply via email to