26 #ifndef OOMPH_MAP_MATRIX_HEADER
27 #define OOMPH_MAP_MATRIX_HEADER
32 #include <oomph-lib-config.h>
107 template<
class KEY_TYPE_ROW,
class KEY_TYPE_COL,
class VALUE_TYPE>
127 typedef std::map<KEY_TYPE_ROW, std::map<KEY_TYPE_COL, VALUE_TYPE>*>
143 it != map_mat.
Row_pt.end();
154 it2 != inner_map.end();
158 if (it2->second != 0)
161 (*this)(it->first, it2->first) = it2->second;
171 std::map<KEY_TYPE_ROW, VALUE_TYPE>& copied_map)
182 if (inner_map[j] != 0)
186 copied_map[it->first] = inner_map[j];
227 VALUE_TYPE&
operator()(
const KEY_TYPE_ROW&
i,
const KEY_TYPE_COL& j)
236 VALUE_TYPE
get(
const KEY_TYPE_ROW&
i,
const KEY_TYPE_COL& j)
const
242 if (inner_map_mixed_pt->count(j) > 0)
244 return inner_map_mixed_pt->find(j)->second;
248 return VALUE_TYPE(0);
254 return VALUE_TYPE(0);
279 for (
InnerMixedIt it2 = inner_map.begin(); it2 != inner_map.end();
283 if (it2->second != 0)
286 outfile << it->first <<
" " << it2->first <<
" " << it2->second
298 unsigned long count = 0;
310 for (
InnerMixedIt it2 = inner_map.begin(); it2 != inner_map.end();
314 if (it2->second != 0)
328 unsigned long count = 0;
341 it2 != inner_map.end();
345 if (it2->second != 0)
360 unsigned long count = 0;
372 for (
InnerMixedIt it2 = inner_map.begin(); it2 != inner_map.end();
386 unsigned long count = 0;
399 it2 != inner_map.end();
412 VALUE_TYPE*
entry_pt(
const KEY_TYPE_ROW&
i,
const KEY_TYPE_COL& j)
418 Row_pt[
i] =
new std::map<KEY_TYPE_COL, VALUE_TYPE>;
419 (*
Row_pt[
i])[j] = VALUE_TYPE(0);
432 std::map<KEY_TYPE_ROW, std::map<KEY_TYPE_COL, VALUE_TYPE>*>
Row_pt;
506 template<
class KEY_TYPE,
class VALUE_TYPE>
523 typedef std::map<KEY_TYPE, std::map<KEY_TYPE, VALUE_TYPE>*>
OuterMap;
545 for (
ConstInnerIt it2 = inner_map.begin(); it2 != inner_map.end();
549 if (it2->second != 0)
551 (*this)(it->first, it2->first) = it2->second;
MapMatrixMixed is a generalised, STL-map-based, sparse(ish) matrix class with mixed indices.
InnerMapMixed::const_iterator ConstInnerMixedIt
Typedef to keep the code more readable const version.
void operator=(const MapMatrixMixed &)=delete
Broken assignment operator.
unsigned long nnz()
Work out number of non-‘zero’ entries.
void copy_column(const KEY_TYPE_COL &j, std::map< KEY_TYPE_ROW, VALUE_TYPE > &copied_map)
Copy a single column into its own map.
MapMatrixMixed()
Default (empty) constructor.
unsigned long nnz() const
Work out number of non-‘zero’ entries, const version.
std::map< KEY_TYPE_COL, VALUE_TYPE > InnerMapMixed
Typedef to keep the code more readable.
virtual ~MapMatrixMixed()
Destructor.
InnerMapMixed::iterator InnerMixedIt
Typedef to keep the code more readable.
VALUE_TYPE * entry_pt(const KEY_TYPE_ROW &i, const KEY_TYPE_COL &j)
Return pointer to entry.
void output(std::ostream &outfile)
Dump all non-‘zero’ entries to file. Output is in the format ‘i’, ‘j’, ‘entry[i][j]’.
OuterMapMixed::const_iterator ConstOuterMixedIt
Typedef to keep the code more readable const version.
void clear()
Wipe all entries.
std::map< KEY_TYPE_ROW, std::map< KEY_TYPE_COL, VALUE_TYPE > * > Row_pt
Here's the generalised matrix structure: A map of pointers to the maps that hold the entries in each ...
VALUE_TYPE & operator()(const KEY_TYPE_ROW &i, const KEY_TYPE_COL &j)
Return (reference to) entry. Careful: If the entry does not exist then it is created and set to zero.
unsigned long size() const
Work out total number of entries const version.
MapMatrixMixed(const MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE > &map_mat)
Copy constructor.
OuterMapMixed::iterator OuterMixedIt
Typedef to keep the code more readable.
VALUE_TYPE get(const KEY_TYPE_ROW &i, const KEY_TYPE_COL &j) const
Get an element corresponding to the key (i,j) Searches the container for an element with a key equiva...
unsigned long size()
Work out total number of entries.
std::map< KEY_TYPE_ROW, std::map< KEY_TYPE_COL, VALUE_TYPE > * > OuterMapMixed
Typedef to keep the code more readable.
//////////////////////////////////////////////////////////////////// ////////////////////////////////...
std::map< KEY_TYPE, std::map< KEY_TYPE, VALUE_TYPE > * > OuterMap
Typedef to keep the code more readable.
InnerMap::iterator InnerIt
Typedef to keep the code more readable.
MapMatrix()
Default (empty) constructor.
OuterMap::const_iterator ConstOuterIt
Typedef to keep the code more readable.
OuterMap::iterator OuterIt
Typedef to keep the code more readable.
InnerMap::const_iterator ConstInnerIt
Typedef to keep the code more readable.
MapMatrix(const MapMatrix< KEY_TYPE, VALUE_TYPE > &map_mat)
Copy constructor.
void operator=(const MapMatrix &)=delete
Broken assignment operator.
std::map< KEY_TYPE, VALUE_TYPE > InnerMap
Typedef to keep the code more readable.
//////////////////////////////////////////////////////////////////// ////////////////////////////////...