From: Guido Kanschat Date: Tue, 9 Jan 2001 12:52:21 +0000 (+0000) Subject: new FullMatrix constructor X-Git-Tag: v8.0.0~19842 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=506062a4d1310c365de652cd692d68f66603c02b;p=dealii.git new FullMatrix constructor git-svn-id: https://svn.dealii.org/trunk@3621 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/full_matrix.h b/deal.II/lac/include/lac/full_matrix.h index 63d46318f9..420a09e6cf 100644 --- a/deal.II/lac/include/lac/full_matrix.h +++ b/deal.II/lac/include/lac/full_matrix.h @@ -56,7 +56,7 @@ template class Vector; * corresponding ``.templates.h'' file and instantiate the respective * class yourself. * - * @author Guido Kanschat, Franz-Theo Suttmeier, Wolfgang Bangerth + * @author Guido Kanschat, Franz-Theo Suttmeier, Wolfgang Bangerth, 1993-2001 */ template class FullMatrix : public Subscriptor @@ -82,13 +82,23 @@ class FullMatrix : public Subscriptor FullMatrix (const unsigned int rows, const unsigned int cols); /** - * Copy constructor. Be very careful with - * this constructor, since it may take a - * huge amount of computing time for large - * matrices!! + * Copy constructor. This constructor does + * a deep copy of the matrix. Therefore, + * it poses an efficiency problem. */ FullMatrix (const FullMatrix&); + /** + * Constructor initializing from + * an array of numbers. The array + * is arranged line by line. No + * range checking is performed. + */ + FullMatrix (const unsigned int rows, + const unsigned int cols, + const number* entries); + + /** * Destructor. Release all memory. */ @@ -537,30 +547,50 @@ class FullMatrix : public Subscriptor void print (ostream& s, int width=5, int precision=2) const; /** - * Print the matrix in the usual format, - * i.e. as a matrix and not as a list of - * nonzero elements. For better - * readability, zero elements - * are displayed as empty space. + * Print the matrix in the usual + * format, i.e. as a matrix and + * not as a list of nonzero + * elements. For better + * readability, elements not in + * the matrix are displayed as + * empty space, while matrix + * elements which are explicitely + * set to zero are displayed as + * such. + * + * The parameters allow for a + * flexible setting of the output + * format: @p{precision} and + * @p{scientific} are used to + * determine the number format, + * where @p{scientific} = @p{false} + * means fixed point notation. A + * zero entry for @p{width} makes + * the function compute a width, + * but it may be changed to a + * positive value, if output is + * crude. + * + * Additionally, a character for + * an empty value may be + * specified. * - * Each entry is printed in scientific - * format, with one pre-comma digit and - * the number of digits given by - * @p{precision} after the comma, with one - * space following. - * The precision defaults to four, which - * suffices for most cases. The precision - * and output format are @em{not} - * properly reset to the old values - * when the function exits. + * Finally, the whole matrix can + * be multiplied with a common + * denominator to produce more + * readable output, even + * integers. * - * You should be aware that this function + * This function * may produce @em{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, + const bool scientific = true, + const unsigned int width = 0, + const char *zero_string = " ", + const double denominator = 1.) const; /** * Determine an estimate for the diff --git a/deal.II/lac/include/lac/full_matrix.templates.h b/deal.II/lac/include/lac/full_matrix.templates.h index c819b10efb..f8b44da4cf 100644 --- a/deal.II/lac/include/lac/full_matrix.templates.h +++ b/deal.II/lac/include/lac/full_matrix.templates.h @@ -47,6 +47,22 @@ FullMatrix::FullMatrix (const unsigned int m, }; +template +FullMatrix::FullMatrix (const unsigned int m, + const unsigned int n, + const number* entries) : + val (0), + dim_range (0), + dim_image (0), + val_size (0) +{ + reinit (m,n); + + if (dim_range*dim_image != 0) + copy (entries, entries+dim_image*dim_range, val); +}; + + template FullMatrix::FullMatrix (const FullMatrix &m) : Subscriptor (), @@ -1304,26 +1320,41 @@ FullMatrix::invert (const FullMatrix &M) template void -FullMatrix::print_formatted (ostream &out, const unsigned int precision) const +FullMatrix::print_formatted (ostream &out, + const unsigned int precision, + bool scientific, + unsigned int width, + const char* zero_string, + const double denominator) const { Assert (val != 0, ExcEmptyMatrix()); - out.precision (precision); - out.setf (ios::scientific, ios::floatfield); // set output format + unsigned int old_precision = out.precision (precision); + 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 #include +const double entries[9] = { 11,12,13,21,22,23,31,32,33 }; + // Create a positive definite random matrix void random_matrix(FullMatrix& A) @@ -44,6 +46,9 @@ main () deallog.attach(logfile); deallog.depth_console(0); srand(3391466); + + FullMatrix T(3,3,entries); + T.print_formatted(logfile, 0, false); for (unsigned int i=1;i<10;++i) { @@ -108,7 +113,7 @@ main () Vector u(5); GrowingVectorMemory > mem; - SolverControl control (500,1.e-8, false, true); + SolverControl control (500,1.e-8, false, false); if (true) { diff --git a/tests/lac/full_matrix.checked b/tests/lac/full_matrix.checked index 483c83127f..fb98d7685a 100644 --- a/tests/lac/full_matrix.checked +++ b/tests/lac/full_matrix.checked @@ -1,4 +1,7 @@ +11. 12. 13. +21. 22. 23. +31. 32. 33. DEAL::Inverse(dim=1): DEAL::Inverse(dim=2): DEAL::Inverse(dim=3): @@ -65,22 +68,14 @@ DEAL::Frobenius-norm: 2.24 4.093e-01 6.399e-01 1.636e+00 2.203e-01 -2.551e-01 -3.813e-02 -5.962e-02 2.203e-01 4.552e+00 5.184e-01 4.415e-02 6.903e-02 -2.551e-01 5.184e-01 4.400e+00 -DEAL:Power method::Starting -DEAL:Power method::Convergence step 21 DEAL::Eigen -DEAL:Power method::Starting -DEAL:Power method::Convergence step 27 DEAL::Eigen 6.460e-01 9.460e-02 -2.046e-01 1.907e-02 -2.208e-02 9.460e-02 4.235e-01 -1.951e-01 1.817e-02 -2.104e-02 -2.046e-01 -1.951e-01 7.536e-01 -4.693e-02 5.433e-02 1.907e-02 1.817e-02 -4.693e-02 2.257e-01 -2.980e-02 -2.208e-02 -2.104e-02 5.433e-02 -2.980e-02 2.345e-01 -DEAL:Power method::Starting -DEAL:Power method::Convergence step 17 DEAL::Eigen -DEAL:Power method::Starting -DEAL:Power method::Convergence step 177 DEAL::Eigen DEAL::GrowingVectorMemory:Overall allocated vectors: 8 DEAL::GrowingVectorMemory:Maximum allocated vectors: 2