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

class specialization instead of function overloading for makeGridFunction

parent f099e85c
......@@ -104,10 +104,10 @@ namespace AMDiS
* A derivative Expression can be created, using \ref gradientAtQP() that
* can be converted to a GridFunction afterwards.
**/
template <class PreGridFct, class GridView>
decltype(auto) makeGridFunction(PreGridFct&& preGridFct, GridView const& gridView)
{
return Impl::makeGridFunctionImpl(std::forward<PreGridFct>(preGridFct), gridView, Dune::PriorityTag<10>{});
}
// template <class PreGridFct, class GridView>
// decltype(auto) makeGridFunction(PreGridFct&& preGridFct, GridView const& gridView)
// {
// return Impl::makeGridFunctionImpl(std::forward<PreGridFct>(preGridFct), gridView, Dune::PriorityTag<10>{});
// }
} // end namespace AMDiS
......@@ -185,6 +185,29 @@ namespace AMDiS
}
template <class Function>
struct GridFunctionCreator<Function, std::enable_if_t<Concepts::CallableDomain<Function>>>
{
template <class GridView>
static auto create(Function const& fct, GridView const& gridView)
{
return AnalyticGridFunction<Function, GridView>{fct, gridView};
}
};
template <class Function>
struct GridFunctionCreator<AnalyticPreGridFunction<Function>>
{
using PreGridFct = AnalyticPreGridFunction<Function>;
template <class GridView>
static auto create(PreGridFct const& pre, GridView const& gridView)
{
return AnalyticGridFunction<Function, GridView>{pre.fct_, gridView};
}
};
namespace Impl
{
/// Generator function for \ref AnalyticGridFunction expressions from callable functions.
......
......@@ -166,15 +166,14 @@ namespace AMDiS
} // end namespace Concepts
namespace Impl
template <class Value>
struct GridFunctionCreator<Value, std::enable_if_t<Concepts::ConstantToGridFunction<Value>>>
{
/// Generator for a GridFunction representing a constant value
template <class T, class GridView,
REQUIRES(Concepts::ConstantToGridFunction<T>)>
auto makeGridFunctionImpl(T const& value, GridView const& gridView, Dune::PriorityTag<2>)
template <class GridView>
static auto create(Value const& value, GridView const& gridView)
{
return ConstantGridFunction<T,GridView>{value, gridView};
return ConstantGridFunction<Value,GridView>{value, gridView};
}
};
} // end namespace Impl
} // end namespace AMDiS
......@@ -5,6 +5,8 @@
#include <dune/common/diagonalmatrix.hh>
#include <dune/common/typeutilities.hh>
#include <amdis/gridfunctions/AnalyticGridFunction.hpp>
namespace AMDiS
{
namespace Operation
......@@ -116,21 +118,28 @@ namespace AMDiS
: std::true_type {};
}
namespace Impl
template <>
struct GridFunctionCreator<Operation::CoordsFunction>
{
/// Generator for GridFunction from the pre-GridFunction \ref CoordsFunction
using PreGridFct = Operation::CoordsFunction;
template <class GridView>
auto makeGridFunctionImpl(Operation::CoordsFunction const& f, GridView const& gridView, Dune::PriorityTag<1>)
static auto create(PreGridFct const& f, GridView const& gridView)
{
return makeAnalyticGridFunction(f, gridView);
}
};
template <>
struct GridFunctionCreator<Operation::CoordsCompFunction>
{
using PreGridFct = Operation::CoordsCompFunction;
/// Generator for GridFunction from the pre-GridFunction \ref CoordsCompFunction
template <class GridView>
auto makeGridFunctionImpl(Operation::CoordsCompFunction const& f, GridView const& gridView, Dune::PriorityTag<1>)
static auto create(PreGridFct const& f, GridView const& gridView)
{
return makeAnalyticGridFunction(f, gridView);
}
};
} // end namespace Impl
} // end namespace AMDiS
......@@ -115,14 +115,17 @@ namespace AMDiS
/** @} **/
namespace Impl
template <class Expr>
struct GridFunctionCreator<DerivativePreGridFunction<Expr>>
{
/// Generator function for \ref AnalyticGridFunction expressions from \ref AnalyticPreGridFunction.
template <class Expr, class GridView>
auto makeGridFunctionImpl(DerivativePreGridFunction<Expr> const& pre, GridView const& gridView, Dune::PriorityTag<3>)
using PreGridFct = DerivativePreGridFunction<Expr>;
template <class GridView>
static auto create(PreGridFct const& pre, GridView const& gridView)
{
return derivative(Impl::makeGridFunctionImpl(pre.expr, gridView, Dune::PriorityTag<10>{}));
return derivative(makeGridFunction(pre.expr, gridView));
}
};
} // end namespace Impl
} // end namespace AMDiS
......@@ -284,19 +284,20 @@ namespace AMDiS
/** @} **/
namespace Impl
template <class Functor, class... GridFcts>
struct GridFunctionCreator<FunctorPreGridFunction<Functor, GridFcts...>>
{
/// Generator function from a \ref FunctorPreGridFunction to a \ref FunctorGridFunction.
template <class Functor, class... GridFcts, class GridView>
auto makeGridFunctionImpl(FunctorPreGridFunction<Functor, GridFcts...> const& preGridFct,
GridView const& gridView,
Dune::PriorityTag<5>)
using PreGridFct = FunctorPreGridFunction<Functor, GridFcts...>;
template <class GridView>
static auto create(PreGridFct const& preGridFct, GridView const& gridView)
{
return Dune::Std::apply([&](auto const&... pgf) {
return makeFunctorGridFunction(preGridFct.fct_,
Impl::makeGridFunctionImpl(pgf, gridView, Dune::PriorityTag<10>{})...);
makeGridFunction(pgf, gridView)...);
}, preGridFct.gridFcts_);
}
};
} // end namespace Impl
} // end namespace AMDiS
......@@ -136,15 +136,38 @@ namespace AMDiS
return valid;
}
template <class GridFct, class = void>
struct GridFunctionCreator
{
template <class GridView>
static auto create(GridFct const& /*gridFct*/, GridView const& /*gridView*/);
};
namespace Impl
{
// Functions that forwards GridFunctions
template <class GridFct, class GridView,
REQUIRES(Concepts::GridFunction<GridFct>)>
auto const& makeGridFunctionImpl(GridFct const& gridFct, GridView const& /*gridView*/, Dune::PriorityTag<10>)
// Specialization for type that is already a GridFunction
template <class GridFct, class GridView>
GridFct const& makeGridFunctionImpl(GridFct const& gridFct, GridView const& /*gridView*/, std::true_type)
{
return gridFct;
}
} // end namespace Impl
// Use the \ref GridFunctionCreator to create a gridFunction from a preGridFunction
template <class PreGridFct, class GridView>
decltype(auto) makeGridFunctionImpl(PreGridFct const& preGridFct, GridView const& gridView, std::false_type)
{
using Creator = GridFunctionCreator<PreGridFct>;
return Creator::create(preGridFct, gridView);
}
}
template <class PreGridFct, class GridView>
decltype(auto) makeGridFunction(PreGridFct const& preGridFct, GridView const& gridView)
{
using isGridFct = bool_t<Concepts::GridFunction<PreGridFct>>;
return Impl::makeGridFunctionImpl(preGridFct, gridView, isGridFct{});
}
} // end namespace AMDiS
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