Flow123d  jenkins-Flow123d-linux-release-multijob-282
local_to_global_map.hh
Go to the documentation of this file.
1 /*
2  * local_to_global_map.hh
3  *
4  * Created on: Mar 9, 2012
5  * Author: jb
6  */
7 
8 #ifndef LOCAL_TO_GLOBAL_MAP_HH_
9 #define LOCAL_TO_GLOBAL_MAP_HH_
10 
11 #include <set>
12 #include <vector>
13 
14 /// Using Boost shared pointer.
15 #include <boost/smart_ptr/shared_ptr.hpp>
16 #include <boost/smart_ptr/make_shared.hpp>
17 
18 #include "system/system.hh"
19 #include "system/global_defs.h"
20 
21 
22 class Distribution;
23 
24 /**
25  * @brief class to manage local indices on sub-domain to global indices on domain
26  *
27  * Currently (March 2012) the local to global maps are managed by individual equations (e.g. DarcyFlow has el_4_loc .. there it is complicated
28  * by different local indexing of elements, sides and edges). In fact el_4_loc etc. are new_local to old_global maps.
29  * This map is created as follows:
30  *
31  * PETSC solver:
32  * 1) create graph
33  * 2) make partitioning
34  * 2.5) create id_4_old (just used to create new_4_id, id was non continuous index not used anymore)
35  * 3) call id_maps which:
36  * 4) call ISPartitioninToNumbering : assign partitions to processors (identity, no optimization); make "distribution";
37  * make mapping (array of ints): old_local to new_global
38  * 5) from this we crate AO (application ordering from PETSc)
39  * 6) use AO to map identity array to old numbering -> creates map: new_global to old_global
40  * 7) go through new_local continuous part and map it to old_global index
41  * ---
42  * So this produce new_local to old_global mapping and only for continuous part of local indices (not for ghost indices)
43  * See that this works without any information about connectivity.
44  *
45  * METIS/BDDC solver:
46  * 1) graph, partition of elements, maps for elements (no overlap, no ghost values) using id_maps function
47  * 2) same for edges -> produce non overlapping local to global maps.
48  * 3) use std::set to collect all dofs on local elements (pass through mesh) complexity: n*log(n) n-local number of dofs
49  * 4) copy set to vector - makes local ordering arbitrary
50  *
51  * Future usage is:
52  * - in mesh to map local idx of entities to global indices
53  * - in dof handler to map local dofs idx to global
54  *
55  * In both cases the mapping is created by adding all global numbers on local subdomain. In order to keep local part of the map
56  * continuous, we need Distribution that describes splitting of global indices into continuous blocks. This Distribution is known
57  * as soon as we assign partitions to processors. So we assume that it is known at construction time.
58  *
59  */
60 
61 
62 
64 public:
65  /**
66  * Constructor. Starts filling of the map.
67  *
68  * @param distr Non overlapping distribution of global indices to processors in continuous blocks.
69  * Local block of indices forms first part of the mapping and then nonlocal indices follows.
70  * This constructor makes a deep copy of the distribution.
71  *
72  */
73  LocalToGlobalMap(const Distribution &distr);
74 
75  /**
76  * Same as the previous constructor, but just takes copy of shared pointer. This assumes that Distribution is allocated on the heap
77  * by something like:
78  *
79  * boost::smart_ptr<Distribution> distr(new Distribution(...));
80  */
81  LocalToGlobalMap(boost::shared_ptr<Distribution> distr);
82 
83  /**
84  * Insert a global index to the mapping.
85  */
86  void insert(const unsigned int idx);
87  /**
88  * Insert more indices at once.
89  */
90  void insert(const std::vector<unsigned int> &indices);
91  /**
92  * Finish filling stage. Creates mapping array, then you can use () operator to map indices.
93  */
94  void finalize();
95  /**
96  * Maps local index to the global one. For DEBUG, performs check for dimension.
97  */
98  inline unsigned int operator[] (const unsigned int local_idx) const
99  {
100  ASSERT_LESS( local_idx, global_indices_.size() );
101  return global_indices_[local_idx];
102  }
103 
104  /**
105  * Returns size of local map.
106  */
107  unsigned int size() const
108  { return global_indices_.size(); }
109 
110  /**
111  * Returns smart_ptr to the Distribution of the global indices. Allow share this among many objects.
112  */
113  boost::shared_ptr<Distribution> &get_distr()
114  { return distr_; }
115 
116  /**
117  * Returns inner vector.
118  */
120  { return global_indices_; }
121 
122 
123 
124 private:
125  /// auxiliary set of non-local part of the map
126  std::set<unsigned int> *nonlocal_indices_;
127  /// distribution of the global indices
128  boost::shared_ptr<Distribution> distr_;
129  /// mapping for all local indices
131 };
132 
133 
134 #endif /* LOCAL_TO_GLOBAL_MAP_HH_ */
boost::shared_ptr< Distribution > distr_
distribution of the global indices
std::vector< unsigned int > global_indices_
mapping for all local indices
void insert(const unsigned int idx)
LocalToGlobalMap(const Distribution &distr)
const std::vector< unsigned int > & get_map_vector() const
boost::shared_ptr< Distribution > & get_distr()
class to manage local indices on sub-domain to global indices on domain
Global macros to enhance readability and debugging, general constants.
#define ASSERT_LESS(a, b)
Definition: global_defs.h:164
unsigned int operator[](const unsigned int local_idx) const
unsigned int size() const
std::set< unsigned int > * nonlocal_indices_
auxiliary set of non-local part of the map