Commit 144b36ba authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

added examples to integrate methods

parent c27b2e73
...@@ -8,12 +8,13 @@ namespace AMDiS ...@@ -8,12 +8,13 @@ namespace AMDiS
{ {
namespace Impl namespace Impl
{ {
template <class GridFct, class GridView, class QuadProvider> template <class GF, class GridView, class QuadProvider>
auto integrateImpl(GridFct&& gridFct, GridView const& gridView, QuadProvider makeQuad) auto integrateImpl(GF&& gf, GridView const& gridView, QuadProvider makeQuad)
{ {
auto localFct = localFunction(gridFct); auto localFct = localFunction(std::forward<GF>(gf));
using Range = typename std::decay_t<GridFct>::Range; using GridFct = std::decay_t<GF>;
using Range = typename GridFct::Range;
Range result(0); Range result(0);
for (auto const& element : elements(gridView)) { for (auto const& element : elements(gridView)) {
...@@ -33,7 +34,15 @@ namespace AMDiS ...@@ -33,7 +34,15 @@ namespace AMDiS
} // end namespace Impl } // end namespace Impl
/// Integrate expression with quadrature rule determined by polynomial order of expression /// \brief Integrate expression with quadrature rule determined by polynomial order of expression
/**
* **Example:**
* ```
* double i1 = integrate(prob.solution(0), prob.gridView());
* double i2 = integrate(X(0) + X(1), prob.gridView());
* double i3 = integrate([](auto const& x) { return x[0] + x[1]; }, prob.gridView()); // ERROR
* ```
**/
template <class Expr, class GridView> template <class Expr, class GridView>
auto integrate(Expr&& expr, GridView const& gridView) auto integrate(Expr&& expr, GridView const& gridView)
{ {
...@@ -47,17 +56,24 @@ namespace AMDiS ...@@ -47,17 +56,24 @@ namespace AMDiS
#if AMDIS_HAS_CXX_CONSTEXPR_IF #if AMDIS_HAS_CXX_CONSTEXPR_IF
if constexpr(expr_has_order) if constexpr(expr_has_order)
return Impl::integrateImpl(gridFct, gridView, makeQuad); return Impl::integrateImpl(std::forward<decltype(gridFct)>(gridFct), gridView, makeQuad);
else else
return 0.0; return 0.0;
#else #else
return Dune::Hybrid::ifElse(bool_<expr_has_order>, return Dune::Hybrid::ifElse(bool_<expr_has_order>,
[&](auto) { return Impl::integrateImpl(gridFct, gridView, makeQuad); }, [&](auto) { return Impl::integrateImpl(std::forward<decltype(gridFct)>(gridFct), gridView, makeQuad); },
[ ](auto) { return 0.0; }); [ ](auto) { return 0.0; });
#endif #endif
} }
/// Integrate expression with quadrature rule provided /// Integrate expression with quadrature rule provided
/**
* **Example:**
* ```
* auto quad = Dune::QuadratureRules<double,DIM>::rule(Dune::GeometryTypes::triangle, 1);
* double i4 = integrate([](auto const& x) { return x[0]; }, prob.gridView(), quad); // OK
* ```
**/
template <class Expr, class GridView, template <class Expr, class GridView,
class QuadratureRule = Dune::QuadratureRule<typename GridView::ctype, GridView::dimension>> class QuadratureRule = Dune::QuadratureRule<typename GridView::ctype, GridView::dimension>>
auto integrate(Expr&& expr, GridView const& gridView, QuadratureRule const& quad) auto integrate(Expr&& expr, GridView const& gridView, QuadratureRule const& quad)
...@@ -68,6 +84,12 @@ namespace AMDiS ...@@ -68,6 +84,12 @@ namespace AMDiS
} }
/// Integrate expression with quadrature rule determined by provided polynomial `degree` /// Integrate expression with quadrature rule determined by provided polynomial `degree`
/**
* **Example:**
* ```
* double i5 = integrate([](auto const& x) { return x[0]; }, prob.gridView(), 1); // OK
* ```
**/
template <class Expr, class GridView> template <class Expr, class GridView>
auto integrate(Expr&& expr, GridView const& gridView, int degree, auto integrate(Expr&& expr, GridView const& gridView, int degree,
Dune::QuadratureType::Enum qt = Dune::QuadratureType::GaussLegendre) Dune::QuadratureType::Enum qt = Dune::QuadratureType::GaussLegendre)
......
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