From 46f38acdd743fd5a671384706eaeadd27b6cf6f5 Mon Sep 17 00:00:00 2001 From: Bruno Turcksin Date: Mon, 21 Sep 2015 12:29:51 -0500 Subject: [PATCH] Change interface of vertex_accessor and add test. --- include/deal.II/grid/tria_accessor.h | 17 ++-- .../deal.II/grid/tria_accessor.templates.h | 19 +++- include/deal.II/grid/tria_iterator_selector.h | 12 +++ source/grid/tria_accessor.cc | 96 ------------------- tests/grid/vertex_iterator.cc | 54 +++++++++++ tests/grid/vertex_iterator.output | 65 +++++++++++++ 6 files changed, 154 insertions(+), 109 deletions(-) create mode 100644 tests/grid/vertex_iterator.cc create mode 100644 tests/grid/vertex_iterator.output diff --git a/include/deal.II/grid/tria_accessor.h b/include/deal.II/grid/tria_accessor.h index c511023fc9..70f74cc865 100644 --- a/include/deal.II/grid/tria_accessor.h +++ b/include/deal.II/grid/tria_accessor.h @@ -631,7 +631,8 @@ public: * Pointer to the @p ith vertex bounding this object. Throw an exception if * dim=1. */ - TriaAccessor<0,dim,spacedim> vertex_accessor (const unsigned int i) const; + typename dealii::internal::Triangulation::Iterators::vertex_iterator + vertex_it (const unsigned int i) const; /** * Return the global index of i-th vertex of the current object. The @@ -1479,7 +1480,7 @@ private: * dim (i.e. 1 for a triangulation of lines, 2 for a triangulation * of quads, and 3 for a triangulation of hexes) that is embedded in a space of * dimensionality spacedim (for spacedim==dim the - * triangulation represents a domain in $R^{dim}$, for + * triangulation represents a domain in ${\mathbb R}^\text{dim}$, for * spacedim@>dim the triangulation is of a manifold embedded in * a higher dimensional space). * @@ -1524,13 +1525,13 @@ public: /** * Constructor. This constructor exists in order to maintain interface - * compatibility with the other accessor classes. However, it doesn't do - * anything useful here and so may not actually be called. + * compatibility with the other accessor classes. @p index can be used to set + * the global index of the vertex we point to. */ - TriaAccessor (const Triangulation *tria = NULL, - const int = 0, - const int = 0, - const AccessorData * = 0); + TriaAccessor (const Triangulation *tria = NULL, + const int level = 0, + const int index = 0, + const AccessorData * = 0); /** * Constructor. Should never be called and thus produces an error. diff --git a/include/deal.II/grid/tria_accessor.templates.h b/include/deal.II/grid/tria_accessor.templates.h index cf34952b60..249d03edee 100644 --- a/include/deal.II/grid/tria_accessor.templates.h +++ b/include/deal.II/grid/tria_accessor.templates.h @@ -1160,6 +1160,17 @@ TriaAccessor::used () const +template +inline +typename dealii::internal::Triangulation::Iterators::vertex_iterator +TriaAccessor::vertex_it (const unsigned int i) const +{ + return typename dealii::internal::Triangulation::Iterators::vertex_iterator + (this->tria, 0, vertex_index (i)); +} + + + template unsigned int TriaAccessor:: @@ -2134,11 +2145,9 @@ TriaAccessor (const Triangulation *tria, const int index, const AccessorData *) : - tria (NULL), - global_vertex_index (numbers::invalid_unsigned_int) -{ - Assert(false, ExcImpossibleInDim(0)); -} + tria (tria), + global_vertex_index (index) +{} diff --git a/include/deal.II/grid/tria_iterator_selector.h b/include/deal.II/grid/tria_iterator_selector.h index 5b3702a1d7..6a990a7b1d 100644 --- a/include/deal.II/grid/tria_iterator_selector.h +++ b/include/deal.II/grid/tria_iterator_selector.h @@ -43,6 +43,9 @@ namespace internal * @ref Iterators * module for more information. * + * A @p vertex_iterator is typedef'd to an iterator operating on the @p + * vertices member variable of a Triangulation<1> object. + * * A @p line_iterator is typedef'd to an iterator operating on the @p * lines member variable of a Triangulation<1> object. An @p * active_line_iterator only operates on the active lines. @p @@ -70,6 +73,8 @@ namespace internal template struct Iterators<1,spacedim> { + typedef TriaIterator > vertex_iterator; + typedef TriaRawIterator > raw_line_iterator; typedef TriaIterator > line_iterator; typedef TriaActiveIterator > active_line_iterator; @@ -93,6 +98,9 @@ namespace internal * @ref Iterators * module for more information. * + * A @p vertex_iterator is typedef'd to an iterator operating on the @p + * vertices member variable of a Triangulation<2> object. + * * A @p line_iterator is typedef'd to an iterator operating on the @p * lines member variable of a Triangulation<2> object. An @p * active_line_iterator only operates on the active lines. @p @@ -126,6 +134,8 @@ namespace internal template struct Iterators<2,spacedim> { + typedef TriaIterator > vertex_iterator; + typedef TriaRawIterator > raw_line_iterator; typedef TriaIterator > line_iterator; typedef TriaActiveIterator > active_line_iterator; @@ -166,6 +176,8 @@ namespace internal template struct Iterators<3,spacedim> { + typedef TriaIterator > vertex_iterator; + typedef TriaRawIterator > raw_line_iterator; typedef TriaIterator > line_iterator; typedef TriaActiveIterator > active_line_iterator; diff --git a/source/grid/tria_accessor.cc b/source/grid/tria_accessor.cc index d5d196ae16..361924f548 100644 --- a/source/grid/tria_accessor.cc +++ b/source/grid/tria_accessor.cc @@ -1082,102 +1082,6 @@ set (const internal::Triangulation::TriaObject &object) const -template <> -TriaAccessor<0,1,1> -TriaAccessor<1,1,1>::vertex_accessor (const unsigned int i) const -{ - // Silence a warning - (void) i; - return TriaAccessor<0,1,1>(); -} - - - -template <> -TriaAccessor<0,1,2> -TriaAccessor<1,1,2>::vertex_accessor (const unsigned int i) const -{ - // Silence a warning - (void) i; - return TriaAccessor<0,1,2>(); -} - - - -template <> -TriaAccessor<0,1,3> -TriaAccessor<1,1,3>::vertex_accessor (const unsigned int i) const -{ - // Silence a warning - (void) i; - return TriaAccessor<0,1,3>(); -} - - - -template <> -TriaAccessor<0,2,2> -TriaAccessor<1,2,2>::vertex_accessor (const unsigned int i) const -{ - return TriaAccessor<0,2,2>(this->tria, vertex_index (i)); -} - - - -template <> -TriaAccessor<0,2,3> -TriaAccessor<1,2,3>::vertex_accessor (const unsigned int i) const -{ - return TriaAccessor<0,2,3>(this->tria, vertex_index (i)); -} - - - -template <> -TriaAccessor<0,3,3> -TriaAccessor<1,3,3>::vertex_accessor (const unsigned int i) const -{ - return TriaAccessor<0,3,3>(this->tria, vertex_index (i)); -} - - - -template <> -TriaAccessor<0,2,2> -TriaAccessor<2,2,2>::vertex_accessor (const unsigned int i) const -{ - return TriaAccessor<0,2,2>(this->tria, vertex_index (i)); -} - - - -template <> -TriaAccessor<0,2,3> -TriaAccessor<2,2,3>::vertex_accessor (const unsigned int i) const -{ - return TriaAccessor<0,2,3>(this->tria, vertex_index (i)); -} - - - -template <> -TriaAccessor<0,3,3> -TriaAccessor<2,3,3>::vertex_accessor (const unsigned int i) const -{ - return TriaAccessor<0,3,3>(this->tria, vertex_index (i)); -} - - - -template <> -TriaAccessor<0,3,3> -TriaAccessor<3,3,3>::vertex_accessor (const unsigned int i) const -{ - return TriaAccessor<0,3,3>(this->tria, vertex_index (i)); -} - - - template Point TriaAccessor:: diff --git a/tests/grid/vertex_iterator.cc b/tests/grid/vertex_iterator.cc new file mode 100644 index 0000000000..4372685c82 --- /dev/null +++ b/tests/grid/vertex_iterator.cc @@ -0,0 +1,54 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2015 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. +// +// --------------------------------------------------------------------- + + +// test TriaAccessor<0,dim,spacedim> + + +#include "../tests.h" +#include +#include +#include +#include + +#include + + +void test () +{ + Triangulation<2> tria; + GridGenerator::hyper_cube (tria); + tria.refine_global (2); + + for (typename Triangulation<2>::active_cell_iterator + cell = tria.begin_active(); cell != tria.end(); ++cell) + { + for (unsigned int i = 0; i<4; ++i) + deallog << cell->vertex_it(i)->center() <