Commit cb00bc20 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Merge branch 'feature/gridfunction-concepts' into 'master'

Extract some concepts from Vtk::Function

See merge request extensions/dune-vtk!29
parents a139f141 9a772702
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <dune/vtk/localfunction.hh> #include <dune/vtk/localfunction.hh>
#include <dune/vtk/types.hh> #include <dune/vtk/types.hh>
#include <dune/vtk/utility/arguments.hh> #include <dune/vtk/utility/arguments.hh>
#include <dune/vtk/utility/concepts.hh>
namespace Dune namespace Dune
{ {
...@@ -28,16 +29,6 @@ namespace Dune ...@@ -28,16 +29,6 @@ namespace Dune
using Element = typename GridView::template Codim<0>::Entity; using Element = typename GridView::template Codim<0>::Entity;
using LocalDomain = typename Element::Geometry::LocalCoordinate; using LocalDomain = typename Element::Geometry::LocalCoordinate;
template <class GF>
using IsGridFunction = decltype(localFunction(std::declval<GF>()));
template <class LocalFunction, class LF = std::decay_t<LocalFunction>>
using IsLocalFunction = decltype((
std::declval<LF&>().bind(std::declval<Element>()),
std::declval<LF&>().unbind(),
std::declval<LF>()(std::declval<LocalDomain>()),
0));
template <class F, class D> template <class F, class D>
using Range = std::decay_t<std::result_of_t<F(D)>>; using Range = std::decay_t<std::result_of_t<F(D)>>;
...@@ -67,15 +58,15 @@ namespace Dune ...@@ -67,15 +58,15 @@ namespace Dune
* \param localFct A local-function, providing a `bind(Element)` and an `operator()(LocalDomain)` * \param localFct A local-function, providing a `bind(Element)` and an `operator()(LocalDomain)`
* \param name The name to use as identification in the VTK file * \param name The name to use as identification in the VTK file
* \param components A vector of component indices to extract from the range type * \param components A vector of component indices to extract from the range type
* \param category The \ref Vtk::RangeTypes category for the range. [Vtk::RangeTypes::AUTO] * \param category The \ref Vtk::RangeTypes category for the range. [Vtk::RangeTypes::UNSPECIFIED]
* \param dataType The \ref Vtk::DataTypes used in the output. [Vtk::DataTypes::FLOAT32] * \param dataType The \ref Vtk::DataTypes used in the output. [Vtk::DataTypes::FLOAT64]
* *
* The arguments `category` and `dataType` can be passed in any order. * The arguments `category` and `dataType` can be passed in any order.
* *
* NOTE: Stores the localFunction by value. * NOTE: Stores the localFunction by value.
**/ **/
template <class LF, class... Args, template <class LF, class... Args,
class = IsLocalFunction<LF>> IsLocalFunction<LF,Element> = true>
Function (LF&& localFct, std::string name, std::vector<int> components, Args&&... args) Function (LF&& localFct, std::string name, std::vector<int> components, Args&&... args)
: localFct_(std::forward<LF>(localFct)) : localFct_(std::forward<LF>(localFct))
, name_(std::move(name)) , name_(std::move(name))
...@@ -97,7 +88,7 @@ namespace Dune ...@@ -97,7 +88,7 @@ namespace Dune
* NOTE: Stores the localFunction by value. * NOTE: Stores the localFunction by value.
**/ **/
template <class LF, class... Args, template <class LF, class... Args,
class = IsLocalFunction<LF>> IsLocalFunction<LF,Element> = true>
Function (LF&& localFct, std::string name, int ncomps, Args&&... args) Function (LF&& localFct, std::string name, int ncomps, Args&&... args)
: Function(std::forward<LF>(localFct), std::move(name), allComponents(ncomps), : Function(std::forward<LF>(localFct), std::move(name), allComponents(ncomps),
std::forward<Args>(args)...) std::forward<Args>(args)...)
...@@ -110,7 +101,7 @@ namespace Dune ...@@ -110,7 +101,7 @@ namespace Dune
* static size information could be extracted. * static size information could be extracted.
**/ **/
template <class LF, class... Args, template <class LF, class... Args,
class = IsLocalFunction<LF>, IsLocalFunction<LF,Element> = true,
class R = Range<LF,LocalDomain> > class R = Range<LF,LocalDomain> >
Function (LF&& localFct, std::string name, Args&&... args) Function (LF&& localFct, std::string name, Args&&... args)
: Function(std::forward<LF>(localFct), std::move(name), sizeOf<R>(), : Function(std::forward<LF>(localFct), std::move(name), sizeOf<R>(),
...@@ -138,7 +129,7 @@ namespace Dune ...@@ -138,7 +129,7 @@ namespace Dune
*/ */
template <class GF, class... Args, template <class GF, class... Args,
disableCopyMove<Function, GF> = 0, disableCopyMove<Function, GF> = 0,
class = IsGridFunction<GF> > IsGridFunction<GF> = true>
Function (GF&& fct, std::string name, Args&&... args) Function (GF&& fct, std::string name, Args&&... args)
: Function(localFunction(std::forward<GF>(fct)), std::move(name), std::forward<Args>(args)...) : Function(localFunction(std::forward<GF>(fct)), std::move(name), std::forward<Args>(args)...)
{} {}
...@@ -149,10 +140,10 @@ namespace Dune ...@@ -149,10 +140,10 @@ namespace Dune
: Function(std::forward<F>(fct), info.name(), info.size(), info.rangeType(), info.dataType()) : Function(std::forward<F>(fct), info.name(), info.size(), info.rangeType(), info.dataType())
{} {}
/// (6) Automatically extract name and num components from GridFunction if available /// (7) Automatically extract name and num components from GridFunction if available
template <class F, class... Args, template <class F, class... Args,
disableCopyMove<Function, F> = 0, disableCopyMove<Function, F> = 0,
class = decltype(localFunction(std::declval<F>())), IsGridFunction<F> = true,
class = decltype(std::declval<F>().name()), class = decltype(std::declval<F>().name()),
class = decltype(std::declval<F>().numComponents()), class = decltype(std::declval<F>().numComponents()),
class = decltype(std::declval<F>().dataType()) > class = decltype(std::declval<F>().dataType()) >
...@@ -161,8 +152,7 @@ namespace Dune ...@@ -161,8 +152,7 @@ namespace Dune
Vtk::RangeTypes::UNSPECIFIED, fct.dataType()) Vtk::RangeTypes::UNSPECIFIED, fct.dataType())
{} {}
/// (8) Construct from legacy VTKFunction
/// (7) Construct from legacy VTKFunction
/** /**
* \param fct The Dune::VTKFunction to wrap * \param fct The Dune::VTKFunction to wrap
**/ **/
...@@ -175,7 +165,7 @@ namespace Dune ...@@ -175,7 +165,7 @@ namespace Dune
setRangeType(rangeTypeOf(fct->ncomps())); setRangeType(rangeTypeOf(fct->ncomps()));
} }
/// (8) Default constructor. After construction, the function is an an invalid state. /// (9) Default constructor. After construction, the function is an an invalid state.
Function () = default; Function () = default;
/// Create a LocalFunction /// Create a LocalFunction
......
...@@ -26,5 +26,17 @@ namespace Dune ...@@ -26,5 +26,17 @@ namespace Dune
CheckTypes<typename GV::Grid, typename GV::IndexSet>{}, CheckTypes<typename GV::Grid, typename GV::IndexSet>{},
true)); true));
template <class GridFunction, class GF = std::decay_t<GridFunction>>
using IsGridFunction = decltype((
localFunction(std::declval<GF const&>()),
true));
template <class LocalFunction, class LocalContext, class LF = std::decay_t<LocalFunction>>
using IsLocalFunction = decltype((
std::declval<LF&>().bind(std::declval<LocalContext>()),
std::declval<LF&>().unbind(),
std::declval<LF>()(std::declval<typename LocalContext::Geometry::LocalCoordinate>()),
true));
} // end namespace Vtk } // end namespace Vtk
} // end namespace Dune } // end namespace Dune
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