]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add new test.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 8 Sep 2011 03:31:09 +0000 (03:31 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 8 Sep 2011 03:31:09 +0000 (03:31 +0000)
git-svn-id: https://svn.dealii.org/trunk@24285 0785d39b-7218-0410-832d-ea1e28bc413d

tests/bits/fe_field_function_02.cc [new file with mode: 0644]
tests/bits/fe_field_function_02/cmp/generic [new file with mode: 0644]

diff --git a/tests/bits/fe_field_function_02.cc b/tests/bits/fe_field_function_02.cc
new file mode 100644 (file)
index 0000000..02884b8
--- /dev/null
@@ -0,0 +1,93 @@
+//----------------------------  template.cc  ---------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2005, 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.
+//
+//----------------------------  template.cc  ---------------------------
+
+
+// Test the FEFieldFunction class. This class was not thread-safe at one point
+// because it keeps a cache on the side that was invalidated when different
+// threads kept pouncing on it. Patrick Sodre wrote a fix for that that's
+// based on a thread-local variable instead of the single cache.
+
+#include "../tests.h"
+#include <fstream>
+
+// all include files you need here
+#include <deal.II/numerics/fe_field_function.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/dofs/dof_handler.h>
+#include <deal.II/dofs/dof_tools.h>
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/base/function_lib.h>
+#include <deal.II/base/quadrature_lib.h>
+#include <deal.II/numerics/vectors.h>
+
+double abs_zero(double a)
+{
+  if( std::abs(a) < 1e-10)
+    return 0;
+  else
+    return a;
+}
+
+template <int dim>
+void test() {
+  Triangulation<dim> tria;
+  GridGenerator::hyper_cube(tria);
+  tria.refine_global(8/dim);
+
+  FE_Q<dim> fe(1);
+  DoFHandler<dim> dh(tria);
+
+  dh.distribute_dofs(fe);
+  deallog << "Ndofs :" << dh.n_dofs() << std::endl;
+
+  Functions::CosineFunction<dim> ff;
+
+  Vector<double> v1(dh.n_dofs()), v2(dh.n_dofs());
+
+  VectorTools::interpolate(dh, ff, v1);
+  deallog << "V norm: " << v1.l2_norm() << std::endl;
+
+  Functions::FEFieldFunction<dim, DoFHandler<dim>, Vector<double> >
+    fef(dh, v1);
+
+                                  // project the discrete function fef back
+                                  // onto the finite element space. this
+                                  // should be the identity operation and
+                                  // consequently subtracting the vector from
+                                  // itself should yield zero
+  {
+    ConstraintMatrix cm;
+    cm.close();
+    VectorTools::project(dh, cm, QGauss<dim>(3), fef, v2);
+  }
+  v2.add(-1, v1);
+
+  deallog << "Projection error: " << abs_zero(v2.l2_norm())
+         << std::endl;
+  Assert (v2.l2_norm() < 1e-12, ExcInternalError());
+}
+
+int main ()
+{
+  std::ofstream logfile("fe_field_function_02/output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  test<1>();
+  test<2>();
+  test<3>();
+
+  return 0;
+}
+
diff --git a/tests/bits/fe_field_function_02/cmp/generic b/tests/bits/fe_field_function_02/cmp/generic
new file mode 100644 (file)
index 0000000..b22d94b
--- /dev/null
@@ -0,0 +1,10 @@
+
+DEAL::Ndofs :257
+DEAL::V norm: 11.3358
+DEAL::Projection error: 0
+DEAL::Ndofs :289
+DEAL::V norm: 8.50000
+DEAL::Projection error: 0
+DEAL::Ndofs :125
+DEAL::V norm: 3.95285
+DEAL::Projection error: 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.