MueLu Version of the Day
Loading...
Searching...
No Matches
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
35namespace 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//
42template <class Scalar = DefaultScalar,
45 class Node = DefaultNode>
46class HierarchyManager : public HierarchyFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
47#undef MUELU_HIERARCHYMANAGER_SHORT
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 void SetNumDesiredLevel(int numDesiredLevel) { numDesiredLevel_ = numDesiredLevel; }
81
84
86
87 typedef std::map<std::string, RCP<const FactoryBase>> FactoryMap;
88
89 protected: // TODO: access function
91 virtual void SetupOperator(Operator& /* Op */) const {}
92
94 // TODO: merge with SetupMatrix ?
95 virtual void SetupExtra(Hierarchy& /* H */) const {}
96
97 // TODO this was private
98 // Used in SetupHierarchy() to access levelManagers_
99 // Inputs i=-1 and i=size() are allowed to simplify calls to hierarchy->Setup()
100 Teuchos::RCP<FactoryManagerBase> LvlMngr(int levelID, int lastLevelID) const;
101
104
105 mutable int numDesiredLevel_;
106 Xpetra::global_size_t maxCoarseSize_;
108
113
121
123
126
128 // Items here get handled manually
129 Teuchos::Array<int> nullspaceToPrint_;
130 Teuchos::Array<int> coordinatesToPrint_;
131 Teuchos::Array<int> materialToPrint_;
132 Teuchos::Array<int> aggregatesToPrint_;
133 Teuchos::Array<int> elementToNodeMapsToPrint_;
134
135 // Data we'll need to keep, either to dump to disk or to use post-setup
136 Teuchos::Array<std::string> dataToKeep_;
137
138 // Matrices we'll need to print
139 std::map<std::string, Teuchos::Array<int>> matricesToPrint_;
140
141 Teuchos::RCP<Teuchos::ParameterList> matvecParams_;
142
143 std::map<int, std::vector<keep_pair>> keep_;
145
146 private:
147 // Set the keep flags for Export Data
148 void ExportDataSetKeepFlags(Hierarchy& H, const Teuchos::Array<int>& data, const std::string& name) const;
149
150 void ExportDataSetKeepFlagsNextLevel(Hierarchy& H, const Teuchos::Array<int>& data, const std::string& name) const;
151
152 // Set the keep flags for Export Data
153 void ExportDataSetKeepFlagsAll(Hierarchy& H, const std::string& name) const;
154
155 template <class T>
156 void WriteData(Hierarchy& H, const Teuchos::Array<int>& data, const std::string& name) const;
157
158 void WriteDataAggregates(Hierarchy& H, const Teuchos::Array<int>& data, const std::string& name) const;
159
160 template <class T>
161 void WriteDataFC(Hierarchy& H, const Teuchos::Array<int>& data, const std::string& name, const std::string& ofname) const;
162
163 // For dumping an IntrepidPCoarsening element-to-node map to disk
164 template <class T>
165 void WriteFieldContainer(const std::string& fileName, T& fcont, const Map& colMap) const;
166
167 // Levels
168 Array<RCP<FactoryManagerBase>> levelManagers_; // one FactoryManager per level (the last levelManager is used for all the remaining levels)
169
170}; // class HierarchyManager
171
172} // namespace MueLu
173
174#define MUELU_HIERARCHYMANAGER_SHORT
175#endif // MUELU_HIERARCHYMANAGER_HPP
176
177// TODO: split into _decl/_def
178// TODO: default value for first param (FactoryManager()) should not be duplicated (code maintainability)
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
MueLu::DefaultNode Node
void WriteFieldContainer(const std::string &fileName, T &fcont, const Map &colMap) const
Teuchos::RCP< Teuchos::ParameterList > matvecParams_
void ExportDataSetKeepFlagsNextLevel(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
Array< RCP< FactoryManagerBase > > levelManagers_
Teuchos::Array< int > elementToNodeMapsToPrint_
virtual void SetupExtra(Hierarchy &) const
Setup extra data.
Teuchos::Array< int > nullspaceToPrint_
Lists of entities to be exported (or saved)
int GetNumDesiredLevel()
Get the number of desired levels.
std::map< std::string, RCP< const FactoryBase > > FactoryMap
void ExportDataSetKeepFlags(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
std::map< int, std::vector< keep_pair > > keep_
void WriteDataFC(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name, const std::string &ofname) const
void WriteData(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
std::map< std::string, Teuchos::Array< int > > matricesToPrint_
bool suppressNullspaceDimensionCheck_
Flag to indicate whether the check of the nullspace dimension is suppressed.
virtual void SetupOperator(Operator &) const
Setup Matrix object.
RCP< FactoryManagerBase > GetFactoryManager(int levelID) const
std::pair< std::string, const FactoryBase * > keep_pair
void WriteDataAggregates(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
int graphOutputLevel_
-2 = no output, -1 = all levels
void AddFactoryManager(int startLevel, int numDesiredLevel, RCP< FactoryManagerBase > manager)
void SetNumDesiredLevel(int numDesiredLevel)
Set the number of desired levels.
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
virtual RCP< Hierarchy > CreateHierarchy() const
Create an empty Hierarchy object.
void ExportDataSetKeepFlagsAll(Hierarchy &H, const std::string &name) const
Teuchos::Array< std::string > dataToKeep_
virtual ~HierarchyManager()=default
Destructor.
Teuchos::RCP< FactoryManagerBase > LvlMngr(int levelID, int lastLevelID) const
size_t getNumFactoryManagers() const
returns number of factory managers stored in levelManagers_ vector.
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
Namespace for MueLu classes and methods.
Tpetra::KokkosClassic::DefaultNode::DefaultNodeType DefaultNode
Tpetra::Details::DefaultTypes::scalar_type DefaultScalar