Tpetra parallel linear algebra  Version of the Day
Tpetra_FEMultiVector_def.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef TPETRA_FEMULTIVECTOR_DEF_HPP
43 #define TPETRA_FEMULTIVECTOR_DEF_HPP
44 
47 
48 #include "Tpetra_Map.hpp"
49 #include "Tpetra_MultiVector.hpp"
50 #include "Tpetra_Import.hpp"
51 
52 namespace Tpetra {
53 namespace Classes {
54 
55 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
57 FEMultiVector(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > & map,
58  const Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >& importer,
59  const size_t numVecs,
60  const bool zeroOut):
61  base_type(importer.is_null()? map:importer->getTargetMap(),numVecs,zeroOut),
62  importer_(importer) {
63 
64  activeMultiVector_ = Teuchos::rcp(new FEWhichActive(FE_ACTIVE_TARGET));
65 
66  // Sanity check the importer
67  if(!importer_.is_null() && !importer_->getSourceMap()->isSameAs(*map)) {
68  throw std::runtime_error("FEMultiVector: 'map' must match 'importer->getSourceMap()' if importer is provided");
69  }
70 
71  if(!importer_.is_null()) {
72  // Check maps to see if we can reuse memory (aka do numSames == domainMap->getNodeNumElements())
73  if(importer_->getNumSameIDs() == importer->getSourceMap()->getNodeNumElements()) {
74  // 1) If so, we then build the inactiveMultiVector_ (w/ source map) using a restricted DualView
75  inactiveMultiVector_ = Teuchos::rcp(new base_type(importer_->getSourceMap(),Kokkos::subview(this->view_,Kokkos::pair<size_t,size_t>(0,map->getNodeNumElements()),Kokkos::ALL)));
76  }
77  else {
78  // 2) If not call a new constructor for the inactive guy (w/ source map)
79  inactiveMultiVector_ = Teuchos::rcp(new base_type(importer_->getSourceMap(),numVecs,zeroOut));
80  }
81  }
82 }// end constructor
83 
84 
85 
86 
87 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
88 void FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::replaceMap (const Teuchos::RCP<const map_type>& newMap) {
89  throw std::runtime_error("Tpetra::FEMultiVector::replaceMap() is not implemented");
90 }// end replaceMap
91 
92 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
93 void FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::doTargetToSource(const CombineMode CM) {
94  if(!importer_.is_null() && *activeMultiVector_ == FE_ACTIVE_TARGET) {
95  inactiveMultiVector_->doExport(*this,*importer_,CM);
96  }
97 }//end doTargetToSource
98 
99 
100 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
101 void FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::doSourceToTarget(const CombineMode CM) {
102  if(!importer_.is_null() && *activeMultiVector_ == FE_ACTIVE_SOURCE) {
103  inactiveMultiVector_->doImport(*this,*importer_,CM);
104  }
105 }//end doTargetToSource
106 
107 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
108 void FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::switchActiveMultiVector() {
109  if(*activeMultiVector_ == FE_ACTIVE_TARGET)
110  *activeMultiVector_ = FE_ACTIVE_SOURCE;
111  else
112  *activeMultiVector_ = FE_ACTIVE_TARGET;
113 
114  if(importer_.is_null()) return;
115 
116  // Use MultiVector's swap routine here
117  this->swap(*inactiveMultiVector_);
118 
119 }//end switchActiveMultiVector
120 
121 } // namespace Classes
122 } // namespace Tpetra
123 
124 //
125 // Explicit instantiation macro
126 //
127 // Must be expanded from within the Tpetra namespace!
128 //
129 
130 #define TPETRA_FEMULTIVECTOR_INSTANT(SCALAR,LO,GO,NODE) \
131  namespace Classes { \
132  template class FEMultiVector< SCALAR , LO , GO , NODE >; \
133  }
134 
135 #endif // TPETRA_FEMULTIVECTOR_DEF_HPP
136 
137 
Tpetra::FEMultiVector
Classes::FEMultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > FEMultiVector
Alias for Tpetra::Classes::FEMultiVector.
Definition: Tpetra_FEMultiVector_fwd.hpp:72
Tpetra
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Tpetra::CombineMode
CombineMode
Rule for combining data in an Import or Export.
Definition: Tpetra_CombineMode.hpp:94