43 #ifndef IFPACK2_ILUK_GRAPH_HPP
44 #define IFPACK2_ILUK_GRAPH_HPP
49 #include <Ifpack2_ConfigDefs.hpp>
52 #include <Teuchos_Describable.hpp>
53 #include <Teuchos_CommHelpers.hpp>
54 #include <Tpetra_CrsGraph.hpp>
55 #include <Tpetra_Import.hpp>
56 #include <Ifpack2_CreateOverlapGraph.hpp>
57 #include <Ifpack2_Parameters.hpp>
82 template<
class LocalOrdinal,
class GlobalOrdinal = LocalOrdinal,
class Node = Kokkos::DefaultNode::DefaultNodeType>
101 IlukGraph(
const Teuchos::RCP<
const Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> > &Graph_in,
int LevelFill_in,
int LevelOverlap_in);
146 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> TpetraMapType;
147 typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> TpetraCrsGraphType;
155 size_t NumMyDiagonals_;
156 size_t NumGlobalDiagonals_;
160 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
164 LevelFill_(LevelFill_in),
165 LevelOverlap_(LevelOverlap_in),
167 NumGlobalDiagonals_(0)
172 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
174 : Graph_(Graph_in.Graph_),
175 OverlapGraph_(Graph_in.OverlapGraph_),
176 LevelFill_(Graph_in.LevelFill_),
177 LevelOverlap_(Graph_in.LevelOverlap_),
181 NumGlobalDiagonals_(0)
183 TpetraCrsGraphType & L_Graph_In = Graph_in.L_Graph();
184 TpetraCrsGraphType & U_Graph_In = Graph_in.U_Graph();
185 L_Graph_ =
Teuchos::rcp(
new TpetraCrsGraphType(L_Graph_In) );
186 U_Graph_ =
Teuchos::rcp(
new TpetraCrsGraphType(U_Graph_In) );
190 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
196 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
199 getParameter(parameterlist,
"iluk level-of-fill", LevelFill_);
200 getParameter(parameterlist,
"iluk level-of-overlap", LevelOverlap_);
204 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
207 if (OverlapGraph_ == Teuchos::null) {
213 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
215 size_t NumIn, NumL, NumU;
218 constructOverlapGraph();
220 L_Graph_ =
Teuchos::rcp(
new TpetraCrsGraphType(OverlapGraph_->getRowMap(), OverlapGraph_->getRowMap(), 0));
221 U_Graph_ =
Teuchos::rcp(
new TpetraCrsGraphType(OverlapGraph_->getRowMap(), OverlapGraph_->getRowMap(), 0));
225 int MaxNumIndices = OverlapGraph_->getNodeMaxNumRowEntries();
232 int NumMyRows = OverlapGraph_->getRowMap()->getNodeNumElements();
235 for (
int i=0; i< NumMyRows; i++) {
238 OverlapGraph_->getLocalRowView(i,my_indices);
245 NumIn = my_indices.
size();
247 for (
size_t j=0; j< NumIn; j++) {
248 LocalOrdinal k = my_indices[j];
252 if (k==i) DiagFound =
true;
267 if (DiagFound) ++NumMyDiagonals_;
270 L_Graph_->insertLocalIndices(i, Lview );
274 U_Graph_->insertLocalIndices(i, Uview );
278 if (LevelFill_ > 0) {
286 params->
set(
"Optimize Storage",
false);
287 L_Graph_->fillComplete(L_DomainMap, L_RangeMap, params);
288 U_Graph_->fillComplete(U_DomainMap, U_RangeMap, params);
289 L_Graph_->resumeFill();
290 U_Graph_->resumeFill();
296 int MaxRC = NumMyRows;
297 std::vector<std::vector<int> > Levels(MaxRC);
298 std::vector<int> LinkList(MaxRC);
299 std::vector<int> CurrentLevel(MaxRC);
301 std::vector<int> LevelsRowU(MaxRC);
303 for (
int i=0; i<NumMyRows; i++)
309 size_t LenL = L_Graph_->getNumEntriesInLocalRow(i);
310 size_t LenU = U_Graph_->getNumEntriesInLocalRow(i);
311 size_t Len = LenL + LenU + 1;
315 L_Graph_->getLocalRowCopy(i, CurrentRow(), LenL);
316 CurrentRow[LenL] = i;
320 U_Graph_->getLocalRowCopy(i, URowView, LenU);
325 for (
size_t j=0; j<Len-1; j++) {
326 LinkList[CurrentRow[j]] = CurrentRow[j+1];
327 CurrentLevel[CurrentRow[j]] = 0;
330 LinkList[CurrentRow[Len-1]] = NumMyRows;
331 CurrentLevel[CurrentRow[Len-1]] = 0;
335 First = CurrentRow[0];
339 int PrevInList = Next;
340 int NextInList = LinkList[Next];
344 U_Graph_->getLocalRowView(RowU,IndicesU);
345 int LengthRowU = IndicesU.
size();
351 for (ii=0; ii<LengthRowU; )
353 int CurInList = IndicesU[ii];
354 if (CurInList < NextInList)
357 int NewLevel = CurrentLevel[RowU] + Levels[RowU][ii+1] + 1;
358 if (NewLevel <= LevelFill_)
360 LinkList[PrevInList] = CurInList;
361 LinkList[CurInList] = NextInList;
362 PrevInList = CurInList;
363 CurrentLevel[CurInList] = NewLevel;
367 else if (CurInList == NextInList)
369 PrevInList = NextInList;
370 NextInList = LinkList[PrevInList];
371 int NewLevel = CurrentLevel[RowU] + Levels[RowU][ii+1] + 1;
372 CurrentLevel[CurInList] = std::min(CurrentLevel[CurInList], NewLevel);
377 PrevInList = NextInList;
378 NextInList = LinkList[PrevInList];
381 Next = LinkList[Next];
386 CurrentRow.resize(0);
393 CurrentRow.push_back(Next);
394 Next = LinkList[Next];
397 L_Graph_->removeLocalIndices(i);
398 if (CurrentRow.size() > 0) {
399 L_Graph_->insertLocalIndices(i, CurrentRow());
405 "Ifpack2::IlukGraph::constructFilledGraph: FATAL: U has zero diagonal")
407 LevelsRowU[0] = CurrentLevel[Next];
408 Next = LinkList[Next];
412 CurrentRow.resize(0);
415 while (Next < NumMyRows) {
416 LevelsRowU[LenU+1] = CurrentLevel[Next];
417 CurrentRow.push_back(Next);
419 Next = LinkList[Next];
422 U_Graph_->removeLocalIndices(i);
424 U_Graph_->insertLocalIndices(i, CurrentRow());
428 Levels[i] = std::vector<int>(LenU+1);
429 for (
size_t jj=0; jj<LenU+1; jj++) {
430 Levels[i][jj] = LevelsRowU[jj];
440 L_Graph_->fillComplete(L_DomainMap, L_RangeMap);
441 U_Graph_->fillComplete(U_DomainMap, U_RangeMap);
443 Teuchos::reduceAll<int,size_t>(*(L_DomainMap->getComm()),
Teuchos::REDUCE_SUM, 1, &NumMyDiagonals_, &NumGlobalDiagonals_);
size_t getNumGlobalDiagonals() const
Returns the global number of diagonals in the ILU(k) graph.
Definition: Ifpack2_IlukGraph.hpp:143
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Teuchos::RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > CreateOverlapGraph(const Teuchos::RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &input_graph, int OverlapLevel)
Constructs an overlapped graph for use with Ifpack2 preconditioners.
Definition: Ifpack2_CreateOverlapGraph.hpp:60
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
int getLevelFill() const
Returns the level of fill used to construct this graph.
Definition: Ifpack2_IlukGraph.hpp:128
void getParameter(const Teuchos::ParameterList ¶ms, const std::string &name, T &value)
Set a value from a ParameterList if a parameter with the specified name exists.
Definition: Ifpack2_Parameters.hpp:59
void constructFilledGraph()
This method performs the actual construction of the graph.
Definition: Ifpack2_IlukGraph.hpp:214
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void constructOverlapGraph()
Does the actual construction of the overlap matrix graph.
Definition: Ifpack2_IlukGraph.hpp:205
const Teuchos::RCP< Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > & getU_Graph() const
Returns the graph of upper triangle of the ILU(k) graph as a Tpetra::CrsGraph.
Definition: Ifpack2_IlukGraph.hpp:137
const Teuchos::RCP< Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > & getL_Graph() const
Returns the graph of lower triangle of the ILU(k) graph as a Tpetra::CrsGraph.
Definition: Ifpack2_IlukGraph.hpp:134
void resize(size_type new_size, const value_type &x=value_type())
A class for constructing level filled graphs for use with ILU(k) class preconditioners.
Definition: Ifpack2_IlukGraph.hpp:83
const Teuchos::RCP< Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > & getOverlapGraph() const
Returns the the overlapped graph.
Definition: Ifpack2_IlukGraph.hpp:140
int getLevelOverlap() const
Returns the level of overlap used to construct this graph.
Definition: Ifpack2_IlukGraph.hpp:131
IlukGraph(const Teuchos::RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &Graph_in, int LevelFill_in, int LevelOverlap_in)
IlukGraph constuctor.
Definition: Ifpack2_IlukGraph.hpp:161
void setParameters(const Teuchos::ParameterList ¶meterlist)
Set parameters using Teuchos::ParameterList object.
Definition: Ifpack2_IlukGraph.hpp:197
virtual ~IlukGraph()
IlukGraph Destructor.
Definition: Ifpack2_IlukGraph.hpp:191