Skip to content
Snippets Groups Projects
Commit 8292a44e authored by Dr. Felix Tobias Schindler's avatar Dr. Felix Tobias Schindler
Browse files

[P|grid.provider] refactor visualize

parent 30b4c3a9
No related branches found
No related tags found
1 merge request!20Update bindings
Pipeline #62845 failed
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
#include <dune/xt/common/numeric_cast.hh> #include <dune/xt/common/numeric_cast.hh>
#include <dune/xt/grid/entity.hh> #include <dune/xt/grid/entity.hh>
#include <dune/xt/grid/exceptions.hh> #include <dune/xt/grid/exceptions.hh>
#include <dune/xt/grid/gridprovider/dgf.hh>
#include <dune/xt/grid/gridprovider/provider.hh> #include <dune/xt/grid/gridprovider/provider.hh>
#include <dune/xt/functions/generic/grid-function.hh>
#include <python/dune/xt/common/configuration.hh> #include <python/dune/xt/common/configuration.hh>
#include <python/dune/xt/common/fvector.hh> #include <python/dune/xt/common/fvector.hh>
...@@ -51,24 +53,42 @@ public: ...@@ -51,24 +53,42 @@ public:
const std::string class_name = class_id + "_" + grid_id; const std::string class_name = class_id + "_" + grid_id;
const auto ClassName = XT::Common::to_camel_case(class_name); const auto ClassName = XT::Common::to_camel_case(class_name);
bound_type c(m, ClassName.c_str(), (XT::Common::to_camel_case(class_id) + " (" + grid_id + " variant)").c_str()); bound_type c(m, ClassName.c_str(), (XT::Common::to_camel_case(class_id) + " (" + grid_id + " variant)").c_str());
c.def_property_readonly("dimension", [dim](type&){return dim;}); c.def_property_readonly("dimension", [dim](type&) { return dim; });
c.def_property_readonly("max_level", &type::max_level); c.def_property_readonly("max_level", &type::max_level);
c.def("size", [dim](type& self, const int codim){ c.def(
DUNE_THROW_IF(codim < 0 || codim > dim, "size",
Exceptions::wrong_codimension, [dim](type& self, const int codim) {
"dim = " << dim << "\n codim = " << codim); DUNE_THROW_IF(
auto grid_view = self.leaf_view(); codim < 0 || codim > dim, Exceptions::wrong_codimension, "dim = " << dim << "\n codim = " << codim);
MultipleCodimMultipleGeomTypeMapper<decltype(grid_view)> mapper(grid_view, [codim](GeometryType gt, int dimgrid) { auto grid_view = self.leaf_view();
return dimgrid - Common::numeric_cast<int>(gt.dim()) == codim; MultipleCodimMultipleGeomTypeMapper<decltype(grid_view)> mapper(
}); grid_view,
return mapper.size(); [codim](GeometryType gt, int dimgrid) { return dimgrid - Common::numeric_cast<int>(gt.dim()) == codim; });
}, "codim"_a); return mapper.size();
c.def("visualize", [](type& self, const std::string& filename, const Common::Configuration& boundary_info_cfg){ },
self.visualize(filename, boundary_info_cfg); "codim"_a);
}, c.def(
"filename"_a, "visualize",
"boundary_info_cfg"_a = Common::Configuration()); [](type& self, const std::string& filename, const std::string& layer) {
c.def("global_refine", [](type& self, const int count){self.global_refine(count);}, "count"_a = 1); DUNE_THROW_IF(layer != "leaf", NotImplemented, "Visualization of level views not implemented yet!");
auto grid_view = self.leaf_view();
using GV = decltype(grid_view);
const MultipleCodimMultipleGeomTypeMapper<GV> mapper(
grid_view, [](GeometryType gt, int dimgrid) { return dimgrid == Common::numeric_cast<int>(gt.dim()); });
double element_index = 0;
Functions::GenericGridFunction<extract_entity_t<GV>> element_index_function(
/*order=*/[](const auto&) { return 0; },
/*post_bind=*/[&mapper, &element_index](const auto& element) { element_index = mapper.index(element); },
/*evaluate=*/[&element_index](const auto&, const auto&) { return element_index; },
/*param_type=*/{},
/*name=*/"Element index");
element_index_function.visualize(grid_view, filename, /*subsampling=*/false);
},
"filename"_a,
"layer"_a = "leaf");
c.def(
"global_refine", [](type& self, const int count) { self.global_refine(count); }, "count"_a = 1);
c.def("refine_steps_for_half", [](type& /*self*/) { return DGFGridInfo<G>::refineStepsForHalf(); });
return c; return c;
} // ... bind(...) } // ... bind(...)
}; // class GridProvider }; // class GridProvider
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment