]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add unit test for make_flux_sparsity_pattern with periodicity. 3237/head
authorSAM COX <spc29@le.ac.uk>
Thu, 13 Oct 2016 21:44:42 +0000 (22:44 +0100)
committerSAM COX <spc29@le.ac.uk>
Thu, 13 Oct 2016 22:15:38 +0000 (23:15 +0100)
tests/bits/periodic_flux_coupling_01.cc [new file with mode: 0644]
tests/bits/periodic_flux_coupling_01.output [new file with mode: 0644]

diff --git a/tests/bits/periodic_flux_coupling_01.cc b/tests/bits/periodic_flux_coupling_01.cc
new file mode 100644 (file)
index 0000000..4573283
--- /dev/null
@@ -0,0 +1,165 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+/* checks that make_flux_sparsity_pattern() with masks runs without
+* calling inactive cells
+* on an adapted mesh with periodic boundary conditions
+*/
+
+#include "../tests.h"
+#include <deal.II/base/function.h>
+#include <deal.II/dofs/dof_handler.h>
+#include <deal.II/dofs/dof_tools.h>
+#include <deal.II/fe/fe_dgq.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/grid_tools.h>
+#include <deal.II/integrators/laplace.h>
+#include <deal.II/lac/vector.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
+#include <deal.II/numerics/data_out.h>
+#include <deal.II/numerics/vector_tools.h>
+
+
+#include <fstream>
+#include <iomanip>
+
+
+template <int dim>
+class MakeFlux
+{
+public:
+  MakeFlux ();
+  void run ();
+
+private:
+  void make_grid ();
+
+  Triangulation<dim>   triangulation;
+  FE_DGQ<dim>          fe;
+  DoFHandler<dim>      dof_handler;
+
+  SparsityPattern      sparsity_pattern;
+};
+
+template <int dim>
+MakeFlux<dim>::MakeFlux ()
+  :
+  fe (1),
+  dof_handler (triangulation)
+{}
+
+
+template <int dim>
+void MakeFlux<dim>::make_grid ()
+{
+  GridGenerator::hyper_cube (triangulation, -1, 1, true);
+  typedef typename dealii::Triangulation<dim>::cell_iterator CellIteratorTria;
+  std::vector<dealii::GridTools::PeriodicFacePair<CellIteratorTria> > periodic_faces;
+  const unsigned int b_id1 = 2;
+  const unsigned int b_id2 = 3;
+  const unsigned int direction = 1;
+
+  dealii::GridTools::collect_periodic_faces (triangulation, b_id1, b_id2,
+                                             direction, periodic_faces, dealii::Tensor<1,dim>());
+  triangulation.add_periodicity(periodic_faces);
+  triangulation.refine_global (1);
+}
+
+
+template <int dim>
+void MakeFlux<dim>::run()
+{
+  for (unsigned int cycle = 0; cycle < 3; ++cycle)
+    {
+      if (cycle == 0)
+        make_grid();
+      else
+        {
+          /* refine the top-left cell to ensure we test this cell being looped over
+          * in make_flux_sparsity_pattern after the bottom-left cell and before the
+          * top-right cell, both of which will be less refined.
+          */
+
+          Point<dim> refn_point;
+          refn_point = Point<dim>( 0.005, 0.995);
+          typename Triangulation<dim>::active_cell_iterator cell_it = triangulation.begin_active();
+          for (; cell_it != triangulation.end(); ++cell_it)
+            {
+              if (cell_it->is_locally_owned() && cell_it->point_inside(refn_point))
+                {
+                  cell_it->set_refine_flag();
+                  break;
+                }
+            }
+          triangulation.execute_coarsening_and_refinement();
+        }
+
+      dof_handler.distribute_dofs (fe);
+
+      DynamicSparsityPattern dsp(dof_handler.n_dofs());
+
+      // set up full mask not doing anything
+      const unsigned int n_components = dof_handler.get_fe().n_components();
+      Table<2,DoFTools::Coupling> mask (n_components, n_components);
+      for (unsigned int i=0; i<n_components; ++i)
+        for (unsigned int j=0; j<n_components; ++j)
+          mask(i,j) = DoFTools::always;
+      DoFTools::make_flux_sparsity_pattern (dof_handler, dsp,
+                                            mask, mask);
+      deallog << Utilities::int_to_string(dof_handler.n_dofs(),2) << std::endl;
+      deallog.pop();
+    }
+  deallog << "PASSED" << std::endl;
+}
+
+
+int main (int argc, char **argv)
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.threshold_double(1.e-10);
+
+  try
+    {
+      MakeFlux<2> test;
+      test.run();
+    }
+  catch (std::exception &exc)
+    {
+      deallog << std::endl << std::endl
+              << "----------------------------------------------------"
+              << std::endl;
+      deallog << "Exception on processing: " << std::endl
+              << exc.what() << std::endl
+              << "Aborting!" << std::endl
+              << "----------------------------------------------------"
+              << std::endl;
+
+      return 1;
+    }
+  catch (...)
+    {
+      deallog << std::endl << std::endl
+              << "----------------------------------------------------"
+              << std::endl;
+      deallog << "Unknown exception!" << std::endl
+              << "Aborting!" << std::endl
+              << "----------------------------------------------------"
+              << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/bits/periodic_flux_coupling_01.output b/tests/bits/periodic_flux_coupling_01.output
new file mode 100644 (file)
index 0000000..f24dcbb
--- /dev/null
@@ -0,0 +1,5 @@
+
+DEAL::16
+28
+52
+PASSED

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.