// classes used in deal.II, and @ref CPP11 for more information about
// range-based for loops and the `auto` keyword.
//
- // Next, we want to loop over all vertices of the cells. Since we are
- // in 2d, we know that each cell has exactly four vertices. However,
- // instead of penning down a 4 in the loop bound, we make a first
- // attempt at writing it in a dimension-independent way by which we
- // find out about the number of vertices of a cell. Using the
- // GeometryInfo class, we will later have an easier time getting the
- // program to also run in 3d: we only have to change all occurrences
- // of <code><2></code> to <code><3></code>, and do not
- // have to audit our code for the hidden appearance of magic numbers
- // like a 4 that needs to be replaced by an 8:
- for (unsigned int v = 0; v < GeometryInfo<2>::vertices_per_cell; ++v)
+ // Next, we loop over all vertices of the cells. For that purpose
+ // we query an iterator over indices from zero to four, which happens
+ // to be the number of vertices in 2d. Since the upper bound is
+ // automatically adjusted in all dimensions this enables us a
+ // dimension-independent programming. This will later enable us to
+ // get the program to also run in 3d.
+ for (const auto v : cell->vertex_indices())
{
// If this cell is at the inner boundary, then at least one of its
// vertices must sit on the inner ring and therefore have a radial
@code
bool refinement_indicated = false;
for (const auto &cell : triangulation.active_cell_iterators())
- for (unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
+ for (const auto v : cell->vertex_indices())
if (cell->vertex(v) == Point<dim>(.5,.5))
{
cell->clear_coarsen_flag();
}
if (refinement_indicated)
for (const auto &cell : triangulation.active_cell_iterators())
- for (unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
+ for (const auto v : cell->vertex_indices())
if (cell->vertex(v) == Point<dim>(.5,.5))
cell->set_refine_flag ();
@endcode
bool evaluation_point_found = false;
for (const auto &cell : dof_handler.active_cell_iterators())
if (!evaluation_point_found)
- for (unsigned int vertex = 0;
- vertex < GeometryInfo<dim>::vertices_per_cell;
- ++vertex)
+ for (const auto vertex : cell->vertex_indices())
if (cell->vertex(vertex) == evaluation_point)
{
// In order to extract the point value from the global solution
bool evaluation_point_found = false;
for (const auto &cell : dof_handler.active_cell_iterators())
if (!evaluation_point_found)
- for (unsigned int vertex = 0;
- vertex < GeometryInfo<dim>::vertices_per_cell;
- ++vertex)
+ for (const auto vertex : cell->vertex_indices())
if (cell->vertex(vertex).distance(evaluation_point) <
cell->diameter() * 1e-8)
{
// often the vertex has been found:
unsigned int evaluation_point_hits = 0;
for (const auto &cell : dof_handler.active_cell_iterators())
- for (unsigned int vertex = 0;
- vertex < GeometryInfo<dim>::vertices_per_cell;
- ++vertex)
+ for (const auto vertex : cell->vertex_indices())
if (cell->vertex(vertex) == evaluation_point)
{
// Things are now no more as simple, since we can't get the
std::vector<CellData<dim>> cells(n_cells, CellData<dim>());
for (unsigned int i = 0; i < n_cells; ++i)
{
- for (unsigned int j = 0; j < GeometryInfo<dim>::vertices_per_cell;
- ++j)
+ for (unsigned int j = 0; j < cell_vertices[i].size(); ++j)
cells[i].vertices[j] = cell_vertices[i][j];
cells[i].material_id = 0;
}
// vertices (or very close to a vertex, which may happen due to floating
// point round-off):
for (const auto &cell : dof_handler.active_cell_iterators())
- for (unsigned int vertex = 0;
- vertex < GeometryInfo<dim>::vertices_per_cell;
- ++vertex)
+ for (const auto vertex : cell->vertex_indices())
if (cell->vertex(vertex).distance(evaluation_point) <
cell->diameter() * 1e-8)
{
// After computing the cell terms, turn to the face terms. For this,
// loop over all faces of the present cell, and see whether
// something needs to be computed on it:
- for (unsigned int face_no : GeometryInfo<dim>::face_indices())
+ for (const auto face_no : cell->face_indices())
{
// First, if this face is part of the boundary, then there is
// nothing to do. However, to make things easier when summing up
// points, see @ref GlossSupport "support points"). For such a case, one
// could construct a custom quadrature rule using
// FiniteElement::get_unit_support_points(). The first
- // <code>GeometryInfo@<dim@>::%vertices_per_cell*fe.dofs_per_vertex</code>
+ // <code>cell->n_vertices()*fe.dofs_per_vertex</code>
// quadrature points will then correspond to the vertices of the cell and
// are ordered consistent with <code>cell-@>vertex(i)</code>, taking into
// account that support points for vector elements will be duplicated
std::vector<bool> vertex_touched(triangulation.n_vertices(), false);
for (auto &cell : dof_handler.active_cell_iterators())
- for (unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell; ++v)
+ for (const auto v : cell->vertex_indices())
if (vertex_touched[cell->vertex_index(v)] == false)
{
vertex_touched[cell->vertex_index(v)] = true;
for (unsigned int step = 0; step < 3; ++step)
{
for (auto &cell : triangulation.active_cell_iterators())
- for (unsigned int v = 0; v < GeometryInfo<2>::vertices_per_cell; ++v)
+ for (const auto v : cell->vertex_indices())
{
const double distance_from_center =
center.distance(cell->vertex(v));
//
// All this is a bit tricky, but has been explained in some detail
// already in step-9. Take a look there how this is supposed to work!
- for (unsigned int face_no : GeometryInfo<dim>::face_indices())
+ for (const auto face_no : cell->face_indices())
{
fe_face_values.reinit(cell, face_no);
std::vector<CellData<dim>> cells(n_cells, CellData<dim>());
for (unsigned int i = 0; i < n_cells; ++i)
{
- for (unsigned int j = 0; j < GeometryInfo<dim>::vertices_per_cell; ++j)
+ for (unsigned int j = 0; j < cell_vertices[i].size(); ++j)
cells[i].vertices[j] = cell_vertices[i][j];
cells[i].material_id = 0;
}
// is at the boundary, and second has the correct boundary indicator
// associated with $\Gamma_2$, the part of the boundary where we have
// absorbing boundary conditions:
- for (unsigned int face_no : GeometryInfo<dim>::face_indices())
+ for (const auto face_no : cell->face_indices())
if (cell->face(face_no)->at_boundary() &&
(cell->face(face_no)->boundary_id() == 0))
{
cell->get_dof_indices(dofs);
- for (unsigned int face_no : GeometryInfo<dim>::face_indices())
+ for (const auto face_no : cell->face_indices())
{
const auto face = cell->face(face_no);
Point<dim> jump;
Point<dim> area;
- for (unsigned int face_no : GeometryInfo<dim>::face_indices())
+ for (const auto face_no : cell->face_indices())
{
const auto face = cell->face(face_no);
std::pair<unsigned int, unsigned int>
neighbor_face_subface =
cell->neighbor_of_coarser_neighbor(face_no);
- Assert(neighbor_face_subface.first <
- GeometryInfo<dim>::faces_per_cell,
+ Assert(neighbor_face_subface.first < cell->n_faces(),
ExcInternalError());
Assert(neighbor_face_subface.second <
neighbor->face(neighbor_face_subface.first)
// whether we are working on an external or internal face; if it is an
// external face, the fourth argument denoting the degrees of freedom
// indices of the neighbor is ignored, so we pass an empty vector):
- for (unsigned int face_no : GeometryInfo<dim>::face_indices())
+ for (const auto face_no : cell->face_indices())
if (cell->at_boundary(face_no))
{
fe_v_face.reinit(cell, face_no);
std::vector<bool> dof_touched(dof_handler.n_dofs(), false);
for (const auto &cell : dof_handler.active_cell_iterators())
- for (unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell; ++v)
+ for (const auto v : cell->vertex_indices())
{
- Assert(dof_handler.get_fe().n_dofs_per_cell() ==
- GeometryInfo<dim>::vertices_per_cell,
+ Assert(dof_handler.get_fe().n_dofs_per_cell() == cell->n_vertices(),
ExcNotImplemented());
const unsigned int dof_index = cell->vertex_dof_index(v, 0);
for (const auto &cell : dof_handler.active_cell_iterators())
if (cell->is_locally_owned())
- for (unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell; ++v)
+ for (const auto v : cell->vertex_indices())
if (vertex_touched[cell->vertex_index(v)] == false)
{
vertex_touched[cell->vertex_index(v)] = true;
std::vector<unsigned int> local_face_dof_indices (stokes_fe.dofs_per_face);
for (const auto &cell: dof_handler.active_cell_iterators())
if (cell_is_in_fluid_domain (cell))
- for (unsigned int f : GeometryInfo<dim>::face_indices())
+ for (const auto f : cell->face_indices())
if (!cell->at_boundary(f))
{
bool face_is_on_interface = false;
stokes_fe.n_dofs_per_face());
for (const auto &cell : dof_handler.active_cell_iterators())
if (cell_is_in_fluid_domain(cell))
- for (unsigned int face_no : GeometryInfo<dim>::face_indices())
+ for (const auto face_no : cell->face_indices())
{
bool face_is_on_interface = false;
// boundary and the potential neighbor behind it is part of the fluid
// domain. Let's start with these conditions:
if (cell_is_in_solid_domain(cell))
- for (unsigned int f : GeometryInfo<dim>::face_indices())
+ for (const auto f : cell->face_indices())
{
// At this point we know that the current cell is a candidate
// for integration and that a neighbor behind face
// encountered when assembling interface terms in
// <code>assemble_system</code>.
for (const auto &cell : dof_handler.active_cell_iterators())
- for (unsigned int f : GeometryInfo<dim>::face_indices())
+ for (const auto f : cell->face_indices())
if (cell_is_in_solid_domain(cell))
{
if ((cell->at_boundary(f) == false) &&
std::vector<CellData<2>> cells(vertex_indices.size());
for (unsigned int i = 0; i < cells.size(); ++i)
{
- for (unsigned int j = 0; j < GeometryInfo<2>::vertices_per_cell; ++j)
+ for (unsigned int j = 0; j < vertex_indices[i].size(); ++j)
cells[i].vertices[j] = vertex_indices[i][j];
}
for (const auto &cell : triangulation.active_cell_iterators())
{
- for (unsigned int i = 0; i < GeometryInfo<2>::vertices_per_cell; ++i)
+ for (const auto i : cell->vertex_indices())
{
Point<2> &v = cell->vertex(i);
if (std::abs(v(1) - 1.0) < 1e-5)
// Face terms are assembled on all faces of all elements. This is in
// contrast to more traditional DG methods, where each face is only visited
// once in the assembly procedure.
- for (unsigned int face_no : GeometryInfo<dim>::face_indices())
+ for (const auto face_no : cell->face_indices())
{
scratch.fe_face_values_local.reinit(loc_cell, face_no);
scratch.fe_face_values.reinit(cell, face_no);
triangulation.begin_active()->face(0)->set_boundary_id(10);
triangulation.begin_active()->face(1)->set_boundary_id(11);
triangulation.begin_active()->face(2)->set_boundary_id(0);
- for (unsigned int f = 3; f < GeometryInfo<dim>::faces_per_cell; ++f)
+ for (unsigned int f = 3;
+ f < triangulation.begin_active()->n_faces();
+ ++f)
triangulation.begin_active()->face(f)->set_boundary_id(1);
std::vector<GridTools::PeriodicFacePair<
for (const auto &cell : triangulation.active_cell_iterators())
if (mesh_center.distance(cell->center()) < 1e-5)
{
- for (unsigned int v=0;
- v < GeometryInfo<dim>::vertices_per_cell;
- ++v)
+ for (const auto v : cell->vertex_indices())
cell->vertex(v) *= core_radius/mesh_center.distance(cell->vertex(v));
}
// created in radial direction to a place where we need
// them.
for (const auto &cell : triangulation.active_cell_iterators())
- for (unsigned int v=0; v < GeometryInfo<dim>::vertices_per_cell; ++v)
+ for (const auto v : cell->vertex_indices())
{
const double dist = mesh_center.distance(cell->vertex(v));
if (dist > core_radius*1.0001 && dist < 0.9999)
for (const auto &cell : triangulation.active_cell_iterators())
{
bool is_in_inner_circle = false;
- for (unsigned int v=0; v < GeometryInfo<2>::vertices_per_cell; ++v)
+ for (const auto v : cell->vertex_indices())
if (mesh_center.distance(cell->vertex(v)) < inner_radius)
{
is_in_inner_circle = true;
for (auto &cell : cells)
{
cell->set_refine_flag();
- for (unsigned int face_no : GeometryInfo<spacedim>::face_indices())
+ for (const auto face_no : cell->face_indices())
if (!cell->at_boundary(face_no))
cell->neighbor(face_no)->set_refine_flag();
}
for (const auto &face : cell->face_iterators())
{
bool face_at_sphere_boundary = true;
- for (unsigned int v = 0;
- v < GeometryInfo<dim - 1>::vertices_per_cell;
- ++v)
+ for (const auto v : face->vertex_indices())
{
if (std::abs(face->vertex(v).norm_square() - 0.25) > 1e-12)
face_at_sphere_boundary = false;
for (const auto &cell : triangulation.active_cell_iterators())
{
- for (unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell; ++v)
+ for (const auto v : cell->vertex_indices())
{
if (cell->vertex(v)[0] <= -disk_diameter + 1.e-6)
cell->vertex(v)[0] = -disk_position;
for (const auto &cell : triangulation.active_cell_iterators())
{
- for (auto f : GeometryInfo<dim>::face_indices())
+ for (const auto f : cell->face_indices())
{
const auto face = cell->face(f);
// Now we have to compute the boundary normals. Note that the
// following loop does not do much unless the element has faces on
// the boundary of the domain.
- for (auto f : GeometryInfo<dim>::face_indices())
+ for (const auto f : cell->face_indices())
{
const auto face = cell->face(f);
const auto id = face->boundary_id();
const auto index = copy.local_dof_indices[j];
Point<dim> position;
- for (unsigned int v = 0;
- v < GeometryInfo<dim>::vertices_per_cell;
- ++v)
+ for (const auto v : cell->vertex_indices())
if (cell->vertex_dof_index(v, 0) ==
partitioner->local_to_global(index))
{
for (auto &matrix : copy.cell_cij_matrix)
matrix = 0.;
- for (auto f : GeometryInfo<dim>::face_indices())
+ for (const auto f : cell->face_indices())
{
const auto face = cell->face(f);
const auto id = face->boundary_id();
// have to clear the array storing the iterators to the active
// neighbors, of course.
scratch_data.active_neighbors.clear();
- for (unsigned int face_n : GeometryInfo<dim>::face_indices())
+ for (const auto face_n : cell->face_indices())
if (!cell->at_boundary(face_n))
{
// First define an abbreviation for the iterator to the face and