26#ifndef OOMPH_SUM_OF_MATRICES_H
27#define OOMPH_SUM_OF_MATRICES_H
40 using namespace StringConversion;
81 " not found in lookup.";
88 std::string
err =
"Something crazy went wrong here.";
102 std::map<unsigned, unsigned>::const_iterator
it =
142 std::string
err =
"negative entry in lookup array!";
160 for (
unsigned i = 0;
i <
ni;
i++)
172 for (
unsigned j = 0;
j <
n;
j++)
202 for (
unsigned nd = 0, nnode = mesh_pt->
nnode();
nd < nnode;
nd++)
215 error_msg <<
"Must set up Added_to_main_mapping first.";
261 public Matrix<double, SumOfMatrices>
371 for (
unsigned long i = 0;
i <
nrow();
i++)
373 for (
unsigned long j = 0;
j <
ncol();
j++)
407 values.push_back(
entry);
426 "Row mapping size should be less than or equal to nrow (less than if "
427 "it is a sparse matrix and there are some empty rows).",
437 "Col mapping size should be less than or equal to ncol (less than if "
438 "it is a sparse matrix and there are some empty cols).",
453 "Trying to add a matrix with a mapping which specifices";
469 "Trying to add a matrix with a mapping which specifices";
501 inline unsigned long nrow()
const
515 inline unsigned long ncol()
const
540 double&
entry(
const unsigned long&
i,
const unsigned long&
j)
const
543 "Broken write to entry: it does not make sense to write to a sum, you "
544 "must write to one of the component matrices.",
552 double operator()(
const unsigned long&
i,
const unsigned long&
j)
const
562 if ((
li != -1) && (
lj != -1))
577 error_msg <<
"Function not yet implemented.";
Class to store bi-directional lookup between added matrix row/col numbers to main matrix (SumOfMatrix...
AddedMainNumberingLookup(const Mesh *mesh_pt, const unsigned &dof_index)
Real constructor: construct lookup from node numbers in mesh and global equation numbers....
unsigned main_to_added(const int &main) const
Given a main matrix row/col number get the equivalent row/col in the added matrix....
AddedMainNumberingLookup()
Default constructor.
void construct_reverse_mapping()
Set up the main to added mapping using the added to main mapping.
AddedMainNumberingLookup(const int *lookup_array, const unsigned &length)
Construct lookup schemes from int array (HLib's format for this data).
unsigned added_to_main(const unsigned &added) const
Given a row/col number in the added matrix return the equivalent row/col number in the main matrix.
const std::map< unsigned, unsigned > * main_to_added_mapping_pt() const
Const access function for mapping.
Vector< unsigned > Added_to_main_mapping
Mapping from added matrix row/col numbers to main matrix row/col numbers.
AddedMainNumberingLookup(const AddedMainNumberingLookup &dummy)=delete
Inaccessible copy constructor.
int unsafe_main_to_added(const int &main) const
Given a main matrix row/col number get the equivalent row/col in the added matrix....
void build(const Mesh *mesh_pt, const unsigned &dof_index)
Construct the lookup schemes given a mesh and the degree of freedom to lookup main equation numbers f...
void operator=(const AddedMainNumberingLookup &dummy)=delete
Inaccessible assignment operator.
void build_identity_map(const unsigned &n)
Construct an identity map (mostly for testing).
void construct_added_to_main_mapping(const Mesh *mesh_pt, const unsigned &dof_index)
Set up the lookup from added matrix row/col to main matrix.
void build(const Vector< const Node * > &bem_lookup, const unsigned &dof_index)
Construct lookup using node vector.
const Vector< unsigned > * added_to_main_mapping_pt() const
Const access function for mapping.
std::map< unsigned, unsigned > Main_to_added_mapping
Mapping from main matrix row/col numbers to added matrix row/col numbers. Note that we cannot use a v...
~AddedMainNumberingLookup()
Destructor.
void build(const int *lookup_array, const unsigned &length)
Construct lookup schemes from int array (HLib's format for this data).
long & eqn_number(const unsigned &i)
Return the equation number of the i-th stored variable.
Abstract base class for matrices of doubles – adds abstract interfaces for solving,...
virtual unsigned long ncol() const =0
Return the number of columns of the matrix.
virtual unsigned long nrow() const =0
Return the number of rows of the matrix.
A vector in the mathematical sense, initially developed for linear algebra type applications....
double size() const
Calculate the size of the element (length, area, volume,...) in Eulerian computational coordinates....
unsigned long eqn_number(const unsigned &ieqn_local) const
Return the global equation number corresponding to the ieqn_local-th local equation number.
Abstract base class for matrices, templated by the type of object that is stored in them and the type...
Node *& node_pt(const unsigned long &n)
Return pointer to global node n.
unsigned long nnode() const
Return number of nodes in the mesh.
An OomphLibError object which should be thrown when an run-time error is encountered....
Class for a matrix of the form M = S + G + H + ... where S is the main matrix and G,...
virtual void multiply_transpose(const DoubleVector &x, DoubleVector &soln) const
Dummy overload of a pure virtual function. I'm not sure how best to implement this and I don't think ...
SumOfMatrices(const SumOfMatrices &matrix)=delete
Broken copy constructor.
void output_bottom_right_zero_helper(std::ostream &outfile) const
Output the "bottom right" entry regardless of it being zero or not (this allows automatic detection o...
SumOfMatrices(DoubleMatrixBase *main_matrix_pt)
Constructor taking a pointer to the main matrix as input.
DoubleMatrixBase *& main_matrix_pt()
unsigned n_added_matrix() const
Return the number of added matrices in the sum.
const AddedMainNumberingLookup * row_map_pt(const unsigned &i) const
Access to the maps.
unsigned long nrow() const
Return the number of rows of the main matrix.
SumOfMatrices()
Default constructor.
Vector< DoubleMatrixBase * > Added_matrix_pt
List of pointers to the matrices that are added to the main matrix.
Vector< const AddedMainNumberingLookup * > Col_map_pt
List of maps between col numbers of the main matrix and the added matrices.
void set_delete_main_matrix()
Set the main matrix to be deleted by the destructor of the SumOfMatrices (default is to not delete it...
double operator()(const unsigned long &i, const unsigned long &j) const
Access function to get the total value of entries in position (i,j). Warning: this way of getting ent...
void add_matrix(DoubleMatrixBase *added_matrix_pt_in, const AddedMainNumberingLookup *main_to_added_rows_pt, const AddedMainNumberingLookup *main_to_added_cols_pt, bool should_delete_matrix=false)
Add a new matrix to the sum by giving a matrix pointer and a mapping from the main matrix numbering t...
const AddedMainNumberingLookup * col_map_pt(const unsigned &i) const
void operator=(const SumOfMatrices &)=delete
Broken assignment operator.
const DoubleMatrixBase * main_matrix_pt() const
Access to the main matrix.
Vector< const AddedMainNumberingLookup * > Row_map_pt
List of maps between row numbers of the main matrix and the added matrices.
Vector< unsigned > Should_delete_added_matrix
Should we delete the sub matrices when destructor is called?
void get_as_indices(Vector< int > &row, Vector< int > &col, Vector< double > &values)
Get a list of row/col indices and total entry for non-zeros in the matrix. e.g. for use as input to o...
double & entry(const unsigned long &i, const unsigned long &j) const
Broken operator() because it does not make sense to return anything by reference.
unsigned long ncol() const
Return the number of columns of the main matrix.
void multiply(const DoubleVector &x, DoubleVector &soln) const
Multiply: just call multiply on each of the matrices and add up the results (with appropriate bookeep...
DoubleMatrixBase * added_matrix_pt(const unsigned &i) const
Access function for ith added matrix (main matrix not included in numbering).
bool Should_delete_main_matrix
Should we delete the main matrix when destructor is called? Default is no.
~SumOfMatrices()
Destructor: delete matrices as instructed by Should_delete_added_matrix vector and Should_delete_main...
void sparse_indexed_output_helper(std::ostream &outfile) const
Output the matrix in sparse format. Note that this is going to be slow because we have to check every...
DoubleMatrixBase * Main_matrix_pt
Pointer to the matrix which we are adding the others to.
TAdvectionDiffusionReactionElement<NREAGENT,DIM,NNODE_1D> elements are isoparametric triangular DIM-d...
std::string to_string(T object, unsigned float_precision=8)
Conversion function that should work for anything with operator<< defined (at least all basic types).
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).