From 1d02d6845e9e45c6769bab5bbaa4a3296df63208 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 3 Feb 2014 19:41:25 +0000 Subject: [PATCH] One more test for curls. git-svn-id: https://svn.dealii.org/trunk@32395 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/deal.II/fe_values_view_29.cc | 153 +++++++++++++++++++++++++ tests/deal.II/fe_values_view_29.output | 10 ++ 2 files changed, 163 insertions(+) create mode 100644 tests/deal.II/fe_values_view_29.cc create mode 100644 tests/deal.II/fe_values_view_29.output diff --git a/tests/deal.II/fe_values_view_29.cc b/tests/deal.II/fe_values_view_29.cc new file mode 100644 index 0000000000..eff1147724 --- /dev/null +++ b/tests/deal.II/fe_values_view_29.cc @@ -0,0 +1,153 @@ +// --------------------------------------------------------------------- +// $Id$ +// +// Copyright (C) 2007 - 2014 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 _28 but also test a non-primitive element. + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +class F : public Function<2> +{ +public: + F() : Function<2>(2) {} + + virtual void vector_value (const Point<2> &p, + Vector &v) const + { + // make the function equal to (0,x^2) + v[0] = 0; + v[1] = p[0]*p[0]; + } +}; + + + +Tensor<1,1> curl (const Tensor<2,2> &grads) +{ + return Point<1>(grads[1][0] - grads[0][1]); +} + + +Tensor<1,3> curl (const Tensor<2,3> &grads) +{ + return Point<3>(grads[2][1] - grads[1][2], + grads[0][2] - grads[2][0], + grads[1][0] - grads[0][1]); +} + + + +template +void test (const Triangulation &tr, + const FiniteElement &fe) +{ + deallog << "FE=" << fe.get_name() + << std::endl; + + DoFHandler dof(tr); + dof.distribute_dofs(fe); + + Vector fe_function(dof.n_dofs()); + // set the elements of the vector in such a way that the function + // equals the vector function (0,x^2) + ConstraintMatrix cm; + cm.close (); + VectorTools::project (dof, cm, QGauss<2>(4), F(), fe_function); + + // verify that we really have something that after projection equals the + // original + { + DataOut x; + x.attach_dof_handler (dof); + x.add_data_vector (fe_function, "u"); + std::ofstream o("x.gnuplot"); + x.build_patches(6); + x.write_gnuplot (o); + } + + const QGauss quadrature(2); + FEValues fe_values (fe, quadrature, + update_values | update_gradients | update_q_points); + fe_values.reinit (dof.begin_active()); + + // let the FEValues object compute the + // divergences at quadrature points + std::vector::type> curls (quadrature.size()); + std::vector > grads (quadrature.size()); + FEValuesExtractors::Vector extractor(0); + fe_values[extractor].get_function_curls (fe_function, curls); + fe_values[extractor].get_function_gradients (fe_function, grads); + + // now compare + for (unsigned int q=0; q(); +} diff --git a/tests/deal.II/fe_values_view_29.output b/tests/deal.II/fe_values_view_29.output new file mode 100644 index 0000000000..534b134add --- /dev/null +++ b/tests/deal.II/fe_values_view_29.output @@ -0,0 +1,10 @@ + +DEAL::FE=FE_Nedelec<2>(2) +DEAL:: curls[q]= 0.423 +DEAL:: grads[q]= 0.00 0.00 0.423 -1.98e-16 +DEAL:: curls[q]= 1.58 +DEAL:: grads[q]= 0.00 0.00 1.58 4.45e-16 +DEAL:: curls[q]= 0.423 +DEAL:: grads[q]= 0.00 0.00 0.423 -2.00e-16 +DEAL:: curls[q]= 1.58 +DEAL:: grads[q]= 0.00 0.00 1.58 -3.38e-16 -- 2.39.5