Skip to content

Commit

Permalink
Make Mapping::get_center() work with simplices.
Browse files Browse the repository at this point in the history
  • Loading branch information
drwells committed Feb 25, 2023
1 parent a8fa2dd commit d867c13
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
14 changes: 7 additions & 7 deletions include/deal.II/fe/mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class Mapping : public Subscriptor
const typename Triangulation<dim, spacedim>::cell_iterator &cell) const;

/**
* Return the mapped center of a cell.
* Return one of two possible mapped centers of a cell.
*
* If you are using a (bi-,tri-)linear mapping that preserves vertex
* locations, this function simply returns the value also produced by
Expand All @@ -358,21 +358,21 @@ class Mapping : public Subscriptor
* polynomials, for which the center may not coincide with the average of
* the vertex locations.
*
* By default, this function returns the push forward of the center of the
* By default, this function returns the push forward of the barycenter of the
* reference cell. If the parameter
* @p map_center_of_reference_cell is set to false, than the return value
* will be the average of the vertex locations, as returned by the
* @p map_barycenter_of_reference_cell is set to false, than the returned
* value will be the average of the vertex locations, as returned by the
* get_vertices() method.
*
* @param[in] cell The cell for which you want to compute the center
* @param[in] map_center_of_reference_cell A flag that switches the algorithm
* for the computation of the cell center from
* @param[in] map_barycenter_of_reference_cell A flag that switches the
* algorithm for the computation of the cell center from
* transform_unit_to_real_cell() applied to the center of the reference cell
* to computing the vertex averages.
*/
virtual Point<spacedim>
get_center(const typename Triangulation<dim, spacedim>::cell_iterator &cell,
const bool map_center_of_reference_cell = true) const;
const bool map_barycenter_of_reference_cell = true) const;

/**
* Return the bounding box of a mapped cell.
Expand Down
12 changes: 5 additions & 7 deletions source/fe/mapping.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,20 @@ template <int dim, int spacedim>
Point<spacedim>
Mapping<dim, spacedim>::get_center(
const typename Triangulation<dim, spacedim>::cell_iterator &cell,
const bool map_center_of_reference_cell) const
const bool map_barycenter_of_reference_cell) const
{
if (map_center_of_reference_cell)
if (map_barycenter_of_reference_cell)
{
Point<dim> reference_center;
for (unsigned int d = 0; d < dim; ++d)
reference_center[d] = .5;
return transform_unit_to_real_cell(cell, reference_center);
return transform_unit_to_real_cell(
cell, cell->reference_cell().template barycenter<dim>());
}
else
{
const auto vertices = get_vertices(cell);
Point<spacedim> center;
for (const auto &v : vertices)
center += v;
return center / GeometryInfo<dim>::vertices_per_cell;
return center / cell->n_vertices();
}
}

Expand Down

0 comments on commit d867c13

Please sign in to comment.