template <typename somenumber>
void precondition_SOR (Vector<somenumber> &dst,
const Vector<somenumber> &src,
- const number om = 1.) const;
+ const number om = 1.) const;
/**
* Perform SSOR preconditioning in-place.
* matrix elements which are explicitely
* set to zero are displayed as such.
*
- * Each entry is printed in scientific
- * format, with one pre-comma digit and
- * the number of digits given by
- * #precision# after the comma, with one
- * space following.
- * The precision defaults to four, which
- * suffices for most cases. The precision
- * and output format are {\it not}
- * properly reset to the old values
- * when the function exits.
+ * The parameters allow for a flexible setting of
+ * the output format: #precision# and #scientific#
+ * are used to determine the number format, where
+ * #scientific# = #false# means fixed point notation.
+ * A zero entry for #width# makes the function compute a
+ * width, but it may be changed to a positive value,
+ * if output is crude.
*
- * You should be aware that this function
+ * Additionally, a character for an empty value
+ * may be specified.
+ *
+ * This function
* may produce {\bf large} amounts of
* output if applied to a large matrix!
* Be careful with it.
*/
void print_formatted (ostream &out,
- const unsigned int presicion=3) const;
+ const unsigned int presicion=3,
+ bool scientific=true,
+ unsigned int width=0,
+ const char * zero_string = " ") const;
/**
* Exception
template <typename number>
-void SparseMatrix<number>::print_formatted (ostream &out, const unsigned int precision) const {
+void SparseMatrix<number>::print_formatted (ostream &out,
+ const unsigned int precision,
+ bool scientific,
+ unsigned int width,
+ const char* zero_string) const
+{
Assert (cols != 0, ExcMatrixNotInitialized());
Assert (val != 0, ExcMatrixNotInitialized());
+
out.precision (precision);
- out.setf (ios::scientific, ios::floatfield); // set output format
-
- for (unsigned int i=0; i<m(); ++i)
+ if (scientific)
+ {
+ out.setf (ios::scientific, ios::floatfield);
+ if (!width)
+ width = precision+7;
+ } else {
+ out.setf (ios::fixed, ios::floatfield);
+ if (!width)
+ width = precision+2;
+ }
+
+ for (unsigned int i=0; i<m(); ++i)
{
for (unsigned int j=0; j<n(); ++j)
if ((*cols)(i,j) != -1)
- out << setw(precision+7)
+ out << setw(width)
<< val[cols->operator()(i,j)] << ' ';
else
- out << setw(precision+8) << " ";
+ out << setw(width) << zero_string << ' ';
out << endl;
};
AssertThrow (out, ExcIO());
- out.setf (0, ios::floatfield); // reset output format
+// see above
+
+// out.setf (0, ios::floatfield); // reset output format
};
void print (const char* format = 0) const;
/**
- * Print to given stream, one element per line.
+ * Print to a stream.
+ *
*/
- void print (ostream &) const;
+ void print (ostream &, unsigned int precision = 3,
+ bool scientific = true,
+ bool across = true) const;
/**
* Write the vector en bloc to a file. This
template <typename Number>
-void Vector<Number>::print (ostream &out) const {
+void Vector<Number>::print (ostream &out,
+ unsigned int precision,
+ bool scientific,
+ bool across) const
+{
Assert (dim!=0, ExcEmptyVector());
- for (unsigned int i=0; i<size(); ++i)
- out << val[i] << endl;
+ out.precision (precision);
+ if (scientific)
+ {
+ out.setf (ios::scientific, ios::floatfield);
+ } else {
+ out.setf (ios::fixed, ios::floatfield);
+ }
+
+ if (across)
+ for (unsigned int i=0; i<size(); ++i)
+ out << val[i] << ' ';
+ else
+ for (unsigned int i=0; i<size(); ++i)
+ out << val[i] << endl;
+ out << endl;
+
AssertThrow (out, ExcIO());
};