15#include "istlexception.hh"
54 int& counter,
int columns,
int width,
57 for (
typename V::ConstIterator i=v.begin(); i!=v.end(); ++i)
68 template<
class K,
int n>
70 std::string rowtext,
int& counter,
int columns,
71 int width,
int precision)
75 for (
int i=0; i<n; i++)
77 if (counter%columns==0)
88 if (counter%columns==0)
103 std::string rowtext,
int columns=1,
int width=10,
110 std::ios_base::fmtflags oldflags = s.flags();
113 s.setf(std::ios_base::scientific, std::ios_base::floatfield);
114 int oldprec = s.precision();
115 s.precision(precision);
118 s << title <<
" [blocks=" << v.N() <<
",dimension=" << v.dim() <<
"]"
125 if (counter%columns!=0)
130 s.precision(oldprec);
146 inline void fill_row (std::ostream& s,
int m,
int width,
int precision)
149 for (
int j=0; j<m; j++)
165 void print_row (std::ostream& s,
const M& A,
typename M::size_type I,
166 typename M::size_type J,
typename M::size_type therow,
167 int width,
int precision)
169 typename M::size_type i0=I;
170 for (
typename M::size_type i=0; i<A.
N(); i++)
172 if (therow>=i0 && therow<i0+MatrixDimension<M>::rowdim(A,i))
175 typename M::size_type j0=J;
176 for (
typename M::size_type j=0; j<A.
M(); j++)
179 typename M::ConstColIterator it = A[i].find(j);
183 print_row(s,*it,i0,j0,therow,width,precision);
185 fill_row(s,MatrixDimension<M>::coldim(A,j),width,precision);
188 j0 += MatrixDimension<M>::coldim(A,j);
192 i0 += MatrixDimension<M>::rowdim(A,i);
203 template<
class K,
int n,
int m>
205 typename FieldMatrix<K,n,m>::size_type I,
206 typename FieldMatrix<K,n,m>::size_type J,
207 typename FieldMatrix<K,n,m>::size_type therow,
int width,
213 typedef typename FieldMatrix<K,n,m>::size_type size_type;
215 for (size_type i=0; i<n; i++)
217 for (
int j=0; j<m; j++)
234 typename FieldMatrix<K,1,1>::size_type I,
235 typename FieldMatrix<K,1,1>::size_type J,
236 typename FieldMatrix<K,1,1>::size_type therow,
237 int width,
int precision)
246 s << static_cast<K>(A);
260 std::string rowtext,
int width=10,
int precision=2)
264 std::ios_base::fmtflags oldflags = s.flags();
267 s.setf(std::ios_base::scientific, std::ios_base::floatfield);
268 int oldprec = s.precision();
269 s.precision(precision);
275 <<
",rowdim=" << MatrixDimension<M>::rowdim(A)
276 <<
",coldim=" << MatrixDimension<M>::coldim(A)
280 for (
typename M::size_type i=0; i<MatrixDimension<M>::rowdim(A); i++)
292 s.precision(oldprec);
316 template<
class B,
int n,
int m,
class A>
319 std::string title, std::string rowtext,
320 int width=3,
int precision=2)
324 std::ios_base::fmtflags oldflags = s.flags();
326 s.setf(std::ios_base::scientific, std::ios_base::floatfield);
327 int oldprec = s.precision();
328 s.precision(precision);
333 <<
",rowdim=" << MatrixDimension<Matrix>::rowdim(mat)
334 <<
",coldim=" << MatrixDimension<Matrix>::coldim(mat)
339 for(Row row=mat.
begin(); row != mat.
end(); ++row) {
341 bool reachedEnd=
false;
344 for(
int innerrow=0; innerrow<n; ++innerrow) {
347 Col col=row->begin();
348 for(; col != row->end(); ++col,++count) {
351 if(count>=skipcols+width)
354 if(count==skipcols) {
358 s << row.index()<<
": ";
361 s<<col.index()<<
": |";
363 if(count==skipcols) {
364 for(
typename std::string::size_type i=0; i < rowtext.length(); i++)
370 for(
int innercol=0; innercol < m; ++innercol) {
372 s<<(*col)[innerrow][innercol]<<
" ";
377 if(innerrow==n-1 && col==row->end())
390 s.precision(oldprec);
396 struct MatlabPODWriter
398 static std::ostream& write(
const T& t, std::ostream& s)
405 struct MatlabPODWriter<
std::complex<T> >
407 static std::ostream& write(
const std::complex<T>& t, std::ostream& s)
409 s << t.real() <<
" " << t.imag();
424 template <
class FieldType,
int dim>
427 for (
int i=0; i<dim; i++)
430 s << rowOffset + i + 1 <<
" " << colOffset + i + 1 <<
" ";
431 MatlabPODWriter<FieldType>::write(matrix.
scalar(), s)<< std::endl;
444 template <
class FieldType,
int dim>
447 for (
int i=0; i<dim; i++)
450 s << rowOffset + i + 1 <<
" " << colOffset + i + 1 <<
" ";
451 MatlabPODWriter<FieldType>::write(matrix.
diagonal(i), s)<< std::endl;
464 template <
class FieldType,
int rows,
int cols>
467 int colOffset, std::ostream& s)
469 for (
int i=0; i<rows; i++)
470 for (
int j=0; j<cols; j++) {
472 s << rowOffset + i + 1 <<
" " << colOffset + j + 1 <<
" ";
473 MatlabPODWriter<FieldType>::write(matrix[i][j], s)<< std::endl;
486 template <
class FieldType>
488 int colOffset, std::ostream& s)
490 for (
int i=0; i<matrix.
N(); i++)
491 for (
int j=0; j<matrix.
M(); j++) {
493 s << rowOffset + i + 1 <<
" " << colOffset + j + 1 <<
" ";
494 MatlabPODWriter<FieldType>::write(matrix[i][j], s)<< std::endl;
505 template <
class MatrixType>
507 int externalRowOffset,
int externalColOffset,
511 std::vector<typename MatrixType::size_type> colOffset(matrix.M());
512 if (colOffset.size() > 0)
515 for (
typename MatrixType::size_type i=0; i<matrix.M()-1; i++)
516 colOffset[i+1] = colOffset[i] +
517 MatrixDimension<MatrixType>::coldim(matrix,i);
519 typename MatrixType::size_type rowOffset = 0;
522 for (
typename MatrixType::size_type rowIdx=0; rowIdx<matrix.N(); rowIdx++)
525 const typename MatrixType::row_type& row = matrix[rowIdx];
527 typename MatrixType::row_type::ConstIterator cIt = row.begin();
528 typename MatrixType::row_type::ConstIterator cEndIt = row.end();
531 for (; cIt!=cEndIt; ++cIt)
533 externalRowOffset+rowOffset,
534 externalColOffset + colOffset[cIt.index()],
537 rowOffset += MatrixDimension<MatrixType>::rowdim(matrix, rowIdx);
561 template <
class MatrixType>
563 const std::string& filename,
int outputPrecision = 18)
565 std::ofstream outStream(filename.c_str());
566 int oldPrecision = outStream.precision();
567 outStream.precision(outputPrecision);
570 outStream.precision(oldPrecision);
Implementation of the BCRSMatrix class.
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:413
size_type M() const
number of columns
Definition: densematrix.hh:689
size_type N() const
number of rows
Definition: densematrix.hh:683
A diagonal matrix of static size.
Definition: diagonalmatrix.hh:51
Construct a matrix with a dynamic size.
Definition: dynmatrix.hh:56
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.
This file implements a dense matrix with dynamic numbers of rows and columns.
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:511
void writeMatrixToMatlab(const MatrixType &matrix, const std::string &filename, int outputPrecision=18)
Writes sparse matrix in a Matlab-readable format.
Definition: io.hh:562
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:53
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:259
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:102
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:165
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:317
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:146
void writeMatrixToMatlabHelper(const ScaledIdentityMatrix< FieldType, dim > &matrix, int rowOffset, int colOffset, std::ostream &s)
Helper method for the writeMatrixToMatlab routine.
Definition: io.hh:425
A dynamic dense block matrix class.
Some handy generic functions for ISTL matrices.
Dune namespace.
Definition: alignment.hh:10
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