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