15#include "istlexception.hh"
53 int& counter,
int columns,
int width,
56 for (
typename V::ConstIterator i=v.begin(); i!=v.end(); ++i)
67 template<
class K,
int n>
69 std::string rowtext,
int& counter,
int columns,
70 int width,
int precision)
74 for (
int i=0; i<n; i++)
76 if (counter%columns==0)
87 if (counter%columns==0)
102 std::string rowtext,
int columns=1,
int width=10,
109 std::ios_base::fmtflags oldflags = s.flags();
112 s.setf(std::ios_base::scientific, std::ios_base::floatfield);
113 int oldprec = s.precision();
114 s.precision(precision);
117 s << title <<
" [blocks=" << v.N() <<
",dimension=" << v.dim() <<
"]"
124 if (counter%columns!=0)
129 s.precision(oldprec);
145 inline void fill_row (std::ostream& s,
int m,
int width,
int precision)
148 for (
int j=0; j<m; j++)
164 void print_row (std::ostream& s,
const M& A,
typename M::size_type I,
165 typename M::size_type J,
typename M::size_type therow,
166 int width,
int precision)
168 typename M::size_type i0=I;
169 for (
typename M::size_type i=0; i<A.
N(); i++)
171 if (therow>=i0 && therow<i0+MatrixDimension<M>::rowdim(A,i))
174 typename M::size_type j0=J;
175 for (
typename M::size_type j=0; j<A.
M(); j++)
178 typename M::ConstColIterator it = A[i].find(j);
182 print_row(s,*it,i0,j0,therow,width,precision);
184 fill_row(s,MatrixDimension<M>::coldim(A,j),width,precision);
187 j0 += MatrixDimension<M>::coldim(A,j);
191 i0 += MatrixDimension<M>::rowdim(A,i);
202 template<
class K,
int n,
int m>
204 typename FieldMatrix<K,n,m>::size_type I,
205 typename FieldMatrix<K,n,m>::size_type J,
206 typename FieldMatrix<K,n,m>::size_type therow,
int width,
212 typedef typename FieldMatrix<K,n,m>::size_type size_type;
214 for (size_type i=0; i<n; i++)
216 for (
int j=0; j<m; j++)
233 typename FieldMatrix<K,1,1>::size_type I,
234 typename FieldMatrix<K,1,1>::size_type J,
235 typename FieldMatrix<K,1,1>::size_type therow,
236 int width,
int precision)
245 s << static_cast<K>(A);
259 std::string rowtext,
int width=10,
int precision=2)
263 std::ios_base::fmtflags oldflags = s.flags();
266 s.setf(std::ios_base::scientific, std::ios_base::floatfield);
267 int oldprec = s.precision();
268 s.precision(precision);
274 <<
",rowdim=" << MatrixDimension<M>::rowdim(A)
275 <<
",coldim=" << MatrixDimension<M>::coldim(A)
279 for (
typename M::size_type i=0; i<MatrixDimension<M>::rowdim(A); i++)
291 s.precision(oldprec);
315 template<
class B,
int n,
int m,
class A>
318 std::string title, std::string rowtext,
319 int width=3,
int precision=2)
323 std::ios_base::fmtflags oldflags = s.flags();
325 s.setf(std::ios_base::scientific, std::ios_base::floatfield);
326 int oldprec = s.precision();
327 s.precision(precision);
332 <<
",rowdim=" << MatrixDimension<Matrix>::rowdim(mat)
333 <<
",coldim=" << MatrixDimension<Matrix>::coldim(mat)
338 for(Row row=mat.
begin(); row != mat.
end(); ++row) {
340 bool reachedEnd=
false;
343 for(
int innerrow=0; innerrow<n; ++innerrow) {
346 Col col=row->begin();
347 for(; col != row->end(); ++col,++count) {
350 if(count>=skipcols+width)
353 if(count==skipcols) {
357 s << row.index()<<
": ";
360 s<<col.index()<<
": |";
362 if(count==skipcols) {
363 for(
typename std::string::size_type i=0; i < rowtext.length(); i++)
369 for(
int innercol=0; innercol < m; ++innercol) {
371 s<<(*col)[innerrow][innercol]<<
" ";
376 if(innerrow==n-1 && col==row->end())
389 s.precision(oldprec);
395 struct MatlabPODWriter
397 static std::ostream& write(
const T& t, std::ostream& s)
404 struct MatlabPODWriter<
std::complex<T> >
406 static std::ostream& write(
const std::complex<T>& t, std::ostream& s)
408 s << t.real() <<
" " << t.imag();
423 template <
class FieldType,
int dim>
426 for (
int i=0; i<dim; i++)
429 s << rowOffset + i + 1 <<
" " << colOffset + i + 1 <<
" ";
430 MatlabPODWriter<FieldType>::write(matrix.
scalar(), s)<< std::endl;
443 template <
class FieldType,
int dim>
446 for (
int i=0; i<dim; i++)
449 s << rowOffset + i + 1 <<
" " << colOffset + i + 1 <<
" ";
450 MatlabPODWriter<FieldType>::write(matrix.
diagonal(i), s)<< std::endl;
463 template <
class FieldType,
int rows,
int cols>
466 int colOffset, std::ostream& s)
468 for (
int i=0; i<rows; i++)
469 for (
int j=0; j<cols; j++) {
471 s << rowOffset + i + 1 <<
" " << colOffset + j + 1 <<
" ";
472 MatlabPODWriter<FieldType>::write(matrix[i][j], s)<< std::endl;
483 template <
class MatrixType>
485 int externalRowOffset,
int externalColOffset,
489 std::vector<typename MatrixType::size_type> colOffset(matrix.M());
490 if (colOffset.size() > 0)
493 for (
typename MatrixType::size_type i=0; i<matrix.M()-1; i++)
494 colOffset[i+1] = colOffset[i] +
495 MatrixDimension<MatrixType>::coldim(matrix,i);
497 typename MatrixType::size_type rowOffset = 0;
500 for (
typename MatrixType::size_type rowIdx=0; rowIdx<matrix.N(); rowIdx++)
503 const typename MatrixType::row_type& row = matrix[rowIdx];
505 typename MatrixType::row_type::ConstIterator cIt = row.begin();
506 typename MatrixType::row_type::ConstIterator cEndIt = row.end();
509 for (; cIt!=cEndIt; ++cIt)
511 externalRowOffset+rowOffset,
512 externalColOffset + colOffset[cIt.index()],
515 rowOffset += MatrixDimension<MatrixType>::rowdim(matrix, rowIdx);
539 template <
class MatrixType>
541 const std::string& filename,
int outputPrecision = 18)
543 std::ofstream outStream(filename.c_str());
544 int oldPrecision = outStream.precision();
545 outStream.precision(outputPrecision);
548 outStream.precision(oldPrecision);
Implementation of the BCRSMatrix class.
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:414
A diagonal matrix of static size.
Definition: diagonalmatrix.hh:49
A dense n x m matrix.
Definition: fmatrix.hh:67
A generic dynamic dense matrix.
Definition: matrix.hh:25
RowIterator end()
Get iterator to one beyond last row.
Definition: matrix.hh:85
RowIterator begin()
Get iterator to first row.
Definition: matrix.hh:79
row_type::const_iterator ConstColIterator
Const iterator for the entries of each row.
Definition: matrix.hh:53
size_type M() const
Return the number of columns.
Definition: matrix.hh:165
size_type N() const
Return the number of rows.
Definition: matrix.hh:160
A multiple of the identity matrix of static size.
Definition: scaledidmatrix.hh:28
const K & scalar() const
Get const reference to the scalar diagonal value.
Definition: scaledidmatrix.hh:459
ConstIterator class for sequential access.
Definition: vbvector.hh:647
This file implements a quadratic diagonal matrix of fixed size.
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
const K & diagonal(size_type i) const
Get const reference to diagonal entry.
Definition: diagonalmatrix.hh:495
void writeMatrixToMatlab(const MatrixType &matrix, const std::string &filename, int outputPrecision=18)
Writes sparse matrix in a Matlab-readable format.
Definition: io.hh:540
void recursive_printvector(std::ostream &s, const V &v, std::string rowtext, int &counter, int columns, int width, int precision)
Recursively print all the blocks.
Definition: io.hh:52
void printmatrix(std::ostream &s, const M &A, std::string title, std::string rowtext, int width=10, int precision=2)
Print a generic block matrix.
Definition: io.hh:258
void printvector(std::ostream &s, const V &v, std::string title, std::string rowtext, int columns=1, int width=10, int precision=2)
Print an ISTL vector.
Definition: io.hh:101
void print_row(std::ostream &s, const M &A, typename M::size_type I, typename M::size_type J, typename M::size_type therow, int width, int precision)
Print one row of a matrix.
Definition: io.hh:164
void printSparseMatrix(std::ostream &s, const BCRSMatrix< FieldMatrix< B, n, m >, A > &mat, std::string title, std::string rowtext, int width=3, int precision=2)
Prints a BCRSMatrix with fixed sized blocks.
Definition: io.hh:316
void fill_row(std::ostream &s, int m, int width, int precision)
Print a row of zeros for a non-existing block.
Definition: io.hh:145
void writeMatrixToMatlabHelper(const ScaledIdentityMatrix< FieldType, dim > &matrix, int rowOffset, int colOffset, std::ostream &s)
Helper method for the writeMatrixToMatlab routine.
Definition: io.hh:424
A dynamic dense block matrix class.
Some handy generic functions for ISTL matrices.
Dune namespace.
Definition: alignment.hh:14
This file implements a quadratic matrix of fixed size which is a multiple of the identity.
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18