Я разобрался с решением этой проблемы. Хотя это вряд ли оптимальный вариант. Для этого решения я сначала преобразовал me sh в vtkUnstructuredGrid
(в данном случае с разрешением 256 точек).
. Ниже приведен код, который я использовал для этого:
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
import numpy as np
import vtk
from vtk.util.numpy_support import vtk_to_numpy
from os import walk, path, system
import pandas as pd
### Create the VTK files
system("foamToVTK")
### Initialization of variables
cnt=1
fig= plt.figure()
npts = 256 #dimensions of the grid
### Get the file names of each step of the simulation
(dirpath, dirnames, filenames) = next(walk('VTK'))
ids=[]
for dir in dirnames:
ids.append(int(dir.split("_")[1]))
ids = sorted(ids)
basename = dirnames[0].split("_")[0]
### Iteration of time steps
for id in ids[1:]:
### Read values from the file of this time step
filename = "%s/%s_%d/internal.vtu" % (dirpath, basename, id)
reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName(filename)
reader.Update()
### Get the coordinates of nodes in the mesh using VTK methods
nodes_vtk_array= reader.GetOutput().GetPoints().GetData()
vtk_array = reader.GetOutput().GetPointData().GetArray('U') #Velocity (3 dimensions)
numpy_array = vtk_to_numpy(vtk_array)
nodes_nummpy_array = vtk_to_numpy(nodes_vtk_array)
x,y,z= nodes_nummpy_array[:,0] , nodes_nummpy_array[:,1] , nodes_nummpy_array[:,2]
xmin, xmax = min(x), max(x)
ymin, ymax = min(y), max(y)
### Define grid
xi = np.linspace(xmin, xmax, npts)
yi = np.linspace(ymin, ymax, npts)
### Grid the data
interpolated = griddata((x, y), numpy_array, (xi[None,:], yi[:,None]), method='cubic')
### Create the list of points
plotOverLine=[]
for point in range(len(interpolated[0])):
plotOverLine.append(interpolated[127][point])
### Update and plot the chart for this time step
df = pd.DataFrame(plotOverLine, columns=['X', 'Y', 'Z'])
plt.clf()
plt.title('Frame %d' % cnt)
plt.plot(df)
plt.legend(df.columns)
axes = plt.gca()
axes.set_ylim([-15,10])
plt.draw()
plt.pause(.05)
Для каждого временного шага обновляется и отображается график, подобный следующему:
![enter image description here](https://i.stack.imgur.com/7fb53.png)