10 #ifndef TPETRA_FECRSMATRIX_DEF_HPP
11 #define TPETRA_FECRSMATRIX_DEF_HPP
13 #include "Tpetra_CrsMatrix.hpp"
17 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
19 FECrsMatrix(
const Teuchos::RCP<const fe_crs_graph_type>& graph,
20 const Teuchos::RCP<Teuchos::ParameterList>& params) :
27 const char tfecfFuncName[] =
"FECrsMatrix(RCP<const FECrsGraph>[, RCP<ParameterList>]): ";
29 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
30 (graph.is_null (), std::runtime_error,
"Input graph is null.");
31 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
32 (!graph->isFillComplete (), std::runtime_error,
"Input graph is not "
33 "fill complete. You must call fillComplete on the graph before using "
34 "it to construct a FECrsMatrix. Note that calling resumeFill on the "
35 "graph makes it not fill complete, even if you had previously called "
36 "fillComplete. In that case, you must call fillComplete on the graph "
38 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
39 ( *graph->activeCrsGraph_!= FE::ACTIVE_OWNED,std::runtime_error,
40 "Input graph must be in FE::ACTIVE_OWNED mode when this constructor is called.");
42 bool start_owned =
false;
43 if (! params.is_null ()) {
44 if (params->isParameter (
"start owned")) {
45 start_owned = params->get<
bool>(
"start owned", start_owned);
49 activeCrsMatrix_ = Teuchos::rcp(
new FE::WhichActive(FE::ACTIVE_OWNED));
51 activeCrsMatrix_ = Teuchos::rcp(
new FE::WhichActive(FE::ACTIVE_OWNED_PLUS_SHARED));
55 if(!graph->inactiveCrsGraph_.is_null() ) {
61 fillState_ = Teuchos::rcp(
new FE::FillState(FE::FillState::closed));
66 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
68 if(!inactiveCrsMatrix_.is_null() && *activeCrsMatrix_ == FE::ACTIVE_OWNED_PLUS_SHARED) {
70 this->doExport(*
this,*feGraph_->ownedRowsImporter_,CM,
true);
71 inactiveCrsMatrix_->fillComplete();
73 crs_matrix_type::fillComplete();
77 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
82 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
84 if(*activeCrsMatrix_ == FE::ACTIVE_OWNED_PLUS_SHARED)
85 *activeCrsMatrix_ = FE::ACTIVE_OWNED;
87 *activeCrsMatrix_ = FE::ACTIVE_OWNED_PLUS_SHARED;
89 if(inactiveCrsMatrix_.is_null())
return;
91 this->swap(*inactiveCrsMatrix_);
96 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
98 if(*activeCrsMatrix_ == FE::ACTIVE_OWNED_PLUS_SHARED) {
100 switchActiveCrsMatrix();
103 throw std::runtime_error(
"FECrsMatrix: Local CrsMatrix already active. Cannot endFill()");
106 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
107 void FECrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::beginFill() {
110 if(*activeCrsMatrix_ == FE::ACTIVE_OWNED) {
112 switchActiveCrsMatrix();
117 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
119 const char tfecfFuncName[] =
"FECrsMatrix::beginAssembly: ";
120 if (*fillState_ != FE::FillState::closed)
122 std::ostringstream errmsg;
123 errmsg <<
"Cannot begin assembly, matrix is not in a closed state "
124 <<
"but is currently open for "
125 << (*fillState_ == FE::FillState::open ?
"assembly" :
"modification");
126 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
true, std::logic_error, errmsg.str());
128 *fillState_ = FE::FillState::open;
132 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
134 const char tfecfFuncName[] =
"FECrsMatrix::endAssembly: ";
135 if (*fillState_ != FE::FillState::open)
137 std::ostringstream errmsg;
138 errmsg <<
"Cannot end assembly, matrix is not open for assembly "
139 <<
"but is currently "
140 << (*fillState_ == FE::FillState::closed ?
"closed" :
"open for modification");
141 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
true, std::logic_error, errmsg.str());
143 *fillState_ = FE::FillState::closed;
147 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
149 const char tfecfFuncName[] =
"FECrsMatrix::beginModify: ";
150 if (*fillState_ != FE::FillState::closed)
152 std::ostringstream errmsg;
153 errmsg <<
"Cannot begin modifying, matrix is not in a closed state "
154 <<
"but is currently open for "
155 << (*fillState_ == FE::FillState::open ?
"assembly" :
"modification");
156 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
true, std::logic_error, errmsg.str());
158 *fillState_ = FE::FillState::modify;
162 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
164 const char tfecfFuncName[] =
"FECrsMatrix::endModify: ";
165 if (*fillState_ != FE::FillState::modify)
167 std::ostringstream errmsg;
168 errmsg <<
"Cannot end modifying, matrix is not open to modify but is currently "
169 << (*fillState_ == FE::FillState::open ?
"open for assembly" :
"closed");
170 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
true, std::logic_error, errmsg.str());
172 *fillState_ = FE::FillState::closed;
173 this->fillComplete();
176 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
182 const GlobalOrdinal inds[],
184 const LocalOrdinal numElts)
186 const char tfecfFuncName[] =
"FECrsMatrix::replaceGlobalValues: ";
187 if (*fillState_ != FE::FillState::open)
189 std::ostringstream errmsg;
190 errmsg <<
"Cannot replace global values, matrix is not open for assembly "
191 <<
"but is currently "
192 << (*fillState_ == FE::FillState::modify ?
"open for modification" :
"closed");
193 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
true, std::logic_error, errmsg.str());
195 return crs_matrix_type::replaceGlobalValuesImpl(rowVals, graph, rowInfo, inds, newVals, numElts);
198 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
201 impl_scalar_type rowVals[],
202 const crs_graph_type& graph,
204 const LocalOrdinal inds[],
205 const impl_scalar_type newVals[],
206 const LocalOrdinal numElts)
208 const char tfecfFuncName[] =
"FECrsMatrix::replaceLocalValues: ";
209 if (*fillState_ != FE::FillState::open && *fillState_ != FE::FillState::modify)
211 std::ostringstream errmsg;
212 errmsg <<
"Cannot replace local values, matrix is not open to fill/modify. "
213 <<
"The matrix is currently closed";
214 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
true, std::logic_error, errmsg.str());
216 return crs_matrix_type::replaceLocalValuesImpl(rowVals, graph, rowInfo, inds, newVals, numElts);
219 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
221 FECrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::sumIntoGlobalValuesImpl(
222 impl_scalar_type rowVals[],
223 const crs_graph_type& graph,
224 const RowInfo& rowInfo,
225 const GlobalOrdinal inds[],
226 const impl_scalar_type newVals[],
227 const LocalOrdinal numElts,
230 const char tfecfFuncName[] =
"FECrsMatrix::sumIntoGlobalValues: ";
231 if (*fillState_ != FE::FillState::open)
233 std::ostringstream errmsg;
234 errmsg <<
"Cannot sum in to global values, matrix is not open for assembly. "
235 <<
"The matrix is currently "
236 << (*fillState_ == FE::FillState::modify ?
"open for modification" :
"closed");
237 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
true, std::logic_error, errmsg.str());
239 return crs_matrix_type::sumIntoGlobalValuesImpl(
240 rowVals, graph, rowInfo, inds, newVals, numElts, atomic
244 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
246 FECrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::sumIntoLocalValuesImpl(
247 impl_scalar_type rowVals[],
248 const crs_graph_type& graph,
249 const RowInfo& rowInfo,
250 const LocalOrdinal inds[],
251 const impl_scalar_type newVals[],
252 const LocalOrdinal numElts,
255 const char tfecfFuncName[] =
"FECrsMatrix::sumIntoLocalValues: ";
256 if (*fillState_ != FE::FillState::open)
258 std::ostringstream errmsg;
259 errmsg <<
"Cannot sum in to local values, matrix is not open for assembly. "
260 <<
"The matrix is currently "
261 << (*fillState_ == FE::FillState::modify ?
"open for modification" :
"closed");
262 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
true, std::logic_error, errmsg.str());
264 return crs_matrix_type::sumIntoLocalValuesImpl(
265 rowVals, graph, rowInfo, inds, newVals, numElts, atomic
269 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
271 FECrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::insertGlobalValuesImpl(
272 crs_graph_type& graph,
274 const GlobalOrdinal gblColInds[],
275 const impl_scalar_type vals[],
276 const size_t numInputEnt)
278 const char tfecfFuncName[] =
"FECrsMatrix::insertGlobalValues: ";
279 if (*fillState_ != FE::FillState::open)
281 std::ostringstream errmsg;
282 errmsg <<
"Cannot insert global values, matrix is not open for assembly. "
283 <<
"The matrix is currently "
284 << (*fillState_ == FE::FillState::modify ?
"open for modification" :
"closed");
285 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
true, std::logic_error, errmsg.str());
287 return crs_matrix_type::insertGlobalValuesImpl(graph, rowInfo, gblColInds, vals, numInputEnt);
298 #define TPETRA_FECRSMATRIX_INSTANT(SCALAR,LO,GO,NODE) \
299 template class FECrsMatrix<SCALAR, LO, GO, NODE>;
303 #endif // TPETRA_FECRSMATRIX_DEF
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > crs_matrix_type
Parent CrsMatrix type using the same scalars.
LocalOrdinal replaceGlobalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const GlobalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts)
Overloads of modification methods.
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.
void doOwnedToOwnedPlusShared(const CombineMode CM=Tpetra::ADD)
Migrate data from the owned to the owned+shared matrix Precondition: Must be FE_ACTIVE_OWNED mode...
void switchActiveCrsMatrix()
Switches which CrsGraph is active (without migrating data)
CombineMode
Rule for combining data in an Import or Export.
void beginAssembly()
Activates the owned+shared mode for assembly.
void endModify()
Closes modification phase.
void doOwnedPlusSharedToOwned(const CombineMode CM=Tpetra::ADD)
Migrate data from the owned+shared to the owned matrix Since this is non-unique -> unique...
FECrsMatrix(const Teuchos::RCP< const fe_crs_graph_type > &graph, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Constructor specifying one or two previously constructed graphs.
void endAssembly()
Migrates data to the owned mode.
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
typename row_matrix_type::impl_scalar_type impl_scalar_type
The type used internally in place of Scalar.
void beginModify()
Activates the owned mode for modifying local values.