]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
new function BlockVector::collect_sizes
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 17 Sep 2002 21:43:12 +0000 (21:43 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 17 Sep 2002 21:43:12 +0000 (21:43 +0000)
git-svn-id: https://svn.dealii.org/trunk@6447 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/2002/c-3-4.html
deal.II/lac/include/lac/block_vector.h
deal.II/lac/include/lac/block_vector.templates.h
tests/lac/block_vector.cc
tests/lac/block_vector.checked

index 0c665b7ea068b7452c4d10363dc02d5c7e11c0cf..c85c2133730ce9169ab1ec560bb8338f335e526e 100644 (file)
@@ -234,6 +234,14 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK
 <h3>lac</h3>
 
 <ol>
+  <li> <p> New: class <code class="class">BlockVector</code> has a
+  function <code class="member">collect_sizes()</code>, very much as
+  <code class="class">BlockSparsityPattern</code>. This allows
+  updating internal structures after blocks have been resized.
+  <br>
+  (GK 2002/09/17)
+  </p>
+
   <li> <p> New: class <code class="class">SparseMatrix</code> has an
   STL-conforming <code class="class">const_iterator</code> and
   functions <code class="member">begin()</code> and <code
index 4bb894ce272f6a389f3b7b498ff1be96941ed2e6..b95b654ad3c09b7283ff87e35e3ccc443aed0621 100644 (file)
@@ -845,6 +845,19 @@ class BlockVector
                                      * STL's @p{vector<>::clear} function.
                                      */
     void clear ();
+
+                                    /**
+                                     * Update internal structures
+                                     * after resizing
+                                     * vectors. Whenever you reinited
+                                     * a block of a block vector, the
+                                     * internal data structures are
+                                     * corrupted. Therefore, you
+                                     * should call this function
+                                     * after al blocks got their new
+                                     * size.
+                                     */
+    void collect_sizes ();
     
                                     /**
                                      * Swap the contents of this
index 15762fcbc500487db042b53654317dec35b05c28..930c93e33b828f7808a4e3d4079fd8a481be9cf2 100644 (file)
@@ -110,6 +110,18 @@ void BlockVector<Number>::reinit (const BlockVector<Number2>& v,
 }
 
 
+template <typename Number>
+void
+BlockVector<Number>::collect_sizes ()
+{
+  std::vector<unsigned int> sizes (num_blocks);
+
+  for (unsigned int i=0; i<num_blocks; ++i)
+    sizes[i] = block(i).size();
+
+  block_indices.reinit(sizes);
+}
+
 
 template <typename Number>
 BlockVector<Number>::~BlockVector ()
index 24930da8a130eb9c4eba6c6a943d97d96cd4e62e..4cf975302722510cc22a0ebc5df2f567320ddcfe 100644 (file)
@@ -30,6 +30,8 @@ void test ()
   ivector[1] = 0;
   ivector[2] = 1;
   ivector[3] = 2;
+
+  const std::vector<unsigned int> vector_indices(ivector);
   
   BlockIndices i1(ivector);
   BlockIndices i2 = i1;
@@ -46,26 +48,6 @@ void test ()
   deallog.pop();
 
 
-                                  // initialization by an iterator
-                                  // range
-  deallog.push ("Initialization from iterators");
-  double array[] = { 0, 1, 2, 3, 4, 5 };
-  BlockVector<double> v1(ivector, &array[0], &array[6]);
-  for (unsigned int i=0; i<v1.size(); ++i)
-    deallog << v1(i) << ' ';
-  deallog << std::endl;
-
-                                  // same test, but do not initialize
-                                  // from double*'s, but from
-                                  // std::list iterators.
-  std::list<double> l(&array[0], &array[6]);
-  BlockVector<double> v2(ivector, l.begin(), l.end());
-  for (unsigned int i=0; i<v2.size(); ++i)
-    deallog << v2(i) << ' ';
-  deallog << std::endl;
-  deallog.pop ();
-
-  
   i3.reinit(ivector);
 
   deallog.push("global->local");
@@ -129,6 +111,37 @@ void test ()
   unsigned int i = i1.global_to_local(3).first;
   i = i1.local_to_global(1,2);
   i = i1.local_to_global(2,0);
+
+  deallog.pop ();
+  deallog.push("BlockVector");
+                                  // initialization by an iterator
+                                  // range
+  deallog.push ("Constructor with iterators");
+  double array[] = { 0, 1, 2, 3, 4, 5 };
+  BlockVector<double> v1(vector_indices, &array[0], &array[6]);
+  for (unsigned int i=0; i<v1.size(); ++i)
+    deallog << v1(i) << ' ';
+  deallog << std::endl;
+
+                                  // same test, but do not initialize
+                                  // from double*'s, but from
+                                  // std::list iterators.
+  std::list<double> l(&array[0], &array[6]);
+  BlockVector<double> v2(vector_indices, l.begin(), l.end());
+  for (unsigned int i=0; i<v2.n_blocks(); ++i)
+    for (unsigned int j=0;j<v2.block(i).size();++j)
+      deallog << i << '\t' << j << '\t' <<v2.block(i)(j) << std::endl;
+
+  deallog.pop();
+  deallog.push("reinit block");
+  v2.block(1).reinit(5);
+  v2.collect_sizes();
+  for (unsigned int i=0; i<v2.size(); ++i)
+    deallog << v2(i) << ' ';
+  deallog << std::endl;
+  
+  deallog.pop ();
+  deallog.pop ();
 }
 
 
index f5591429860811a9d7ac2814d8d5e3b571a7d04f..4c539d6666784aadf294b446ecfa36f19f2e5e42 100644 (file)
@@ -1,6 +1,4 @@
 
-DEAL:BlockIndices:Initialization from iterators::0.000 1.000 2.000 3.000 4.000 5.000 
-DEAL:BlockIndices:Initialization from iterators::0.000 1.000 2.000 3.000 4.000 5.000 
 DEAL:BlockIndices:global->local::0     0       0       0       0       0       0
 DEAL:BlockIndices:global->local::1     0       1       0       1       0       1
 DEAL:BlockIndices:global->local::2     0       2       0       2       0       2
@@ -40,3 +38,11 @@ Additional Information:
 Index 3 is not in [0,3[
 --------------------------------------------------------
 ******** More assertions fail but messages are suppressed! ********
+DEAL:BlockVector:Constructor with iterators::0.000 1.000 2.000 3.000 4.000 5.000 
+DEAL:BlockVector:Constructor with iterators::0 0       0.000
+DEAL:BlockVector:Constructor with iterators::0 1       1.000
+DEAL:BlockVector:Constructor with iterators::0 2       2.000
+DEAL:BlockVector:Constructor with iterators::2 0       3.000
+DEAL:BlockVector:Constructor with iterators::3 0       4.000
+DEAL:BlockVector:Constructor with iterators::3 1       5.000
+DEAL:BlockVector:reinit block::0.000 1.000 2.000 0.000 0.000 0.000 0.000 0.000 3.000 4.000 5.000 

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.