Flow123d  release_2.2.0-914-gf1a3a4f
local_to_global_map.cc
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.cc
15  * @brief
16  */
17 
19 #include <la/distribution.hh>
20 
21 #include "system/system.hh"
22 
23 
25 : nonlocal_indices_(new std::set<unsigned int>()),
26  distr_(std::make_shared<Distribution>(any_distr)),
27  global_indices_(0)
28 {}
29 
30 LocalToGlobalMap::LocalToGlobalMap(std::shared_ptr<Distribution> any_distr)
31 : nonlocal_indices_(new std::set<unsigned int>()),
32  distr_(any_distr),
34 {}
35 
36 void LocalToGlobalMap::insert(const unsigned int global_idx) {
37  OLD_ASSERT( global_indices_.size() == 0, "Insertion into the map after finalize.");
38  if (! distr_->is_local( global_idx ) ) nonlocal_indices_->insert( global_idx );
39 }
40 
42  OLD_ASSERT( global_indices_.size() == 0, "Insertion into the map after finalize.");
43  for(std::vector<unsigned int>::const_iterator it=indices.begin(); it != indices.end(); ++it)
44  if (! distr_->is_local( *it ) ) nonlocal_indices_->insert( *it );
45 }
46 
48  global_indices_.resize( distr_->lsize() + nonlocal_indices_->size() );
49  unsigned int i;
50 
51  for(i=0; i< distr_->lsize(); i++) global_indices_[i]=distr_->begin()+i;
52  for(std::set<unsigned int>::iterator it = nonlocal_indices_->begin();
53  it != nonlocal_indices_->end(); ++it)
54  global_indices_[i++]=*it;
55  delete nonlocal_indices_;
56 }
57 
58 
59 
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 > distr_
distribution of the global indices
#define OLD_ASSERT(...)
Definition: global_defs.h:131
Support classes for parallel programing.
std::set< unsigned int > * nonlocal_indices_
auxiliary set of non-local part of the map