43 #ifndef IFPACK2_ILUK_GRAPH_HPP 44 #define IFPACK2_ILUK_GRAPH_HPP 49 #include <Ifpack2_ConfigDefs.hpp> 50 #include <Teuchos_RCP.hpp> 51 #include <Teuchos_ParameterList.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);
115 void setParameters(
const Teuchos::ParameterList& parameterlist);
134 const Teuchos::RCP<Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> >&
getL_Graph()
const {
return(L_Graph_);}
137 const Teuchos::RCP<Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> >&
getU_Graph()
const {
return(U_Graph_);}
140 const Teuchos::RCP<Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> >&
getOverlapGraph()
const {
return(OverlapGraph_);}
146 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> TpetraMapType;
147 typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> TpetraCrsGraphType;
149 Teuchos::RCP<const TpetraCrsGraphType > Graph_;
150 Teuchos::RCP<const TpetraCrsGraphType > OverlapGraph_;
153 Teuchos::RCP<TpetraCrsGraphType > L_Graph_;
154 Teuchos::RCP<TpetraCrsGraphType > U_Graph_;
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;
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();
227 Teuchos::Array<LocalOrdinal> L(MaxNumIndices);
228 Teuchos::Array<LocalOrdinal> U(MaxNumIndices);
232 int NumMyRows = OverlapGraph_->getRowMap()->getNodeNumElements();
235 for (
int i=0; i< NumMyRows; i++) {
237 Teuchos::ArrayView<const LocalOrdinal> my_indices;
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_;
269 Teuchos::ArrayView<LocalOrdinal> Lview(&L[0], NumL);
270 L_Graph_->insertLocalIndices(i, Lview );
273 Teuchos::ArrayView<LocalOrdinal> Uview(&U[0], NumU);
274 U_Graph_->insertLocalIndices(i, Uview );
278 if (LevelFill_ > 0) {
281 Teuchos::RCP<const TpetraMapType> L_DomainMap = OverlapGraph_->getRowMap();
282 Teuchos::RCP<const TpetraMapType> L_RangeMap = Graph_->getRangeMap();
283 Teuchos::RCP<const TpetraMapType> U_DomainMap = Graph_->getDomainMap();
284 Teuchos::RCP<const TpetraMapType> U_RangeMap = OverlapGraph_->getRowMap();
285 Teuchos::RCP<Teuchos::ParameterList> params = Teuchos::rcp(
new Teuchos::ParameterList());
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);
300 Teuchos::Array<LocalOrdinal> CurrentRow(MaxRC+1);
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;
313 CurrentRow.resize(Len);
315 L_Graph_->getLocalRowCopy(i, CurrentRow(), LenL);
316 CurrentRow[LenL] = i;
318 Teuchos::ArrayView<LocalOrdinal> URowView(&CurrentRow[LenL+1], LenU);
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];
343 Teuchos::ArrayView<const LocalOrdinal> IndicesU;
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());
404 TEUCHOS_TEST_FOR_EXCEPTION(Next != i, std::runtime_error,
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];
436 Teuchos::RCP<const TpetraMapType> L_DomainMap = OverlapGraph_->getRowMap();
437 Teuchos::RCP<const TpetraMapType> L_RangeMap = Graph_->getRangeMap();
438 Teuchos::RCP<const TpetraMapType> U_DomainMap = Graph_->getDomainMap();
439 Teuchos::RCP<const TpetraMapType> U_RangeMap = OverlapGraph_->getRowMap();
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
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
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
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
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
Ifpack2::Container: a pure virtual class for creating and solving local linear problems.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:67
virtual ~IlukGraph()
IlukGraph Destructor.
Definition: Ifpack2_IlukGraph.hpp:191