From 340c5cbfc60d30d819d12e2b4b90f2461d220658 Mon Sep 17 00:00:00 2001 From: Bruno Turcksin Date: Fri, 18 Sep 2015 17:09:12 -0500 Subject: [PATCH] Add TriaAccessor<0,dim,spacedim>. --- include/deal.II/grid/tria_accessor.h | 353 +++++++++++++++- .../deal.II/grid/tria_accessor.templates.h | 382 ++++++++++++++++++ source/grid/tria_accessor.cc | 96 +++++ 3 files changed, 822 insertions(+), 9 deletions(-) diff --git a/include/deal.II/grid/tria_accessor.h b/include/deal.II/grid/tria_accessor.h index dd59f11ea5..c511023fc9 100644 --- a/include/deal.II/grid/tria_accessor.h +++ b/include/deal.II/grid/tria_accessor.h @@ -627,6 +627,12 @@ 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; + /** * Return the global index of i-th vertex of the current object. The * convention regarding the numbering of vertices is laid down in the @@ -1468,19 +1474,350 @@ private: /** - * Closure class to stop induction of classes. Should never be called and thus - * produces an error when created. + * Specialization of TriaAccessor. + * This class represent vertices in a triangulation of dimensionality + * 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 + * spacedim@>dim the triangulation is of a manifold embedded in + * a higher dimensional space). * - * @ingroup grid + * @ingroup Accessors + * @author Bruno Turcksin, 2015 */ template class TriaAccessor<0, dim, spacedim> { -private: +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 = 0; + + /** + * Pointer to internal data. + */ + typedef void AccessorData; + + /** + * Constructor. The second argument is the global index of the vertex we point to. + */ + TriaAccessor (const Triangulation *tria, + const unsigned int vertex_index); + + /** + * 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. + */ + TriaAccessor (const Triangulation *tria = NULL, + const int = 0, + const int = 0, + const AccessorData * = 0); + + /** + * Constructor. Should never be called and thus produces an error. + */ + template + TriaAccessor (const TriaAccessor &); + + /** + * Constructor. Should never be called and thus produces an error. + */ + template + TriaAccessor (const InvalidAccessor &); + + /** + * Return the state of the iterator. Since an iterator to points can not be + * incremented or decremented, its state remains constant, and in particular + * equal to IteratorState::valid. + */ + static IteratorState::IteratorStates state (); + + /** + * Level of this object. Vertices have no level, so this function always + * returns zero. + */ + static int level (); + + /** + * Index of this object. Returns the global index of the vertex this object + * points to. + */ + int index () const; + + /** + * @name Advancement of iterators + */ + /** + * @{ + */ + /** + * This operator advances the iterator to the next element. For points, this + * operation is not defined, so you can't iterate over point iterators. + */ + void operator ++ () const; + + /** + * This operator moves the iterator to the previous element. For points, + * this operation is not defined, so you can't iterate over point iterators. + */ + void operator -- () const; + /** + * Compare for equality. + */ + bool operator == (const TriaAccessor &) const; + + /** + * Compare for inequality. + */ + bool operator != (const TriaAccessor &) const; + + /** + * @} + */ + + + /** + * @name Accessing sub-objects + */ + /** + * @{ + */ + + /** + * Return the global index of i-th vertex of the current object. If @p i is + * zero, this returns the index of the current point to which this object + * refers. Otherwise, it throws an exception. + * + * Note that the returned value is only the index of the geometrical vertex. + * It has nothing to do with possible degrees of freedom associated with it. + * For this, see the @p DoFAccessor::vertex_dof_index functions. + * + * @note Despite the name, the index returned here is only global in the + * sense that it is specific to a particular Triangulation object or, in the + * case the triangulation is actually of type + * parallel::distributed::Triangulation, specific to that part of the + * distributed triangulation stored on the current processor. + */ + unsigned int vertex_index (const unsigned int i = 0) const; + + /** + * Return a reference to the @p ith vertex. If i is zero, this returns a + * reference to the current point to which this object refers. Otherwise, it + * throws an exception. + */ + Point &vertex (const unsigned int i = 0) const; + + /** + * Pointer to the @p ith line bounding this object. Will point to an invalid + * object. + */ + typename dealii::internal::Triangulation::Iterators::line_iterator + static line (const unsigned int); + + /** + * Line index of the @p ith line bounding this object. Throws an exception. + */ + static unsigned int line_index (const unsigned int i); + + /** + * Pointer to the @p ith quad bounding this object. + */ + static + typename dealii::internal::Triangulation::Iterators::quad_iterator + quad (const unsigned int i); + + /** + * Quad index of the @p ith quad bounding this object. Throws an excption. + */ + static unsigned int quad_index (const unsigned int i); + + /** + * @} + */ + + + /** + * @name Geometric information about an object + */ + /** + * @{ + */ + + /** + * Diameter of the object. This function always returns zero. + */ + double diameter () const; + + /** + * Length of an object in the direction of the given axis, specified in the + * local coordinate system. See the documentation of GeometryInfo for the + * meaning and enumeration of the local axes. + * + * This function always returns zero. + */ + double extent_in_direction (const unsigned int axis) const; + + /** + * Return the center of this object, which of course coincides with the + * location of the vertex this object refers to. The parameters + * @p respect_manifold and @p use_laplace_transformation are not used. They + * are there to provide the same interface as + * TriaAccessor. + */ + Point center (const bool respect_manifold=false, + const bool use_laplace_transformation=false) const; + + /** + * Compute the dim-dimensional measure of the object. For a dim-dimensional + * cell in dim-dimensional space, this equals its volume. On the other hand, + * for a 2d cell in 3d space, or if the current object pointed to is a 2d + * face of a 3d cell in 3d space, then the function computes the area the + * object occupies. For a one-dimensional object, return its length. For a + * zero-dimensional object, return zero. + */ + double measure () const; + /** + * @} + */ + + /** + * @name Orientation of sub-objects + */ + /** + * @{ + */ + + /** + * @brief Always return false + */ + static bool face_orientation (const unsigned int face); + + /** + * @brief Always return false + */ + static bool face_flip (const unsigned int face); + + /** + * @brief Always return false + */ + static bool face_rotation (const unsigned int face); + + /** + * @brief Always return false + */ + static bool line_orientation (const unsigned int line); + + /** + * @} + */ + + /** + * @name Accessing children + */ + /** + * @{ + */ + + /** + * Test whether the object has children. Always false. + */ + static bool has_children (); + + /** + * Return the number of immediate children of this object. This is always + * zero. + */ + static unsigned int n_children(); + + /** + * Compute and return the number of active descendants of this objects. + * Always zero. + */ + static unsigned int number_of_children (); + + /** + * Return the number of times that this object is refined. Always 0. + */ + static unsigned int max_refinement_depth (); + + /** + * @brief Return an invalid object. + */ + static + TriaIterator > + child (const unsigned int); + + /** + * @brief Return an invalid object. + */ + static + TriaIterator > + isotropic_child (const unsigned int); + + /** + * Always return no refinement. + */ + static + RefinementCase<0> refinement_case (); + /** - * Constructor. Made private to make sure that this class can't be used. + * @brief Returns -1 */ - TriaAccessor (); + static + int child_index (const unsigned int i); + + /** + * @brief Returns -1 + */ + static + int isotropic_child_index (const unsigned int i); + /** + * @} + */ + + /** + * Return whether the vertex pointed to here is used. + */ + bool used () const; + +protected: + /** + * 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 TriaAccessor &); + + /** + * Pointer to the triangulation we operate on. + */ + const Triangulation *tria; + + /** + * The global vertex index of the vertex this object corresponds to. + */ + unsigned int global_vertex_index; }; @@ -1491,6 +1828,7 @@ private: * example, you can't iterate from one such point to the next. Point also * don't have children, and they don't have neighbors. * + * @ingroup Accessors * @author Wolfgang Bangerth, 2010 */ template @@ -1574,9 +1912,6 @@ public: /** * 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 TriaAccessor &); diff --git a/include/deal.II/grid/tria_accessor.templates.h b/include/deal.II/grid/tria_accessor.templates.h index 641ecb9494..cf34952b60 100644 --- a/include/deal.II/grid/tria_accessor.templates.h +++ b/include/deal.II/grid/tria_accessor.templates.h @@ -2112,6 +2112,388 @@ is_translation_of (const TriaIterator > &o) } +/*------------------------ Functions: TriaAccessor<0,dim,spacedim> -----------------------*/ + +template +inline +TriaAccessor<0, dim, spacedim>:: +TriaAccessor (const Triangulation *tria, + const unsigned int vertex_index) + : + tria (tria), + global_vertex_index (vertex_index) +{} + + + +template +inline +TriaAccessor<0, dim, spacedim>:: +TriaAccessor (const Triangulation *tria, + const int level, + const int index, + const AccessorData *) + : + tria (NULL), + global_vertex_index (numbers::invalid_unsigned_int) +{ + Assert(false, ExcImpossibleInDim(0)); +} + + + +template +template +inline +TriaAccessor<0, dim, spacedim>:: +TriaAccessor (const TriaAccessor &) + : + tria (NULL), + global_vertex_index (numbers::invalid_unsigned_int) +{ + Assert(false, ExcImpossibleInDim(0)); +} + + + +template +template +inline +TriaAccessor<0, dim, spacedim>:: +TriaAccessor (const InvalidAccessor &) + : + tria (NULL), + global_vertex_index (numbers::invalid_unsigned_int) +{ + Assert(false, ExcImpossibleInDim(0)); +} + + + +template +inline +void +TriaAccessor<0, dim, spacedim>::copy_from (const TriaAccessor &t) +{ + tria = t.tria; + global_vertex_index = t.global_vertex_index; +} + + + +template +inline +IteratorState::IteratorStates +TriaAccessor<0, dim, spacedim>::state () +{ + return IteratorState::valid; +} + + + +template +inline +int +TriaAccessor<0, dim, spacedim>::level () +{ + return 0; +} + + + +template +inline +int +TriaAccessor<0, dim, spacedim>::index () const +{ + return global_vertex_index; +} + + + +template +inline +void +TriaAccessor<0, dim, spacedim>::operator ++ () const +{ + Assert (false, ExcNotImplemented()); +} + + + +template +inline +void +TriaAccessor<0, dim, spacedim>::operator -- () const +{ + Assert (false, ExcNotImplemented()); +} + + + +template +inline +bool +TriaAccessor<0, dim, spacedim>::operator == (const TriaAccessor &t) const +{ + const bool result = ((tria == t.tria) + && + (global_vertex_index == t.global_vertex_index)); + + return result; +} + + + +template +inline +bool +TriaAccessor<0, dim, spacedim>::operator != (const TriaAccessor &t) const +{ + return !(*this==t); +} + + + +template +inline +unsigned int +TriaAccessor<0, dim, spacedim>::vertex_index (const unsigned int i) const +{ + Assert(i==0, ExcIndexRange(i, 0, 1)); + (void)i; + return global_vertex_index; +} + + + +template +inline +Point & +TriaAccessor<0, dim, spacedim>::vertex (const unsigned int i) const +{ + Assert(i==0, ExcIndexRange(i, 0, 1)); + (void)i; + return const_cast &> (this->tria->vertices[global_vertex_index]); +} + + + +template +inline +typename dealii::internal::Triangulation::Iterators::line_iterator +TriaAccessor<0, dim, spacedim>::line (const unsigned int) +{ + return typename dealii::internal::Triangulation::Iterators::line_iterator(); +} + + + +template +inline +unsigned int +TriaAccessor<0, dim, spacedim>::line_index (const unsigned int) +{ + Assert(false, ExcImpossibleInDim(0)); + return numbers::invalid_unsigned_int; +} + + + +template +inline +typename dealii::internal::Triangulation::Iterators::quad_iterator +TriaAccessor<0, dim, spacedim>::quad (const unsigned int) +{ + return typename dealii::internal::Triangulation::Iterators::quad_iterator(); +} + + + +template +inline +unsigned int +TriaAccessor<0, dim, spacedim>::quad_index (const unsigned int) +{ + Assert(false, ExcImpossibleInDim(0)); + return numbers::invalid_unsigned_int; +} + + + +template +inline +double +TriaAccessor<0, dim, spacedim>::diameter () const +{ + return 0.; +} + + + +template +inline +double +TriaAccessor<0, dim, spacedim>::extent_in_direction (const unsigned int axis) const +{ + (void) axis; + return 0.; +} + + + +template +inline +Point +TriaAccessor<0, dim, spacedim>::center (const bool respect_manifold, + const bool use_laplace_transformation) const +{ + // Silence warning + (void) respect_manifold; + (void) use_laplace_transformation; + return this->tria->vertices[global_vertex_index]; +} + + + +template +inline +double +TriaAccessor<0, dim, spacedim>::measure () const +{ + return 0.; +} + + + +template +inline +bool TriaAccessor<0, dim, spacedim>::face_orientation (const unsigned int /*face*/) +{ + return false; +} + + + +template +inline +bool TriaAccessor<0, dim, spacedim>::face_flip (const unsigned int /*face*/) +{ + return false; +} + + + +template +inline +bool TriaAccessor<0, dim, spacedim>::face_rotation (const unsigned int /*face*/) +{ + return false; +} + + + +template +inline +bool TriaAccessor<0, dim, spacedim>::line_orientation (const unsigned int /*line*/) +{ + return false; +} + + + +template +inline +bool TriaAccessor<0, dim, spacedim>::has_children () +{ + return false; +} + + + +template +inline +unsigned int TriaAccessor<0, dim, spacedim>::n_children() +{ + return 0; +} + + + +template +inline +unsigned int TriaAccessor<0, dim, spacedim>::number_of_children () +{ + return 0; +} + + + +template +inline +unsigned int TriaAccessor<0, dim, spacedim>::max_refinement_depth () +{ + return 0; +} + + + +template +inline +TriaIterator > +TriaAccessor<0, dim, spacedim>::child (const unsigned int) +{ + return TriaIterator >(); +} + + + +template +inline +TriaIterator > +TriaAccessor<0, dim, spacedim>::isotropic_child (const unsigned int) +{ + return TriaIterator >(); +} + + + +template +inline +RefinementCase<0> TriaAccessor<0, dim, spacedim>::refinement_case () +{ + return RefinementCase<0>(RefinementPossibilities<0>::no_refinement); +} + + + +template +inline +int TriaAccessor<0, dim, spacedim>::child_index (const unsigned int) +{ + return -1; +} + + + +template +inline +int TriaAccessor<0, dim, spacedim>::isotropic_child_index (const unsigned int) +{ + return -1; +} + + + +template +inline +bool TriaAccessor<0, dim, spacedim>::used () const +{ + return tria->vertex_used(global_vertex_index); +} + + + /*------------------------ Functions: TriaAccessor<0,1,spacedim> -----------------------*/ template diff --git a/source/grid/tria_accessor.cc b/source/grid/tria_accessor.cc index 361924f548..d5d196ae16 100644 --- a/source/grid/tria_accessor.cc +++ b/source/grid/tria_accessor.cc @@ -1082,6 +1082,102 @@ 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:: -- 2.39.5