MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_HierarchyManager_decl.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_HIERARCHYMANAGER_DECL_HPP
11 #define MUELU_HIERARCHYMANAGER_DECL_HPP
12 
13 #include <string>
14 #include <map>
15 
16 #include <Teuchos_Array.hpp>
17 
18 #include <Xpetra_Operator.hpp>
19 #include <Xpetra_IO.hpp>
20 
21 #include "MueLu_ConfigDefs.hpp"
22 
23 #include "MueLu_Exceptions.hpp"
24 #include "MueLu_Aggregates.hpp"
25 #include "MueLu_Hierarchy.hpp"
27 #include "MueLu_Level.hpp"
28 #include "MueLu_MasterList.hpp"
29 #include "MueLu_PerfUtils.hpp"
30 
31 #ifdef HAVE_MUELU_INTREPID2
32 #include "Kokkos_DynRankView.hpp"
33 #endif
34 
35 namespace MueLu {
36 
37 // This class stores the configuration of a Hierarchy.
38 // The class also provides an algorithm to build a Hierarchy from the configuration.
39 //
40 // See also: FactoryManager
41 //
42 template <class Scalar = DefaultScalar,
45  class Node = DefaultNode>
46 class HierarchyManager : public HierarchyFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
47 #undef MUELU_HIERARCHYMANAGER_SHORT
48 #include "MueLu_UseShortNames.hpp"
49  typedef std::pair<std::string, const FactoryBase*> keep_pair;
50 
51  public:
53  HierarchyManager(int numDesiredLevel = MasterList::getDefault<int>("max levels"));
54 
56  virtual ~HierarchyManager() = default;
57 
59  void AddFactoryManager(int startLevel, int numDesiredLevel, RCP<FactoryManagerBase> manager);
60 
62  RCP<FactoryManagerBase> GetFactoryManager(int levelID) const;
63 
65  size_t getNumFactoryManagers() const;
66 
68  void CheckConfig();
69 
71 
72  virtual RCP<Hierarchy> CreateHierarchy() const;
73 
74  virtual RCP<Hierarchy> CreateHierarchy(const std::string& label) const;
75 
77  virtual void SetupHierarchy(Hierarchy& H) const;
78 
80 
81  typedef std::map<std::string, RCP<const FactoryBase>> FactoryMap;
82 
83  protected: // TODO: access function
85  virtual void SetupOperator(Operator& /* Op */) const {}
86 
88  // TODO: merge with SetupMatrix ?
89  virtual void SetupExtra(Hierarchy& /* H */) const {}
90 
91  // TODO this was private
92  // Used in SetupHierarchy() to access levelManagers_
93  // Inputs i=-1 and i=size() are allowed to simplify calls to hierarchy->Setup()
94  Teuchos::RCP<FactoryManagerBase> LvlMngr(int levelID, int lastLevelID) const;
95 
98 
99  mutable int numDesiredLevel_;
102 
103  bool doPRrebalance_;
105  bool implicitTranspose_;
107 
115 
117 
119  int graphOutputLevel_;
120 
122  // Items here get handled manually
127 
128  // Data we'll need to save, not necessarily print
130 
131  // Matrices we'll need to print
132  std::map<std::string, Teuchos::Array<int>> matricesToPrint_;
133 
135 
136  std::map<int, std::vector<keep_pair>> keep_;
138 
139  private:
140  // Set the keep flags for Export Data
141  void ExportDataSetKeepFlags(Hierarchy& H, const Teuchos::Array<int>& data, const std::string& name) const;
142 
143  void ExportDataSetKeepFlagsNextLevel(Hierarchy& H, const Teuchos::Array<int>& data, const std::string& name) const;
144 
145  // Set the keep flags for Export Data
146  void ExportDataSetKeepFlagsAll(Hierarchy& H, const std::string& name) const;
147 
148  template <class T>
149  void WriteData(Hierarchy& H, const Teuchos::Array<int>& data, const std::string& name) const;
150 
151  void WriteDataAggregates(Hierarchy& H, const Teuchos::Array<int>& data, const std::string& name) const;
152 
153  template <class T>
154  void WriteDataFC(Hierarchy& H, const Teuchos::Array<int>& data, const std::string& name, const std::string& ofname) const;
155 
156  // For dumping an IntrepidPCoarsening element-to-node map to disk
157  template <class T>
158  void WriteFieldContainer(const std::string& fileName, T& fcont, const Map& colMap) const;
159 
160  // Levels
161  Array<RCP<FactoryManagerBase>> levelManagers_; // one FactoryManager per level (the last levelManager is used for all the remaining levels)
162 
163 }; // class HierarchyManager
164 
165 } // namespace MueLu
166 
167 #define MUELU_HIERARCHYMANAGER_SHORT
168 #endif // MUELU_HIERARCHYMANAGER_HPP
169 
170 // TODO: split into _decl/_def
171 // TODO: default value for first param (FactoryManager()) should not be duplicated (code maintainability)
virtual void SetupExtra(Hierarchy &) const
Setup extra data.
virtual ~HierarchyManager()=default
Destructor.
MueLu::DefaultLocalOrdinal LocalOrdinal
Tpetra::KokkosClassic::DefaultNode::DefaultNodeType DefaultNode
void WriteDataAggregates(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
void ExportDataSetKeepFlags(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
RCP< FactoryManagerBase > GetFactoryManager(int levelID) const
Teuchos::Array< std::string > dataToSave_
void AddFactoryManager(int startLevel, int numDesiredLevel, RCP< FactoryManagerBase > manager)
Teuchos::Array< int > elementToNodeMapsToPrint_
Teuchos::RCP< FactoryManagerBase > LvlMngr(int levelID, int lastLevelID) const
std::map< std::string, RCP< const FactoryBase > > FactoryMap
MueLu::DefaultNode Node
Teuchos::Array< int > coordinatesToPrint_
virtual RCP< Hierarchy > CreateHierarchy() const
Create an empty Hierarchy object.
Teuchos::Array< int > nullspaceToPrint_
Lists of entities to be exported (or saved)
void WriteData(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
size_t getNumFactoryManagers() const
returns number of factory managers stored in levelManagers_ vector.
MueLu::DefaultScalar Scalar
Tpetra::Details::DefaultTypes::scalar_type DefaultScalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Teuchos::Array< int > aggregatesToPrint_
bool suppressNullspaceDimensionCheck_
Flag to indicate whether the check of the nullspace dimension is suppressed.
void ExportDataSetKeepFlagsAll(Hierarchy &H, const std::string &name) const
int graphOutputLevel_
-2 = no output, -1 = all levels
size_t global_size_t
std::map< std::string, Teuchos::Array< int > > matricesToPrint_
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
virtual void SetupOperator(Operator &) const
Setup Matrix object.
HierarchyManager(int numDesiredLevel=MasterList::getDefault< int >("max levels"))
Constructor.
std::pair< std::string, const FactoryBase * > keep_pair
void WriteDataFC(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name, const std::string &ofname) const
Xpetra::global_size_t maxCoarseSize_
void WriteFieldContainer(const std::string &fileName, T &fcont, const Map &colMap) const
Teuchos::RCP< Teuchos::ParameterList > matvecParams_
std::map< int, std::vector< keep_pair > > keep_
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
Array< RCP< FactoryManagerBase > > levelManagers_
void ExportDataSetKeepFlagsNextLevel(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const