10#ifndef TPETRA_FECRSMATRIX_DEF_HPP
11#define TPETRA_FECRSMATRIX_DEF_HPP
13#include "Tpetra_CrsMatrix.hpp"
17template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
20 const Teuchos::RCP<Teuchos::ParameterList>&
params) :
27 const char tfecfFuncName[] =
"FECrsMatrix(RCP<const FECrsGraph>[, RCP<ParameterList>]): ";
30 (
graph.is_null (), std::runtime_error,
"Input graph is null.");
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 "
39 ( *
graph->activeCrsGraph_!= FE::ACTIVE_OWNED,std::runtime_error,
40 "Input graph must be in FE::ACTIVE_OWNED mode when this constructor is called.");
44 if (
params->isParameter (
"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));
66template<
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();
77template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
82template<
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_);
96template<
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()");
106template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
107void FECrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::beginFill() {
110 if(*activeCrsMatrix_ == FE::ACTIVE_OWNED) {
112 switchActiveCrsMatrix();
117template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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");
128 *fillState_ = FE::FillState::open;
132template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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");
143 *fillState_ = FE::FillState::closed;
147template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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");
158 *fillState_ = FE::FillState::modify;
162template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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");
172 *fillState_ = FE::FillState::closed;
173 this->fillComplete();
176template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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");
198template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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";
219template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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");
244template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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");
269template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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");
298#define TPETRA_FECRSMATRIX_INSTANT(SCALAR,LO,GO,NODE) \
299 template class FECrsMatrix<SCALAR, LO, GO, NODE>;
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
Struct that holds views of the contents of a CrsMatrix.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries.
virtual void insertGlobalValuesImpl(crs_graph_type &graph, RowInfo &rowInfo, const GlobalOrdinal gblColInds[], const impl_scalar_type vals[], const size_t numInputEnt)
Common implementation detail of insertGlobalValues and insertGlobalValuesFiltered.
virtual LocalOrdinal sumIntoGlobalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const GlobalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts, const bool atomic=useAtomicUpdatesByDefault)
Implementation detail of sumIntoGlobalValues.
void fillComplete(const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Tell the matrix that you are done changing its structure or values, and that you are ready to do comp...
virtual LocalOrdinal sumIntoLocalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const LocalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts, const bool atomic=useAtomicUpdatesByDefault)
Implementation detail of sumIntoLocalValues.
virtual LocalOrdinal replaceLocalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const LocalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts)
Implementation detail of replaceLocalValues.
virtual 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)
Implementation detail of replaceGlobalValues.
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.
void beginAssembly()
Activates the owned+shared mode for assembly.
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 insertGlobalValuesImpl(crs_graph_type &graph, RowInfo &rowInfo, const GlobalOrdinal gblColInds[], const impl_scalar_type vals[], const size_t numInputEnt)
Common implementation detail of insertGlobalValues and insertGlobalValuesFiltered.
LocalOrdinal replaceLocalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const LocalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts)
Implementation detail of replaceLocalValues.
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.
CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::impl_scalar_type impl_scalar_type
The type used internally in place of Scalar.
void endAssembly()
Migrates data to the owned mode.
void doOwnedPlusSharedToOwned(const CombineMode CM=Tpetra::ADD)
Migrate data from the owned+shared to the owned matrix Since this is non-unique -> unique,...
void endModify()
Closes modification phase.
void beginModify()
Activates the owned mode for modifying local values.
LocalOrdinal sumIntoGlobalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const GlobalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts, const bool atomic=useAtomicUpdatesByDefault)
Implementation detail of sumIntoGlobalValues.
LocalOrdinal sumIntoLocalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const LocalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts, const bool atomic=useAtomicUpdatesByDefault)
Implementation detail of sumIntoLocalValues.
void switchActiveCrsMatrix()
Switches which CrsGraph is active (without migrating data)
void doOwnedToOwnedPlusShared(const CombineMode CM=Tpetra::ADD)
Migrate data from the owned to the owned+shared matrix Precondition: Must be FE_ACTIVE_OWNED mode.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
CombineMode
Rule for combining data in an Import or Export.
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.