From: Wolfgang Bangerth Date: Tue, 28 Apr 2020 18:19:03 +0000 (-0600) Subject: Add a test. X-Git-Tag: v9.2.0-rc1~156^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15f9b3b44e8a9a752d38ec23991bc39e0d1e71ef;p=dealii.git Add a test. --- diff --git a/tests/hp/hp_fe_values_copy.cc b/tests/hp/hp_fe_values_copy.cc new file mode 100644 index 0000000000..3c6d2e4256 --- /dev/null +++ b/tests/hp/hp_fe_values_copy.cc @@ -0,0 +1,100 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2020 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + + +// hp::FEValues objects can be copied, but that sometimes led to +// surprising results because it kept shared pointers underneath (this +// has been fixed). + + +#include + +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include "../tests.h" + + + +template +void +test() +{ + Triangulation triangulation; + GridGenerator::hyper_cube(triangulation); + triangulation.refine_global(1); + + hp::FECollection fe_collection; + fe_collection.push_back(FE_Nothing()); + + hp::DoFHandler dof_handler(triangulation); + dof_handler.distribute_dofs(fe_collection); + + deallog << " Number of active cells: " + << triangulation.n_active_cells() << std::endl + << " Number of degrees of freedom: " << dof_handler.n_dofs() + << std::endl; + + + hp::QCollection quadrature_collection; + quadrature_collection.push_back(QMidpoint()); + + // Create one hp::FEValues object, and initialize it for the first + // cell. When we later ask for the location of the quadrature point, + // it better be the midpoint of that cell + const auto cell1 = dof_handler.begin_active(); + hp::FEValues hp_fe_values1(fe_collection, + quadrature_collection, + update_quadrature_points); + hp_fe_values1.reinit(cell1); + + // Now make a copy of the object and initialize it for the second cell + const auto cell2 = ++dof_handler.begin_active(); + hp::FEValues hp_fe_values2(hp_fe_values1); + hp_fe_values2.reinit(cell2); + + // Output the quadrature points computed by the two objects. They + // ought to correspond to the cell centers of the first and second + // cell. + deallog << hp_fe_values1.get_present_fe_values().get_quadrature_points()[0] + << " should be at " << cell1->center() << std::endl; + + deallog << hp_fe_values2.get_present_fe_values().get_quadrature_points()[0] + << " should be at " << cell2->center() << std::endl; +} + + + +int +main() +{ + initlog(); + + test<1>(); + test<2>(); + test<3>(); +} diff --git a/tests/hp/hp_fe_values_copy.output b/tests/hp/hp_fe_values_copy.output new file mode 100644 index 0000000000..382683d88f --- /dev/null +++ b/tests/hp/hp_fe_values_copy.output @@ -0,0 +1,13 @@ + +DEAL:: Number of active cells: 2 +DEAL:: Number of degrees of freedom: 0 +DEAL::0.250000 should be at 0.250000 +DEAL::0.750000 should be at 0.750000 +DEAL:: Number of active cells: 4 +DEAL:: Number of degrees of freedom: 0 +DEAL::0.250000 0.250000 should be at 0.250000 0.250000 +DEAL::0.750000 0.250000 should be at 0.750000 0.250000 +DEAL:: Number of active cells: 8 +DEAL:: Number of degrees of freedom: 0 +DEAL::0.250000 0.250000 0.250000 should be at 0.250000 0.250000 0.250000 +DEAL::0.750000 0.250000 0.250000 should be at 0.750000 0.250000 0.250000