11 #include "Thyra_DefaultSpmdVectorSpace.hpp"
12 #include "Thyra_DefaultSpmdMultiVector.hpp"
13 #include "Thyra_DefaultSpmdVector.hpp"
14 #include "Thyra_DetachedVectorView.hpp"
15 #include "Thyra_DetachedMultiVectorView.hpp"
16 #include "Thyra_VectorSpaceFactoryBase.hpp"
17 #include "Thyra_ProductVectorSpaceBase.hpp"
18 #include "Teuchos_Assert.hpp"
19 #include "Teuchos_dyn_cast.hpp"
21 #include "Teuchos_DefaultSerialComm.hpp"
23 #include "Teuchos_DefaultMpiComm.hpp"
26 #include "Epetra_Map.h"
27 #include "Epetra_Comm.h"
28 #include "Epetra_SerialComm.h"
30 # include "Epetra_MpiComm.h"
32 #include "Epetra_MultiVector.h"
33 #include "Epetra_Vector.h"
44 unwrapSingleProductVectorSpace(
49 using Teuchos::rcp_dynamic_cast;
51 const RCP<const ProductVectorSpaceBase<double> > pvs =
52 rcp_dynamic_cast<
const ProductVectorSpaceBase<double> >(vs_in);
55 return pvs->getBlock(0);
73 using Teuchos::rcp_dynamic_cast;
74 using Teuchos::set_extra_data;
78 if( serialEpetraComm.
get() ) {
81 set_extra_data( serialEpetraComm,
"serialEpetraComm", Teuchos::inOutArg(serialComm) );
88 mpiEpetraComm = rcp_dynamic_cast<
const Epetra_MpiComm>(epetraComm);
89 if( mpiEpetraComm.
get() ) {
91 rawMpiComm = Teuchos::opaqueWrapper(mpiEpetraComm->
Comm());
92 set_extra_data( mpiEpetraComm,
"mpiEpetraComm", Teuchos::inOutArg(rawMpiComm) );
94 mpiComm =
rcp(
new Teuchos::MpiComm<Ordinal>(rawMpiComm));
101 return Teuchos::null;
115 !epetra_map.
get(), std::invalid_argument,
116 "create_VectorSpace::initialize(...): Error!" );
117 #endif // TEUCHOS_DEBUG
122 Teuchos::set_extra_data(epetra_map,
"epetra_map", inoutArg(comm));
126 defaultSpmdVectorSpace<double>(
127 comm, localSubDim, epetra_map->NumGlobalElements64(),
138 Teuchos::set_extra_data( epetra_map,
"epetra_map", inoutArg(vs) );
150 using Teuchos::rcp_dynamic_cast;
156 return parentSpace->smallVecSpcFcty()->createVecSpc(dim);
177 return Teuchos::null;
186 Teuchos::arcp(localValues,0,epetra_v->Map().NumMyElements(),
false),
190 Teuchos::set_extra_data<RCP<Epetra_Vector> >( epetra_v,
"Epetra_Vector",
191 Teuchos::inOutArg(v) );
213 return Teuchos::null;
222 Teuchos::arcp(localValues,0,epetra_v->Map().NumMyElements(),
false),
226 Teuchos::set_extra_data<RCP<const Epetra_Vector> >( epetra_v,
"Epetra_Vector",
227 Teuchos::inOutArg(v) );
239 using Teuchos::rcp_dynamic_cast;
245 unwrapSingleProductVectorSpace(range_in),
250 unwrapSingleProductVectorSpace(domain_in),
257 if (!epetra_mv.
get() )
258 return Teuchos::null;
265 double *localValues;
int leadingDim;
266 if( epetra_mv->ConstantStride() ) {
267 epetra_mv->ExtractView( &localValues, &leadingDim );
278 Teuchos::arcp(localValues,0,leadingDim*epetra_mv->NumVectors(),
false),
282 Teuchos::set_extra_data<RCP<Epetra_MultiVector> >(
283 epetra_mv,
"Epetra_MultiVector", Teuchos::inOutArg(mv) );
295 using Teuchos::rcp_dynamic_cast;
301 unwrapSingleProductVectorSpace(range_in),
306 unwrapSingleProductVectorSpace(domain_in),
313 if (!epetra_mv.
get())
314 return Teuchos::null;
321 double *localValues;
int leadingDim;
322 if( epetra_mv->ConstantStride() ) {
323 epetra_mv->ExtractView( &localValues, &leadingDim );
334 Teuchos::arcp(localValues,0,leadingDim*epetra_mv->NumVectors(),
false),
338 Teuchos::set_extra_data<RCP<const Epetra_MultiVector> >(
339 epetra_mv,
"Epetra_MultiVector", Teuchos::inOutArg(mv) );
349 using Teuchos::ptrFromRef;
350 using Teuchos::ptr_dynamic_cast;
353 using Teuchos::MpiComm;
359 ptr_dynamic_cast<
const SerialComm<Ordinal> >(comm);
366 ptr_dynamic_cast<
const MpiComm<Ordinal> >(comm);
370 "SPMD std::vector space has a communicator that is "
371 "neither a serial comm nor an MPI comm");
382 TEUCHOS_TEST_FOR_EXCEPTION(
is_null(serialComm), std::runtime_error,
383 "SPMD std::vector space has a communicator that is "
384 "neither a serial comm nor an MPI comm");
390 TEUCHOS_TEST_FOR_EXCEPTION(
is_null(epetraComm), std::runtime_error,
391 "null communicator created");
404 using Teuchos::rcpFromRef;
405 using Teuchos::rcpFromPtr;
406 using Teuchos::rcp_dynamic_cast;
407 using Teuchos::ptrFromRef;
408 using Teuchos::ptr_dynamic_cast;
419 "Error, the concrete VectorSpaceBase object of type "
421 " SpmdVectorSpaceBase or the ProductVectorSpaceBase interfaces!" );
423 const int numBlocks = (
nonnull(prod_vs) ? prod_vs->numBlocks() : 1);
429 for (
int block_i = 0; block_i < numBlocks; ++block_i) {
432 prod_vs->getBlock(block_i),
true);
437 spmd_vs_blocks.
push_back(rcpFromPtr(spmd_vs));
442 int myLocalElements = 0;
443 for (
int block_i = 0; block_i < numBlocks; ++block_i) {
444 myLocalElements += spmd_vs_blocks[block_i]->localSubDim();
451 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
456 for (
int block_i = 0; block_i < numBlocks; ++block_i) {
458 const int lowGIDInBlock = spmd_vs_i->localOffset();
459 const int numLocalElementsInBlock = spmd_vs_i->localSubDim();
460 for (
int i=0; i < numLocalElementsInBlock; ++i, ++count) {
461 myGIDs[count] = blockOffset + lowGIDInBlock + i;
463 blockOffset += spmd_vs_i->dim();
466 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
467 const int globalDim = vs_in.
dim();
469 const long long globalDim = vs_in.
dim();
481 const RCP<
const VectorSpaceBase<double>>& vs,
482 const RCP<const Epetra_Comm>& comm)
488 const Ptr<const RCP<const Epetra_Map> >
489 epetra_map_ptr = Teuchos::get_optional_extra_data<RCP<const Epetra_Map> >(
494 return *epetra_map_ptr;
499 "Error! No RCP Epetra_Map attached to the input vector space RCP, "
500 "and the input comm RCP is null.\n");
511 using Teuchos::get_optional_extra_data;
516 "Thyra::get_Epetra_Vector(map,v)", *epetra_vs, *v->space() );
523 epetra_v_ptr = get_optional_extra_data<RCP<Epetra_Vector> >(
528 return *epetra_v_ptr;
558 ,
Range1D(localOffset,localOffset+localSubDim-1)
569 ,const_cast<double*>(emvv->values())
577 Teuchos::set_extra_data( emvv,
"emvv", Teuchos::inOutArg(epetra_v),
578 Teuchos::PRE_DESTROY );
587 const RCP<VectorBase<double> > &v,
588 const RCP<const Epetra_Map>& map
595 const Ptr<const RCP<Epetra_Vector> >
596 epetra_v_ptr = Teuchos::get_optional_extra_data<RCP<Epetra_Vector> >(
601 return *epetra_v_ptr;
606 "Error! No RCP Epetra_Vector attached to the input vector RCP, "
607 "and the input map RCP is null.\n");
618 using Teuchos::get_optional_extra_data;
623 "Thyra::get_Epetra_Vector(map,v)", *epetra_vs, *v->space() );
630 epetra_v_ptr = get_optional_extra_data<RCP<const Epetra_Vector> >(
635 return *epetra_v_ptr;
637 epetra_nonconst_v_ptr = get_optional_extra_data<RCP<Epetra_Vector> >(
641 if(!
is_null(epetra_nonconst_v_ptr))
642 return *epetra_nonconst_v_ptr;
657 ,
Range1D(localOffset,localOffset+localSubDim-1)
668 ,const_cast<double*>(evv->values())
676 Teuchos::set_extra_data( evv,
"evv", Teuchos::inOutArg(epetra_v),
677 Teuchos::PRE_DESTROY );
686 const RCP<
const VectorBase<double> > &v,
687 const RCP<const Epetra_Map>& map
694 const Ptr<const RCP<const Epetra_Vector> >
695 epetra_v_ptr = Teuchos::get_optional_extra_data<RCP<const Epetra_Vector> >(
700 return *epetra_v_ptr;
705 "Error! No RCP to Epetra_Vector attached to the input vector RCP, "
706 "and the input map RCP is null.\n");
717 using Teuchos::get_optional_extra_data;
722 "Thyra::get_Epetra_MultiVector(map,mv)", *epetra_vs, *mv->range() );
729 epetra_mv_ptr = get_optional_extra_data<RCP<Epetra_MultiVector> >(
730 mv,
"Epetra_MultiVector");
734 return *epetra_mv_ptr;
761 ,
Range1D(localOffset,localOffset+localSubDim-1)
771 ,const_cast<double*>(emmvv->values())
782 Teuchos::set_extra_data( emmvv,
"emmvv", Teuchos::inOutArg(epetra_mv),
783 Teuchos::PRE_DESTROY );
785 Teuchos::set_extra_data( mv,
"mv", Teuchos::inOutArg(epetra_mv) );
794 const RCP<MultiVectorBase<double> > &mv,
795 const RCP<const Epetra_Map>& map
802 const Ptr<const RCP<Epetra_MultiVector> >
803 epetra_mv_ptr = Teuchos::get_optional_extra_data<RCP<Epetra_MultiVector> >(
804 mv,
"Epetra_MultiVector");
808 return *epetra_mv_ptr;
813 "Error! No RCP to Epetra_MultiVector attached to the input vector RCP, "
814 "and the input map RCP is null.\n");
825 using Teuchos::get_optional_extra_data;
832 "Thyra::get_Epetra_MultiVector(map,mv)",
833 *epetra_vs, *mv->range() );
842 = get_optional_extra_data<RCP<const Epetra_MultiVector> >(
843 mv,
"Epetra_MultiVector" );
847 return *epetra_mv_ptr;
864 ,
Range1D(localOffset,localOffset+localSubDim-1)
875 ,const_cast<double*>(emvv->values())
886 Teuchos::set_extra_data( emvv,
"emvv", Teuchos::inOutArg(epetra_mv),
887 Teuchos::PRE_DESTROY );
889 Teuchos::set_extra_data( mv,
"mv", Teuchos::inOutArg(epetra_mv) );
899 const RCP<
const MultiVectorBase<double> > &mv,
900 const RCP<const Epetra_Map>& map
907 const Ptr<const RCP<const Epetra_MultiVector> >
908 epetra_mv_ptr = Teuchos::get_optional_extra_data<RCP<const Epetra_MultiVector> >(
909 mv,
"Epetra_MultiVector");
913 return *epetra_mv_ptr;
918 "Error! No RCP to Epetra_MultiVector attached to the input vector RCP, "
919 "and the input map RCP is null.\n");
930 using Teuchos::rcpWithEmbeddedObj;
931 using Teuchos::ptrFromRef;
932 using Teuchos::ptr_dynamic_cast;
933 using Teuchos::outArg;
941 mvSpmdMv->getNonconstLocalData(outArg(mvData), outArg(mvLeadingDim));
944 return rcpWithEmbeddedObj(
946 ::
View, map, mvData.getRawPtr(), mvLeadingDim, mv.
domain()->dim()
959 using Teuchos::rcpWithEmbeddedObj;
960 using Teuchos::ptrFromRef;
961 using Teuchos::ptr_dynamic_cast;
962 using Teuchos::outArg;
970 mvSpmdMv->getLocalData(outArg(mvData), outArg(mvLeadingDim));
973 return rcpWithEmbeddedObj(
975 ::
View, map, const_cast<double*>(mvData.getRawPtr()), mvLeadingDim, mv.
domain()->dim()
RCP< Epetra_MultiVector > get_Epetra_MultiVector(const Epetra_Map &map, const RCP< MultiVectorBase< double > > &mv)
Get a non-const Epetra_MultiVector view from a non-const MultiVectorBase object if possible...
bool DistributedGlobal() const
#define THYRA_ASSERT_VEC_SPACES(FUNC_NAME, VS1, VS2)
This is a very useful macro that should be used to validate that two vector spaces are compatible...
Create an explicit non-mutable (const) view of a MultiVectorBase object.
bool is_null(const boost::shared_ptr< T > &p)
Base interface class for SPMD multi-vectors.
RCP< const Epetra_Map > get_Epetra_Map(const VectorSpaceBase< double > &vs, const RCP< const Epetra_Comm > &comm)
Get (or create) an Epetra_Map object given an VectorSpaceBase object an optionally an extra Epetra_Co...
RCP< const VectorSpaceBase< double > > create_VectorSpace(const RCP< const Epetra_Map > &epetra_map)
Create an VectorSpaceBase object given an Epetra_Map object.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
T_To & dyn_cast(T_From &from)
Create an explicit non-mutable (const) view of a VectorBase object.
TEUCHOSCORE_LIB_DLL_EXPORT std::string demangleName(const std::string &mangledName)
Abstract interface for objects that represent a space for vectors.
RCP< MultiVectorBase< double > > create_MultiVector(const RCP< Epetra_MultiVector > &epetra_mv, const RCP< const VectorSpaceBase< double > > &range=Teuchos::null, const RCP< const VectorSpaceBase< double > > &domain=Teuchos::null)
Create a non-const MultiVectorBase object from a non-const Epetra_MultiVector object.
Create an explicit mutable (non-const) view of a MultiVectorBase object.
int NumMyElements() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
RCP< VectorBase< double > > create_Vector(const RCP< Epetra_Vector > &epetra_v, const RCP< const VectorSpaceBase< double > > &space=Teuchos::null)
Create a non-const VectorBase object from a non-const Epetra_Vector object.
Create an explicit mutable (non-const) view of a VectorBase object.
RCP< Epetra_Vector > get_Epetra_Vector(const Epetra_Map &map, const RCP< VectorBase< double > > &v)
Get a non-const Epetra_Vector view from a non-const VectorBase object if possible.
Abstract interface for finite-dimensional dense vectors.
const Epetra_Comm & Comm() const
const RCP< T > & assert_not_null() const
Efficient concrete implementation subclass for SPMD vectors.
RCP< const Epetra_Comm > get_Epetra_Comm(const Teuchos::Comm< Ordinal > &comm)
Get (or create) and Epetra_Comm given a Teuchos::Comm object.
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
bool nonnull(const boost::shared_ptr< T > &p)
void push_back(const value_type &x)
virtual Ordinal localOffset() const =0
Returns the offset for the local sub-vector stored on this process.
TypeTo as(const TypeFrom &t)
Efficient concrete implementation subclass for SPMD multi-vectors.
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
int ExtractView(double **V) const
RCP< const VectorSpaceBase< double > > create_LocallyReplicatedVectorSpace(const RCP< const VectorSpaceBase< double > > &parentSpace, const int dim)
Create a VectorSpaceBase object that creates locally replicated vector objects.
RCP< const Teuchos::Comm< Ordinal > > create_Comm(const RCP< const Epetra_Comm > &epetraComm)
Given an Epetra_Comm object, return an equivalent Teuchos::Comm object.
Base abstract VectorSpaceBase class for all SPMD-based vector spaces.
virtual Ordinal dim() const =0
Return the dimension of the vector space.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
virtual Ordinal localSubDim() const =0
Returns the number of local elements stored on this process.