]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test.
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 29 Mar 2018 22:25:05 +0000 (16:25 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 3 Apr 2018 16:25:03 +0000 (10:25 -0600)
tests/vector_tools/integrate_difference_02_nan.cc [new file with mode: 0644]
tests/vector_tools/integrate_difference_02_nan.output [new file with mode: 0644]

diff --git a/tests/vector_tools/integrate_difference_02_nan.cc b/tests/vector_tools/integrate_difference_02_nan.cc
new file mode 100644 (file)
index 0000000..fa8c761
--- /dev/null
@@ -0,0 +1,140 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2003 - 2017 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.
+//
+// ---------------------------------------------------------------------
+
+
+// Test integrate_difference
+//
+// The VectorTools::integrate_difference() function allows users
+// to provide a weight function that can also serve as a component mask
+// to select individual components of the solution vector for error
+// computation. For components not selected, such a mask would then
+// simply be zero.
+//
+// In some cases, the solution vector contains NaN numbers, for example
+// when one uses the FE_FaceQ element for certain components of the
+// solution vector and uses a quadrature formula for error evaluation
+// that has quadrature points in the interior of the cell. For any
+// "regular" solution component for which the component mask has a zero
+// weight, the value of that component will be multiplied by zero and
+// consequently does not add anything to the error computation. However,
+// if the NaNs of a FE_FaceQ are multiplied with zero weights, the result
+// is still a NaN, and adding it to the values times weights of the other
+// components results in NaNs -- in effect rendering it impossible to get
+// any information out of the VectorTools::integrate_difference()
+// function if one of the finite elements involved is FE_FaceQ.
+//
+// This is now fixed by simply skipping vector components for which the
+// weight vector is zero. This has the same result as before for all
+// "normal" situations, but also properly skips the NaN case outlined
+// above.
+
+
+#include "../tests.h"
+#include <deal.II/base/function.h>
+#include <deal.II/base/quadrature_lib.h>
+#include <deal.II/base/signaling_nan.h>
+#include <deal.II/numerics/vector_tools.h>
+#include <deal.II/lac/vector.h>
+#include <deal.II/dofs/dof_tools.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_refinement.h>
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/fe/fe_face.h>
+#include <deal.II/fe/fe_system.h>
+
+using namespace dealii;
+
+
+template <int dim>
+void test(VectorTools::NormType norm, double exp = 2.0)
+{
+  Triangulation<dim> tria;
+  GridGenerator::hyper_cube(tria);
+  tria.refine_global(2);
+
+  FESystem<dim> fe(FE_Q<dim>(1), 1,
+                   FE_FaceQ<dim>(1), 1);
+  DoFHandler<dim> dofh(tria);
+  dofh.distribute_dofs(fe);
+
+  // Create a zero vector. (The values in there are not important,
+  // just that the difference between this and later the exact
+  // solution happens to have signaling_nans in it. It will have these
+  // values because FE_FaceQ refuses to fill FEValues values --
+  // because it's a face element, so this refusal actually makes sense
+  // -- and thus leaves the signaling NaNs from the original invalid
+  // initialization.)
+  Vector<double> solution (dofh.n_dofs ());
+
+  Vector<double> cellwise_errors (tria.n_active_cells());
+  QIterated<dim> quadrature (QTrapez<1>(), 2);
+
+  const ComponentSelectFunction<dim> component_mask (1, 2);
+  VectorTools::integrate_difference (dofh,
+                                     solution,
+                                     ZeroFunction<dim>(2),
+                                     cellwise_errors,
+                                     quadrature,
+                                     norm,
+                                     &component_mask,
+                                     exp);
+
+  const double error
+    = VectorTools::compute_global_error(tria, cellwise_errors, norm, exp);
+
+  deallog << "computed: " << error
+          << std::endl;
+}
+
+
+
+template <int dim>
+void test()
+{
+  deallog << "L2_norm:" << std::endl;
+  test<dim>(VectorTools::L2_norm);
+
+  deallog << "H1_seminorm:" << std::endl;
+  test<dim>(VectorTools::H1_seminorm);
+
+  deallog << "H1_norm:" << std::endl;
+  test<dim>(VectorTools::H1_norm);
+
+  deallog << "L1_norm:" << std::endl;
+  test<dim>(VectorTools::L1_norm);
+
+  deallog << "Linfty_norm:" << std::endl;
+  test<dim>(VectorTools::Linfty_norm);
+
+  deallog << "mean:" << std::endl;
+  test<dim>(VectorTools::mean);
+
+  deallog << "Lp_norm:" << std::endl;
+  test<dim>(VectorTools::Lp_norm, 3.0);
+
+  deallog << "W1p_seminorm:" << std::endl;
+  test<dim>(VectorTools::W1p_seminorm, 3.0);
+
+  deallog << "OK" << std::endl;
+}
+
+
+int main (int argc, char **argv)
+{
+  initlog();
+  test<3>();
+}
diff --git a/tests/vector_tools/integrate_difference_02_nan.output b/tests/vector_tools/integrate_difference_02_nan.output
new file mode 100644 (file)
index 0000000..9e9cfe1
--- /dev/null
@@ -0,0 +1,18 @@
+
+DEAL::L2_norm:
+DEAL::computed: 0.00000
+DEAL::H1_seminorm:
+DEAL::computed: 0.00000
+DEAL::H1_norm:
+DEAL::computed: 0.00000
+DEAL::L1_norm:
+DEAL::computed: 0.00000
+DEAL::Linfty_norm:
+DEAL::computed: 0.00000
+DEAL::mean:
+DEAL::computed: 0.00000
+DEAL::Lp_norm:
+DEAL::computed: 0.00000
+DEAL::W1p_seminorm:
+DEAL::computed: 0.00000
+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.