From c496c6aedfb4f09e8cd1886b56e7410c5f76015e Mon Sep 17 00:00:00 2001 From: SAM COX Date: Thu, 13 Oct 2016 22:44:42 +0100 Subject: [PATCH] Add unit test for make_flux_sparsity_pattern with periodicity. --- tests/bits/periodic_flux_coupling_01.cc | 165 ++++++++++++++++++++ tests/bits/periodic_flux_coupling_01.output | 5 + 2 files changed, 170 insertions(+) create mode 100644 tests/bits/periodic_flux_coupling_01.cc create mode 100644 tests/bits/periodic_flux_coupling_01.output diff --git a/tests/bits/periodic_flux_coupling_01.cc b/tests/bits/periodic_flux_coupling_01.cc new file mode 100644 index 0000000000..4573283548 --- /dev/null +++ b/tests/bits/periodic_flux_coupling_01.cc @@ -0,0 +1,165 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2016 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. +// +// --------------------------------------------------------------------- + + +/* checks that make_flux_sparsity_pattern() with masks runs without +* calling inactive cells +* on an adapted mesh with periodic boundary conditions +*/ + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include +#include + + +template +class MakeFlux +{ +public: + MakeFlux (); + void run (); + +private: + void make_grid (); + + Triangulation triangulation; + FE_DGQ fe; + DoFHandler dof_handler; + + SparsityPattern sparsity_pattern; +}; + +template +MakeFlux::MakeFlux () + : + fe (1), + dof_handler (triangulation) +{} + + +template +void MakeFlux::make_grid () +{ + GridGenerator::hyper_cube (triangulation, -1, 1, true); + typedef typename dealii::Triangulation::cell_iterator CellIteratorTria; + std::vector > periodic_faces; + const unsigned int b_id1 = 2; + const unsigned int b_id2 = 3; + const unsigned int direction = 1; + + dealii::GridTools::collect_periodic_faces (triangulation, b_id1, b_id2, + direction, periodic_faces, dealii::Tensor<1,dim>()); + triangulation.add_periodicity(periodic_faces); + triangulation.refine_global (1); +} + + +template +void MakeFlux::run() +{ + for (unsigned int cycle = 0; cycle < 3; ++cycle) + { + if (cycle == 0) + make_grid(); + else + { + /* refine the top-left cell to ensure we test this cell being looped over + * in make_flux_sparsity_pattern after the bottom-left cell and before the + * top-right cell, both of which will be less refined. + */ + + Point refn_point; + refn_point = Point( 0.005, 0.995); + typename Triangulation::active_cell_iterator cell_it = triangulation.begin_active(); + for (; cell_it != triangulation.end(); ++cell_it) + { + if (cell_it->is_locally_owned() && cell_it->point_inside(refn_point)) + { + cell_it->set_refine_flag(); + break; + } + } + triangulation.execute_coarsening_and_refinement(); + } + + dof_handler.distribute_dofs (fe); + + DynamicSparsityPattern dsp(dof_handler.n_dofs()); + + // set up full mask not doing anything + const unsigned int n_components = dof_handler.get_fe().n_components(); + Table<2,DoFTools::Coupling> mask (n_components, n_components); + for (unsigned int i=0; i test; + test.run(); + } + catch (std::exception &exc) + { + deallog << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + deallog << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/bits/periodic_flux_coupling_01.output b/tests/bits/periodic_flux_coupling_01.output new file mode 100644 index 0000000000..f24dcbb6b4 --- /dev/null +++ b/tests/bits/periodic_flux_coupling_01.output @@ -0,0 +1,5 @@ + +DEAL::16 +28 +52 +PASSED -- 2.39.5