From: kanschat Date: Sun, 25 Apr 2010 23:30:36 +0000 (+0000) Subject: remove specialization of TriaAccessorBase X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba83451b813d1d67d892704e4f847341c1fb0290;p=dealii-svn.git remove specialization of TriaAccessorBase git-svn-id: https://svn.dealii.org/trunk@21035 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/grid/tria_accessor.h b/deal.II/deal.II/include/grid/tria_accessor.h index 2425da41e2..1cfd218748 100644 --- a/deal.II/deal.II/include/grid/tria_accessor.h +++ b/deal.II/deal.II/include/grid/tria_accessor.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -67,22 +67,36 @@ template class TriaAccessor<0, dim, spacedim>; */ namespace TriaAccessorExceptions { +//TODO: Write documentation! /** * @ingroup Exceptions */ DeclException0 (ExcCellNotUsed); /** + * The cell is not an @ref + * GlossActive "active" cell, but + * it already has children. Some + * operations, like setting + * refinement flags or accessing + * degrees of freedom are only + * possible on active cells. + * * @ingroup Exceptions */ DeclException0 (ExcCellNotActive); /** + * Trying to access the children of + * a cell which is in fact active. + * * @ingroup Exceptions */ DeclException0 (ExcCellHasNoChildren); +//TODO: Write documentation! /** * @ingroup Exceptions */ DeclException0 (ExcUnusedCellAsChild); +//TODO: Write documentation! /** * @ingroup Exceptions */ @@ -91,34 +105,49 @@ namespace TriaAccessorExceptions << "You can only set the child index if the cell has no " << "children, or clear it. The given " << "index was " << arg1 << " (-1 means: clear children)"); +//TODO: Write documentation! /** * @ingroup Exceptions */ DeclException0 (ExcUnusedCellAsNeighbor); +//TODO: Write documentation! /** * @ingroup Exceptions */ DeclException0 (ExcUncaughtCase); +//TODO: Write documentation! /** * @ingroup Exceptions */ DeclException0 (ExcDereferenceInvalidObject); +//TODO: Write documentation! /** * @ingroup Exceptions */ DeclException0 (ExcCantCompareIterators); +//TODO: Write documentation! /** * @ingroup Exceptions */ DeclException0 (ExcNeighborIsCoarser); +//TODO: Write documentation! /** * @ingroup Exceptions */ DeclException0 (ExcNeighborIsNotCoarser); /** + * You are trying to access the + * level of a face, but faces have + * no inherent level. The level of + * a face can only be determined by + * the level of an adjacent face, + * which in turn implies that a + * face can have several levels. + * * @ingroup Exceptions */ DeclException0 (ExcFacesHaveNoLevel); +//TODO: Write documentation! /** * @ingroup Exceptions */ @@ -138,19 +167,21 @@ namespace TriaAccessorExceptions * operators and the like), but has no functionality to actually * dereference data. This is done in the derived classes. * - * This template is used for faces and edges, which have no level in - * the triangulation hierarchy associated with them. There exists a - * partial specialization of the current class template where - * structdim (the dimensionality of the object represented, - * for example 1 for a line) equals dim (the dimensionality - * of the space the object lives in, for example 3 if we solve - * three-dimensional problems). + * In the implementation, the behavior of this class differs between + * the cases where structdim==dim (cells of a mesh) and + * structdim<dim (faces and edges). For the latter, + * #present_level is always equal to zero and the constructors may not + * receive a positive value there. For cells, any level is + * possible, but only those within the range of the levels of the + * Triangulation are reasonable. Furthermore, the function objects() + * returns either the container with all cells on the same level or + * the container with all objects of this dimension (structdim<dim). * * Some internals of this class are discussed in @ref IteratorAccessorInternals . * * @ingroup grid * @ingroup Accessors - * @author Wolfgang Bangerth, 1998 + * @author Wolfgang Bangerth, Guido Kanschat, 1998, 2010 */ template class TriaAccessorBase @@ -329,264 +360,6 @@ class TriaAccessorBase * pointed to belongs to. * This is only valid for cells. */ - static int level (); - - /** - * Return the index of the - * element presently pointed to - * on the present level. - */ - int index () const; - - /** - * Return the state of the - * iterator. For the different - * states an accessor can be in, - * refer to the - * TriaRawIterator - * documentation. - */ - IteratorState::IteratorStates state () const; - - /** - * Return a pointer to the - * triangulation which the object - * pointed to by this class - * belongs to. - */ - const Triangulation & get_triangulation () const; - - /** - * @} - */ - protected: - - /** - * Used to store the index of - * the element presently pointed - * to on the level presentl - * used. - */ - int present_index; - - /** - * Pointer to the triangulation - * which we act on. - */ - const Triangulation *tria; - - private: - - template friend class TriaRawIterator; - template friend class TriaIterator; - template friend class TriaActiveIterator; -}; - - - -/** - * A base class for the accessor classes used by TriaRawIterator and - * derived classes. - * - * This class offers only the basic functionality required by the - * iterators (stores the necessary data members, offers comparison - * operators and the like), but has no functionality to actually - * dereference data. This is done in the derived classes. - * - * This template is a partial specialization of the general template - * used for cells only, i.e. for the case where structdim - * (the dimensionality of the object represented, for example 1 for a - * line) equals dim (the dimensionality of the triangulation - * the object lives in, for example 2 if we solve problems on a - * two-dimensional manifold -- whether this manifold is itself the - * space $R^2$ or embedded in a higher-dimensional space whose - * dimensionality is determined by the spacedim template - * argument). The reason for using a partial specialization rather - * than the general template is that cells have a level in the - * triangulation hierarchy associated with them, whereas faces and - * edges do not. - * - * Some internals of this class are discussed in @ref IteratorAccessorInternals . - * - * @ingroup grid - * @ingroup Accessors - * @author Wolfgang Bangerth, 1998 - */ -template -class TriaAccessorBase -{ - public: - /** - * Dimension of the space the - * object represented by this - * accessor lives in. For - * example, if this accessor - * represents a quad that is - * part of a two-dimensional - * surface in four-dimensional - * space, then this value is - * four. - */ - static const unsigned int space_dimension = spacedim; - - /** - * Dimensionality of the object - * that the thing represented by - * this accessopr is part of. For - * example, if this accessor - * represents a line that is part - * of a hexahedron, then this - * value will be three. - */ - static const unsigned int dimension = dim; - - /** - * Dimensionality of the current - * object represented by this - * accessor. For example, if it - * is line (irrespective of - * whether it is part of a quad - * or hex, and what dimension we - * are in), then this value - * equals 1. - */ - static const unsigned int structure_dimension = dim; - - protected: - /** - * Declare the data type that - * this accessor class expects to - * get passed from the iterator - * classes. Since the pure - * triangulation iterators need - * no additional data, this data - * type is @p void. - */ - typedef void AccessorData; - - /** - * Constructor. Protected, thus - * only callable from friend - * classes. - */ - TriaAccessorBase (const Triangulation *parent = 0, - const int level = -1, - const int index = -1, - const AccessorData * = 0); - - /** - * Copy operator. Since this is - * only called from iterators, - * do not return anything, since - * the iterator will return - * itself. - * - * This method is protected, - * since it is only to be called - * from the iterator class. - */ - void copy_from (const TriaAccessorBase &); - - /** - * Copy operator. This is normally - * used in a context like - * iterator a,b; *a=*b;. Since - * the meaning is to copy the object - * pointed to by @p b to the object - * pointed to by @p a and since - * accessors are not real but - * virtual objects, this operation - * is not useful for iterators on - * triangulations. We declare this - * function here private, thus it may - * not be used from outside. - * Furthermore it is not implemented - * and will give a linker error if - * used anyway. - */ - void operator = (const TriaAccessorBase *); - - /** - * Same as above. - */ - TriaAccessorBase & operator = (const TriaAccessorBase &); - - /** - * @name Advancement of iterators - */ - /** - * @{ - */ - - /** - * This operator advances the - * iterator to the next element. - * - * For cells only: - * The next element is next on - * this level if there are - * more. If the present element - * is the last on this level, - * the first on the next level - * is accessed. - */ - void operator ++ (); - - /** - * This operator moves the - * iterator to the previous - * element. - * - * For cells only: - * The previous element is - * previous on this level if - * index>0. If the present - * element is the first on this - * level, the last on the - * previous level is accessed. - */ - void operator -- (); - - /** - * Access to the other objects of - * a Triangulation with same - * dimension. - */ - internal::Triangulation::TriaObjects > & - objects () const; - - protected: - - /** - * Compare for equality. - */ - bool operator == (const TriaAccessorBase &) const; - - /** - * Compare for inequality. - */ - bool operator != (const TriaAccessorBase &) const; - - public: - /** - * Data type to be used for passing - * parameters from iterators to the - * accessor classes in a unified - * way, no matter what the type of - * number of these parameters is. - */ - typedef void * LocalData; - - /** @name Iterator address and state - */ - /** - * @{ - */ - /** - * Return the level the element - * pointed to belongs to. - * This is only valid for cells. - */ int level () const; /** @@ -619,10 +392,9 @@ class TriaAccessorBase */ protected: /** - * Used to store the level - * presently pointed to. For - * faces this should always be - * 0. + * The level if this is a cell + * (structdim==dim). Else, + * contains zero. */ int present_level; @@ -639,17 +411,16 @@ class TriaAccessorBase * which we act on. */ const Triangulation *tria; - + private: template friend class TriaRawIterator; template friend class TriaIterator; template friend class TriaActiveIterator; - - template friend class TriaAccessor; }; + /** * A class that represents accessor objects to iterators that don't * make sense such as quad iterators in on 1d meshes. This class can 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 c9055a63a8..cc1b026487 100644 --- a/deal.II/deal.II/include/grid/tria_accessor.templates.h +++ b/deal.II/deal.II/include/grid/tria_accessor.templates.h @@ -32,22 +32,27 @@ DEAL_II_NAMESPACE_OPEN template inline -TriaAccessorBase::TriaAccessorBase (const Triangulation *parent, - const int level, - const int index, - const AccessorData *) +TriaAccessorBase::TriaAccessorBase ( + const Triangulation* tria, + const int level, + const int index, + const AccessorData*) : + present_level((structdim==dim) ? level : 0), present_index (index), - tria (parent) + tria (tria) { - + // non-cells have no level, so a 0 // should have been passed, or a -1 // for an end-iterator, or -2 for // an invalid (default constructed) // iterator - Assert ((level == 0) || (level == -1) || (level == -2), - ExcInternalError()); + if (structdim != dim) + { + Assert ((level == 0) || (level == -1) || (level == -2), + ExcInternalError()); + } } @@ -57,8 +62,34 @@ inline void TriaAccessorBase::copy_from (const TriaAccessorBase &a) { + present_level = a.present_level; present_index = a.present_index; tria = a.tria; + + if (structdim != dim) + { + Assert ((present_level == 0) || (present_level == -1) || (present_level == -2), + ExcInternalError()); + } +} + + + +template +inline +TriaAccessorBase& +TriaAccessorBase::operator= (const TriaAccessorBase &a) +{ + present_level = a.present_level; + present_index = a.present_index; + tria = a.tria; + + if (structdim != dim) + { + Assert ((present_level == 0) || (present_level == -1) || (present_level == -2), + ExcInternalError()); + } + return *this; } @@ -69,7 +100,8 @@ bool TriaAccessorBase::operator == (const TriaAccessorBase &a) const { Assert (tria == a.tria, TriaAccessorExceptions::ExcCantCompareIterators()); - return (present_index == a.present_index); + return ((present_level == a.present_level) && + (present_index == a.present_index)); } @@ -80,7 +112,8 @@ bool TriaAccessorBase::operator != (const TriaAccessorBase &a) const { Assert (tria == a.tria, TriaAccessorExceptions::ExcCantCompareIterators()); - return (present_index != a.present_index); + return ((present_level != a.present_level) || + (present_index != a.present_index)); } @@ -88,9 +121,11 @@ TriaAccessorBase::operator != (const TriaAccessorBase inline int -TriaAccessorBase::level () +TriaAccessorBase::level () const { - return 0; + // This is always zero or invalid + // if the object is not a cell + return present_level; } @@ -110,7 +145,7 @@ inline IteratorState::IteratorStates TriaAccessorBase::state () const { - if (present_index>=0) + if ((present_level>=0) && (present_index>=0)) return IteratorState::valid; else if (present_index==-1) @@ -139,15 +174,38 @@ TriaAccessorBase::operator ++ () // this iterator is used for // objects without level ++this->present_index; - // is index still in the range of - // the vector? (note that we don't - // have to set the level, since - // dim!=1 and the object therefore - // has no level) - if (this->present_index - >= - static_cast(objects().cells.size())) - this->present_index = -1; + + if (structdim != dim) + { + // is index still in the range of + // the vector? (note that we don't + // have to set the level, since + // dim!=1 and the object therefore + // has no level) + if (this->present_index + >= + static_cast(objects().cells.size())) + this->present_index = -1; + } + else + { + while (this->present_index + >= + static_cast(this->tria->levels[this->present_level]->cells.cells.size())) + { + // no -> go one level up until we find + // one with more than zero cells + ++this->present_level; + this->present_index = 0; + // highest level reached? + if (this->present_level >= static_cast(this->tria->levels.size())) + { + // return with past the end pointer + this->present_level = this->present_index = -1; + return; + } + } + } } @@ -159,8 +217,28 @@ TriaAccessorBase::operator -- () // same as operator++ --this->present_index; - if (this->present_index < 0) - this->present_index = -1; + if (structdim != dim) + { + if (this->present_index < 0) + this->present_index = -1; + } + else + { + while (this->present_index < 0) + { + // no -> go one level down + --this->present_level; + // lowest level reached? + if (this->present_level == -1) + { + // return with past the end pointer + this->present_level = this->present_index = -1; + return; + } + // else + this->present_index = this->tria->levels[this->present_level]->cells.cells.size()-1; + } + } } @@ -175,209 +253,110 @@ namespace internal */ template inline - internal::Triangulation::TriaObjects > & + internal::Triangulation::TriaObjects >* get_objects (internal::Triangulation::TriaFaces *faces, const internal::int2type<1>) { - return faces->lines; + return &faces->lines; } template inline - internal::Triangulation::TriaObjects > & + internal::Triangulation::TriaObjects >* get_objects (internal::Triangulation::TriaFaces *faces, const internal::int2type<2>) { - return faces->quads; + return &faces->quads; } - } -} - - - - -template -inline -internal::Triangulation::TriaObjects > & -TriaAccessorBase::objects() const -{ - // get sub-objects. note that the - // current class is only used for - // objects that are *not* cells - return internal::TriaAccessorBase::get_objects (this->tria->faces, - internal::int2type ()); -} - - - - -/*------------------------ Functions: TriaAccessorBase ---------------------------*/ - -template -inline -TriaAccessorBase::TriaAccessorBase (const Triangulation *parent, - const int level, - const int index, - const AccessorData *) - : - present_level (level), - present_index (index), - tria (parent) -{} - - - -template -inline -void -TriaAccessorBase::copy_from (const TriaAccessorBase &a) -{ - present_level = a.present_level; - present_index = a.present_index; - tria = a.tria; -} - - - -template -inline -bool -TriaAccessorBase::operator == (const TriaAccessorBase &a) const -{ - Assert (tria == a.tria, TriaAccessorExceptions::ExcCantCompareIterators()); - return ((present_index == a.present_index) && - (present_level == a.present_level)); -} - - - -template -inline -bool -TriaAccessorBase::operator != (const TriaAccessorBase &a) const -{ - Assert (tria == a.tria, TriaAccessorExceptions::ExcCantCompareIterators()); - return ((present_index != a.present_index) || - (present_level != a.present_level)); -} - - - -template -inline -int -TriaAccessorBase::level () const -{ - return present_level; -} - - - -template -inline -int -TriaAccessorBase::index () const -{ - return present_index; -} - - - -template -inline -IteratorState::IteratorStates -TriaAccessorBase::state () const -{ - if ((present_level>=0) && (present_index>=0)) - return IteratorState::valid; - else - if ((present_index==-1) && (present_index==-1)) - return IteratorState::past_the_end; - else - return IteratorState::invalid; -} - - - -template -inline -const Triangulation & -TriaAccessorBase::get_triangulation () const -{ - return *tria; -} - - - -template -inline -void -TriaAccessorBase::operator ++ () -{ - // in structdim == dim, so we have - // cells here. these have levels - ++this->present_index; - // is index still in the range of - // the vector? - while (this->present_index - >= - static_cast(this->tria->levels[this->present_level]->cells.cells.size())) + + inline + internal::Triangulation::TriaObjects >* + get_objects (internal::Triangulation::TriaFaces<1>*, + const internal::int2type<1>) { - // no -> go one level up until we find - // one with more than zero cells - ++this->present_level; - this->present_index = 0; - // highest level reached? - if (this->present_level >= static_cast(this->tria->levels.size())) - { - // return with past the end pointer - this->present_level = this->present_index = -1; - return; - } + Assert (false, ExcInternalError()); + return 0; + } + + inline + internal::Triangulation::TriaObjects >* + get_objects (internal::Triangulation::TriaFaces<2>*, + const internal::int2type<2>) + { + Assert (false, ExcInternalError()); + return 0; + } + + inline + internal::Triangulation::TriaObjects >* + get_objects (internal::Triangulation::TriaFaces<3>*, + const internal::int2type<3>) + { + Assert (false, ExcInternalError()); + return 0; + } + + /** + * This function should never be + * used, but we need it for the + * template instantiation of TriaAccessorBase::objects() const + */ + template + inline + internal::Triangulation::TriaObjects >* + get_objects (internal::Triangulation::TriaFaces *faces, + const internal::int2type<3>) + { + Assert (false, ExcInternalError()); + return 0; } -} + /** + * Copy the above functions for + * cell objects. + */ + template + inline + internal::Triangulation::TriaObjects >* + get_objects (internal::Triangulation::TriaObjects >*, + const internal::int2type) + { + Assert (false, ExcInternalError()); + return 0; + } -template -inline -void -TriaAccessorBase::operator -- () -{ - // same as operator++ - --this->present_index; - // is index still in the range of - // the vector? - while (this->present_index < 0) + template + inline + internal::Triangulation::TriaObjects >* + get_objects (internal::Triangulation::TriaObjects >* cells, + const internal::int2type) { - // no -> go one level down - --this->present_level; - // lowest level reached? - if (this->present_level == -1) - { - // return with past the end pointer - this->present_level = this->present_index = -1; - return; - } - // else - this->present_index = this->tria->levels[this->present_level]->cells.cells.size()-1; + return cells; } + } } -template +template inline -internal::Triangulation::TriaObjects > & -TriaAccessorBase::objects() const +internal::Triangulation::TriaObjects > & +TriaAccessorBase::objects() const { - return this->tria->levels[this->present_level]->cells; + if (structdim != dim) + // get sub-objects. note that the + // current class is only used for + // objects that are *not* cells + return *internal::TriaAccessorBase::get_objects (this->tria->faces, + internal::int2type ()); + else + return *internal::TriaAccessorBase::get_objects (&this->tria->levels[this->present_level]->cells, + internal::int2type ()); } - - /*------------------------ Functions: InvalidAccessor ---------------------------*/ template diff --git a/deal.II/deal.II/include/grid/tria_iterator_selector.h b/deal.II/deal.II/include/grid/tria_iterator_selector.h index 7885d63ec7..eb34f7c931 100644 --- a/deal.II/deal.II/include/grid/tria_iterator_selector.h +++ b/deal.II/deal.II/include/grid/tria_iterator_selector.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 by the deal.II authors +// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2010 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -20,7 +20,6 @@ DEAL_II_NAMESPACE_OPEN template class CellAccessor; template class TriaAccessorBase; -template class TriaAccessorBase; template class InvalidAccessor; template class TriaAccessor; template class TriaAccessor<0, dim, spacedim>;