Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE > Class Template Reference

#include <map_matrix.h>

Public Types

typedef std::map< KEY_TYPE_COL,
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_ROW,
std::map< KEY_TYPE_COL,
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

 MapMatrixMixed ()
 Default (empty) constructor. More...
 
void operator= (const MapMatrixMixed &)
 Broken assignment operator. More...
 
 MapMatrixMixed (const MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE > &map_mat)
 Copy constructor. More...
 
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. More...
 
virtual ~MapMatrixMixed ()
 Destructor. More...
 
void clear ()
 Wipe all entries. More...
 
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. More...
 
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 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...
 

Protected Member Functions

VALUE_TYPE * entry_pt (const KEY_TYPE_ROW &i, const KEY_TYPE_COL &j)
 Return pointer to entry. More...
 

Protected Attributes

std::map< KEY_TYPE_ROW,
std::map< KEY_TYPE_COL,
VALUE_TYPE > * > 
Row_pt
 

Detailed Description

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
class oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >

MapMatrixMixed is a generalised, STL-map-based, sparse(ish) matrix class with mixed indices

The matrix is indexed by indices of type KEY_TYPE_ROW and KEY_TYPE_COL and has entries of type VALUE_TYPE.

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 and associated integers as indices
// in a MapMatrixMixed whose entries are of type int
MapMatrixMixed<Rubbish*,int,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],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:
like_a_matrix(object_pt[1],20)+=13;
like_a_matrix(object_pt[1],1)+=13;
oomph_info << "\n\n\n Here are the nonzero entries: i, j, a(i,j)\n";
like_a_matrix.output(oomph_info);

Definition at line 114 of file map_matrix.h.

Member Typedef Documentation

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
typedef InnerMapMixed::const_iterator oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::ConstInnerMixedIt

Typedef to keep the code more readable const version.

Definition at line 135 of file map_matrix.h.

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
typedef OuterMapMixed::const_iterator oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::ConstOuterMixedIt

Typedef to keep the code more readable const version.

Definition at line 145 of file map_matrix.h.

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
typedef std::map<KEY_TYPE_COL,VALUE_TYPE> oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::InnerMapMixed

Typedef to keep the code more readable.

Definition at line 129 of file map_matrix.h.

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
typedef InnerMapMixed::iterator oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::InnerMixedIt

Typedef to keep the code more readable.

Definition at line 132 of file map_matrix.h.

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
typedef std::map<KEY_TYPE_ROW,std::map<KEY_TYPE_COL,VALUE_TYPE>*> oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::OuterMapMixed

Typedef to keep the code more readable.

Definition at line 139 of file map_matrix.h.

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
typedef OuterMapMixed::iterator oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::OuterMixedIt

Typedef to keep the code more readable.

Definition at line 142 of file map_matrix.h.

Constructor & Destructor Documentation

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::MapMatrixMixed ( )
inline

Default (empty) constructor.

Definition at line 120 of file map_matrix.h.

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::MapMatrixMixed ( const MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE > &  map_mat)
inline

Copy constructor.

Definition at line 149 of file map_matrix.h.

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
virtual oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::~MapMatrixMixed ( )
inlinevirtual

Destructor.

Definition at line 206 of file map_matrix.h.

Member Function Documentation

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
void oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::clear ( )
inline

Wipe all entries.

Definition at line 221 of file map_matrix.h.

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
void oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::copy_column ( const KEY_TYPE_COL &  j,
std::map< KEY_TYPE_ROW, VALUE_TYPE > &  copied_map 
)
inline

Copy a single column into its own map.

Definition at line 182 of file map_matrix.h.

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
VALUE_TYPE* oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::entry_pt ( const KEY_TYPE_ROW &  i,
const KEY_TYPE_COL &  j 
)
inlineprotected

Return pointer to entry.

Definition at line 420 of file map_matrix.h.

Referenced by oomph::MapMatrixMixed< unsigned, unsigned, oomph::CRDoubleMatrix * >::operator()().

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
VALUE_TYPE oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::get ( const KEY_TYPE_ROW &  i,
const KEY_TYPE_COL &  j 
) const
inline

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.

Definition at line 248 of file map_matrix.h.

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
unsigned long oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::nnz ( )
inline

Work out number of non-`zero' entries.

Definition at line 306 of file map_matrix.h.

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
unsigned long oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::nnz ( ) const
inline

Work out number of non-`zero' entries, const version.

Definition at line 335 of file map_matrix.h.

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
VALUE_TYPE& oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::operator() ( const KEY_TYPE_ROW &  i,
const KEY_TYPE_COL &  j 
)
inline

Return (reference to) entry. Careful: If the entry does not exist then it is created and set to zero.

Definition at line 239 of file map_matrix.h.

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
void oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::operator= ( const MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE > &  )
inline

Broken assignment operator.

Definition at line 123 of file map_matrix.h.

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
void oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::output ( std::ostream &  outfile)
inline

Dump all non-`zero' entries to file. Output is in the format `i', `j', `entry[i][j]'.

Definition at line 274 of file map_matrix.h.

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
unsigned long oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::size ( )
inline

Work out total number of entries.

Definition at line 367 of file map_matrix.h.

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
unsigned long oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::size ( ) const
inline

Work out total number of entries const version.

Definition at line 392 of file map_matrix.h.

Member Data Documentation

template<class KEY_TYPE_ROW, class KEY_TYPE_COL, class VALUE_TYPE>
std::map<KEY_TYPE_ROW, std::map<KEY_TYPE_COL, VALUE_TYPE>* > oomph::MapMatrixMixed< KEY_TYPE_ROW, KEY_TYPE_COL, VALUE_TYPE >::Row_pt
protected

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