Debian Codegraph @

packages/muelu/research/max/XpetraSplitting/Xpetra_RegionHandler_decl.hpp

raw
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 * Xpetra_RegionHandler_decl.hpp
12 *
13 * Created on: August 17, 2017
14 * Author: Massimiliano Lupo Pasini ([email protected])
15 */
16 #ifndef XPETRA_REGIONHANDLER_DECL_HPP
17 #define XPETRA_REGIONHANDLER_DECL_HPP
18
19 #include "Xpetra_Map.hpp"
20 #include <string>
21 #include <fstream>
22 #include <vector>
23
24 namespace Xpetra {
25
26 template <class GlobalOrdinal>
27 bool compareRegions(const std::tuple<GlobalOrdinal, GlobalOrdinal> &, const std::tuple<GlobalOrdinal, GlobalOrdinal> &);
28
29 template <class GlobalOrdinal>
30 bool compareNodes(const std::tuple<GlobalOrdinal, GlobalOrdinal> &, const std::tuple<GlobalOrdinal, GlobalOrdinal> &);
31
32 // Definition of the predicate for the node_ structure.
33 // Given a tuple made of node index and a specific region it belongs to,
34 // this predicate returns true if the node belongs to the region specified in input to the predicate.
35 template <class GlobalOrdinal>
36 class checkerNode {
37 public:
38 // Constructor
39 checkerNode(GlobalOrdinal region_index) { region_index_ = region_index; };
40
41 // Unary Operator
42 bool operator()(const std::tuple<GlobalOrdinal, GlobalOrdinal> &node) { return (std::get<1>(node) == region_index_); }
43
44 private:
45 GlobalOrdinal region_index_;
46 };
47
48 // Definition of the predicate for the nodesToRegion_ sitructure
49 // Given a tuple made of node index and a vector with labels of regions it belongs to,
50 // this predicate returns true if the node coincides with the node specified in input to the predicate.
51 template <class GlobalOrdinal>
52 class checkerNodesToRegion {
53 public:
54 // Constructor
55 checkerNodesToRegion(GlobalOrdinal node_index) { node_index_ = node_index; };
56
57 // Unary Operator
58 bool operator()(const std::tuple<GlobalOrdinal, Array<GlobalOrdinal> > &node) { return (std::get<0>(node) == node_index_); }
59
60 private:
61 GlobalOrdinal node_index_;
62 };
63
64 // This is an auxiliary class to store row maps for the composite matrix, region matrices and
65 // a regionToAll map to link region node indices with the composite ones
66 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
67 class Splitting_MapsInfo {
68 public:
69 Array<Array<std::tuple<GlobalOrdinal, GlobalOrdinal> > > regionToAll_; // used as a map for a RegionToAll node index
70 Array<GlobalOrdinal> composite_map_; // used as RowMap for composite matrices
71 Array<Array<GlobalOrdinal> > region_maps_; // used as RowMap for region matrices
72 };
73
74 // This is the actual class that defines the regionHandler
75 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
76 class RegionHandler {
77 public:
78 //! @name Constructor/Destructor Methods
79 //@{
80
81 //! Constructor specifying the file name containing region information.
82 RegionHandler(const std::string &, RCP<const Teuchos::Comm<int> >);
83
84 //}
85 //! @Interface methods
86 //@{
87 GlobalOrdinal GetNumGlobalElements() const { return num_total_nodes_; };
88 GlobalOrdinal GetNumTotalRegions() const { return num_total_regions_; };
89 GlobalOrdinal GetNumRegionNodes(GlobalOrdinal region_idx) const { return num_region_nodes_[region_idx]; };
90 Array<GlobalOrdinal> GetGlobalRowMap() const { return maps_.composite_map_; };
91 Array<GlobalOrdinal> GetRegionRowMap(GlobalOrdinal region_index) const;
92 Array<Array<GlobalOrdinal> > GetRegionRowMaps() const { return maps_.region_maps_; };
93 Array<Array<std::tuple<GlobalOrdinal, GlobalOrdinal> > > GetRegionToAll() const; // used as a map for a RegionToAll node index
94 Array<std::tuple<GlobalOrdinal, GlobalOrdinal> > GetRegionToAll(GlobalOrdinal) const; // used as a map for a RegionToAll node index
95 Array<std::tuple<int, Array<GlobalOrdinal> > > GetInterfaceNodes() const { return interfaceNodes_; };
96 //}
97 //! @Printout methods
98 void printView() const;
99 void printNodesToRegion() const;
100 void printInactive() const;
101 //}
102
103 private:
104 //! @Private variables
105 //@{
106
107 RCP<const Teuchos::Comm<int> > comm_;
108 bool nodes_sorted_by_regions_ = false;
109
110 // Global information
111 GlobalOrdinal num_total_nodes_ = 0;
112 GlobalOrdinal num_total_regions_ = 0;
113 Array<std::tuple<GlobalOrdinal, GlobalOrdinal> > nodes_; // basic structure that imports the information from the input file
114
115 // the following two Array are used to handle the situation where either the number of processes exceeds the number of regions or viceversa
116 Array<GlobalOrdinal> regions_per_proc_; // if num_proc > num_regions, then it says how many regions are owned by a single process, empty otherwise
117 Array<std::tuple<int, Array<GlobalOrdinal> > > procs_per_region_; // lists of processes instantiated for each region
118
119 Array<std::tuple<int, Array<GlobalOrdinal> > > nodesToRegion_; // for each node it lists the regions it belongs to
120 Array<std::tuple<int, Array<GlobalOrdinal> > > interfaceNodes_; // for each node on the interface it lists the regions it belongs to
121 // vector which contains the number of region nodes for each domain region
122 Array<GlobalOrdinal> num_region_nodes_;
123
124 // Maps used for composite and region operators
125 Splitting_MapsInfo<Scalar, LocalOrdinal, GlobalOrdinal, Node> maps_;
126 //@}
127
128 //! @Private Methods
129 //@{
130 void ReadFileInfo(const std::string &);
131 void ComputeProcRegions();
132 void NodesToRegion();
133 void CreateRowMaps();
134 //@}
135
136 }; // class RegionHandler
137
138 // This compare class is used to run the sorting algorithm on the list of nodes with associated regions they belong to.
139 // First, nodes are sorted in ascending order for region labels. Then, the sorting shuffles the nodes in ascending node index for
140 // each given region
141 template <class GlobalOrdinal>
142 bool compareRegions(const std::tuple<GlobalOrdinal, GlobalOrdinal> &lhs, const std::tuple<GlobalOrdinal, GlobalOrdinal> &rhs) {
143 // First we prioritize the sorting according to the region label
144 // If the region is the same, then the sorting looks at the composite node index
145 if (std::get<1>(lhs) < std::get<1>(rhs))
146 return true;
147 else if (std::get<1>(lhs) == std::get<1>(rhs))
148 return std::get<0>(lhs) < std::get<0>(rhs);
149 else
150 return false;
151 }
152
153 // This compare is sed to run the sorting algorithm where the nodes are ordered in ascendin order for thei node indes, regardless of the
154 // associated region index
155 template <class GlobalOrdinal>
156 bool compareNodes(const std::tuple<GlobalOrdinal, GlobalOrdinal> &lhs, const std::tuple<GlobalOrdinal, GlobalOrdinal> &rhs) {
157 return std::get<0>(lhs) < std::get<0>(rhs);
158 }
159
160 } // namespace Xpetra
161
162 #endif