MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_MatrixTransferFactory_def.hpp
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_MATRIXTRANSFER_FACTORY_DEF_HPP
11#define MUELU_MATRIXTRANSFER_FACTORY_DEF_HPP
12
14
15#include <Xpetra_Matrix.hpp>
16
17#include "MueLu_MasterList.hpp"
18#include "MueLu_Level.hpp"
19#include "MueLu_Monitor.hpp"
20
21namespace MueLu {
22
23template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
25 RCP<ParameterList> validParamList = rcp(new ParameterList());
26#define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
27 SET_VALID_ENTRY("transpose: use implicit");
28 SET_VALID_ENTRY("rap: triple product");
29 SET_VALID_ENTRY("rap: fix zero diagonals");
30 SET_VALID_ENTRY("rap: fix zero diagonals threshold");
31 SET_VALID_ENTRY("rap: fix zero diagonals replacement");
32 SET_VALID_ENTRY("rap: relative diagonal floor");
33#undef SET_VALID_ENTRY
34
35 validParamList->set<std::string>("Matrix name", "A", "Name of the matrix that will be transferred on the coarse grid (level key)");
36 validParamList->set<std::string>("Restrictor name", "R", "Name of the operator that will be used to transfer data");
37 validParamList->set<std::string>("Prolongator name", "P", "Name of the operator that will be used to transfer data");
38
39 validParamList->set<RCP<const FactoryBase>>("A", Teuchos::null, "Generating factory of the matrix A used during the prolongator smoothing process");
40 validParamList->set<RCP<const FactoryBase>>("P", Teuchos::null, "Prolongator factory");
41 validParamList->set<RCP<const FactoryBase>>("R", Teuchos::null, "Restrictor factory");
42
43 validParamList->set<bool>("CheckMainDiagonal", false, "Check main diagonal for zeros");
44 validParamList->set<bool>("RepairMainDiagonal", false, "Repair zeros on main diagonal");
45
46 // Make sure we don't recursively validate options for the matrixmatrix kernels
47 ParameterList norecurse;
48 norecurse.disableRecursiveValidation();
49 validParamList->set<ParameterList>("matrixmatrix: kernel params", norecurse, "MatrixMatrix kernel parameters");
50
51 return validParamList;
52}
53
54template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
56 const ParameterList &pL = GetParameterList();
57 std::string matrixName = pL.get<std::string>("Matrix name");
58 fineLevel.DeclareInput(matrixName, GetFactory("A").get(), this);
59
60 std::string prolongatorName = pL.get<std::string>("Prolongator name");
61 coarseLevel.DeclareInput(prolongatorName, GetFactory("P").get(), this);
62
63 if (!pL.get<bool>("transpose: use implicit")) {
64 std::string restrictorName = pL.get<std::string>("Restrictor name");
65 coarseLevel.DeclareInput(restrictorName, GetFactory("R").get(), this);
66 }
67}
68
69template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
71 FactoryMonitor m(*this, "Build", coarseLevel);
72
73 const ParameterList &pL = GetParameterList();
74 const std::string matrixName = pL.get<std::string>("Matrix name");
75 const std::string prolongatorName = pL.get<std::string>("Prolongator name");
76
77 RCP<Matrix> A;
78 RCP<Matrix> P;
79 RCP<Matrix> R;
80 RCP<Matrix> Ac;
81 A = fineLevel.Get<RCP<Matrix>>(matrixName, GetFactory("A").get());
82 P = coarseLevel.Get<RCP<Matrix>>(prolongatorName, GetFactory("P").get());
83 if (!pL.get<bool>("transpose: use implicit")) {
84 const std::string restrictorName = pL.get<std::string>("Restrictor name");
85 R = coarseLevel.Get<RCP<Matrix>>(restrictorName, GetFactory("R").get());
86 }
87 Teuchos::RCP<Teuchos::ParameterList> APparams;
88 Teuchos::RCP<Teuchos::ParameterList> RAPparams;
89 Utilities::TripleMatrixProduct(R, A, P, Ac, pL, *this, APparams, RAPparams, &coarseLevel);
90 Set<RCP<Matrix>>(coarseLevel, matrixName, Ac);
91
92} // Build
93
94} // namespace MueLu
95
96#endif
#define SET_VALID_ENTRY(name)
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
void DeclareInput(Level &finelevel, Level &coarseLevel) const
Specifies the data that this class needs, and the factories that generate that data.
static void TripleMatrixProduct(const Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &R, const Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &A, const Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &P, Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &Ac, const Teuchos::ParameterList &pL, const MueLu::BaseClass &verbObj, Teuchos::RCP< Teuchos::ParameterList > &APparams, Teuchos::RCP< Teuchos::ParameterList > &RAPparams, Level *coarseLevel=nullptr)
Namespace for MueLu classes and methods.