16 #include <dune/common/fvector.hh>
17 #include <dune/common/fmatrix.hh>
49 int& counter,
int columns,
int width,
52 for (
typename V::ConstIterator i=v.begin(); i!=v.end(); ++i)
62 template<
class K,
int n>
64 std::string rowtext,
int& counter,
int columns,
65 int width,
int precision)
68 for (
int i=0; i<n; i++)
70 if (counter%columns==0)
81 if (counter%columns==0)
94 void printvector (std::ostream& s,
const V& v, std::string title,
95 std::string rowtext,
int columns=1,
int width=10,
102 std::ios_base::fmtflags oldflags = s.flags();
105 s.setf(std::ios_base::scientific, std::ios_base::floatfield);
106 int oldprec = s.precision();
107 s.precision(precision);
110 s << title <<
" [blocks=" << v.N() <<
",dimension=" << v.dim() <<
"]"
117 if (counter%columns!=0)
122 s.precision(oldprec);
137 inline void fill_row (std::ostream& s,
int m,
int width,
int precision)
139 for (
int j=0; j<m; j++)
154 void print_row (std::ostream& s,
const M&
A,
typename M::size_type I,
155 typename M::size_type J,
typename M::size_type therow,
156 int width,
int precision)
158 typename M::size_type i0=I;
159 for (
typename M::size_type i=0; i<A.N(); i++)
164 typename M::size_type j0=J;
165 for (
typename M::size_type j=0; j<A.M(); j++)
168 typename M::ConstColIterator it = A[i].find(j);
172 print_row(s,*it,i0,j0,therow,width,precision);
191 template<
class K,
int n,
int m>
192 void print_row (std::ostream& s,
const FieldMatrix<K,n,m>&
A,
193 typename FieldMatrix<K,n,m>::size_type I,
194 typename FieldMatrix<K,n,m>::size_type J,
195 typename FieldMatrix<K,n,m>::size_type therow,
int width,
198 typedef typename FieldMatrix<K,n,m>::size_type size_type;
200 for (size_type i=0; i<n; i++)
202 for (
int j=0; j<m; j++)
217 void print_row (std::ostream& s,
const FieldMatrix<K,1,1>&
A,
218 typename FieldMatrix<K,1,1>::size_type I,
219 typename FieldMatrix<K,1,1>::size_type J,
220 typename FieldMatrix<K,1,1>::size_type therow,
221 int width,
int precision)
227 s << static_cast<K>(
A);
240 std::string rowtext,
int width=10,
int precision=2)
244 std::ios_base::fmtflags oldflags = s.flags();
247 s.setf(std::ios_base::scientific, std::ios_base::floatfield);
248 int oldprec = s.precision();
249 s.precision(precision);
260 for (
typename M::size_type i=0; i<MatrixDimension<M>::rowdim(A); i++)
272 s.precision(oldprec);
295 template<
class B,
int n,
int m,
class A>
298 std::string title, std::string rowtext,
299 int width=3,
int precision=2)
303 std::ios_base::fmtflags oldflags = s.flags();
305 s.setf(std::ios_base::scientific, std::ios_base::floatfield);
306 int oldprec = s.precision();
307 s.precision(precision);
320 bool reachedEnd=
false;
323 for(
int innerrow=0; innerrow<n; ++innerrow) {
330 if(count>=skipcols+width)
333 if(count==skipcols) {
337 s <<
row.index()<<
": ";
340 s<<col.index()<<
": |";
343 for(
typename std::string::size_type i=0; i < rowtext.length(); i++)
349 for(
int innercol=0; innercol < m; ++innercol) {
351 s<<(*col)[innerrow][innercol]<<
" ";
356 if(innerrow==n-1 && col==
row->end())
369 s.precision(oldprec);
375 struct MatlabPODWriter
377 static std::ostream& write(
const T& t, std::ostream& s)
384 struct MatlabPODWriter<std::complex<T> >
386 static std::ostream& write(
const std::complex<T>& t, std::ostream& s)
388 s << t.real() <<
" " << t.imag();
402 template <
class FieldType,
int rows,
int cols>
404 (
const FieldMatrix<FieldType,rows,cols>& matrix,
int rowOffset,
405 int colOffset, std::ostream& s)
407 for (
int i=0; i<rows; i++)
408 for (
int j=0; j<cols; j++){
410 s << rowOffset + i + 1 <<
" " << colOffset + j + 1 <<
" ";
411 MatlabPODWriter<FieldType>::write(matrix[i][j], s)<< std::endl;
421 template <
class MatrixType>
423 int externalRowOffset,
int externalColOffset,
427 std::vector<typename MatrixType::size_type> colOffset(matrix.M());
428 if (colOffset.size() > 0)
431 for (
typename MatrixType::size_type i=0; i<matrix.M()-1; i++)
432 colOffset[i+1] = colOffset[i] +
435 typename MatrixType::size_type rowOffset = 0;
438 for (
typename MatrixType::size_type rowIdx=0; rowIdx<matrix.N(); rowIdx++)
441 const typename MatrixType::row_type&
row = matrix[rowIdx];
443 typename MatrixType::row_type::ConstIterator cIt = row.begin();
444 typename MatrixType::row_type::ConstIterator cEndIt = row.end();
447 for (; cIt!=cEndIt; ++cIt)
449 externalRowOffset+rowOffset,
450 externalColOffset + colOffset[cIt.index()],
476 template <
class MatrixType>
478 const std::string& filename,
int outputPrecision = 18)
480 std::ofstream outStream(filename.c_str());
481 int oldPrecision = outStream.precision();
482 outStream.precision(outputPrecision);
485 outStream.precision(oldPrecision);