...
 
Commits (3)
......@@ -13,15 +13,38 @@ namespace Dune
namespace VoF
{
// Flag
// Flags
// ----
enum class Flag : std::size_t {
empty = 0,
mixed = 1,
mixedfull = 2,
full = 3,
nan = 99
class Flags
{
template<std::size_t Lower, std::size_t Upper>
struct Range
{
constexpr Range () = default;
static constexpr bool contains (std::size_t val) { return (val - Lower <= Upper - Lower); }
template<class T, class = std::enable_if_t<std::is_enum<T>::value>,
class = std::enable_if_t<std::is_integral<std::underlying_type_t<T>>::value>>
static constexpr bool contains (T val)
{
return contains(static_cast<std::underlying_type_t<T>>(val));
}
};
public:
enum Enum : std::size_t {
empty = 0,
mixed = 1,
mixedfull = 2,
full = 3,
nan = 99
};
using Empty = Range<empty, empty>;
using Mixed = Range<mixed, mixedfull>;
using Full = Range<full, full>;
};
......@@ -35,54 +58,34 @@ namespace Dune
* \tparam GridView grid view
*/
template< class GridView >
class FlagSet : public DataSet<GridView, Flag>
class FlagSet : public DataSet<GridView, Flags::Enum>
{
private:
using This = FlagSet<GridView>;
using Base = DataSet<GridView, Flag>;
using Entity = typename Base::Entity;
template<std::size_t Lower, std::size_t Upper>
struct Range
{
constexpr Range () = default;
static constexpr bool contains (std::size_t val) { return (val - Lower <= Upper - Lower); }
template<class T, class = std::enable_if_t<std::is_enum<T>::value>,
class = std::enable_if_t<std::is_integral<std::underlying_type_t<T>>::value>>
static constexpr bool contains (T val)
{
return contains(static_cast<std::underlying_type_t<T>>(val));
}
};
using Base = DataSet<GridView, Flags::Enum>;
public:
using typename Base::Entity;
using typename Base::Index;
using Base::Base;
using Base::operator[];
double operator[] (const typename Base::Index& index) const { return static_cast<double>(this->Base::operator[](index)); }
double operator[] (const Index& i) const { return static_cast<double>(this->Base::operator[](i)); }
using Empty = Range<static_cast<std::size_t>(Flag::empty), static_cast<std::size_t>(Flag::empty)>;
using Mixed = Range<static_cast<std::size_t>(Flag::mixed), static_cast<std::size_t>(Flag::mixedfull)>;
using Full = Range<static_cast<std::size_t>(Flag::full), static_cast<std::size_t>(Flag::full)>;
bool isEmpty (const Entity& entity) const { return this->operator[](entity) == Flag::empty; }
bool isMixed (const Entity& entity) const { return inRange(entity, Mixed{}); }
bool isFull (const Entity& entity) const { return this->operator[](entity) == Flag::full; }
bool isEmpty (const Entity& entity) const { return this->operator[](entity) == Flags::empty; }
bool isMixed (const Entity& entity) const { return inRange(entity, Flags::Mixed{}); }
bool isFull (const Entity& entity) const { return this->operator[](entity) == Flags::full; }
private:
template<class _Range>
bool inRange (const Entity& en, _Range = {}) const
{
return _Range::contains(this->operator[](en));
}
template<class Range>
bool inRange (const Entity& en, Range = {}) const { return Range::contains(this->operator[](en)); }
};
template<class GridView>
auto localView (const FlagSet<GridView>& flags) -> DataSetLocalView<GridView, Flag>
auto localView (const FlagSet<GridView>& flags) -> DataSetLocalView<GridView, Flags::Enum>
{
return DataSetLocalView<GridView, Flag>(flags);
return DataSetLocalView<GridView, Flags::Enum>(flags);
}
} // namespace VoF
......
......@@ -40,25 +40,25 @@ namespace Dune
for ( const auto &entity : elements( color.gridView(), Partitions::all ) )
{
Flag &flag = flags[ entity ];
auto& flag = flags[ entity ];
const auto colorEn = color[ entity ];
if ( colorEn < eps_ )
flag = Flag::empty;
flag = Flags::empty;
else if ( colorEn <= ( 1 - eps_ ) )
flag = Flag::mixed;
flag = Flags::mixed;
else
{
if ( std::isnan( colorEn ) )
flag = Flag::nan;
flag = Flags::nan;
else
{
flag = Flag::full;
flag = Flags::full;
for ( const auto &intersection : intersections( color.gridView(), entity ) )
if ( intersection.neighbor() && color[ intersection.outside() ] < eps_ )
{
flag = Flag::mixedfull;
flag = Flags::mixedfull;
break;
}
}
......
......@@ -76,7 +76,7 @@ namespace Dune
P.axpy(-l1 / (l0 - l1), L->vertex(0));
P.axpy( l0 / (l0 - l1), L->vertex(1));
return {makeLine(P)};
return {makePoint(P)};
}
}
......
......@@ -51,7 +51,7 @@ namespace Dune
: innerNormal_(normal), distanceToOrigin_(dist)
{
using std::abs;
assert(abs(innerNormal_.two_norm()-ctype{1.0}) < 3*dimension * std::numeric_limits<ctype>::epsilon());
assert(abs(innerNormal_.two_norm2()-ctype{1.0}) < 3 * dimension * std::numeric_limits<ctype>::epsilon());
}
HalfSpace (const Coordinate& normal, const Coordinate& point) : HalfSpace(normal, -(normal * point)) {}
......
......@@ -221,6 +221,10 @@ namespace Dune {
Polyhedron (const FaceIndices& faces, const EdgeIndices& edges, Nodes nodes)
: nodes_(std::move(nodes))
{
assert(faces.size() >= 4);
assert(edges.size() >= 12);
assert(nodes_.size() >= 4);
for (const auto& indices : edges)
edges_.emplace_back(this, indices);
......
......@@ -17,11 +17,6 @@ namespace Dune
namespace VoF
{
// ToDo:
// - externalize Polyhedron implementations
// - implement centroid of Polygon in 3D
// forward declarations
// --------------------
......
......@@ -34,6 +34,14 @@ namespace Dune
template<class T, std::size_t I, class = std::enable_if_t<T::dimension-1 == I>>
struct _GCP;
template<class K>
struct _GCP<FieldVector<K, 1>, 0>
{
using Coordinate = FieldVector<K, 1>;
inline static auto apply () -> Coordinate { return {1}; }
};
/**
* \brief generalized cross product implementation for 2D
*/
......@@ -42,7 +50,7 @@ namespace Dune
{
using Coordinate = FieldVector<K, 2>;
inline static auto apply(const Coordinate& v) -> Coordinate { return {-v[1], v[0]}; }
inline static auto apply (const Coordinate& v) -> Coordinate { return {-v[1], v[0]}; }
};
/**
......@@ -53,7 +61,7 @@ namespace Dune
{
using Coordinate = FieldVector<K, 3>;
inline static auto apply( const Coordinate& v, const Coordinate& w )
inline static auto apply ( const Coordinate& v, const Coordinate& w )
-> Coordinate
{
return { v[ 1 ] * w[ 2 ] - v[ 2 ] * w[ 1 ],
......