Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_FEMultiVector_def.hpp
1// @HEADER
2// *****************************************************************************
3// Tpetra: Templated Linear Algebra Services Package
4//
5// Copyright 2008 NTESS and the Tpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef TPETRA_FEMULTIVECTOR_DEF_HPP
11#define TPETRA_FEMULTIVECTOR_DEF_HPP
12
15
16#include "Tpetra_Map.hpp"
17#include "Tpetra_MultiVector.hpp"
18#include "Tpetra_Import.hpp"
20
21
22namespace Tpetra {
23
24template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
25FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
26FEMultiVector (const Teuchos::RCP<const map_type>& map,
27 const Teuchos::RCP<const Import<local_ordinal_type, global_ordinal_type, node_type>>& importer,
28 const size_t numVecs,
29 const bool zeroOut) :
30 base_type (importer.is_null () ? map : importer->getTargetMap (),
31 numVecs, zeroOut),
32 activeMultiVector_ (Teuchos::rcp (new FE::WhichActive (FE::ACTIVE_OWNED_PLUS_SHARED))),
33 importer_ (importer)
34{
35 const char tfecfFuncName[] = "FEMultiVector constructor: ";
36
37 if (! importer_.is_null ()) {
38 const bool debug = ::Tpetra::Details::Behavior::debug ();
39 if (debug) {
40 // Checking Map sameness may require an all-reduce, so we should
41 // reserve it for debug mode.
42 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
43 (! importer_->getSourceMap ()->isSameAs (*map),
44 std::runtime_error,
45 "If you provide a nonnull Import, then the input Map "
46 "must be the same as the input Import's source Map.");
47
48 // Checking whether one Map is locally fitted to another could be
49 // expensive.
50 const bool locallyFitted =
51 importer->getTargetMap ()->isLocallyFitted (* (importer->getSourceMap ()));
52 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
53 (! locallyFitted, std::runtime_error,
54 "If you provide a nonnull Import, then its target Map must be "
55 "locally fitted (see Map::isLocallyFitted documentation) to its "
56 "source Map.");
57 }
58
59 // Memory aliasing is required for FEMultiVector
60 inactiveMultiVector_ =
61 Teuchos::rcp (new base_type (*this, importer_->getSourceMap(), 0));
62 }
63 fillState_ = Teuchos::rcp(new FE::FillState(FE::FillState::closed));
64}
65
66template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
67void
68FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
69beginFill ()
70{
71 // The FEMultiVector is in owned+shared mode on construction, so we
72 // do not throw in that case.
73 if (*activeMultiVector_ == FE::ACTIVE_OWNED) {
74 switchActiveMultiVector ();
75 }
76}
77
78template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
79void
80FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
81endFill ()
82{
83 const char tfecfFuncName[] = "endFill: ";
84
85 if (*activeMultiVector_ == FE::ACTIVE_OWNED_PLUS_SHARED) {
86 doOwnedPlusSharedToOwned (Tpetra::ADD);
87 switchActiveMultiVector ();
88 }
89 else {
90 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
91 (true, std::runtime_error, "Owned+Shared MultiVector already active; "
92 "cannot call endFill.");
93 }
94}
95
96template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
97void FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::beginAssembly() {
98 const char tfecfFuncName[] = "FEMultiVector::beginAssembly: ";
99 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
100 *fillState_ != FE::FillState::closed,
101 std::runtime_error,
102 "Cannot beginAssembly, matrix is not in a closed state"
103 );
104 *fillState_ = FE::FillState::open;
105 this->beginFill();
106}
107
108template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
109void FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::endAssembly() {
110 const char tfecfFuncName[] = "FEMultiVector::endAssembly: ";
111 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
112 *fillState_ != FE::FillState::open,
113 std::runtime_error,
114 "Cannot endAssembly, matrix is not open to fill."
115 );
116 *fillState_ = FE::FillState::closed;
117 this->endFill();
118}
119
120template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
121void FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::beginModify() {
122 const char tfecfFuncName[] = "FEMultiVector::beginModify: ";
123 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
124 *fillState_ != FE::FillState::closed,
125 std::runtime_error,
126 "Cannot beginModify, matrix is not in a closed state"
127 );
128 *fillState_ = FE::FillState::modify;
129}
130
131template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
132void FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::endModify() {
133 const char tfecfFuncName[] = "FEMultiVector::endModify: ";
134 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
135 *fillState_ != FE::FillState::modify,
136 std::runtime_error,
137 "Cannot endModify, matrix is not open to modify."
138 );
139 *fillState_ = FE::FillState::closed;
140}
141
142template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
143void
144FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
145globalAssemble ()
146{
147 endFill ();
148}
149
150template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
151void
152FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
153replaceMap (const Teuchos::RCP<const map_type>& /* newMap */)
154{
155 const char tfecfFuncName[] = "replaceMap: ";
156
157 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
158 (true, std::runtime_error, "This method is not implemented.");
159}
160
161template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
162void
163FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
164doOwnedPlusSharedToOwned (const CombineMode CM)
165{
166 if (! importer_.is_null () &&
167 *activeMultiVector_ == FE::ACTIVE_OWNED_PLUS_SHARED) {
168 inactiveMultiVector_->doExport (*this, *importer_, CM);
169 }
170}
171
172template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
173void
174FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
175doOwnedToOwnedPlusShared (const CombineMode CM)
176{
177 if (! importer_.is_null () &&
178 *activeMultiVector_ == FE::ACTIVE_OWNED) {
179 inactiveMultiVector_->doImport (*this, *importer_, CM);
180 }
181}
182
183template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
184void
185FEMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
186switchActiveMultiVector ()
187{
188 if (*activeMultiVector_ == FE::ACTIVE_OWNED_PLUS_SHARED) {
189 *activeMultiVector_ = FE::ACTIVE_OWNED;
190 }
191 else {
192 *activeMultiVector_ = FE::ACTIVE_OWNED_PLUS_SHARED;
193 }
194
195 if (importer_.is_null ()) {
196 return;
197 }
198
199 // Use MultiVector's swap routine here
200 this->swap (*inactiveMultiVector_);
201}
202
203} // namespace Tpetra
204
205//
206// Explicit instantiation macro
207//
208// Must be expanded from within the Tpetra namespace!
209//
210
211#define TPETRA_FEMULTIVECTOR_INSTANT(SCALAR,LO,GO,NODE) \
212 template class FEMultiVector< SCALAR , LO , GO , NODE >;
213
214#endif // TPETRA_FEMULTIVECTOR_DEF_HPP
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
Namespace Tpetra contains the class and methods constituting the Tpetra library.
@ ADD
Sum new values.