MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_CreateEpetraPreconditioner.cpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// MueLu: A package for multigrid based preconditioning
4//
5// Copyright 2012 NTESS and the MueLu contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef MUELU_CREATE_EPETRA_PRECONDITIONER_CPP
11#define MUELU_CREATE_EPETRA_PRECONDITIONER_CPP
12
13#include <Teuchos_XMLParameterListHelpers.hpp>
14#include <Xpetra_CrsMatrix.hpp>
15#include <Xpetra_MultiVector.hpp>
16#include <Xpetra_MultiVectorFactory.hpp>
17
18#include <MueLu.hpp>
19
21#include <MueLu_Exceptions.hpp>
22#include <MueLu_Hierarchy.hpp>
24#include <MueLu_MasterList.hpp>
25#include <MueLu_ParameterListInterpreter.hpp>
26#include <MueLu_Utilities.hpp>
27#include <MueLu_HierarchyUtils.hpp>
28
31#if defined(HAVE_MUELU_EPETRA)
32namespace MueLu {
33
41Teuchos::RCP<MueLu::EpetraOperator>
42CreateEpetraPreconditioner(const Teuchos::RCP<Epetra_CrsMatrix>& inA,
43 // FIXME: why is it non-const
44 Teuchos::ParameterList& paramListIn) {
45 using SC = double;
46 using LO = int;
47 using GO = int;
48 using NO = Xpetra::EpetraNode;
49
50 using Teuchos::ParameterList;
51
52 using MultiVector = Xpetra::MultiVector<SC, LO, GO, NO>;
53 using Matrix = Xpetra::Matrix<SC, LO, GO, NO>;
56
57 Teuchos::ParameterList& userList = paramListIn.sublist("user data");
58 if (userList.isParameter("Coordinates")) {
59 RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType, LO, GO, NO> > coordinates = Teuchos::null;
60 try {
61 coordinates = EpetraMultiVector_To_XpetraMultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType, LO, GO, NO>(userList.get<RCP<Epetra_MultiVector> >("Coordinates"));
62 } catch (Teuchos::Exceptions::InvalidParameterType&) {
63 coordinates = userList.get<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType, LO, GO, NO> > >("Coordinates");
64 }
65 if (Teuchos::nonnull(coordinates)) {
66 userList.set<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType, LO, GO, NO> > >("Coordinates", coordinates);
67 }
68 }
69 if (userList.isParameter("Nullspace")) {
70 RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType, LO, GO, NO> > nullspace = Teuchos::null;
71 try {
72 nullspace = EpetraMultiVector_To_XpetraMultiVector<SC, LO, GO, NO>(userList.get<RCP<Epetra_MultiVector> >("Nullspace"));
73 } catch (Teuchos::Exceptions::InvalidParameterType&) {
74 nullspace = userList.get<RCP<Xpetra::MultiVector<SC, LO, GO, NO> > >("Nullspace");
75 }
76 if (Teuchos::nonnull(nullspace)) {
77 userList.set<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType, LO, GO, NO> > >("Nullspace", nullspace);
78 }
79 }
80
81 RCP<Matrix> A = EpetraCrs_To_XpetraMatrix<SC, LO, GO, NO>(inA);
82 RCP<Hierarchy> H = MueLu::CreateXpetraPreconditioner<SC, LO, GO, NO>(A, paramListIn);
83 return rcp(new EpetraOperator(H));
84}
85
93Teuchos::RCP<MueLu::EpetraOperator>
94CreateEpetraPreconditioner(const Teuchos::RCP<Epetra_CrsMatrix>& A,
95 const std::string& xmlFileName) {
96 Teuchos::ParameterList paramList;
97 Teuchos::updateParametersFromXmlFileAndBroadcast(xmlFileName, Teuchos::Ptr<Teuchos::ParameterList>(&paramList), *Xpetra::toXpetra(A->Comm()));
98
99 return CreateEpetraPreconditioner(A, paramList);
100}
101
108Teuchos::RCP<MueLu::EpetraOperator>
109CreateEpetraPreconditioner(const Teuchos::RCP<Epetra_CrsMatrix>& A) {
110 Teuchos::ParameterList paramList;
111 return CreateEpetraPreconditioner(A, paramList);
112}
113
114void ReuseEpetraPreconditioner(const Teuchos::RCP<Epetra_CrsMatrix>& inA, MueLu::EpetraOperator& Op) {
115 using SC = double;
116 using LO = int;
117 using GO = int;
118 using NO = Xpetra::EpetraNode;
119
120 using Teuchos::ParameterList;
121
122 using Matrix = Xpetra::Matrix<SC, LO, GO, NO>;
124
125 RCP<Hierarchy> H = Op.GetHierarchy();
126 RCP<Matrix> A = EpetraCrs_To_XpetraMatrix<SC, LO, GO, NO>(inA);
127
128 MueLu::ReuseXpetraPreconditioner<SC, LO, GO, NO>(A, H);
129}
130
131} // namespace MueLu
132#endif // HAVE_MUELU_SERIAL and HAVE_MUELU_EPETRA
133
134#endif // ifndef MUELU_CREATE_EPETRA_PRECONDITIONER_CPP
Various adapters that will create a MueLu preconditioner that is an Xpetra::Matrix.
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
Namespace for MueLu classes and methods.
void ReuseEpetraPreconditioner(const Teuchos::RCP< Epetra_CrsMatrix > &inA, MueLu::EpetraOperator &Op)
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,...