9 #ifndef _fei_DofMapper_hpp_
10 #define _fei_DofMapper_hpp_
41 template<
class LocalOrdinal,
class GlobalOrdinal,
class DofOrder=less_rank_
id_field<LocalOrdinal, GlobalOrdinal> >
51 void addDOF(LocalOrdinal rank, GlobalOrdinal
id, LocalOrdinal field)
63 void setFieldSize(LocalOrdinal field, LocalOrdinal field_size);
67 GlobalOrdinal
getGlobalIndex(LocalOrdinal rank, GlobalOrdinal
id, LocalOrdinal field)
const;
69 std::pair<const Dof<LocalOrdinal,GlobalOrdinal>*,LocalOrdinal>
getDof(GlobalOrdinal global_index)
const;
74 typedef typename std::map<Dof<LocalOrdinal,GlobalOrdinal>,GlobalOrdinal,DofOrder>
DofMap;
79 typename DofMap::const_iterator
end_dof()
const
88 typedef typename std::map<GlobalOrdinal,const Dof<LocalOrdinal,GlobalOrdinal>*>
IdxMap;
93 typename IdxMap::const_iterator
end_idx()
const
112 std::map<Dof<LocalOrdinal, GlobalOrdinal>, GlobalOrdinal, DofOrder >
m_dof_idx;
114 std::map<GlobalOrdinal, const Dof<LocalOrdinal, GlobalOrdinal>*>
m_idx_dof;
123 template<
class LocalOrdinal,
class GlobalOrdinal,
class DofOrder>
126 typename FieldSizeMap::iterator f_iter = m_field_sizes.find(field);
127 if (f_iter == m_field_sizes.end()) {
128 m_field_sizes.insert(std::make_pair(field, field_size));
132 f_iter->second = field_size;
136 template<
class LocalOrdinal,
class GlobalOrdinal,
class DofOrder>
139 typename FieldSizeMap::const_iterator f_iter = m_field_sizes.find(field);
140 if (f_iter == m_field_sizes.end()) {
141 std::ostringstream os;
142 os <<
"fei::DofMapper::getFieldSize ERROR, field=="
143 << field <<
" not found";
144 std::string str = os.str();
145 throw std::runtime_error(str);
147 return f_iter->second;
150 template<
class LocalOrdinal,
class GlobalOrdinal,
class DofOrder>
154 if (iter == m_dof_idx.end()) {
155 std::ostringstream osstr;
156 osstr <<
"fei::DofMapper::getGlobalIndex ERROR, dof("
157 << rank <<
"," <<
id <<
"," << field <<
") not found.";
158 std::string str = osstr.str();
159 throw std::runtime_error(str);
165 template<
class LocalOrdinal,
class GlobalOrdinal,
class DofOrder>
166 std::pair<const Dof<LocalOrdinal,GlobalOrdinal>*,LocalOrdinal>
169 typename IdxMap::const_iterator iter = m_idx_dof.lower_bound(global_index);
170 if (iter == m_idx_dof.begin()) {
171 if (iter->first == global_index) {
172 return std::make_pair(iter->second, global_index);
175 std::ostringstream osstr;
176 osstr <<
"fei::DofMapper::getDof ERROR, dof not found for global_index=="
178 std::string str = osstr.str();
179 throw std::runtime_error(str);
182 else if (iter != m_idx_dof.end() && iter->first == global_index) {
184 return std::make_pair(iter->second, 0);
187 bool last_dof = iter == m_idx_dof.end();
190 LocalOrdinal component = global_index - iter->first;
191 bool check_range_of_component = last_dof && !m_field_sizes.empty();
192 if (check_range_of_component) {
193 typename std::map<LocalOrdinal,LocalOrdinal>::const_iterator f_iter = m_field_sizes.find(iter->second->field());
194 if (f_iter == m_field_sizes.end() || f_iter->second <= component) {
195 std::ostringstream os;
196 os <<
"fei::DofMapper::getDof ERROR2, dof not found for global_index=="
198 std::string str = os.str();
199 throw std::runtime_error(str);
203 return std::make_pair(iter->second, component);
DofMap::const_iterator begin_dof() const
IdxMap::iterator end_idx()
bool maps_are_valid() const
GlobalOrdinal getGlobalIndex(LocalOrdinal rank, GlobalOrdinal id, LocalOrdinal field) const
std::map< Dof< LocalOrdinal, GlobalOrdinal >, GlobalOrdinal, DofOrder > DofMap
const DofMap & get_dof_idx_map() const
void set_maps_are_valid(bool flag)
DofMapper & operator=(const DofMapper< LocalOrdinal, GlobalOrdinal > &src)
DofMap & get_dof_idx_map()
const IdxMap & get_idx_dof_map() const
DofMap::const_iterator end_dof() const
std::map< GlobalOrdinal, const Dof< LocalOrdinal, GlobalOrdinal > * > IdxMap
IdxMap::const_iterator begin_idx() const
const FieldSizeMap & getFieldSizeMap() const
std::map< LocalOrdinal, LocalOrdinal > FieldSizeMap
IdxMap::iterator begin_idx()
DofMap::iterator begin_dof()
std::map< Dof< LocalOrdinal, GlobalOrdinal >, GlobalOrdinal, DofOrder > m_dof_idx
void addDOF(LocalOrdinal rank, GlobalOrdinal id, LocalOrdinal field)
IdxMap & get_idx_dof_map()
std::map< GlobalOrdinal, const Dof< LocalOrdinal, GlobalOrdinal > * > m_idx_dof
std::pair< const Dof< LocalOrdinal, GlobalOrdinal > *, LocalOrdinal > getDof(GlobalOrdinal global_index) const
std::map< LocalOrdinal, LocalOrdinal > m_field_sizes
void setFieldSize(LocalOrdinal field, LocalOrdinal field_size)
DofMap::iterator end_dof()
IdxMap::const_iterator end_idx() const
LocalOrdinal getFieldSize(LocalOrdinal field) const