From e1148a5603453ca0ab6bec17e27edfce91d8b3ba Mon Sep 17 00:00:00 2001 From: hartmann Date: Thu, 13 Jun 2002 12:50:19 +0000 Subject: [PATCH] Tests old and new interpolate, back_interpolate and interpolation_difference functions. git-svn-id: https://svn.dealii.org/trunk@6093 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/fe/fe_tools_test.cc | 211 ++++++++++++++ tests/fe/fe_tools_test.checked | 506 +++++++++++++++++++++++++++++++++ 2 files changed, 717 insertions(+) create mode 100644 tests/fe/fe_tools_test.cc create mode 100644 tests/fe/fe_tools_test.checked diff --git a/tests/fe/fe_tools_test.cc b/tests/fe/fe_tools_test.cc new file mode 100644 index 0000000000..ab9325b2a6 --- /dev/null +++ b/tests/fe/fe_tools_test.cc @@ -0,0 +1,211 @@ +/* $Id$ */ +/* Author: Ralf Hartmann, University of Heidelberg, 1999 */ + +/* $Id$ */ +/* Version: $Name$ */ +/* */ +/* Copyright (C) 1999, 2000, 2001, 2002 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. */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + // This is needed for C++ output: +#include +#include + +const double pi=acos(-1); + +class TestFunction: public Function<2> +{ + public: + TestFunction() {}; + virtual ~TestFunction() {}; + + virtual double value(const Point<2> &p, + const unsigned int component) const; +}; + + +double +TestFunction::value(const Point<2> &p, + const unsigned int component) const +{ + Assert(component==0, ExcInternalError()); + return sin(pi*p(0))*cos(pi*p(1)); +} + + + + +void make_grid (Triangulation<2> &triangulation) +{ + GridGenerator::hyper_cube (triangulation); + + const Point<2> p0=triangulation.begin_active()->vertex(0); + + triangulation.refine_global(1); + + for (unsigned int step=0; step<1; ++step) + { + Triangulation<2>::active_cell_iterator cell, endc; + cell = triangulation.begin_active(); + endc = triangulation.end(); + + for (; cell!=endc; ++cell) + if (cell->vertex(0)==p0) + { + cell->set_refine_flag (); + break; + } + + triangulation.execute_coarsening_and_refinement (); + }; +}; + + +template +void test(const Triangulation &tria, + const Mapping &mapping, + const FiniteElement &fe1, + const string &fe_string1, + const FiniteElement &fe2, + const string &fe_string2, + const unsigned int testcase) +{ + DoFHandler dof_handler1 (tria); + DoFHandler dof_handler2 (tria); + + dof_handler1.distribute_dofs (fe1); + dof_handler2.distribute_dofs (fe2); + + Vector function1(dof_handler1.n_dofs()); + Vector function1_back(dof_handler1.n_dofs()); + Vector function2(dof_handler2.n_dofs()); + + ConstraintMatrix constraints1; + DoFTools::make_hanging_node_constraints (dof_handler1, constraints1); + constraints1.close(); + + ConstraintMatrix constraints2; + DoFTools::make_hanging_node_constraints (dof_handler2, constraints2); + constraints2.close(); + + QGauss4 quadrature; + TestFunction function; + VectorTools::project(mapping, + dof_handler1, + constraints1, + quadrature, + function, + function1); + + switch (testcase) + { + case 1: + FETools::interpolate(dof_handler1, function1, + dof_handler2, constraints2, function2); + break; + case 2: + FETools::back_interpolate(dof_handler1, constraints1, function1, + dof_handler2, constraints2, function1_back); + break; + case 3: + FETools::interpolation_difference(dof_handler1, constraints1, function1, + dof_handler2, constraints2, function1_back); + break; + default: + Assert(false, ExcNotImplemented()); + } + + DataOut data_out; + data_out.attach_dof_handler (dof_handler1); + data_out.add_data_vector (function1, fe_string1); + data_out.build_patches (2); + string file1_name=fe_string1+"_function.gnuplot"; + ofstream file1(file1_name.c_str()); + data_out.write_gnuplot(file1); + file1.close(); + data_out.clear(); + + string file2_name=fe_string1+"_"; + switch (testcase) + { + case 1: + data_out.attach_dof_handler (dof_handler2); + data_out.add_data_vector (function2, fe_string2); + file2_name+=fe_string2+"_interpolation.gnuplot"; + break; + case 2: + data_out.attach_dof_handler (dof_handler1); + data_out.add_data_vector (function1_back, fe_string1); + file2_name+=fe_string2+"_back_interpolation.gnuplot"; + break; + case 3: + data_out.attach_dof_handler (dof_handler1); + data_out.add_data_vector (function1_back, fe_string1); + file2_name+=fe_string2+"_interpolation_diff.gnuplot"; + break; + default: + Assert(false, ExcNotImplemented()); + } + deallog << file2_name << endl; + + data_out.build_patches (2); + data_out.write_gnuplot(deallog.get_file_stream()); + ofstream file2(file2_name.c_str()); + file2.setf(std::ios::showpoint | std::ios::left); + data_out.write_gnuplot(file2); + file2.close(); +}; + + + +int main () +{ + std::ofstream logfile("fe_tools_test.output"); + deallog.attach(logfile); + deallog.depth_console(0); + + Triangulation<2> tria; + MappingQ1<2> mapping; + + make_grid (tria); + + deallog.push("dg2dg1_int"); + test(tria, mapping, FE_DGQ<2>(2), "dg2", FE_DGQ<2>(1), "dg1", 1); + deallog.pop(); + deallog.push("cg2dg1_back"); + test(tria, mapping, FE_Q<2>(2), "cg2", FE_DGQ<2>(1), "dg1", 2); + deallog.pop(); + deallog.push("dg2dg1_back"); + test(tria, mapping, FE_DGQ<2>(2), "dg2", FE_DGQ<2>(1), "dg1", 2); + deallog.pop(); + deallog.push("cg2dg1_diff"); + test(tria, mapping, FE_Q<2>(2), "cg2", FE_DGQ<2>(1), "dg1", 3); + deallog.pop(); + deallog.push("dg2dg1_diff"); + test(tria, mapping, FE_DGQ<2>(2), "dg2", FE_DGQ<2>(1), "dg1", 3); + deallog.pop(); +} diff --git a/tests/fe/fe_tools_test.checked b/tests/fe/fe_tools_test.checked new file mode 100644 index 0000000000..74a97782f3 --- /dev/null +++ b/tests/fe/fe_tools_test.checked @@ -0,0 +1,506 @@ + +DEAL:dg2dg1_int:cg::Starting +DEAL:dg2dg1_int:cg::Convergence step 9 +DEAL:dg2dg1_int::dg2_dg1_interpolation.gnuplot +# This file was generated by the deal.II library. + + +# +# For a description of the GNUPLOT format see the GNUPLOT manual. +# +# +0.500000 0.00000 1.03914 +0.500000 0.250000 0.507178 +0.500000 0.500000 -0.0247869 + +0.750000 0.00000 0.507178 +0.750000 0.250000 0.247540 +0.750000 0.500000 -0.0120978 + +1.00000 0.00000 -0.0247869 +1.00000 0.250000 -0.0120978 +1.00000 0.500000 0.000591247 + + +0.500000 0.500000 0.0247869 +0.500000 0.750000 -0.507178 +0.500000 1.00000 -1.03914 + +0.750000 0.500000 0.0120978 +0.750000 0.750000 -0.247540 +0.750000 1.00000 -0.507178 + +1.00000 0.500000 0.000591247 +1.00000 0.750000 0.0120978 +1.00000 1.00000 0.0247869 + + +0.00000 0.500000 0.000591247 +0.00000 0.750000 0.0120978 +0.00000 1.00000 0.0247869 + +0.250000 0.500000 0.0120978 +0.250000 0.750000 -0.247540 +0.250000 1.00000 -0.507178 + +0.500000 0.500000 0.0247869 +0.500000 0.750000 -0.507178 +0.500000 1.00000 -1.03914 + + +0.00000 0.00000 0.00377989 +0.00000 0.125000 0.00322130 +0.00000 0.250000 0.00266271 + +0.125000 0.00000 0.353934 +0.125000 0.125000 0.301630 +0.125000 0.250000 0.249326 + +0.250000 0.00000 0.711649 +0.250000 0.125000 0.606482 +0.250000 0.250000 0.501315 + + +0.250000 0.00000 0.706303 +0.250000 0.125000 0.601926 +0.250000 0.250000 0.497549 + +0.375000 0.00000 0.854473 +0.375000 0.125000 0.728200 +0.375000 0.250000 0.601926 + +0.500000 0.00000 1.00264 +0.500000 0.125000 0.854473 +0.500000 0.250000 0.706303 + + +0.250000 0.250000 0.501315 +0.250000 0.375000 0.249326 +0.250000 0.500000 0.00266271 + +0.375000 0.250000 0.606482 +0.375000 0.375000 0.301630 +0.375000 0.500000 0.00322130 + +0.500000 0.250000 0.711649 +0.500000 0.375000 0.353934 +0.500000 0.500000 0.00377989 + + +0.00000 0.250000 0.00268286 +0.00000 0.375000 0.00133430 +0.00000 0.500000 1.42499e-05 + +0.125000 0.250000 0.251213 +0.125000 0.375000 0.124939 +0.125000 0.500000 0.00133430 + +0.250000 0.250000 0.505109 +0.250000 0.375000 0.251213 +0.250000 0.500000 0.00268286 + + +DEAL:cg2dg1_back:cg::Starting +DEAL:cg2dg1_back:cg::Convergence step 16 +DEAL:cg2dg1_back::cg2_dg1_back_interpolation.gnuplot +# This file was generated by the deal.II library. + + +# +# For a description of the GNUPLOT format see the GNUPLOT manual. +# +# +0.500000 0.00000 1.04224 +0.500000 0.250000 0.522530 +0.500000 0.500000 0.00282475 + +0.750000 0.00000 0.507765 +0.750000 0.250000 0.254824 +0.750000 0.500000 0.00188317 + +1.00000 0.00000 -0.0267069 +1.00000 0.250000 -0.0128827 +1.00000 0.500000 0.000941583 + + +0.500000 0.500000 0.00282475 +0.500000 0.750000 -0.521819 +0.500000 1.00000 -1.04646 + +0.750000 0.500000 0.00188317 +0.750000 0.750000 -0.254350 +0.750000 1.00000 -0.510583 + +1.00000 0.500000 0.000941583 +1.00000 0.750000 0.0131197 +1.00000 1.00000 0.0252978 + + +0.00000 0.500000 0.00425934 +0.00000 0.750000 0.00965243 +0.00000 1.00000 0.0235642 + +0.250000 0.500000 0.000717295 +0.250000 0.750000 -0.256083 +0.250000 1.00000 -0.511450 + +0.500000 0.500000 0.00282475 +0.500000 0.750000 -0.521819 +0.500000 1.00000 -1.04646 + + +0.00000 0.00000 0.00272861 +0.00000 0.125000 0.00338912 +0.00000 0.250000 0.00404962 + +0.125000 0.00000 0.357187 +0.125000 0.125000 0.303595 +0.125000 0.250000 0.250003 + +0.250000 0.00000 0.717103 +0.250000 0.125000 0.610579 +0.250000 0.250000 0.504056 + + +0.250000 0.00000 0.717103 +0.250000 0.125000 0.610579 +0.250000 0.250000 0.504056 + +0.375000 0.00000 0.879670 +0.375000 0.125000 0.743618 +0.375000 0.250000 0.607566 + +0.500000 0.00000 1.04224 +0.500000 0.125000 0.782383 +0.500000 0.250000 0.522530 + + +0.250000 0.250000 0.504056 +0.250000 0.375000 0.258049 +0.250000 0.500000 0.000717295 + +0.375000 0.250000 0.607566 +0.375000 0.375000 0.307500 +0.375000 0.500000 0.00105373 + +0.500000 0.250000 0.522530 +0.500000 0.375000 0.262678 +0.500000 0.500000 0.00282475 + + +0.00000 0.250000 0.00404962 +0.00000 0.375000 0.00415448 +0.00000 0.500000 0.00425934 + +0.125000 0.250000 0.250003 +0.125000 0.375000 0.126947 +0.125000 0.500000 0.00248832 + +0.250000 0.250000 0.504056 +0.250000 0.375000 0.258049 +0.250000 0.500000 0.000717295 + + +DEAL:dg2dg1_back:cg::Starting +DEAL:dg2dg1_back:cg::Convergence step 9 +DEAL:dg2dg1_back::dg2_dg1_back_interpolation.gnuplot +# This file was generated by the deal.II library. + + +# +# For a description of the GNUPLOT format see the GNUPLOT manual. +# +# +0.500000 0.00000 1.03914 +0.500000 0.250000 0.507178 +0.500000 0.500000 -0.0247869 + +0.750000 0.00000 0.507178 +0.750000 0.250000 0.247540 +0.750000 0.500000 -0.0120978 + +1.00000 0.00000 -0.0247869 +1.00000 0.250000 -0.0120978 +1.00000 0.500000 0.000591247 + + +0.500000 0.500000 0.0247869 +0.500000 0.750000 -0.507178 +0.500000 1.00000 -1.03914 + +0.750000 0.500000 0.0120978 +0.750000 0.750000 -0.247540 +0.750000 1.00000 -0.507178 + +1.00000 0.500000 0.000591247 +1.00000 0.750000 0.0120978 +1.00000 1.00000 0.0247869 + + +0.00000 0.500000 0.000591247 +0.00000 0.750000 0.0120978 +0.00000 1.00000 0.0247869 + +0.250000 0.500000 0.0120978 +0.250000 0.750000 -0.247540 +0.250000 1.00000 -0.507178 + +0.500000 0.500000 0.0247869 +0.500000 0.750000 -0.507178 +0.500000 1.00000 -1.03914 + + +0.00000 0.00000 0.00377989 +0.00000 0.125000 0.00322130 +0.00000 0.250000 0.00266271 + +0.125000 0.00000 0.353934 +0.125000 0.125000 0.301630 +0.125000 0.250000 0.249326 + +0.250000 0.00000 0.711649 +0.250000 0.125000 0.606482 +0.250000 0.250000 0.501315 + + +0.250000 0.00000 0.706303 +0.250000 0.125000 0.601926 +0.250000 0.250000 0.497549 + +0.375000 0.00000 0.854473 +0.375000 0.125000 0.728200 +0.375000 0.250000 0.601926 + +0.500000 0.00000 1.00264 +0.500000 0.125000 0.854473 +0.500000 0.250000 0.706303 + + +0.250000 0.250000 0.501315 +0.250000 0.375000 0.249326 +0.250000 0.500000 0.00266271 + +0.375000 0.250000 0.606482 +0.375000 0.375000 0.301630 +0.375000 0.500000 0.00322130 + +0.500000 0.250000 0.711649 +0.500000 0.375000 0.353934 +0.500000 0.500000 0.00377989 + + +0.00000 0.250000 0.00268286 +0.00000 0.375000 0.00133430 +0.00000 0.500000 1.42499e-05 + +0.125000 0.250000 0.251213 +0.125000 0.375000 0.124939 +0.125000 0.500000 0.00133430 + +0.250000 0.250000 0.505109 +0.250000 0.375000 0.251213 +0.250000 0.500000 0.00268286 + + +DEAL:cg2dg1_diff:cg::Starting +DEAL:cg2dg1_diff:cg::Convergence step 16 +DEAL:cg2dg1_diff::cg2_dg1_interpolation_diff.gnuplot +# This file was generated by the deal.II library. + + +# +# For a description of the GNUPLOT format see the GNUPLOT manual. +# +# +0.500000 0.00000 0.00000 +0.500000 0.250000 0.188546 +0.500000 0.500000 0.00000 + +0.750000 0.00000 0.218671 +0.750000 0.250000 0.241754 +0.750000 0.500000 0.00235396 + +1.00000 0.00000 0.00000 +1.00000 0.250000 0.00573732 +1.00000 0.500000 0.00000 + + +0.500000 0.500000 0.00000 +0.500000 0.750000 -0.194371 +0.500000 1.00000 0.00000 + +0.750000 0.500000 0.00235396 +0.750000 0.750000 -0.241376 +0.750000 1.00000 -0.215148 + +1.00000 0.500000 0.00000 +1.00000 0.750000 0.00379557 +1.00000 1.00000 0.00000 + + +0.00000 0.500000 0.00000 +0.00000 0.750000 0.00812967 +0.00000 1.00000 0.00000 + +0.250000 0.500000 0.0127601 +0.250000 0.750000 -0.241728 +0.250000 1.00000 -0.210110 + +0.500000 0.500000 0.00000 +0.500000 0.750000 -0.194371 +0.500000 1.00000 0.00000 + + +0.00000 0.00000 0.00000 +0.00000 0.125000 0.000873549 +0.00000 0.250000 0.00000 + +0.125000 0.00000 0.0261782 +0.125000 0.125000 0.0499189 +0.125000 0.250000 0.0228053 + +0.250000 0.00000 0.00000 +0.250000 0.125000 0.0424990 +0.250000 0.250000 0.00000 + + +0.250000 0.00000 0.00000 +0.250000 0.125000 0.0424990 +0.250000 0.250000 0.00000 + +0.375000 0.00000 0.0411108 +0.375000 0.125000 0.108734 +0.375000 0.250000 0.0488215 + +0.500000 0.00000 0.00000 +0.500000 0.125000 0.141409 +0.500000 0.250000 0.188546 + + +0.250000 0.250000 0.00000 +0.250000 0.375000 0.0146911 +0.250000 0.500000 0.0127601 + +0.375000 0.250000 0.0488215 +0.375000 0.375000 0.0409141 +0.375000 0.500000 0.00957008 + +0.500000 0.250000 0.188546 +0.500000 0.375000 0.141409 +0.500000 0.500000 0.00000 + + +0.00000 0.250000 0.00000 +0.00000 0.375000 0.00424686 +0.00000 0.500000 0.00000 + +0.125000 0.250000 0.0228053 +0.125000 0.375000 0.0178860 +0.125000 0.500000 0.00957008 + +0.250000 0.250000 0.00000 +0.250000 0.375000 0.0146911 +0.250000 0.500000 0.0127601 + + +DEAL:dg2dg1_diff:cg::Starting +DEAL:dg2dg1_diff:cg::Convergence step 9 +DEAL:dg2dg1_diff::dg2_dg1_interpolation_diff.gnuplot +# This file was generated by the deal.II library. + + +# +# For a description of the GNUPLOT format see the GNUPLOT manual. +# +# +0.500000 0.00000 0.00000 +0.500000 0.250000 0.212673 +0.500000 0.500000 0.00000 + +0.750000 0.00000 0.212673 +0.750000 0.250000 0.251126 +0.750000 0.500000 0.00507293 + +1.00000 0.00000 0.00000 +1.00000 0.250000 0.00507293 +1.00000 0.500000 0.00000 + + +0.500000 0.500000 0.00000 +0.500000 0.750000 -0.212673 +0.500000 1.00000 0.00000 + +0.750000 0.500000 0.00507293 +0.750000 0.750000 -0.251126 +0.750000 1.00000 -0.212673 + +1.00000 0.500000 0.00000 +1.00000 0.750000 0.00507293 +1.00000 1.00000 0.00000 + + +0.00000 0.500000 0.00000 +0.00000 0.750000 0.00507293 +0.00000 1.00000 0.00000 + +0.250000 0.500000 0.00507293 +0.250000 0.750000 -0.251126 +0.250000 1.00000 -0.212673 + +0.500000 0.500000 0.00000 +0.500000 0.750000 -0.212673 +0.500000 1.00000 0.00000 + + +0.00000 0.00000 0.00000 +0.00000 0.125000 0.000265962 +0.00000 0.250000 0.00000 + +0.125000 0.00000 0.0292221 +0.125000 0.125000 0.0518634 +0.125000 0.250000 0.0205852 + +0.250000 0.00000 0.00000 +0.250000 0.125000 0.0500733 +0.250000 0.250000 0.00000 + + +0.250000 0.00000 0.00000 +0.250000 0.125000 0.0496971 +0.250000 0.250000 0.00000 + +0.375000 0.00000 0.0705483 +0.375000 0.125000 0.125209 +0.375000 0.250000 0.0496971 + +0.500000 0.00000 0.00000 +0.500000 0.125000 0.0705483 +0.500000 0.250000 0.00000 + + +0.250000 0.250000 0.00000 +0.250000 0.375000 0.0205852 +0.250000 0.500000 0.00000 + +0.375000 0.250000 0.0500733 +0.375000 0.375000 0.0518634 +0.375000 0.500000 0.000265962 + +0.500000 0.250000 0.00000 +0.500000 0.375000 0.0292221 +0.500000 0.500000 0.00000 + + +0.00000 0.250000 0.00000 +0.00000 0.375000 0.000110165 +0.00000 0.500000 0.00000 + +0.125000 0.250000 0.0207410 +0.125000 0.375000 0.0214825 +0.125000 0.500000 0.000110165 + +0.250000 0.250000 0.00000 +0.250000 0.375000 0.0207410 +0.250000 0.500000 0.00000 + + -- 2.39.5