Skip to content
Snippets Groups Projects
Commit d0abc043 authored by Lisa Julia Nebel's avatar Lisa Julia Nebel
Browse files

Add printSparseMatrix method for ScaledIdentityMatrix

parent 497d5223
No related branches found
No related tags found
1 merge request!531Add printSparseMatrix method for ScaledIdentityMatrix
...@@ -267,13 +267,13 @@ namespace Dune { ...@@ -267,13 +267,13 @@ namespace Dune {
* @param width The number of nonzero blocks to print in one line. * @param width The number of nonzero blocks to print in one line.
* @param precision The precision to use when printing the numbers. * @param precision The precision to use when printing the numbers.
*/ */
template<class B, int n, int m, class A> template<class A, class InnerMatrixType>
void printSparseMatrix(std::ostream& s, void printSparseMatrix(std::ostream& s,
const BCRSMatrix<FieldMatrix<B,n,m>,A>& mat, const BCRSMatrix<InnerMatrixType,A>& mat,
std::string title, std::string rowtext, std::string title, std::string rowtext,
int width=3, int precision=2) int width=3, int precision=2)
{ {
typedef BCRSMatrix<FieldMatrix<B,n,m>,A> Matrix; typedef BCRSMatrix<InnerMatrixType,A> Matrix;
// remember old flags // remember old flags
std::ios_base::fmtflags oldflags = s.flags(); std::ios_base::fmtflags oldflags = s.flags();
// set the output format // set the output format
...@@ -290,6 +290,8 @@ namespace Dune { ...@@ -290,6 +290,8 @@ namespace Dune {
typedef typename Matrix::ConstRowIterator Row; typedef typename Matrix::ConstRowIterator Row;
int n = InnerMatrixType::rows;
int m = InnerMatrixType::cols;
for(Row row=mat.begin(); row != mat.end(); ++row) { for(Row row=mat.begin(); row != mat.end(); ++row) {
int skipcols=0; int skipcols=0;
bool reachedEnd=false; bool reachedEnd=false;
...@@ -323,7 +325,7 @@ namespace Dune { ...@@ -323,7 +325,7 @@ namespace Dune {
} }
for(int innercol=0; innercol < m; ++innercol) { for(int innercol=0; innercol < m; ++innercol) {
s.width(9); s.width(9);
s<<(*col)[innerrow][innercol]<<" "; printInnerMatrixElement(s,*col,innerrow,innercol);
} }
s<<"|"; s<<"|";
...@@ -344,6 +346,25 @@ namespace Dune { ...@@ -344,6 +346,25 @@ namespace Dune {
s.precision(oldprec); s.precision(oldprec);
} }
template<class B, int n>
void printInnerMatrixElement(std::ostream& s,
const ScaledIdentityMatrix<B,n> innerMatrixElement,
int innerrow, int innercol)
{
if (innerrow == innercol)
s<<innerMatrixElement.scalar()<<" ";
else
s<<"-";
}
template<class B, int n, int m, class A>
void printInnerMatrixElement(std::ostream& s,
const FieldMatrix<B,n,m> innerMatrixElement,
int innerrow, int innercol)
{
s<<innerMatrixElement[innerrow][innercol]<<" ";
}
namespace namespace
{ {
template<typename T> template<typename T>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment