Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_TpetraReorderedMappingStrategy.cpp
1 // @HEADER
2 // *****************************************************************************
3 // Teko: A package for block and physics based preconditioning
4 //
5 // Copyright 2010 NTESS and the Teko contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Teko_TpetraReorderedMappingStrategy.hpp"
11 
12 #include "Teko_BlockedReordering.hpp"
13 
14 using Teuchos::RCP;
15 using Teuchos::rcp;
16 using Teuchos::rcp_dynamic_cast;
17 using Teuchos::rcpFromRef;
18 
19 namespace Teko {
20 namespace TpetraHelpers {
21 
22 TpetraReorderedMappingStrategy::TpetraReorderedMappingStrategy(
23  const BlockReorderManager& brm, const Teuchos::RCP<const MappingStrategy>& map)
24  : reorderManager_(brm), mapStrategy_(map) {
25  rangeMap_ = mapStrategy_->rangeMap();
26  domainMap_ = mapStrategy_->domainMap();
27 }
28 
29 void TpetraReorderedMappingStrategy::copyTpetraIntoThyra(
30  const Tpetra::MultiVector<ST, LO, GO, NT>& X,
31  const Teuchos::Ptr<Thyra::MultiVectorBase<ST> >& thyra_X) const {
32  using Teuchos::ptr_const_cast;
33  using Teuchos::rcp_const_cast;
34 
35  // first flatten the vector: notice this just works on the block structure
36  RCP<Thyra::ProductMultiVectorBase<ST> > prod_X =
37  rcp_dynamic_cast<Thyra::ProductMultiVectorBase<ST> >(rcpFromRef(*thyra_X));
38  RCP<Thyra::MultiVectorBase<ST> > flat_X = buildFlatMultiVector(reorderManager_, prod_X);
39 
40  // now use the underlying mapping strategy to copy the flat vector
41  mapStrategy_->copyTpetraIntoThyra(X, flat_X.ptr());
42 }
43 
44 void TpetraReorderedMappingStrategy::copyThyraIntoTpetra(
45  const RCP<const Thyra::MultiVectorBase<ST> >& thyra_Y,
46  Tpetra::MultiVector<ST, LO, GO, NT>& Y) const {
47  // first flatten the vector: notice this just works on the block structure
48  RCP<const Thyra::ProductMultiVectorBase<ST> > prod_Y =
49  rcp_dynamic_cast<const Thyra::ProductMultiVectorBase<ST> >(rcpFromRef(*thyra_Y));
50  RCP<const Thyra::MultiVectorBase<ST> > flat_Y = buildFlatMultiVector(reorderManager_, prod_Y);
51 
52  // now use the underlying mapping strategy to copy the flat vector
53  mapStrategy_->copyThyraIntoTpetra(flat_Y, Y);
54 }
55 
56 } // end namespace TpetraHelpers
57 } // end namespace Teko