CEPS  24.01
Cardiac ElectroPhysiology Simulator
LocalGlobalMapping.hpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
30 #pragma once
31 
35 
47 template <class _Type, class _Hash=CepsHash>
49 {
50  public:
51 
54 
57 
59  void
61 
65  void
66  append(const _Type&x , const _Hash& hashValue);
67 
72  void
73  append(const _Type& x, const _Hash& hashValue, const CepsGlobalIndex& gId);
74 
76  const CepsVector<_Type>&
77  all() const;
78 
81  all();
82 
84  CepsUInt
85  size() const;
86 
88  CepsBool
89  contains(const _Type& x) const;
90 
92  void
94 
96  void
97  reset();
98 
100  void
102 
105  void
107 
110  void
111  updateObjects(std::function<void(_Type&,CepsGlobalIndex)> func);
112 
115  const CepsVector<CepsUInt>&
116  getLocalSizes() const;
117 
119  CepsBool
120  hasLocal(const CepsLocalIndex& lId) const;
121 
123  CepsBool
124  hasGlobal(const CepsGlobalIndex& gId) const;
125 
127  CepsBool
128  hasHash(const _Hash& hId) const;
129 
131  _Type&
132  atLocal(const CepsLocalIndex& lId, const _Type& def);
133 
135  const _Type&
136  atLocal(const CepsLocalIndex& lId, const _Type& def) const;
137 
139  const _Type&
140  atLocal(const CepsLocalIndex& lId) const;
141 
143  _Type&
144  atLocal(const CepsLocalIndex& lId);
145 
147  const CepsGlobalIndex&
148  localToGlobal(const CepsLocalIndex& lId) const;
149 
151  _Type&
152  atGlobal(const CepsGlobalIndex& gId, const _Type& def);
153 
155  const _Type&
156  atGlobal(const CepsGlobalIndex& gId, const _Type& def) const;
157 
159  _Type&
161 
163  const _Type&
164  atGlobal(const CepsGlobalIndex& gId) const;
165 
167  const CepsLocalIndex&
168  globalToLocal(const CepsGlobalIndex& gId) const;
169 
171  _Type&
172  atHash(const _Hash& hId);
173 
175  const _Type&
176  atHash(const _Hash& hId) const;
177 
179  _Type&
180  atHash(const _Hash& hId, const _Type& def);
181 
183  const _Type&
184  atHash(const _Hash& hId, const _Type& def) const;
185 
187  const CepsLocalIndex&
188  hashToLocal(const _Hash& hId) const;
189 
191  const CepsGlobalIndex&
192  hashToGlobal(const _Hash& hId) const;
193 
195  void
196  registerIndices(const CepsLocalIndex& localId, const CepsGlobalIndex& globalId);
197 
198 
199  protected:
200 
203  pushBack(const _Type& x);
204 
206  void
207  registerHash(const CepsLocalIndex& localId, const _Hash& hashValue);
208 
209 
210  protected:
211 
218 
219 };
220 
221 // Template definitions
std::map< _Key, _Tp, _Compare, _Alloc > CepsMap
C++ map.
Definition: CepsTypes.hpp:196
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
CepsIndex CepsGlobalIndex
Many uses. Has to be signed for PETSc.
Definition: CepsTypes.hpp:218
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
CepsIndex CepsLocalIndex
To use when the indexing is only on one process.
Definition: CepsTypes.hpp:219
A map destined for things that have (or could have) a global index and must be distributed amongst CP...
_Type & atLocal(const CepsLocalIndex &lId)
Access value with local ID.
void reserve(CepsUInt n)
Prepare room for storage.
void registerIndices(const CepsLocalIndex &localId, const CepsGlobalIndex &globalId)
Stores the pair (localID,globalID)
CepsMap< CepsLocalIndex, CepsGlobalIndex > m_localToGlobal
reverse map
const _Type & atHash(const _Hash &hId, const _Type &def) const
Access value with given hash, with default value.
void reset()
Wipes content, erase structure.
CepsVector< _Type > & all()
acces to data
CepsBool hasLocal(const CepsLocalIndex &lId) const
Tells if item with local index lID can be found on this CPU.
void append(const _Type &x, const _Hash &hashValue, const CepsGlobalIndex &gId)
Emplace an element in the map, with an extra global index.
_Type & atGlobal(const CepsGlobalIndex &gId)
Access value with global ID.
CepsMap< _Hash, CepsLocalIndex > m_hash
hash map
CepsUInt size() const
Number of elements.
CepsBool contains(const _Type &x) const
Tells if the map has the element x.
const CepsGlobalIndex & localToGlobal(const CepsLocalIndex &lId) const
Local index to global index conversion.
CepsVector< CepsUInt > m_localSizes
sizes of maps on each cpu
~LocalGlobalMapping()
Destructor.
const _Type & atHash(const _Hash &hId) const
Access value with given hash, with default value.
const CepsVector< _Type > & all() const
access to data
void setGlobalIndicesFromLocals()
Modifies the local indices by adding the total number of elements on CPUs before self.
void registerHash(const CepsLocalIndex &localId, const _Hash &hashValue)
Stores the localID associated to the hash.
const CepsLocalIndex & hashToLocal(const _Hash &hId) const
Access value with given hash.
_Type & atHash(const _Hash &hId, const _Type &def)
Access value with given hash, with default value.
void updateObjects(std::function< void(_Type &, CepsGlobalIndex)> func)
Applies function func to all elements stored.
_Type & atLocal(const CepsLocalIndex &lId, const _Type &def)
Access value with local ID, with default value.
const CepsLocalIndex & globalToLocal(const CepsGlobalIndex &gId) const
Global index to local index conversion.
CepsMap< CepsGlobalIndex, CepsLocalIndex > m_globalToLocal
global local map
_Type & atGlobal(const CepsGlobalIndex &gId, const _Type &def)
Access value with global ID, with default value.
_Type & atHash(const _Hash &hId)
Access value with given hash, with default value.
const CepsGlobalIndex & hashToGlobal(const _Hash &hId) const
Access value with given hash.
void destroyObjects()
Wipes content, keeps structure.
const CepsVector< CepsUInt > & getLocalSizes() const
Number of elements on each CPU synchronize must be called beforehand.
CepsBool hasHash(const _Hash &hId) const
Tells if map contains the hash hID.
CepsLocalIndex pushBack(const _Type &x)
Adds an element to the map, returns the localID.
CepsBool hasGlobal(const CepsGlobalIndex &gId) const
Tells if item with global index gID can be found on this CPU.
CepsVector< _Type > m_data
Stored objects.
const _Type & atLocal(const CepsLocalIndex &lId) const
Access value with local ID.
LocalGlobalMapping()
Constructor, empty structures.
const _Type & atGlobal(const CepsGlobalIndex &gId, const _Type &def) const
Access value with global ID, with default value.
void append(const _Type &x, const _Hash &hashValue)
Emplace an element in the map.
const _Type & atGlobal(const CepsGlobalIndex &gId) const
Access value with global ID.
void synchronizeLocalSizes()
Get info on number of local elements from each CPU.
const _Type & atLocal(const CepsLocalIndex &lId, const _Type &def) const
Access value with local ID, with default value.
CepsBool m_synchronized
true if sizes were updated