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"
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(
45 const Teuchos::RCP<
const Thyra::VectorSpaceBase<double> > &vs_in
49 using Teuchos::rcp_dynamic_cast;
50 using Thyra::ProductVectorSpaceBase;
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;
77 serialEpetraComm = rcp_dynamic_cast<
const Epetra_SerialComm>(epetraComm);
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));
115 !epetra_map.
get(), std::invalid_argument,
116 "create_VectorSpace::initialize(...): Error!" );
117 #endif // TEUCHOS_DEBUG
120 create_Comm(Teuchos::rcpFromRef(epetra_map->Comm())).assert_not_null();
122 Teuchos::set_extra_data(epetra_map,
"epetra_map", inoutArg(comm));
123 const Ordinal localSubDim = epetra_map->NumMyElements();
126 defaultSpmdVectorSpace<double>(
127 comm, localSubDim, epetra_map->NumGlobalElements64(),
128 !epetra_map->DistributedGlobal());
138 Teuchos::set_extra_data( epetra_map,
"epetra_map", inoutArg(vs) );
146 const RCP<
const VectorSpaceBase<double> > &parentSpace,
150 using Teuchos::rcp_dynamic_cast;
156 return parentSpace->smallVecSpcFcty()->createVecSpc(dim);
163 const RCP<
const VectorSpaceBase<double> > &space_in
170 space = Teuchos::rcp_dynamic_cast<
const SpmdVectorSpaceBase<double> >(
180 epetra_v->ExtractView( &localValues );
184 new DefaultSpmdVector<double>(
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) );
199 const RCP<
const VectorSpaceBase<double> > &space_in
206 space = Teuchos::rcp_dynamic_cast<
const SpmdVectorSpaceBase<double> >(
216 epetra_v->ExtractView( &localValues );
220 new DefaultSpmdVector<double>(
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) );
235 const RCP<
const VectorSpaceBase<double> > &range_in,
236 const RCP<
const VectorSpaceBase<double> > &domain_in
239 using Teuchos::rcp_dynamic_cast;
244 Teuchos::rcp_dynamic_cast<
const SpmdVectorSpaceBase<double> >(
245 unwrapSingleProductVectorSpace(range_in),
249 Teuchos::rcp_dynamic_cast<
const ScalarProdVectorSpaceBase<double> >(
250 unwrapSingleProductVectorSpace(domain_in),
257 if (!epetra_mv.
get() )
260 domain = rcp_dynamic_cast<
const ScalarProdVectorSpaceBase<double> >(
265 double *localValues;
int leadingDim;
266 if( epetra_mv->ConstantStride() ) {
267 epetra_mv->ExtractView( &localValues, &leadingDim );
275 new DefaultSpmdMultiVector<double>(
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) );
291 const RCP<
const VectorSpaceBase<double> > &range_in,
292 const RCP<
const VectorSpaceBase<double> > &domain_in
295 using Teuchos::rcp_dynamic_cast;
300 Teuchos::rcp_dynamic_cast<
const SpmdVectorSpaceBase<double> >(
301 unwrapSingleProductVectorSpace(range_in),
305 Teuchos::rcp_dynamic_cast<
const ScalarProdVectorSpaceBase<double> >(
306 unwrapSingleProductVectorSpace(domain_in),
313 if (!epetra_mv.
get())
316 domain = rcp_dynamic_cast<
const ScalarProdVectorSpaceBase<double> >(
321 double *localValues;
int leadingDim;
322 if( epetra_mv->ConstantStride() ) {
323 epetra_mv->ExtractView( &localValues, &leadingDim );
331 new DefaultSpmdMultiVector<double>(
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;
356 const Ptr<const Teuchos::Comm<Ordinal> > comm = Teuchos::ptrFromRef(comm_in);
358 const Ptr<const SerialComm<Ordinal> > serialComm =
359 ptr_dynamic_cast<
const SerialComm<Ordinal> >(comm);
365 const Ptr<const MpiComm<Ordinal> > mpiComm =
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");
374 epetraComm =
rcp(
new Epetra_MpiComm(*mpiComm->getRawMpiComm()()));
377 epetraComm =
rcp(
new Epetra_SerialComm());
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");
386 epetraComm =
rcp(
new Epetra_SerialComm());
390 TEUCHOS_TEST_FOR_EXCEPTION(
is_null(epetraComm), std::runtime_error,
391 "null communicator created");
400 const VectorSpaceBase<double>& vs_in,
404 using Teuchos::rcpFromRef;
405 using Teuchos::rcpFromPtr;
406 using Teuchos::rcp_dynamic_cast;
407 using Teuchos::ptrFromRef;
408 using Teuchos::ptr_dynamic_cast;
410 const Ptr<const VectorSpaceBase<double> > vs_ptr = ptrFromRef(vs_in);
412 const Ptr<const SpmdVectorSpaceBase<double> > spmd_vs =
413 ptr_dynamic_cast<
const SpmdVectorSpaceBase<double> >(vs_ptr);
415 const Ptr<const ProductVectorSpaceBase<double> > &prod_vs =
416 ptr_dynamic_cast<
const ProductVectorSpaceBase<double> >(vs_ptr);
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);
427 Array<RCP<const SpmdVectorSpaceBase<double> > > spmd_vs_blocks;
429 for (
int block_i = 0; block_i < numBlocks; ++block_i) {
431 rcp_dynamic_cast<
const SpmdVectorSpaceBase<double> >(
432 prod_vs->getBlock(block_i),
true);
433 spmd_vs_blocks.push_back(spmd_vs_i);
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
452 Array<int> myGIDs(myLocalElements);
454 Array<long long> myGIDs(myLocalElements);
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();
473 new Epetra_Map(globalDim, myLocalElements, myGIDs.getRawPtr(), 0, *comm));
481 const RCP<
const VectorSpaceBase<double>>& vs,
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");
507 const Epetra_Map &map,
508 const RCP<VectorBase<double> > &v
511 using Teuchos::get_optional_extra_data;
515 THYRA_ASSERT_VEC_SPACES(
516 "Thyra::get_Epetra_Vector(map,v)", *epetra_vs, *v->space() );
522 const Ptr<const RCP<Epetra_Vector> >
523 epetra_v_ptr = get_optional_extra_data<RCP<Epetra_Vector> >(
528 return *epetra_v_ptr;
536 const VectorSpaceBase<double> &vs = *v->range();
537 const SpmdVectorSpaceBase<double> *mpi_vs
538 =
dynamic_cast<const SpmdVectorSpaceBase<double>*
>(&vs);
539 const Ordinal localOffset = ( mpi_vs ? mpi_vs->localOffset() : 0 );
540 const Ordinal localSubDim = ( mpi_vs ? mpi_vs->localSubDim() : vs.dim() );
556 new DetachedVectorView<double>(
558 ,Range1D(localOffset,localOffset+localSubDim-1)
569 ,const_cast<double*>(emvv->values())
577 Teuchos::set_extra_data( emvv,
"emvv", Teuchos::inOutArg(epetra_v),
587 const RCP<VectorBase<double> > &v,
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");
614 const Epetra_Map &map,
615 const RCP<
const VectorBase<double> > &v
618 using Teuchos::get_optional_extra_data;
622 THYRA_ASSERT_VEC_SPACES(
623 "Thyra::get_Epetra_Vector(map,v)", *epetra_vs, *v->space() );
629 const Ptr<const RCP<const Epetra_Vector> >
630 epetra_v_ptr = get_optional_extra_data<RCP<const Epetra_Vector> >(
635 return *epetra_v_ptr;
636 const Ptr<const RCP<Epetra_Vector> >
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;
646 const VectorSpaceBase<double> &vs = *v->range();
647 const SpmdVectorSpaceBase<double> *mpi_vs
648 =
dynamic_cast<const SpmdVectorSpaceBase<double>*
>(&vs);
649 const Ordinal localOffset = ( mpi_vs ? mpi_vs->localOffset() : 0 );
650 const Ordinal localSubDim = ( mpi_vs ? mpi_vs->localSubDim() : vs.dim() );
655 new ConstDetachedVectorView<double>(
657 ,Range1D(localOffset,localOffset+localSubDim-1)
668 ,const_cast<double*>(evv->values())
676 Teuchos::set_extra_data( evv,
"evv", Teuchos::inOutArg(epetra_v),
686 const RCP<
const VectorBase<double> > &v,
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");
713 const Epetra_Map &map,
714 const RCP<MultiVectorBase<double> > &mv
717 using Teuchos::get_optional_extra_data;
721 THYRA_ASSERT_VEC_SPACES(
722 "Thyra::get_Epetra_MultiVector(map,mv)", *epetra_vs, *mv->range() );
728 const Ptr<const RCP<Epetra_MultiVector> >
729 epetra_mv_ptr = get_optional_extra_data<RCP<Epetra_MultiVector> >(
730 mv,
"Epetra_MultiVector");
734 return *epetra_mv_ptr;
742 const VectorSpaceBase<double> &vs = *mv->range();
743 const SpmdVectorSpaceBase<double> *mpi_vs
744 =
dynamic_cast<const SpmdVectorSpaceBase<double>*
>(&vs);
745 const Ordinal localOffset = ( mpi_vs ? mpi_vs->localOffset() : 0 );
746 const Ordinal localSubDim = ( mpi_vs ? mpi_vs->localSubDim() : vs.dim() );
759 new DetachedMultiVectorView<double>(
761 ,Range1D(localOffset,localOffset+localSubDim-1)
768 new Epetra_MultiVector(
771 ,const_cast<double*>(emmvv->values())
782 Teuchos::set_extra_data( emmvv,
"emmvv", Teuchos::inOutArg(epetra_mv),
785 Teuchos::set_extra_data( mv,
"mv", Teuchos::inOutArg(epetra_mv) );
794 const RCP<MultiVectorBase<double> > &mv,
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");
821 const Epetra_Map &map,
822 const RCP<
const MultiVectorBase<double> > &mv
825 using Teuchos::get_optional_extra_data;
831 THYRA_ASSERT_VEC_SPACES(
832 "Thyra::get_Epetra_MultiVector(map,mv)",
833 *epetra_vs, *mv->range() );
840 const Ptr<const RCP<const Epetra_MultiVector> >
842 = get_optional_extra_data<RCP<const Epetra_MultiVector> >(
843 mv,
"Epetra_MultiVector" );
847 return *epetra_mv_ptr;
853 const VectorSpaceBase<double> &vs = *mv->range();
854 const SpmdVectorSpaceBase<double> *mpi_vs
855 =
dynamic_cast<const SpmdVectorSpaceBase<double>*
>(&vs);
856 const Ordinal localOffset = ( mpi_vs ? mpi_vs->localOffset() : 0 );
857 const Ordinal localSubDim = ( mpi_vs ? mpi_vs->localSubDim() : vs.dim() );
862 new ConstDetachedMultiVectorView<double>(
864 ,Range1D(localOffset,localOffset+localSubDim-1)
872 new Epetra_MultiVector(
875 ,const_cast<double*>(emvv->values())
886 Teuchos::set_extra_data( emvv,
"emvv", Teuchos::inOutArg(epetra_mv),
889 Teuchos::set_extra_data( mv,
"mv", Teuchos::inOutArg(epetra_mv) );
899 const RCP<
const MultiVectorBase<double> > &mv,
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");
926 const Epetra_Map &map,
927 MultiVectorBase<double> &mv
930 using Teuchos::rcpWithEmbeddedObj;
931 using Teuchos::ptrFromRef;
932 using Teuchos::ptr_dynamic_cast;
933 using Teuchos::outArg;
935 Ptr<SpmdMultiVectorBase<double> > mvSpmdMv =
936 ptr_dynamic_cast<SpmdMultiVectorBase<double> >(ptrFromRef(mv));
938 ArrayRCP<double> mvData;
941 mvSpmdMv->getNonconstLocalData(outArg(mvData), outArg(mvLeadingDim));
944 return rcpWithEmbeddedObj(
945 new Epetra_MultiVector(
946 ::
View, map, mvData.getRawPtr(), mvLeadingDim, mv.domain()->dim()
955 const Epetra_Map &map,
956 const MultiVectorBase<double> &mv
959 using Teuchos::rcpWithEmbeddedObj;
960 using Teuchos::ptrFromRef;
961 using Teuchos::ptr_dynamic_cast;
962 using Teuchos::outArg;
964 Ptr<const SpmdMultiVectorBase<double> > mvSpmdMv =
965 ptr_dynamic_cast<
const SpmdMultiVectorBase<double> >(ptrFromRef(mv));
967 ArrayRCP<const double> mvData;
970 mvSpmdMv->getLocalData(outArg(mvData), outArg(mvLeadingDim));
973 return rcpWithEmbeddedObj(
974 new Epetra_MultiVector(
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 is_null(const boost::shared_ptr< T > &p)
TEUCHOSCORE_LIB_DLL_EXPORT std::string demangleName(const std::string &mangledName)
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)
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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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.
bool is_null(const RCP< T > &p)
T_To & dyn_cast(T_From &from)
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.
TypeTo as(const TypeFrom &t)
RCP< const Epetra_Comm > get_Epetra_Comm(const Teuchos::Comm< Ordinal > &comm)
Get (or create) and Epetra_Comm given a Teuchos::Comm object.
bool nonnull(const boost::shared_ptr< T > &p)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
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.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)