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