OpenFOAM的vtk流场文件的Python后处理脚本 您所在的位置:网站首页 ubuntu安装openfoam OpenFOAM的vtk流场文件的Python后处理脚本

OpenFOAM的vtk流场文件的Python后处理脚本

2023-03-24 11:07| 来源: 网络整理| 查看: 265

实现了用python处理OpenFOAM生成的vtk流场文件的脚本。 1、流场生成vtk文件, reconstructPar, foamToVTK -ascii, 结果放在./VTK文件夹下

2、运行后处理脚本,目前只支持网格大小相等的结构网格,可以全自动生成轴向固含率分布图和数据。

3、需要时变数据只需将下面脚本改为函数即可。

import vtk import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl reader = vtk.vtkUnstructuredGridReader() reader.SetFileName("./VTK/cfd_100.vtk") reader.Update() output = reader.GetOutput() # print(output) points = output.GetPoints() voidfractions = output.GetCellData().GetArray("voidfractionMean") cell_centers = vtk.vtkCellCenters() cell_centers.SetInputData(output) cell_centers.Update() # point = points.GetPoint(1) # point = output.GetPoint(1) # point, voidfraction # # ((0.004999999888241291, 0.0, 0.0), 0.9999974966049194) points_np = np.array([points.GetPoint(i) for i in range(points.GetNumberOfPoints())]) voidfractions_np = np.array([voidfractions.GetValue(i) for i in range(voidfractions.GetNumberOfTuples())]) cell_centers_np = np.array([cell_centers.GetOutput().GetPoint(i) for i in range(cell_centers.GetOutput().GetNumberOfPoints())]) zLength = max(points_np[:,2]) gap = zLength/20 threshold = gap/2 # volume = 6.25e-9 volume = 1 heights = np.arange(0, 1, gap) solid_volume_fractions = [] height_of_data = [] z_index = 2 cell_number = cell_centers.GetOutput().GetNumberOfPoints() for height in heights: # print(height) num_of_points = 0 total_volume = 0 solid_volume = 0 for i in range(0, cell_number): if cell_centers_np[i][z_index] >= height - threshold and cell_centers_np[i][z_index]


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有