// $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
* classes.
*
* @ingroup grid
- * @author Tobias Leicht, 2006
+ * @author Tobias Leicht, Guido Kanschat, 2006, 2007
*/
template <typename G>
class TriaObjects
{
public:
+ /**
+ * Constructor resetting some data.
+ */
+ TriaObjects();
+
/**
* Vector of the objects belonging to
* this level. The index of the object
* which cell it belongs to.
*/
std::vector<unsigned char> 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<void*> user_pointers;
-
+
/**
* Assert that enough space is
* allocated to accomodate
* 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
<< 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<UserData> 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;
};
/**
*/
unsigned int memory_consumption () const;
};
+
+ template<typename G>
+ void*& TriaObjects<G>::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<user_data.size(), ExcIndexRange(i,0,user_data.size()));
+ return user_data[i].p;
+ }
+
+
+ template<typename G>
+ const void* TriaObjects<G>::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<user_data.size(), ExcIndexRange(i,0,user_data.size()));
+ return user_data[i].p;
+ }
+
+
+ template<typename G>
+ unsigned int& TriaObjects<G>::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<user_data.size(), ExcIndexRange(i,0,user_data.size()));
+ return user_data[i].i;
+ }
+
+ template <typename G>
+ TriaObjects<G>::TriaObjects()
+ :
+ user_data_type(data_unknown)
+ {}
+
+ template<typename G>
+ unsigned int TriaObjects<G>::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<user_data.size(), ExcIndexRange(i,0,user_data.size()));
+ return user_data[i].i;
+ }
+
+
+ template<typename G>
+ void TriaObjects<G>::clear_user_data ()
+ {
+ user_data_type = data_unknown;
+ for (unsigned int i=0;i<user_data.size();++i)
+ user_data[i].p = 0;
+ }
}
}
+
+
DEAL_II_NAMESPACE_CLOSE
#endif
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;level<levels.size();++level)
+ levels[level]->lines.clear_user_data();
}
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;level<levels.size();++level)
+ levels[level]->quads.clear_user_data();
+ faces->lines.clear_user_data();
}
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;level<levels.size();++level)
+ levels[level]->hexes.clear_user_data();
+ faces->quads.clear_user_data();
+ faces->lines.clear_user_data();
}
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;
}
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;
}
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);
}
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;
}
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;
}
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);
}
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;
}
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;
}
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
// $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
#include <algorithm>
#include <functional>
-DEAL_II_NAMESPACE_OPEN
+
+DEAL_II_NAMESPACE_OPEN
namespace internal
{
namespace Triangulation
- {
-
+ {
template<>
void
TriaObjects<Line>::reserve_space (const unsigned int new_lines)
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());
};
}
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());
};
}
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(),
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()));
}
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()));
}
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,
used.clear();
user_flags.clear();
material_id.clear();
- user_pointers.clear();
+ user_data.clear();
+ user_data_type = data_unknown;
}
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));
}