Flow123d  master-c754b67
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 //
22 
23 #include <iosfwd>
24 #include <memory>
25 #include <set>
26 #include <string>
27 #include <vector>
28 
29 #include "system/exc_common.hh"
30 #include "system/exceptions.hh"
31 #include "system/global_defs.h"
32 
33 
34 class Distribution;
35 
36 /**
37  * @brief class to manage local indices on sub-domain to global indices on domain
38  *
39  * Currently (March 2012) the local to global maps are managed by individual equations (e.g. DarcyFlow has el_4_loc .. there it is complicated
40  * by different local indexing of elements, sides and edges). In fact el_4_loc etc. are new_local to old_global maps.
41  * This map is created as follows:
42  *
43  * PETSC solver:
44  * 1) create graph
45  * 2) make partitioning
46  * 2.5) create id_4_old (just used to create new_4_id, id was non continuous index not used anymore)
47  * 3) call id_maps which:
48  * 4) call ISPartitioninToNumbering : assign partitions to processors (identity, no optimization); make "distribution";
49  * make mapping (array of ints): old_local to new_global
50  * 5) from this we crate AO (application ordering from PETSc)
51  * 6) use AO to map identity array to old numbering -> creates map: new_global to old_global
52  * 7) go through new_local continuous part and map it to old_global index
53  * ---
54  * So this produce new_local to old_global mapping and only for continuous part of local indices (not for ghost indices)
55  * See that this works without any information about connectivity.
56  *
57  * METIS/BDDC solver:
58  * 1) graph, partition of elements, maps for elements (no overlap, no ghost values) using id_maps function
59  * 2) same for edges -> produce non overlapping local to global maps.
60  * 3) use std::set to collect all dofs on local elements (pass through mesh) complexity: n*log(n) n-local number of dofs
61  * 4) copy set to vector - makes local ordering arbitrary
62  *
63  * Future usage is:
64  * - in mesh to map local idx of entities to global indices
65  * - in dof handler to map local dofs idx to global
66  *
67  * In both cases the mapping is created by adding all global numbers on local subdomain. In order to keep local part of the map
68  * continuous, we need Distribution that describes splitting of global indices into continuous blocks. This Distribution is known
69  * as soon as we assign partitions to processors. So we assume that it is known at construction time.
70  *
71  */
72 
73 
74 
76 public:
77  /**
78  * Constructor. Starts filling of the map.
79  *
80  * @param distr Non overlapping distribution of global indices to processors in continuous blocks.
81  * Local block of indices forms first part of the mapping and then nonlocal indices follows.
82  * This constructor makes a deep copy of the distribution.
83  *
84  */
85  LocalToGlobalMap(const Distribution &distr);
86 
87  /**
88  * Same as the previous constructor, but just takes copy of shared pointer. This assumes that Distribution is allocated on the heap
89  * by: std::make_shared<Distribution>
90  */
91  LocalToGlobalMap(std::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  ASSERT_LT( 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  std::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  std::shared_ptr<Distribution> distr_;
139  /// mapping for all local indices
141 };
142 
143 
144 #endif /* LOCAL_TO_GLOBAL_MAP_HH_ */
LocalToGlobalMap::get_map_vector
const std::vector< unsigned int > & get_map_vector() const
Definition: local_to_global_map.hh:129
LocalToGlobalMap::size
unsigned int size() const
Definition: local_to_global_map.hh:117
std::vector< unsigned int >
LocalToGlobalMap
class to manage local indices on sub-domain to global indices on domain
Definition: local_to_global_map.hh:75
LocalToGlobalMap::nonlocal_indices_
std::set< unsigned int > * nonlocal_indices_
auxiliary set of non-local part of the map
Definition: local_to_global_map.hh:136
exceptions.hh
ASSERT_LT
#define ASSERT_LT(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
Definition: asserts.hh:301
Distribution
Definition: distribution.hh:50
LocalToGlobalMap::finalize
void finalize()
Definition: local_to_global_map.cc:47
LocalToGlobalMap::operator[]
unsigned int operator[](const unsigned int local_idx) const
Definition: local_to_global_map.hh:108
LocalToGlobalMap::global_indices_
std::vector< unsigned int > global_indices_
mapping for all local indices
Definition: local_to_global_map.hh:140
LocalToGlobalMap::insert
void insert(const unsigned int idx)
Definition: local_to_global_map.cc:36
exc_common.hh
LocalToGlobalMap::distr_
std::shared_ptr< Distribution > distr_
distribution of the global indices
Definition: local_to_global_map.hh:138
global_defs.h
Global macros to enhance readability and debugging, general constants.
LocalToGlobalMap::LocalToGlobalMap
LocalToGlobalMap(const Distribution &distr)
Definition: local_to_global_map.cc:24
LocalToGlobalMap::get_distr
std::shared_ptr< Distribution > get_distr()
Definition: local_to_global_map.hh:123