version 0.4.1
griddrawer.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2024 The Ikarus Developers mueller@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
10#pragma once
11
12#include <matplot/matplot.h>
13#include <ranges>
14#include <set>
15#include <thread>
16
17#include <dune/geometry/dimension.hh>
18
30template <typename GV>
31void draw(const GV& gridView, bool forever = false) {
32 using namespace matplot;
33 auto f = figure(true);
34 auto ax = gca();
35 hold(ax, true);
36 constexpr int edgeCodim = GV::dimension - 1;
37 for (auto&& element : elements(gridView)) {
38 std::array<std::array<double, 2>, GV::dimensionworld> edgeCoords{};
39 for (size_t edgeIndex = 0; edgeIndex < element.subEntities(edgeCodim); ++edgeIndex) {
40 auto edge = element.template subEntity<edgeCodim>(edgeIndex);
41 for (int i = 0; i < 2; ++i) {
42 const auto vertCoords = edge.geometry().corner(i);
43 for (int j = 0; j < GV::dimensionworld; ++j)
44 edgeCoords[j][i] = vertCoords[j];
45 }
46 if constexpr (GV::dimensionworld == 3) {
47 auto l = ax->plot3(edgeCoords[0], edgeCoords[1], edgeCoords[2], "-o");
48 l->line_width(2);
49 l->color("black");
50 l->marker_size(10);
51 l->marker_face_color("red");
52 } else {
53 auto l = ax->plot(edgeCoords[0], edgeCoords[1], "-o");
54 l->line_width(2);
55 l->color("black");
56 l->marker_size(10);
57 l->marker_face_color("red");
58 }
59 }
60 }
61
62 if (forever)
63 f->show();
64 else {
65 f->draw();
66 using namespace std::chrono_literals;
67 std::this_thread::sleep_for(5s);
68 }
69 f.reset();
70}
void draw(const GV &gridView, bool forever=false)
Draw function for visualizing the elements of a DUNE grid view.
Definition: griddrawer.hh:31