]> https://gitweb.dealii.org/ - dealii.git/commitdiff
new FullMatrix constructor
authorGuido Kanschat <dr.guido.kanschat@gmail.com>
Tue, 9 Jan 2001 12:52:21 +0000 (12:52 +0000)
committerGuido Kanschat <dr.guido.kanschat@gmail.com>
Tue, 9 Jan 2001 12:52:21 +0000 (12:52 +0000)
git-svn-id: https://svn.dealii.org/trunk@3621 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/full_matrix.h
deal.II/lac/include/lac/full_matrix.templates.h
tests/lac/full_matrix.cc
tests/lac/full_matrix.checked

index 63d46318f9e3ed40591133529046b9d47e76fe67..420a09e6cfe970cdd74794c74ef952379192cecd 100644 (file)
@@ -56,7 +56,7 @@ template<typename number> 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<typename number>
 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
index c819b10efb1af4d8da0a71f5ac8db940b4b61e8e..f8b44da4cf2170d1a8ebb1a84a2723f0dd449db3 100644 (file)
@@ -47,6 +47,22 @@ FullMatrix<number>::FullMatrix (const unsigned int m,
 };
 
 
+template <typename number>
+FullMatrix<number>::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 <typename number>
 FullMatrix<number>::FullMatrix (const FullMatrix &m) :
                Subscriptor (),
@@ -1304,26 +1320,41 @@ FullMatrix<number>::invert (const FullMatrix<number> &M)
 
 template <typename number>
 void
-FullMatrix<number>::print_formatted (ostream &out, const unsigned int precision) const
+FullMatrix<number>::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<m(); ++i) 
     {
       for (unsigned int j=0; j<n(); ++j)
        if (el(i,j) != 0)
-         out << setw(precision+7)
-             << el(i,j) << ' ';
+         out << setw(width)
+             << el(i,j) * denominator << ' ';
        else
-         out << setw(precision+8) << " ";
+         out << setw(width) << zero_string << ' ';
       out << endl;
     };
 
   AssertThrow (out, ExcIO());
-  
+
+  out.precision(old_precision);
   out.setf (0, ios::floatfield);                 // reset output format
 };
 
index ab77c1752c70c68408fdc79662b5708dfc7cc590..a4a6b063ed7037bf4cd422c56824aee4d19f7876 100644 (file)
@@ -22,6 +22,8 @@
 #include <lac/full_matrix.h>
 #include <lac/eigen.h>
 
+const double entries[9] = { 11,12,13,21,22,23,31,32,33 };
+
 // Create a positive definite random matrix
 
 void random_matrix(FullMatrix<double>& A)
@@ -44,6 +46,9 @@ main ()
   deallog.attach(logfile);
   deallog.depth_console(0);
   srand(3391466);
+
+  FullMatrix<double> T(3,3,entries);
+  T.print_formatted(logfile, 0, false);
   
   for (unsigned int i=1;i<10;++i)
     {
@@ -108,7 +113,7 @@ main ()
       Vector<double> u(5);
       GrowingVectorMemory<Vector<double> > mem;
       
-      SolverControl control (500,1.e-8, false, true);
+      SolverControl control (500,1.e-8, false, false);
       
       if (true)
        {
index 483c83127fa5cfabb66bd80041a3fe632ef5d248..fb98d7685a77a4d48a20837bdbecdb6f71f37c0a 100644 (file)
@@ -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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.