MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_CreateEpetraPreconditioner.cpp
Go to the documentation of this file.
1 #ifndef MUELU_CREATE_EPETRA_PRECONDITIONER_CPP
2 #define MUELU_CREATE_EPETRA_PRECONDITIONER_CPP
3 
5 #include <Xpetra_CrsMatrix.hpp>
6 #include <Xpetra_MultiVector.hpp>
8 
9 #include <MueLu.hpp>
10 
11 #include <MueLu_EpetraOperator.hpp>
12 #include <MueLu_Exceptions.hpp>
13 #include <MueLu_Hierarchy.hpp>
15 #include <MueLu_MasterList.hpp>
16 #include <MueLu_MLParameterListInterpreter.hpp>
17 #include <MueLu_ParameterListInterpreter.hpp>
18 #include <MueLu_Utilities.hpp>
19 #include <MueLu_HierarchyUtils.hpp>
20 
23 #if defined(HAVE_MUELU_EPETRA)
24 namespace MueLu {
25 
35  // FIXME: why is it non-const
36  Teuchos::ParameterList& paramListIn)
37  {
38  using SC = double;
39  using LO = int;
40  using GO = int;
41  using NO = Xpetra::EpetraNode;
42 
44 
45  using MultiVector = Xpetra::MultiVector<SC, LO, GO, NO>;
46  using Matrix = Xpetra::Matrix<SC, LO, GO, NO>;
49 
50  Teuchos::ParameterList& userList = paramListIn.sublist("user data");
51  if (userList.isParameter("Coordinates")) {
53  try {
54  coordinates = EpetraMultiVector_To_XpetraMultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType,LO,GO,NO>(userList.get<RCP<Epetra_MultiVector> >("Coordinates"));
56  coordinates = userList.get<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType, LO, GO, NO> > >("Coordinates");
57  }
58  if(Teuchos::nonnull(coordinates)){
59  userList.set<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType,LO,GO,NO> > >("Coordinates", coordinates);
60  }
61  }
62  if (userList.isParameter("Nullspace")) {
64  try {
65  nullspace = EpetraMultiVector_To_XpetraMultiVector<SC,LO,GO,NO>(userList.get<RCP<Epetra_MultiVector> >("Nullspace"));
67  nullspace = userList.get<RCP<Xpetra::MultiVector<SC, LO, GO, NO> > >("Nullspace");
68  }
69  if(Teuchos::nonnull(nullspace)){
70  userList.set<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType,LO,GO,NO> > >("Nullspace", nullspace);
71  }
72  }
73 
74  RCP<Matrix> A = EpetraCrs_To_XpetraMatrix<SC, LO, GO, NO>(inA);
75  RCP<Hierarchy> H = MueLu::CreateXpetraPreconditioner<SC,LO,GO,NO>(A, paramListIn);
76  return rcp(new EpetraOperator(H));
77  }
78 
88  const std::string& xmlFileName)
89  {
90  Teuchos::ParameterList paramList;
91  Teuchos::updateParametersFromXmlFileAndBroadcast(xmlFileName, Teuchos::Ptr<Teuchos::ParameterList>(&paramList), *Xpetra::toXpetra(A->Comm()));
92 
93  return CreateEpetraPreconditioner(A, paramList);
94  }
95 
104  {
105  Teuchos::ParameterList paramList;
106  return CreateEpetraPreconditioner(A, paramList);
107  }
108 
109  void ReuseEpetraPreconditioner(const Teuchos::RCP<Epetra_CrsMatrix>& inA, MueLu::EpetraOperator& Op) {
110  using SC = double;
111  using LO = int;
112  using GO = int;
113  using NO = Xpetra::EpetraNode;
114 
116 
117  using Matrix = Xpetra::Matrix<SC, LO, GO, NO>;
119 
120  RCP<Hierarchy> H = Op.GetHierarchy();
121  RCP<Matrix> A = EpetraCrs_To_XpetraMatrix<SC,LO,GO,NO>(inA);
122 
123  MueLu::ReuseXpetraPreconditioner<SC,LO,GO,NO>(A, H);
124  }
125 
126 #ifdef HAVE_MUELU_DEPRECATED_CODE
127 
137  MUELU_DEPRECATED
140  // FIXME: why is it non-const
141  Teuchos::ParameterList& paramListIn,
142  const Teuchos::RCP<Epetra_MultiVector>& inCoords,
143  const Teuchos::RCP<Epetra_MultiVector>& inNullspace)
144  {
145  using SC = double;
146  using LO = int;
147  using GO = int;
148  using NO = Xpetra::EpetraNode;
149 
151 
152  using MultiVector = Xpetra::MultiVector<SC, LO, GO, NO>;
153  using Matrix = Xpetra::Matrix<SC, LO, GO, NO>;
154  using Hierarchy = Hierarchy<SC,LO,GO,NO>;
155  using HierarchyManager = HierarchyManager<SC,LO,GO,NO>;
156 
157  RCP<Matrix> A = EpetraCrs_To_XpetraMatrix<SC, LO, GO, NO>(inA);
158 
159  Teuchos::ParameterList& userParamList = paramListIn.sublist("user data");
160  RCP<MultiVector> coordinates = Teuchos::null;
161  if (Teuchos::nonnull(inCoords)) {
162  coordinates = EpetraMultiVector_To_XpetraMultiVector<SC,LO,GO,NO>(inCoords);
163  }
164  if (Teuchos::nonnull(coordinates)) {
165  userParamList.set<RCP<MultiVector> >("Coordinates", coordinates);
166  }
167  RCP<MultiVector> nullspace = Teuchos::null;
168  if (Teuchos::nonnull(inNullspace)) {
169  nullspace = EpetraMultiVector_To_XpetraMultiVector<SC, LO, GO, NO>(inNullspace);
170  }
171  if (Teuchos::nonnull(nullspace)) {
172  userParamList.set<RCP<MultiVector> >("Nullspace", nullspace);
173  }
174 
175  RCP<Hierarchy> H = MueLu::CreateXpetraPreconditioner<SC,LO,GO,NO>(A, paramListIn);
176  return rcp(new EpetraOperator(H));
177  }
178 
187  MUELU_DEPRECATED
190  // FIXME: why is it non-const
191  Teuchos::ParameterList& paramListIn,
192  const Teuchos::RCP<Epetra_MultiVector>& inCoords)
193  {
194  using SC = double;
195  using LO = int;
196  using GO = int;
197  using NO = Xpetra::EpetraNode;
198 
200 
201  using MultiVector = Xpetra::MultiVector<SC, LO, GO, NO>;
202  using Matrix = Xpetra::Matrix<SC, LO, GO, NO>;
203  using Hierarchy = Hierarchy<SC,LO,GO,NO>;
204  using HierarchyManager = HierarchyManager<SC,LO,GO,NO>;
205 
206  RCP<Matrix> A = EpetraCrs_To_XpetraMatrix<SC, LO, GO, NO>(inA);
207 
208  Teuchos::ParameterList& userParamList = paramListIn.sublist("user data");
209  RCP<MultiVector> coordinates = Teuchos::null;
210  if (Teuchos::nonnull(inCoords)) {
211  coordinates = EpetraMultiVector_To_XpetraMultiVector<SC,LO,GO,NO>(inCoords);
212  }
213  if (Teuchos::nonnull(coordinates)) {
214  userParamList.set<RCP<MultiVector> >("Coordinates", coordinates);
215  }
216 
217  RCP<Hierarchy> H = MueLu::CreateXpetraPreconditioner<SC,LO,GO,NO>(A, paramListIn);
218  return rcp(new EpetraOperator(H));
219  }
220 
229  MUELU_DEPRECATED
232  const Teuchos::RCP<Epetra_MultiVector>& inCoords,
233  const Teuchos::RCP<Epetra_MultiVector>& inNullspace) {
234  using SC = double;
235  using LO = int;
236  using GO = int;
237  using NO = Xpetra::EpetraNode;
238 
239  using MultiVector = Xpetra::MultiVector<SC, LO, GO, NO>;
240 
241  Teuchos::ParameterList paramList;
242  Teuchos::ParameterList& userParamList = paramList.sublist("user data");
243 
244  RCP<MultiVector> coordinates = Teuchos::null;
245  if (Teuchos::nonnull(inCoords)) {
246  coordinates = EpetraMultiVector_To_XpetraMultiVector<SC,LO,GO,NO>(inCoords);
247  }
248  if (Teuchos::nonnull(coordinates)) {
249  userParamList.set<RCP<MultiVector> >("Coordinates", coordinates);
250  }
251 
252  RCP<MultiVector> nullspace = Teuchos::null;
253  if (Teuchos::nonnull(inNullspace)) {
254  nullspace = EpetraMultiVector_To_XpetraMultiVector<SC,LO,GO,NO>(inNullspace);
255  }
256  if (Teuchos::nonnull(nullspace)) {
257  userParamList.set<const Teuchos::RCP<MultiVector> >("Nullspace", nullspace);
258  }
259 
260  return CreateEpetraPreconditioner(inA, paramList);
261  }
262 
271  MUELU_DEPRECATED
274  const Teuchos::RCP<Epetra_MultiVector>& inCoords) {
275  using SC = double;
276  using LO = int;
277  using GO = int;
278  using NO = Xpetra::EpetraNode;
279 
280  using MultiVector = Xpetra::MultiVector<SC, LO, GO, NO>;
281 
282  Teuchos::ParameterList paramList;
283  Teuchos::ParameterList& userParamList = paramList.sublist("user data");
284 
285  RCP<MultiVector> coordinates = Teuchos::null;
286  if (Teuchos::nonnull(inCoords)) {
287  coordinates = EpetraMultiVector_To_XpetraMultiVector<SC,LO,GO,NO>(inCoords);
288  }
289  if (Teuchos::nonnull(coordinates)) {
290  userParamList.set<RCP<MultiVector> >("Coordinates", coordinates);
291  }
292 
293  return CreateEpetraPreconditioner(inA, paramList);
294  }
295 
305  MUELU_DEPRECATED
308  const std::string& xmlFileName,
309  const Teuchos::RCP<Epetra_MultiVector>& inCoords,
310  const Teuchos::RCP<Epetra_MultiVector>& inNullspace)
311  {
312  using SC = double;
313  using LO = int;
314  using GO = int;
315  using NO = Xpetra::EpetraNode;
316 
317  using MultiVector = Xpetra::MultiVector<SC, LO, GO, NO>;
318 
319  Teuchos::ParameterList paramList;
320  Teuchos::updateParametersFromXmlFileAndBroadcast(xmlFileName, Teuchos::Ptr<Teuchos::ParameterList>(&paramList), *Xpetra::toXpetra(A->Comm()));
321  Teuchos::ParameterList& userParamList = paramList.sublist("user data");
322 
323  RCP<MultiVector> coordinates = Teuchos::null;
324  if (inCoords != Teuchos::null) {
325  coordinates = EpetraMultiVector_To_XpetraMultiVector<SC,LO,GO,NO>(inCoords);
326  }
327  if (Teuchos::nonnull(coordinates)) {
328  userParamList.set<RCP<MultiVector> >("Coordinates", coordinates);
329  }
330 
331  RCP<MultiVector> nullspace = Teuchos::null;
332  if (inCoords != Teuchos::null) {
333  nullspace = EpetraMultiVector_To_XpetraMultiVector<SC,LO,GO,NO>(inNullspace);
334  }
335  if (Teuchos::nonnull(nullspace)) {
336  userParamList.set<const Teuchos::RCP<MultiVector> >("Nullspace", nullspace);
337  }
338 
339  return CreateEpetraPreconditioner(A, paramList);
340  }
341 
350  MUELU_DEPRECATED
353  const std::string& xmlFileName,
354  const Teuchos::RCP<Epetra_MultiVector>& inCoords)
355  {
356  using SC = double;
357  using LO = int;
358  using GO = int;
359  using NO = Xpetra::EpetraNode;
360 
361  using MultiVector = Xpetra::MultiVector<SC, LO, GO, NO>;
362 
363  Teuchos::ParameterList paramList;
364  Teuchos::updateParametersFromXmlFileAndBroadcast(xmlFileName, Teuchos::Ptr<Teuchos::ParameterList>(&paramList), *Xpetra::toXpetra(A->Comm()));
365  Teuchos::ParameterList& userParamList = paramList.sublist("user data");
366 
367  RCP<MultiVector> coordinates = Teuchos::null;
368  if (inCoords != Teuchos::null) {
369  coordinates = EpetraMultiVector_To_XpetraMultiVector<SC,LO,GO,NO>(inCoords);
370  }
371  if (Teuchos::nonnull(coordinates)) {
372  userParamList.set<RCP<MultiVector> >("Coordinates", coordinates);
373  }
374 
375  return CreateEpetraPreconditioner(A, paramList);
376  }
377 
378 #endif // HAVE_MUELU_DEPRECATED_CODE
379 
380 } //namespace
381 #endif // HAVE_MUELU_SERIAL and HAVE_MUELU_EPETRA
382 
383 #endif //ifndef MUELU_CREATE_EPETRA_PRECONDITIONER_CPP
Various adapters that will create a MueLu preconditioner that is an Xpetra::Matrix.
void ReuseEpetraPreconditioner(const Teuchos::RCP< Epetra_CrsMatrix > &inA, MueLu::EpetraOperator &Op)
GlobalOrdinal GO
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
bool nonnull(const std::shared_ptr< T > &p)
LocalOrdinal LO
Kokkos::Compat::KokkosSerialWrapperNode EpetraNode
EpetraOperatorT< int > EpetraOperator
bool isParameter(const std::string &name) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< MueLu::EpetraOperator > CreateEpetraPreconditioner(const Teuchos::RCP< Epetra_CrsMatrix > &inA, Teuchos::ParameterList &paramListIn)
Helper function to create a MueLu preconditioner that can be used by Epetra.Given a EpetraCrs_Matrix...
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
Scalar SC
Node NO
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
const Epetra_Comm & Comm() const
Provides methods to build a multigrid hierarchy and apply multigrid cycles.