我得到了一个风的模拟结果,想在z方向7个不同的高度切片计算风速比,并保存每张截图。但是,我遇到了一个问题,轴网格只出现在第一个循环中,因为在第二个循环中,只显示风速比。这是我试过的。
#### import the simple module from the paraview
from paraview.simple import *
import numpy as np
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()
# get the material library
materialLibrary1 = GetMaterialLibrary()
# Create a new 'Render View'
renderView1 = CreateView('RenderView')
renderView1.ViewSize = [1280, 720]
renderView1.AxesGrid = 'GridAxes3DActor'
renderView1.OrientationAxesVisibility = 0
renderView1.CenterOfRotation = [1000.0, 1145.0, 10.0]
renderView1.StereoType = 'Crystal Eyes'
renderView1.CameraPosition = [1000.0, 1145.0, 4864.234146297973]
renderView1.CameraFocalPoint = [1000.0, 1145.0, 10.0]
renderView1.CameraViewUp = [-1.0, 0.0, 0.0]
renderView1.CameraFocalDisk = 1.0
renderView1.CameraParallelScale = 1520.2055782031587
renderView1.BackEnd = 'OSPRay raycaster'
renderView1.OSPRayMaterialLibrary = materialLibrary1
SetActiveView(None)
# ----------------------------------------------------------------
# setup view layouts
# ----------------------------------------------------------------
# create new layout object 'Layout #1'
layout1 = CreateLayout(name='Layout #1')
layout1.AssignView(0, renderView1)
# ----------------------------------------------------------------
# restore active view
SetActiveView(renderView1)
# ----------------------------------------------------------------
# ----------------------------------------------------------------
# setup the inlet velocity profile
# ----------------------------------------------------------------
u_ref = 30
z_ref = 10
z0 = 0.0002
kappa = 0.41
u_star = u_ref*kappa/np.log((z_ref+z0)/z0)
height = [5,10, 15, 20, 25, 30, 35]
inlet_speed = [u_star / kappa * np.log((h + z0) / z0) for h in height]
# ----------------------------------------------------------------
# setup the data processing pipelines
# ----------------------------------------------------------------
# create a new 'OpenFOAMReader'
runfoam = OpenFOAMReader(FileName='run.foam')
runfoam.MeshRegions = ['internalMesh']
runfoam.CellArrays = ['U', 'epsilon', 'k', 'nut', 'p']
# Set active time step to the second timestep
reader = GetActiveSource()
view = GetActiveView()
times = reader.TimestepValues
view.ViewTime = times[1]
# create a new 'Slice'
slice1 = Slice(Input=runfoam)
slice1.SliceType = 'Plane'
slice1.HyperTreeGridSlicer = 'Plane'
slice1.SliceOffsetValues = [0.0]
for ii in range(len(height)):
# init the 'Plane' selected for 'SliceType'
slice1.SliceType.Origin = [1000.0, 1145.0, height[ii]]
slice1.SliceType.Normal = [0.0, 0.0, 1.0]
renderView1.AxesGrid = 'GridAxes3DActor' # add this line to show axes grid
renderView1.Update()
# init the 'Plane' selected for 'HyperTreeGridSlicer'
slice1.HyperTreeGridSlicer.Origin = [1000.0, 1145.0, 107.32312601804733]
# create a new 'Calculator'
calculator1 = Calculator(Input=slice1)
calculator1.ResultArrayName = 'Uratio'
calculator1.Function = 'U/'+str(inlet_speed[ii])
renderView1.Update()
# ----------------------------------------------------------------
# setup the visualization in view 'renderView1'
# ----------------------------------------------------------------
# show data from calculator1
calculator1Display = Show(calculator1, renderView1, 'GeometryRepresentation')
# get color transfer function/color map for 'Uratio'
uratioLUT = GetColorTransferFunction('Uratio')
uratioLUT.AutomaticRescaleRangeMode = 'Never'
uratioLUT.RGBPoints = [0.0, 0.0, 0.0, 0.5625, 0.1555554, 0.0, 0.0, 1.0, 0.5111112999999999, 0.0, 1.0, 1.0, 0.6888888999999999, 0.5, 1.0, 0.5, 0.8666664999999999, 1.0, 1.0, 0.0, 1.2222224, 1.0, 0.0, 0.0, 1.4, 0.5, 0.0, 0.0]
uratioLUT.ColorSpace = 'RGB'
uratioLUT.NumberOfTableValues = 14
uratioLUT.ScalarRangeInitialized = 1.0
# trace defaults for the display properties.
calculator1Display.Representation = 'Surface'
calculator1Display.ColorArrayName = ['POINTS', 'Uratio']
calculator1Display.LookupTable = uratioLUT
calculator1Display.OSPRayScaleArray = 'p'
calculator1Display.OSPRayScaleFunction = 'PiecewiseFunction'
calculator1Display.SelectOrientationVectors = 'Uratio'
calculator1Display.ScaleFactor = 229.0
calculator1Display.SelectScaleArray = 'p'
calculator1Display.GlyphType = 'Arrow'
calculator1Display.GlyphTableIndexArray = 'p'
calculator1Display.GaussianRadius = 11.450000000000001
calculator1Display.SetScaleArray = ['POINTS', 'p']
calculator1Display.ScaleTransferFunction = 'PiecewiseFunction'
calculator1Display.OpacityArray = ['POINTS', 'p']
calculator1Display.OpacityTransferFunction = 'PiecewiseFunction'
calculator1Display.DataAxesGrid = 'GridAxesRepresentation'
calculator1Display.PolarAxes = 'PolarAxesRepresentation'
# init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
calculator1Display.ScaleTransferFunction.Points = [-1396.27392578125, 0.0, 0.5, 0.0, 570.5612182617188, 1.0, 0.5, 0.0]
# init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
calculator1Display.OpacityTransferFunction.Points = [-1396.27392578125, 0.0, 0.5, 0.0, 570.5612182617188, 1.0, 0.5, 0.0]
# init the 'GridAxes3DActor' selected for 'AxesGrid'
renderView1.AxesGrid.XTitle = ''
renderView1.AxesGrid.YTitle = ''
renderView1.AxesGrid.ZTitle = ''
renderView1.AxesGrid.XTitleBold = 1
renderView1.AxesGrid.XTitleFontSize = 28
renderView1.AxesGrid.YTitleBold = 1
renderView1.AxesGrid.YTitleFontSize = 28
renderView1.AxesGrid.AxesToLabel = 3
renderView1.AxesGrid.XLabelBold = 1
renderView1.AxesGrid.XLabelFontSize = 28
renderView1.AxesGrid.YLabelBold = 1
renderView1.AxesGrid.YLabelFontSize = 28
renderView1.AxesGrid.ZLabelBold = 1
renderView1.Update()
# setup the color legend parameters for each legend in this view
# get color legend/bar for uratioLUT in view renderView1
uratioLUTColorBar = GetScalarBar(uratioLUT, renderView1)
uratioLUTColorBar.WindowLocation = 'AnyLocation'
uratioLUTColorBar.Position = [0.7813682909604519, 0.12386300027987682]
uratioLUTColorBar.Title = 'U/Uinlet'
uratioLUTColorBar.ComponentTitle = ''
uratioLUTColorBar.TitleBold = 1
uratioLUTColorBar.TitleFontSize = 24
uratioLUTColorBar.LabelBold = 1
uratioLUTColorBar.LabelFontSize = 24
uratioLUTColorBar.RangeLabelFormat = '%-#6.1f'
uratioLUTColorBar.ScalarBarLength = 0.4345340050377833
# set color bar visibility
uratioLUTColorBar.Visibility = 1
# show color legend
calculator1Display.SetScalarBarVisibility(renderView1, True)
# ----------------------------------------------------------------
# setup color maps and opacity mapes used in the visualization
# note: the Get..() functions create a new object, if needed
# ----------------------------------------------------------------
# get opacity transfer function/opacity map for 'Uratio'
uratioPWF = GetOpacityTransferFunction('Uratio')
uratioPWF.Points = [0.0, 0.0, 0.5, 0.0, 1.4, 1.0, 0.5, 0.0]
uratioPWF.ScalarRangeInitialized = 1
# save screenshot
SaveScreenshot('test'+str(height[ii])+'.tiff', renderView1, ImageResolution=[2560, 1440],
# TIFF options
Compression='None')