Loading...
Searching...
No Matches
intersectionlist.hh
Go to the documentation of this file.
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-GPL-2.0-only-with-dune-grid-glue-exception
#ifndef DUNE_GRIDGLUE_MERGING_INTERSECTIONLIST_HH
#define DUNE_GRIDGLUE_MERGING_INTERSECTIONLIST_HH 1
#include <array>
#include <type_traits>
#include <utility>
#include <vector>
#include <dune/common/fvector.hh>
namespace Dune {
namespace GridGlue {
template<typename L0, typename L1>
class IntersectionListProvider
{
public:
using Local0 = L0;
using Local1 = L1;
using Index = unsigned int;
virtual std::size_t size() const = 0;
virtual std::size_t parents0(Index intersection) const = 0;
virtual std::size_t parents1(Index intersection) const = 0;
virtual Index parent0(Index intersection, unsigned index) const = 0;
virtual Index parent1(Index intersection, unsigned index) const = 0;
virtual Local0 corner0(Index intersection, unsigned corner, unsigned index) const = 0;
virtual Local1 corner1(Index intersection, unsigned corner, unsigned index) const = 0;
};
namespace Impl {
template<typename P, int I>
struct IntersectionListLocal
{};
template<typename P>
struct IntersectionListLocal<P, 0>
{
static std::size_t parents(const P& p, typename P::Index intersection)
{ return p.parents0(intersection); }
static typename P::Index parent(const P& p, typename P::Index intersection, unsigned index)
{ return p.parent0(intersection, index); }
static typename P::Local0 corner(const P& p, typename P::Index intersection, unsigned corner, unsigned index)
{ return p.corner0(intersection, corner, index); }
};
template<typename P>
struct IntersectionListLocal<P, 1>
{
static std::size_t parents(const P& p, typename P::Index intersection)
{ return p.parents1(intersection); }
static typename P::Index parent(const P& p, typename P::Index intersection, unsigned index)
{ return p.parent1(intersection, index); }
static typename P::Local1 corner(const P& p, typename P::Index intersection, unsigned corner, unsigned index)
{ return p.corner1(intersection, corner, index); }
};
} /* namespace Impl */
template<typename Local0, typename Local1>
class IntersectionList
{
public:
using Provider = IntersectionListProvider<Local0, Local1>;
using Index = typename Provider::Index;
IntersectionList(const std::shared_ptr<Provider>& provider)
: impl_(provider)
{}
std::size_t size() const
{ return impl_->size(); }
template<int I>
std::size_t parents(Index intersection) const
{
static_assert(I == 0 or I == 1, "I must be 0 or 1");
// TODO [C++17]: use `if constexpr` instead of indirection
return Impl::IntersectionListLocal<Provider, I>::parents(*impl_, intersection);
}
template<int I>
Index parent(Index intersection, unsigned index = 0) const
{
static_assert(I == 0 or I == 1, "I must be 0 or 1");
// TODO [C++17]: use `if constexpr` instead of indirection
return Impl::IntersectionListLocal<Provider, I>::parent(*impl_, intersection, index);
}
template<int I>
auto corner(Index intersection, unsigned corner, unsigned index = 0) const
{
static_assert(I == 0 or I == 1, "I must be 0 or 1");
// TODO [C++17]: use `if constexpr` instead of indirection
return Impl::IntersectionListLocal<Provider, I>::corner(*impl_, intersection, corner, index);
}
private:
std::shared_ptr<Provider> impl_;
};
template<int dim0, int dim1>
class SimplicialIntersectionListProvider final
: public IntersectionListProvider< FieldVector<double, dim0>, FieldVector<double, dim1> >
{
using Base = IntersectionListProvider< FieldVector<double, dim0>, FieldVector<double, dim1> >;
public:
using Index = typename Base::Index;
using Local0 = FieldVector<double, dim0>;
using Local1 = FieldVector<double, dim1>;
template<int I>
using Local = std::conditional_t< I == 0, Local0, Local1 >;
struct SimplicialIntersection
{
private:
static constexpr int intersectionDim = dim0 < dim1 ? dim0 : dim1;
static constexpr int nVertices = intersectionDim + 1;
public:
SimplicialIntersection() = default;
SimplicialIntersection(Index parent0, Index parent1)
: parents0{parent0}
, parents1{parent1}
{}
template<int I>
using Corners = std::array<Local<I>, nVertices>;
std::vector< Corners<0> > corners0 = std::vector< Corners<0> >(1);
std::vector< Index > parents0 = std::vector< Index >(1);
std::vector< Corners<1> > corners1 = std::vector< Corners<1> >(1);
std::vector< Index > parents1 = std::vector< Index >(1);
};
SimplicialIntersectionListProvider() = default;
SimplicialIntersectionListProvider(std::vector<SimplicialIntersection>&& intersections)
: intersections_(std::move(intersections))
{}
auto& intersections()
{ return intersections_; }
std::size_t size() const override
{ return intersections_.size(); }
std::size_t parents0(Index intersection) const override
{ return intersections_[intersection].parents0.size(); }
std::size_t parents1(Index intersection) const override
{ return intersections_[intersection].parents1.size(); }
Index parent0(Index intersection, unsigned index) const override
{ return intersections_[intersection].parents0[index]; }
Index parent1(Index intersection, unsigned index) const override
{ return intersections_[intersection].parents1[index]; }
Local0 corner0(Index intersection, unsigned corner, unsigned index) const override
{ return intersections_[intersection].corners0[index][corner]; }
Local1 corner1(Index intersection, unsigned corner, unsigned index) const override
{ return intersections_[intersection].corners1[index][corner]; }
void clear()
{
intersections_.clear();
}
private:
std::vector<SimplicialIntersection> intersections_;
};
} /* namespace GridGlue */
} /* namespace Dune */
#endif
Dune
Definition gridglue.hh:37
Dune::GridGlue
Definition gridglue.hh:38
Dune::GridGlue::ProjectionImplementation::corner
Coordinate corner(unsigned c)
Definition projection_impl.hh:24
Dune::GridGlue::IntersectionListProvider
Definition intersectionlist.hh:22
Dune::GridGlue::IntersectionListProvider::parents0
virtual std::size_t parents0(Index intersection) const =0
Dune::GridGlue::IntersectionListProvider::corner1
virtual Local1 corner1(Index intersection, unsigned corner, unsigned index) const =0
Dune::GridGlue::IntersectionListProvider::Index
unsigned int Index
Definition intersectionlist.hh:38
Dune::GridGlue::IntersectionListProvider::size
virtual std::size_t size() const =0
Dune::GridGlue::IntersectionListProvider::Local0
L0 Local0
Definition intersectionlist.hh:28
Dune::GridGlue::IntersectionListProvider::corner0
virtual Local0 corner0(Index intersection, unsigned corner, unsigned index) const =0
Dune::GridGlue::IntersectionListProvider::Local1
L1 Local1
Definition intersectionlist.hh:33
Dune::GridGlue::IntersectionListProvider::parent1
virtual Index parent1(Index intersection, unsigned index) const =0
Dune::GridGlue::IntersectionListProvider::parents1
virtual std::size_t parents1(Index intersection) const =0
Dune::GridGlue::IntersectionListProvider::parent0
virtual Index parent0(Index intersection, unsigned index) const =0
Dune::GridGlue::IntersectionList::parent
Index parent(Index intersection, unsigned index=0) const
Definition intersectionlist.hh:171
Dune::GridGlue::IntersectionList::corner
auto corner(Index intersection, unsigned corner, unsigned index=0) const
Definition intersectionlist.hh:187
Dune::GridGlue::IntersectionList::Index
typename Provider::Index Index
Definition intersectionlist.hh:137
Dune::GridGlue::IntersectionList::IntersectionList
IntersectionList(const std::shared_ptr< Provider > &provider)
Definition intersectionlist.hh:139
Dune::GridGlue::IntersectionList::parents
std::size_t parents(Index intersection) const
Definition intersectionlist.hh:156
Dune::GridGlue::IntersectionList::Provider
IntersectionListProvider< Local0, Local1 > Provider
Definition intersectionlist.hh:136
Dune::GridGlue::IntersectionList::size
std::size_t size() const
Definition intersectionlist.hh:146
Dune::GridGlue::SimplicialIntersectionListProvider::Local0
FieldVector< double, dim0 > Local0
Definition intersectionlist.hh:212
Dune::GridGlue::SimplicialIntersectionListProvider< grid1Dim, grid2Dim >::intersections
auto & intersections()
Definition intersectionlist.hh:266
Dune::GridGlue::SimplicialIntersectionListProvider::SimplicialIntersectionListProvider
SimplicialIntersectionListProvider(std::vector< SimplicialIntersection > &&intersections)
Definition intersectionlist.hh:262
Dune::GridGlue::SimplicialIntersectionListProvider::corner1
Local1 corner1(Index intersection, unsigned corner, unsigned index) const override
Definition intersectionlist.hh:287
Dune::GridGlue::SimplicialIntersectionListProvider::corner0
Local0 corner0(Index intersection, unsigned corner, unsigned index) const override
Definition intersectionlist.hh:284
Dune::GridGlue::SimplicialIntersectionListProvider::parent1
Index parent1(Index intersection, unsigned index) const override
Definition intersectionlist.hh:281
Dune::GridGlue::SimplicialIntersectionListProvider::Index
typename Base::Index Index
Definition intersectionlist.hh:211
Dune::GridGlue::SimplicialIntersectionListProvider::Local
std::conditional_t< I==0, Local0, Local1 > Local
Definition intersectionlist.hh:216
Dune::GridGlue::SimplicialIntersectionListProvider::SimplicialIntersectionListProvider
SimplicialIntersectionListProvider()=default
Dune::GridGlue::SimplicialIntersectionListProvider::clear
void clear()
Definition intersectionlist.hh:290
Dune::GridGlue::SimplicialIntersectionListProvider::size
std::size_t size() const override
Definition intersectionlist.hh:269
Dune::GridGlue::SimplicialIntersectionListProvider::Local1
FieldVector< double, dim1 > Local1
Definition intersectionlist.hh:213
Dune::GridGlue::SimplicialIntersectionListProvider::parents1
std::size_t parents1(Index intersection) const override
Definition intersectionlist.hh:275
Dune::GridGlue::SimplicialIntersectionListProvider::parent0
Index parent0(Index intersection, unsigned index) const override
Definition intersectionlist.hh:278
Dune::GridGlue::SimplicialIntersectionListProvider::parents0
std::size_t parents0(Index intersection) const override
Definition intersectionlist.hh:272
Dune::GridGlue::SimplicialIntersectionListProvider::SimplicialIntersection::SimplicialIntersection
SimplicialIntersection(Index parent0, Index parent1)
Definition intersectionlist.hh:229
Dune::GridGlue::SimplicialIntersectionListProvider::SimplicialIntersection::Corners
std::array< Local< I >, nVertices > Corners
Definition intersectionlist.hh:238
Dune::GridGlue::SimplicialIntersectionListProvider::SimplicialIntersection::parents1
std::vector< Index > parents1
Definition intersectionlist.hh:258
Dune::GridGlue::SimplicialIntersectionListProvider::SimplicialIntersection::parents0
std::vector< Index > parents0
Definition intersectionlist.hh:248
Dune::GridGlue::SimplicialIntersectionListProvider::SimplicialIntersection::corners1
std::vector< Corners< 1 > > corners1
Definition intersectionlist.hh:253
Dune::GridGlue::SimplicialIntersectionListProvider::SimplicialIntersection::SimplicialIntersection
SimplicialIntersection()=default
Dune::GridGlue::SimplicialIntersectionListProvider::SimplicialIntersection::corners0
std::vector< Corners< 0 > > corners0
Definition intersectionlist.hh:243