Skip to content
Snippets Groups Projects
Commit 241aa9bf authored by Dr. Felix Tobias Schindler's avatar Dr. Felix Tobias Schindler
Browse files

[grid.element] add sub_entity_center to select codim at runtime

parent 761f6186
No related branches found
No related tags found
3 merge requests!41Fix compilation with icc, several other changes,!39Make functions copyable,!35dailywork-ftschindler
// This file is part of the dune-xt project:
// https://github.com/dune-community/dune-xt
// Copyright 2009-2020 dune-xt developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
// or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
// with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
// Felix Schindler (2020)
#ifndef DUNE_XT_GRID_ELEMENT_HH
#define DUNE_XT_GRID_ELEMENT_HH
#include <dune/grid/common/entity.hh>
#include <dune/xt/common/numeric_cast.hh>
#include <dune/xt/grid/type_traits.hh>
namespace Dune {
namespace XT {
namespace Grid {
template <class E>
class SubEntityCenter
{
static_assert(is_entity<E>::value, "");
using G = extract_grid_t<E>;
using D = typename G::ctype;
static const constexpr size_t d = G::dimension;
template <int cd = d, bool anything = true>
struct subEntity
{
static FieldVector<D, d> center(const E& element, const int codim, const size_t i)
{
if (codim == cd) {
DUNE_THROW_IF(i >= element.subEntities(codim),
Common::Exceptions::index_out_of_range,
"element.subEntities(" << codim << ") = " << element.subEntities(codim) << "\n i = " << i);
return element.subEntity<cd>(i).geometry().center();
} else
return subEntity<cd - 1>::center(element, codim, i);
} // ... center(...)
}; // struct subEntity
template <bool anything>
struct subEntity<0, anything>
{
static FieldVector<D, d> center(const E& element, const int codim, const size_t i)
{
DUNE_THROW_IF(codim != 0, Common::Exceptions::internal_error, "This must not happen");
return element.subEntity<0>(i).geometry().center();
}
}; // struct subEntity
public:
static FieldVector<D, d> get(const E& element, const int codim, const size_t i)
{
return subEntity<>::center(element, codim, i);
}
}; // class SubEntityCenter
template <int dim, class GridImp, template <int, int, class> class EntityImp>
FieldVector<typename GridImp::ctype, GridImp::dimension>
sub_entity_center(const Dune::Entity<0, dim, GridImp, EntityImp> element, const int codim, const size_t i)
{
return SubEntityCenter<Dune::Entity<0, dim, GridImp, EntityImp>>::get(element, codim, i);
}
} // namespace Grid
} // namespace XT
} // namespace Dune
#endif // DUNE_XT_GRID_ELEMENT_HH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment