From: Wolfgang Bangerth Date: Thu, 16 Jan 2020 15:09:35 +0000 (-0700) Subject: Add tests. X-Git-Tag: v9.2.0-rc1~657^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d38353ee9c4f0a437a39a0ae8d1a8c4a078fecd;p=dealii.git Add tests. --- diff --git a/tests/data_out/data_out_08.cc b/tests/data_out/data_out_08.cc index 597cbeab3d..bfd9e56c60 100644 --- a/tests/data_out/data_out_08.cc +++ b/tests/data_out/data_out_08.cc @@ -14,7 +14,7 @@ // --------------------------------------------------------------------- -// this test documents two unrelated bugs in DataOut when used with a Filter (by +// This test documents two unrelated bugs in DataOut when used with a Filter (by // deriving from DataOut): // 1. The patch index computation in data_out.cc is wrong and causes an SIGV (or // an Assert after adding that): @@ -37,7 +37,7 @@ dealii::TriaIterator >] 466: The violated condition was: 466: cell_and_index->second < patches.size() 466: The name and call sequence of the exception was: 466: ExcInternalError() */ -// 2. DataOut used begi_active() instead of first_cell() in two places which +// 2. DataOut used begin_active() instead of first_cell() in two places which // caused a wrong patch to be generated when the first active cell is not picked // by the filter. @@ -112,15 +112,12 @@ check() // this should skip the first cell typename Triangulation::active_cell_iterator it = tria.begin_active(); - //++it; it->set_subdomain_id(1); FE_DGQ fe(0); DoFHandler dof_handler(tria); dof_handler.distribute_dofs(fe); - // DataOut data_out; - // we pick only subdomain==0 which will // skip the first of the four cells FilteredDataOut data_out(0); diff --git a/tests/data_out/data_out_08_set_cell_selection_01.cc b/tests/data_out/data_out_08_set_cell_selection_01.cc new file mode 100644 index 0000000000..0f72e6e9ac --- /dev/null +++ b/tests/data_out/data_out_08_set_cell_selection_01.cc @@ -0,0 +1,141 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2003 - 2018 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. +// +// --------------------------------------------------------------------- + + +// This test is an adaptation of the _08 test, but using the +// DataOut::set_cell_selection() function instead of overloading +// member functions. +// +// Because the _08 test is eventually going away (as it uses +// deprecated functions), here is the description of that test: +// .................... +// This test documents two unrelated bugs in DataOut when used with a Filter (by +// deriving from DataOut): +// 1. The patch index computation in data_out.cc is wrong and causes an SIGV (or +// an Assert after adding that): +/* +466: -------------------------------------------------------- +466: An error occurred in line <306> of file + in function +466: void dealii::DataOut::build_one_patch(const +std::pair::cell_iterator, unsigned int>*, +dealii::internal::DataOut::ParallelData&, dealii::DataOutBase::Patch&, dealii::DataOut::CurvedCellRegion, +std::vector >&) [with int dim = 2, DoFHandlerType = +dealii::DoFHandler<2>, typename dealii::DataOut_DoFData::cell_iterator = +dealii::TriaIterator >] 466: The violated condition +was: 466: cell_and_index->second < patches.size() 466: The name and call +sequence of the exception was: 466: ExcInternalError() +*/ +// 2. DataOut used begin_active() instead of first_cell() in two places which +// caused a wrong patch to be generated when the first active cell is not picked +// by the filter. + +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include + +#include + +#include "../tests.h" + + + +template +void +check() +{ + Triangulation tria; + GridGenerator::hyper_cube(tria, 0., 1.); + tria.refine_global(1); + + Vector cell_data(4); + for (unsigned int i = 0; i < 4; ++i) + cell_data(i) = i * 1.0; + + // this should skip the first cell + typename Triangulation::active_cell_iterator it = tria.begin_active(); + it->set_subdomain_id(1); + + FE_DGQ fe(0); + DoFHandler dof_handler(tria); + dof_handler.distribute_dofs(fe); + + // we pick only subdomain==0 which will + // skip the first of the four cells + DataOut data_out; + data_out.set_cell_selection( + [](const Triangulation &t) { + auto cell = t.begin_active(); + while ((cell != t.end()) && (cell->subdomain_id() != 0)) + ++cell; + + return cell; + }, + + [](const Triangulation & t, + const typename Triangulation::cell_iterator &old_cell) -> + typename Triangulation::cell_iterator { + if (old_cell != t.end()) + { + const IteratorFilters::SubdomainEqualTo predicate(0); + + return ++( + FilteredIterator::active_cell_iterator>( + predicate, old_cell)); + } + else + return old_cell; + }); + + + data_out.attach_dof_handler(dof_handler); + + data_out.add_data_vector(cell_data, + "cell_data", + DataOut::type_cell_data); + data_out.build_patches(); + + data_out.write_deal_II_intermediate(deallog.get_file_stream()); + + deallog << "OK" << std::endl; +} + +int +main(int argc, char **argv) +{ + std::ofstream logfile("output"); + deallog << std::setprecision(2); + logfile << std::setprecision(2); + deallog.attach(logfile); + + check<2>(); + + return 0; +} diff --git a/tests/data_out/data_out_08_set_cell_selection_01.output b/tests/data_out/data_out_08_set_cell_selection_01.output new file mode 100644 index 0000000000..bd4f3f7361 --- /dev/null +++ b/tests/data_out/data_out_08_set_cell_selection_01.output @@ -0,0 +1,38 @@ + +2 2 +[deal.II intermediate format graphics data] +[written by deal.II x.y.z] +[Version: 3] +1 +cell_data +3 +[deal.II intermediate Patch<2,2>] +0.50 0.0 1.0 0.0 1.0 0.50 0.50 0.50 +4294967295 4294967295 4294967295 2 +0 1 +0 +1 4 +1.0 1.0 1.0 1.0 + + +[deal.II intermediate Patch<2,2>] +0.0 0.50 0.50 0.50 0.50 1.0 0.0 1.0 +4294967295 2 4294967295 4294967295 +1 1 +0 +1 4 +2.0 2.0 2.0 2.0 + + +[deal.II intermediate Patch<2,2>] +0.50 0.50 1.0 0.50 1.0 1.0 0.50 1.0 +1 4294967295 0 4294967295 +2 1 +0 +1 4 +3.0 3.0 3.0 3.0 + + +0 + +DEAL::OK diff --git a/tests/data_out/data_out_08_set_cell_selection_02.cc b/tests/data_out/data_out_08_set_cell_selection_02.cc new file mode 100644 index 0000000000..9b5a0a8fbb --- /dev/null +++ b/tests/data_out/data_out_08_set_cell_selection_02.cc @@ -0,0 +1,125 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2003 - 2018 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. +// +// --------------------------------------------------------------------- + + +// This test is an adaptation of the _08 test, but using the +// DataOut::set_cell_selection() function with the FilteredIterator +// argument instead of overloading member functions. +// +// Because the _08 test is eventually going away (as it uses +// deprecated functions), here is the description of that test: +// .................... +// This test documents two unrelated bugs in DataOut when used with a Filter (by +// deriving from DataOut): +// 1. The patch index computation in data_out.cc is wrong and causes an SIGV (or +// an Assert after adding that): +/* +466: -------------------------------------------------------- +466: An error occurred in line <306> of file + in function +466: void dealii::DataOut::build_one_patch(const +std::pair::cell_iterator, unsigned int>*, +dealii::internal::DataOut::ParallelData&, dealii::DataOutBase::Patch&, dealii::DataOut::CurvedCellRegion, +std::vector >&) [with int dim = 2, DoFHandlerType = +dealii::DoFHandler<2>, typename dealii::DataOut_DoFData::cell_iterator = +dealii::TriaIterator >] 466: The violated condition +was: 466: cell_and_index->second < patches.size() 466: The name and call +sequence of the exception was: 466: ExcInternalError() +*/ +// 2. DataOut used begin_active() instead of first_cell() in two places which +// caused a wrong patch to be generated when the first active cell is not picked +// by the filter. + +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include + +#include + +#include "../tests.h" + + + +template +void +check() +{ + Triangulation tria; + GridGenerator::hyper_cube(tria, 0., 1.); + tria.refine_global(1); + + Vector cell_data(4); + for (unsigned int i = 0; i < 4; ++i) + cell_data(i) = i * 1.0; + + // this should skip the first cell + typename Triangulation::active_cell_iterator it = tria.begin_active(); + it->set_subdomain_id(1); + + FE_DGQ fe(0); + DoFHandler dof_handler(tria); + dof_handler.distribute_dofs(fe); + + // we pick only subdomain==0 which will + // skip the first of the four cells + DataOut data_out; + auto predicate = [](const typename Triangulation::cell_iterator &cell) { + return (!cell->has_children() && cell->subdomain_id() == 0); + }; + + FilteredIterator::cell_iterator> filter( + predicate); + data_out.set_cell_selection(filter); + + + data_out.attach_dof_handler(dof_handler); + + data_out.add_data_vector(cell_data, + "cell_data", + DataOut::type_cell_data); + data_out.build_patches(); + + data_out.write_deal_II_intermediate(deallog.get_file_stream()); + + deallog << "OK" << std::endl; +} + +int +main(int argc, char **argv) +{ + std::ofstream logfile("output"); + deallog << std::setprecision(2); + logfile << std::setprecision(2); + deallog.attach(logfile); + + check<2>(); + + return 0; +} diff --git a/tests/data_out/data_out_08_set_cell_selection_02.output b/tests/data_out/data_out_08_set_cell_selection_02.output new file mode 100644 index 0000000000..bd4f3f7361 --- /dev/null +++ b/tests/data_out/data_out_08_set_cell_selection_02.output @@ -0,0 +1,38 @@ + +2 2 +[deal.II intermediate format graphics data] +[written by deal.II x.y.z] +[Version: 3] +1 +cell_data +3 +[deal.II intermediate Patch<2,2>] +0.50 0.0 1.0 0.0 1.0 0.50 0.50 0.50 +4294967295 4294967295 4294967295 2 +0 1 +0 +1 4 +1.0 1.0 1.0 1.0 + + +[deal.II intermediate Patch<2,2>] +0.0 0.50 0.50 0.50 0.50 1.0 0.0 1.0 +4294967295 2 4294967295 4294967295 +1 1 +0 +1 4 +2.0 2.0 2.0 2.0 + + +[deal.II intermediate Patch<2,2>] +0.50 0.50 1.0 0.50 1.0 1.0 0.50 1.0 +1 4294967295 0 4294967295 +2 1 +0 +1 4 +3.0 3.0 3.0 3.0 + + +0 + +DEAL::OK