Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Concept check for grid and gridview #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions dune/jupyter-kernel/dune/jupyter-kernel/printgrid.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,41 @@
#include<dune/grid/io/file/printgrid.hh>
#include<nlohmann/json.hpp>
#include<xtl/xbase64.hpp>
#include<memory>
#include<functional>

// We inject this into the Dune namespace to enable ADL
namespace Dune {

// TODO: Add a concept check for a Dune grid
template<typename Grid>
nlohmann::json mime_bundle_repr(const std::unique_ptr<Grid>& grid)
template<typename T>
nlohmann::json mime_bundle_repr(const std::unique_ptr<T>& ptr)
{
//check for grid dimension
return mime_bundle_repr(*ptr);
}

template<typename T>
nlohmann::json mime_bundle_repr(const std::shared_ptr<T>& ptr)
{
return mime_bundle_repr(*ptr);
}

template <class GridView>
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<class Grid>
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.";
Expand All @@ -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);
Expand Down