Commit 38da11b0 authored by Janick Gerstenberger's avatar Janick Gerstenberger

[stencil] reorganize stencils

parent 6fee6491
set(HEADERS
edgeneighborsstencil.hh
vertexneighborsstencil.hh
edgeneighbors.hh
heightfunction.hh
vertexneighbors.hh
)
install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/vof/stencil)
#ifndef DUNE_VOF_EDGENEIGHBORSSTENCIL_HH
#define DUNE_VOF_EDGENEIGHBORSSTENCIL_HH
#ifndef DUNE_VOF_STENCIL_EDGENEIGHBORS_HH
#define DUNE_VOF_STENCIL_EDGENEIGHBORS_HH
#include <utility>
#include <vector>
......@@ -65,4 +65,4 @@ namespace Dune
} // namespace Dune
#endif // #ifndef DUNE_VOF_EDGENEIGHBORSSTENCIL_HH
#endif // #ifndef DUNE_VOF_STENCIL_EDGENEIGHBORS_HH
#ifndef DUNE_VOF_HEIGHTFUNCTIONSTENCILS_HH
#define DUNE_VOF_HEIGHTFUNCTIONSTENCILS_HH
#ifndef DUNE_VOF_STENCIL_HEIGHTFUNCTION_HH
#define DUNE_VOF_STENCIL_HEIGHTFUNCTION_HH
#include <tuple>
#include <type_traits>
#include <dune/common/power.hh>
#include <dune/common/rangeutilities.hh>
#include <dune/grid/spgrid/entity.hh>
namespace Dune
{
namespace VoF
......@@ -18,92 +24,90 @@ namespace Dune
*
* \tparam GV grid view
*/
template< class GV >
template<class GV>
struct HeightFunctionStencil
{
using GridView = GV;
static constexpr int dim = GridView::dimension;
using Entity = typename GridView::template Codim< 0 >::Entity;
using EntityImpl = SPEntity< 0, dim, const typename GridView::Grid >;
using EntityInfo = typename EntityImpl::EntityInfo;
using MultiIndex = typename EntityInfo::MultiIndex;
using Entity = typename GridView::template Codim<0>::Entity;
using Orientation = std::tuple<int, int>;
using Orientation = std::tuple< int, int >;
static constexpr int dim = GridView::dimension;
static constexpr int noc = StaticPower<3, dim-1>::power;
using EntityImpl = SPEntity<0, dim, const typename GridView::Grid>;
using EntityInfo = typename EntityImpl::EntityInfo;
using MultiIndex = typename EntityInfo::MultiIndex;
static constexpr int noc = StaticPower< 3, dim-1 >::power;
static_assert(std::is_same<EntityImpl, typename Entity::Implementation>::value, "...");
public:
explicit HeightFunctionStencil ( const GridView &gridView, const EntityInfo &entityInfo, const Orientation &orientation, const double tup = 3 )
: gridView_( gridView ), tup_( tup ), entityInfo_( entityInfo ), orientation_( orientation )
HeightFunctionStencil (const GridView& gridView, const EntityInfo& entityInfo, const Orientation& orientation, int tup = 3)
: gridView_(gridView), entityInfo_(entityInfo), orientation_(orientation), tup_(tup)
{}
std::size_t columns() const { return noc; }
int tdown() const { return -tup_; }
int tup() const { return tup_; }
int effectiveTdown() const
{
for ( int i = -1; i >= tdown(); --i )
if ( !valid( ( noc - 1 ) / 2, i ) )
return - 1 - i;
for (int i : range(1, tup_))
if (!valid((noc - 1) / 2, -i))
return i-1;
return tup_;
}
Entity operator() ( const std::size_t c, const int t ) const
auto operator() (const std::size_t c, const int t) const -> Entity
{
EntityInfo entityInfo( entityInfo_ );
entityInfo.id() = getMultiIndex< dim >( c, t );
EntityInfo entityInfo(entityInfo_);
entityInfo.id() = getMultiIndex<dim>(c, t);
entityInfo.update();
return EntityImpl( entityInfo );
return EntityImpl(entityInfo);
}
bool valid ( const std::size_t c, const int t ) const
bool valid (const std::size_t c, const int t) const
{
return entityInfo_.gridLevel().template partition< All_Partition >().contains( getMultiIndex< dim >( c, t ), entityInfo_.partitionNumber() );
return entityInfo_.gridLevel().template partition<All_Partition>().contains(getMultiIndex<dim>(c, t), entityInfo_.partitionNumber());
}
template < int dimension >
auto getMultiIndex( const std::size_t c, const int t ) const
-> typename std::enable_if< dimension == 2, MultiIndex >::type
template <int dimension>
auto getMultiIndex (const std::size_t c, const int t) const
-> std::enable_if_t<dimension == 2, MultiIndex>
{
MultiIndex m;
int i = std::get< 0 >( orientation_ );
int j = std::get< 1 >( orientation_ );
int i = std::get<0>(orientation_);
int j = std::get<1>(orientation_);
m[ 1 - i ] += ( c - 1 ) * ( i == 0 ? -1 : 1 );
m[ i ] += t;
m[1 - i] += (c - 1) * (i == 0 ? -1 : 1);
m[i] += t;
m *= j;
m *= 2;
return m + entityInfo_.id();
return 2*m + entityInfo_.id();
}
template < int dimension >
auto getMultiIndex( const std::size_t c, const int t ) const
-> typename std::enable_if< dimension == 3, MultiIndex >::type
template <int dimension>
auto getMultiIndex (const std::size_t c, const int t) const
-> std::enable_if_t<dimension == 3, MultiIndex>
{
MultiIndex m;
int i = std::get< 0 >( orientation_ );
int j = std::get< 1 >( orientation_ );
int i = std::get<0>(orientation_);
int j = std::get<1>(orientation_);
m[ i ] += j * t;
m[ (i+1)%3 ] += ( ( c % 3 ) - 1 ) * -j;
m[ (i+2)%3 ] += ( ( c / 3 ) - 1 );
m[i] += j * t;
m[(i+1)%3] += ((c % 3) - 1) * -j;
m[(i+2)%3] += ((c / 3) - 1);
m *= 2;
return m + entityInfo_.id();
return 2*m + entityInfo_.id();
}
private:
const GridView &gridView_;
std::size_t tup_;
const GridView& gridView_;
const EntityInfo entityInfo_;
const Orientation orientation_;
int tup_;
};
......@@ -111,4 +115,4 @@ namespace Dune
} // namespace Dune
#endif // #ifndef DUNE_VOF_HEIGHTFUNCTIONSTENCIL_HH
#endif // #ifndef DUNE_VOF_STENCIL_HEIGHTFUNCTION_HH
#ifndef DUNE_VOF_VERTEXNEIGHBORSSTENCIL_HH
#define DUNE_VOF_VERTEXNEIGHBORSSTENCIL_HH
#ifndef DUNE_VOF_STENCIL_VERTEXNEIGHBORS_HH
#define DUNE_VOF_STENCIL_VERTEXNEIGHBORS_HH
#include <algorithm>
#include <utility>
......@@ -101,4 +101,4 @@ namespace Dune
} // namespace Dune
#endif // #ifndef DUNE_VOF_VERTEXNEIGHBORSSTENCIL_HH
#endif // #ifndef DUNE_VOF_STENCIL_VERTEXNEIGHBORS_HH
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment