From b9afe77ce9de453773ca9528e9ec81985b9e50cb Mon Sep 17 00:00:00 2001 From: bangerth Date: Thu, 8 Sep 2011 03:31:09 +0000 Subject: [PATCH] Add new test. git-svn-id: https://svn.dealii.org/trunk@24285 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/bits/fe_field_function_02.cc | 93 +++++++++++++++++++++ tests/bits/fe_field_function_02/cmp/generic | 10 +++ 2 files changed, 103 insertions(+) create mode 100644 tests/bits/fe_field_function_02.cc create mode 100644 tests/bits/fe_field_function_02/cmp/generic diff --git a/tests/bits/fe_field_function_02.cc b/tests/bits/fe_field_function_02.cc new file mode 100644 index 0000000000..02884b8e0a --- /dev/null +++ b/tests/bits/fe_field_function_02.cc @@ -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 + +// all include files you need here +#include +#include +#include +#include +#include +#include +#include +#include +#include + +double abs_zero(double a) +{ + if( std::abs(a) < 1e-10) + return 0; + else + return a; +} + +template +void test() { + Triangulation tria; + GridGenerator::hyper_cube(tria); + tria.refine_global(8/dim); + + FE_Q fe(1); + DoFHandler dh(tria); + + dh.distribute_dofs(fe); + deallog << "Ndofs :" << dh.n_dofs() << std::endl; + + Functions::CosineFunction ff; + + Vector v1(dh.n_dofs()), v2(dh.n_dofs()); + + VectorTools::interpolate(dh, ff, v1); + deallog << "V norm: " << v1.l2_norm() << std::endl; + + Functions::FEFieldFunction, Vector > + 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(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 index 0000000000..b22d94b605 --- /dev/null +++ b/tests/bits/fe_field_function_02/cmp/generic @@ -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 -- 2.39.5