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