]> https://gitweb.dealii.org/ - dealii.git/commitdiff
new test for BlockSmoother
authorGuido Kanschat <dr.guido.kanschat@gmail.com>
Sat, 3 Dec 2005 17:27:26 +0000 (17:27 +0000)
committerGuido Kanschat <dr.guido.kanschat@gmail.com>
Sat, 3 Dec 2005 17:27:26 +0000 (17:27 +0000)
git-svn-id: https://svn.dealii.org/trunk@11807 0785d39b-7218-0410-832d-ea1e28bc413d

tests/multigrid/Makefile
tests/multigrid/smoother_block.cc [new file with mode: 0644]
tests/multigrid/smoother_block/cmp/generic [new file with mode: 0644]

index 8f69a242dc060222815ebca3c8cd63b5c3a5a228..e779f2cb6070aad53537de0825bc2d0b7142b5c1 100644 (file)
@@ -21,7 +21,8 @@ default: run-tests
 
 ############################################################
 
-tests_x = cycles transfer transfer_select transfer_block
+tests_x = cycles transfer transfer_select transfer_block \
+       smoother_block
 
 # from above list of regular expressions, generate the real set of
 # tests
diff --git a/tests/multigrid/smoother_block.cc b/tests/multigrid/smoother_block.cc
new file mode 100644 (file)
index 0000000..b18df2f
--- /dev/null
@@ -0,0 +1,216 @@
+//----------------------------------------------------------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2000 - 2005 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------------------------------------------------------
+
+
+#include <base/logstream.h>
+#include <lac/vector.h>
+#include <lac/block_vector.h>
+#include <lac/block_matrix_array.h>
+#include <multigrid/mg_level_object.h>
+#include <multigrid/mg_block_smoother.h>
+#include <fstream>
+#include <iostream>
+#include <iomanip>
+#include <algorithm>
+
+using namespace std;
+
+template <typename number>
+class ScalingMatrix : public Subscriptor
+{
+  public:
+                                    /**
+                                     * Constructor setting the
+                                     * scaling factor. Default is
+                                     * constructing the identity
+                                     * matrix.
+                                     */
+    ScalingMatrix(number scaling_factor = 1.);
+                                    /**
+                                     * Apply preconditioner.
+                                     */
+    template<class VECTOR>
+    void vmult (VECTOR&, const VECTOR&) const;
+
+                                    /**
+                                     * Apply transpose
+                                     * preconditioner. Since this is
+                                     * the identity, this function is
+                                     * the same as
+                                     * vmult().
+                                     */
+    template<class VECTOR>
+    void Tvmult (VECTOR&, const VECTOR&) const;
+                                    /**
+                                     * Apply preconditioner, adding to the previous value.
+                                     */
+    template<class VECTOR>
+    void vmult_add (VECTOR&, const VECTOR&) const;
+
+                                    /**
+                                     * Apply transpose
+                                     * preconditioner, adding. Since this is
+                                     * the identity, this function is
+                                     * the same as
+                                     * vmult_add().
+                                     */
+    template<class VECTOR>
+    void Tvmult_add (VECTOR&, const VECTOR&) const;
+
+  private:
+    number factor;
+};
+
+
+//----------------------------------------------------------------------//
+
+template<typename number>
+ScalingMatrix<number>::ScalingMatrix(number factor)
+               :
+               factor(factor)
+{}
+
+
+template<typename number>
+template<class VECTOR>
+inline void
+ScalingMatrix<number>::vmult (VECTOR &dst, const VECTOR &src) const
+{
+  dst.equ(factor, src);
+}
+
+template<typename number>
+template<class VECTOR>
+inline void
+ScalingMatrix<number>::Tvmult (VECTOR &dst, const VECTOR &src) const
+{
+  dst.equ(factor, src);
+}
+
+template<typename number>
+template<class VECTOR>
+inline void
+ScalingMatrix<number>::vmult_add (VECTOR &dst, const VECTOR &src) const
+{
+  dst.add(factor, src);
+}
+
+
+
+template<typename number>
+template<class VECTOR>
+inline void
+ScalingMatrix<number>::Tvmult_add (VECTOR &dst, const VECTOR &src) const
+{
+  dst.add(factor, src);
+}
+
+//----------------------------------------------------------------------//
+
+template<class MATRIX, class RELAX>
+void check_smoother(const MGLevelObject<MATRIX>& m,
+                   const MGLevelObject<RELAX>& r)
+{
+  GrowingVectorMemory<BlockVector<double> > mem;
+  MGSmootherBlock<MATRIX, RELAX, double> smoother(mem);
+  
+  smoother.initialize(m, r);
+
+  for (unsigned int l=m.get_minlevel(); l<= m.get_maxlevel();++l)
+    {
+      deallog << "Level " << l << std::endl;
+      
+      BlockVector<double>& u = *mem.alloc();
+      BlockVector<double>& f = *mem.alloc();
+      u.reinit(m[l].n_block_rows(), 3);
+      f.reinit(u);
+      for (unsigned int b=0;b<f.n_blocks();++b)
+       for (unsigned int i=0;i<f.block(b).size();++i)
+         f.block(b)(i) = (b+1)*(i+l);
+      
+      deallog << "First step" << std::endl;
+      smoother.set_steps(1);
+      smoother.smooth(l, u, f);
+      
+      for (unsigned int b=0;b<u.n_blocks();++b)
+       {
+         for (unsigned int i=0;i<u.block(b).size();++i)
+           deallog << '\t' << (int) (u.block(b)(i)+.5);
+         deallog << std::endl;
+       }
+      
+      deallog << "Second step" << std::endl;
+      smoother.smooth(l, u, f);
+      
+      for (unsigned int b=0;b<u.n_blocks();++b)
+       {
+         for (unsigned int i=0;i<u.block(b).size();++i)
+           deallog << '\t' << (int) (u.block(b)(i)+.5);
+         deallog << std::endl;
+       }
+      
+      deallog << "Two steps" << std::endl;
+      u = 0.;
+      smoother.set_steps(2);
+      smoother.smooth(l, u, f);
+      
+      for (unsigned int b=0;b<u.n_blocks();++b)
+       {
+         for (unsigned int i=0;i<u.block(b).size();++i)
+           deallog << '\t' << (int) (u.block(b)(i)+.5);
+         deallog << std::endl;
+       }
+      
+      mem.free(&u);
+      mem.free(&f);
+    }
+}
+
+void check()
+{
+  ScalingMatrix<double> s1(-1.);
+  ScalingMatrix<double> s2(2.);
+  ScalingMatrix<double> s8(8.);
+  
+  GrowingVectorMemory<Vector<double> > mem;
+  MGLevelObject<BlockMatrixArray<double> > A (2,4);
+  MGLevelObject<BlockTrianglePrecondition<double> > P(2,4);
+  
+  for (unsigned int l=A.get_minlevel(); l<= A.get_maxlevel();++l)
+    {
+      A[l].initialize(3, 3, mem);
+      P[l].initialize(3, mem);
+      for (unsigned int b=0;b<A[l].n_block_rows();++b)
+       {
+         P[l].enter(s2, b, b, A[l].n_block_rows()-b);
+         A[l].enter(s8, b, b, 1);
+         for (unsigned int b2=0;b2<A[l].n_block_rows();++b2)
+           A[l].enter(s1,b,b2,1.);
+       }
+    }
+  
+  check_smoother(A, P);
+}
+
+
+int main()
+{
+  std::ofstream logfile("smoother_block/output");
+  logfile.precision(3);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  check();
+}
+
diff --git a/tests/multigrid/smoother_block/cmp/generic b/tests/multigrid/smoother_block/cmp/generic
new file mode 100644 (file)
index 0000000..f55e664
--- /dev/null
@@ -0,0 +1,44 @@
+
+DEAL::Level 2
+DEAL::First step
+DEAL:: 12      18      24
+DEAL:: 16      24      32
+DEAL:: 12      18      24
+DEAL::Second step
+DEAL:: -311    -467    -623
+DEAL:: -319    -479    -639
+DEAL:: -87     -131    -175
+DEAL::Two steps
+DEAL:: -311    -467    -623
+DEAL:: -319    -479    -639
+DEAL:: -87     -131    -175
+DEAL::Level 3
+DEAL::First step
+DEAL:: 18      24      30
+DEAL:: 24      32      40
+DEAL:: 18      24      30
+DEAL::Second step
+DEAL:: -467    -623    -779
+DEAL:: -479    -639    -799
+DEAL:: -131    -175    -219
+DEAL::Two steps
+DEAL:: -467    -623    -779
+DEAL:: -479    -639    -799
+DEAL:: -131    -175    -219
+DEAL::Level 4
+DEAL::First step
+DEAL:: 24      30      36
+DEAL:: 32      40      48
+DEAL:: 24      30      36
+DEAL::Second step
+DEAL:: -623    -779    -935
+DEAL:: -639    -799    -959
+DEAL:: -175    -219    -263
+DEAL::Two steps
+DEAL:: -623    -779    -935
+DEAL:: -639    -799    -959
+DEAL:: -175    -219    -263
+DEAL::GrowingVectorMemory:Overall allocated vectors: 24
+DEAL::GrowingVectorMemory:Maximum allocated vectors: 4
+DEAL::GrowingVectorMemory:Overall allocated vectors: 48
+DEAL::GrowingVectorMemory:Maximum allocated vectors: 1

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.