Commit 152f9268 authored by gfourestey's avatar gfourestey
Browse files

MatrixMarket format writter for both matrices and vectors implemented

parent ea044f41
......@@ -161,6 +161,15 @@ public:
void set_mat_inc( UInt row, UInt col, DataType loc_val );
/*! Save the matrix into a MatrixMarket (.mtx) file
* @param filename file where the matrix will be saved
* @param headers boolean to write the MM headers or not
*/
void matrixMarket( std::string const &filename, const bool headers = true );
/*! Save the matrix into a Matlab (.m) file
* @param filename file where the matrix will be saved
*/
......@@ -911,6 +920,33 @@ int EpetraMatrix<DataType>::getMeanNumEntries() const
return meanNumEntries;
}
template <typename DataType>
void EpetraMatrix<DataType>::matrixMarket( std::string const &filename, const bool headers)
{
// Purpose: Matlab dumping and spy
std::string nome = filename;
std::string desc = "Created by LifeV";
//int me = M_epetraCrs->Comm().MyPID();
//
// check on the file name
//
// std::ostringstream myStream;
// myStream << me;
nome = filename + ".mtx";
EpetraExt::RowMatrixToMatrixMarketFile( nome.c_str(),
*M_epetraCrs,
nome.c_str(),
desc.c_str(),
headers
);
}
template <typename DataType>
void EpetraMatrix<DataType>::spy( std::string const &filename)
{
......
......@@ -425,6 +425,38 @@ EpetraVector::Dot( const EpetraVector& vector, data_type& scalarProduct )
M_epetraVector->Dot( vector.getEpetraVector(), &scalarProduct );
}
void EpetraVector::matrixMarket( std::string const &filename, const bool headers ) const
{
// Purpose: Matlab dumping and spy
std::string nome = filename;
std::string desc = "Created by LifeV";
int me = M_epetraVector->Comm().MyPID();
if (M_maptype == Repeated)
{
EpetraVector unique(*this, Unique, Zero);
unique.spy(filename);
return;
}
// check on the file name
// std::ostringstream myStream;
// myStream << me;
nome = filename + ".mtx";
EpetraExt::MultiVectorToMatrixMarketFile(nome.c_str(),
*M_epetraVector,
nome.c_str(),
desc.c_str(),
headers
);
}
void EpetraVector::spy( std::string const &filename ) const
{
// Purpose: Matlab dumping and spy
......@@ -447,6 +479,7 @@ void EpetraVector::spy( std::string const &filename ) const
EpetraExt::MultiVectorToMatlabFile(nome.c_str(), *M_epetraVector);
}
void EpetraVector::ShowMe( std::ostream& output ) const
{
EpetraVector redVec( *this, 0 ); // reduced vector (all at proc 0)
......
......@@ -213,6 +213,8 @@ public:
*
* To read the file in Matlab type load filename;
*/
void matrixMarket( std::string const &filename, const bool headers = true ) const;
void spy( std::string const &filename ) const;
void ShowMe( std::ostream& output = std::cout ) const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment