From 8f5f88ab5b016dc535230183eccadea75006fc8a Mon Sep 17 00:00:00 2001 From: hartmann Date: Fri, 30 Jun 2006 12:57:50 +0000 Subject: [PATCH] New objectdim variable. Overload level function. Make sure level() is not called for lines and quads being part of faces. git-svn-id: https://svn.dealii.org/trunk@13321 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/grid/tria_accessor.h | 62 ++++++++++++++ .../include/grid/tria_accessor.templates.h | 20 +++++ deal.II/deal.II/include/grid/tria_iterator.h | 81 +++++++++++++++---- deal.II/deal.II/source/grid/tria_accessor.cc | 16 ++++ 4 files changed, 162 insertions(+), 17 deletions(-) diff --git a/deal.II/deal.II/include/grid/tria_accessor.h b/deal.II/deal.II/include/grid/tria_accessor.h index 8126d60535..06a8834568 100644 --- a/deal.II/deal.II/include/grid/tria_accessor.h +++ b/deal.II/deal.II/include/grid/tria_accessor.h @@ -320,6 +320,14 @@ class TriaAccessor */ const Triangulation *tria; + private: + + /** + * Dimension of the TriaObject + * this accessor gives access to. + */ + static const unsigned int objectdim = dim; + template friend class TriaRawIterator; template friend class TriaIterator; template friend class TriaActiveIterator; @@ -380,6 +388,13 @@ class TriaObjectAccessor : public TriaAccessor * celldim==3. */ void set (const internal::Triangulation::Hexahedron&) const; + + /** + * Return the level the element + * pointed to belongs to. + * This is only valid for cells. + */ + int level () const; /** * Index of vertex. The @@ -838,6 +853,14 @@ class TriaObjectAccessor : public TriaAccessor * previous level is accessed. */ void operator -- (); + + private: + + /** + * Dimension of the TriaObject + * this accessor gives access to. + */ + static const unsigned int objectdim = celldim; /*@}*/ /** @@ -916,6 +939,13 @@ class TriaObjectAccessor<1, dim> : public TriaAccessor */ void set (const internal::Triangulation::Line &l) const; + /** + * Return the level the element + * pointed to belongs to. + * This is only valid for cells. + */ + int level () const; + /** * Return the index of vertex * i=0,1 of a line. @@ -1358,6 +1388,14 @@ class TriaObjectAccessor<1, dim> : public TriaAccessor */ internal::Triangulation::TriaObjects & lines() const; + private: + + /** + * Dimension of the TriaObject + * this accessor gives access to. + */ + static const unsigned int objectdim = 1; + /*@}*/ /** @@ -1400,6 +1438,13 @@ class TriaObjectAccessor<2, dim> : public TriaAccessor * Copy the data of the given quad. */ void set (const internal::Triangulation::Quad &q) const; + + /** + * Return the level the element + * pointed to belongs to. + * This is only valid for cells. + */ + int level () const; /** * Return index of a vertex of a @@ -1893,6 +1938,14 @@ class TriaObjectAccessor<2, dim> : public TriaAccessor * without specialization. */ internal::Triangulation::TriaObjects & quads() const; + + private: + + /** + * Dimension of the TriaObject + * this accessor gives access to. + */ + static const unsigned int objectdim = 2; /*@}*/ /** @@ -2428,6 +2481,14 @@ class TriaObjectAccessor<3, dim> : public TriaAccessor * previous level is accessed. */ void operator -- (); + + private: + + /** + * Dimension of the TriaObject + * this accessor gives access to. + */ + static const unsigned int objectdim = 3; /*@}*/ /** @@ -2814,6 +2875,7 @@ class CellAccessor : public TriaObjectAccessor DeclException0 (ExcCellFlaggedForCoarsening); private: + /** * Copy operator. This is * normally used in a context diff --git a/deal.II/deal.II/include/grid/tria_accessor.templates.h b/deal.II/deal.II/include/grid/tria_accessor.templates.h index 6d11f0602c..712de02843 100644 --- a/deal.II/deal.II/include/grid/tria_accessor.templates.h +++ b/deal.II/deal.II/include/grid/tria_accessor.templates.h @@ -160,6 +160,16 @@ TriaObjectAccessor<1,dim>::lines() const +template +inline +int +TriaObjectAccessor<1,dim>::level () const +{ + return TriaAccessor::level(); +} + + + template inline bool @@ -409,6 +419,16 @@ TriaObjectAccessor<2,dim>::quads() const +template +inline +int +TriaObjectAccessor<2,dim>::level () const +{ + return TriaAccessor::level(); +} + + + template inline bool diff --git a/deal.II/deal.II/include/grid/tria_iterator.h b/deal.II/deal.II/include/grid/tria_iterator.h index a69633518b..8c315f1693 100644 --- a/deal.II/deal.II/include/grid/tria_iterator.h +++ b/deal.II/deal.II/include/grid/tria_iterator.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -480,11 +480,12 @@ class TriaRawIterator : /**@name Exceptions*/ /*@{*/ /** - * Exception + * Exception for TriaObjects with + * level, i.e. cells. */ - DeclException1 (ExcDereferenceInvalidObject, + DeclException1 (ExcDereferenceInvalidCell, Accessor, - << "You tried to dereference an iterator for which this " + << "You tried to dereference a cell iterator for which this " << "is not possible. More information on this iterator: " << "level=" << arg1.level() << ", index=" << arg1.index() @@ -493,6 +494,22 @@ class TriaRawIterator : (arg1.state() == IteratorState::past_the_end ? "past_the_end" : "invalid"))); + /** + * Exception for + * lower-dimensional TriaObjects + * without level, i.e. objects + * faces are constructed with. + */ + DeclException1 (ExcDereferenceInvalidObject, + Accessor, + << "You tried to dereference an iterator for which this " + << "is not possible. More information on this iterator: " + << "index=" << arg1.index() + << ", state=" + << (arg1.state() == IteratorState::valid ? "valid" : + (arg1.state() == IteratorState::past_the_end ? + "past_the_end" : "invalid"))); + #ifdef DEAL_II_NESTED_CLASS_FRIEND_BUG // the above exception class is // supposed to report information @@ -891,8 +908,13 @@ inline const Accessor & TriaRawIterator::operator * () const { - Assert (state() == IteratorState::valid, + Assert (Accessor::objectdim!=dim || + state() == IteratorState::valid, + ExcDereferenceInvalidCell(accessor)); + Assert (Accessor::objectdim==dim || + state() == IteratorState::valid, ExcDereferenceInvalidObject(accessor)); + return accessor; } @@ -903,8 +925,13 @@ inline Accessor & TriaRawIterator::operator * () { - Assert (state() == IteratorState::valid, + Assert (Accessor::objectdim!=dim || + state() == IteratorState::valid, + ExcDereferenceInvalidCell(accessor)); + Assert (Accessor::objectdim==dim || + state() == IteratorState::valid, ExcDereferenceInvalidObject(accessor)); + return accessor; } @@ -945,20 +972,37 @@ inline bool TriaRawIterator::operator < (const TriaRawIterator &i) const { - Assert (state() != IteratorState::invalid, + Assert (Accessor::objectdim!=dim || + state() != IteratorState::invalid, + ExcDereferenceInvalidCell(accessor)); + Assert (Accessor::objectdim==dim || + state() != IteratorState::invalid, ExcDereferenceInvalidObject(accessor)); - Assert (i.state() != IteratorState::invalid, + + Assert (Accessor::objectdim!=dim || + i.state() != IteratorState::invalid, + ExcDereferenceInvalidCell(i.accessor)); + Assert (Accessor::objectdim==dim || + i.state() != IteratorState::invalid, ExcDereferenceInvalidObject(i.accessor)); + Assert (&accessor.get_triangulation() == &i.accessor.get_triangulation(), ExcInvalidComparison()); - - return ((((accessor.level() < i.accessor.level()) || - ((accessor.level() == i.accessor.level()) && - (accessor.index() < i.accessor.index())) ) && - (state()==IteratorState::valid) && - (i.state()==IteratorState::valid) ) || - ((state()==IteratorState::valid) && - (i.state()==IteratorState::past_the_end))); + + if (Accessor::objectdim==dim) + return ((((accessor.level() < i.accessor.level()) || + ((accessor.level() == i.accessor.level()) && + (accessor.index() < i.accessor.index())) ) && + (state()==IteratorState::valid) && + (i.state()==IteratorState::valid) ) || + ((state()==IteratorState::valid) && + (i.state()==IteratorState::past_the_end))); + else + return ((((accessor.index() < i.accessor.index()) ) && + (state()==IteratorState::valid) && + (i.state()==IteratorState::valid) ) || + ((state()==IteratorState::valid) && + (i.state()==IteratorState::past_the_end))); } @@ -993,7 +1037,10 @@ inline void TriaRawIterator::print (std::ostream &out) const { - out << accessor.level() << "." << accessor.index(); + if (Accessor::objectdim==dim) + out << accessor.level() << "." << accessor.index(); + else + out << accessor.index(); } diff --git a/deal.II/deal.II/source/grid/tria_accessor.cc b/deal.II/deal.II/source/grid/tria_accessor.cc index e63c3cfcc8..430e97833c 100644 --- a/deal.II/deal.II/source/grid/tria_accessor.cc +++ b/deal.II/deal.II/source/grid/tria_accessor.cc @@ -25,9 +25,16 @@ #include +template +const unsigned int TriaAccessor::objectdim; + /*------------------------ Functions: LineAccessor ---------------------------*/ +template +const unsigned int TriaObjectAccessor<1, dim>::objectdim; + + template void TriaObjectAccessor<1, dim>::set (const internal::Triangulation::Line &line) const @@ -255,6 +262,10 @@ unsigned int TriaObjectAccessor<1, dim>::number_of_children () const /*------------------------ Functions: QuadAccessor ---------------------------*/ +template +const unsigned int TriaObjectAccessor<2, dim>::objectdim; + + template void TriaObjectAccessor<2, dim>::set (const internal::Triangulation::Quad &quad) const @@ -666,6 +677,11 @@ unsigned int TriaObjectAccessor<2, dim>::number_of_children () const /*------------------------ Functions: TriaObjectAccessor ---------------------------*/ + +template +const unsigned int TriaObjectAccessor<3, dim>::objectdim; + + #if deal_II_dimension == 3 template <> -- 2.39.5