From 27f942e793c20ca043809b85c06cc2c2e2728739 Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Tue, 15 Feb 2011 17:58:08 +0000 Subject: [PATCH] test Assembler::Functional git-svn-id: https://svn.dealii.org/trunk@23367 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/integrators/empty_info.h | 46 ++++++ tests/integrators/functional_01.cc | 169 ++++++++++++++++++++ tests/integrators/functional_01/cmp/generic | 13 ++ 3 files changed, 228 insertions(+) create mode 100644 tests/integrators/empty_info.h create mode 100644 tests/integrators/functional_01.cc create mode 100644 tests/integrators/functional_01/cmp/generic diff --git a/tests/integrators/empty_info.h b/tests/integrators/empty_info.h new file mode 100644 index 0000000000..9fcd35e330 --- /dev/null +++ b/tests/integrators/empty_info.h @@ -0,0 +1,46 @@ +//---------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2000, 2001, 2003, 2004, 2007, 2008, 2009, 2010, 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. +// +//---------------------------------------------------------------------- + +// Provide scratch data objects with no contents for the MeshWorker::loop() + +#include + +class EmptyInfo +{ + public: + template + void reinit(const DOFINFO&) + {} +}; + + +class EmptyInfoBox +{ + public: + typedef EmptyInfo CellInfo; + template + void post_cell(const MeshWorker::DoFInfoBox&) + {} + + template + void post_faces(const MeshWorker::DoFInfoBox&) + {} + + EmptyInfo cell; + EmptyInfo boundary; + EmptyInfo face; + EmptyInfo subface; + EmptyInfo neighbor; +}; + + diff --git a/tests/integrators/functional_01.cc b/tests/integrators/functional_01.cc new file mode 100644 index 0000000000..0de3225154 --- /dev/null +++ b/tests/integrators/functional_01.cc @@ -0,0 +1,169 @@ +//---------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2000, 2001, 2003, 2004, 2007, 2008, 2009, 2010, 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. +// +//---------------------------------------------------------------------- + +// Test whether Assember::Functional adds up correctly. + +#include "../tests.h" +#include "empty_info.h" +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +using namespace dealii; + + +// Define a class that fills all available entries in the info objects +// with recognizable numbers. + +// Fills the following functionals: +// 0: number of cells +// 1: number of interior faces +// 2: number of boundary faces + +const unsigned int n_functionals = 3; + +template +class Local : public Subscriptor +{ + public: + typedef EmptyInfo CellInfo; + + void cell(MeshWorker::DoFInfo& dinfo, CellInfo& info) const; + void bdry(MeshWorker::DoFInfo& dinfo, CellInfo& info) const; + void face(MeshWorker::DoFInfo& dinfo1, MeshWorker::DoFInfo& dinfo2, + CellInfo& info1, CellInfo& info2) const; +}; + + +template +void +Local::cell(MeshWorker::DoFInfo& info, CellInfo&) const +{ + info.value(0) = 1.; +} + + +template +void +Local::bdry(MeshWorker::DoFInfo& info, CellInfo&) const +{ + info.value(2) = 1.; +} + + +template +void +Local::face(MeshWorker::DoFInfo& info1, MeshWorker::DoFInfo& info2, + CellInfo&, CellInfo&) const +{ + info1.value(1) = 1./2.; + info2.value(1) = 1./2.; +} + + +template +void +test_mesh(MGDoFHandler& mgdofs) +{ + const DoFHandler& dofs = mgdofs; + + Local local; + EmptyInfoBox info_box; + MeshWorker::DoFInfo dof_info(dofs); + + MeshWorker::Assembler::Functional assembler; + assembler.initialize(n_functionals); + + MeshWorker::loop, EmptyInfoBox> + (dofs.begin_active(), dofs.end(), + dof_info, info_box, + std_cxx1x::bind (&Local::cell, local, _1, _2), + std_cxx1x::bind (&Local::bdry, local, _1, _2), + std_cxx1x::bind (&Local::face, local, _1, _2, _3, _4), + assembler, true); + + deallog << " Results"; + for (unsigned int i=0;i mg_dof_info(mgdofs); + MeshWorker::loop, EmptyInfoBox> + (mgdofs.begin(), mgdofs.end(), + mg_dof_info, info_box, + std_cxx1x::bind (&Local::cell, local, _1, _2), + std_cxx1x::bind (&Local::bdry, local, _1, _2), + std_cxx1x::bind (&Local::face, local, _1, _2, _3, _4), + assembler, true); + + deallog << "MGResults"; + for (unsigned int i=0;i +void +test(const FiniteElement& fe) +{ + Triangulation tr; + MGDoFHandler dofs(tr); + GridGenerator::hyper_cube(tr); + tr.refine_global(1); + deallog.push("1"); + dofs.distribute_dofs(fe); + test_mesh(dofs); + deallog.pop(); + tr.begin(1)->set_refine_flag(); + tr.execute_coarsening_and_refinement(); + deallog.push("2"); + dofs.distribute_dofs(fe); + test_mesh(dofs); + deallog.pop(); + tr.begin(2)->set_refine_flag(); + tr.execute_coarsening_and_refinement(); + deallog.push("3"); + dofs.distribute_dofs(fe); + test_mesh(dofs); + deallog.pop(); +} + + +int main () +{ + const std::string logname = JobIdentifier::base_name(__FILE__) + std::string("/output"); + std::ofstream logfile(logname.c_str()); + deallog.attach(logfile); +// deallog.depth_console (0); + + FE_DGP<2> el2(0); + FE_DGP<3> el3(0); + + deallog.push("2D"); + test(el2); + deallog.pop(); + deallog.push("3D"); + test(el3); + deallog.pop(); +} diff --git a/tests/integrators/functional_01/cmp/generic b/tests/integrators/functional_01/cmp/generic new file mode 100644 index 0000000000..0c72628cab --- /dev/null +++ b/tests/integrators/functional_01/cmp/generic @@ -0,0 +1,13 @@ + +DEAL:2D:1:: Results 4.00000 4.00000 8.00000 +DEAL:2D:1::MGResults 5.00000 4.00000 12.0000 +DEAL:2D:2:: Results 7.00000 10.0000 10.0000 +DEAL:2D:2::MGResults 9.00000 12.0000 16.0000 +DEAL:2D:3:: Results 10.0000 16.0000 12.0000 +DEAL:2D:3::MGResults 13.0000 20.0000 20.0000 +DEAL:3D:1:: Results 8.00000 12.0000 24.0000 +DEAL:3D:1::MGResults 9.00000 12.0000 30.0000 +DEAL:3D:2:: Results 15.0000 33.0000 33.0000 +DEAL:3D:2::MGResults 17.0000 36.0000 42.0000 +DEAL:3D:3:: Results 22.0000 54.0000 42.0000 +DEAL:3D:3::MGResults 25.0000 60.0000 54.0000 -- 2.39.5