Commit 9d434a94 authored by Timo Koch's avatar Timo Koch
Browse files

Merge branch 'fix/isindexable-warning' into 'master'

[io][vtk] avoid deprecation warnings for Dune::IsIndexable

See merge request !943
parents 759bd3c8 1612f45e
......@@ -26,6 +26,8 @@
#include <type_traits>
#include <dune/common/version.hh>
namespace Dumux
{
/*!
......@@ -34,5 +36,17 @@ namespace Dumux
*/
template<typename T>
struct AlwaysFalse : public std::false_type {};
/*! \brief We define our own is_indexable type in order
* to avoid several version checks throughout dumux.
* This should be deleted when the deprecation phase is over.
*/
template<typename T, typename I = std::size_t>
using IsIndexable =
#if DUNE_VERSION_NEWER(DUNE_COMMON,2,7)
typename Dune::IsIndexable<T, I>;
#else
typename Dune::is_indexable<T, I>;
#endif
}
#endif
......@@ -30,6 +30,8 @@
#include <dune/grid/io/file/vtk/common.hh>
#include <dune/grid/io/file/vtk/function.hh>
#include <dumux/common/typetraits/typetraits.hh>
namespace Dumux {
namespace Vtk {
......@@ -56,7 +58,7 @@ public:
//! evaluate
virtual double evaluate(int mycomp, const Element& e, const Dune::FieldVector<ctype, dim>&) const
{ return accessChooser_(mycomp, mapper_.index(e), Dune::is_indexable<decltype(field_[0])>()); }
{ return accessChooser_(mycomp, mapper_.index(e), IsIndexable<decltype(field_[0])>()); }
//! Constructor
VectorP0VTKFunction(const GridView& gridView, const Mapper& mapper, const F& field, const std::string& name, int nComps)
......@@ -70,20 +72,16 @@ private:
//! access for vectorial fields
double accessChooser_(int mycomp, int i, std::true_type) const
{
static constexpr auto isIndexable = Dune::is_indexable<decltype(field_[0][0])>();
return vectorFieldAccess_<isIndexable>(mycomp, i); }
{ return vectorFieldAccess_(mycomp, i, IsIndexable<decltype(field_[0][0])>()); }
//! access for scalar fields
double accessChooser_(int mycomp, int i, std::false_type) const { return field_[i]; }
//! access to permissive vectorial fields
template<bool is, std::enable_if_t<!is, int> = 0>
double vectorFieldAccess_(int mycomp, int i) const { return field_[i][mycomp]; }
double vectorFieldAccess_(int mycomp, int i, std::false_type) const { return field_[i][mycomp]; }
//! if the field is indexable more than two times, throw error
template<bool is, std::enable_if_t<is, int> = 0>
double vectorFieldAccess_(int mycomp, int i) const { DUNE_THROW(Dune::InvalidStateException, "Invalid field type"); }
double vectorFieldAccess_(int mycomp, int i, std::true_type) const { DUNE_THROW(Dune::InvalidStateException, "Invalid field type"); }
const F& field_;
const std::string name_;
......@@ -120,7 +118,7 @@ public:
std::vector<Dune::FieldVector<ctype, 1>> cornerValues(nVertices);
for (unsigned i = 0; i < nVertices; ++i)
cornerValues[i] = accessChooser_(mycomp, mapper_.subIndex(e, i, dim), Dune::is_indexable<decltype(field_[0])>());
cornerValues[i] = accessChooser_(mycomp, mapper_.subIndex(e, i, dim), IsIndexable<decltype(field_[0])>());
// (Ab)use the MultiLinearGeometry class to do multi-linear interpolation between scalars
const Dune::MultiLinearGeometry<ctype, dim, 1> interpolation(e.type(), std::move(cornerValues));
......@@ -138,7 +136,7 @@ private:
//! access for vectorial fields
double accessChooser_(int mycomp, int i, std::true_type) const
{ return vectorFieldAccess_(mycomp, i, Dune::is_indexable<decltype(field_[0][0])>()); }
{ return vectorFieldAccess_(mycomp, i, IsIndexable<decltype(field_[0][0])>()); }
//! access for scalar fields
double accessChooser_(int mycomp, int i, std::false_type) const { return field_[i]; }
......@@ -184,7 +182,7 @@ public:
std::vector<Dune::FieldVector<ctype, 1>> cornerValues(nVertices);
for (unsigned i = 0; i < nVertices; ++i)
cornerValues[i] = accessChooser_(mycomp, mapper_.index(e), i, Dune::is_indexable<decltype(field_[0])>());
cornerValues[i] = accessChooser_(mycomp, mapper_.index(e), i, IsIndexable<decltype(field_[0])>());
// (Ab)use the MultiLinearGeometry class to do multi-linear interpolation between scalars
const Dune::MultiLinearGeometry<ctype, dim, 1> interpolation(e.type(), std::move(cornerValues));
......@@ -202,7 +200,7 @@ private:
//! access to the field
double accessChooser_(int mycomp, int eIdx, int cornerIdx, std::true_type) const
{ return fieldAccess_(mycomp, eIdx, cornerIdx, Dune::is_indexable<decltype(field_[0][0])>()); }
{ return fieldAccess_(mycomp, eIdx, cornerIdx, IsIndexable<decltype(field_[0][0])>()); }
//! fields have to be indexable at least twice
double accessChooser_(int mycomp, int eIdx, int cornerIdx, std::false_type) const
......
......@@ -42,6 +42,7 @@
#include <dumux/common/properties.hh>
#include <dumux/common/parameters.hh>
#include <dumux/common/typetraits/typetraits.hh>
#include <dumux/discretization/methods.hh>
#include "vtkfunction.hh"
......@@ -569,11 +570,11 @@ private:
}
//! Deduces the number of components of the value type of a vector of values
template<class Vector, typename std::enable_if_t<Dune::is_indexable<decltype(std::declval<Vector>()[0])>::value, int> = 0>
template<class Vector, typename std::enable_if_t<IsIndexable<decltype(std::declval<Vector>()[0])>::value, int> = 0>
std::size_t getNumberOfComponents_(const Vector& v) { return v[0].size(); }
//! Deduces the number of components of the value type of a vector of values
template<class Vector, typename std::enable_if_t<!Dune::is_indexable<decltype(std::declval<Vector>()[0])>::value, int> = 0>
template<class Vector, typename std::enable_if_t<!IsIndexable<decltype(std::declval<Vector>()[0])>::value, int> = 0>
std::size_t getNumberOfComponents_(const Vector& v) { return 1; }
//! return the number of dofs
......
Supports Markdown
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