From: Wolfgang Bangerth Date: Tue, 1 Mar 2005 18:04:59 +0000 (+0000) Subject: Work around a lose end left over from when we wrote the MG code initially back in... X-Git-Tag: v8.0.0~14576 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3d274df4bd644ce6d625e0d761bcaeb3176e4f4;p=dealii.git Work around a lose end left over from when we wrote the MG code initially back in 1999. git-svn-id: https://svn.dealii.org/trunk@9932 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/multigrid/mg_dof_handler.h b/deal.II/deal.II/include/multigrid/mg_dof_handler.h index 39d1f09064..0904913095 100644 --- a/deal.II/deal.II/include/multigrid/mg_dof_handler.h +++ b/deal.II/deal.II/include/multigrid/mg_dof_handler.h @@ -949,7 +949,8 @@ class MGDoFHandler : public DoFHandler * needed and need not handle * growing arrays and the like. */ - class MGVertexDoFs { + class MGVertexDoFs + { public: /** @@ -968,6 +969,14 @@ class MGDoFHandler : public DoFHandler /** * Allocate memory and set * all indices to @p -1. + * + * If @p coarsest_level is + * greater than @p + * finest_level, then no + * memory is allocated and + * the object is left in an + * invalid state. This is + * used for unused vertices. */ void init (const unsigned int coarsest_level, const unsigned int finest_level, @@ -978,6 +987,14 @@ class MGDoFHandler : public DoFHandler */ ~MGVertexDoFs (); + /** + * Assignment operator. Will + * throw an exception since + * it can't do the work that + * @p init is supposed to do. + */ + MGVertexDoFs & operator = (const MGVertexDoFs &vertex); + /** * Set the index with number * @p dof_number of this diff --git a/deal.II/deal.II/source/multigrid/mg_dof_handler.cc b/deal.II/deal.II/source/multigrid/mg_dof_handler.cc index 1b7576ad76..0ef8768172 100644 --- a/deal.II/deal.II/source/multigrid/mg_dof_handler.cc +++ b/deal.II/deal.II/source/multigrid/mg_dof_handler.cc @@ -32,8 +32,9 @@ /* ------------------------ MGVertexDoFs ----------------------------------- */ template -MGDoFHandler::MGVertexDoFs::MGVertexDoFs () : - coarsest_level (1<<30), +MGDoFHandler::MGVertexDoFs::MGVertexDoFs () + : + coarsest_level (deal_II_numbers::invalid_unsigned_int), finest_level (0), indices (0) {} @@ -42,12 +43,23 @@ MGDoFHandler::MGVertexDoFs::MGVertexDoFs () : template void MGDoFHandler::MGVertexDoFs::init (const unsigned int cl, const unsigned int fl, - const unsigned int dofs_per_vertex) { - Assert (indices == 0, ExcInternalError()); + const unsigned int dofs_per_vertex) +{ + if (indices != 0) + { + delete[] indices; + indices = 0; + } coarsest_level = cl; finest_level = fl; + // in the case where an invalid + // entry is requested, just leave + // everything else alone + if (cl > fl) + return; + const unsigned int n_levels = finest_level-coarsest_level + 1; indices = new unsigned int[n_levels * dofs_per_vertex]; @@ -64,6 +76,18 @@ MGDoFHandler::MGVertexDoFs::~MGVertexDoFs () { } +template +typename MGDoFHandler::MGVertexDoFs & +MGDoFHandler::MGVertexDoFs::operator = (const MGVertexDoFs &) +{ + Assert (false, + ExcMessage ("We don't know how many dofs per vertex there are, so there's " + "no way we can copy the 'indices' array")); + return *this; +} + + + template inline unsigned int MGDoFHandler::MGVertexDoFs::get_coarsest_level () const { @@ -1640,6 +1664,8 @@ void MGDoFHandler<2>::reserve_space () { // vertex we pass by belongs to mg_vertex_dofs.resize (this->tria->vertices.size()); + // initialize these arrays with + // invalid values (min>max) std::vector min_level (this->tria->vertices.size(), this->tria->n_levels()); std::vector max_level (this->tria->vertices.size(), 0); @@ -1655,20 +1681,28 @@ void MGDoFHandler<2>::reserve_space () { min_level[vertex_index] = cell->level(); if (max_level[vertex_index] < static_cast(cell->level())) max_level[vertex_index] = cell->level(); - }; + } // now allocate the needed space for (unsigned int vertex=0; vertextria->vertices.size(); ++vertex) - { -//TODO:[WB,GK] These conditions are violated on unused vertices - Assert (min_level[vertex] < this->tria->n_levels(), ExcInternalError()); - Assert (max_level[vertex] >= min_level[vertex], ExcInternalError()); + if (this->tria->vertices_used[vertex]) + { + Assert (min_level[vertex] < this->tria->n_levels(), ExcInternalError()); + Assert (max_level[vertex] >= min_level[vertex], ExcInternalError()); + + mg_vertex_dofs[vertex].init (min_level[vertex], + max_level[vertex], + this->selected_fe->dofs_per_vertex); + } + else + { + Assert (min_level[vertex] == this->tria->n_levels(), ExcInternalError()); + Assert (max_level[vertex] == 0, ExcInternalError()); - mg_vertex_dofs[vertex].init (min_level[vertex], - max_level[vertex], - this->selected_fe->dofs_per_vertex); - }; + // reset to original state + mg_vertex_dofs[vertex].init (1, 0, 0); + } } #endif