From 42d242b1785925c6e3dc8ef7595007a12324b737 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 15 Jul 2009 03:19:09 +0000 Subject: [PATCH] Re-indent a couple functions. git-svn-id: https://svn.dealii.org/trunk@19082 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/source/grid/grid_tools.cc | 357 +++++++++++----------- 1 file changed, 180 insertions(+), 177 deletions(-) diff --git a/deal.II/deal.II/source/grid/grid_tools.cc b/deal.II/deal.II/source/grid/grid_tools.cc index f7d4510b3e..427ff0d354 100644 --- a/deal.II/deal.II/source/grid/grid_tools.cc +++ b/deal.II/deal.II/source/grid/grid_tools.cc @@ -553,6 +553,7 @@ GridTools::scale (const double scaling_factor, } + template class Container, int spacedim> unsigned int GridTools::find_closest_vertex (const Container &container, @@ -562,37 +563,37 @@ GridTools::find_closest_vertex (const Container &container, // triangulation from the // container and determine vertices // and used vertices - const Triangulation &tria = get_tria(container); + const Triangulation &tria = get_tria(container); - const std::vector< Point > &vertices = tria.get_vertices(); - const std::vector< bool > &used = tria.get_used_vertices(); + const std::vector< Point > &vertices = tria.get_vertices(); + const std::vector< bool > &used = tria.get_used_vertices(); // At the beginning, the first // used vertex is the closest one - std::vector::const_iterator first = - std::find(used.begin(), used.end(), true); + std::vector::const_iterator first = + std::find(used.begin(), used.end(), true); // Assert that at least one vertex // is actually used - Assert(first != used.end(), ExcInternalError()); + Assert(first != used.end(), ExcInternalError()); - unsigned int best_vertex = std::distance(used.begin(), first); - double best_dist = (p - vertices[best_vertex]).square(); + unsigned int best_vertex = std::distance(used.begin(), first); + double best_dist = (p - vertices[best_vertex]).square(); // For all remaining vertices, test // whether they are any closer - for(unsigned int j = best_vertex+1; j < vertices.size(); j++) - if(used[j]) - { - double dist = (p - vertices[j]).square(); - if(dist < best_dist) - { - best_vertex = j; - best_dist = dist; - } - } - - return best_vertex; + for(unsigned int j = best_vertex+1; j < vertices.size(); j++) + if(used[j]) + { + double dist = (p - vertices[j]).square(); + if(dist < best_dist) + { + best_vertex = j; + best_dist = dist; + } + } + + return best_vertex; } @@ -604,114 +605,116 @@ GridTools::find_cells_adjacent_to_vertex(const Container &containe // make sure that the given vertex is // an active vertex of the underlying // triangulation - Assert(vertex < get_tria(container).n_vertices(), - ExcIndexRange(0,get_tria(container).n_vertices(),vertex)); - Assert(get_tria(container).get_used_vertices()[vertex], - ExcVertexNotUsed(vertex)); - - // We use a set instead of a vector - // to ensure that cells are inserted only - // once. A bug in the previous version - // prevented some cases to be - // treated correctly - std::set::active_cell_iterator> adj_cells_set; + Assert(vertex < get_tria(container).n_vertices(), + ExcIndexRange(0,get_tria(container).n_vertices(),vertex)); + Assert(get_tria(container).get_used_vertices()[vertex], + ExcVertexNotUsed(vertex)); + + // We use a set instead of a vector + // to ensure that cells are inserted only + // once. A bug in the previous version + // prevented some cases to be + // treated correctly + std::set::active_cell_iterator> adj_cells_set; - typename Container::active_cell_iterator - cell = container.begin_active(), - endc = container.end(); + typename Container::active_cell_iterator + cell = container.begin_active(), + endc = container.end(); // go through all active cells and look // if the vertex is part of that cell - for (; cell != endc; ++cell) - for (unsigned v = 0; v < GeometryInfo::vertices_per_cell; v++) - if (cell->vertex_index(v) == vertex) - { - // OK, we found a cell that contains - // the particular vertex. We add it - // to the list. - adj_cells_set.insert(cell); - - // Now we need to make sure that the - // vertex is not a locally refined - // vertex not being part of the - // neighboring cells. So we loop over - // all faces to which this vertex - // belongs, check the level of - // the neighbor, and if it is coarser, - // then check whether the vertex is - // part of that neighbor or not. - for (unsigned vface = 0; vface < dim; vface++) - { - const unsigned face = - GeometryInfo::vertex_to_face[v][vface]; - if (!cell->at_boundary(face)) - { - typename Container::cell_iterator - nb = cell->neighbor(face); + for (; cell != endc; ++cell) + for (unsigned v = 0; v < GeometryInfo::vertices_per_cell; v++) + if (cell->vertex_index(v) == vertex) + { + // OK, we found a cell that contains + // the particular vertex. We add it + // to the list. + adj_cells_set.insert(cell); + + // Now we need to make sure that the + // vertex is not a locally refined + // vertex not being part of the + // neighboring cells. So we loop over + // all faces to which this vertex + // belongs, check the level of + // the neighbor, and if it is coarser, + // then check whether the vertex is + // part of that neighbor or not. + for (unsigned vface = 0; vface < dim; vface++) + { + const unsigned face = + GeometryInfo::vertex_to_face[v][vface]; + if (!cell->at_boundary(face)) + { + typename Container::cell_iterator + nb = cell->neighbor(face); - // Here we - // check - // whether - // the - // neighbor - // is - // coarser. If - // it is, we - // search - // for the - // vertex in - // this - // coarser - // cell and - // only if - // not found - // we will - // add the - // coarser - // cell - // itself - if (nb->level() < cell->level()) - { - bool found = false; - for (unsigned v=0; v::vertices_per_cell; v++) - if (nb->vertex_index(v) == vertex) - { - found = true; - break; - } - if (!found) - adj_cells_set.insert(nb); - } - } - } + // Here we + // check + // whether + // the + // neighbor + // is + // coarser. If + // it is, we + // search + // for the + // vertex in + // this + // coarser + // cell and + // only if + // not found + // we will + // add the + // coarser + // cell + // itself + if (nb->level() < cell->level()) + { + bool found = false; + for (unsigned v=0; v::vertices_per_cell; v++) + if (nb->vertex_index(v) == vertex) + { + found = true; + break; + } + if (!found) + adj_cells_set.insert(nb); + } + } + } - break; - } + break; + } - std::vector::active_cell_iterator> adjacent_cells; - - // We now produce the output vector - // from the set that we assembled above. - typename std::set::active_cell_iterator>::iterator - it = adj_cells_set.begin(), - endit = adj_cells_set.end(); - for(; it != endit; ++it) - adjacent_cells.push_back(*it); + std::vector::active_cell_iterator> + adjacent_cells; + + // We now produce the output vector + // from the set that we assembled above. + typename std::set::active_cell_iterator>::iterator + it = adj_cells_set.begin(), + endit = adj_cells_set.end(); + for(; it != endit; ++it) + adjacent_cells.push_back(*it); - Assert(adjacent_cells.size() > 0, ExcInternalError()); + Assert(adjacent_cells.size() > 0, ExcInternalError()); - return adjacent_cells; + return adjacent_cells; } + template class Container, int spacedim> typename Container::active_cell_iterator GridTools::find_active_cell_around_point (const Container &container, const Point &p) { - return find_active_cell_around_point(StaticMappingQ1::mapping, - container, p).first; + return find_active_cell_around_point(StaticMappingQ1::mapping, + container, p).first; } @@ -721,52 +724,52 @@ GridTools::find_active_cell_around_point (const Mapping &mapping const Container &container, const Point &p) { - typedef typename Container::active_cell_iterator cell_iterator; + typedef typename Container::active_cell_iterator cell_iterator; // The best distance is set to the // maximum allowable distance from // the unit cell; we assume a // max. deviation of 1e-10 - double best_distance = 1e-10; - int best_level = -1; - std::pair > best_cell; + double best_distance = 1e-10; + int best_level = -1; + std::pair > best_cell; // Find closest vertex and determine // all adjacent cells - unsigned int vertex = find_closest_vertex(container, p); + unsigned int vertex = find_closest_vertex(container, p); - std::vector adjacent_cells = - find_cells_adjacent_to_vertex(container, vertex); + std::vector adjacent_cells = + find_cells_adjacent_to_vertex(container, vertex); - typename std::vector::const_iterator - cell = adjacent_cells.begin(), - endc = adjacent_cells.end(); + typename std::vector::const_iterator + cell = adjacent_cells.begin(), + endc = adjacent_cells.end(); - for(; cell != endc; ++cell) - { - const Point p_cell = mapping.transform_real_to_unit_cell(*cell, p); - - // calculate the infinity norm of - // the distance vector to the unit cell. - const double dist = GeometryInfo::distance_to_unit_cell(p_cell); - - // We compare if the point is inside the - // unit cell (or at least not too far - // outside). If it is, it is also checked - // that the cell has a more refined state - if (dist < best_distance || - (dist == best_distance && (*cell)->level() > best_level)) - { - best_distance = dist; - best_level = (*cell)->level(); - best_cell = std::make_pair(*cell, p_cell); - } - } + for(; cell != endc; ++cell) + { + const Point p_cell = mapping.transform_real_to_unit_cell(*cell, p); + + // calculate the infinity norm of + // the distance vector to the unit cell. + const double dist = GeometryInfo::distance_to_unit_cell(p_cell); + + // We compare if the point is inside the + // unit cell (or at least not too far + // outside). If it is, it is also checked + // that the cell has a more refined state + if (dist < best_distance || + (dist == best_distance && (*cell)->level() > best_level)) + { + best_distance = dist; + best_level = (*cell)->level(); + best_cell = std::make_pair(*cell, p_cell); + } + } - Assert (best_cell.first.state() == IteratorState::valid, - ExcPointNotFound(p)); + Assert (best_cell.first.state() == IteratorState::valid, + ExcPointNotFound(p)); - return best_cell; + return best_cell; } @@ -777,53 +780,53 @@ GridTools::find_active_cell_around_point (const hp::MappingCollection &container, const Point &p) { - typedef typename hp::DoFHandler::active_cell_iterator cell_iterator; + typedef typename hp::DoFHandler::active_cell_iterator cell_iterator; // The best distance is set to the // maximum allowable distance from // the unit cell; we assume a // max. deviation of 1e-10 - double best_distance = 1e-10; - int best_level = -1; - std::pair > best_cell; + double best_distance = 1e-10; + int best_level = -1; + std::pair > best_cell; // Find closest vertex and determine // all adjacent cells - unsigned int vertex = find_closest_vertex(container, p); + unsigned int vertex = find_closest_vertex(container, p); - std::vector adjacent_cells = - find_cells_adjacent_to_vertex(container, vertex); + std::vector adjacent_cells = + find_cells_adjacent_to_vertex(container, vertex); - typename std::vector::const_iterator - cell = adjacent_cells.begin(), - endc = adjacent_cells.end(); + typename std::vector::const_iterator + cell = adjacent_cells.begin(), + endc = adjacent_cells.end(); - for(; cell != endc; ++cell) - { - const Point p_cell - = mapping[(*cell)->active_fe_index()].transform_real_to_unit_cell(*cell, p); - - // calculate the infinity norm of - // the distance vector to the unit cell. - const double dist = GeometryInfo::distance_to_unit_cell(p_cell); - - // We compare if the point is inside the - // unit cell (or at least not too far - // outside). If it is, it is also checked - // that the cell has a more refined state - if (dist < best_distance || - (dist == best_distance && (*cell)->level() > best_level)) - { - best_distance = dist; - best_level = (*cell)->level(); - best_cell = std::make_pair(*cell, p_cell); - } - } + for(; cell != endc; ++cell) + { + const Point p_cell + = mapping[(*cell)->active_fe_index()].transform_real_to_unit_cell(*cell, p); + + // calculate the infinity norm of + // the distance vector to the unit cell. + const double dist = GeometryInfo::distance_to_unit_cell(p_cell); + + // We compare if the point is inside the + // unit cell (or at least not too far + // outside). If it is, it is also checked + // that the cell has a more refined state + if (dist < best_distance || + (dist == best_distance && (*cell)->level() > best_level)) + { + best_distance = dist; + best_level = (*cell)->level(); + best_cell = std::make_pair(*cell, p_cell); + } + } - Assert (best_cell.first.state() == IteratorState::valid, - ExcPointNotFound(p)); + Assert (best_cell.first.state() == IteratorState::valid, + ExcPointNotFound(p)); - return best_cell; + return best_cell; } -- 2.39.5