]> https://gitweb.dealii.org/ - dealii.git/commitdiff
New tests.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 9 Mar 2004 17:32:48 +0000 (17:32 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 9 Mar 2004 17:32:48 +0000 (17:32 +0000)
git-svn-id: https://svn.dealii.org/trunk@8703 0785d39b-7218-0410-832d-ea1e28bc413d

tests/bits/Makefile
tests/bits/subdomain_ids_01.cc [new file with mode: 0644]
tests/bits/subdomain_ids_02.cc [new file with mode: 0644]

index 892f3bc824fca37316ae8813bc66dcea90301a55..449742f13d907dba598a5129aea794c41c18e58a 100644 (file)
@@ -51,7 +51,8 @@ tests_x = anna_? \
          full_matrix_vector_* \
          solver_selector \
          deal_solver_* \
-         vector_*
+         vector_* \
+         subdomain_ids_*
 
 ifeq ($(USE_CONTRIB_PETSC),yes)
   tests_x += petsc_*
diff --git a/tests/bits/subdomain_ids_01.cc b/tests/bits/subdomain_ids_01.cc
new file mode 100644 (file)
index 0000000..07c8074
--- /dev/null
@@ -0,0 +1,106 @@
+//----------------------------  subdomain_ids_01.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2001, 2002, 2003, 2004 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.
+//
+//----------------------------  subdomain_ids_01.cc  ---------------------------
+
+// check DoFTools::extract_subdomain_dofs
+
+
+#include "../tests.h"
+#include <base/logstream.h>
+#include <grid/tria.h>
+#include <grid/grid_generator.h>
+#include <grid/tria_iterator.h>
+#include <dofs/dof_handler.h>
+#include <dofs/dof_accessor.h>
+#include <dofs/dof_tools.h>
+#include <fe/fe_dgq.h>
+#include <fe/fe_q.h>
+#include <fe/fe_system.h>
+#include <dofs/dof_tools.h>
+
+#include <fstream>
+#include <algorithm>
+#include <cmath>
+
+
+std::ofstream logfile("subdomain_ids_01.output");
+
+
+DeclException2 (ExcNumberMismatch,
+               int, int,
+               << "The numbers " << arg1 << " and " << arg2
+               << " should be equal, but are not.");
+
+
+template <int dim>
+void test ()
+{
+  deallog << dim << 'D' << std::endl;
+  Triangulation<dim> tria;
+  GridGenerator::hyper_cube(tria, -1, 1);
+  tria.refine_global (2);
+
+                                  // we now have a number of cells,
+                                  // flag them with some subdomain
+                                  // ids based on their position, in
+                                  // particular we take the quadrant
+                                  // (octant)
+  typename Triangulation<dim>::active_cell_iterator
+    cell = tria.begin_active (),
+    endc = tria.end ();
+  for (; cell!=endc; ++cell)
+    {
+      unsigned int subdomain = 0;
+      for (unsigned int d=0; d<dim; ++d)
+       if (cell->center()(d) > 0)
+         subdomain |= (1<<d);
+      Assert (subdomain < (1<<dim), ExcInternalError());
+
+      cell->set_subdomain_id (subdomain);
+    };
+
+                                  // distribute some degrees of freedom and
+                                  // output some information on them
+  FESystem<dim> fe(FE_Q<dim>(2),dim, FE_DGQ<dim>(1), 1);
+  DoFHandler<dim> dof_handler (tria);
+  dof_handler.distribute_dofs (fe);
+  deallog << dof_handler.n_dofs() << std::endl;
+  
+  std::vector<bool> selected_dofs (dof_handler.n_dofs());
+  for (unsigned int subdomain=0; subdomain<(1<<dim); ++subdomain)
+    {
+                                       // count number on dofs on
+                                       // subdomain. note that they add up to
+                                       // more than n_dofs() since the ones on
+                                       // the interfaces count for each
+                                       // subdomain
+      DoFTools::extract_subdomain_dofs (dof_handler, subdomain,
+                                        selected_dofs);
+      deallog << std::count (selected_dofs.begin(),
+                             selected_dofs.end(), true)
+              << std::endl;
+    }
+}
+
+
+int main ()
+{
+  logfile.precision(4);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  test<1> ();
+  test<2> ();
+  test<3> ();
+  
+  return 0;
+}
diff --git a/tests/bits/subdomain_ids_02.cc b/tests/bits/subdomain_ids_02.cc
new file mode 100644 (file)
index 0000000..f646b6d
--- /dev/null
@@ -0,0 +1,115 @@
+//----------------------------  subdomain_ids_02.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2001, 2002, 2003, 2004 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.
+//
+//----------------------------  subdomain_ids_02.cc  ---------------------------
+
+// check DoFTools::get_subdomain_association
+
+
+#include "../tests.h"
+#include <base/logstream.h>
+#include <grid/tria.h>
+#include <grid/grid_generator.h>
+#include <grid/tria_iterator.h>
+#include <dofs/dof_handler.h>
+#include <dofs/dof_accessor.h>
+#include <dofs/dof_tools.h>
+#include <fe/fe_dgq.h>
+#include <fe/fe_q.h>
+#include <fe/fe_system.h>
+#include <dofs/dof_tools.h>
+
+#include <fstream>
+#include <algorithm>
+#include <cmath>
+
+
+std::ofstream logfile("subdomain_ids_02.output");
+
+
+DeclException2 (ExcNumberMismatch,
+               int, int,
+               << "The numbers " << arg1 << " and " << arg2
+               << " should be equal, but are not.");
+
+
+template <int dim>
+void test ()
+{
+  deallog << dim << 'D' << std::endl;
+  Triangulation<dim> tria;
+  GridGenerator::hyper_cube(tria, -1, 1);
+  tria.refine_global (2);
+
+                                  // we now have a number of cells,
+                                  // flag them with some subdomain
+                                  // ids based on their position, in
+                                  // particular we take the quadrant
+                                  // (octant)
+  typename Triangulation<dim>::active_cell_iterator
+    cell = tria.begin_active (),
+    endc = tria.end ();
+  for (; cell!=endc; ++cell)
+    {
+      unsigned int subdomain = 0;
+      for (unsigned int d=0; d<dim; ++d)
+       if (cell->center()(d) > 0)
+         subdomain |= (1<<d);
+      Assert (subdomain < (1<<dim), ExcInternalError());
+
+      cell->set_subdomain_id (subdomain);
+    };
+
+                                  // distribute some degrees of freedom and
+                                  // output some information on them
+  FESystem<dim> fe(FE_Q<dim>(2),dim, FE_DGQ<dim>(1), 1);
+  DoFHandler<dim> dof_handler (tria);
+  dof_handler.distribute_dofs (fe);
+  deallog << dof_handler.n_dofs() << std::endl;
+  
+  std::vector<unsigned int> subdomain_association (dof_handler.n_dofs());
+  DoFTools::get_subdomain_association (dof_handler,
+                                       subdomain_association);
+  for (unsigned int subdomain=0; subdomain<(1<<dim); ++subdomain)
+    {
+                                       // count number on dofs on
+                                       // subdomain. this time it should add
+                                       // up, since each dof is uniquely
+                                       // associated
+      deallog << std::count (subdomain_association.begin(),
+                             subdomain_association.end(), subdomain)
+              << std::endl;
+    }
+
+                                   // make sure that all subdomain_ids are
+                                   // really in the allowed range. if this is
+                                   // the case, then we have also proven that
+                                   // the numbers really add up correctly,
+                                   // since every dof is assigned a valid
+                                   // subdomain id
+  for (unsigned int i=0;i<dof_handler.n_dofs(); ++i)
+    Assert (subdomain_association[i] < (1<<dim),
+            ExcInternalError());
+}
+
+
+int main ()
+{
+  logfile.precision(4);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  test<1> ();
+  test<2> ();
+  test<3> ();
+  
+  return 0;
+}

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.