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