From 9f77dce3da74e97f0cbc96eaffd7220ee3c5f31e Mon Sep 17 00:00:00 2001 From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be> Date: Wed, 17 Jul 2013 08:28:37 +0000 Subject: [PATCH] linearSystemPETSc::printMatlab --- Solver/linearSystemPETSc.cpp | 16 ++++++++++++++++ Solver/linearSystemPETSc.h | 1 + 2 files changed, 17 insertions(+) diff --git a/Solver/linearSystemPETSc.cpp b/Solver/linearSystemPETSc.cpp index dfd6069413..f1b0cd9402 100644 --- a/Solver/linearSystemPETSc.cpp +++ b/Solver/linearSystemPETSc.cpp @@ -341,4 +341,20 @@ double linearSystemPETScBlockDouble::normInfRightHandSide() const return nor; } +void linearSystemPETScBlockDouble::printMatlab(const char *filename) const +{ + _try(MatAssemblyBegin(_a, MAT_FINAL_ASSEMBLY)); + _try(MatAssemblyEnd(_a, MAT_FINAL_ASSEMBLY)); + _try(VecAssemblyBegin(_b)); + _try(VecAssemblyEnd(_b)); + + PetscViewer viewer; + PetscViewerASCIIOpen(PETSC_COMM_WORLD, filename, &viewer); + PetscViewerSetFormat(viewer,PETSC_VIEWER_ASCII_MATLAB); + printf("export mat to %s\n", filename); + MatView(_a, viewer); + PetscViewerDestroy(&viewer); + return; +} + #endif // HAVE_PETSC diff --git a/Solver/linearSystemPETSc.h b/Solver/linearSystemPETSc.h index 040b062a50..8dafd26108 100644 --- a/Solver/linearSystemPETSc.h +++ b/Solver/linearSystemPETSc.h @@ -105,6 +105,7 @@ class linearSystemPETScBlockDouble : public linearSystem<fullMatrix<double> > { public: void _kspCreate(); void print(); + void printMatlab(const char *filename) const; virtual void addToMatrix(int row, int col, const fullMatrix<double> &val); virtual void addToRightHandSide(int row, const fullMatrix<double> &val); virtual void addToSolution(int row, const fullMatrix<double> &val); -- GitLab