Public Types | Public Member Functions | List of all members
oomph::MapMatrix< KEY_TYPE, VALUE_TYPE > Class Template Reference

//////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// More...

#include <map_matrix.h>

+ Inheritance diagram for oomph::MapMatrix< KEY_TYPE, VALUE_TYPE >:

Public Types

typedef std::map< KEY_TYPE, VALUE_TYPE > InnerMap
 Typedef to keep the code more readable. More...
 
typedef InnerMap::iterator InnerIt
 Typedef to keep the code more readable. More...
 
typedef InnerMap::const_iterator ConstInnerIt
 Typedef to keep the code more readable. More...
 
typedef std::map< KEY_TYPE, std::map< KEY_TYPE, VALUE_TYPE > * > OuterMap
 Typedef to keep the code more readable. More...
 
typedef OuterMap::iterator OuterIt
 Typedef to keep the code more readable. More...
 
typedef OuterMap::const_iterator ConstOuterIt
 Typedef to keep the code more readable. More...
 
- Public Types inherited from oomph::MapMatrixMixed< KEY_TYPE, KEY_TYPE, VALUE_TYPE >
typedef std::map< KEY_TYPE, VALUE_TYPE > InnerMapMixed
 Typedef to keep the code more readable. More...
 
typedef InnerMapMixed::iterator InnerMixedIt
 Typedef to keep the code more readable. More...
 
typedef InnerMapMixed::const_iterator ConstInnerMixedIt
 Typedef to keep the code more readable const version. More...
 
typedef std::map< KEY_TYPE, std::map< KEY_TYPE, VALUE_TYPE > * > OuterMapMixed
 Typedef to keep the code more readable. More...
 
typedef OuterMapMixed::iterator OuterMixedIt
 Typedef to keep the code more readable. More...
 
typedef OuterMapMixed::const_iterator ConstOuterMixedIt
 Typedef to keep the code more readable const version. More...
 

Public Member Functions

 MapMatrix ()
 Default (empty) constructor. More...
 
 MapMatrix (const MapMatrix< KEY_TYPE, VALUE_TYPE > &map_mat)
 Copy constructor. More...
 
void operator= (const MapMatrix &)=delete
 Broken assignment operator. More...
 
- Public Member Functions inherited from oomph::MapMatrixMixed< KEY_TYPE, KEY_TYPE, VALUE_TYPE >
 MapMatrixMixed ()
 Default (empty) constructor. More...
 
 MapMatrixMixed (const MapMatrixMixed< KEY_TYPE, KEY_TYPE, VALUE_TYPE > &map_mat)
 Copy constructor. More...
 
void operator= (const MapMatrixMixed &)=delete
 Broken assignment operator. More...
 
void copy_column (const KEY_TYPE &j, std::map< KEY_TYPE, VALUE_TYPE > &copied_map)
 Copy a single column into its own map. More...
 
virtual ~MapMatrixMixed ()
 Destructor. More...
 
void clear ()
 Wipe all entries. More...
 
VALUE_TYPE & operator() (const KEY_TYPE &i, const KEY_TYPE &j)
 Return (reference to) entry. Careful: If the entry does not exist then it is created and set to zero. More...
 
VALUE_TYPE get (const KEY_TYPE &i, const KEY_TYPE &j) const
 Get an element corresponding to the key (i,j) Searches the container for an element with a key equivalent to (i,j) and returns the element if found, otherwise the default 0 value for the value type is returned. The container is not modified. More...
 
void output (std::ostream &outfile)
 Dump all non-‘zero’ entries to file. Output is in the format ‘i’, ‘j’, ‘entry[i][j]’. More...
 
unsigned long nnz ()
 Work out number of non-‘zero’ entries. More...
 
unsigned long nnz () const
 Work out number of non-‘zero’ entries, const version. More...
 
unsigned long size ()
 Work out total number of entries. More...
 
unsigned long size () const
 Work out total number of entries const version. More...
 

Additional Inherited Members

- Protected Member Functions inherited from oomph::MapMatrixMixed< KEY_TYPE, KEY_TYPE, VALUE_TYPE >
VALUE_TYPE * entry_pt (const KEY_TYPE &i, const KEY_TYPE &j)
 Return pointer to entry. More...
 
- Protected Attributes inherited from oomph::MapMatrixMixed< KEY_TYPE, KEY_TYPE, VALUE_TYPE >
std::map< KEY_TYPE, std::map< KEY_TYPE, VALUE_TYPE > * > Row_pt
 Here's the generalised matrix structure: A map of pointers to the maps that hold the entries in each row. More...
 

Detailed Description

template<class KEY_TYPE, class VALUE_TYPE>
class oomph::MapMatrix< KEY_TYPE, VALUE_TYPE >

//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

MapMatrix is a generalised, STL-map-based, sparse(-ish) matrix class.

The matrix is indexed by indices of type KEY_TYPE and has entries of type VALUE_TYPE. It is a specialisation of the class MapMatrixMixed. Please implement future functions in that class.

Careful: If a zero entry is referenced then it is created in memory. Therefore this isn't really a practical sparse matrix scheme. Do not loop over ‘all’ possible indices as even looking at them will inflate the matrix until it occupies as much space as a full one – use (modification of) output routine to retrieve all nonzero entries.

However, this is not a serious restriction, as the main purpose of this class is to allow non-integer indices.

Example of usage:

// Assume we have a Vector of pointers to objects:
Vector<Rubbish*> object_pt;
[...]
// Number of objects
int nentry=object_pt.size();
// Use the pointers to the objects as indices
// in a MapMatrix whose entries are of type int
MapMatrix<Rubbish*,int> like_a_matrix;
for (int i=1;i<nentry;i++)
{
for (int j=1;j<nentry;j++)
{
int number=100*i+j;
like_a_matrix(object_pt[i],object_pt[j])=number;
}
}
oomph_info << "Matrix has nnz() " << like_a_matrix.nnz() <<
" and size() " << like_a_matrix.size() << std::endl;
oomph_info << "\n\n\n Here are the nonzero entries: i, j, a(i,j)\n";
like_a_matrix.output(oomph_info);
// Can be used like a normal matrix:
//Add to existing entry
like_a_matrix(object_pt[1],object_pt[2])+=13;
// Add to non-existing entry
Rubbish* temp_pt=new Rubbish(20);
like_a_matrix(object_pt[1],temp_pt)+=13;
oomph_info << "\n\n\n Here are the nonzero entries: i, j, a(i,j)\n";
like_a_matrix.output(oomph_info);
cstr elem_len * i
Definition: cfortran.h:603
OomphInfo oomph_info
Single (global) instantiation of the OomphInfo object – this is used throughout the library as a "rep...

Definition at line 507 of file map_matrix.h.

Member Typedef Documentation

◆ ConstInnerIt

template<class KEY_TYPE , class VALUE_TYPE >
typedef InnerMap::const_iterator oomph::MapMatrix< KEY_TYPE, VALUE_TYPE >::ConstInnerIt

Typedef to keep the code more readable.

Definition at line 520 of file map_matrix.h.

◆ ConstOuterIt

template<class KEY_TYPE , class VALUE_TYPE >
typedef OuterMap::const_iterator oomph::MapMatrix< KEY_TYPE, VALUE_TYPE >::ConstOuterIt

Typedef to keep the code more readable.

Definition at line 529 of file map_matrix.h.

◆ InnerIt

template<class KEY_TYPE , class VALUE_TYPE >
typedef InnerMap::iterator oomph::MapMatrix< KEY_TYPE, VALUE_TYPE >::InnerIt

Typedef to keep the code more readable.

Definition at line 517 of file map_matrix.h.

◆ InnerMap

template<class KEY_TYPE , class VALUE_TYPE >
typedef std::map<KEY_TYPE, VALUE_TYPE> oomph::MapMatrix< KEY_TYPE, VALUE_TYPE >::InnerMap

Typedef to keep the code more readable.

Definition at line 514 of file map_matrix.h.

◆ OuterIt

template<class KEY_TYPE , class VALUE_TYPE >
typedef OuterMap::iterator oomph::MapMatrix< KEY_TYPE, VALUE_TYPE >::OuterIt

Typedef to keep the code more readable.

Definition at line 526 of file map_matrix.h.

◆ OuterMap

template<class KEY_TYPE , class VALUE_TYPE >
typedef std::map<KEY_TYPE, std::map<KEY_TYPE, VALUE_TYPE>*> oomph::MapMatrix< KEY_TYPE, VALUE_TYPE >::OuterMap

Typedef to keep the code more readable.

Definition at line 523 of file map_matrix.h.

Constructor & Destructor Documentation

◆ MapMatrix() [1/2]

template<class KEY_TYPE , class VALUE_TYPE >
oomph::MapMatrix< KEY_TYPE, VALUE_TYPE >::MapMatrix ( )
inline

Default (empty) constructor.

Definition at line 511 of file map_matrix.h.

◆ MapMatrix() [2/2]

template<class KEY_TYPE , class VALUE_TYPE >
oomph::MapMatrix< KEY_TYPE, VALUE_TYPE >::MapMatrix ( const MapMatrix< KEY_TYPE, VALUE_TYPE > &  map_mat)
inline

Copy constructor.

Definition at line 532 of file map_matrix.h.

References oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::Row_pt.

Member Function Documentation

◆ operator=()

template<class KEY_TYPE , class VALUE_TYPE >
void oomph::MapMatrix< KEY_TYPE, VALUE_TYPE >::operator= ( const MapMatrix< KEY_TYPE, VALUE_TYPE > &  )
delete

Broken assignment operator.


The documentation for this class was generated from the following file: