#include <iostream>
#include <vector>
+#include <cstring>
#include "MEDCouplingUMesh.hxx"
#include "Vector.hxx"
friend SparseMatrixPetsc operator*(const SparseMatrixPetsc& M, const SparseMatrixPetsc& N) ;
void viewMatrix() const ;
+ //Save matrix coefficients into a file in ascii or binary mode
+ void saveMatrix(std::string filename, bool binaryMode=false) const ;
double getMatrixCoeff(int i, int j) const;
bool containsPetscMatrix() const;
Mat getPetscMatrix() const;
+ //returns the array of matrix coefficients
+ std::vector< double > getArray();
void diagonalShift(double lambda);
void zeroEntries();//sets the matrix coefficients to zero
#include "SparseMatrixPetsc.hxx"
#include "CdmathException.hxx"
-#include <cstring>
-
using namespace std;
//----------------------------------------------------------------------
MatView(_mat,PETSC_VIEWER_STDOUT_SELF);
}
+
+void
+SparseMatrixPetsc::saveMatrix(string filename, bool binaryMode) const
+{
+ MatAssemblyBegin(_mat, MAT_FINAL_ASSEMBLY);
+ MatAssemblyEnd(_mat, MAT_FINAL_ASSEMBLY);
+
+ PetscViewer fileViewer;
+ PetscViewerCreate(PETSC_COMM_WORLD,&fileViewer);
+ PetscViewerFileSetMode(fileViewer,FILE_MODE_WRITE);
+ PetscViewerFileSetName(fileViewer,filename.c_str());
+
+ if( binaryMode)
+ {
+ PetscViewerSetType(fileViewer, PETSCVIEWERBINARY);
+ PetscViewerASCIIOpen(PETSC_COMM_WORLD, filename.c_str(), &fileViewer);
+ }
+ else
+ {
+ PetscViewerSetType(fileViewer, PETSCVIEWERASCII);
+ PetscViewerBinaryOpen(PETSC_COMM_WORLD, filename.c_str(), FILE_MODE_WRITE, &fileViewer);
+ }
+
+ MatView(_mat,fileViewer);
+}
+
double
SparseMatrixPetsc::getMatrixCoeff(int i, int j) const
{
return res;
}
+std::vector< double >
+SparseMatrixPetsc::getArray()
+{
+ int size=_numberOfRows*_numberOfColumns;
+
+ vector< double > result(size);
+ double* values = result.data();
+
+ int * idxm = new int[_numberOfRows];
+ int * idxn = new int[_numberOfColumns];
+ for (int i=0;i<_numberOfRows;i++)
+ idxm[i]=i;
+ for (int i=0;i<_numberOfColumns;i++)
+ idxn[i]=i;
+
+ MatAssemblyBegin(_mat, MAT_FINAL_ASSEMBLY);
+ MatAssemblyEnd(_mat, MAT_FINAL_ASSEMBLY);
+
+ MatGetValues(_mat,_numberOfRows, idxm,_numberOfColumns, idxn,values);
+
+ return result;
+}
+
void
SparseMatrixPetsc::diagonalShift(double lambda)
{