]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Sat, 18 Apr 2015 02:45:12 +0000 (21:45 -0500)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 20 Apr 2015 01:38:42 +0000 (20:38 -0500)
tests/hp/integrate_difference_03.cc [new file with mode: 0644]
tests/hp/integrate_difference_03.output [new file with mode: 0644]

diff --git a/tests/hp/integrate_difference_03.cc b/tests/hp/integrate_difference_03.cc
new file mode 100644 (file)
index 0000000..1fe3e33
--- /dev/null
@@ -0,0 +1,136 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2005 - 2015 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.
+//
+// ---------------------------------------------------------------------
+
+
+
+// like _02, but test the Hdiv seminorm. this requires a vector-valued
+// element and a function we interpolate that is vector-valued. we
+// simply extend the function from _02 by zeros
+
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/function_lib.h>
+#include <deal.II/base/quadrature_lib.h>
+#include <deal.II/lac/vector.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/grid_out.h>
+#include <deal.II/grid/tria_iterator.h>
+#include <deal.II/hp/dof_handler.h>
+#include <deal.II/dofs/dof_accessor.h>
+#include <deal.II/hp/fe_collection.h>
+#include <deal.II/hp/q_collection.h>
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/fe/fe_system.h>
+#include <deal.II/numerics/vector_tools.h>
+
+#include <fstream>
+
+
+template <int dim>
+double f (const Point<dim> &p)
+{
+  return p[0];
+}
+
+
+
+template <int dim>
+void test ()
+{
+  deallog << "dim=" << dim << std::endl;
+
+  Triangulation<dim> tria;
+  GridGenerator::hyper_cube(tria);
+  tria.refine_global (2);
+  tria.begin_active()->set_refine_flag ();
+  tria.execute_coarsening_and_refinement ();
+  tria.refine_global (4-dim);
+
+  hp::FECollection<dim> fe_collection;
+  hp::QCollection<dim> q_collection;
+  for (unsigned int i=1; i<=4; ++i)
+    {
+      fe_collection.push_back(FESystem<dim>(FE_Q<dim> (i), dim));
+      q_collection.push_back (QGauss<dim> (i+2));
+    }
+
+
+  hp::DoFHandler<dim> dof_handler(tria);
+
+  for (typename hp::DoFHandler<dim>::active_cell_iterator
+       cell = dof_handler.begin_active();
+       cell != dof_handler.end(); ++cell)
+    cell->set_active_fe_index (Testing::rand() % fe_collection.size());
+
+  dof_handler.distribute_dofs(fe_collection);
+
+  // interpolate a linear function
+  Vector<double> vec (dof_handler.n_dofs());
+  VectorTools::interpolate (dof_handler,
+                           VectorFunctionFromScalarFunctionObject<dim> (&f<dim>, 0, dim),
+                            vec);
+
+  Vector<float> diff (tria.n_active_cells());
+
+  // H1 seminorm. the function is u(x)=x, so
+  // its H1 seminorm should be equal to 1/2
+  {
+    VectorTools::integrate_difference (dof_handler,
+                                       vec,
+                                       ZeroFunction<dim>(dim),
+                                       diff,
+                                       q_collection,
+                                       VectorTools::H1_seminorm);
+    deallog << "H1 seminorm, diff=" << diff.l2_norm() << std::endl;
+  }
+
+  // Hdiv seminorm. the function is
+  // u(x)=x, so the norm must be equal to 1
+  // on every cell
+  {
+    VectorTools::integrate_difference (dof_handler,
+                                       vec,
+                                       ZeroFunction<dim>(dim),
+                                       diff,
+                                       q_collection,
+                                       VectorTools::W1infty_seminorm);
+    deallog << "Hdiv semi, diff=" << diff.linfty_norm() << std::endl;
+    // also ensure that we indeed get the
+    // same value on every cell
+    diff. add(-1);
+    AssertThrow (diff.l2_norm() == 0, ExcInternalError());
+  }
+}
+
+
+int main ()
+{
+  std::ofstream logfile("output");
+  logfile.precision(2);
+  deallog << std::setprecision(2);
+
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  test<1> ();
+  test<2> ();
+  test<3> ();
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/hp/integrate_difference_03.output b/tests/hp/integrate_difference_03.output
new file mode 100644 (file)
index 0000000..1d59a57
--- /dev/null
@@ -0,0 +1,11 @@
+
+DEAL::dim=1
+DEAL::H1 seminorm, diff=1.0
+DEAL::Hdiv semi, diff=1.0
+DEAL::dim=2
+DEAL::H1 seminorm, diff=1.0
+DEAL::Hdiv semi, diff=1.0
+DEAL::dim=3
+DEAL::H1 seminorm, diff=1.0
+DEAL::Hdiv semi, diff=1.0
+DEAL::OK

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.