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

Merge branch 'dailywork-ftschindler' into 'master'

[P|grid] allow to visualize 1d grid

See merge request !71
parents a8c1d41e b9aca6de
No related branches found
No related tags found
1 merge request!71[P|grid] allow to visualize 1d grid
Pipeline #73586 passed
......@@ -11,6 +11,7 @@
# Tobias Leibner (2019 - 2020)
# ~~~
import numpy as np
from numbers import Number
from tempfile import NamedTemporaryFile
......@@ -48,7 +49,27 @@ def Dim(d):
def visualize_grid(grid):
tmpfile = NamedTemporaryFile(mode='wb', delete=False, suffix='.vtu').name
grid.visualize(tmpfile[:-4])
return plot(
tmpfile, color_attribute_name='Element index') # see visualize in python/dune/xt/grid/gridprovider.hh
if grid.dimension == 1:
from matplotlib import pyplot as plt
centers = np.array(grid.centers(1), copy=False)[:, 0]
points = np.zeros(2*grid.size(0))
points[1::2] = centers[1:]
points[2::2] = centers[1:(len(centers) - 1)]
indices = np.zeros(2*grid.size(0))
indices[::2] = np.arange(grid.size(0))
indices[1::2] = np.arange(grid.size(0))
plt.figure()
plt.title(f'grid with {grid.size(0)} elements')
plt.plot(points, indices)
return plt.gca()
else:
tmpfile = NamedTemporaryFile(mode='wb', delete=False, suffix='.vtu').name
grid.visualize(tmpfile[:-4])
return plot(
tmpfile, color_attribute_name='Element index') # see visualize in python/dune/xt/grid/gridprovider.hh
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