diff --git a/dune/jupyter-kernel/dune/jupyter-kernel/printgrid.hh b/dune/jupyter-kernel/dune/jupyter-kernel/printgrid.hh index a45e9ca..16ca24b 100644 --- a/dune/jupyter-kernel/dune/jupyter-kernel/printgrid.hh +++ b/dune/jupyter-kernel/dune/jupyter-kernel/printgrid.hh @@ -5,20 +5,41 @@ #include #include #include +#include +#include // We inject this into the Dune namespace to enable ADL namespace Dune { - // TODO: Add a concept check for a Dune grid - template - nlohmann::json mime_bundle_repr(const std::unique_ptr& grid) + template + nlohmann::json mime_bundle_repr(const std::unique_ptr& ptr) { - //check for grid dimension + return mime_bundle_repr(*ptr); + } + + template + nlohmann::json mime_bundle_repr(const std::shared_ptr& ptr) + { + return mime_bundle_repr(*ptr); + } + + template + auto mime_bundle_repr(const GridView& gv) -> decltype((gv.grid(), nlohmann::json{})) // currently causes ambiguity + { + const auto& grid = gv.grid(); + return mime_bundle_repr(grid); + } + + // concept check for grid + template + auto mime_bundle_repr(const Grid& grid) -> decltype((grid.leafGridView(), nlohmann::json{})) // currently causes ambiguity + { + // check for grid dimension const int dim = Grid::dimension; if constexpr (dim == 2){ - //only print grids with not too many elements - int gridsize = grid->size(0); + // only print grids with not too many elements + int gridsize = grid.size(0); if (gridsize > 1000){ auto bundle = nlohmann::json::object(); bundle["text/plain"] = "Grid is to large for visualization."; @@ -29,7 +50,7 @@ namespace Dune { int argc; char** argv; const auto& helper = Dune::MPIHelper::instance(argc, argv); - Dune::printGrid(*grid, helper, "gridexercise"); + Dune::printGrid(grid, helper, "gridexercise"); // Read it back into a string buffer std::ifstream fin("gridexercise_0.png", std::ios::binary);