From be98c03f2f05a47e2988b06a6ea9b565ec469997 Mon Sep 17 00:00:00 2001 From: kanschat Date: Wed, 23 May 2007 20:50:54 +0000 Subject: [PATCH] test user_index functions git-svn-id: https://svn.dealii.org/trunk@14688 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/deal.II/user_data_01.cc | 213 ++++++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 tests/deal.II/user_data_01.cc diff --git a/tests/deal.II/user_data_01.cc b/tests/deal.II/user_data_01.cc new file mode 100644 index 0000000000..25e93cbbd8 --- /dev/null +++ b/tests/deal.II/user_data_01.cc @@ -0,0 +1,213 @@ +//---------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2007 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. +// +//---------------------------------------------------------------------- + + +// Check the handling of user pointers and user indices + +#include "../tests.h" +#include +#include +#include + +#include +#include + +#include +#include + + + + +/** + * Check if user pointers are the same as entered below + */ +template +void +check_user_pointers(Triangulation& tr) +{ + // Check if values are the same as below + Triangulation* p = &tr; + for (typename Triangulation::cell_iterator it = tr.begin(); + it != tr.end();++it) + { + deallog << '.'; + if (it->user_pointer() != p++) + deallog << "Error" << std::endl; + } + deallog << "cells" << std::endl; + + if (dim > 1) + for (typename Triangulation::face_iterator it = tr.begin_face(); + it != tr.end_face();++it) + { + deallog << '.'; + if (it->user_pointer() != p++) + deallog << "Error" << std::endl; + } + deallog << "faces" << std::endl; + + if (dim > 2) + for (typename Triangulation::line_iterator it = tr.begin_line(); + it != tr.end_line();++it) + { + deallog << '.'; + if (it->user_pointer() != p++) + deallog << "Error" << std::endl; + } + deallog << "lines" << std::endl; +} + +/** + * Check if user indices are the same as entered below + */ +template +void +check_user_indices(Triangulation& tr) +{ + // Check if values are the same as below + unsigned int p=1; + for (typename Triangulation::cell_iterator it = tr.begin(); + it != tr.end();++it) + { + deallog << '.'; + if (it->user_index() != p++) + deallog << "Error" << std::endl; + } + deallog << "cells" << std::endl; + + if (dim > 1) + for (typename Triangulation::face_iterator it = tr.begin_face(); + it != tr.end_face();++it) + { + deallog << '.'; + if (it->user_index() != p++) + deallog << "Error" << std::endl; + } + deallog << "faces" << std::endl; + + if (dim > 2) + for (typename Triangulation::line_iterator it = tr.begin_line(); + it != tr.end_line();++it) + { + deallog << '.'; + if (it->user_index() != p++) + deallog << "Error" << std::endl; + } + deallog << "lines" << std::endl; +} + + +template +void +user_pointers(Triangulation& tr) +{ + deallog << "Pointers" << dim << 'D' << std::endl; + + // Fill user pointers with some nonsense + Triangulation* p = &tr; + for (typename Triangulation::cell_iterator it = tr.begin(); + it != tr.end();++it) + it->set_user_pointer(p++); + + if (dim > 1) + for (typename Triangulation::face_iterator it = tr.begin_face(); + it != tr.end_face();++it) + it->set_user_pointer(p++); + + if (dim > 2) + for (typename Triangulation::line_iterator it = tr.begin_line(); + it != tr.end_line();++it) + it->set_user_pointer(p++); + + // Check if they are still the same + check_user_pointers(tr); + // Create two pointer index clashes here + deallog << tr.begin()->user_index() << std::endl; + deallog << tr.begin()->user_pointer() << std::endl; + + + // Check if save and load work + std::vector cell_pointers(tr.n_cells()); + deallog << "Save" << dim << 'D' << std::endl; + tr.save_user_pointers(cell_pointers); + tr.clear_user_data(); + deallog << "Load" << dim << 'D' << std::endl; + tr.load_user_pointers(cell_pointers); + check_user_pointers(tr); +} + + +template +void +user_indices(Triangulation& tr) +{ + deallog << "Indices" << dim << 'D' << std::endl; + + // Fill user pointers with some nonsense + unsigned int p=1; + for (typename Triangulation::cell_iterator it = tr.begin(); + it != tr.end();++it) + it->set_user_index(p++); + + if (dim > 1) + for (typename Triangulation::face_iterator it = tr.begin_face(); + it != tr.end_face();++it) + it->set_user_index(p++); + + if (dim > 2) + for (typename Triangulation::line_iterator it = tr.begin_line(); + it != tr.end_line();++it) + it->set_user_index(p++); + + // Check if they are still the same + check_user_indices(tr); + // Create two pointer index clashes here + deallog << tr.begin()->user_pointer() << std::endl; + deallog << tr.begin()->user_index() << std::endl; + + + // Check if save and load work + std::vector indices(tr.n_cells()); + deallog << "Save" << dim << 'D' << std::endl; + tr.save_user_indices(indices); + tr.clear_user_data(); + deallog << "Load" << dim << 'D' << std::endl; + tr.load_user_indices(indices); + check_user_indices(tr); +} + + +template +void check() +{ + Triangulation tr; + GridGenerator::hyper_cube(tr); + tr.refine_global(2); + + user_pointers(tr); + tr.clear_user_pointers(); + user_indices(tr); +} + + +int main() +{ + deal_II_exceptions::disable_abort_on_exception(); + std::ofstream logfile("user_data_01/output"); + deallog.attach(logfile); + deallog.depth_console(10); + deallog.threshold_double(1.e-10); + + check<2>(); + check<3>(); +} -- 2.39.5