Flow123d  master-f44eb46
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),
33  global_indices_(0)
34 {}
35 
36 void LocalToGlobalMap::insert(const unsigned int global_idx) {
37  ASSERT_EQ( global_indices_.size(), 0 ).error("Insertion into the map after finalize.");
38  if (! distr_->is_local( global_idx ) ) nonlocal_indices_->insert( global_idx );
39 }
40 
42  ASSERT_EQ( global_indices_.size(), 0 ).error("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 
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
Definition: asserts.hh:333
void insert(const unsigned int idx)
std::shared_ptr< Distribution > distr_
distribution of the global indices
std::set< unsigned int > * nonlocal_indices_
auxiliary set of non-local part of the map
std::vector< unsigned int > global_indices_
mapping for all local indices
LocalToGlobalMap(const Distribution &distr)
Support classes for parallel programing.