MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_PermutationFactory_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/*
11 * MueLu_PermutationFactory_def.hpp
12 *
13 * Created on: Nov 28, 2012
14 * Author: wiesner
15 */
16
17#ifndef MUELU_PERMUTATIONFACTORY_DEF_HPP_
18#define MUELU_PERMUTATIONFACTORY_DEF_HPP_
19
20#include <vector>
21#include <queue>
22
24
25#include <Xpetra_Map.hpp>
26#include <Xpetra_StridedMap.hpp> // for nDofsPerNode...
27#include <Xpetra_Vector.hpp>
28#include <Xpetra_VectorFactory.hpp>
29#include <Xpetra_Matrix.hpp>
30#include <Xpetra_CrsMatrixWrap.hpp>
31#include <Xpetra_Export.hpp>
32#include <Xpetra_ExportFactory.hpp>
33#include <Xpetra_Import.hpp>
34#include <Xpetra_ImportFactory.hpp>
35
36#include "MueLu_Level.hpp"
37#include "MueLu_Monitor.hpp"
38
39#include "MueLu_AlgebraicPermutationStrategy.hpp"
40#include "MueLu_LocalPermutationStrategy.hpp"
41
42#undef DEBUG_OUTPUT
43
44namespace MueLu {
45template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
47
48template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
50
51template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
53 RCP<ParameterList> validParamList = rcp(new ParameterList());
54
55 validParamList->set<RCP<const FactoryBase> >("A", Teuchos::null, "Generating factory of the matrix A to be permuted.");
56
57 validParamList->set<std::string>("PermutationRowMapName", "", "Name of input row map for which rows the permutation shall be done. (default='')");
58 validParamList->set<RCP<const FactoryBase> >("PermutationRowMapFactory", Teuchos::null, "Generating factory of the input row map for the permutation.");
59
60 validParamList->set<std::string>("PermutationStrategy", "Algebraic", "Permutation strategy (default = 'Algebraic', 'Local'");
61
62 return validParamList;
63}
64
65template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
67 Input(currentLevel, "A");
68
69 const ParameterList &pL = GetParameterList();
70 std::string mapName = pL.get<std::string>("PermutationRowMapName");
71 Teuchos::RCP<const FactoryBase> mapFactory = GetFactory("PermutationRowMapFactory");
72
73 if (mapName.length() > 0) {
74 currentLevel.DeclareInput(mapName, mapFactory.get(), this);
75 }
76}
77
78template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
80 FactoryMonitor m(*this, "Permutation Factory ", currentLevel);
81
82 Teuchos::RCP<Matrix> A = Get<Teuchos::RCP<Matrix> >(currentLevel, "A");
83
84 const ParameterList &pL = GetParameterList();
85 std::string mapName = pL.get<std::string>("PermutationRowMapName");
86 Teuchos::RCP<const FactoryBase> mapFactory = GetFactory("PermutationRowMapFactory");
87
88 Teuchos::RCP<const Map> permRowMap = Teuchos::null;
89 if (mapName.length() > 0) {
90 permRowMap = currentLevel.Get<RCP<const Map> >(mapName, mapFactory.get());
91 } else {
92 permRowMap = A->getRowMap(); // use full row map of A
93 }
94
95 std::string strStrategy = pL.get<std::string>("PermutationStrategy");
96 if (strStrategy == "Algebraic") {
97 Teuchos::RCP<AlgebraicPermutationStrategy> permStrat = Teuchos::rcp(new AlgebraicPermutationStrategy());
98 permStrat->BuildPermutation(A, permRowMap, currentLevel, this);
99 } else if (strStrategy == "Local") {
100 Teuchos::RCP<LocalPermutationStrategy> permStrat = Teuchos::rcp(new LocalPermutationStrategy());
101 permStrat->BuildPermutation(A, permRowMap, currentLevel, this);
102 } else
103 TEUCHOS_TEST_FOR_EXCEPTION(true,
104 std::logic_error,
105 "`PermutationStrategy' has incorrect value (" << strStrategy << ") in input to PermutationFactory."
106 << "Check the documentation for a list of valid choices");
107
108 GetOStream(Runtime0) << "Using " << strStrategy << " permutation strategy." << std::endl;
109}
110
111} // namespace MueLu
112
113#endif /* MUELU_PERMUTATIONFACTORY_DEF_HPP_ */
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 DeclareInput(Level &currentLevel) const
Specifies the data that this class needs, and the factories that generate that data.
void Build(Level &currentLevel) const
Build an object with this factory.
Namespace for MueLu classes and methods.
@ Runtime0
One-liner description of what is happening.