MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
44 namespace MueLu {
45 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
47 
48 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
50 
51 template <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 
65 template <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 
78 template <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") {
98  permStrat->BuildPermutation(A, permRowMap, currentLevel, this);
99  } else if (strStrategy == "Local") {
101  permStrat->BuildPermutation(A, permRowMap, currentLevel, this);
102  } else
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_ */
void BuildPermutation(const Teuchos::RCP< Matrix > &A, const Teuchos::RCP< const Map > &permRowMap, Level &currentLevel, const FactoryBase *genFactory) const
build permutation operators
void BuildPermutation(const Teuchos::RCP< Matrix > &A, const Teuchos::RCP< const Map > permRowMap, Level &currentLevel, const FactoryBase *genFactory) const
build permutation operators
T & get(const std::string &name, T def_value)
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
One-liner description of what is happening.
T * get() const
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:63
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
void Build(Level &currentLevel) const
Build an object with this factory.
void DeclareInput(Level &currentLevel) const
Specifies the data that this class needs, and the factories that generate that data.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()