]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add new test.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 1 Jun 2011 15:10:53 +0000 (15:10 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 1 Jun 2011 15:10:53 +0000 (15:10 +0000)
git-svn-id: https://svn.dealii.org/trunk@23757 0785d39b-7218-0410-832d-ea1e28bc413d

tests/deal.II/refinement_listener_01.cc [new file with mode: 0644]
tests/deal.II/refinement_listener_01/cmp/generic [new file with mode: 0644]

diff --git a/tests/deal.II/refinement_listener_01.cc b/tests/deal.II/refinement_listener_01.cc
new file mode 100644 (file)
index 0000000..b6743d2
--- /dev/null
@@ -0,0 +1,120 @@
+//----------------------------  refinement_listener_01.cc  ---------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2006, 2008, 2011 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.
+//
+//----------------------------  refinement_listener_01.cc  ---------------------------
+
+
+// test the various refinement listener functions
+
+
+#include "../tests.h"
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/base/logstream.h>
+
+#include <fstream>
+#include <iomanip>
+#include <cstdio>
+
+std::ofstream logfile("refinement_listener_01/output");
+
+
+template <int dim, int spacedim = dim>
+class RefinementListener :
+  public Triangulation<dim,spacedim>::RefinementListener
+{
+  public:
+    RefinementListener (const std::string &prefix)
+                   :
+                   prefix(prefix)
+      {}
+
+    virtual
+    void
+    pre_refinement_notification (const Triangulation<dim, spacedim> &tria)
+      {
+       deallog << prefix << ' ' << "Pre-refinement: " << tria.n_active_cells() << std::endl;
+      }
+
+    virtual
+    void
+    post_refinement_notification (const Triangulation<dim, spacedim> &tria)
+      {
+       deallog << prefix << ' ' << "Post-refinement: " << tria.n_active_cells() << std::endl;
+      }
+
+    virtual
+    void
+    copy_notification (const Triangulation<dim, spacedim> &old_tria,
+                      const Triangulation<dim, spacedim> &new_tria)
+      {
+       deallog << prefix << ' ' << "Copy: "
+               << old_tria.n_active_cells() << ' '
+               << new_tria.n_active_cells() << std::endl;
+      }
+
+    virtual
+    void
+    create_notification (const Triangulation<dim, spacedim> &tria)
+      {
+       deallog << prefix << ' ' << "Create: " << tria.n_active_cells() << std::endl;
+      }
+
+  private:
+    std::string prefix;
+};
+
+
+template <int dim>
+void test ()
+{
+  deallog << dim << "D" << std::endl;
+
+  Triangulation<dim> tria_1, tria_2;
+
+  GridGenerator::hyper_cube(tria_2);
+
+  RefinementListener<dim> rl_1 ("tria_1");
+  RefinementListener<dim> rl_2 ("tria_2");
+  tria_1.add_refinement_listener (rl_1);
+  tria_2.add_refinement_listener (rl_2);
+
+                                  // this should print the create note
+  GridGenerator::hyper_cube(tria_1);
+
+                                  // this should print the pre- and
+                                  // post-refinement note
+  tria_1.refine_global (1);
+
+                                  // this should print the copy note
+  tria_1.clear ();
+  tria_1.copy_triangulation (tria_2);
+
+                                  // no longer print anything
+  tria_1.remove_refinement_listener (rl_1);
+  tria_1.refine_global (2);
+}
+
+
+int main ()
+{
+  deallog << std::setprecision(2);
+  logfile << std::setprecision(2);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  test<1> ();
+  test<2> ();
+  test<3> ();
+
+  return 0;
+}
diff --git a/tests/deal.II/refinement_listener_01/cmp/generic b/tests/deal.II/refinement_listener_01/cmp/generic
new file mode 100644 (file)
index 0000000..7c274b6
--- /dev/null
@@ -0,0 +1,16 @@
+
+DEAL::1D
+DEAL::tria_1 Create: 1
+DEAL::tria_1 Pre-refinement: 1
+DEAL::tria_1 Post-refinement: 2
+DEAL::tria_2 Copy: 1 1
+DEAL::2D
+DEAL::tria_1 Create: 1
+DEAL::tria_1 Pre-refinement: 1
+DEAL::tria_1 Post-refinement: 4
+DEAL::tria_2 Copy: 1 1
+DEAL::3D
+DEAL::tria_1 Create: 1
+DEAL::tria_1 Pre-refinement: 1
+DEAL::tria_1 Post-refinement: 8
+DEAL::tria_2 Copy: 1 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.