From 8f7b51ba9ca5f25d5d807b62fcb939df9b872786 Mon Sep 17 00:00:00 2001 From: kanschat Date: Wed, 2 May 2007 13:26:28 +0000 Subject: [PATCH] data structures prepared for user index git-svn-id: https://svn.dealii.org/trunk@14661 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/grid/tria_objects.h | 180 +++++++++++++++++-- deal.II/deal.II/source/grid/tria.cc | 36 +--- deal.II/deal.II/source/grid/tria_accessor.cc | 18 +- deal.II/deal.II/source/grid/tria_objects.cc | 49 ++--- 4 files changed, 212 insertions(+), 71 deletions(-) diff --git a/deal.II/deal.II/include/grid/tria_objects.h b/deal.II/deal.II/include/grid/tria_objects.h index ce6ca946b5..c8b001f9ec 100644 --- a/deal.II/deal.II/include/grid/tria_objects.h +++ b/deal.II/deal.II/include/grid/tria_objects.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2006 by the deal.II authors +// Copyright (C) 2006, 2007 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -46,13 +46,18 @@ namespace internal * classes. * * @ingroup grid - * @author Tobias Leicht, 2006 + * @author Tobias Leicht, Guido Kanschat, 2006, 2007 */ template class TriaObjects { public: + /** + * Constructor resetting some data. + */ + TriaObjects(); + /** * Vector of the objects belonging to * this level. The index of the object @@ -127,15 +132,7 @@ namespace internal * which cell it belongs to. */ std::vector material_id; - - /** - * Pointer which is not used by the - * library but may be accessed and set - * by the user to handle data local to - * a line/quad/etc. - */ - std::vector user_pointers; - + /** * Assert that enough space is * allocated to accomodate @@ -151,6 +148,34 @@ namespace internal * Clear all the data contained in this object. */ void clear(); + + /** + * Access to user pointers. + */ + void*& user_pointer(const unsigned int i); + + /** + * Read-only access to user pointers. + */ + const void* user_pointer(const unsigned int i) const; + + /** + * Access to user indices. + */ + unsigned int& user_index(const unsigned int i); + + /** + * Read-only access to user pointers. + */ + unsigned int user_index(const unsigned int i) const; + + /** + * Clear all user pointers or + * indices and reset their + * type, such that the next + * access may be aither or. + */ + void clear_user_data(); /** * Check the memory consistency of the @@ -179,12 +204,78 @@ namespace internal << arg3 << "."); /** * Exception + * @ingroup Exceptions */ DeclException2 (ExcMemoryInexact, int, int, << "The containers have sizes " << arg1 << " and " << arg2 << ", which is not as expected."); + + /** + * Triangulation objacts can + * either access a user + * pointer or a user + * index. What you tried to + * do is trying to access one + * of those after using the + * other. + * + * @ingroup Exceptions + */ + DeclException0 (ExcPointerIndexClash); + protected: + /** + * The data type storing user + * pointers or user indices. + */ + union UserData + { + /// The entry used as user pointer. + void* p; + /// The entry used as user index. + unsigned int i; + /// Default constructor + UserData() + { + p = 0; + } + }; + + /** + * Enum descibing the + * possible types of + * userdata. + */ + enum UserDataType + { + /// No userdata used yet. + data_unknown, + /// UserData contains pointers. + data_pointer, + /// UserData contains indices. + data_index + }; + + + /** + * Pointer which is not used by the + * library but may be accessed and set + * by the user to handle data local to + * a line/quad/etc. + */ + std::vector user_data; + /** + * In order to avoid + * confusion between user + * pointers and indices, this + * enum is set by the first + * function accessing either + * and subsequent access will + * not be allowed to change + * the type of data accessed. + */ + mutable UserDataType user_data_type; }; /** @@ -342,10 +433,77 @@ namespace internal */ unsigned int memory_consumption () const; }; + + template + void*& TriaObjects::user_pointer (const unsigned int i) + { +#ifdef DEBUG + Assert(user_data_type == data_unknown || user_data_type == data_pointer, + ExcPointerIndexClash()); + user_data_type = data_pointer; +#endif + Assert(i + const void* TriaObjects::user_pointer (const unsigned int i) const + { +#ifdef DEBUG + Assert(user_data_type == data_unknown || user_data_type == data_pointer, + ExcPointerIndexClash()); + user_data_type = data_pointer; +#endif + Assert(i + unsigned int& TriaObjects::user_index (const unsigned int i) + { +#ifdef DEBUG + Assert(user_data_type == data_unknown || user_data_type == data_index, + ExcPointerIndexClash()); + user_data_type = data_index; +#endif + Assert(i + TriaObjects::TriaObjects() + : + user_data_type(data_unknown) + {} + + template + unsigned int TriaObjects::user_index (const unsigned int i) const + { +#ifdef DEBUG + Assert(user_data_type == data_unknown || user_data_type == data_index, + ExcPointerIndexClash()); + user_data_type = data_index; +#endif + Assert(i + void TriaObjects::clear_user_data () + { + user_data_type = data_unknown; + for (unsigned int i=0;i::load_coarsen_flags (const std::vector &v) template <> void Triangulation<1>::clear_user_pointers () { - cell_iterator cell = begin(), - endc = end(); - for (; cell!=endc; ++cell) - cell->clear_user_pointer (); + for (unsigned int level=0;levellines.clear_user_data(); } @@ -2160,15 +2158,9 @@ void Triangulation<1>::clear_user_flags_hex () template <> void Triangulation<2>::clear_user_pointers () { - line_iterator line = begin_line(), - endl = end_line(); - for (; line!=endl; ++line) - line->clear_user_pointer (); - - cell_iterator cell = begin(), - endc = end(); - for (; cell!=endc; ++cell) - cell->clear_user_pointer (); + for (unsigned int level=0;levelquads.clear_user_data(); + faces->lines.clear_user_data(); } @@ -2195,20 +2187,10 @@ void Triangulation<2>::clear_user_flags_hex () template <> void Triangulation<3>::clear_user_pointers () { - line_iterator line = begin_line(), - endl = end_line(); - for (; line!=endl; ++line) - line->clear_user_pointer (); - - quad_iterator quad = begin_quad(), - endq = end_quad(); - for (; quad!=endq; ++quad) - quad->clear_user_pointer (); - - cell_iterator cell = begin(), - endc = end(); - for (; cell!=endc; ++cell) - cell->clear_user_pointer (); + for (unsigned int level=0;levelhexes.clear_user_data(); + faces->quads.clear_user_data(); + faces->lines.clear_user_data(); } diff --git a/deal.II/deal.II/source/grid/tria_accessor.cc b/deal.II/deal.II/source/grid/tria_accessor.cc index 1fc68df26a..ac51722d2b 100644 --- a/deal.II/deal.II/source/grid/tria_accessor.cc +++ b/deal.II/deal.II/source/grid/tria_accessor.cc @@ -112,7 +112,7 @@ template void TriaObjectAccessor<1, dim>::set_user_pointer (void *p) const { Assert (used(), TriaAccessorExceptions::ExcCellNotUsed()); - lines().user_pointers[this->present_index] = p; + lines().user_pointer(this->present_index) = p; } @@ -121,7 +121,7 @@ template void TriaObjectAccessor<1, dim>::clear_user_pointer () const { Assert (used(), TriaAccessorExceptions::ExcCellNotUsed()); - lines().user_pointers[this->present_index] = 0; + lines().user_pointer(this->present_index) = 0; } @@ -130,7 +130,7 @@ template void * TriaObjectAccessor<1, dim>::user_pointer () const { Assert (used(), TriaAccessorExceptions::ExcCellNotUsed()); - return lines().user_pointers[this->present_index]; + return lines().user_pointer(this->present_index); } @@ -356,7 +356,7 @@ template void TriaObjectAccessor<2, dim>::set_user_pointer (void *p) const { Assert (used(), TriaAccessorExceptions::ExcCellNotUsed()); - quads().user_pointers[this->present_index] = p; + quads().user_pointer(this->present_index) = p; } @@ -365,7 +365,7 @@ template void TriaObjectAccessor<2, dim>::clear_user_pointer () const { Assert (used(), TriaAccessorExceptions::ExcCellNotUsed()); - quads().user_pointers[this->present_index] = 0; + quads().user_pointer(this->present_index) = 0; } @@ -374,7 +374,7 @@ template void * TriaObjectAccessor<2, dim>::user_pointer () const { Assert (used(), TriaAccessorExceptions::ExcCellNotUsed()); - return quads().user_pointers[this->present_index]; + return quads().user_pointer(this->present_index); } @@ -828,7 +828,7 @@ template <> void TriaObjectAccessor<3, 3>::set_user_pointer (void *p) const { Assert (used(), TriaAccessorExceptions::ExcCellNotUsed()); - this->tria->levels[this->present_level]->hexes.user_pointers[this->present_index] = p; + this->tria->levels[this->present_level]->hexes.user_pointer(this->present_index) = p; } @@ -836,7 +836,7 @@ template <> void TriaObjectAccessor<3, 3>::clear_user_pointer () const { Assert (used(), TriaAccessorExceptions::ExcCellNotUsed()); - this->tria->levels[this->present_level]->hexes.user_pointers[this->present_index] = 0; + this->tria->levels[this->present_level]->hexes.user_pointer(this->present_index) = 0; } @@ -844,7 +844,7 @@ template <> void * TriaObjectAccessor<3, 3>::user_pointer () const { Assert (used(), TriaAccessorExceptions::ExcCellNotUsed()); - return this->tria->levels[this->present_level]->hexes.user_pointers[this->present_index]; + return this->tria->levels[this->present_level]->hexes.user_pointer(this->present_index); } #endif diff --git a/deal.II/deal.II/source/grid/tria_objects.cc b/deal.II/deal.II/source/grid/tria_objects.cc index 07b1f2c1b7..edc01981d8 100644 --- a/deal.II/deal.II/source/grid/tria_objects.cc +++ b/deal.II/deal.II/source/grid/tria_objects.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2006 by the deal.II authors +// Copyright (C) 2006, 2007 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -18,14 +18,14 @@ #include #include -DEAL_II_NAMESPACE_OPEN + +DEAL_II_NAMESPACE_OPEN namespace internal { namespace Triangulation - { - + { template<> void TriaObjects::reserve_space (const unsigned int new_lines) @@ -63,10 +63,10 @@ namespace internal new_size-material_id.size(), 255); - user_pointers.reserve (new_size); - user_pointers.insert (user_pointers.end(), - new_size-user_pointers.size(), - 0); + user_data.reserve (new_size); + user_data.insert (user_data.end(), + new_size-user_data.size(), + UserData()); }; } @@ -108,10 +108,10 @@ namespace internal new_size-material_id.size(), 255); - user_pointers.reserve (new_size); - user_pointers.insert (user_pointers.end(), - new_size-user_pointers.size(), - 0); + user_data.reserve (new_size); + user_data.insert (user_data.end(), + new_size-user_data.size(), + UserData()); }; } @@ -152,10 +152,10 @@ namespace internal new_size-material_id.size(), 255); - user_pointers.reserve (new_size); - user_pointers.insert (user_pointers.end(), - new_size-user_pointers.size(), - 0); + user_data.reserve (new_size); + user_data.insert (user_data.end(), + new_size-user_data.size(), + UserData()); face_orientations.reserve (new_size * GeometryInfo<3>::faces_per_cell); face_orientations.insert (face_orientations.end(), @@ -232,8 +232,8 @@ namespace internal ExcMemoryInexact (cells.size(), children.size())); Assert (cells.size() == material_id.size(), ExcMemoryInexact (cells.size(), material_id.size())); - Assert (cells.size() == user_pointers.size(), - ExcMemoryInexact (cells.size(), user_pointers.size())); + Assert (cells.size() == user_data.size(), + ExcMemoryInexact (cells.size(), user_data.size())); } @@ -272,8 +272,8 @@ namespace internal ExcMemoryInexact (cells.size(), children.size())); Assert (cells.size() == material_id.size(), ExcMemoryInexact (cells.size(), material_id.size())); - Assert (cells.size() == user_pointers.size(), - ExcMemoryInexact (cells.size(), user_pointers.size())); + Assert (cells.size() == user_data.size(), + ExcMemoryInexact (cells.size(), user_data.size())); } @@ -311,8 +311,8 @@ namespace internal ExcMemoryInexact (cells.size(), children.size())); Assert (cells.size() == material_id.size(), ExcMemoryInexact (cells.size(), material_id.size())); - Assert (cells.size() == user_pointers.size(), - ExcMemoryInexact (cells.size(), user_pointers.size())); + Assert (cells.size() == user_data.size(), + ExcMemoryInexact (cells.size(), user_data.size())); Assert (cells.size() * GeometryInfo<3>::faces_per_cell == face_orientations.size(), ExcMemoryInexact (cells.size() * GeometryInfo<3>::faces_per_cell, @@ -356,7 +356,8 @@ namespace internal used.clear(); user_flags.clear(); material_id.clear(); - user_pointers.clear(); + user_data.clear(); + user_data_type = data_unknown; } @@ -387,7 +388,7 @@ namespace internal MemoryConsumption::memory_consumption (used) + MemoryConsumption::memory_consumption (user_flags) + MemoryConsumption::memory_consumption (material_id) + - MemoryConsumption::memory_consumption (user_pointers)); + user_data.capacity() * sizeof(UserData) + sizeof(user_data)); } -- 2.39.5