[Trilinos-Users] Epetra_Vector conversion

Bartlett, Roscoe A. bartlettra at ornl.gov
Thu Oct 2 06:58:54 MDT 2014


Antonella,

With respect to conversions, Teuchos::RCP behaves exactly the same as boost::shared_ptr and std::shared_ptr and every other smart pointer in C++.  To help under how they work, I would suggest that you start with:

     http://web.ornl.gov/~8vt/RefCountPtrBeginnersGuideSAND.pdf

If the beginner guide is not sufficient, then the following document will answer all questions (I guarantee it):

   http://web.ornl.gov/~8vt/TeuchosMemoryManagementSAND.pdf

But your problem is that Epetra_MultiVector does not derive from Epetra_Vector, so you can't convert from an Epetra_MultiVector to an Epetra_Vector.  If you only have one column, why not just allocate an Epetra_Vector in the first place?  If your Epetra_MultiVector has more than one column, of course you can't convert that to an Epetra_Vector

However, If you want just one column of an Epetra_MultiVector as an Epetra_Vector, then Epetra_MultiVector already provides that:

     http://trilinos.org/docs/r11.10/packages/epetra/doc/html/classEpetra__MultiVector.html#a9ff1873a78c6fecf7a3188f925689e9c

If you want a correct owning RCP<Epetra_Vector> view of a column of given an RCP<Epetra_MultiVector> 'myMV', you would use:

    const Teuchos::RCP<Epetra_Vector> vec_i =
        Teuchos::rcpWithEmbeddedObj( (*myMV)(i), myMV, false );

That way, the Epetra_Vector pointed to by vec_i will persist even if myMV goes away.   For details, see the section  "5.9.4 Embedded objects" in the above document.

Cheers,

-Ross


> -----Original Message-----
> From: trilinos-users-bounces at software.sandia.gov [mailto:trilinos-users-
> bounces at software.sandia.gov] On Behalf Of Antonella Longo
> Sent: Thursday, October 02, 2014 8:36 AM
> To: trilinos-users at software.sandia.gov
> Cc: Deepak Garg
> Subject: [Trilinos-Users] Epetra_Vector conversion
> 
> We have an RCP<Epetra_MultiVector> and we have to
> convert it into an Epetra_Vector (non RCP<Epetra_Vector>).
> What is the way to make this conversion?
> 
> Deepak Garg and Antonella Longo
> 
> 
> 
> -----------------------------------------------
> Antonella Longo
> Istituto Nazionale di Geofisica e Vulcanologia
> Sezione di Pisa
> Via Uguccione della Faggiola, 32
> Pisa, Italy
> Tel. office: 050 8311939
> Cell.: 339 7532089
> 
> _______________________________________________
> Trilinos-Users mailing list
> Trilinos-Users at software.sandia.gov
> https://software.sandia.gov/mailman/listinfo/trilinos-users


More information about the Trilinos-Users mailing list