From: wolf Date: Fri, 19 Mar 1999 18:15:19 +0000 (+0000) Subject: Make many functions inline and put them into the header files, but only when optimize... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=becda8091d555b3ceab1fa2befe69b5ecc905cf4;p=dealii-svn.git Make many functions inline and put them into the header files, but only when optimized mode is used. This gains us approx. 10 per cent in computing time in real life programs. git-svn-id: https://svn.dealii.org/trunk@1026 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/Attic/examples/grid/grid_test.cc b/deal.II/deal.II/Attic/examples/grid/grid_test.cc index fe2dd4feff..f4aa02e899 100644 --- a/deal.II/deal.II/Attic/examples/grid/grid_test.cc +++ b/deal.II/deal.II/Attic/examples/grid/grid_test.cc @@ -3,6 +3,7 @@ #include +#include #include #include #include diff --git a/deal.II/deal.II/include/dofs/dof_accessor.h b/deal.II/deal.II/include/dofs/dof_accessor.h index 6902d0f0fc..5c9e04ac88 100644 --- a/deal.II/deal.II/include/dofs/dof_accessor.h +++ b/deal.II/deal.II/include/dofs/dof_accessor.h @@ -11,6 +11,13 @@ #include +// note: in non-debug mode, i.e. with optimizations, the file +// dof_accessor.templates.h is included at the end of this file. +// this includes a lot of templates and thus makes compilation +// slower, but at the same time allows for more aggressive +// inlining and thus faster code. + + /** * Define the basis for accessors to the degrees of freedom. @@ -805,10 +812,6 @@ class DoFCellAccessor : public DoFSubstructAccessor { template void get_interpolated_dof_values (const Vector &values, Vector &interpolated_values) const; -// void get_interpolated_dof_values (const Vector &values, -// Vector &interpolated_values) const; -// void get_interpolated_dof_values (const Vector &values, -// Vector &interpolated_values) const; /** * This function is the counterpart to @@ -907,6 +910,10 @@ class DoFCellAccessor : public DoFSubstructAccessor { +// if in optimized mode: include more templates +#ifndef DEBUG +# include "dof_accessor.templates.h" +#endif diff --git a/deal.II/deal.II/include/dofs/dof_accessor.templates.h b/deal.II/deal.II/include/dofs/dof_accessor.templates.h new file mode 100644 index 0000000000..4ef917f102 --- /dev/null +++ b/deal.II/deal.II/include/dofs/dof_accessor.templates.h @@ -0,0 +1,394 @@ +/*---------------------------- dof_accessor.templates.h ---------------------------*/ +/* $Id$ */ +#ifndef __dof_accessor_templates_H +#define __dof_accessor_templates_H +/*---------------------------- dof_accessor.templates.h ---------------------------*/ + + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + + +/*------------------------- Functions: DoFLineAccessor -----------------------*/ + +template +inline +int DoFLineAccessor::dof_index (const unsigned int i) const { + Assert (dof_handler != 0, ExcInvalidObject()); + // make sure a FE has been selected + // and enough room was reserved + Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); + Assert (iselected_fe->dofs_per_line, + ExcInvalidIndex (i, 0, dof_handler->selected_fe->dofs_per_line)); + + return dof_handler->levels[present_level] + ->line_dofs[present_index*dof_handler->selected_fe->dofs_per_line+i]; +}; + + + + +template +inline +int DoFLineAccessor::vertex_dof_index (const unsigned int vertex, + const unsigned int i) const { + Assert (dof_handler != 0, ExcInvalidObject()); + Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); + Assert (vertex<2, ExcInvalidIndex (i,0,2)); + Assert (iselected_fe->dofs_per_vertex, + ExcInvalidIndex (i, 0, dof_handler->selected_fe->dofs_per_vertex)); + + const unsigned int dof_number = (vertex_index(vertex) * + dof_handler->selected_fe->dofs_per_vertex + + i); + return dof_handler->vertex_dofs[dof_number]; +}; + + + +template +inline +void +DoFLineAccessor::get_dof_indices (vector &dof_indices) const { + Assert (dof_handler != 0, ExcInvalidObject()); + Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); + Assert (dof_indices.size() == (2*dof_handler->get_fe().dofs_per_vertex + + dof_handler->get_fe().dofs_per_line), + ExcVectorDoesNotMatch()); + + const unsigned int dofs_per_vertex = dof_handler->get_fe().dofs_per_vertex, + dofs_per_line = dof_handler->get_fe().dofs_per_line; + vector::iterator next = dof_indices.begin(); + for (unsigned int vertex=0; vertex<2; ++vertex) + for (unsigned int d=0; d +inline +TriaIterator > +DoFLineAccessor::child (const unsigned int i) const { + TriaIterator > q (tria, + present_level+1, + child_index (i), + dof_handler); + +#ifdef DEBUG + if (q.state() != past_the_end) + Assert (q->used(), typename TriaAccessor::ExcUnusedCellAsChild()); +#endif + return q; +}; + + + +template +inline +void +DoFLineAccessor::copy_from (const DoFLineAccessor &a) { + BaseClass::copy_from (a); + set_dof_handler (a.dof_handler); +}; + + + + +/*------------------------- Functions: DoFQuadAccessor -----------------------*/ + +template +inline +int DoFQuadAccessor::dof_index (const unsigned int i) const { + Assert (dof_handler != 0, ExcInvalidObject()); + // make sure a FE has been selected + // and enough room was reserved + Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); + Assert (iselected_fe->dofs_per_quad, + ExcInvalidIndex (i, 0, dof_handler->selected_fe->dofs_per_quad)); + + return dof_handler->levels[present_level] + ->quad_dofs[present_index*dof_handler->selected_fe->dofs_per_quad+i]; +}; + + + +template +inline +int DoFQuadAccessor::vertex_dof_index (const unsigned int vertex, + const unsigned int i) const { + Assert (dof_handler != 0, ExcInvalidObject()); + Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); + Assert (vertex<4, ExcInvalidIndex (i,0,4)); + Assert (iselected_fe->dofs_per_vertex, + ExcInvalidIndex (i, 0, dof_handler->selected_fe->dofs_per_vertex)); + + const unsigned int dof_number = (vertex_index(vertex) * + dof_handler->selected_fe->dofs_per_vertex + + i); + return dof_handler->vertex_dofs[dof_number]; +}; + + + +template +inline +void +DoFQuadAccessor::get_dof_indices (vector &dof_indices) const { + Assert (dof_handler != 0, ExcInvalidObject()); + Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); + Assert (dof_indices.size() == (4*dof_handler->get_fe().dofs_per_vertex + + 4*dof_handler->get_fe().dofs_per_line + + dof_handler->get_fe().dofs_per_quad), + ExcVectorDoesNotMatch()); + + const unsigned int dofs_per_vertex = dof_handler->get_fe().dofs_per_vertex, + dofs_per_line = dof_handler->get_fe().dofs_per_line, + dofs_per_quad = dof_handler->get_fe().dofs_per_quad; + vector::iterator next = dof_indices.begin(); + for (unsigned int vertex=0; vertex<4; ++vertex) + for (unsigned int d=0; dline(line)->dof_index(d); + for (unsigned int d=0; d +inline +TriaIterator > > +DoFQuadAccessor::line (const unsigned int i) const { + Assert (i<4, ExcInvalidIndex (i, 0, 4)); + + return TriaIterator > > + ( + tria, + present_level, + line_index (i), + dof_handler + ); +}; + + + +template +inline +TriaIterator > +DoFQuadAccessor::child (const unsigned int i) const { + TriaIterator > q (tria, + present_level+1, + child_index (i), + dof_handler); + +#ifdef DEBUG + if (q.state() != past_the_end) + Assert (q->used(), typename TriaAccessor::ExcUnusedCellAsChild()); +#endif + return q; +}; + + + +template +inline +void +DoFQuadAccessor::copy_from (const DoFQuadAccessor &a) { + BaseClass::copy_from (a); + set_dof_handler (a.dof_handler); +}; + + + + +/*------------------------- Functions: DoFHexAccessor -----------------------*/ + + +template +inline +int DoFHexAccessor::dof_index (const unsigned int i) const { + Assert (dof_handler != 0, ExcInvalidObject()); + // make sure a FE has been selected + // and enough room was reserved + Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); + Assert (iselected_fe->dofs_per_hex, + ExcInvalidIndex (i, 0, dof_handler->selected_fe->dofs_per_hex)); + + return dof_handler->levels[present_level] + ->hex_dofs[present_index*dof_handler->selected_fe->dofs_per_hex+i]; +}; + + + +template +inline +int DoFHexAccessor::vertex_dof_index (const unsigned int vertex, + const unsigned int i) const { + Assert (dof_handler != 0, ExcInvalidObject()); + Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); + Assert (vertex<8, ExcInvalidIndex (i,0,8)); + Assert (iselected_fe->dofs_per_vertex, + ExcInvalidIndex (i, 0, dof_handler->selected_fe->dofs_per_vertex)); + + const unsigned int dof_number = (vertex_index(vertex) * + dof_handler->selected_fe->dofs_per_vertex + + i); + return dof_handler->vertex_dofs[dof_number]; +}; + + + +template +inline +void +DoFHexAccessor::get_dof_indices (vector &dof_indices) const { + Assert (dof_handler != 0, ExcInvalidObject()); + Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); + Assert (dof_indices.size() == (8*dof_handler->get_fe().dofs_per_vertex + + 12*dof_handler->get_fe().dofs_per_line + + 6*dof_handler->get_fe().dofs_per_quad + + dof_handler->get_fe().dofs_per_hex), + ExcVectorDoesNotMatch()); + + const unsigned int dofs_per_vertex = dof_handler->get_fe().dofs_per_vertex, + dofs_per_line = dof_handler->get_fe().dofs_per_line, + dofs_per_quad = dof_handler->get_fe().dofs_per_quad, + dofs_per_hex = dof_handler->get_fe().dofs_per_hex; + vector::iterator next = dof_indices.begin(); + for (unsigned int vertex=0; vertex<8; ++vertex) + for (unsigned int d=0; dline(line)->dof_index(d); + for (unsigned int quad=0; quad<6; ++quad) + for (unsigned int d=0; dquad(quad)->dof_index(d); + for (unsigned int d=0; d +inline +TriaIterator > > +DoFHexAccessor::line (const unsigned int i) const { + TriaIterator > l = BaseClass::line(i); + return TriaIterator > > + ( + tria, + present_level, + l->index(), + dof_handler + ); +}; + + + +template +inline +TriaIterator > > +DoFHexAccessor::quad (const unsigned int i) const { + Assert (i<6, ExcInvalidIndex (i, 0, 6)); + + return TriaIterator > > + ( + tria, + present_level, + quad_index (i), + dof_handler + ); +}; + + + +template +inline +TriaIterator > +DoFHexAccessor::child (const unsigned int i) const { + TriaIterator > q (tria, + present_level+1, + child_index (i), + dof_handler); + +#ifdef DEBUG + if (q.state() != past_the_end) + Assert (q->used(), typename TriaAccessor::ExcUnusedCellAsChild()); +#endif + return q; +}; + + + +template +void DoFHexAccessor::copy_from (const DoFHexAccessor &a) { + BaseClass::copy_from (a); + set_dof_handler (a.dof_handler); +}; + + + + +/*------------------------- Functions: DoFCellAccessor -----------------------*/ + + +template +inline +TriaIterator > +DoFCellAccessor::neighbor (const unsigned int i) const { + TriaIterator > q (tria, + neighbor_level (i), + neighbor_index (i), + dof_handler); + +#ifdef DEBUG + if (q.state() != past_the_end) + Assert (q->used(), typename TriaAccessor::ExcUnusedCellAsNeighbor()); +#endif + return q; +}; + + + +template +inline +TriaIterator > +DoFCellAccessor::child (const unsigned int i) const { + TriaIterator > q (tria, + present_level+1, + child_index (i), + dof_handler); + +#ifdef DEBUG + if (q.state() != past_the_end) + Assert (q->used(), typename TriaAccessor::ExcUnusedCellAsChild()); +#endif + return q; +}; + + + + + + + +/*---------------------------- dof_accessor.templates.h ---------------------------*/ +/* end of #ifndef __dof_accessor_templates_H */ +#endif +/*---------------------------- dof_accessor.templates.h ---------------------------*/ diff --git a/deal.II/deal.II/include/grid/tria_accessor.h b/deal.II/deal.II/include/grid/tria_accessor.h index 35fbf9bcb4..b2edfc5653 100644 --- a/deal.II/deal.II/include/grid/tria_accessor.h +++ b/deal.II/deal.II/include/grid/tria_accessor.h @@ -9,20 +9,18 @@ #include #include #include +#include +// note: in non-debug mode, i.e. with optimizations, the file +// tria_accessor.templates.h is included at the end of this file. +// this includes a lot of templates and thus makes compilation +// slower, but at the same time allows for more aggressive +// inlining and thus faster code. -/** - * The three states an iterator can be in: valid, past-the-end and - * invalid. - */ -enum IteratorState { valid, past_the_end, invalid }; - - - /** @@ -1280,6 +1278,11 @@ class TriaSubstructAccessor; template <> class TriaSubstructAccessor<1> : public LineAccessor<1> { public: + /** + * Propagate the AccessorData type + * into the present class. + */ + typedef typename LineAccessor<1>::AccessorData AccessorData; /** * Constructor */ @@ -1308,6 +1311,11 @@ class TriaSubstructAccessor<1> : public LineAccessor<1> { template <> class TriaSubstructAccessor<2> : public QuadAccessor<2> { public: + /** + * Propagate the AccessorData type + * into the present class. + */ + typedef typename QuadAccessor<2>::AccessorData AccessorData; /** * Constructor */ @@ -1337,6 +1345,12 @@ class TriaSubstructAccessor<2> : public QuadAccessor<2> { template <> class TriaSubstructAccessor<3> : public HexAccessor<3> { public: + /** + * Propagate the AccessorData type + * into the present class. + */ + typedef typename HexAccessor<3>::AccessorData AccessorData; + /** * Constructor */ @@ -1377,6 +1391,12 @@ class TriaSubstructAccessor<3> : public HexAccessor<3> { template class CellAccessor : public TriaSubstructAccessor { public: + /** + * Propagate the AccessorData type + * into the present class. + */ + typedef typename TriaSubstructAccessor::AccessorData AccessorData; + /** * Constructor. */ @@ -1536,11 +1556,18 @@ class CellAccessor : public TriaSubstructAccessor { - - +// if in optimized mode: include more templates +#ifndef DEBUG +# include "tria_accessor.templates.h" +#endif /*---------------------------- tria_accessor.h ---------------------------*/ /* end of #ifndef __tria_accessor_H */ #endif /*---------------------------- tria_accessor.h ---------------------------*/ + + + + + diff --git a/deal.II/deal.II/include/grid/tria_accessor.templates.h b/deal.II/deal.II/include/grid/tria_accessor.templates.h new file mode 100644 index 0000000000..6035ebf6bc --- /dev/null +++ b/deal.II/deal.II/include/grid/tria_accessor.templates.h @@ -0,0 +1,747 @@ +/*---------------------------- tria_accessor.templates.h ---------------------------*/ +/* $Id$ */ +#ifndef __tria_accessor_templates_H +#define __tria_accessor_templates_H +/*---------------------------- tria_accessor.templates.h ---------------------------*/ + + +#include +#include +#include +#include +#include +#include + +#include + + +/*------------------------ Functions: TriaAccessor ---------------------------*/ + + +template +inline +void +TriaAccessor::copy_from (const TriaAccessor &a) { + present_level = a.present_level; + present_index = a.present_index; + tria = a.tria; +}; + + + +template +inline +bool +TriaAccessor::operator == (const TriaAccessor &a) const { + Assert (tria == a.tria, ExcCantCompareIterators()); + return ((present_index == a.present_index) && + (present_level == a.present_level)); +}; + + + +template +inline +bool +TriaAccessor::operator != (const TriaAccessor &a) const { + Assert (tria == a.tria, ExcCantCompareIterators()); + return ((present_index != a.present_index) || + (present_level != a.present_level)); +}; + + + +template +inline +int +TriaAccessor::level () const { + return present_level; +}; + + + +template +inline +int +TriaAccessor::index () const { + return present_index; +}; + + + +template +inline +IteratorState +TriaAccessor::state () const { + if ((present_level>=0) && (present_index>=0)) + return valid; + else + if ((present_level==-1) && (present_index==-1)) + return past_the_end; + else + return invalid; +}; + + + +/*------------------------ Functions: LineAccessor ---------------------------*/ + + + + +template +inline +bool +LineAccessor::used () const { + Assert (state() == valid, ExcDereferenceInvalidObject()); + return tria->levels[present_level]->lines.used[present_index]; +}; + + + + +template +inline +bool +LineAccessor::user_flag_set () const { + Assert (used(), ExcCellNotUsed()); + return tria->levels[present_level]->lines.user_flags[present_index]; +}; + + + +template +inline +void +LineAccessor::set_user_flag () const { + Assert (used(), ExcCellNotUsed()); + tria->levels[present_level]->lines.user_flags[present_index] = true; +}; + + + +template +inline +void +LineAccessor::clear_user_flag () const { + Assert (used(), ExcCellNotUsed()); + tria->levels[present_level]->lines.user_flags[present_index] = false; +}; + + + + +template +inline +TriaIterator > +LineAccessor::child (const unsigned int i) const { + Assert (i<2, ExcInvalidIndex(i,0,1)); + + TriaIterator > q (tria, present_level+1, child_index (i)); + +#ifdef DEBUG + if (q.state() != past_the_end) + Assert (q->used(), ExcUnusedCellAsChild()); +#endif + return q; +}; + + + +template +inline +int +LineAccessor::child_index (unsigned int i) const { + Assert (i<2, ExcInvalidIndex(i,0,1)); + return tria->levels[present_level]->lines.children[present_index]+i; +}; + + + + +template +inline +bool +LineAccessor::has_children () const { + Assert (state() == valid, ExcDereferenceInvalidObject()); + return (tria->levels[present_level]->lines.children[present_index] != -1); +} + + + +template +inline +void +LineAccessor::operator ++ () { + ++present_index; + // is index still in the range of + // the vector? + while (present_index + >= + (int)tria->levels[present_level]->lines.lines.size()) + { + // no -> go one level up until we find + // one with more than zero cells + ++present_level; + present_index = 0; + // highest level reached? + if (present_level >= (int)tria->levels.size()) + { + // return with past the end pointer + present_level = present_index = -1; + return; + }; + }; +}; + + + +template +inline +void +LineAccessor::operator -- () { + --present_index; + // is index still in the range of + // the vector? + while (present_index < 0) + { + // no -> go one level down + --present_level; + // lowest level reached? + if (present_level == -1) + { + // return with past the end pointer + present_level = present_index = -1; + return; + }; + // else + present_index = tria->levels[present_level]->lines.lines.size()-1; + }; +}; + + + + +/*------------------------ Functions: QuadAccessor ---------------------------*/ + + + +template +inline +bool +QuadAccessor::used () const { + Assert (state() == valid, ExcDereferenceInvalidObject()); + return tria->levels[present_level]->quads.used[present_index]; +}; + + + + +template +inline +bool +QuadAccessor::user_flag_set () const { + Assert (used(), ExcCellNotUsed()); + return tria->levels[present_level]->quads.user_flags[present_index]; +}; + + + +template +inline +void +QuadAccessor::set_user_flag () const { + Assert (used(), ExcCellNotUsed()); + tria->levels[present_level]->quads.user_flags[present_index] = true; +}; + + + +template +inline +void +QuadAccessor::clear_user_flag () const { + Assert (used(), ExcCellNotUsed()); + tria->levels[present_level]->quads.user_flags[present_index] = false; +}; + + + + +template +inline +TriaIterator > +QuadAccessor::line (const unsigned int i) const { + return + TriaIterator > + ( + tria, + present_level, + line_index (i) + ); +}; + + + +template +inline +unsigned int +QuadAccessor::line_index (unsigned int i) const { + Assert (i<4, ExcInvalidIndex(i,0,3)); + + return tria->levels[present_level]->quads.quads[present_index].line(i); +}; + + + +template +inline +TriaIterator > +QuadAccessor::child (const unsigned int i) const { + Assert (i<4, ExcInvalidIndex(i,0,3)); + + TriaIterator > q (tria, present_level+1, child_index (i)); + +#ifdef DEBUG + if (q.state() != past_the_end) + Assert (q->used(), ExcUnusedCellAsChild()); +#endif + return q; +}; + + + +template +inline +int QuadAccessor::child_index (unsigned int i) const { + Assert (i<4, ExcInvalidIndex(i,0,3)); + return tria->levels[present_level]->quads.children[present_index]+i; +}; + + + + +template +inline +bool +QuadAccessor::has_children () const { + Assert (state() == valid, ExcDereferenceInvalidObject()); + return (tria->levels[present_level]->quads.children[present_index] != -1); +}; + + + +template +inline +void +QuadAccessor::operator ++ () { + ++present_index; + // is index still in the range of + // the vector? + while (present_index + >= + (int)tria->levels[present_level]->quads.quads.size()) + { + // no -> go one level up + ++present_level; + present_index = 0; + // highest level reached? + if (present_level >= (int)tria->levels.size()) + { + // return with past the end pointer + present_level = present_index = -1; + return; + }; + }; +}; + + + +template +inline +void +QuadAccessor::operator -- () { + --present_index; + // is index still in the range of + // the vector? + while (present_index < 0) + { + // no -> go one level down + --present_level; + // lowest level reached? + if (present_level == -1) + { + // return with past the end pointer + present_level = present_index = -1; + return; + }; + // else + present_index = tria->levels[present_level]->quads.quads.size()-1; + }; +}; + + + + +/*------------------------ Functions: HexAccessor ---------------------------*/ + + + +template +inline +bool +HexAccessor::used () const { + Assert (state() == valid, ExcDereferenceInvalidObject()); + return tria->levels[present_level]->hexes.used[present_index]; +}; + + + +template +inline +bool +HexAccessor::user_flag_set () const { + Assert (used(), ExcCellNotUsed()); + return tria->levels[present_level]->hexes.user_flags[present_index]; +}; + + + +template +inline +void +HexAccessor::set_user_flag () const { + Assert (used(), ExcCellNotUsed()); + tria->levels[present_level]->hexes.user_flags[present_index] = true; +}; + + + +template +inline +void HexAccessor::clear_user_flag () const { + Assert (used(), ExcCellNotUsed()); + tria->levels[present_level]->hexes.user_flags[present_index] = false; +}; + + + + +template +inline +TriaIterator > +HexAccessor::line (const unsigned int i) const { + Assert (used(), ExcCellNotUsed()); + Assert (i<12, ExcInvalidIndex (i,0,11)); + + if (i<4) + return quad(0)->line(i); + else + if (i<8) + return quad(1)->line(i-4); + else + switch (i) + { + case 8: + return quad(2)->line(3); + case 9: + return quad(2)->line(1); + case 10: + return quad(4)->line(1); + case 11: + return quad(4)->line(3); + }; + Assert (false, ExcInvalidIndex(i,0,11)); + return TriaIterator >(tria, -1, -1, 0); +}; + + + +template +inline +TriaIterator > +HexAccessor::quad (const unsigned int i) const { + Assert (used(), ExcCellNotUsed()); + return + TriaIterator > + ( + tria, + present_level, + quad_index (i) + ); +}; + + + +template +inline +unsigned int +HexAccessor::quad_index (unsigned int i) const { + Assert (i<6, ExcInvalidIndex(i,0,5)); + + return tria->levels[present_level]->hexes.hexes[present_index].quad(i); +}; + + + +template +inline +TriaIterator > +HexAccessor::child (const unsigned int i) const { + Assert (i<6, ExcInvalidIndex(i,0,5)); + + TriaIterator > q (tria, present_level+1, child_index (i)); + +#ifdef DEBUG + if (q.state() != past_the_end) + Assert (q->used(), ExcUnusedCellAsChild()); +#endif + return q; +}; + + + +template +inline +int HexAccessor::child_index (unsigned int i) const { + Assert (i<8, ExcInvalidIndex(i,0,7)); + return tria->levels[present_level]->hexes.children[present_index]+i; +}; + + + + +template +inline +void +HexAccessor::operator ++ () { + ++present_index; + // is index still in the range of + // the vector? + while (present_index + >= + (int)tria->levels[present_level]->hexes.hexes.size()) + { + // no -> go one level up + ++present_level; + present_index = 0; + // highest level reached? + if (present_level >= (int)tria->levels.size()) + { + // return with past the end pointer + present_level = present_index = -1; + return; + }; + }; +}; + + + +template +inline +void +HexAccessor::operator -- () { + --present_index; + // is index still in the range of + // the vector? + while (present_index < 0) + { + // no -> go one level down + --present_level; + // lowest level reached? + if (present_level == -1) + { + // return with past the end pointer + present_level = present_index = -1; + return; + }; + // else + present_index = tria->levels[present_level]->hexes.hexes.size()-1; + }; +}; + + + + +/*------------------------ Functions: CellAccessor -----------------------*/ + + +template <> +inline +Triangulation<1>::face_iterator +CellAccessor<1>::face (const unsigned int) const { + Assert (false, ExcNotUsefulForThisDimension()); + return 0; +}; + + + +template <> +inline +Triangulation<2>::face_iterator +CellAccessor<2>::face (const unsigned int i) const { + return line(i); +}; + + + +template <> +inline +Triangulation<3>::face_iterator +CellAccessor<3>::face (const unsigned int i) const { + return quad(i); +}; + + + +template +inline +int +CellAccessor::neighbor_index (const unsigned int i) const { + Assert (i::faces_per_cell, + typename TriaSubstructAccessor::ExcInvalidNeighbor(i)); + return tria->levels[present_level]-> + neighbors[present_index*GeometryInfo::faces_per_cell+i].second; +}; + + + +template +inline +int +CellAccessor::neighbor_level (const unsigned int i) const { + Assert (i::faces_per_cell, + typename TriaSubstructAccessor::ExcInvalidNeighbor(i)); + return tria->levels[present_level]-> + neighbors[present_index*GeometryInfo::faces_per_cell+i].first; +}; + + + + +template +inline +bool +CellAccessor::refine_flag_set () const { + Assert (used(), typename TriaSubstructAccessor::ExcCellNotUsed()); + // cells flagged for refinement must be active + // (the #set_refine_flag# function checks this, + // but activity may change when refinement is + // executed and for some reason the refine + // flag is not cleared). + Assert (active() || !tria->levels[present_level]->refine_flags[present_index], + ExcRefineCellNotActive()); + return tria->levels[present_level]->refine_flags[present_index]; +}; + + + +template +inline +void +CellAccessor::set_refine_flag () const { + Assert (used() && active(), ExcRefineCellNotActive()); + Assert (!coarsen_flag_set(), ExcCellFlaggedForCoarsening()); + + tria->levels[present_level]->refine_flags[present_index] = true; +}; + + + +template +inline +void +CellAccessor::clear_refine_flag () const { + Assert (used() && active(), ExcRefineCellNotActive()); + tria->levels[present_level]->refine_flags[present_index] = false; +}; + + + +template +inline +bool +CellAccessor::coarsen_flag_set () const { + Assert (used(), typename TriaSubstructAccessor::ExcCellNotUsed()); + // cells flagged for coarsening must be active + // (the #set_refine_flag# function checks this, + // but activity may change when refinement is + // executed and for some reason the refine + // flag is not cleared). + Assert (active() || !tria->levels[present_level]->coarsen_flags[present_index], + ExcRefineCellNotActive()); + return tria->levels[present_level]->coarsen_flags[present_index]; +}; + + + +template +inline +void +CellAccessor::set_coarsen_flag () const { + Assert (used() && active(), ExcRefineCellNotActive()); + Assert (!refine_flag_set(), ExcCellFlaggedForRefinement()); + + tria->levels[present_level]->coarsen_flags[present_index] = true; +}; + + + +template +inline +void +CellAccessor::clear_coarsen_flag () const { + Assert (used() && active(), ExcRefineCellNotActive()); + tria->levels[present_level]->coarsen_flags[present_index] = false; +}; + + + +template +inline +TriaIterator > +CellAccessor::neighbor (const unsigned int i) const { + TriaIterator > q (tria, neighbor_level (i), neighbor_index (i)); + +#ifdef DEBUG + if (q.state() != past_the_end) + Assert (q->used(), + typename TriaSubstructAccessor::ExcUnusedCellAsNeighbor()); +#endif + return q; +}; + + + +template +inline +TriaIterator > +CellAccessor::child (const unsigned int i) const { + TriaIterator > q (tria, present_level+1, child_index (i)); + +#ifdef DEBUG + if (q.state() != past_the_end) + Assert (q->used(), + typename TriaSubstructAccessor::ExcUnusedCellAsChild()); +#endif + return q; +}; + + + +template +inline +bool +CellAccessor::active () const { + return !has_children(); +}; + + + + + + +/*---------------------------- tria_accessor.templates.h ---------------------------*/ +/* end of #ifndef __tria_accessor_templates_H */ +#endif +/*---------------------------- tria_accessor.templates.h ---------------------------*/ diff --git a/deal.II/deal.II/include/grid/tria_iterator.h b/deal.II/deal.II/include/grid/tria_iterator.h index 5e7ef319e3..71f6e77fb8 100644 --- a/deal.II/deal.II/include/grid/tria_iterator.h +++ b/deal.II/deal.II/include/grid/tria_iterator.h @@ -11,9 +11,14 @@ #include #include #include -#include - +#include +//#include +// note: in non-debug mode, i.e. with optimizations, the file +// tria_iterator.templates.h is included at the end of this file. +// this includes a lot of templates and thus makes compilation +// slower, but at the same time allows for more aggressive +// inlining and thus faster code. @@ -1010,6 +1015,12 @@ ostream & operator << (ostream &out, const TriaActiveIterator &i) +// if in optimized mode: include more templates +#ifndef DEBUG +# include "tria_iterator.templates.h" +#endif + + /*---------------------------- tria-iterator.h ---------------------------*/ /* end of #ifndef __tria_iterator_H */ #endif diff --git a/deal.II/deal.II/include/grid/tria_iterator.templates.h b/deal.II/deal.II/include/grid/tria_iterator.templates.h index 7dce8b431c..a70ed1a0df 100644 --- a/deal.II/deal.II/include/grid/tria_iterator.templates.h +++ b/deal.II/deal.II/include/grid/tria_iterator.templates.h @@ -1,5 +1,9 @@ -/* $Id$ */ -/* Copyright W. Bangerth, University of Heidelberg, 1998 */ +/*---------------------------- tria_iterator.templates.h ---------------------------*/ +/* Copyright W. Bangerth, University of Heidelberg, 1998 */ +/* $Id$ */ +#ifndef __tria_iterator_templates_H +#define __tria_iterator_templates_H +/*---------------------------- tria_iterator.templates.h ---------------------------*/ #include #include @@ -16,18 +20,21 @@ template +inline TriaRawIterator::TriaRawIterator () : accessor (0, -2, -2, 0) {}; template +inline TriaRawIterator::TriaRawIterator (const TriaRawIterator &i) : accessor (i.accessor) {}; template +inline TriaRawIterator::TriaRawIterator (Triangulation *parent, const int level, const int index, @@ -37,6 +44,7 @@ TriaRawIterator::TriaRawIterator (Triangulation *parent, template +inline TriaRawIterator & TriaRawIterator::operator = (const TriaRawIterator &i) { accessor.copy_from (i.accessor); @@ -47,6 +55,7 @@ TriaRawIterator::operator = (const TriaRawIterator & template +inline bool TriaRawIterator::operator == (const TriaRawIterator &i) const { return accessor == i.accessor; @@ -55,6 +64,7 @@ TriaRawIterator::operator == (const TriaRawIterator template +inline bool TriaRawIterator::operator != (const TriaRawIterator &i) const { return accessor != i.accessor; @@ -63,7 +73,9 @@ TriaRawIterator::operator != (const TriaRawIterator template -TriaRawIterator TriaRawIterator::operator ++ (int) { +inline +TriaRawIterator +TriaRawIterator::operator ++ (int) { TriaRawIterator tmp(*this); operator++ (); @@ -73,7 +85,9 @@ TriaRawIterator TriaRawIterator::operator ++ (int) { template -TriaRawIterator TriaRawIterator::operator -- (int) { +inline +TriaRawIterator +TriaRawIterator::operator -- (int) { TriaRawIterator tmp(*this); operator-- (); @@ -87,11 +101,13 @@ TriaRawIterator TriaRawIterator::operator -- (int) { template +inline TriaIterator::TriaIterator () : TriaRawIterator () {}; template +inline TriaIterator:: TriaIterator (const TriaIterator &i) : TriaRawIterator (static_cast >(i)) {}; @@ -99,6 +115,7 @@ TriaIterator (const TriaIterator &i) : template +inline TriaIterator:: TriaIterator (const TriaRawIterator &i) : TriaRawIterator (i) @@ -119,6 +136,7 @@ TriaIterator (const TriaRawIterator &i) : template +inline TriaIterator::TriaIterator (Triangulation *parent, const int level, const int index, @@ -141,6 +159,7 @@ TriaIterator::TriaIterator (Triangulation *parent, template +inline TriaIterator & TriaIterator::operator = (const TriaIterator &i) { accessor.copy_from (i.accessor); @@ -149,6 +168,7 @@ TriaIterator::operator = (const TriaIterator &i) { template +inline TriaIterator & TriaIterator::operator = (const TriaRawIterator &i) { accessor.copy_from (i.accessor); @@ -169,6 +189,7 @@ TriaIterator::operator = (const TriaRawIterator &i) template +inline TriaIterator & TriaIterator::operator ++ () { while (TriaRawIterator::operator++(), (state() == valid)) @@ -180,6 +201,7 @@ TriaIterator & TriaIterator::operator ++ () { template +inline TriaIterator TriaIterator::operator ++ (int) { TriaIterator tmp(*this); operator++ (); @@ -190,7 +212,9 @@ TriaIterator TriaIterator::operator ++ (int) { template -TriaIterator & TriaIterator::operator -- () { +inline +TriaIterator & +TriaIterator::operator -- () { while (TriaRawIterator::operator--(), (state() == valid)) if (accessor.used() == true) @@ -200,7 +224,9 @@ TriaIterator & TriaIterator::operator -- () { template -TriaIterator TriaIterator::operator -- (int) { +inline +TriaIterator +TriaIterator::operator -- (int) { TriaIterator tmp(*this); operator-- (); @@ -213,12 +239,14 @@ TriaIterator TriaIterator::operator -- (int) { template +inline TriaActiveIterator::TriaActiveIterator () : TriaIterator () {}; template +inline TriaActiveIterator:: TriaActiveIterator (const TriaActiveIterator &i) : TriaIterator (static_cast >(i)) {}; @@ -226,6 +254,7 @@ TriaActiveIterator (const TriaActiveIterator &i) : template +inline TriaActiveIterator:: TriaActiveIterator (const TriaRawIterator &i) : TriaIterator (i) @@ -245,6 +274,7 @@ TriaActiveIterator (const TriaRawIterator &i) : template +inline TriaActiveIterator:: TriaActiveIterator (const TriaIterator &i) : TriaIterator (i) @@ -265,6 +295,7 @@ TriaActiveIterator (const TriaIterator &i) : template +inline TriaActiveIterator::TriaActiveIterator (Triangulation *parent, const int level, const int index, @@ -287,6 +318,7 @@ TriaActiveIterator::TriaActiveIterator (Triangulation *parent template +inline TriaActiveIterator & TriaActiveIterator::operator = (const TriaActiveIterator &i) { accessor.copy_from (i.accessor); @@ -296,6 +328,7 @@ TriaActiveIterator::operator = (const TriaActiveIterator +inline TriaActiveIterator & TriaActiveIterator::operator = (const TriaRawIterator &i) { accessor.copy_from (i.accessor); @@ -316,6 +349,7 @@ TriaActiveIterator::operator = (const TriaRawIterator +inline TriaActiveIterator & TriaActiveIterator::operator = (const TriaIterator &i) { accessor.copy_from (i.accessor); @@ -336,7 +370,9 @@ TriaActiveIterator::operator = (const TriaIterator & template -TriaActiveIterator & TriaActiveIterator::operator ++ () { +inline +TriaActiveIterator & +TriaActiveIterator::operator ++ () { while (TriaIterator::operator++(), (state() == valid)) if (accessor.has_children() == false) @@ -347,7 +383,9 @@ TriaActiveIterator & TriaActiveIterator::operator ++ template -TriaActiveIterator TriaActiveIterator::operator ++ (int) { +inline +TriaActiveIterator +TriaActiveIterator::operator ++ (int) { TriaActiveIterator tmp(*this); operator++ (); @@ -357,7 +395,9 @@ TriaActiveIterator TriaActiveIterator::operator ++ ( template -TriaActiveIterator & TriaActiveIterator::operator -- () { +inline +TriaActiveIterator & +TriaActiveIterator::operator -- () { while (TriaIterator::operator--(), (state() == valid)) if (accessor.has_children() == false) @@ -368,6 +408,7 @@ TriaActiveIterator & TriaActiveIterator::operator -- template +inline TriaActiveIterator TriaActiveIterator::operator -- (int) { TriaActiveIterator tmp(*this); operator-- (); @@ -378,8 +419,7 @@ TriaActiveIterator TriaActiveIterator::operator -- ( - - - - - +/*---------------------------- tria_iterator.templates.h ---------------------------*/ +/* end of #ifndef __tria_iterator_templates_H */ +#endif +/*---------------------------- tria_iterator.templates.h ---------------------------*/ diff --git a/deal.II/deal.II/source/Makefile b/deal.II/deal.II/source/Makefile index 639e8e4192..12db3c5ef6 100644 --- a/deal.II/deal.II/source/Makefile +++ b/deal.II/deal.II/source/Makefile @@ -173,6 +173,7 @@ ifneq (1,${recursive-make-fwd-decl}) | perl -pe 's!(\.\./lib/2d/[^ ]+)_DIM_PLACEHOLDER!$$1_2d!g;' \ | perl -pe 's!(\.\./lib/3d/[^ ]+)_DIM_PLACEHOLDER!$$1_3d!g;' \ >> ../lib/Makefile.dep + @echo ============================ Done else @echo ============================ Not remaking Makefile since in nested mode endif diff --git a/deal.II/deal.II/source/dofs/dof_accessor.cc b/deal.II/deal.II/source/dofs/dof_accessor.cc index 31afbea681..33787933cd 100644 --- a/deal.II/deal.II/source/dofs/dof_accessor.cc +++ b/deal.II/deal.II/source/dofs/dof_accessor.cc @@ -4,6 +4,7 @@ #include +#include #include #include #include @@ -23,23 +24,6 @@ /*------------------------- Functions: DoFLineAccessor -----------------------*/ -template -inline -int DoFLineAccessor::dof_index (const unsigned int i) const { - Assert (dof_handler != 0, ExcInvalidObject()); - // make sure a FE has been selected - // and enough room was reserved - Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); - Assert (iselected_fe->dofs_per_line, - ExcInvalidIndex (i, 0, dof_handler->selected_fe->dofs_per_line)); - - return dof_handler->levels[present_level] - ->line_dofs[present_index*dof_handler->selected_fe->dofs_per_line+i]; -}; - - - - template void DoFLineAccessor::set_dof_index (const unsigned int i, @@ -58,24 +42,6 @@ void DoFLineAccessor::set_dof_index (const unsigned int i, -template -inline -int DoFLineAccessor::vertex_dof_index (const unsigned int vertex, - const unsigned int i) const { - Assert (dof_handler != 0, ExcInvalidObject()); - Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); - Assert (vertex<2, ExcInvalidIndex (i,0,2)); - Assert (iselected_fe->dofs_per_vertex, - ExcInvalidIndex (i, 0, dof_handler->selected_fe->dofs_per_vertex)); - - const unsigned int dof_number = (vertex_index(vertex) * - dof_handler->selected_fe->dofs_per_vertex + - i); - return dof_handler->vertex_dofs[dof_number]; -}; - - - template void DoFLineAccessor::set_vertex_dof_index (const unsigned int vertex, const unsigned int i, @@ -94,44 +60,6 @@ void DoFLineAccessor::set_vertex_dof_index (const unsigned int ve -template -void -DoFLineAccessor::get_dof_indices (vector &dof_indices) const { - Assert (dof_handler != 0, ExcInvalidObject()); - Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); - Assert (dof_indices.size() == (2*dof_handler->get_fe().dofs_per_vertex + - dof_handler->get_fe().dofs_per_line), - ExcVectorDoesNotMatch()); - - const unsigned int dofs_per_vertex = dof_handler->get_fe().dofs_per_vertex, - dofs_per_line = dof_handler->get_fe().dofs_per_line; - vector::iterator next = dof_indices.begin(); - for (unsigned int vertex=0; vertex<2; ++vertex) - for (unsigned int d=0; d -TriaIterator > -DoFLineAccessor::child (const unsigned int i) const { - TriaIterator > q (tria, - present_level+1, - child_index (i), - dof_handler); - -#ifdef DEBUG - if (q.state() != past_the_end) - Assert (q->used(), typename TriaAccessor::ExcUnusedCellAsChild()); -#endif - return q; -}; - - - template void DoFLineAccessor:: distribute_local_to_global (const Vector &local_source, @@ -187,33 +115,9 @@ distribute_local_to_global (const FullMatrix &local_source, -template -void DoFLineAccessor::copy_from (const DoFLineAccessor &a) { - BaseClass::copy_from (a); - set_dof_handler (a.dof_handler); -}; - - - /*------------------------- Functions: DoFQuadAccessor -----------------------*/ -template -inline -int DoFQuadAccessor::dof_index (const unsigned int i) const { - Assert (dof_handler != 0, ExcInvalidObject()); - // make sure a FE has been selected - // and enough room was reserved - Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); - Assert (iselected_fe->dofs_per_quad, - ExcInvalidIndex (i, 0, dof_handler->selected_fe->dofs_per_quad)); - - return dof_handler->levels[present_level] - ->quad_dofs[present_index*dof_handler->selected_fe->dofs_per_quad+i]; -}; - - - template void DoFQuadAccessor::set_dof_index (const unsigned int i, const int index) const { @@ -230,24 +134,6 @@ void DoFQuadAccessor::set_dof_index (const unsigned int i, -template -inline -int DoFQuadAccessor::vertex_dof_index (const unsigned int vertex, - const unsigned int i) const { - Assert (dof_handler != 0, ExcInvalidObject()); - Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); - Assert (vertex<4, ExcInvalidIndex (i,0,4)); - Assert (iselected_fe->dofs_per_vertex, - ExcInvalidIndex (i, 0, dof_handler->selected_fe->dofs_per_vertex)); - - const unsigned int dof_number = (vertex_index(vertex) * - dof_handler->selected_fe->dofs_per_vertex + - i); - return dof_handler->vertex_dofs[dof_number]; -}; - - - template void DoFQuadAccessor::set_vertex_dof_index (const unsigned int vertex, const unsigned int i, @@ -266,65 +152,6 @@ void DoFQuadAccessor::set_vertex_dof_index (const unsigned int ve -template -void -DoFQuadAccessor::get_dof_indices (vector &dof_indices) const { - Assert (dof_handler != 0, ExcInvalidObject()); - Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); - Assert (dof_indices.size() == (4*dof_handler->get_fe().dofs_per_vertex + - 4*dof_handler->get_fe().dofs_per_line + - dof_handler->get_fe().dofs_per_quad), - ExcVectorDoesNotMatch()); - - const unsigned int dofs_per_vertex = dof_handler->get_fe().dofs_per_vertex, - dofs_per_line = dof_handler->get_fe().dofs_per_line, - dofs_per_quad = dof_handler->get_fe().dofs_per_quad; - vector::iterator next = dof_indices.begin(); - for (unsigned int vertex=0; vertex<4; ++vertex) - for (unsigned int d=0; dline(line)->dof_index(d); - for (unsigned int d=0; d -TriaIterator > > -DoFQuadAccessor::line (const unsigned int i) const { - Assert (i<4, ExcInvalidIndex (i, 0, 4)); - - return TriaIterator > > - ( - tria, - present_level, - line_index (i), - dof_handler - ); -}; - - - -template -TriaIterator > -DoFQuadAccessor::child (const unsigned int i) const { - TriaIterator > q (tria, - present_level+1, - child_index (i), - dof_handler); - -#ifdef DEBUG - if (q.state() != past_the_end) - Assert (q->used(), typename TriaAccessor::ExcUnusedCellAsChild()); -#endif - return q; -}; - - - template void DoFQuadAccessor:: distribute_local_to_global (const Vector &local_source, @@ -382,33 +209,10 @@ distribute_local_to_global (const FullMatrix &local_source, -template -void DoFQuadAccessor::copy_from (const DoFQuadAccessor &a) { - BaseClass::copy_from (a); - set_dof_handler (a.dof_handler); -}; - - /*------------------------- Functions: DoFHexAccessor -----------------------*/ -template -inline -int DoFHexAccessor::dof_index (const unsigned int i) const { - Assert (dof_handler != 0, ExcInvalidObject()); - // make sure a FE has been selected - // and enough room was reserved - Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); - Assert (iselected_fe->dofs_per_hex, - ExcInvalidIndex (i, 0, dof_handler->selected_fe->dofs_per_hex)); - - return dof_handler->levels[present_level] - ->hex_dofs[present_index*dof_handler->selected_fe->dofs_per_hex+i]; -}; - - - template void DoFHexAccessor::set_dof_index (const unsigned int i, const int index) const { @@ -425,24 +229,6 @@ void DoFHexAccessor::set_dof_index (const unsigned int i, -template -inline -int DoFHexAccessor::vertex_dof_index (const unsigned int vertex, - const unsigned int i) const { - Assert (dof_handler != 0, ExcInvalidObject()); - Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); - Assert (vertex<8, ExcInvalidIndex (i,0,8)); - Assert (iselected_fe->dofs_per_vertex, - ExcInvalidIndex (i, 0, dof_handler->selected_fe->dofs_per_vertex)); - - const unsigned int dof_number = (vertex_index(vertex) * - dof_handler->selected_fe->dofs_per_vertex + - i); - return dof_handler->vertex_dofs[dof_number]; -}; - - - template void DoFHexAccessor::set_vertex_dof_index (const unsigned int vertex, const unsigned int i, @@ -461,85 +247,6 @@ void DoFHexAccessor::set_vertex_dof_index (const unsigned int ver -template -void -DoFHexAccessor::get_dof_indices (vector &dof_indices) const { - Assert (dof_handler != 0, ExcInvalidObject()); - Assert (dof_handler->selected_fe != 0, ExcInvalidObject()); - Assert (dof_indices.size() == (8*dof_handler->get_fe().dofs_per_vertex + - 12*dof_handler->get_fe().dofs_per_line + - 6*dof_handler->get_fe().dofs_per_quad + - dof_handler->get_fe().dofs_per_hex), - ExcVectorDoesNotMatch()); - - const unsigned int dofs_per_vertex = dof_handler->get_fe().dofs_per_vertex, - dofs_per_line = dof_handler->get_fe().dofs_per_line, - dofs_per_quad = dof_handler->get_fe().dofs_per_quad, - dofs_per_hex = dof_handler->get_fe().dofs_per_hex; - vector::iterator next = dof_indices.begin(); - for (unsigned int vertex=0; vertex<8; ++vertex) - for (unsigned int d=0; dline(line)->dof_index(d); - for (unsigned int quad=0; quad<6; ++quad) - for (unsigned int d=0; dquad(quad)->dof_index(d); - for (unsigned int d=0; d -TriaIterator > > -DoFHexAccessor::line (const unsigned int i) const { - TriaIterator > l = BaseClass::line(i); - return TriaIterator > > - ( - tria, - present_level, - l->index(), - dof_handler - ); -}; - - - -template -TriaIterator > > -DoFHexAccessor::quad (const unsigned int i) const { - Assert (i<6, ExcInvalidIndex (i, 0, 6)); - - return TriaIterator > > - ( - tria, - present_level, - quad_index (i), - dof_handler - ); -}; - - - -template -TriaIterator > -DoFHexAccessor::child (const unsigned int i) const { - TriaIterator > q (tria, - present_level+1, - child_index (i), - dof_handler); - -#ifdef DEBUG - if (q.state() != past_the_end) - Assert (q->used(), typename TriaAccessor::ExcUnusedCellAsChild()); -#endif - return q; -}; - - - template void DoFHexAccessor:: distribute_local_to_global (const Vector &local_source, @@ -599,52 +306,11 @@ distribute_local_to_global (const FullMatrix &local_source, -template -void DoFHexAccessor::copy_from (const DoFHexAccessor &a) { - BaseClass::copy_from (a); - set_dof_handler (a.dof_handler); -}; - - - - /*------------------------- Functions: DoFCellAccessor -----------------------*/ -template -TriaIterator > -DoFCellAccessor::neighbor (const unsigned int i) const { - TriaIterator > q (tria, - neighbor_level (i), - neighbor_index (i), - dof_handler); - -#ifdef DEBUG - if (q.state() != past_the_end) - Assert (q->used(), typename TriaAccessor::ExcUnusedCellAsNeighbor()); -#endif - return q; -}; - - - -template -TriaIterator > -DoFCellAccessor::child (const unsigned int i) const { - TriaIterator > q (tria, - present_level+1, - child_index (i), - dof_handler); - -#ifdef DEBUG - if (q.state() != past_the_end) - Assert (q->used(), typename TriaAccessor::ExcUnusedCellAsChild()); -#endif - return q; -}; - #if deal_II_dimension == 1 diff --git a/deal.II/deal.II/source/grid/tria_accessor.cc b/deal.II/deal.II/source/grid/tria_accessor.cc index d580f5ebed..3b82da72eb 100644 --- a/deal.II/deal.II/source/grid/tria_accessor.cc +++ b/deal.II/deal.II/source/grid/tria_accessor.cc @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -13,64 +14,6 @@ -/*------------------------ Functions: LineAccessor ---------------------------*/ - -template -void TriaAccessor::copy_from (const TriaAccessor &a) { - present_level = a.present_level; - present_index = a.present_index; - tria = a.tria; -}; - - - -template -bool TriaAccessor::operator == (const TriaAccessor &a) const { - Assert (tria == a.tria, ExcCantCompareIterators()); - return ((present_index == a.present_index) && - (present_level == a.present_level)); -}; - - - -template -bool TriaAccessor::operator != (const TriaAccessor &a) const { - Assert (tria == a.tria, ExcCantCompareIterators()); - return ((present_index != a.present_index) || - (present_level != a.present_level)); -}; - - - -template -int TriaAccessor::level () const { - return present_level; -}; - - - -template -int TriaAccessor::index () const { - return present_index; -}; - - - - -template -IteratorState TriaAccessor::state () const { - if ((present_level>=0) && (present_index>=0)) - return valid; - else - if ((present_level==-1) && (present_index==-1)) - return past_the_end; - else - return invalid; -}; - - - - @@ -99,14 +42,6 @@ LineAccessor::vertex (const unsigned int i) const { -template -bool LineAccessor::used () const { - Assert (state() == valid, ExcDereferenceInvalidObject()); - return tria->levels[present_level]->lines.used[present_index]; -}; - - - template void LineAccessor::set_used_flag () const { Assert (state() == valid, ExcDereferenceInvalidObject()); @@ -122,29 +57,6 @@ void LineAccessor::clear_used_flag () const { }; -template -bool LineAccessor::user_flag_set () const { - Assert (used(), ExcCellNotUsed()); - return tria->levels[present_level]->lines.user_flags[present_index]; -}; - - - -template -void LineAccessor::set_user_flag () const { - Assert (used(), ExcCellNotUsed()); - tria->levels[present_level]->lines.user_flags[present_index] = true; -}; - - - -template -void LineAccessor::clear_user_flag () const { - Assert (used(), ExcCellNotUsed()); - tria->levels[present_level]->lines.user_flags[present_index] = false; -}; - - template void LineAccessor::recursively_set_user_flag () const { @@ -189,33 +101,7 @@ void * LineAccessor::user_pointer () const { Assert (used(), ExcCellNotUsed()); return tria->levels[present_level]->lines.user_pointers[present_index]; }; - - - - -template -TriaIterator > -LineAccessor::child (const unsigned int i) const { - Assert (i<2, ExcInvalidIndex(i,0,1)); - TriaIterator > q (tria, present_level+1, child_index (i)); - -#ifdef DEBUG - if (q.state() != past_the_end) - Assert (q->used(), ExcUnusedCellAsChild()); -#endif - return q; -}; - - -template -int LineAccessor::child_index (unsigned int i) const { - Assert (i<2, ExcInvalidIndex(i,0,1)); - return tria->levels[present_level]->lines.children[present_index]+i; -}; - - - template void LineAccessor::set_children (const int index) const { @@ -235,62 +121,6 @@ void LineAccessor::clear_children () const { -template -bool LineAccessor::has_children () const { - Assert (state() == valid, ExcDereferenceInvalidObject()); - return (tria->levels[present_level]->lines.children[present_index] != -1); -} - - - -template -void LineAccessor::operator ++ () { - ++present_index; - // is index still in the range of - // the vector? - while (present_index - >= - (int)tria->levels[present_level]->lines.lines.size()) - { - // no -> go one level up until we find - // one with more than zero cells - ++present_level; - present_index = 0; - // highest level reached? - if (present_level >= (int)tria->levels.size()) - { - // return with past the end pointer - present_level = present_index = -1; - return; - }; - }; -}; - - - -template -void LineAccessor::operator -- () { - --present_index; - // is index still in the range of - // the vector? - while (present_index < 0) - { - // no -> go one level down - --present_level; - // lowest level reached? - if (present_level == -1) - { - // return with past the end pointer - present_level = present_index = -1; - return; - }; - // else - present_index = tria->levels[present_level]->lines.lines.size()-1; - }; -}; - - - template unsigned char LineAccessor::boundary_indicator () const { Assert (dim>=2, ExcNotUsefulForThisDimension()); @@ -391,16 +221,10 @@ QuadAccessor::vertex (const unsigned int i) const { -template -bool QuadAccessor::used () const { - Assert (state() == valid, ExcDereferenceInvalidObject()); - return tria->levels[present_level]->quads.used[present_index]; -}; - - template -void QuadAccessor::set_used_flag () const { +void +QuadAccessor::set_used_flag () const { Assert (state() == valid, ExcDereferenceInvalidObject()); tria->levels[present_level]->quads.used[present_index] = true; }; @@ -415,31 +239,6 @@ void QuadAccessor::clear_used_flag () const { - -template -bool QuadAccessor::user_flag_set () const { - Assert (used(), ExcCellNotUsed()); - return tria->levels[present_level]->quads.user_flags[present_index]; -}; - - - -template -void QuadAccessor::set_user_flag () const { - Assert (used(), ExcCellNotUsed()); - tria->levels[present_level]->quads.user_flags[present_index] = true; -}; - - - -template -void QuadAccessor::clear_user_flag () const { - Assert (used(), ExcCellNotUsed()); - tria->levels[present_level]->quads.user_flags[present_index] = false; -}; - - - template void QuadAccessor::recursively_set_user_flag () const { set_user_flag (); @@ -486,54 +285,6 @@ void * QuadAccessor::user_pointer () const { - -template -TriaIterator > -QuadAccessor::line (const unsigned int i) const { - return - TriaIterator > - ( - tria, - present_level, - line_index (i) - ); -}; - - - -template -unsigned int QuadAccessor::line_index (unsigned int i) const { - Assert (i<4, ExcInvalidIndex(i,0,3)); - - return tria->levels[present_level]->quads.quads[present_index].line(i); -}; - - - -template -TriaIterator > -QuadAccessor::child (const unsigned int i) const { - Assert (i<4, ExcInvalidIndex(i,0,3)); - - TriaIterator > q (tria, present_level+1, child_index (i)); - -#ifdef DEBUG - if (q.state() != past_the_end) - Assert (q->used(), ExcUnusedCellAsChild()); -#endif - return q; -}; - - - -template -int QuadAccessor::child_index (unsigned int i) const { - Assert (i<4, ExcInvalidIndex(i,0,3)); - return tria->levels[present_level]->quads.children[present_index]+i; -}; - - - template void QuadAccessor::set_children (const int index) const { Assert (used(), ExcCellNotUsed()); @@ -552,61 +303,6 @@ void QuadAccessor::clear_children () const { -template -bool QuadAccessor::has_children () const { - Assert (state() == valid, ExcDereferenceInvalidObject()); - return (tria->levels[present_level]->quads.children[present_index] != -1); -}; - - - -template -void QuadAccessor::operator ++ () { - ++present_index; - // is index still in the range of - // the vector? - while (present_index - >= - (int)tria->levels[present_level]->quads.quads.size()) - { - // no -> go one level up - ++present_level; - present_index = 0; - // highest level reached? - if (present_level >= (int)tria->levels.size()) - { - // return with past the end pointer - present_level = present_index = -1; - return; - }; - }; -}; - - - -template -void QuadAccessor::operator -- () { - --present_index; - // is index still in the range of - // the vector? - while (present_index < 0) - { - // no -> go one level down - --present_level; - // lowest level reached? - if (present_level == -1) - { - // return with past the end pointer - present_level = present_index = -1; - return; - }; - // else - present_index = tria->levels[present_level]->quads.quads.size()-1; - }; -}; - - - template unsigned char QuadAccessor::boundary_indicator () const { Assert (dim>=3, ExcNotUsefulForThisDimension()); @@ -828,14 +524,6 @@ HexAccessor::vertex (const unsigned int i) const { -template -bool HexAccessor::used () const { - Assert (state() == valid, ExcDereferenceInvalidObject()); - return tria->levels[present_level]->hexes.used[present_index]; -}; - - - template void HexAccessor::set_used_flag () const { Assert (state() == valid, ExcDereferenceInvalidObject()); @@ -853,30 +541,6 @@ void HexAccessor::clear_used_flag () const { -template -bool HexAccessor::user_flag_set () const { - Assert (used(), ExcCellNotUsed()); - return tria->levels[present_level]->hexes.user_flags[present_index]; -}; - - - -template -void HexAccessor::set_user_flag () const { - Assert (used(), ExcCellNotUsed()); - tria->levels[present_level]->hexes.user_flags[present_index] = true; -}; - - - -template -void HexAccessor::clear_user_flag () const { - Assert (used(), ExcCellNotUsed()); - tria->levels[present_level]->hexes.user_flags[present_index] = false; -}; - - - template void HexAccessor::recursively_set_user_flag () const { set_user_flag (); @@ -923,84 +587,6 @@ void * HexAccessor::user_pointer () const { - -template -TriaIterator > -HexAccessor::line (const unsigned int i) const { - Assert (used(), ExcCellNotUsed()); - Assert (i<12, ExcInvalidIndex (i,0,11)); - - if (i<4) - return quad(0)->line(i); - else - if (i<8) - return quad(1)->line(i-4); - else - switch (i) - { - case 8: - return quad(2)->line(3); - case 9: - return quad(2)->line(1); - case 10: - return quad(4)->line(1); - case 11: - return quad(4)->line(3); - }; - Assert (false, ExcInvalidIndex(i,0,11)); - return TriaIterator >(tria, -1, -1, 0); -}; - - - -template -TriaIterator > -HexAccessor::quad (const unsigned int i) const { - Assert (used(), ExcCellNotUsed()); - return - TriaIterator > - ( - tria, - present_level, - quad_index (i) - ); -}; - - - -template -unsigned int HexAccessor::quad_index (unsigned int i) const { - Assert (i<6, ExcInvalidIndex(i,0,5)); - - return tria->levels[present_level]->hexes.hexes[present_index].quad(i); -}; - - - -template -TriaIterator > -HexAccessor::child (const unsigned int i) const { - Assert (i<6, ExcInvalidIndex(i,0,5)); - - TriaIterator > q (tria, present_level+1, child_index (i)); - -#ifdef DEBUG - if (q.state() != past_the_end) - Assert (q->used(), ExcUnusedCellAsChild()); -#endif - return q; -}; - - - -template -int HexAccessor::child_index (unsigned int i) const { - Assert (i<8, ExcInvalidIndex(i,0,7)); - return tria->levels[present_level]->hexes.children[present_index]+i; -}; - - - template void HexAccessor::set_children (const int index) const { Assert (used(), ExcCellNotUsed()); @@ -1027,53 +613,6 @@ bool HexAccessor::has_children () const { -template -void HexAccessor::operator ++ () { - ++present_index; - // is index still in the range of - // the vector? - while (present_index - >= - (int)tria->levels[present_level]->hexes.hexes.size()) - { - // no -> go one level up - ++present_level; - present_index = 0; - // highest level reached? - if (present_level >= (int)tria->levels.size()) - { - // return with past the end pointer - present_level = present_index = -1; - return; - }; - }; -}; - - - -template -void HexAccessor::operator -- () { - --present_index; - // is index still in the range of - // the vector? - while (present_index < 0) - { - // no -> go one level down - --present_level; - // lowest level reached? - if (present_level == -1) - { - // return with past the end pointer - present_level = present_index = -1; - return; - }; - // else - present_index = tria->levels[present_level]->hexes.hexes.size()-1; - }; -}; - - - template unsigned char HexAccessor::boundary_indicator () const { Assert (dim<4, ExcNotUsefulForThisDimension()); @@ -1899,16 +1438,9 @@ void CellAccessor<1>::set_material_id (const unsigned char mat_id) const { }; - -template <> -Triangulation<1>::face_iterator -CellAccessor<1>::face (const unsigned int) const { - Assert (false, ExcNotUsefulForThisDimension()); - return 0; -}; - #endif + /*------------------------ Functions: CellAccessor<2> -----------------------*/ @@ -1938,14 +1470,6 @@ void CellAccessor<2>::set_material_id (const unsigned char mat_id) const { = mat_id; }; - - -template <> -Triangulation<2>::face_iterator -CellAccessor<2>::face (const unsigned int i) const { - return line(i); -}; - #endif @@ -1981,40 +1505,12 @@ void CellAccessor<3>::set_material_id (const unsigned char mat_id) const { = mat_id; }; - - -template <> -Triangulation<3>::face_iterator -CellAccessor<3>::face (const unsigned int i) const { - return quad(i); -}; - #endif /*------------------------ Functions: CellAccessor -----------------------*/ -template -int CellAccessor::neighbor_index (const unsigned int i) const { - Assert (i::faces_per_cell, - typename TriaSubstructAccessor::ExcInvalidNeighbor(i)); - return tria->levels[present_level]-> - neighbors[present_index*GeometryInfo::faces_per_cell+i].second; -}; - - - -template -int CellAccessor::neighbor_level (const unsigned int i) const { - Assert (i::faces_per_cell, - typename TriaSubstructAccessor::ExcInvalidNeighbor(i)); - return tria->levels[present_level]-> - neighbors[present_index*GeometryInfo::faces_per_cell+i].first; -}; - - - template void CellAccessor::set_neighbor (const unsigned int i, const TriaIterator > &pointer) const { @@ -2055,114 +1551,6 @@ bool CellAccessor::at_boundary (const unsigned int i) const { -template -bool CellAccessor::refine_flag_set () const { - Assert (used(), typename TriaSubstructAccessor::ExcCellNotUsed()); - // cells flagged for refinement must be active - // (the #set_refine_flag# function checks this, - // but activity may change when refinement is - // executed and for some reason the refine - // flag is not cleared). - Assert (active() || !tria->levels[present_level]->refine_flags[present_index], - ExcRefineCellNotActive()); - return tria->levels[present_level]->refine_flags[present_index]; -}; - - - -template -void CellAccessor::set_refine_flag () const { - Assert (used() && active(), ExcRefineCellNotActive()); - Assert (!coarsen_flag_set(), ExcCellFlaggedForCoarsening()); - - tria->levels[present_level]->refine_flags[present_index] = true; -}; - - - -template -void CellAccessor::clear_refine_flag () const { - Assert (used() && active(), ExcRefineCellNotActive()); - tria->levels[present_level]->refine_flags[present_index] = false; -}; - - - -template -bool CellAccessor::coarsen_flag_set () const { - Assert (used(), typename TriaSubstructAccessor::ExcCellNotUsed()); - // cells flagged for coarsening must be active - // (the #set_refine_flag# function checks this, - // but activity may change when refinement is - // executed and for some reason the refine - // flag is not cleared). - Assert (active() || !tria->levels[present_level]->coarsen_flags[present_index], - ExcRefineCellNotActive()); - return tria->levels[present_level]->coarsen_flags[present_index]; -}; - - - -template -void CellAccessor::set_coarsen_flag () const { - Assert (used() && active(), ExcRefineCellNotActive()); - Assert (!refine_flag_set(), ExcCellFlaggedForRefinement()); - - tria->levels[present_level]->coarsen_flags[present_index] = true; -}; - - - -template -void CellAccessor::clear_coarsen_flag () const { - Assert (used() && active(), ExcRefineCellNotActive()); - tria->levels[present_level]->coarsen_flags[present_index] = false; -}; - - - -template -TriaIterator > -CellAccessor::neighbor (const unsigned int i) const { - TriaIterator > q (tria, neighbor_level (i), neighbor_index (i)); - -#ifdef DEBUG - if (q.state() != past_the_end) - Assert (q->used(), - typename TriaSubstructAccessor::ExcUnusedCellAsNeighbor()); -#endif - return q; -}; - - - -template -TriaIterator > -CellAccessor::child (const unsigned int i) const { - TriaIterator > q (tria, present_level+1, child_index (i)); - -#ifdef DEBUG - if (q.state() != past_the_end) - Assert (q->used(), - typename TriaSubstructAccessor::ExcUnusedCellAsChild()); -#endif - return q; -}; - - - -template -bool CellAccessor::active () const { - return !has_children(); -}; - - - - - - - - // explicit instantiations diff --git a/tests/big-tests/grid/grid_test.cc b/tests/big-tests/grid/grid_test.cc index fe2dd4feff..f4aa02e899 100644 --- a/tests/big-tests/grid/grid_test.cc +++ b/tests/big-tests/grid/grid_test.cc @@ -3,6 +3,7 @@ #include +#include #include #include #include